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
98 lyxerr << "Paragraph::operator=()" << endl;
101 pimpl_ = new Pimpl(*lp.pimpl_, this);
103 enumdepth = lp.enumdepth;
104 itemdepth = lp.itemdepth;
105 // this is because of the dummy layout of the paragraphs that
107 layout_ = lp.layout();
109 // copy everything behind the break-position to the new paragraph
110 insetlist = lp.insetlist;
111 InsetList::iterator it = insetlist.begin();
112 InsetList::iterator end = insetlist.end();
113 for (; it != end; ++it) {
114 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
115 // tell the new inset who is the boss now
116 it->inset->parOwner(this);
120 // the destructor removes the new paragraph from the list
121 Paragraph::~Paragraph()
125 //lyxerr << "Paragraph::paragraph_id = "
126 // << Paragraph::paragraph_id << endl;
130 void Paragraph::write(Buffer const * buf, ostream & os,
131 BufferParams const & bparams,
132 depth_type & dth) const
134 // The beginning or end of a deeper (i.e. nested) area?
135 if (dth != params().depth()) {
136 if (params().depth() > dth) {
137 while (params().depth() > dth) {
138 os << "\n\\begin_deeper ";
142 while (params().depth() < dth) {
143 os << "\n\\end_deeper ";
149 // First write the layout
150 os << "\n\\begin_layout " << layout()->name() << '\n';
154 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
156 Change running_change = Change(Change::UNCHANGED);
157 lyx::time_type const curtime(lyx::current_time());
160 for (pos_type i = 0; i < size(); ++i) {
166 Change change = pimpl_->lookupChangeFull(i);
167 Changes::lyxMarkChange(os, column, curtime, running_change, change);
168 running_change = change;
170 // Write font changes
171 LyXFont font2 = getFontSettings(bparams, i);
172 if (font2 != font1) {
173 font2.lyxWriteChanges(font1, os);
178 value_type const c = getChar(i);
182 InsetOld const * inset = getInset(i);
184 if (inset->directWrite()) {
185 // international char, let it write
186 // code directly so it's shorter in
188 inset->write(buf, os);
190 os << "\n\\begin_inset ";
191 inset->write(buf, os);
192 os << "\n\\end_inset \n\n";
198 os << "\n\\backslash \n";
202 if (i + 1 < size() && getChar(i + 1) == ' ') {
209 if ((column > 70 && c == ' ')
214 // this check is to amend a bug. LyX sometimes
215 // inserts '\0' this could cause problems.
219 lyxerr << "ERROR (Paragraph::writeFile):"
220 " NULL char in structure." << endl;
226 // to make reading work properly
228 running_change = pimpl_->lookupChange(0);
229 Changes::lyxMarkChange(os, column, curtime,
230 Change(Change::UNCHANGED), running_change);
232 Changes::lyxMarkChange(os, column, curtime,
233 running_change, Change(Change::UNCHANGED));
235 os << "\n\\end_layout\n";
239 void Paragraph::validate(LaTeXFeatures & features) const
241 pimpl_->validate(features, *layout());
245 void Paragraph::eraseIntern(lyx::pos_type pos)
247 pimpl_->eraseIntern(pos);
251 bool Paragraph::erase(pos_type pos)
253 return pimpl_->erase(pos);
257 int Paragraph::erase(pos_type start, pos_type end)
259 return pimpl_->erase(start, end);
263 bool Paragraph::checkInsertChar(LyXFont & font)
265 if (pimpl_->inset_owner)
266 return pimpl_->inset_owner->checkInsertChar(font);
271 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
273 insertChar(pos, c, LyXFont(LyXFont::ALL_INHERIT));
277 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
278 LyXFont const & font, Change change)
280 pimpl_->insertChar(pos, c, font, change);
284 void Paragraph::insertInset(pos_type pos, InsetOld * inset)
286 insertInset(pos, inset, LyXFont(LyXFont::ALL_INHERIT));
290 void Paragraph::insertInset(pos_type pos, InsetOld * inset, LyXFont const & font, Change change)
292 pimpl_->insertInset(pos, inset, font, change);
296 bool Paragraph::insetAllowed(InsetOld::Code code)
298 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
299 if (pimpl_->inset_owner)
300 return pimpl_->inset_owner->insetAllowed(code);
305 InsetOld * Paragraph::getInset(pos_type pos)
307 Assert(pos < size());
308 return insetlist.get(pos);
312 InsetOld const * Paragraph::getInset(pos_type pos) const
314 Assert(pos < size());
315 return insetlist.get(pos);
319 // Gets uninstantiated font setting at position.
320 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
323 Assert(pos <= size());
325 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
326 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
327 for (; cit != end; ++cit)
328 if (cit->pos() >= pos)
334 if (pos == size() && !empty())
335 return getFontSettings(bparams, pos - 1);
337 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
341 lyx::pos_type Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const
343 Assert(pos <= size());
345 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
346 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
347 for (; cit != end; ++cit)
348 if (cit->pos() >= pos)
351 // This should not happen, but if so, we take no chances.
352 lyxerr << "Pararaph::getEndPosOfFontSpan: This should not happen!"
358 // Gets uninstantiated font setting at position 0
359 LyXFont const Paragraph::getFirstFontSettings() const
361 if (!empty() && !pimpl_->fontlist.empty())
362 return pimpl_->fontlist[0].font();
364 return LyXFont(LyXFont::ALL_INHERIT);
368 // Gets the fully instantiated font at a given position in a paragraph
369 // This is basically the same function as LyXText::GetFont() in text2.C.
370 // The difference is that this one is used for generating the LaTeX file,
371 // and thus cosmetic "improvements" are disallowed: This has to deliver
372 // the true picture of the buffer. (Asger)
373 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
374 LyXFont const & outerfont) const
378 LyXLayout_ptr const & lout = layout();
380 pos_type const body_pos = beginningOfBody();
384 layoutfont = lout->labelfont;
386 layoutfont = lout->font;
388 LyXFont tmpfont = getFontSettings(bparams, pos);
389 tmpfont.realize(layoutfont);
390 tmpfont.realize(outerfont);
391 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
397 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
398 LyXFont const & outerfont) const
400 LyXFont tmpfont = layout()->labelfont;
401 tmpfont.setLanguage(getParLanguage(bparams));
402 tmpfont.realize(outerfont);
403 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
408 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
409 LyXFont const & outerfont) const
411 LyXFont tmpfont = layout()->font;
412 tmpfont.setLanguage(getParLanguage(bparams));
413 tmpfont.realize(outerfont);
414 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
419 /// Returns the height of the highest font in range
421 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
422 LyXFont::FONT_SIZE const def_size) const
424 if (pimpl_->fontlist.empty())
427 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
428 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
429 for (; end_it != end; ++end_it) {
430 if (end_it->pos() >= endpos)
437 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
438 for (; cit != end; ++cit) {
439 if (cit->pos() >= startpos)
443 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
444 for (; cit != end_it; ++cit) {
445 LyXFont::FONT_SIZE size = cit->font().size();
446 if (size == LyXFont::INHERIT_SIZE)
448 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
455 Paragraph::value_type
456 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
458 value_type c = getChar(pos);
459 if (!lyxrc.rtl_support)
489 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
496 void Paragraph::setFont(pos_type pos, LyXFont const & font)
498 Assert(pos <= size());
500 // First, reduce font against layout/label font
501 // Update: The SetCharFont() routine in text2.C already
502 // reduces font, so we don't need to do that here. (Asger)
503 // No need to simplify this because it will disappear
504 // in a new kernel. (Asger)
505 // Next search font table
507 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
508 Pimpl::FontList::iterator it = beg;
509 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
510 for (; it != endit; ++it) {
511 if (it->pos() >= pos)
514 unsigned int i = std::distance(beg, it);
515 bool notfound = (it == endit);
517 if (!notfound && pimpl_->fontlist[i].font() == font)
520 bool begin = pos == 0 || notfound ||
521 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
522 // Is position pos is a beginning of a font block?
523 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
524 // Is position pos is the end of a font block?
525 if (begin && end) { // A single char block
526 if (i + 1 < pimpl_->fontlist.size() &&
527 pimpl_->fontlist[i + 1].font() == font) {
528 // Merge the singleton block with the next block
529 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
530 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
531 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
532 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
533 // Merge the singleton block with the previous block
534 pimpl_->fontlist[i - 1].pos(pos);
535 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
537 pimpl_->fontlist[i].font(font);
539 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
540 pimpl_->fontlist[i - 1].pos(pos);
542 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
543 Pimpl::FontTable(pos, font));
545 pimpl_->fontlist[i].pos(pos - 1);
546 if (!(i + 1 < pimpl_->fontlist.size() &&
547 pimpl_->fontlist[i + 1].font() == font))
548 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
549 Pimpl::FontTable(pos, font));
550 } else { // The general case. The block is splitted into 3 blocks
551 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
552 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
553 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
554 Pimpl::FontTable(pos, font));
559 void Paragraph::makeSameLayout(Paragraph const & par)
561 layout(par.layout());
563 params() = par.params();
567 int Paragraph::stripLeadingSpaces()
573 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
574 pimpl_->eraseIntern(0);
582 bool Paragraph::hasSameLayout(Paragraph const & par) const
585 par.layout() == layout() &&
586 params().sameLayout(par.params());
590 Paragraph::depth_type Paragraph::getDepth() const
592 return params().depth();
596 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
598 if (layout()->isEnvironment())
599 return params().depth() + 1;
601 return params().depth();
605 char Paragraph::getAlign() const
607 return params().align();
611 string const & Paragraph::getLabelstring() const
613 return params().labelString();
617 // the next two functions are for the manual labels
618 string const Paragraph::getLabelWidthString() const
620 if (!params().labelWidthString().empty())
621 return params().labelWidthString();
623 return _("Senseless with this layout!");
627 void Paragraph::setLabelWidthString(string const & s)
629 params().labelWidthString(s);
633 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
636 params().labelWidthString(string());
637 params().align(LYX_ALIGN_LAYOUT);
638 params().spaceTop(VSpace(VSpace::NONE));
639 params().spaceBottom(VSpace(VSpace::NONE));
640 params().spacing(Spacing(Spacing::Default));
644 int Paragraph::beginningOfBody() const
646 if (layout()->labeltype != LABEL_MANUAL)
649 // Unroll the first two cycles of the loop
650 // and remember the previous character to
651 // remove unnecessary GetChar() calls
653 if (i < size() && !isNewline(i)) {
655 char previous_char = 0;
658 previous_char = getChar(i);
661 while (i < size() && previous_char != ' ') {
667 previous_char = temp;
677 // returns -1 if inset not found
678 int Paragraph::getPositionOfInset(InsetOld const * inset) const
681 InsetList::const_iterator it = insetlist.begin();
682 InsetList::const_iterator end = insetlist.end();
683 for (; it != end; ++it)
684 if (it->inset == inset)
690 InsetBibitem * Paragraph::bibitem() const
692 InsetList::const_iterator it = insetlist.begin();
693 if (it != insetlist.end() && it->inset->lyxCode() == InsetOld::BIBTEX_CODE)
694 return static_cast<InsetBibitem *>(it->inset);
700 // This could go to ParagraphParameters if we want to
701 int Paragraph::startTeXParParams(BufferParams const & bparams,
702 ostream & os, bool moving_arg) const
706 if (params().noindent()) {
711 switch (params().align()) {
713 case LYX_ALIGN_BLOCK:
714 case LYX_ALIGN_LAYOUT:
715 case LYX_ALIGN_SPECIAL:
718 case LYX_ALIGN_RIGHT:
719 case LYX_ALIGN_CENTER:
727 switch (params().align()) {
729 case LYX_ALIGN_BLOCK:
730 case LYX_ALIGN_LAYOUT:
731 case LYX_ALIGN_SPECIAL:
734 if (getParLanguage(bparams)->babel() != "hebrew") {
735 os << "\\begin{flushleft}";
738 os << "\\begin{flushright}";
742 case LYX_ALIGN_RIGHT:
743 if (getParLanguage(bparams)->babel() != "hebrew") {
744 os << "\\begin{flushright}";
747 os << "\\begin{flushleft}";
751 case LYX_ALIGN_CENTER:
752 os << "\\begin{center}";
761 // This could go to ParagraphParameters if we want to
762 int Paragraph::endTeXParParams(BufferParams const & bparams,
763 ostream & os, bool moving_arg) const
767 switch (params().align()) {
769 case LYX_ALIGN_BLOCK:
770 case LYX_ALIGN_LAYOUT:
771 case LYX_ALIGN_SPECIAL:
774 case LYX_ALIGN_RIGHT:
775 case LYX_ALIGN_CENTER:
783 switch (params().align()) {
785 case LYX_ALIGN_BLOCK:
786 case LYX_ALIGN_LAYOUT:
787 case LYX_ALIGN_SPECIAL:
790 if (getParLanguage(bparams)->babel() != "hebrew") {
791 os << "\\end{flushleft}";
794 os << "\\end{flushright}";
798 case LYX_ALIGN_RIGHT:
799 if (getParLanguage(bparams)->babel() != "hebrew") {
800 os << "\\end{flushright}";
803 os << "\\end{flushleft}";
807 case LYX_ALIGN_CENTER:
808 os << "\\end{center}";
816 // This one spits out the text of the paragraph
817 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
818 BufferParams const & bparams,
819 LyXFont const & outerfont,
820 ostream & os, TexRow & texrow,
821 LatexRunParams const & runparams)
823 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
825 bool return_value = false;
829 // well we have to check if we are in an inset with unlimited
830 // lenght (all in one row) if that is true then we don't allow
831 // any special options in the paragraph and also we don't allow
832 // any environment other then "Standard" to be valid!
834 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
837 style = bparams.getLyXTextClass().defaultLayout();
844 // Maybe we have to create a optional argument.
847 // FIXME: can we actually skip this check and just call
848 // beginningOfBody() ??
849 if (style->labeltype != LABEL_MANUAL) {
852 body_pos = beginningOfBody();
855 unsigned int column = 0;
860 basefont = getLabelFont(bparams, outerfont);
862 basefont = getLayoutFont(bparams, outerfont);
865 bool moving_arg = runparams.moving_arg;
866 moving_arg |= style->needprotect;
868 // Which font is currently active?
869 LyXFont running_font(basefont);
870 // Do we have an open font change?
871 bool open_font = false;
873 Change::Type running_change = Change::UNCHANGED;
875 texrow.start(id(), 0);
877 // if the paragraph is empty, the loop will not be entered at all
879 if (style->isCommand()) {
884 column += startTeXParParams(bparams, os, moving_arg);
888 for (pos_type i = 0; i < size(); ++i) {
890 // First char in paragraph or after label?
894 column += running_font.latexWriteEndChanges(os, basefont, basefont);
897 basefont = getLayoutFont(bparams, outerfont);
898 running_font = basefont;
902 if (style->isCommand()) {
908 column += startTeXParParams(bparams, os,
912 value_type c = getChar(i);
914 // Fully instantiated font
915 LyXFont font = getFont(bparams, i, outerfont);
917 LyXFont const last_font = running_font;
919 // Spaces at end of font change are simulated to be
920 // outside font change, i.e. we write "\textXX{text} "
921 // rather than "\textXX{text }". (Asger)
922 if (open_font && c == ' ' && i <= size() - 2) {
923 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
924 if (next_font != running_font
925 && next_font != font) {
930 // We end font definition before blanks
932 (font != running_font ||
933 font.language() != running_font.language()))
935 column += running_font.latexWriteEndChanges(os,
937 (i == body_pos-1) ? basefont : font);
938 running_font = basefont;
942 // Blanks are printed before start of fontswitch
944 // Do not print the separation of the optional argument
945 if (i != body_pos - 1) {
946 pimpl_->simpleTeXBlanks(os, texrow, i,
947 column, font, *style);
951 // Do we need to change font?
952 if ((font != running_font ||
953 font.language() != running_font.language()) &&
956 column += font.latexWriteStartChanges(os, basefont,
962 Change::Type change = pimpl_->lookupChange(i);
964 column += Changes::latexMarkChange(os, running_change, change);
965 running_change = change;
967 LatexRunParams rp = runparams;
968 rp.moving_arg = moving_arg;
969 rp.free_spacing = style->free_spacing;
970 pimpl_->simpleTeXSpecialChars(buf, bparams,
971 os, texrow, runparams,
973 basefont, outerfont, open_font,
975 *style, i, column, c);
978 column += Changes::latexMarkChange(os,
979 running_change, Change::UNCHANGED);
981 // If we have an open font definition, we have to close it
983 #ifdef FIXED_LANGUAGE_END_DETECTION
986 .latexWriteEndChanges(os, basefont,
987 next_->getFont(bparams,
990 running_font.latexWriteEndChanges(os, basefont,
995 //#warning For now we ALWAYS have to close the foreign font settings if they are
996 //#warning there as we start another \selectlanguage with the next paragraph if
997 //#warning we are in need of this. This should be fixed sometime (Jug)
999 running_font.latexWriteEndChanges(os, basefont, basefont);
1003 // Needed if there is an optional argument but no contents.
1004 if (body_pos > 0 && body_pos == size()) {
1006 return_value = false;
1010 column += endTeXParParams(bparams, os, moving_arg);
1013 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1014 return return_value;
1020 bool Paragraph::isHfill(pos_type pos) const
1022 return IsInsetChar(getChar(pos))
1023 && getInset(pos)->lyxCode() == InsetOld::HFILL_CODE;
1027 bool Paragraph::isInset(pos_type pos) const
1029 return IsInsetChar(getChar(pos));
1033 bool Paragraph::isNewline(pos_type pos) const
1035 return IsInsetChar(getChar(pos))
1036 && getInset(pos)->lyxCode() == InsetOld::NEWLINE_CODE;
1040 bool Paragraph::isSeparator(pos_type pos) const
1042 return IsSeparatorChar(getChar(pos));
1046 bool Paragraph::isLineSeparator(pos_type pos) const
1048 value_type const c = getChar(pos);
1049 return IsLineSeparatorChar(c)
1050 || (IsInsetChar(c) && getInset(pos) &&
1051 getInset(pos)->isLineSeparator());
1055 bool Paragraph::isKomma(pos_type pos) const
1057 return IsKommaChar(getChar(pos));
1061 /// Used by the spellchecker
1062 bool Paragraph::isLetter(pos_type pos) const
1064 value_type const c = getChar(pos);
1065 if (IsLetterChar(c))
1068 return getInset(pos)->isLetter();
1069 // We want to pass the ' and escape chars to ispell
1070 string const extra = lyxrc.isp_esc_chars + '\'';
1071 return contains(extra, c);
1075 bool Paragraph::isWord(pos_type pos) const
1077 return IsWordChar(getChar(pos)) ;
1082 Paragraph::getParLanguage(BufferParams const & bparams) const
1085 return getFirstFontSettings().language();
1086 #warning FIXME we should check the prev par as well (Lgb)
1087 return bparams.language;
1091 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1093 return lyxrc.rtl_support
1094 && getParLanguage(bparams)->RightToLeft()
1095 && !(inInset() && inInset()->owner() &&
1096 inInset()->owner()->lyxCode() == InsetOld::ERT_CODE);
1100 void Paragraph::changeLanguage(BufferParams const & bparams,
1101 Language const * from, Language const * to)
1103 for (pos_type i = 0; i < size(); ++i) {
1104 LyXFont font = getFontSettings(bparams, i);
1105 if (font.language() == from) {
1106 font.setLanguage(to);
1113 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1115 Language const * doc_language = bparams.language;
1116 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1117 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1119 for (; cit != end; ++cit)
1120 if (cit->font().language() != ignore_language &&
1121 cit->font().language() != latex_language &&
1122 cit->font().language() != doc_language)
1128 // Convert the paragraph to a string.
1129 // Used for building the table of contents
1130 string const Paragraph::asString(Buffer const * buffer, bool label) const
1134 if (label && !params().labelString().empty())
1135 s += params().labelString() + ' ';
1137 for (pos_type i = 0; i < size(); ++i) {
1138 value_type c = getChar(i);
1141 else if (c == META_INSET &&
1142 getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
1144 getInset(i)->ascii(buffer, ost);
1145 s += subst(STRCONV(ost.str()),'\n',' ');
1151 // This should really be done by the caller and not here.
1152 string ret(asString(buffer, 0, size(), label));
1153 return subst(ret, '\n', ' ');
1158 string const Paragraph::asString(Buffer const * buffer,
1159 pos_type beg, pos_type end, bool label) const
1163 if (beg == 0 && label && !params().labelString().empty())
1164 os << params().labelString() << ' ';
1166 for (pos_type i = beg; i < end; ++i) {
1167 value_type const c = getUChar(buffer->params, i);
1170 else if (c == META_INSET)
1171 getInset(i)->ascii(buffer, os);
1174 return STRCONV(os.str());
1178 void Paragraph::setInsetOwner(UpdatableInset * inset)
1180 pimpl_->inset_owner = inset;
1181 InsetList::iterator it = insetlist.begin();
1182 InsetList::iterator end = insetlist.end();
1183 for (; it != end; ++it)
1185 it->inset->setOwner(inset);
1189 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1191 insetlist.deleteInsetsLyXText(bv);
1195 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1197 insetlist.resizeInsetsLyXText(bv);
1201 void Paragraph::setContentsFromPar(Paragraph const & par)
1203 pimpl_->setContentsFromPar(par);
1207 void Paragraph::trackChanges(Change::Type type)
1209 pimpl_->trackChanges(type);
1213 void Paragraph::untrackChanges()
1215 pimpl_->untrackChanges();
1219 void Paragraph::cleanChanges()
1221 pimpl_->cleanChanges();
1225 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1227 Assert(!size() || pos < size());
1228 return pimpl_->lookupChange(pos);
1232 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1234 Assert(!size() || pos < size());
1235 return pimpl_->lookupChangeFull(pos);
1239 bool Paragraph::isChanged(pos_type start, pos_type end) const
1241 return pimpl_->isChanged(start, end);
1245 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1247 return pimpl_->isChangeEdited(start, end);
1251 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1253 pimpl_->setChange(pos, type);
1258 void Paragraph::markErased()
1260 pimpl_->markErased();
1264 void Paragraph::acceptChange(pos_type start, pos_type end)
1266 return pimpl_->acceptChange(start, end);
1270 void Paragraph::rejectChange(pos_type start, pos_type end)
1272 return pimpl_->rejectChange(start, end);
1276 lyx::pos_type Paragraph::size() const
1278 return pimpl_->size();
1282 bool Paragraph::empty() const
1284 return pimpl_->empty();
1288 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1290 return pimpl_->getChar(pos);
1294 int Paragraph::id() const
1300 void Paragraph::id(int i)
1306 LyXLayout_ptr const & Paragraph::layout() const
1309 InsetOld * inset = inInset();
1310 if (inset && inset->lyxCode() == InsetOld::ENVIRONMENT_CODE)
1311 return static_cast<InsetEnvironment*>(inset)->layout();
1317 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1319 layout_ = new_layout;
1323 UpdatableInset * Paragraph::inInset() const
1325 return pimpl_->inset_owner;
1329 void Paragraph::clearContents()
1334 void Paragraph::setChar(pos_type pos, value_type c)
1336 pimpl_->setChar(pos, c);
1340 ParagraphParameters & Paragraph::params()
1342 return pimpl_->params;
1346 ParagraphParameters const & Paragraph::params() const
1348 return pimpl_->params;
1352 bool Paragraph::isFreeSpacing() const
1354 if (layout()->free_spacing)
1357 // for now we just need this, later should we need this in some
1358 // other way we can always add a function to InsetOld::() too.
1359 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1360 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
1365 bool Paragraph::allowEmpty() const
1367 if (layout()->keepempty)
1369 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1370 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;