3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
11 * \author André Pönitz
13 * \author Jürgen Vigna
15 * Full author contact details are available in file CREDITS.
20 #include "paragraph.h"
21 #include "paragraph_pimpl.h"
24 #include "bufferparams.h"
29 #include "latexrunparams.h"
36 #include "insets/insetbibitem.h"
37 #include "insets/insetoptarg.h"
39 #include "support/lstrings.h"
40 #include "support/textutils.h"
41 #include "support/std_sstream.h"
45 using lyx::support::contains;
46 using lyx::support::subst;
51 using std::ostringstream;
54 Paragraph::Paragraph()
55 : y(0), pimpl_(new Paragraph::Pimpl(this))
63 Paragraph::Paragraph(Paragraph const & lp)
64 : y(0), text_(lp.text_), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
68 // this is because of the dummy layout of the paragraphs that
70 layout_ = lp.layout();
72 // copy everything behind the break-position to the new paragraph
73 insetlist = lp.insetlist;
74 InsetList::iterator it = insetlist.begin();
75 InsetList::iterator end = insetlist.end();
76 for (; it != end; ++it) {
77 // currently we hold Inset*, not InsetBase*
78 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
83 void Paragraph::operator=(Paragraph const & lp)
85 // needed as we will destroy the pimpl_ before copying it
89 lyxerr << "Paragraph::operator=()" << endl;
94 pimpl_ = new Pimpl(*lp.pimpl_, this);
96 enumdepth = lp.enumdepth;
97 itemdepth = lp.itemdepth;
98 // this is because of the dummy layout of the paragraphs that
100 layout_ = lp.layout();
102 // copy everything behind the break-position to the new paragraph
103 insetlist = lp.insetlist;
104 InsetList::iterator it = insetlist.begin();
105 InsetList::iterator end = insetlist.end();
106 for (; it != end; ++it) {
107 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
111 // the destructor removes the new paragraph from the list
112 Paragraph::~Paragraph()
116 //lyxerr << "Paragraph::paragraph_id = "
117 // << Paragraph::paragraph_id << endl;
121 void Paragraph::write(Buffer const & buf, ostream & os,
122 BufferParams const & bparams,
123 depth_type & dth) const
125 // The beginning or end of a deeper (i.e. nested) area?
126 if (dth != params().depth()) {
127 if (params().depth() > dth) {
128 while (params().depth() > dth) {
129 os << "\n\\begin_deeper ";
133 while (params().depth() < dth) {
134 os << "\n\\end_deeper ";
140 // First write the layout
141 os << "\n\\begin_layout " << layout()->name() << '\n';
145 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
147 Change running_change = Change(Change::UNCHANGED);
148 lyx::time_type const curtime(lyx::current_time());
151 for (pos_type i = 0; i < size(); ++i) {
157 Change change = pimpl_->lookupChangeFull(i);
158 Changes::lyxMarkChange(os, column, curtime, running_change, change);
159 running_change = change;
161 // Write font changes
162 LyXFont font2 = getFontSettings(bparams, i);
163 if (font2 != font1) {
164 font2.lyxWriteChanges(font1, os);
169 value_type const c = getChar(i);
173 InsetOld const * inset = getInset(i);
175 if (inset->directWrite()) {
176 // international char, let it write
177 // code directly so it's shorter in
179 inset->write(buf, os);
181 os << "\n\\begin_inset ";
182 inset->write(buf, os);
183 os << "\n\\end_inset \n\n";
189 os << "\n\\backslash \n";
193 if (i + 1 < size() && getChar(i + 1) == ' ') {
200 if ((column > 70 && c == ' ')
205 // this check is to amend a bug. LyX sometimes
206 // inserts '\0' this could cause problems.
210 lyxerr << "ERROR (Paragraph::writeFile):"
211 " NULL char in structure." << endl;
217 // to make reading work properly
219 running_change = pimpl_->lookupChange(0);
220 Changes::lyxMarkChange(os, column, curtime,
221 Change(Change::UNCHANGED), running_change);
223 Changes::lyxMarkChange(os, column, curtime,
224 running_change, Change(Change::UNCHANGED));
226 os << "\n\\end_layout\n";
230 void Paragraph::validate(LaTeXFeatures & features) const
232 pimpl_->validate(features, *layout());
236 void Paragraph::eraseIntern(lyx::pos_type pos)
238 pimpl_->eraseIntern(pos);
242 bool Paragraph::erase(pos_type pos)
244 return pimpl_->erase(pos);
248 int Paragraph::erase(pos_type start, pos_type end)
250 return pimpl_->erase(start, end);
254 bool Paragraph::checkInsertChar(LyXFont & font)
256 if (pimpl_->inset_owner)
257 return pimpl_->inset_owner->checkInsertChar(font);
262 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
264 insertChar(pos, c, LyXFont(LyXFont::ALL_INHERIT));
268 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
269 LyXFont const & font, Change change)
271 pimpl_->insertChar(pos, c, font, change);
275 void Paragraph::insertInset(pos_type pos, InsetOld * inset)
277 insertInset(pos, inset, LyXFont(LyXFont::ALL_INHERIT));
281 void Paragraph::insertInset(pos_type pos, InsetOld * inset,
282 LyXFont const & font, Change change)
284 pimpl_->insertInset(pos, inset, font, change);
288 bool Paragraph::insetAllowed(InsetOld_code code)
290 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
291 if (pimpl_->inset_owner)
292 return pimpl_->inset_owner->insetAllowed(code);
297 InsetOld * Paragraph::getInset(pos_type pos)
299 BOOST_ASSERT(pos < size());
300 return insetlist.get(pos);
304 InsetOld const * Paragraph::getInset(pos_type pos) const
306 BOOST_ASSERT(pos < size());
307 return insetlist.get(pos);
311 // Gets uninstantiated font setting at position.
312 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
315 BOOST_ASSERT(pos <= size());
317 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
318 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
319 for (; cit != end; ++cit)
320 if (cit->pos() >= pos)
326 if (pos == size() && !empty())
327 return getFontSettings(bparams, pos - 1);
329 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
333 lyx::pos_type Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const
335 BOOST_ASSERT(pos <= size());
337 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
338 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
339 for (; cit != end; ++cit)
340 if (cit->pos() >= pos)
343 // This should not happen, but if so, we take no chances.
344 //lyxerr << "Paragraph::getEndPosOfFontSpan: This should not happen!"
350 // Gets uninstantiated font setting at position 0
351 LyXFont const Paragraph::getFirstFontSettings() const
353 if (!empty() && !pimpl_->fontlist.empty())
354 return pimpl_->fontlist[0].font();
356 return LyXFont(LyXFont::ALL_INHERIT);
360 // Gets the fully instantiated font at a given position in a paragraph
361 // This is basically the same function as LyXText::GetFont() in text2.C.
362 // The difference is that this one is used for generating the LaTeX file,
363 // and thus cosmetic "improvements" are disallowed: This has to deliver
364 // the true picture of the buffer. (Asger)
365 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
366 LyXFont const & outerfont) const
368 BOOST_ASSERT(pos >= 0);
370 LyXLayout_ptr const & lout = layout();
372 pos_type const body_pos = beginningOfBody();
376 layoutfont = lout->labelfont;
378 layoutfont = lout->font;
380 LyXFont tmpfont = getFontSettings(bparams, pos);
381 tmpfont.realize(layoutfont);
382 tmpfont.realize(outerfont);
383 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
389 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
390 LyXFont const & outerfont) const
392 LyXFont tmpfont = layout()->labelfont;
393 tmpfont.setLanguage(getParLanguage(bparams));
394 tmpfont.realize(outerfont);
395 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
400 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
401 LyXFont const & outerfont) const
403 LyXFont tmpfont = layout()->font;
404 tmpfont.setLanguage(getParLanguage(bparams));
405 tmpfont.realize(outerfont);
406 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
411 /// Returns the height of the highest font in range
413 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
414 LyXFont_size def_size) const
416 if (pimpl_->fontlist.empty())
419 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
420 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
421 for (; end_it != end; ++end_it) {
422 if (end_it->pos() >= endpos)
429 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
430 for (; cit != end; ++cit) {
431 if (cit->pos() >= startpos)
435 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
436 for (; cit != end_it; ++cit) {
437 LyXFont::FONT_SIZE size = cit->font().size();
438 if (size == LyXFont::INHERIT_SIZE)
440 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
447 Paragraph::value_type
448 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
450 value_type c = getChar(pos);
451 if (!lyxrc.rtl_support)
481 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
488 void Paragraph::setFont(pos_type pos, LyXFont const & font)
490 BOOST_ASSERT(pos <= size());
492 // First, reduce font against layout/label font
493 // Update: The SetCharFont() routine in text2.C already
494 // reduces font, so we don't need to do that here. (Asger)
495 // No need to simplify this because it will disappear
496 // in a new kernel. (Asger)
497 // Next search font table
499 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
500 Pimpl::FontList::iterator it = beg;
501 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
502 for (; it != endit; ++it) {
503 if (it->pos() >= pos)
506 unsigned int i = std::distance(beg, it);
507 bool notfound = (it == endit);
509 if (!notfound && pimpl_->fontlist[i].font() == font)
512 bool begin = pos == 0 || notfound ||
513 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
514 // Is position pos is a beginning of a font block?
515 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
516 // Is position pos is the end of a font block?
517 if (begin && end) { // A single char block
518 if (i + 1 < pimpl_->fontlist.size() &&
519 pimpl_->fontlist[i + 1].font() == font) {
520 // Merge the singleton block with the next block
521 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
522 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
523 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
524 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
525 // Merge the singleton block with the previous block
526 pimpl_->fontlist[i - 1].pos(pos);
527 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
529 pimpl_->fontlist[i].font(font);
531 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
532 pimpl_->fontlist[i - 1].pos(pos);
534 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
535 Pimpl::FontTable(pos, font));
537 pimpl_->fontlist[i].pos(pos - 1);
538 if (!(i + 1 < pimpl_->fontlist.size() &&
539 pimpl_->fontlist[i + 1].font() == font))
540 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
541 Pimpl::FontTable(pos, font));
542 } else { // The general case. The block is splitted into 3 blocks
543 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
544 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
545 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
546 Pimpl::FontTable(pos, font));
551 void Paragraph::makeSameLayout(Paragraph const & par)
553 layout(par.layout());
555 params() = par.params();
559 int Paragraph::stripLeadingSpaces()
565 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
566 pimpl_->eraseIntern(0);
574 bool Paragraph::hasSameLayout(Paragraph const & par) const
577 par.layout() == layout() &&
578 params().sameLayout(par.params());
582 Paragraph::depth_type Paragraph::getDepth() const
584 return params().depth();
588 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
590 if (layout()->isEnvironment())
591 return params().depth() + 1;
593 return params().depth();
597 char Paragraph::getAlign() const
599 return params().align();
603 string const & Paragraph::getLabelstring() const
605 return params().labelString();
609 // the next two functions are for the manual labels
610 string const Paragraph::getLabelWidthString() const
612 if (!params().labelWidthString().empty())
613 return params().labelWidthString();
615 return _("Senseless with this layout!");
619 void Paragraph::setLabelWidthString(string const & s)
621 params().labelWidthString(s);
625 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
628 params().labelWidthString(string());
629 params().align(LYX_ALIGN_LAYOUT);
630 params().spaceTop(VSpace(VSpace::NONE));
631 params().spaceBottom(VSpace(VSpace::NONE));
632 params().spacing(Spacing(Spacing::Default));
636 int Paragraph::beginningOfBody() const
638 if (layout()->labeltype != LABEL_MANUAL)
641 // Unroll the first two cycles of the loop
642 // and remember the previous character to
643 // remove unnecessary GetChar() calls
645 if (i < size() && !isNewline(i)) {
647 char previous_char = 0;
650 previous_char = getChar(i);
653 while (i < size() && previous_char != ' ') {
659 previous_char = temp;
669 // returns -1 if inset not found
670 int Paragraph::getPositionOfInset(InsetOld const * inset) const
673 InsetList::const_iterator it = insetlist.begin();
674 InsetList::const_iterator end = insetlist.end();
675 for (; it != end; ++it)
676 if (it->inset == inset)
682 InsetBibitem * Paragraph::bibitem() const
684 InsetList::const_iterator it = insetlist.begin();
685 if (it != insetlist.end() && it->inset->lyxCode() == InsetOld::BIBTEX_CODE)
686 return static_cast<InsetBibitem *>(it->inset);
693 /* paragraphs inside floats need different alignment tags to avoid
696 bool noTrivlistCentering(UpdatableInset const * inset)
698 if (inset && inset->owner()) {
699 InsetOld::Code const code = inset->owner()->lyxCode();
700 return code == InsetOld::FLOAT_CODE ||
701 code == InsetOld::WRAP_CODE;
707 string correction(string const & orig)
709 if (orig == "flushleft")
710 return "raggedright";
711 if (orig == "flushright")
713 if (orig == "center")
719 string const corrected_env(string const & suffix, string const & env,
720 UpdatableInset const * inset)
722 string output = suffix + "{";
723 if (noTrivlistCentering(inset))
724 output += correction(env);
733 // This could go to ParagraphParameters if we want to
734 int Paragraph::startTeXParParams(BufferParams const & bparams,
735 ostream & os, bool moving_arg) const
739 if (params().noindent()) {
744 switch (params().align()) {
746 case LYX_ALIGN_BLOCK:
747 case LYX_ALIGN_LAYOUT:
748 case LYX_ALIGN_SPECIAL:
751 case LYX_ALIGN_RIGHT:
752 case LYX_ALIGN_CENTER:
760 switch (params().align()) {
762 case LYX_ALIGN_BLOCK:
763 case LYX_ALIGN_LAYOUT:
764 case LYX_ALIGN_SPECIAL:
766 case LYX_ALIGN_LEFT: {
768 UpdatableInset const * const inset = pimpl_->inset_owner;
769 if (getParLanguage(bparams)->babel() != "hebrew")
770 output = corrected_env("\\begin", "flushleft", inset);
772 output = corrected_env("\\begin", "flushright", inset);
774 column += output.size();
776 } case LYX_ALIGN_RIGHT: {
778 UpdatableInset const * const inset = pimpl_->inset_owner;
779 if (getParLanguage(bparams)->babel() != "hebrew")
780 output = corrected_env("\\begin", "flushright", inset);
782 output = corrected_env("\\begin", "flushleft", inset);
784 column += output.size();
786 } case LYX_ALIGN_CENTER: {
788 output = corrected_env("\\begin", "center", pimpl_->inset_owner);
790 column += output.size();
799 // This could go to ParagraphParameters if we want to
800 int Paragraph::endTeXParParams(BufferParams const & bparams,
801 ostream & os, bool moving_arg) const
805 switch (params().align()) {
807 case LYX_ALIGN_BLOCK:
808 case LYX_ALIGN_LAYOUT:
809 case LYX_ALIGN_SPECIAL:
812 case LYX_ALIGN_RIGHT:
813 case LYX_ALIGN_CENTER:
821 switch (params().align()) {
823 case LYX_ALIGN_BLOCK:
824 case LYX_ALIGN_LAYOUT:
825 case LYX_ALIGN_SPECIAL:
827 case LYX_ALIGN_LEFT: {
829 UpdatableInset const * const inset = pimpl_->inset_owner;
830 if (getParLanguage(bparams)->babel() != "hebrew")
831 output = corrected_env("\\par\\end", "flushleft", inset);
833 output = corrected_env("\\par\\end", "flushright", inset);
835 column += output.size();
837 } case LYX_ALIGN_RIGHT: {
839 UpdatableInset const * const inset = pimpl_->inset_owner;
840 if (getParLanguage(bparams)->babel() != "hebrew")
841 output = corrected_env("\\par\\end", "flushright", inset);
843 output = corrected_env("\\par\\end", "flushleft", inset);
845 column += output.size();
847 } case LYX_ALIGN_CENTER: {
849 output = corrected_env("\\par\\end", "center", pimpl_->inset_owner);
851 column += output.size();
860 // This one spits out the text of the paragraph
861 bool Paragraph::simpleTeXOnePar(Buffer const & buf,
862 BufferParams const & bparams,
863 LyXFont const & outerfont,
864 ostream & os, TexRow & texrow,
865 LatexRunParams const & runparams)
867 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
869 bool return_value = false;
873 // well we have to check if we are in an inset with unlimited
874 // lenght (all in one row) if that is true then we don't allow
875 // any special options in the paragraph and also we don't allow
876 // any environment other then "Standard" to be valid!
878 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
881 style = bparams.getLyXTextClass().defaultLayout();
888 // Maybe we have to create a optional argument.
891 // FIXME: can we actually skip this check and just call
892 // beginningOfBody() ??
893 if (style->labeltype != LABEL_MANUAL) {
896 body_pos = beginningOfBody();
899 unsigned int column = 0;
904 basefont = getLabelFont(bparams, outerfont);
906 basefont = getLayoutFont(bparams, outerfont);
909 bool moving_arg = runparams.moving_arg;
910 moving_arg |= style->needprotect;
912 // Which font is currently active?
913 LyXFont running_font(basefont);
914 // Do we have an open font change?
915 bool open_font = false;
917 Change::Type running_change = Change::UNCHANGED;
919 texrow.start(id(), 0);
921 // if the paragraph is empty, the loop will not be entered at all
923 if (style->isCommand()) {
928 column += startTeXParParams(bparams, os, moving_arg);
932 for (pos_type i = 0; i < size(); ++i) {
934 // First char in paragraph or after label?
938 column += running_font.latexWriteEndChanges(os, basefont, basefont);
941 basefont = getLayoutFont(bparams, outerfont);
942 running_font = basefont;
946 if (style->isCommand()) {
952 column += startTeXParParams(bparams, os,
956 value_type c = getChar(i);
958 // Fully instantiated font
959 LyXFont font = getFont(bparams, i, outerfont);
961 LyXFont const last_font = running_font;
963 // Spaces at end of font change are simulated to be
964 // outside font change, i.e. we write "\textXX{text} "
965 // rather than "\textXX{text }". (Asger)
966 if (open_font && c == ' ' && i <= size() - 2) {
967 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
968 if (next_font != running_font
969 && next_font != font) {
974 // We end font definition before blanks
976 (font != running_font ||
977 font.language() != running_font.language()))
979 column += running_font.latexWriteEndChanges(os,
981 (i == body_pos-1) ? basefont : font);
982 running_font = basefont;
986 // Blanks are printed before start of fontswitch
988 // Do not print the separation of the optional argument
989 if (i != body_pos - 1) {
990 pimpl_->simpleTeXBlanks(os, texrow, i,
991 column, font, *style);
995 // Do we need to change font?
996 if ((font != running_font ||
997 font.language() != running_font.language()) &&
1000 column += font.latexWriteStartChanges(os, basefont,
1002 running_font = font;
1006 Change::Type change = pimpl_->lookupChange(i);
1008 column += Changes::latexMarkChange(os, running_change, change);
1009 running_change = change;
1011 LatexRunParams rp = runparams;
1012 rp.moving_arg = moving_arg;
1013 rp.free_spacing = style->free_spacing;
1014 pimpl_->simpleTeXSpecialChars(buf, bparams,
1015 os, texrow, runparams,
1017 basefont, outerfont, open_font,
1019 *style, i, column, c);
1022 column += Changes::latexMarkChange(os,
1023 running_change, Change::UNCHANGED);
1025 // If we have an open font definition, we have to close it
1027 #ifdef FIXED_LANGUAGE_END_DETECTION
1030 .latexWriteEndChanges(os, basefont,
1031 next_->getFont(bparams,
1034 running_font.latexWriteEndChanges(os, basefont,
1038 #ifdef WITH_WARNINGS
1039 //#warning For now we ALWAYS have to close the foreign font settings if they are
1040 //#warning there as we start another \selectlanguage with the next paragraph if
1041 //#warning we are in need of this. This should be fixed sometime (Jug)
1043 running_font.latexWriteEndChanges(os, basefont, basefont);
1047 // Needed if there is an optional argument but no contents.
1048 if (body_pos > 0 && body_pos == size()) {
1050 return_value = false;
1054 column += endTeXParParams(bparams, os, moving_arg);
1057 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1058 return return_value;
1064 /// return true if the char is a meta-character for an inset
1066 bool IsInsetChar(char c)
1068 return (c == Paragraph::META_INSET);
1075 bool Paragraph::isHfill(pos_type pos) const
1077 return IsInsetChar(getChar(pos))
1078 && getInset(pos)->lyxCode() == InsetOld::HFILL_CODE;
1082 bool Paragraph::isInset(pos_type pos) const
1084 return IsInsetChar(getChar(pos));
1088 bool Paragraph::isNewline(pos_type pos) const
1090 return IsInsetChar(getChar(pos))
1091 && getInset(pos)->lyxCode() == InsetOld::NEWLINE_CODE;
1095 bool Paragraph::isSeparator(pos_type pos) const
1097 return IsSeparatorChar(getChar(pos));
1101 bool Paragraph::isLineSeparator(pos_type pos) const
1103 value_type const c = getChar(pos);
1104 return IsLineSeparatorChar(c)
1105 || (IsInsetChar(c) && getInset(pos) &&
1106 getInset(pos)->isLineSeparator());
1110 bool Paragraph::isKomma(pos_type pos) const
1112 return IsKommaChar(getChar(pos));
1116 /// Used by the spellchecker
1117 bool Paragraph::isLetter(pos_type pos) const
1119 value_type const c = getChar(pos);
1120 if (IsLetterChar(c))
1123 return getInset(pos)->isLetter();
1124 // We want to pass the ' and escape chars to ispell
1125 string const extra = lyxrc.isp_esc_chars + '\'';
1126 return contains(extra, c);
1130 bool Paragraph::isWord(pos_type pos) const
1132 unsigned char const c = getChar(pos);
1133 return !(IsSeparatorChar(c)
1140 Paragraph::getParLanguage(BufferParams const & bparams) const
1143 return getFirstFontSettings().language();
1144 #warning FIXME we should check the prev par as well (Lgb)
1145 return bparams.language;
1149 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1151 return lyxrc.rtl_support
1152 && getParLanguage(bparams)->RightToLeft()
1153 && !(inInset() && inInset()->owner() &&
1154 inInset()->owner()->lyxCode() == InsetOld::ERT_CODE);
1158 void Paragraph::changeLanguage(BufferParams const & bparams,
1159 Language const * from, Language const * to)
1161 for (pos_type i = 0; i < size(); ++i) {
1162 LyXFont font = getFontSettings(bparams, i);
1163 if (font.language() == from) {
1164 font.setLanguage(to);
1171 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1173 Language const * doc_language = bparams.language;
1174 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1175 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1177 for (; cit != end; ++cit)
1178 if (cit->font().language() != ignore_language &&
1179 cit->font().language() != latex_language &&
1180 cit->font().language() != doc_language)
1186 // Convert the paragraph to a string.
1187 // Used for building the table of contents
1188 string const Paragraph::asString(Buffer const & buffer, bool label) const
1192 if (label && !params().labelString().empty())
1193 s += params().labelString() + ' ';
1195 for (pos_type i = 0; i < size(); ++i) {
1196 value_type c = getChar(i);
1199 else if (c == META_INSET &&
1200 getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
1202 getInset(i)->ascii(buffer, ost);
1203 s += subst(STRCONV(ost.str()),'\n',' ');
1209 // This should really be done by the caller and not here.
1210 string ret(asString(buffer, 0, size(), label));
1211 return subst(ret, '\n', ' ');
1216 string const Paragraph::asString(Buffer const & buffer,
1217 pos_type beg, pos_type end, bool label) const
1221 if (beg == 0 && label && !params().labelString().empty())
1222 os << params().labelString() << ' ';
1224 for (pos_type i = beg; i < end; ++i) {
1225 value_type const c = getUChar(buffer.params(), i);
1228 else if (c == META_INSET)
1229 getInset(i)->ascii(buffer, os);
1236 void Paragraph::setInsetOwner(UpdatableInset * inset)
1238 pimpl_->inset_owner = inset;
1239 InsetList::iterator it = insetlist.begin();
1240 InsetList::iterator end = insetlist.end();
1241 for (; it != end; ++it)
1243 it->inset->setOwner(inset);
1247 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1249 insetlist.deleteInsetsLyXText(bv);
1253 void Paragraph::setContentsFromPar(Paragraph const & par)
1255 pimpl_->setContentsFromPar(par);
1259 void Paragraph::trackChanges(Change::Type type)
1261 pimpl_->trackChanges(type);
1265 void Paragraph::untrackChanges()
1267 pimpl_->untrackChanges();
1271 void Paragraph::cleanChanges()
1273 pimpl_->cleanChanges();
1277 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1279 BOOST_ASSERT(!size() || pos < size());
1280 return pimpl_->lookupChange(pos);
1284 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1286 BOOST_ASSERT(!size() || pos < size());
1287 return pimpl_->lookupChangeFull(pos);
1291 bool Paragraph::isChanged(pos_type start, pos_type end) const
1293 return pimpl_->isChanged(start, end);
1297 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1299 return pimpl_->isChangeEdited(start, end);
1303 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1305 pimpl_->setChange(pos, type);
1310 void Paragraph::markErased()
1312 pimpl_->markErased();
1316 void Paragraph::acceptChange(pos_type start, pos_type end)
1318 return pimpl_->acceptChange(start, end);
1322 void Paragraph::rejectChange(pos_type start, pos_type end)
1324 return pimpl_->rejectChange(start, end);
1328 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1330 // This is in the critical path!
1331 pos_type const siz = text_.size();
1333 BOOST_ASSERT(pos <= siz);
1336 lyxerr << "getChar() on pos " << pos << " in par id "
1337 << id() << " of size " << siz
1338 << " is a bit silly !" << endl;
1346 int Paragraph::id() const
1352 void Paragraph::id(int i)
1358 LyXLayout_ptr const & Paragraph::layout() const
1361 InsetOld * inset = inInset();
1362 if (inset && inset->lyxCode() == InsetOld::ENVIRONMENT_CODE)
1363 return static_cast<InsetEnvironment*>(inset)->layout();
1369 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1371 layout_ = new_layout;
1375 UpdatableInset * Paragraph::inInset() const
1377 return pimpl_->inset_owner;
1381 void Paragraph::clearContents()
1387 void Paragraph::setChar(pos_type pos, value_type c)
1393 ParagraphParameters & Paragraph::params()
1395 return pimpl_->params;
1399 ParagraphParameters const & Paragraph::params() const
1401 return pimpl_->params;
1405 bool Paragraph::isFreeSpacing() const
1407 if (layout()->free_spacing)
1410 // for now we just need this, later should we need this in some
1411 // other way we can always add a function to InsetOld too.
1412 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1413 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
1418 bool Paragraph::allowEmpty() const
1420 if (layout()->keepempty)
1422 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1423 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;