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"
25 #include "BufferView.h"
31 #include "latexrunparams.h"
34 #include "paragraph_funcs.h"
35 #include "ParameterStruct.h"
40 #include "insets/insetbibitem.h"
41 #include "insets/insetoptarg.h"
42 #include "insets/insetenv.h"
44 #include "support/filetools.h"
45 #include "support/lstrings.h"
46 #include "support/lyxmanip.h"
47 #include "support/FileInfo.h"
48 #include "support/LAssert.h"
49 #include "support/textutils.h"
56 using namespace lyx::support;
62 using std::lower_bound;
63 using std::upper_bound;
68 Paragraph::Paragraph()
69 : y(0), pimpl_(new Paragraph::Pimpl(this))
77 Paragraph::Paragraph(Paragraph const & lp)
78 : y(0), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
82 // this is because of the dummy layout of the paragraphs that
84 layout_ = lp.layout();
86 // copy everything behind the break-position to the new paragraph
87 insetlist = lp.insetlist;
88 InsetList::iterator it = insetlist.begin();
89 InsetList::iterator end = insetlist.end();
90 for (; it != end; ++it) {
91 // currently we hold Inset*, not InsetBase*
92 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
97 void Paragraph::operator=(Paragraph const & lp)
99 // needed as we will destroy the pimpl_ before copying it
103 lyxerr << "Paragraph::operator=()" << endl;
106 pimpl_ = new Pimpl(*lp.pimpl_, this);
108 enumdepth = lp.enumdepth;
109 itemdepth = lp.itemdepth;
110 // this is because of the dummy layout of the paragraphs that
112 layout_ = lp.layout();
114 // copy everything behind the break-position to the new paragraph
115 insetlist = lp.insetlist;
116 InsetList::iterator it = insetlist.begin();
117 InsetList::iterator end = insetlist.end();
118 for (; it != end; ++it) {
119 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
123 // the destructor removes the new paragraph from the list
124 Paragraph::~Paragraph()
128 //lyxerr << "Paragraph::paragraph_id = "
129 // << Paragraph::paragraph_id << endl;
133 void Paragraph::write(Buffer const * buf, ostream & os,
134 BufferParams const & bparams,
135 depth_type & dth) const
137 // The beginning or end of a deeper (i.e. nested) area?
138 if (dth != params().depth()) {
139 if (params().depth() > dth) {
140 while (params().depth() > dth) {
141 os << "\n\\begin_deeper ";
145 while (params().depth() < dth) {
146 os << "\n\\end_deeper ";
152 // First write the layout
153 os << "\n\\begin_layout " << layout()->name() << '\n';
157 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
159 Change running_change = Change(Change::UNCHANGED);
160 lyx::time_type const curtime(lyx::current_time());
163 for (pos_type i = 0; i < size(); ++i) {
169 Change change = pimpl_->lookupChangeFull(i);
170 Changes::lyxMarkChange(os, column, curtime, running_change, change);
171 running_change = change;
173 // Write font changes
174 LyXFont font2 = getFontSettings(bparams, i);
175 if (font2 != font1) {
176 font2.lyxWriteChanges(font1, os);
181 value_type const c = getChar(i);
185 InsetOld const * inset = getInset(i);
187 if (inset->directWrite()) {
188 // international char, let it write
189 // code directly so it's shorter in
191 inset->write(buf, os);
193 os << "\n\\begin_inset ";
194 inset->write(buf, os);
195 os << "\n\\end_inset \n\n";
201 os << "\n\\backslash \n";
205 if (i + 1 < size() && getChar(i + 1) == ' ') {
212 if ((column > 70 && c == ' ')
217 // this check is to amend a bug. LyX sometimes
218 // inserts '\0' this could cause problems.
222 lyxerr << "ERROR (Paragraph::writeFile):"
223 " NULL char in structure." << endl;
229 // to make reading work properly
231 running_change = pimpl_->lookupChange(0);
232 Changes::lyxMarkChange(os, column, curtime,
233 Change(Change::UNCHANGED), running_change);
235 Changes::lyxMarkChange(os, column, curtime,
236 running_change, Change(Change::UNCHANGED));
238 os << "\n\\end_layout\n";
242 void Paragraph::validate(LaTeXFeatures & features) const
244 pimpl_->validate(features, *layout());
248 void Paragraph::eraseIntern(lyx::pos_type pos)
250 pimpl_->eraseIntern(pos);
254 bool Paragraph::erase(pos_type pos)
256 return pimpl_->erase(pos);
260 int Paragraph::erase(pos_type start, pos_type end)
262 return pimpl_->erase(start, end);
266 bool Paragraph::checkInsertChar(LyXFont & font)
268 if (pimpl_->inset_owner)
269 return pimpl_->inset_owner->checkInsertChar(font);
274 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
276 insertChar(pos, c, LyXFont(LyXFont::ALL_INHERIT));
280 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
281 LyXFont const & font, Change change)
283 pimpl_->insertChar(pos, c, font, change);
287 void Paragraph::insertInset(pos_type pos, InsetOld * inset)
289 insertInset(pos, inset, LyXFont(LyXFont::ALL_INHERIT));
293 void Paragraph::insertInset(pos_type pos, InsetOld * inset,
294 LyXFont const & font, Change change)
296 pimpl_->insertInset(pos, inset, font, change);
300 bool Paragraph::insetAllowed(InsetOld::Code code)
302 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
303 if (pimpl_->inset_owner)
304 return pimpl_->inset_owner->insetAllowed(code);
309 InsetOld * Paragraph::getInset(pos_type pos)
311 Assert(pos < size());
312 return insetlist.get(pos);
316 InsetOld const * Paragraph::getInset(pos_type pos) const
318 Assert(pos < size());
319 return insetlist.get(pos);
323 // Gets uninstantiated font setting at position.
324 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
327 Assert(pos <= size());
329 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
330 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
331 for (; cit != end; ++cit)
332 if (cit->pos() >= pos)
338 if (pos == size() && !empty())
339 return getFontSettings(bparams, pos - 1);
341 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
345 lyx::pos_type Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const
347 Assert(pos <= size());
349 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
350 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
351 for (; cit != end; ++cit)
352 if (cit->pos() >= pos)
355 // This should not happen, but if so, we take no chances.
356 //lyxerr << "Paragraph::getEndPosOfFontSpan: This should not happen!"
362 // Gets uninstantiated font setting at position 0
363 LyXFont const Paragraph::getFirstFontSettings() const
365 if (!empty() && !pimpl_->fontlist.empty())
366 return pimpl_->fontlist[0].font();
368 return LyXFont(LyXFont::ALL_INHERIT);
372 // Gets the fully instantiated font at a given position in a paragraph
373 // This is basically the same function as LyXText::GetFont() in text2.C.
374 // The difference is that this one is used for generating the LaTeX file,
375 // and thus cosmetic "improvements" are disallowed: This has to deliver
376 // the true picture of the buffer. (Asger)
377 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
378 LyXFont const & outerfont) const
382 LyXLayout_ptr const & lout = layout();
384 pos_type const body_pos = beginningOfBody();
388 layoutfont = lout->labelfont;
390 layoutfont = lout->font;
392 LyXFont tmpfont = getFontSettings(bparams, pos);
393 tmpfont.realize(layoutfont);
394 tmpfont.realize(outerfont);
395 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
401 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
402 LyXFont const & outerfont) const
404 LyXFont tmpfont = layout()->labelfont;
405 tmpfont.setLanguage(getParLanguage(bparams));
406 tmpfont.realize(outerfont);
407 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
412 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
413 LyXFont const & outerfont) const
415 LyXFont tmpfont = layout()->font;
416 tmpfont.setLanguage(getParLanguage(bparams));
417 tmpfont.realize(outerfont);
418 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
423 /// Returns the height of the highest font in range
425 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
426 LyXFont::FONT_SIZE const def_size) const
428 if (pimpl_->fontlist.empty())
431 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
432 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
433 for (; end_it != end; ++end_it) {
434 if (end_it->pos() >= endpos)
441 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
442 for (; cit != end; ++cit) {
443 if (cit->pos() >= startpos)
447 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
448 for (; cit != end_it; ++cit) {
449 LyXFont::FONT_SIZE size = cit->font().size();
450 if (size == LyXFont::INHERIT_SIZE)
452 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
459 Paragraph::value_type
460 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
462 value_type c = getChar(pos);
463 if (!lyxrc.rtl_support)
493 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
500 void Paragraph::setFont(pos_type pos, LyXFont const & font)
502 Assert(pos <= size());
504 // First, reduce font against layout/label font
505 // Update: The SetCharFont() routine in text2.C already
506 // reduces font, so we don't need to do that here. (Asger)
507 // No need to simplify this because it will disappear
508 // in a new kernel. (Asger)
509 // Next search font table
511 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
512 Pimpl::FontList::iterator it = beg;
513 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
514 for (; it != endit; ++it) {
515 if (it->pos() >= pos)
518 unsigned int i = std::distance(beg, it);
519 bool notfound = (it == endit);
521 if (!notfound && pimpl_->fontlist[i].font() == font)
524 bool begin = pos == 0 || notfound ||
525 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
526 // Is position pos is a beginning of a font block?
527 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
528 // Is position pos is the end of a font block?
529 if (begin && end) { // A single char block
530 if (i + 1 < pimpl_->fontlist.size() &&
531 pimpl_->fontlist[i + 1].font() == font) {
532 // Merge the singleton block with the next block
533 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
534 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
535 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
536 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
537 // Merge the singleton block with the previous block
538 pimpl_->fontlist[i - 1].pos(pos);
539 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
541 pimpl_->fontlist[i].font(font);
543 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
544 pimpl_->fontlist[i - 1].pos(pos);
546 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
547 Pimpl::FontTable(pos, font));
549 pimpl_->fontlist[i].pos(pos - 1);
550 if (!(i + 1 < pimpl_->fontlist.size() &&
551 pimpl_->fontlist[i + 1].font() == font))
552 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
553 Pimpl::FontTable(pos, font));
554 } else { // The general case. The block is splitted into 3 blocks
555 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
556 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
557 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
558 Pimpl::FontTable(pos, font));
563 void Paragraph::makeSameLayout(Paragraph const & par)
565 layout(par.layout());
567 params() = par.params();
571 int Paragraph::stripLeadingSpaces()
577 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
578 pimpl_->eraseIntern(0);
586 bool Paragraph::hasSameLayout(Paragraph const & par) const
589 par.layout() == layout() &&
590 params().sameLayout(par.params());
594 Paragraph::depth_type Paragraph::getDepth() const
596 return params().depth();
600 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
602 if (layout()->isEnvironment())
603 return params().depth() + 1;
605 return params().depth();
609 char Paragraph::getAlign() const
611 return params().align();
615 string const & Paragraph::getLabelstring() const
617 return params().labelString();
621 // the next two functions are for the manual labels
622 string const Paragraph::getLabelWidthString() const
624 if (!params().labelWidthString().empty())
625 return params().labelWidthString();
627 return _("Senseless with this layout!");
631 void Paragraph::setLabelWidthString(string const & s)
633 params().labelWidthString(s);
637 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
640 params().labelWidthString(string());
641 params().align(LYX_ALIGN_LAYOUT);
642 params().spaceTop(VSpace(VSpace::NONE));
643 params().spaceBottom(VSpace(VSpace::NONE));
644 params().spacing(Spacing(Spacing::Default));
648 int Paragraph::beginningOfBody() const
650 if (layout()->labeltype != LABEL_MANUAL)
653 // Unroll the first two cycles of the loop
654 // and remember the previous character to
655 // remove unnecessary GetChar() calls
657 if (i < size() && !isNewline(i)) {
659 char previous_char = 0;
662 previous_char = getChar(i);
665 while (i < size() && previous_char != ' ') {
671 previous_char = temp;
681 // returns -1 if inset not found
682 int Paragraph::getPositionOfInset(InsetOld const * inset) const
685 InsetList::const_iterator it = insetlist.begin();
686 InsetList::const_iterator end = insetlist.end();
687 for (; it != end; ++it)
688 if (it->inset == inset)
694 InsetBibitem * Paragraph::bibitem() const
696 InsetList::const_iterator it = insetlist.begin();
697 if (it != insetlist.end() && it->inset->lyxCode() == InsetOld::BIBTEX_CODE)
698 return static_cast<InsetBibitem *>(it->inset);
704 // This could go to ParagraphParameters if we want to
705 int Paragraph::startTeXParParams(BufferParams const & bparams,
706 ostream & os, bool moving_arg) const
710 if (params().noindent()) {
715 switch (params().align()) {
717 case LYX_ALIGN_BLOCK:
718 case LYX_ALIGN_LAYOUT:
719 case LYX_ALIGN_SPECIAL:
722 case LYX_ALIGN_RIGHT:
723 case LYX_ALIGN_CENTER:
731 switch (params().align()) {
733 case LYX_ALIGN_BLOCK:
734 case LYX_ALIGN_LAYOUT:
735 case LYX_ALIGN_SPECIAL:
738 if (getParLanguage(bparams)->babel() != "hebrew") {
739 os << "\\begin{flushleft}";
742 os << "\\begin{flushright}";
746 case LYX_ALIGN_RIGHT:
747 if (getParLanguage(bparams)->babel() != "hebrew") {
748 os << "\\begin{flushright}";
751 os << "\\begin{flushleft}";
755 case LYX_ALIGN_CENTER:
756 os << "\\begin{center}";
765 // This could go to ParagraphParameters if we want to
766 int Paragraph::endTeXParParams(BufferParams const & bparams,
767 ostream & os, bool moving_arg) const
771 switch (params().align()) {
773 case LYX_ALIGN_BLOCK:
774 case LYX_ALIGN_LAYOUT:
775 case LYX_ALIGN_SPECIAL:
778 case LYX_ALIGN_RIGHT:
779 case LYX_ALIGN_CENTER:
787 switch (params().align()) {
789 case LYX_ALIGN_BLOCK:
790 case LYX_ALIGN_LAYOUT:
791 case LYX_ALIGN_SPECIAL:
794 if (getParLanguage(bparams)->babel() != "hebrew") {
795 os << "\\end{flushleft}";
798 os << "\\end{flushright}";
802 case LYX_ALIGN_RIGHT:
803 if (getParLanguage(bparams)->babel() != "hebrew") {
804 os << "\\end{flushright}";
807 os << "\\end{flushleft}";
811 case LYX_ALIGN_CENTER:
812 os << "\\end{center}";
820 // This one spits out the text of the paragraph
821 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
822 BufferParams const & bparams,
823 LyXFont const & outerfont,
824 ostream & os, TexRow & texrow,
825 LatexRunParams const & runparams)
827 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
829 bool return_value = false;
833 // well we have to check if we are in an inset with unlimited
834 // lenght (all in one row) if that is true then we don't allow
835 // any special options in the paragraph and also we don't allow
836 // any environment other then "Standard" to be valid!
838 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
841 style = bparams.getLyXTextClass().defaultLayout();
848 // Maybe we have to create a optional argument.
851 // FIXME: can we actually skip this check and just call
852 // beginningOfBody() ??
853 if (style->labeltype != LABEL_MANUAL) {
856 body_pos = beginningOfBody();
859 unsigned int column = 0;
864 basefont = getLabelFont(bparams, outerfont);
866 basefont = getLayoutFont(bparams, outerfont);
869 bool moving_arg = runparams.moving_arg;
870 moving_arg |= style->needprotect;
872 // Which font is currently active?
873 LyXFont running_font(basefont);
874 // Do we have an open font change?
875 bool open_font = false;
877 Change::Type running_change = Change::UNCHANGED;
879 texrow.start(id(), 0);
881 // if the paragraph is empty, the loop will not be entered at all
883 if (style->isCommand()) {
888 column += startTeXParParams(bparams, os, moving_arg);
892 for (pos_type i = 0; i < size(); ++i) {
894 // First char in paragraph or after label?
898 column += running_font.latexWriteEndChanges(os, basefont, basefont);
901 basefont = getLayoutFont(bparams, outerfont);
902 running_font = basefont;
906 if (style->isCommand()) {
912 column += startTeXParParams(bparams, os,
916 value_type c = getChar(i);
918 // Fully instantiated font
919 LyXFont font = getFont(bparams, i, outerfont);
921 LyXFont const last_font = running_font;
923 // Spaces at end of font change are simulated to be
924 // outside font change, i.e. we write "\textXX{text} "
925 // rather than "\textXX{text }". (Asger)
926 if (open_font && c == ' ' && i <= size() - 2) {
927 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
928 if (next_font != running_font
929 && next_font != font) {
934 // We end font definition before blanks
936 (font != running_font ||
937 font.language() != running_font.language()))
939 column += running_font.latexWriteEndChanges(os,
941 (i == body_pos-1) ? basefont : font);
942 running_font = basefont;
946 // Blanks are printed before start of fontswitch
948 // Do not print the separation of the optional argument
949 if (i != body_pos - 1) {
950 pimpl_->simpleTeXBlanks(os, texrow, i,
951 column, font, *style);
955 // Do we need to change font?
956 if ((font != running_font ||
957 font.language() != running_font.language()) &&
960 column += font.latexWriteStartChanges(os, basefont,
966 Change::Type change = pimpl_->lookupChange(i);
968 column += Changes::latexMarkChange(os, running_change, change);
969 running_change = change;
971 LatexRunParams rp = runparams;
972 rp.moving_arg = moving_arg;
973 rp.free_spacing = style->free_spacing;
974 pimpl_->simpleTeXSpecialChars(buf, bparams,
975 os, texrow, runparams,
977 basefont, outerfont, open_font,
979 *style, i, column, c);
982 column += Changes::latexMarkChange(os,
983 running_change, Change::UNCHANGED);
985 // If we have an open font definition, we have to close it
987 #ifdef FIXED_LANGUAGE_END_DETECTION
990 .latexWriteEndChanges(os, basefont,
991 next_->getFont(bparams,
994 running_font.latexWriteEndChanges(os, basefont,
999 //#warning For now we ALWAYS have to close the foreign font settings if they are
1000 //#warning there as we start another \selectlanguage with the next paragraph if
1001 //#warning we are in need of this. This should be fixed sometime (Jug)
1003 running_font.latexWriteEndChanges(os, basefont, basefont);
1007 // Needed if there is an optional argument but no contents.
1008 if (body_pos > 0 && body_pos == size()) {
1010 return_value = false;
1014 column += endTeXParParams(bparams, os, moving_arg);
1017 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1018 return return_value;
1024 bool Paragraph::isHfill(pos_type pos) const
1026 return IsInsetChar(getChar(pos))
1027 && getInset(pos)->lyxCode() == InsetOld::HFILL_CODE;
1031 bool Paragraph::isInset(pos_type pos) const
1033 return IsInsetChar(getChar(pos));
1037 bool Paragraph::isNewline(pos_type pos) const
1039 return IsInsetChar(getChar(pos))
1040 && getInset(pos)->lyxCode() == InsetOld::NEWLINE_CODE;
1044 bool Paragraph::isSeparator(pos_type pos) const
1046 return IsSeparatorChar(getChar(pos));
1050 bool Paragraph::isLineSeparator(pos_type pos) const
1052 value_type const c = getChar(pos);
1053 return IsLineSeparatorChar(c)
1054 || (IsInsetChar(c) && getInset(pos) &&
1055 getInset(pos)->isLineSeparator());
1059 bool Paragraph::isKomma(pos_type pos) const
1061 return IsKommaChar(getChar(pos));
1065 /// Used by the spellchecker
1066 bool Paragraph::isLetter(pos_type pos) const
1068 value_type const c = getChar(pos);
1069 if (IsLetterChar(c))
1072 return getInset(pos)->isLetter();
1073 // We want to pass the ' and escape chars to ispell
1074 string const extra = lyxrc.isp_esc_chars + '\'';
1075 return contains(extra, c);
1079 bool Paragraph::isWord(pos_type pos) const
1081 return IsWordChar(getChar(pos)) ;
1086 Paragraph::getParLanguage(BufferParams const & bparams) const
1089 return getFirstFontSettings().language();
1090 #warning FIXME we should check the prev par as well (Lgb)
1091 return bparams.language;
1095 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1097 return lyxrc.rtl_support
1098 && getParLanguage(bparams)->RightToLeft()
1099 && !(inInset() && inInset()->owner() &&
1100 inInset()->owner()->lyxCode() == InsetOld::ERT_CODE);
1104 void Paragraph::changeLanguage(BufferParams const & bparams,
1105 Language const * from, Language const * to)
1107 for (pos_type i = 0; i < size(); ++i) {
1108 LyXFont font = getFontSettings(bparams, i);
1109 if (font.language() == from) {
1110 font.setLanguage(to);
1117 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1119 Language const * doc_language = bparams.language;
1120 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1121 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1123 for (; cit != end; ++cit)
1124 if (cit->font().language() != ignore_language &&
1125 cit->font().language() != latex_language &&
1126 cit->font().language() != doc_language)
1132 // Convert the paragraph to a string.
1133 // Used for building the table of contents
1134 string const Paragraph::asString(Buffer const * buffer, bool label) const
1138 if (label && !params().labelString().empty())
1139 s += params().labelString() + ' ';
1141 for (pos_type i = 0; i < size(); ++i) {
1142 value_type c = getChar(i);
1145 else if (c == META_INSET &&
1146 getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
1148 getInset(i)->ascii(buffer, ost);
1149 s += subst(STRCONV(ost.str()),'\n',' ');
1155 // This should really be done by the caller and not here.
1156 string ret(asString(buffer, 0, size(), label));
1157 return subst(ret, '\n', ' ');
1162 string const Paragraph::asString(Buffer const * buffer,
1163 pos_type beg, pos_type end, bool label) const
1167 if (beg == 0 && label && !params().labelString().empty())
1168 os << params().labelString() << ' ';
1170 for (pos_type i = beg; i < end; ++i) {
1171 value_type const c = getUChar(buffer->params, i);
1174 else if (c == META_INSET)
1175 getInset(i)->ascii(buffer, os);
1178 return STRCONV(os.str());
1182 void Paragraph::setInsetOwner(UpdatableInset * inset)
1184 pimpl_->inset_owner = inset;
1185 InsetList::iterator it = insetlist.begin();
1186 InsetList::iterator end = insetlist.end();
1187 for (; it != end; ++it)
1189 it->inset->setOwner(inset);
1193 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1195 insetlist.deleteInsetsLyXText(bv);
1199 void Paragraph::setContentsFromPar(Paragraph const & par)
1201 pimpl_->setContentsFromPar(par);
1205 void Paragraph::trackChanges(Change::Type type)
1207 pimpl_->trackChanges(type);
1211 void Paragraph::untrackChanges()
1213 pimpl_->untrackChanges();
1217 void Paragraph::cleanChanges()
1219 pimpl_->cleanChanges();
1223 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1225 Assert(!size() || pos < size());
1226 return pimpl_->lookupChange(pos);
1230 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1232 Assert(!size() || pos < size());
1233 return pimpl_->lookupChangeFull(pos);
1237 bool Paragraph::isChanged(pos_type start, pos_type end) const
1239 return pimpl_->isChanged(start, end);
1243 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1245 return pimpl_->isChangeEdited(start, end);
1249 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1251 pimpl_->setChange(pos, type);
1256 void Paragraph::markErased()
1258 pimpl_->markErased();
1262 void Paragraph::acceptChange(pos_type start, pos_type end)
1264 return pimpl_->acceptChange(start, end);
1268 void Paragraph::rejectChange(pos_type start, pos_type end)
1270 return pimpl_->rejectChange(start, end);
1274 lyx::pos_type Paragraph::size() const
1276 return pimpl_->size();
1280 bool Paragraph::empty() const
1282 return pimpl_->empty();
1286 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1288 return pimpl_->getChar(pos);
1292 int Paragraph::id() const
1298 void Paragraph::id(int i)
1304 LyXLayout_ptr const & Paragraph::layout() const
1307 InsetOld * inset = inInset();
1308 if (inset && inset->lyxCode() == InsetOld::ENVIRONMENT_CODE)
1309 return static_cast<InsetEnvironment*>(inset)->layout();
1315 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1317 layout_ = new_layout;
1321 UpdatableInset * Paragraph::inInset() const
1323 return pimpl_->inset_owner;
1327 void Paragraph::clearContents()
1332 void Paragraph::setChar(pos_type pos, value_type c)
1334 pimpl_->setChar(pos, c);
1338 ParagraphParameters & Paragraph::params()
1340 return pimpl_->params;
1344 ParagraphParameters const & Paragraph::params() const
1346 return pimpl_->params;
1350 bool Paragraph::isFreeSpacing() const
1352 if (layout()->free_spacing)
1355 // for now we just need this, later should we need this in some
1356 // other way we can always add a function to InsetOld too.
1357 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1358 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
1363 bool Paragraph::allowEmpty() const
1365 if (layout()->keepempty)
1367 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1368 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;