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"
35 #include "insets/insetbibitem.h"
36 #include "insets/insetoptarg.h"
38 #include "support/lstrings.h"
39 #include "support/textutils.h"
40 #include "support/std_sstream.h"
44 using lyx::support::contains;
45 using lyx::support::subst;
50 using std::ostringstream;
53 Paragraph::Paragraph()
54 : y(0), pimpl_(new Paragraph::Pimpl(this))
62 Paragraph::Paragraph(Paragraph const & lp)
63 : y(0), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
67 // this is because of the dummy layout of the paragraphs that
69 layout_ = lp.layout();
71 // copy everything behind the break-position to the new paragraph
72 insetlist = lp.insetlist;
73 InsetList::iterator it = insetlist.begin();
74 InsetList::iterator end = insetlist.end();
75 for (; it != end; ++it) {
76 // currently we hold Inset*, not InsetBase*
77 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
82 void Paragraph::operator=(Paragraph const & lp)
84 // needed as we will destroy the pimpl_ before copying it
88 lyxerr << "Paragraph::operator=()" << endl;
91 pimpl_ = new Pimpl(*lp.pimpl_, this);
93 enumdepth = lp.enumdepth;
94 itemdepth = lp.itemdepth;
95 // this is because of the dummy layout of the paragraphs that
97 layout_ = lp.layout();
99 // copy everything behind the break-position to the new paragraph
100 insetlist = lp.insetlist;
101 InsetList::iterator it = insetlist.begin();
102 InsetList::iterator end = insetlist.end();
103 for (; it != end; ++it) {
104 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
108 // the destructor removes the new paragraph from the list
109 Paragraph::~Paragraph()
113 //lyxerr << "Paragraph::paragraph_id = "
114 // << Paragraph::paragraph_id << endl;
118 void Paragraph::write(Buffer const & buf, ostream & os,
119 BufferParams const & bparams,
120 depth_type & dth) const
122 // The beginning or end of a deeper (i.e. nested) area?
123 if (dth != params().depth()) {
124 if (params().depth() > dth) {
125 while (params().depth() > dth) {
126 os << "\n\\begin_deeper ";
130 while (params().depth() < dth) {
131 os << "\n\\end_deeper ";
137 // First write the layout
138 os << "\n\\begin_layout " << layout()->name() << '\n';
142 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
144 Change running_change = Change(Change::UNCHANGED);
145 lyx::time_type const curtime(lyx::current_time());
148 for (pos_type i = 0; i < size(); ++i) {
154 Change change = pimpl_->lookupChangeFull(i);
155 Changes::lyxMarkChange(os, column, curtime, running_change, change);
156 running_change = change;
158 // Write font changes
159 LyXFont font2 = getFontSettings(bparams, i);
160 if (font2 != font1) {
161 font2.lyxWriteChanges(font1, os);
166 value_type const c = getChar(i);
170 InsetOld const * inset = getInset(i);
172 if (inset->directWrite()) {
173 // international char, let it write
174 // code directly so it's shorter in
176 inset->write(buf, os);
178 os << "\n\\begin_inset ";
179 inset->write(buf, os);
180 os << "\n\\end_inset \n\n";
186 os << "\n\\backslash \n";
190 if (i + 1 < size() && getChar(i + 1) == ' ') {
197 if ((column > 70 && c == ' ')
202 // this check is to amend a bug. LyX sometimes
203 // inserts '\0' this could cause problems.
207 lyxerr << "ERROR (Paragraph::writeFile):"
208 " NULL char in structure." << endl;
214 // to make reading work properly
216 running_change = pimpl_->lookupChange(0);
217 Changes::lyxMarkChange(os, column, curtime,
218 Change(Change::UNCHANGED), running_change);
220 Changes::lyxMarkChange(os, column, curtime,
221 running_change, Change(Change::UNCHANGED));
223 os << "\n\\end_layout\n";
227 void Paragraph::validate(LaTeXFeatures & features) const
229 pimpl_->validate(features, *layout());
233 void Paragraph::eraseIntern(lyx::pos_type pos)
235 pimpl_->eraseIntern(pos);
239 bool Paragraph::erase(pos_type pos)
241 return pimpl_->erase(pos);
245 int Paragraph::erase(pos_type start, pos_type end)
247 return pimpl_->erase(start, end);
251 bool Paragraph::checkInsertChar(LyXFont & font)
253 if (pimpl_->inset_owner)
254 return pimpl_->inset_owner->checkInsertChar(font);
259 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
261 insertChar(pos, c, LyXFont(LyXFont::ALL_INHERIT));
265 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
266 LyXFont const & font, Change change)
268 pimpl_->insertChar(pos, c, font, change);
272 void Paragraph::insertInset(pos_type pos, InsetOld * inset)
274 insertInset(pos, inset, LyXFont(LyXFont::ALL_INHERIT));
278 void Paragraph::insertInset(pos_type pos, InsetOld * inset,
279 LyXFont const & font, Change change)
281 pimpl_->insertInset(pos, inset, font, change);
285 bool Paragraph::insetAllowed(InsetOld::Code code)
287 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
288 if (pimpl_->inset_owner)
289 return pimpl_->inset_owner->insetAllowed(code);
294 InsetOld * Paragraph::getInset(pos_type pos)
296 BOOST_ASSERT(pos < size());
297 return insetlist.get(pos);
301 InsetOld const * Paragraph::getInset(pos_type pos) const
303 BOOST_ASSERT(pos < size());
304 return insetlist.get(pos);
308 // Gets uninstantiated font setting at position.
309 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
312 BOOST_ASSERT(pos <= size());
314 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
315 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
316 for (; cit != end; ++cit)
317 if (cit->pos() >= pos)
323 if (pos == size() && !empty())
324 return getFontSettings(bparams, pos - 1);
326 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
330 lyx::pos_type Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const
332 BOOST_ASSERT(pos <= size());
334 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
335 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
336 for (; cit != end; ++cit)
337 if (cit->pos() >= pos)
340 // This should not happen, but if so, we take no chances.
341 //lyxerr << "Paragraph::getEndPosOfFontSpan: This should not happen!"
347 // Gets uninstantiated font setting at position 0
348 LyXFont const Paragraph::getFirstFontSettings() const
350 if (!empty() && !pimpl_->fontlist.empty())
351 return pimpl_->fontlist[0].font();
353 return LyXFont(LyXFont::ALL_INHERIT);
357 // Gets the fully instantiated font at a given position in a paragraph
358 // This is basically the same function as LyXText::GetFont() in text2.C.
359 // The difference is that this one is used for generating the LaTeX file,
360 // and thus cosmetic "improvements" are disallowed: This has to deliver
361 // the true picture of the buffer. (Asger)
362 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
363 LyXFont const & outerfont) const
365 BOOST_ASSERT(pos >= 0);
367 LyXLayout_ptr const & lout = layout();
369 pos_type const body_pos = beginningOfBody();
373 layoutfont = lout->labelfont;
375 layoutfont = lout->font;
377 LyXFont tmpfont = getFontSettings(bparams, pos);
378 tmpfont.realize(layoutfont);
379 tmpfont.realize(outerfont);
380 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
386 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
387 LyXFont const & outerfont) const
389 LyXFont tmpfont = layout()->labelfont;
390 tmpfont.setLanguage(getParLanguage(bparams));
391 tmpfont.realize(outerfont);
392 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
397 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
398 LyXFont const & outerfont) const
400 LyXFont tmpfont = layout()->font;
401 tmpfont.setLanguage(getParLanguage(bparams));
402 tmpfont.realize(outerfont);
403 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
408 /// Returns the height of the highest font in range
410 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
411 LyXFont::FONT_SIZE const def_size) const
413 if (pimpl_->fontlist.empty())
416 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
417 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
418 for (; end_it != end; ++end_it) {
419 if (end_it->pos() >= endpos)
426 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
427 for (; cit != end; ++cit) {
428 if (cit->pos() >= startpos)
432 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
433 for (; cit != end_it; ++cit) {
434 LyXFont::FONT_SIZE size = cit->font().size();
435 if (size == LyXFont::INHERIT_SIZE)
437 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
444 Paragraph::value_type
445 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
447 value_type c = getChar(pos);
448 if (!lyxrc.rtl_support)
478 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
485 void Paragraph::setFont(pos_type pos, LyXFont const & font)
487 BOOST_ASSERT(pos <= size());
489 // First, reduce font against layout/label font
490 // Update: The SetCharFont() routine in text2.C already
491 // reduces font, so we don't need to do that here. (Asger)
492 // No need to simplify this because it will disappear
493 // in a new kernel. (Asger)
494 // Next search font table
496 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
497 Pimpl::FontList::iterator it = beg;
498 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
499 for (; it != endit; ++it) {
500 if (it->pos() >= pos)
503 unsigned int i = std::distance(beg, it);
504 bool notfound = (it == endit);
506 if (!notfound && pimpl_->fontlist[i].font() == font)
509 bool begin = pos == 0 || notfound ||
510 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
511 // Is position pos is a beginning of a font block?
512 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
513 // Is position pos is the end of a font block?
514 if (begin && end) { // A single char block
515 if (i + 1 < pimpl_->fontlist.size() &&
516 pimpl_->fontlist[i + 1].font() == font) {
517 // Merge the singleton block with the next block
518 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
519 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
520 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
521 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
522 // Merge the singleton block with the previous block
523 pimpl_->fontlist[i - 1].pos(pos);
524 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
526 pimpl_->fontlist[i].font(font);
528 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
529 pimpl_->fontlist[i - 1].pos(pos);
531 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
532 Pimpl::FontTable(pos, font));
534 pimpl_->fontlist[i].pos(pos - 1);
535 if (!(i + 1 < pimpl_->fontlist.size() &&
536 pimpl_->fontlist[i + 1].font() == font))
537 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
538 Pimpl::FontTable(pos, font));
539 } else { // The general case. The block is splitted into 3 blocks
540 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
541 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
542 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
543 Pimpl::FontTable(pos, font));
548 void Paragraph::makeSameLayout(Paragraph const & par)
550 layout(par.layout());
552 params() = par.params();
556 int Paragraph::stripLeadingSpaces()
562 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
563 pimpl_->eraseIntern(0);
571 bool Paragraph::hasSameLayout(Paragraph const & par) const
574 par.layout() == layout() &&
575 params().sameLayout(par.params());
579 Paragraph::depth_type Paragraph::getDepth() const
581 return params().depth();
585 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
587 if (layout()->isEnvironment())
588 return params().depth() + 1;
590 return params().depth();
594 char Paragraph::getAlign() const
596 return params().align();
600 string const & Paragraph::getLabelstring() const
602 return params().labelString();
606 // the next two functions are for the manual labels
607 string const Paragraph::getLabelWidthString() const
609 if (!params().labelWidthString().empty())
610 return params().labelWidthString();
612 return _("Senseless with this layout!");
616 void Paragraph::setLabelWidthString(string const & s)
618 params().labelWidthString(s);
622 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
625 params().labelWidthString(string());
626 params().align(LYX_ALIGN_LAYOUT);
627 params().spaceTop(VSpace(VSpace::NONE));
628 params().spaceBottom(VSpace(VSpace::NONE));
629 params().spacing(Spacing(Spacing::Default));
633 int Paragraph::beginningOfBody() const
635 if (layout()->labeltype != LABEL_MANUAL)
638 // Unroll the first two cycles of the loop
639 // and remember the previous character to
640 // remove unnecessary GetChar() calls
642 if (i < size() && !isNewline(i)) {
644 char previous_char = 0;
647 previous_char = getChar(i);
650 while (i < size() && previous_char != ' ') {
656 previous_char = temp;
666 // returns -1 if inset not found
667 int Paragraph::getPositionOfInset(InsetOld const * inset) const
670 InsetList::const_iterator it = insetlist.begin();
671 InsetList::const_iterator end = insetlist.end();
672 for (; it != end; ++it)
673 if (it->inset == inset)
679 InsetBibitem * Paragraph::bibitem() const
681 InsetList::const_iterator it = insetlist.begin();
682 if (it != insetlist.end() && it->inset->lyxCode() == InsetOld::BIBTEX_CODE)
683 return static_cast<InsetBibitem *>(it->inset);
689 // This could go to ParagraphParameters if we want to
690 int Paragraph::startTeXParParams(BufferParams const & bparams,
691 ostream & os, bool moving_arg) const
695 if (params().noindent()) {
700 switch (params().align()) {
702 case LYX_ALIGN_BLOCK:
703 case LYX_ALIGN_LAYOUT:
704 case LYX_ALIGN_SPECIAL:
707 case LYX_ALIGN_RIGHT:
708 case LYX_ALIGN_CENTER:
716 switch (params().align()) {
718 case LYX_ALIGN_BLOCK:
719 case LYX_ALIGN_LAYOUT:
720 case LYX_ALIGN_SPECIAL:
723 if (getParLanguage(bparams)->babel() != "hebrew") {
724 os << "\\begin{flushleft}";
727 os << "\\begin{flushright}";
731 case LYX_ALIGN_RIGHT:
732 if (getParLanguage(bparams)->babel() != "hebrew") {
733 os << "\\begin{flushright}";
736 os << "\\begin{flushleft}";
740 case LYX_ALIGN_CENTER:
741 os << "\\begin{center}";
750 // This could go to ParagraphParameters if we want to
751 int Paragraph::endTeXParParams(BufferParams const & bparams,
752 ostream & os, bool moving_arg) const
756 switch (params().align()) {
758 case LYX_ALIGN_BLOCK:
759 case LYX_ALIGN_LAYOUT:
760 case LYX_ALIGN_SPECIAL:
763 case LYX_ALIGN_RIGHT:
764 case LYX_ALIGN_CENTER:
772 switch (params().align()) {
774 case LYX_ALIGN_BLOCK:
775 case LYX_ALIGN_LAYOUT:
776 case LYX_ALIGN_SPECIAL:
779 if (getParLanguage(bparams)->babel() != "hebrew") {
780 os << "\\end{flushleft}";
783 os << "\\end{flushright}";
787 case LYX_ALIGN_RIGHT:
788 if (getParLanguage(bparams)->babel() != "hebrew") {
789 os << "\\end{flushright}";
792 os << "\\end{flushleft}";
796 case LYX_ALIGN_CENTER:
797 os << "\\end{center}";
805 // This one spits out the text of the paragraph
806 bool Paragraph::simpleTeXOnePar(Buffer const & buf,
807 BufferParams const & bparams,
808 LyXFont const & outerfont,
809 ostream & os, TexRow & texrow,
810 LatexRunParams const & runparams)
812 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
814 bool return_value = false;
818 // well we have to check if we are in an inset with unlimited
819 // lenght (all in one row) if that is true then we don't allow
820 // any special options in the paragraph and also we don't allow
821 // any environment other then "Standard" to be valid!
823 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
826 style = bparams.getLyXTextClass().defaultLayout();
833 // Maybe we have to create a optional argument.
836 // FIXME: can we actually skip this check and just call
837 // beginningOfBody() ??
838 if (style->labeltype != LABEL_MANUAL) {
841 body_pos = beginningOfBody();
844 unsigned int column = 0;
849 basefont = getLabelFont(bparams, outerfont);
851 basefont = getLayoutFont(bparams, outerfont);
854 bool moving_arg = runparams.moving_arg;
855 moving_arg |= style->needprotect;
857 // Which font is currently active?
858 LyXFont running_font(basefont);
859 // Do we have an open font change?
860 bool open_font = false;
862 Change::Type running_change = Change::UNCHANGED;
864 texrow.start(id(), 0);
866 // if the paragraph is empty, the loop will not be entered at all
868 if (style->isCommand()) {
873 column += startTeXParParams(bparams, os, moving_arg);
877 for (pos_type i = 0; i < size(); ++i) {
879 // First char in paragraph or after label?
883 column += running_font.latexWriteEndChanges(os, basefont, basefont);
886 basefont = getLayoutFont(bparams, outerfont);
887 running_font = basefont;
891 if (style->isCommand()) {
897 column += startTeXParParams(bparams, os,
901 value_type c = getChar(i);
903 // Fully instantiated font
904 LyXFont font = getFont(bparams, i, outerfont);
906 LyXFont const last_font = running_font;
908 // Spaces at end of font change are simulated to be
909 // outside font change, i.e. we write "\textXX{text} "
910 // rather than "\textXX{text }". (Asger)
911 if (open_font && c == ' ' && i <= size() - 2) {
912 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
913 if (next_font != running_font
914 && next_font != font) {
919 // We end font definition before blanks
921 (font != running_font ||
922 font.language() != running_font.language()))
924 column += running_font.latexWriteEndChanges(os,
926 (i == body_pos-1) ? basefont : font);
927 running_font = basefont;
931 // Blanks are printed before start of fontswitch
933 // Do not print the separation of the optional argument
934 if (i != body_pos - 1) {
935 pimpl_->simpleTeXBlanks(os, texrow, i,
936 column, font, *style);
940 // Do we need to change font?
941 if ((font != running_font ||
942 font.language() != running_font.language()) &&
945 column += font.latexWriteStartChanges(os, basefont,
951 Change::Type change = pimpl_->lookupChange(i);
953 column += Changes::latexMarkChange(os, running_change, change);
954 running_change = change;
956 LatexRunParams rp = runparams;
957 rp.moving_arg = moving_arg;
958 rp.free_spacing = style->free_spacing;
959 pimpl_->simpleTeXSpecialChars(buf, bparams,
960 os, texrow, runparams,
962 basefont, outerfont, open_font,
964 *style, i, column, c);
967 column += Changes::latexMarkChange(os,
968 running_change, Change::UNCHANGED);
970 // If we have an open font definition, we have to close it
972 #ifdef FIXED_LANGUAGE_END_DETECTION
975 .latexWriteEndChanges(os, basefont,
976 next_->getFont(bparams,
979 running_font.latexWriteEndChanges(os, basefont,
984 //#warning For now we ALWAYS have to close the foreign font settings if they are
985 //#warning there as we start another \selectlanguage with the next paragraph if
986 //#warning we are in need of this. This should be fixed sometime (Jug)
988 running_font.latexWriteEndChanges(os, basefont, basefont);
992 // Needed if there is an optional argument but no contents.
993 if (body_pos > 0 && body_pos == size()) {
995 return_value = false;
999 column += endTeXParParams(bparams, os, moving_arg);
1002 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1003 return return_value;
1009 bool Paragraph::isHfill(pos_type pos) const
1011 return IsInsetChar(getChar(pos))
1012 && getInset(pos)->lyxCode() == InsetOld::HFILL_CODE;
1016 bool Paragraph::isInset(pos_type pos) const
1018 return IsInsetChar(getChar(pos));
1022 bool Paragraph::isNewline(pos_type pos) const
1024 return IsInsetChar(getChar(pos))
1025 && getInset(pos)->lyxCode() == InsetOld::NEWLINE_CODE;
1029 bool Paragraph::isSeparator(pos_type pos) const
1031 return IsSeparatorChar(getChar(pos));
1035 bool Paragraph::isLineSeparator(pos_type pos) const
1037 value_type const c = getChar(pos);
1038 return IsLineSeparatorChar(c)
1039 || (IsInsetChar(c) && getInset(pos) &&
1040 getInset(pos)->isLineSeparator());
1044 bool Paragraph::isKomma(pos_type pos) const
1046 return IsKommaChar(getChar(pos));
1050 /// Used by the spellchecker
1051 bool Paragraph::isLetter(pos_type pos) const
1053 value_type const c = getChar(pos);
1054 if (IsLetterChar(c))
1057 return getInset(pos)->isLetter();
1058 // We want to pass the ' and escape chars to ispell
1059 string const extra = lyxrc.isp_esc_chars + '\'';
1060 return contains(extra, c);
1064 bool Paragraph::isWord(pos_type pos) const
1066 return IsWordChar(getChar(pos)) ;
1071 Paragraph::getParLanguage(BufferParams const & bparams) const
1074 return getFirstFontSettings().language();
1075 #warning FIXME we should check the prev par as well (Lgb)
1076 return bparams.language;
1080 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1082 return lyxrc.rtl_support
1083 && getParLanguage(bparams)->RightToLeft()
1084 && !(inInset() && inInset()->owner() &&
1085 inInset()->owner()->lyxCode() == InsetOld::ERT_CODE);
1089 void Paragraph::changeLanguage(BufferParams const & bparams,
1090 Language const * from, Language const * to)
1092 for (pos_type i = 0; i < size(); ++i) {
1093 LyXFont font = getFontSettings(bparams, i);
1094 if (font.language() == from) {
1095 font.setLanguage(to);
1102 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1104 Language const * doc_language = bparams.language;
1105 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1106 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1108 for (; cit != end; ++cit)
1109 if (cit->font().language() != ignore_language &&
1110 cit->font().language() != latex_language &&
1111 cit->font().language() != doc_language)
1117 // Convert the paragraph to a string.
1118 // Used for building the table of contents
1119 string const Paragraph::asString(Buffer const & buffer, bool label) const
1123 if (label && !params().labelString().empty())
1124 s += params().labelString() + ' ';
1126 for (pos_type i = 0; i < size(); ++i) {
1127 value_type c = getChar(i);
1130 else if (c == META_INSET &&
1131 getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
1133 getInset(i)->ascii(buffer, ost);
1134 s += subst(STRCONV(ost.str()),'\n',' ');
1140 // This should really be done by the caller and not here.
1141 string ret(asString(buffer, 0, size(), label));
1142 return subst(ret, '\n', ' ');
1147 string const Paragraph::asString(Buffer const & buffer,
1148 pos_type beg, pos_type end, bool label) const
1152 if (beg == 0 && label && !params().labelString().empty())
1153 os << params().labelString() << ' ';
1155 for (pos_type i = beg; i < end; ++i) {
1156 value_type const c = getUChar(buffer.params(), i);
1159 else if (c == META_INSET)
1160 getInset(i)->ascii(buffer, os);
1167 void Paragraph::setInsetOwner(UpdatableInset * inset)
1169 pimpl_->inset_owner = inset;
1170 InsetList::iterator it = insetlist.begin();
1171 InsetList::iterator end = insetlist.end();
1172 for (; it != end; ++it)
1174 it->inset->setOwner(inset);
1178 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1180 insetlist.deleteInsetsLyXText(bv);
1184 void Paragraph::setContentsFromPar(Paragraph const & par)
1186 pimpl_->setContentsFromPar(par);
1190 void Paragraph::trackChanges(Change::Type type)
1192 pimpl_->trackChanges(type);
1196 void Paragraph::untrackChanges()
1198 pimpl_->untrackChanges();
1202 void Paragraph::cleanChanges()
1204 pimpl_->cleanChanges();
1208 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1210 BOOST_ASSERT(!size() || pos < size());
1211 return pimpl_->lookupChange(pos);
1215 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1217 BOOST_ASSERT(!size() || pos < size());
1218 return pimpl_->lookupChangeFull(pos);
1222 bool Paragraph::isChanged(pos_type start, pos_type end) const
1224 return pimpl_->isChanged(start, end);
1228 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1230 return pimpl_->isChangeEdited(start, end);
1234 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1236 pimpl_->setChange(pos, type);
1241 void Paragraph::markErased()
1243 pimpl_->markErased();
1247 void Paragraph::acceptChange(pos_type start, pos_type end)
1249 return pimpl_->acceptChange(start, end);
1253 void Paragraph::rejectChange(pos_type start, pos_type end)
1255 return pimpl_->rejectChange(start, end);
1259 lyx::pos_type Paragraph::size() const
1261 return pimpl_->size();
1265 bool Paragraph::empty() const
1267 return pimpl_->empty();
1271 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1273 return pimpl_->getChar(pos);
1277 int Paragraph::id() const
1283 void Paragraph::id(int i)
1289 LyXLayout_ptr const & Paragraph::layout() const
1292 InsetOld * inset = inInset();
1293 if (inset && inset->lyxCode() == InsetOld::ENVIRONMENT_CODE)
1294 return static_cast<InsetEnvironment*>(inset)->layout();
1300 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1302 layout_ = new_layout;
1306 UpdatableInset * Paragraph::inInset() const
1308 return pimpl_->inset_owner;
1312 void Paragraph::clearContents()
1317 void Paragraph::setChar(pos_type pos, value_type c)
1319 pimpl_->setChar(pos, c);
1323 ParagraphParameters & Paragraph::params()
1325 return pimpl_->params;
1329 ParagraphParameters const & Paragraph::params() const
1331 return pimpl_->params;
1335 bool Paragraph::isFreeSpacing() const
1337 if (layout()->free_spacing)
1340 // for now we just need this, later should we need this in some
1341 // other way we can always add a function to InsetOld too.
1342 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1343 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
1348 bool Paragraph::allowEmpty() const
1350 if (layout()->keepempty)
1352 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1353 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;