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"
28 #include "latexrunparams.h"
31 #include "insets/insetbibitem.h"
32 #include "insets/insetoptarg.h"
34 #include "support/lstrings.h"
35 #include "support/LAssert.h"
36 #include "support/textutils.h"
38 #include "support/std_sstream.h"
41 using namespace lyx::support;
44 using std::ostringstream;
48 using std::lower_bound;
49 using std::upper_bound;
54 Paragraph::Paragraph()
55 : y(0), pimpl_(new Paragraph::Pimpl(this))
63 Paragraph::Paragraph(Paragraph const & lp)
64 : y(0), 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;
92 pimpl_ = new Pimpl(*lp.pimpl_, this);
94 enumdepth = lp.enumdepth;
95 itemdepth = lp.itemdepth;
96 // this is because of the dummy layout of the paragraphs that
98 layout_ = lp.layout();
100 // copy everything behind the break-position to the new paragraph
101 insetlist = lp.insetlist;
102 InsetList::iterator it = insetlist.begin();
103 InsetList::iterator end = insetlist.end();
104 for (; it != end; ++it) {
105 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
109 // the destructor removes the new paragraph from the list
110 Paragraph::~Paragraph()
114 //lyxerr << "Paragraph::paragraph_id = "
115 // << Paragraph::paragraph_id << endl;
119 void Paragraph::write(Buffer const & buf, ostream & os,
120 BufferParams const & bparams,
121 depth_type & dth) const
123 // The beginning or end of a deeper (i.e. nested) area?
124 if (dth != params().depth()) {
125 if (params().depth() > dth) {
126 while (params().depth() > dth) {
127 os << "\n\\begin_deeper ";
131 while (params().depth() < dth) {
132 os << "\n\\end_deeper ";
138 // First write the layout
139 os << "\n\\begin_layout " << layout()->name() << '\n';
143 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
145 Change running_change = Change(Change::UNCHANGED);
146 lyx::time_type const curtime(lyx::current_time());
149 for (pos_type i = 0; i < size(); ++i) {
155 Change change = pimpl_->lookupChangeFull(i);
156 Changes::lyxMarkChange(os, column, curtime, running_change, change);
157 running_change = change;
159 // Write font changes
160 LyXFont font2 = getFontSettings(bparams, i);
161 if (font2 != font1) {
162 font2.lyxWriteChanges(font1, os);
167 value_type const c = getChar(i);
171 InsetOld const * inset = getInset(i);
173 if (inset->directWrite()) {
174 // international char, let it write
175 // code directly so it's shorter in
177 inset->write(buf, os);
179 os << "\n\\begin_inset ";
180 inset->write(buf, os);
181 os << "\n\\end_inset \n\n";
187 os << "\n\\backslash \n";
191 if (i + 1 < size() && getChar(i + 1) == ' ') {
198 if ((column > 70 && c == ' ')
203 // this check is to amend a bug. LyX sometimes
204 // inserts '\0' this could cause problems.
208 lyxerr << "ERROR (Paragraph::writeFile):"
209 " NULL char in structure." << endl;
215 // to make reading work properly
217 running_change = pimpl_->lookupChange(0);
218 Changes::lyxMarkChange(os, column, curtime,
219 Change(Change::UNCHANGED), running_change);
221 Changes::lyxMarkChange(os, column, curtime,
222 running_change, Change(Change::UNCHANGED));
224 os << "\n\\end_layout\n";
228 void Paragraph::validate(LaTeXFeatures & features) const
230 pimpl_->validate(features, *layout());
234 void Paragraph::eraseIntern(lyx::pos_type pos)
236 pimpl_->eraseIntern(pos);
240 bool Paragraph::erase(pos_type pos)
242 return pimpl_->erase(pos);
246 int Paragraph::erase(pos_type start, pos_type end)
248 return pimpl_->erase(start, end);
252 bool Paragraph::checkInsertChar(LyXFont & font)
254 if (pimpl_->inset_owner)
255 return pimpl_->inset_owner->checkInsertChar(font);
260 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
262 insertChar(pos, c, LyXFont(LyXFont::ALL_INHERIT));
266 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
267 LyXFont const & font, Change change)
269 pimpl_->insertChar(pos, c, font, change);
273 void Paragraph::insertInset(pos_type pos, InsetOld * inset)
275 insertInset(pos, inset, LyXFont(LyXFont::ALL_INHERIT));
279 void Paragraph::insertInset(pos_type pos, InsetOld * inset,
280 LyXFont const & font, Change change)
282 pimpl_->insertInset(pos, inset, font, change);
286 bool Paragraph::insetAllowed(InsetOld::Code code)
288 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
289 if (pimpl_->inset_owner)
290 return pimpl_->inset_owner->insetAllowed(code);
295 InsetOld * Paragraph::getInset(pos_type pos)
297 Assert(pos < size());
298 return insetlist.get(pos);
302 InsetOld const * Paragraph::getInset(pos_type pos) const
304 Assert(pos < size());
305 return insetlist.get(pos);
309 // Gets uninstantiated font setting at position.
310 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
313 Assert(pos <= size());
315 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
316 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
317 for (; cit != end; ++cit)
318 if (cit->pos() >= pos)
324 if (pos == size() && !empty())
325 return getFontSettings(bparams, pos - 1);
327 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
331 lyx::pos_type Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const
333 Assert(pos <= size());
335 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
336 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
337 for (; cit != end; ++cit)
338 if (cit->pos() >= pos)
341 // This should not happen, but if so, we take no chances.
342 //lyxerr << "Paragraph::getEndPosOfFontSpan: This should not happen!"
348 // Gets uninstantiated font setting at position 0
349 LyXFont const Paragraph::getFirstFontSettings() const
351 if (!empty() && !pimpl_->fontlist.empty())
352 return pimpl_->fontlist[0].font();
354 return LyXFont(LyXFont::ALL_INHERIT);
358 // Gets the fully instantiated font at a given position in a paragraph
359 // This is basically the same function as LyXText::GetFont() in text2.C.
360 // The difference is that this one is used for generating the LaTeX file,
361 // and thus cosmetic "improvements" are disallowed: This has to deliver
362 // the true picture of the buffer. (Asger)
363 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
364 LyXFont const & outerfont) const
368 LyXLayout_ptr const & lout = layout();
370 pos_type const body_pos = beginningOfBody();
374 layoutfont = lout->labelfont;
376 layoutfont = lout->font;
378 LyXFont tmpfont = getFontSettings(bparams, pos);
379 tmpfont.realize(layoutfont);
380 tmpfont.realize(outerfont);
381 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
387 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
388 LyXFont const & outerfont) const
390 LyXFont tmpfont = layout()->labelfont;
391 tmpfont.setLanguage(getParLanguage(bparams));
392 tmpfont.realize(outerfont);
393 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
398 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
399 LyXFont const & outerfont) const
401 LyXFont tmpfont = layout()->font;
402 tmpfont.setLanguage(getParLanguage(bparams));
403 tmpfont.realize(outerfont);
404 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
409 /// Returns the height of the highest font in range
411 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
412 LyXFont::FONT_SIZE const def_size) const
414 if (pimpl_->fontlist.empty())
417 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
418 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
419 for (; end_it != end; ++end_it) {
420 if (end_it->pos() >= endpos)
427 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
428 for (; cit != end; ++cit) {
429 if (cit->pos() >= startpos)
433 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
434 for (; cit != end_it; ++cit) {
435 LyXFont::FONT_SIZE size = cit->font().size();
436 if (size == LyXFont::INHERIT_SIZE)
438 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
445 Paragraph::value_type
446 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
448 value_type c = getChar(pos);
449 if (!lyxrc.rtl_support)
479 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
486 void Paragraph::setFont(pos_type pos, LyXFont const & font)
488 Assert(pos <= size());
490 // First, reduce font against layout/label font
491 // Update: The SetCharFont() routine in text2.C already
492 // reduces font, so we don't need to do that here. (Asger)
493 // No need to simplify this because it will disappear
494 // in a new kernel. (Asger)
495 // Next search font table
497 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
498 Pimpl::FontList::iterator it = beg;
499 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
500 for (; it != endit; ++it) {
501 if (it->pos() >= pos)
504 unsigned int i = std::distance(beg, it);
505 bool notfound = (it == endit);
507 if (!notfound && pimpl_->fontlist[i].font() == font)
510 bool begin = pos == 0 || notfound ||
511 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
512 // Is position pos is a beginning of a font block?
513 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
514 // Is position pos is the end of a font block?
515 if (begin && end) { // A single char block
516 if (i + 1 < pimpl_->fontlist.size() &&
517 pimpl_->fontlist[i + 1].font() == font) {
518 // Merge the singleton block with the next block
519 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
520 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
521 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
522 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
523 // Merge the singleton block with the previous block
524 pimpl_->fontlist[i - 1].pos(pos);
525 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
527 pimpl_->fontlist[i].font(font);
529 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
530 pimpl_->fontlist[i - 1].pos(pos);
532 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
533 Pimpl::FontTable(pos, font));
535 pimpl_->fontlist[i].pos(pos - 1);
536 if (!(i + 1 < pimpl_->fontlist.size() &&
537 pimpl_->fontlist[i + 1].font() == font))
538 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
539 Pimpl::FontTable(pos, font));
540 } else { // The general case. The block is splitted into 3 blocks
541 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
542 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
543 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
544 Pimpl::FontTable(pos, font));
549 void Paragraph::makeSameLayout(Paragraph const & par)
551 layout(par.layout());
553 params() = par.params();
557 int Paragraph::stripLeadingSpaces()
563 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
564 pimpl_->eraseIntern(0);
572 bool Paragraph::hasSameLayout(Paragraph const & par) const
575 par.layout() == layout() &&
576 params().sameLayout(par.params());
580 Paragraph::depth_type Paragraph::getDepth() const
582 return params().depth();
586 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
588 if (layout()->isEnvironment())
589 return params().depth() + 1;
591 return params().depth();
595 char Paragraph::getAlign() const
597 return params().align();
601 string const & Paragraph::getLabelstring() const
603 return params().labelString();
607 // the next two functions are for the manual labels
608 string const Paragraph::getLabelWidthString() const
610 if (!params().labelWidthString().empty())
611 return params().labelWidthString();
613 return _("Senseless with this layout!");
617 void Paragraph::setLabelWidthString(string const & s)
619 params().labelWidthString(s);
623 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
626 params().labelWidthString(string());
627 params().align(LYX_ALIGN_LAYOUT);
628 params().spaceTop(VSpace(VSpace::NONE));
629 params().spaceBottom(VSpace(VSpace::NONE));
630 params().spacing(Spacing(Spacing::Default));
634 int Paragraph::beginningOfBody() const
636 if (layout()->labeltype != LABEL_MANUAL)
639 // Unroll the first two cycles of the loop
640 // and remember the previous character to
641 // remove unnecessary GetChar() calls
643 if (i < size() && !isNewline(i)) {
645 char previous_char = 0;
648 previous_char = getChar(i);
651 while (i < size() && previous_char != ' ') {
657 previous_char = temp;
667 // returns -1 if inset not found
668 int Paragraph::getPositionOfInset(InsetOld const * inset) const
671 InsetList::const_iterator it = insetlist.begin();
672 InsetList::const_iterator end = insetlist.end();
673 for (; it != end; ++it)
674 if (it->inset == inset)
680 InsetBibitem * Paragraph::bibitem() const
682 InsetList::const_iterator it = insetlist.begin();
683 if (it != insetlist.end() && it->inset->lyxCode() == InsetOld::BIBTEX_CODE)
684 return static_cast<InsetBibitem *>(it->inset);
690 // This could go to ParagraphParameters if we want to
691 int Paragraph::startTeXParParams(BufferParams const & bparams,
692 ostream & os, bool moving_arg) const
696 if (params().noindent()) {
701 switch (params().align()) {
703 case LYX_ALIGN_BLOCK:
704 case LYX_ALIGN_LAYOUT:
705 case LYX_ALIGN_SPECIAL:
708 case LYX_ALIGN_RIGHT:
709 case LYX_ALIGN_CENTER:
717 switch (params().align()) {
719 case LYX_ALIGN_BLOCK:
720 case LYX_ALIGN_LAYOUT:
721 case LYX_ALIGN_SPECIAL:
724 if (getParLanguage(bparams)->babel() != "hebrew") {
725 os << "\\begin{flushleft}";
728 os << "\\begin{flushright}";
732 case LYX_ALIGN_RIGHT:
733 if (getParLanguage(bparams)->babel() != "hebrew") {
734 os << "\\begin{flushright}";
737 os << "\\begin{flushleft}";
741 case LYX_ALIGN_CENTER:
742 os << "\\begin{center}";
751 // This could go to ParagraphParameters if we want to
752 int Paragraph::endTeXParParams(BufferParams const & bparams,
753 ostream & os, bool moving_arg) const
757 switch (params().align()) {
759 case LYX_ALIGN_BLOCK:
760 case LYX_ALIGN_LAYOUT:
761 case LYX_ALIGN_SPECIAL:
764 case LYX_ALIGN_RIGHT:
765 case LYX_ALIGN_CENTER:
773 switch (params().align()) {
775 case LYX_ALIGN_BLOCK:
776 case LYX_ALIGN_LAYOUT:
777 case LYX_ALIGN_SPECIAL:
780 if (getParLanguage(bparams)->babel() != "hebrew") {
781 os << "\\end{flushleft}";
784 os << "\\end{flushright}";
788 case LYX_ALIGN_RIGHT:
789 if (getParLanguage(bparams)->babel() != "hebrew") {
790 os << "\\end{flushright}";
793 os << "\\end{flushleft}";
797 case LYX_ALIGN_CENTER:
798 os << "\\end{center}";
806 // This one spits out the text of the paragraph
807 bool Paragraph::simpleTeXOnePar(Buffer const & buf,
808 BufferParams const & bparams,
809 LyXFont const & outerfont,
810 ostream & os, TexRow & texrow,
811 LatexRunParams const & runparams)
813 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
815 bool return_value = false;
819 // well we have to check if we are in an inset with unlimited
820 // lenght (all in one row) if that is true then we don't allow
821 // any special options in the paragraph and also we don't allow
822 // any environment other then "Standard" to be valid!
824 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
827 style = bparams.getLyXTextClass().defaultLayout();
834 // Maybe we have to create a optional argument.
837 // FIXME: can we actually skip this check and just call
838 // beginningOfBody() ??
839 if (style->labeltype != LABEL_MANUAL) {
842 body_pos = beginningOfBody();
845 unsigned int column = 0;
850 basefont = getLabelFont(bparams, outerfont);
852 basefont = getLayoutFont(bparams, outerfont);
855 bool moving_arg = runparams.moving_arg;
856 moving_arg |= style->needprotect;
858 // Which font is currently active?
859 LyXFont running_font(basefont);
860 // Do we have an open font change?
861 bool open_font = false;
863 Change::Type running_change = Change::UNCHANGED;
865 texrow.start(id(), 0);
867 // if the paragraph is empty, the loop will not be entered at all
869 if (style->isCommand()) {
874 column += startTeXParParams(bparams, os, moving_arg);
878 for (pos_type i = 0; i < size(); ++i) {
880 // First char in paragraph or after label?
884 column += running_font.latexWriteEndChanges(os, basefont, basefont);
887 basefont = getLayoutFont(bparams, outerfont);
888 running_font = basefont;
892 if (style->isCommand()) {
898 column += startTeXParParams(bparams, os,
902 value_type c = getChar(i);
904 // Fully instantiated font
905 LyXFont font = getFont(bparams, i, outerfont);
907 LyXFont const last_font = running_font;
909 // Spaces at end of font change are simulated to be
910 // outside font change, i.e. we write "\textXX{text} "
911 // rather than "\textXX{text }". (Asger)
912 if (open_font && c == ' ' && i <= size() - 2) {
913 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
914 if (next_font != running_font
915 && next_font != font) {
920 // We end font definition before blanks
922 (font != running_font ||
923 font.language() != running_font.language()))
925 column += running_font.latexWriteEndChanges(os,
927 (i == body_pos-1) ? basefont : font);
928 running_font = basefont;
932 // Blanks are printed before start of fontswitch
934 // Do not print the separation of the optional argument
935 if (i != body_pos - 1) {
936 pimpl_->simpleTeXBlanks(os, texrow, i,
937 column, font, *style);
941 // Do we need to change font?
942 if ((font != running_font ||
943 font.language() != running_font.language()) &&
946 column += font.latexWriteStartChanges(os, basefont,
952 Change::Type change = pimpl_->lookupChange(i);
954 column += Changes::latexMarkChange(os, running_change, change);
955 running_change = change;
957 LatexRunParams rp = runparams;
958 rp.moving_arg = moving_arg;
959 rp.free_spacing = style->free_spacing;
960 pimpl_->simpleTeXSpecialChars(buf, bparams,
961 os, texrow, runparams,
963 basefont, outerfont, open_font,
965 *style, i, column, c);
968 column += Changes::latexMarkChange(os,
969 running_change, Change::UNCHANGED);
971 // If we have an open font definition, we have to close it
973 #ifdef FIXED_LANGUAGE_END_DETECTION
976 .latexWriteEndChanges(os, basefont,
977 next_->getFont(bparams,
980 running_font.latexWriteEndChanges(os, basefont,
985 //#warning For now we ALWAYS have to close the foreign font settings if they are
986 //#warning there as we start another \selectlanguage with the next paragraph if
987 //#warning we are in need of this. This should be fixed sometime (Jug)
989 running_font.latexWriteEndChanges(os, basefont, basefont);
993 // Needed if there is an optional argument but no contents.
994 if (body_pos > 0 && body_pos == size()) {
996 return_value = false;
1000 column += endTeXParParams(bparams, os, moving_arg);
1003 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1004 return return_value;
1010 bool Paragraph::isHfill(pos_type pos) const
1012 return IsInsetChar(getChar(pos))
1013 && getInset(pos)->lyxCode() == InsetOld::HFILL_CODE;
1017 bool Paragraph::isInset(pos_type pos) const
1019 return IsInsetChar(getChar(pos));
1023 bool Paragraph::isNewline(pos_type pos) const
1025 return IsInsetChar(getChar(pos))
1026 && getInset(pos)->lyxCode() == InsetOld::NEWLINE_CODE;
1030 bool Paragraph::isSeparator(pos_type pos) const
1032 return IsSeparatorChar(getChar(pos));
1036 bool Paragraph::isLineSeparator(pos_type pos) const
1038 value_type const c = getChar(pos);
1039 return IsLineSeparatorChar(c)
1040 || (IsInsetChar(c) && getInset(pos) &&
1041 getInset(pos)->isLineSeparator());
1045 bool Paragraph::isKomma(pos_type pos) const
1047 return IsKommaChar(getChar(pos));
1051 /// Used by the spellchecker
1052 bool Paragraph::isLetter(pos_type pos) const
1054 value_type const c = getChar(pos);
1055 if (IsLetterChar(c))
1058 return getInset(pos)->isLetter();
1059 // We want to pass the ' and escape chars to ispell
1060 string const extra = lyxrc.isp_esc_chars + '\'';
1061 return contains(extra, c);
1065 bool Paragraph::isWord(pos_type pos) const
1067 return IsWordChar(getChar(pos)) ;
1072 Paragraph::getParLanguage(BufferParams const & bparams) const
1075 return getFirstFontSettings().language();
1076 #warning FIXME we should check the prev par as well (Lgb)
1077 return bparams.language;
1081 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1083 return lyxrc.rtl_support
1084 && getParLanguage(bparams)->RightToLeft()
1085 && !(inInset() && inInset()->owner() &&
1086 inInset()->owner()->lyxCode() == InsetOld::ERT_CODE);
1090 void Paragraph::changeLanguage(BufferParams const & bparams,
1091 Language const * from, Language const * to)
1093 for (pos_type i = 0; i < size(); ++i) {
1094 LyXFont font = getFontSettings(bparams, i);
1095 if (font.language() == from) {
1096 font.setLanguage(to);
1103 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1105 Language const * doc_language = bparams.language;
1106 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1107 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1109 for (; cit != end; ++cit)
1110 if (cit->font().language() != ignore_language &&
1111 cit->font().language() != latex_language &&
1112 cit->font().language() != doc_language)
1118 // Convert the paragraph to a string.
1119 // Used for building the table of contents
1120 string const Paragraph::asString(Buffer const & buffer, bool label) const
1124 if (label && !params().labelString().empty())
1125 s += params().labelString() + ' ';
1127 for (pos_type i = 0; i < size(); ++i) {
1128 value_type c = getChar(i);
1131 else if (c == META_INSET &&
1132 getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
1134 getInset(i)->ascii(buffer, ost);
1135 s += subst(STRCONV(ost.str()),'\n',' ');
1141 // This should really be done by the caller and not here.
1142 string ret(asString(buffer, 0, size(), label));
1143 return subst(ret, '\n', ' ');
1148 string const Paragraph::asString(Buffer const & buffer,
1149 pos_type beg, pos_type end, bool label) const
1153 if (beg == 0 && label && !params().labelString().empty())
1154 os << params().labelString() << ' ';
1156 for (pos_type i = beg; i < end; ++i) {
1157 value_type const c = getUChar(buffer.params, i);
1160 else if (c == META_INSET)
1161 getInset(i)->ascii(buffer, os);
1164 return STRCONV(os.str());
1168 void Paragraph::setInsetOwner(UpdatableInset * inset)
1170 pimpl_->inset_owner = inset;
1171 InsetList::iterator it = insetlist.begin();
1172 InsetList::iterator end = insetlist.end();
1173 for (; it != end; ++it)
1175 it->inset->setOwner(inset);
1179 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1181 insetlist.deleteInsetsLyXText(bv);
1185 void Paragraph::setContentsFromPar(Paragraph const & par)
1187 pimpl_->setContentsFromPar(par);
1191 void Paragraph::trackChanges(Change::Type type)
1193 pimpl_->trackChanges(type);
1197 void Paragraph::untrackChanges()
1199 pimpl_->untrackChanges();
1203 void Paragraph::cleanChanges()
1205 pimpl_->cleanChanges();
1209 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1211 Assert(!size() || pos < size());
1212 return pimpl_->lookupChange(pos);
1216 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1218 Assert(!size() || pos < size());
1219 return pimpl_->lookupChangeFull(pos);
1223 bool Paragraph::isChanged(pos_type start, pos_type end) const
1225 return pimpl_->isChanged(start, end);
1229 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1231 return pimpl_->isChangeEdited(start, end);
1235 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1237 pimpl_->setChange(pos, type);
1242 void Paragraph::markErased()
1244 pimpl_->markErased();
1248 void Paragraph::acceptChange(pos_type start, pos_type end)
1250 return pimpl_->acceptChange(start, end);
1254 void Paragraph::rejectChange(pos_type start, pos_type end)
1256 return pimpl_->rejectChange(start, end);
1260 lyx::pos_type Paragraph::size() const
1262 return pimpl_->size();
1266 bool Paragraph::empty() const
1268 return pimpl_->empty();
1272 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1274 return pimpl_->getChar(pos);
1278 int Paragraph::id() const
1284 void Paragraph::id(int i)
1290 LyXLayout_ptr const & Paragraph::layout() const
1293 InsetOld * inset = inInset();
1294 if (inset && inset->lyxCode() == InsetOld::ENVIRONMENT_CODE)
1295 return static_cast<InsetEnvironment*>(inset)->layout();
1301 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1303 layout_ = new_layout;
1307 UpdatableInset * Paragraph::inInset() const
1309 return pimpl_->inset_owner;
1313 void Paragraph::clearContents()
1318 void Paragraph::setChar(pos_type pos, value_type c)
1320 pimpl_->setChar(pos, c);
1324 ParagraphParameters & Paragraph::params()
1326 return pimpl_->params;
1330 ParagraphParameters const & Paragraph::params() const
1332 return pimpl_->params;
1336 bool Paragraph::isFreeSpacing() const
1338 if (layout()->free_spacing)
1341 // for now we just need this, later should we need this in some
1342 // other way we can always add a function to InsetOld too.
1343 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1344 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
1349 bool Paragraph::allowEmpty() const
1351 if (layout()->keepempty)
1353 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1354 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;