1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
13 #include "paragraph.h"
14 #include "paragraph_pimpl.h"
17 #include "bufferparams.h"
18 #include "BufferView.h"
24 #include "latexrunparams.h"
27 #include "paragraph_funcs.h"
28 #include "ParameterStruct.h"
33 #include "insets/insetbibitem.h"
34 #include "insets/insetoptarg.h"
35 #include "insets/insetenv.h"
37 #include "support/filetools.h"
38 #include "support/lstrings.h"
39 #include "support/lyxmanip.h"
40 #include "support/FileInfo.h"
41 #include "support/LAssert.h"
42 #include "support/textutils.h"
49 using namespace lyx::support;
55 using std::lower_bound;
56 using std::upper_bound;
61 Paragraph::Paragraph()
62 : pimpl_(new Paragraph::Pimpl(this))
70 Paragraph::Paragraph(Paragraph const & lp)
71 : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
75 // this is because of the dummy layout of the paragraphs that
77 layout_ = lp.layout();
79 // copy everything behind the break-position to the new paragraph
80 insetlist = lp.insetlist;
81 InsetList::iterator it = insetlist.begin();
82 InsetList::iterator end = insetlist.end();
83 for (; it != end; ++it) {
84 // currently we hold Inset*, not InsetBase*
85 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
86 // tell the new inset who is the boss now
87 it->inset->parOwner(this);
92 void Paragraph::operator=(Paragraph const & lp)
94 // needed as we will destroy the pimpl_ before copying it
97 lyxerr << "Paragraph::operator=()\n";
99 pimpl_ = new Pimpl(*lp.pimpl_, this);
101 enumdepth = lp.enumdepth;
102 itemdepth = lp.itemdepth;
103 // this is because of the dummy layout of the paragraphs that
105 layout_ = lp.layout();
107 // copy everything behind the break-position to the new paragraph
108 insetlist = lp.insetlist;
109 InsetList::iterator it = insetlist.begin();
110 InsetList::iterator end = insetlist.end();
111 for (; it != end; ++it) {
112 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
113 // tell the new inset who is the boss now
114 it->inset->parOwner(this);
118 // the destructor removes the new paragraph from the list
119 Paragraph::~Paragraph()
123 //lyxerr << "Paragraph::paragraph_id = "
124 // << Paragraph::paragraph_id << endl;
128 void Paragraph::write(Buffer const * buf, ostream & os,
129 BufferParams const & bparams,
130 depth_type & dth) const
132 // The beginning or end of a deeper (i.e. nested) area?
133 if (dth != params().depth()) {
134 if (params().depth() > dth) {
135 while (params().depth() > dth) {
136 os << "\n\\begin_deeper ";
140 while (params().depth() < dth) {
141 os << "\n\\end_deeper ";
147 // First write the layout
148 os << "\n\\begin_layout " << layout()->name() << '\n';
152 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
154 Change running_change = Change(Change::UNCHANGED);
155 lyx::time_type const curtime(lyx::current_time());
158 for (pos_type i = 0; i < size(); ++i) {
164 Change change = pimpl_->lookupChangeFull(i);
165 Changes::lyxMarkChange(os, column, curtime, running_change, change);
166 running_change = change;
168 // Write font changes
169 LyXFont font2 = getFontSettings(bparams, i);
170 if (font2 != font1) {
171 font2.lyxWriteChanges(font1, os);
176 value_type const c = getChar(i);
180 InsetOld const * inset = getInset(i);
182 if (inset->directWrite()) {
183 // international char, let it write
184 // code directly so it's shorter in
186 inset->write(buf, os);
188 os << "\n\\begin_inset ";
189 inset->write(buf, os);
190 os << "\n\\end_inset \n\n";
196 os << "\n\\backslash \n";
200 if (i + 1 < size() && getChar(i + 1) == ' ') {
207 if ((column > 70 && c == ' ')
212 // this check is to amend a bug. LyX sometimes
213 // inserts '\0' this could cause problems.
217 lyxerr << "ERROR (Paragraph::writeFile):"
218 " NULL char in structure." << endl;
224 // to make reading work properly
226 running_change = pimpl_->lookupChange(0);
227 Changes::lyxMarkChange(os, column, curtime,
228 Change(Change::UNCHANGED), running_change);
230 Changes::lyxMarkChange(os, column, curtime,
231 running_change, Change(Change::UNCHANGED));
233 os << "\n\\end_layout\n";
237 void Paragraph::validate(LaTeXFeatures & features) const
239 pimpl_->validate(features, *layout());
243 void Paragraph::eraseIntern(lyx::pos_type pos)
245 pimpl_->eraseIntern(pos);
249 bool Paragraph::erase(pos_type pos)
251 return pimpl_->erase(pos);
255 int Paragraph::erase(pos_type start, pos_type end)
257 return pimpl_->erase(start, end);
261 bool Paragraph::checkInsertChar(LyXFont & font)
263 if (pimpl_->inset_owner)
264 return pimpl_->inset_owner->checkInsertChar(font);
269 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
271 insertChar(pos, c, LyXFont(LyXFont::ALL_INHERIT));
275 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
276 LyXFont const & font, Change change)
278 pimpl_->insertChar(pos, c, font, change);
282 void Paragraph::insertInset(pos_type pos, InsetOld * inset)
284 insertInset(pos, inset, LyXFont(LyXFont::ALL_INHERIT));
288 void Paragraph::insertInset(pos_type pos, InsetOld * inset, LyXFont const & font, Change change)
290 pimpl_->insertInset(pos, inset, font, change);
294 bool Paragraph::insetAllowed(InsetOld::Code code)
296 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
297 if (pimpl_->inset_owner)
298 return pimpl_->inset_owner->insetAllowed(code);
303 InsetOld * Paragraph::getInset(pos_type pos)
305 Assert(pos < size());
306 return insetlist.get(pos);
310 InsetOld const * Paragraph::getInset(pos_type pos) const
312 Assert(pos < size());
313 return insetlist.get(pos);
317 // Gets uninstantiated font setting at position.
318 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
321 Assert(pos <= size());
323 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
324 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
325 for (; cit != end; ++cit)
326 if (cit->pos() >= pos)
332 if (pos == size() && !empty())
333 return getFontSettings(bparams, pos - 1);
335 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
339 lyx::pos_type Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const
341 Assert(pos <= size());
343 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
344 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
345 for (; cit != end; ++cit)
346 if (cit->pos() >= pos)
349 // This should not happen, but if so, we take no chances.
350 lyxerr << "Pararaph::getEndPosOfFontSpan: This should not happen!\n";
355 // Gets uninstantiated font setting at position 0
356 LyXFont const Paragraph::getFirstFontSettings() const
358 if (!empty() && !pimpl_->fontlist.empty())
359 return pimpl_->fontlist[0].font();
361 return LyXFont(LyXFont::ALL_INHERIT);
365 // Gets the fully instantiated font at a given position in a paragraph
366 // This is basically the same function as LyXText::GetFont() in text2.C.
367 // The difference is that this one is used for generating the LaTeX file,
368 // and thus cosmetic "improvements" are disallowed: This has to deliver
369 // the true picture of the buffer. (Asger)
370 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
371 LyXFont const & outerfont) const
375 LyXLayout_ptr const & lout = layout();
377 pos_type const body_pos = beginningOfBody();
381 layoutfont = lout->labelfont;
383 layoutfont = lout->font;
385 LyXFont tmpfont = getFontSettings(bparams, pos);
386 tmpfont.realize(layoutfont);
387 tmpfont.realize(outerfont);
388 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
394 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
395 LyXFont const & outerfont) const
397 LyXFont tmpfont = layout()->labelfont;
398 tmpfont.setLanguage(getParLanguage(bparams));
399 tmpfont.realize(outerfont);
400 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
405 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
406 LyXFont const & outerfont) const
408 LyXFont tmpfont = layout()->font;
409 tmpfont.setLanguage(getParLanguage(bparams));
410 tmpfont.realize(outerfont);
411 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
416 /// Returns the height of the highest font in range
418 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
419 LyXFont::FONT_SIZE const def_size) const
421 if (pimpl_->fontlist.empty())
424 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
425 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
426 for (; end_it != end; ++end_it) {
427 if (end_it->pos() >= endpos)
434 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
435 for (; cit != end; ++cit) {
436 if (cit->pos() >= startpos)
440 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
441 for (; cit != end_it; ++cit) {
442 LyXFont::FONT_SIZE size = cit->font().size();
443 if (size == LyXFont::INHERIT_SIZE)
445 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
452 Paragraph::value_type
453 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
455 value_type c = getChar(pos);
456 if (!lyxrc.rtl_support)
486 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
493 void Paragraph::setFont(pos_type pos, LyXFont const & font)
495 Assert(pos <= size());
497 // First, reduce font against layout/label font
498 // Update: The SetCharFont() routine in text2.C already
499 // reduces font, so we don't need to do that here. (Asger)
500 // No need to simplify this because it will disappear
501 // in a new kernel. (Asger)
502 // Next search font table
504 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
505 Pimpl::FontList::iterator it = beg;
506 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
507 for (; it != endit; ++it) {
508 if (it->pos() >= pos)
511 unsigned int i = std::distance(beg, it);
512 bool notfound = (it == endit);
514 if (!notfound && pimpl_->fontlist[i].font() == font)
517 bool begin = pos == 0 || notfound ||
518 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
519 // Is position pos is a beginning of a font block?
520 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
521 // Is position pos is the end of a font block?
522 if (begin && end) { // A single char block
523 if (i + 1 < pimpl_->fontlist.size() &&
524 pimpl_->fontlist[i + 1].font() == font) {
525 // Merge the singleton block with the next block
526 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
527 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
528 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
529 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
530 // Merge the singleton block with the previous block
531 pimpl_->fontlist[i - 1].pos(pos);
532 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
534 pimpl_->fontlist[i].font(font);
536 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
537 pimpl_->fontlist[i - 1].pos(pos);
539 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
540 Pimpl::FontTable(pos, font));
542 pimpl_->fontlist[i].pos(pos - 1);
543 if (!(i + 1 < pimpl_->fontlist.size() &&
544 pimpl_->fontlist[i + 1].font() == font))
545 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
546 Pimpl::FontTable(pos, font));
547 } else { // The general case. The block is splitted into 3 blocks
548 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
549 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
550 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
551 Pimpl::FontTable(pos, font));
556 void Paragraph::makeSameLayout(Paragraph const & par)
558 layout(par.layout());
560 params() = par.params();
564 int Paragraph::stripLeadingSpaces()
570 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
571 pimpl_->eraseIntern(0);
579 bool Paragraph::hasSameLayout(Paragraph const & par) const
582 par.layout() == layout() &&
583 params().sameLayout(par.params());
587 Paragraph::depth_type Paragraph::getDepth() const
589 return params().depth();
593 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
595 if (layout()->isEnvironment())
596 return params().depth() + 1;
598 return params().depth();
602 char Paragraph::getAlign() const
604 return params().align();
608 string const & Paragraph::getLabelstring() const
610 return params().labelString();
614 // the next two functions are for the manual labels
615 string const Paragraph::getLabelWidthString() const
617 if (!params().labelWidthString().empty())
618 return params().labelWidthString();
620 return _("Senseless with this layout!");
624 void Paragraph::setLabelWidthString(string const & s)
626 params().labelWidthString(s);
630 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
633 params().labelWidthString(string());
634 params().align(LYX_ALIGN_LAYOUT);
635 params().spaceTop(VSpace(VSpace::NONE));
636 params().spaceBottom(VSpace(VSpace::NONE));
637 params().spacing(Spacing(Spacing::Default));
641 int Paragraph::beginningOfBody() const
643 if (layout()->labeltype != LABEL_MANUAL)
646 // Unroll the first two cycles of the loop
647 // and remember the previous character to
648 // remove unnecessary GetChar() calls
650 if (i < size() && !isNewline(i)) {
652 char previous_char = 0;
655 previous_char = getChar(i);
658 while (i < size() && previous_char != ' ') {
664 previous_char = temp;
674 // returns -1 if inset not found
675 int Paragraph::getPositionOfInset(InsetOld const * inset) const
678 InsetList::const_iterator it = insetlist.begin();
679 InsetList::const_iterator end = insetlist.end();
680 for (; it != end; ++it)
681 if (it->inset == inset)
687 InsetBibitem * Paragraph::bibitem() const
689 InsetList::const_iterator it = insetlist.begin();
690 if (it != insetlist.end() && it->inset->lyxCode() == InsetOld::BIBTEX_CODE)
691 return static_cast<InsetBibitem *>(it->inset);
697 // This could go to ParagraphParameters if we want to
698 int Paragraph::startTeXParParams(BufferParams const & bparams,
699 ostream & os, bool moving_arg) const
703 if (params().noindent()) {
708 switch (params().align()) {
710 case LYX_ALIGN_BLOCK:
711 case LYX_ALIGN_LAYOUT:
712 case LYX_ALIGN_SPECIAL:
715 case LYX_ALIGN_RIGHT:
716 case LYX_ALIGN_CENTER:
724 switch (params().align()) {
726 case LYX_ALIGN_BLOCK:
727 case LYX_ALIGN_LAYOUT:
728 case LYX_ALIGN_SPECIAL:
731 if (getParLanguage(bparams)->babel() != "hebrew") {
732 os << "\\begin{flushleft}";
735 os << "\\begin{flushright}";
739 case LYX_ALIGN_RIGHT:
740 if (getParLanguage(bparams)->babel() != "hebrew") {
741 os << "\\begin{flushright}";
744 os << "\\begin{flushleft}";
748 case LYX_ALIGN_CENTER:
749 os << "\\begin{center}";
758 // This could go to ParagraphParameters if we want to
759 int Paragraph::endTeXParParams(BufferParams const & bparams,
760 ostream & os, bool moving_arg) const
764 switch (params().align()) {
766 case LYX_ALIGN_BLOCK:
767 case LYX_ALIGN_LAYOUT:
768 case LYX_ALIGN_SPECIAL:
771 case LYX_ALIGN_RIGHT:
772 case LYX_ALIGN_CENTER:
780 switch (params().align()) {
782 case LYX_ALIGN_BLOCK:
783 case LYX_ALIGN_LAYOUT:
784 case LYX_ALIGN_SPECIAL:
787 if (getParLanguage(bparams)->babel() != "hebrew") {
788 os << "\\end{flushleft}";
791 os << "\\end{flushright}";
795 case LYX_ALIGN_RIGHT:
796 if (getParLanguage(bparams)->babel() != "hebrew") {
797 os << "\\end{flushright}";
800 os << "\\end{flushleft}";
804 case LYX_ALIGN_CENTER:
805 os << "\\end{center}";
813 // This one spits out the text of the paragraph
814 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
815 BufferParams const & bparams,
816 LyXFont const & outerfont,
817 ostream & os, TexRow & texrow,
818 LatexRunParams const & runparams)
820 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
822 bool return_value = false;
826 // well we have to check if we are in an inset with unlimited
827 // lenght (all in one row) if that is true then we don't allow
828 // any special options in the paragraph and also we don't allow
829 // any environment other then "Standard" to be valid!
831 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
834 style = bparams.getLyXTextClass().defaultLayout();
841 // Maybe we have to create a optional argument.
844 // FIXME: can we actually skip this check and just call
845 // beginningOfBody() ??
846 if (style->labeltype != LABEL_MANUAL) {
849 body_pos = beginningOfBody();
852 unsigned int column = 0;
857 basefont = getLabelFont(bparams, outerfont);
859 basefont = getLayoutFont(bparams, outerfont);
862 bool moving_arg = runparams.moving_arg;
863 moving_arg |= style->needprotect;
865 // Which font is currently active?
866 LyXFont running_font(basefont);
867 // Do we have an open font change?
868 bool open_font = false;
870 Change::Type running_change = Change::UNCHANGED;
872 texrow.start(id(), 0);
874 // if the paragraph is empty, the loop will not be entered at all
876 if (style->isCommand()) {
881 column += startTeXParParams(bparams, os, moving_arg);
885 for (pos_type i = 0; i < size(); ++i) {
887 // First char in paragraph or after label?
891 column += running_font.latexWriteEndChanges(os, basefont, basefont);
894 basefont = getLayoutFont(bparams, outerfont);
895 running_font = basefont;
899 if (style->isCommand()) {
905 column += startTeXParParams(bparams, os,
909 value_type c = getChar(i);
911 // Fully instantiated font
912 LyXFont font = getFont(bparams, i, outerfont);
914 LyXFont const last_font = running_font;
916 // Spaces at end of font change are simulated to be
917 // outside font change, i.e. we write "\textXX{text} "
918 // rather than "\textXX{text }". (Asger)
919 if (open_font && c == ' ' && i <= size() - 2) {
920 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
921 if (next_font != running_font
922 && next_font != font) {
927 // We end font definition before blanks
929 (font != running_font ||
930 font.language() != running_font.language()))
932 column += running_font.latexWriteEndChanges(os,
934 (i == body_pos-1) ? basefont : font);
935 running_font = basefont;
939 // Blanks are printed before start of fontswitch
941 // Do not print the separation of the optional argument
942 if (i != body_pos - 1) {
943 pimpl_->simpleTeXBlanks(os, texrow, i,
944 column, font, *style);
948 // Do we need to change font?
949 if ((font != running_font ||
950 font.language() != running_font.language()) &&
953 column += font.latexWriteStartChanges(os, basefont,
959 Change::Type change = pimpl_->lookupChange(i);
961 column += Changes::latexMarkChange(os, running_change, change);
962 running_change = change;
964 LatexRunParams rp = runparams;
965 rp.moving_arg = moving_arg;
966 rp.free_spacing = style->free_spacing;
967 pimpl_->simpleTeXSpecialChars(buf, bparams,
968 os, texrow, runparams,
970 basefont, outerfont, open_font,
972 *style, i, column, c);
975 column += Changes::latexMarkChange(os,
976 running_change, Change::UNCHANGED);
978 // If we have an open font definition, we have to close it
980 #ifdef FIXED_LANGUAGE_END_DETECTION
983 .latexWriteEndChanges(os, basefont,
984 next_->getFont(bparams,
987 running_font.latexWriteEndChanges(os, basefont,
992 //#warning For now we ALWAYS have to close the foreign font settings if they are
993 //#warning there as we start another \selectlanguage with the next paragraph if
994 //#warning we are in need of this. This should be fixed sometime (Jug)
996 running_font.latexWriteEndChanges(os, basefont, basefont);
1000 // Needed if there is an optional argument but no contents.
1001 if (body_pos > 0 && body_pos == size()) {
1003 return_value = false;
1007 column += endTeXParParams(bparams, os, moving_arg);
1010 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1011 return return_value;
1017 bool Paragraph::isHfill(pos_type pos) const
1019 return IsInsetChar(getChar(pos))
1020 && getInset(pos)->lyxCode() == InsetOld::HFILL_CODE;
1024 bool Paragraph::isInset(pos_type pos) const
1026 return IsInsetChar(getChar(pos));
1030 bool Paragraph::isNewline(pos_type pos) const
1032 return IsInsetChar(getChar(pos))
1033 && getInset(pos)->lyxCode() == InsetOld::NEWLINE_CODE;
1037 bool Paragraph::isSeparator(pos_type pos) const
1039 return IsSeparatorChar(getChar(pos));
1043 bool Paragraph::isLineSeparator(pos_type pos) const
1045 value_type const c = getChar(pos);
1046 return IsLineSeparatorChar(c)
1047 || (IsInsetChar(c) && getInset(pos) &&
1048 getInset(pos)->isLineSeparator());
1052 bool Paragraph::isKomma(pos_type pos) const
1054 return IsKommaChar(getChar(pos));
1058 /// Used by the spellchecker
1059 bool Paragraph::isLetter(pos_type pos) const
1061 value_type const c = getChar(pos);
1062 if (IsLetterChar(c))
1065 return getInset(pos)->isLetter();
1066 // We want to pass the ' and escape chars to ispell
1067 string const extra = lyxrc.isp_esc_chars + '\'';
1068 return contains(extra, c);
1072 bool Paragraph::isWord(pos_type pos) const
1074 return IsWordChar(getChar(pos)) ;
1079 Paragraph::getParLanguage(BufferParams const & bparams) const
1082 return getFirstFontSettings().language();
1083 #warning FIXME we should check the prev par as well (Lgb)
1084 return bparams.language;
1088 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1090 return lyxrc.rtl_support
1091 && getParLanguage(bparams)->RightToLeft()
1092 && !(inInset() && inInset()->owner() &&
1093 inInset()->owner()->lyxCode() == InsetOld::ERT_CODE);
1097 void Paragraph::changeLanguage(BufferParams const & bparams,
1098 Language const * from, Language const * to)
1100 for (pos_type i = 0; i < size(); ++i) {
1101 LyXFont font = getFontSettings(bparams, i);
1102 if (font.language() == from) {
1103 font.setLanguage(to);
1110 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1112 Language const * doc_language = bparams.language;
1113 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1114 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1116 for (; cit != end; ++cit)
1117 if (cit->font().language() != ignore_language &&
1118 cit->font().language() != latex_language &&
1119 cit->font().language() != doc_language)
1125 // Convert the paragraph to a string.
1126 // Used for building the table of contents
1127 string const Paragraph::asString(Buffer const * buffer, bool label) const
1131 if (label && !params().labelString().empty())
1132 s += params().labelString() + ' ';
1134 for (pos_type i = 0; i < size(); ++i) {
1135 value_type c = getChar(i);
1138 else if (c == META_INSET &&
1139 getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
1141 getInset(i)->ascii(buffer, ost);
1142 s += subst(STRCONV(ost.str()),'\n',' ');
1148 // This should really be done by the caller and not here.
1149 string ret(asString(buffer, 0, size(), label));
1150 return subst(ret, '\n', ' ');
1155 string const Paragraph::asString(Buffer const * buffer,
1156 pos_type beg, pos_type end, bool label) const
1160 if (beg == 0 && label && !params().labelString().empty())
1161 os << params().labelString() << ' ';
1163 for (pos_type i = beg; i < end; ++i) {
1164 value_type const c = getUChar(buffer->params, i);
1167 else if (c == META_INSET)
1168 getInset(i)->ascii(buffer, os);
1171 return STRCONV(os.str());
1175 void Paragraph::setInsetOwner(UpdatableInset * inset)
1177 pimpl_->inset_owner = inset;
1178 InsetList::iterator it = insetlist.begin();
1179 InsetList::iterator end = insetlist.end();
1180 for (; it != end; ++it)
1182 it->inset->setOwner(inset);
1186 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1188 insetlist.deleteInsetsLyXText(bv);
1192 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1194 insetlist.resizeInsetsLyXText(bv);
1198 void Paragraph::setContentsFromPar(Paragraph const & par)
1200 pimpl_->setContentsFromPar(par);
1204 void Paragraph::trackChanges(Change::Type type)
1206 pimpl_->trackChanges(type);
1210 void Paragraph::untrackChanges()
1212 pimpl_->untrackChanges();
1216 void Paragraph::cleanChanges()
1218 pimpl_->cleanChanges();
1222 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1224 Assert(!size() || pos < size());
1225 return pimpl_->lookupChange(pos);
1229 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1231 Assert(!size() || pos < size());
1232 return pimpl_->lookupChangeFull(pos);
1236 bool Paragraph::isChanged(pos_type start, pos_type end) const
1238 return pimpl_->isChanged(start, end);
1242 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1244 return pimpl_->isChangeEdited(start, end);
1248 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1250 pimpl_->setChange(pos, type);
1255 void Paragraph::markErased()
1257 pimpl_->markErased();
1261 void Paragraph::acceptChange(pos_type start, pos_type end)
1263 return pimpl_->acceptChange(start, end);
1267 void Paragraph::rejectChange(pos_type start, pos_type end)
1269 return pimpl_->rejectChange(start, end);
1273 lyx::pos_type Paragraph::size() const
1275 return pimpl_->size();
1279 bool Paragraph::empty() const
1281 return pimpl_->empty();
1285 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1287 return pimpl_->getChar(pos);
1291 int Paragraph::id() const
1297 void Paragraph::id(int i)
1303 LyXLayout_ptr const & Paragraph::layout() const
1306 InsetOld * inset = inInset();
1307 if (inset && inset->lyxCode() == InsetOld::ENVIRONMENT_CODE)
1308 return static_cast<InsetEnvironment*>(inset)->layout();
1314 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1316 layout_ = new_layout;
1320 UpdatableInset * Paragraph::inInset() const
1322 return pimpl_->inset_owner;
1326 void Paragraph::clearContents()
1331 void Paragraph::setChar(pos_type pos, value_type c)
1333 pimpl_->setChar(pos, c);
1337 ParagraphParameters & Paragraph::params()
1339 return pimpl_->params;
1343 ParagraphParameters const & Paragraph::params() const
1345 return pimpl_->params;
1349 bool Paragraph::isFreeSpacing() const
1351 if (layout()->free_spacing)
1354 // for now we just need this, later should we need this in some
1355 // other way we can always add a function to InsetOld::() too.
1356 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1357 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
1362 bool Paragraph::allowEmpty() const
1364 if (layout()->keepempty)
1366 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1367 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;