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,
291 LyXFont const & font, Change change)
293 pimpl_->insertInset(pos, inset, font, change);
297 bool Paragraph::insetAllowed(InsetOld::Code code)
299 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
300 if (pimpl_->inset_owner)
301 return pimpl_->inset_owner->insetAllowed(code);
306 InsetOld * Paragraph::getInset(pos_type pos)
308 Assert(pos < size());
309 return insetlist.get(pos);
313 InsetOld const * Paragraph::getInset(pos_type pos) const
315 Assert(pos < size());
316 return insetlist.get(pos);
320 // Gets uninstantiated font setting at position.
321 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
324 Assert(pos <= size());
326 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
327 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
328 for (; cit != end; ++cit)
329 if (cit->pos() >= pos)
335 if (pos == size() && !empty())
336 return getFontSettings(bparams, pos - 1);
338 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
342 lyx::pos_type Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const
344 Assert(pos <= size());
346 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
347 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
348 for (; cit != end; ++cit)
349 if (cit->pos() >= pos)
352 // This should not happen, but if so, we take no chances.
353 //lyxerr << "Paragraph::getEndPosOfFontSpan: This should not happen!"
359 // Gets uninstantiated font setting at position 0
360 LyXFont const Paragraph::getFirstFontSettings() const
362 if (!empty() && !pimpl_->fontlist.empty())
363 return pimpl_->fontlist[0].font();
365 return LyXFont(LyXFont::ALL_INHERIT);
369 // Gets the fully instantiated font at a given position in a paragraph
370 // This is basically the same function as LyXText::GetFont() in text2.C.
371 // The difference is that this one is used for generating the LaTeX file,
372 // and thus cosmetic "improvements" are disallowed: This has to deliver
373 // the true picture of the buffer. (Asger)
374 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
375 LyXFont const & outerfont) const
379 LyXLayout_ptr const & lout = layout();
381 pos_type const body_pos = beginningOfBody();
385 layoutfont = lout->labelfont;
387 layoutfont = lout->font;
389 LyXFont tmpfont = getFontSettings(bparams, pos);
390 tmpfont.realize(layoutfont);
391 tmpfont.realize(outerfont);
392 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
398 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
399 LyXFont const & outerfont) const
401 LyXFont tmpfont = layout()->labelfont;
402 tmpfont.setLanguage(getParLanguage(bparams));
403 tmpfont.realize(outerfont);
404 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
409 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
410 LyXFont const & outerfont) const
412 LyXFont tmpfont = layout()->font;
413 tmpfont.setLanguage(getParLanguage(bparams));
414 tmpfont.realize(outerfont);
415 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
420 /// Returns the height of the highest font in range
422 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
423 LyXFont::FONT_SIZE const def_size) const
425 if (pimpl_->fontlist.empty())
428 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
429 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
430 for (; end_it != end; ++end_it) {
431 if (end_it->pos() >= endpos)
438 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
439 for (; cit != end; ++cit) {
440 if (cit->pos() >= startpos)
444 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
445 for (; cit != end_it; ++cit) {
446 LyXFont::FONT_SIZE size = cit->font().size();
447 if (size == LyXFont::INHERIT_SIZE)
449 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
456 Paragraph::value_type
457 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
459 value_type c = getChar(pos);
460 if (!lyxrc.rtl_support)
490 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
497 void Paragraph::setFont(pos_type pos, LyXFont const & font)
499 Assert(pos <= size());
501 // First, reduce font against layout/label font
502 // Update: The SetCharFont() routine in text2.C already
503 // reduces font, so we don't need to do that here. (Asger)
504 // No need to simplify this because it will disappear
505 // in a new kernel. (Asger)
506 // Next search font table
508 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
509 Pimpl::FontList::iterator it = beg;
510 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
511 for (; it != endit; ++it) {
512 if (it->pos() >= pos)
515 unsigned int i = std::distance(beg, it);
516 bool notfound = (it == endit);
518 if (!notfound && pimpl_->fontlist[i].font() == font)
521 bool begin = pos == 0 || notfound ||
522 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
523 // Is position pos is a beginning of a font block?
524 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
525 // Is position pos is the end of a font block?
526 if (begin && end) { // A single char block
527 if (i + 1 < pimpl_->fontlist.size() &&
528 pimpl_->fontlist[i + 1].font() == font) {
529 // Merge the singleton block with the next block
530 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
531 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
532 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
533 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
534 // Merge the singleton block with the previous block
535 pimpl_->fontlist[i - 1].pos(pos);
536 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
538 pimpl_->fontlist[i].font(font);
540 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
541 pimpl_->fontlist[i - 1].pos(pos);
543 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
544 Pimpl::FontTable(pos, font));
546 pimpl_->fontlist[i].pos(pos - 1);
547 if (!(i + 1 < pimpl_->fontlist.size() &&
548 pimpl_->fontlist[i + 1].font() == font))
549 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
550 Pimpl::FontTable(pos, font));
551 } else { // The general case. The block is splitted into 3 blocks
552 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
553 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
554 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
555 Pimpl::FontTable(pos, font));
560 void Paragraph::makeSameLayout(Paragraph const & par)
562 layout(par.layout());
564 params() = par.params();
568 int Paragraph::stripLeadingSpaces()
574 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
575 pimpl_->eraseIntern(0);
583 bool Paragraph::hasSameLayout(Paragraph const & par) const
586 par.layout() == layout() &&
587 params().sameLayout(par.params());
591 Paragraph::depth_type Paragraph::getDepth() const
593 return params().depth();
597 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
599 if (layout()->isEnvironment())
600 return params().depth() + 1;
602 return params().depth();
606 char Paragraph::getAlign() const
608 return params().align();
612 string const & Paragraph::getLabelstring() const
614 return params().labelString();
618 // the next two functions are for the manual labels
619 string const Paragraph::getLabelWidthString() const
621 if (!params().labelWidthString().empty())
622 return params().labelWidthString();
624 return _("Senseless with this layout!");
628 void Paragraph::setLabelWidthString(string const & s)
630 params().labelWidthString(s);
634 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
637 params().labelWidthString(string());
638 params().align(LYX_ALIGN_LAYOUT);
639 params().spaceTop(VSpace(VSpace::NONE));
640 params().spaceBottom(VSpace(VSpace::NONE));
641 params().spacing(Spacing(Spacing::Default));
645 int Paragraph::beginningOfBody() const
647 if (layout()->labeltype != LABEL_MANUAL)
650 // Unroll the first two cycles of the loop
651 // and remember the previous character to
652 // remove unnecessary GetChar() calls
654 if (i < size() && !isNewline(i)) {
656 char previous_char = 0;
659 previous_char = getChar(i);
662 while (i < size() && previous_char != ' ') {
668 previous_char = temp;
678 // returns -1 if inset not found
679 int Paragraph::getPositionOfInset(InsetOld const * inset) const
682 InsetList::const_iterator it = insetlist.begin();
683 InsetList::const_iterator end = insetlist.end();
684 for (; it != end; ++it)
685 if (it->inset == inset)
691 InsetBibitem * Paragraph::bibitem() const
693 InsetList::const_iterator it = insetlist.begin();
694 if (it != insetlist.end() && it->inset->lyxCode() == InsetOld::BIBTEX_CODE)
695 return static_cast<InsetBibitem *>(it->inset);
701 // This could go to ParagraphParameters if we want to
702 int Paragraph::startTeXParParams(BufferParams const & bparams,
703 ostream & os, bool moving_arg) const
707 if (params().noindent()) {
712 switch (params().align()) {
714 case LYX_ALIGN_BLOCK:
715 case LYX_ALIGN_LAYOUT:
716 case LYX_ALIGN_SPECIAL:
719 case LYX_ALIGN_RIGHT:
720 case LYX_ALIGN_CENTER:
728 switch (params().align()) {
730 case LYX_ALIGN_BLOCK:
731 case LYX_ALIGN_LAYOUT:
732 case LYX_ALIGN_SPECIAL:
735 if (getParLanguage(bparams)->babel() != "hebrew") {
736 os << "\\begin{flushleft}";
739 os << "\\begin{flushright}";
743 case LYX_ALIGN_RIGHT:
744 if (getParLanguage(bparams)->babel() != "hebrew") {
745 os << "\\begin{flushright}";
748 os << "\\begin{flushleft}";
752 case LYX_ALIGN_CENTER:
753 os << "\\begin{center}";
762 // This could go to ParagraphParameters if we want to
763 int Paragraph::endTeXParParams(BufferParams const & bparams,
764 ostream & os, bool moving_arg) const
768 switch (params().align()) {
770 case LYX_ALIGN_BLOCK:
771 case LYX_ALIGN_LAYOUT:
772 case LYX_ALIGN_SPECIAL:
775 case LYX_ALIGN_RIGHT:
776 case LYX_ALIGN_CENTER:
784 switch (params().align()) {
786 case LYX_ALIGN_BLOCK:
787 case LYX_ALIGN_LAYOUT:
788 case LYX_ALIGN_SPECIAL:
791 if (getParLanguage(bparams)->babel() != "hebrew") {
792 os << "\\end{flushleft}";
795 os << "\\end{flushright}";
799 case LYX_ALIGN_RIGHT:
800 if (getParLanguage(bparams)->babel() != "hebrew") {
801 os << "\\end{flushright}";
804 os << "\\end{flushleft}";
808 case LYX_ALIGN_CENTER:
809 os << "\\end{center}";
817 // This one spits out the text of the paragraph
818 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
819 BufferParams const & bparams,
820 LyXFont const & outerfont,
821 ostream & os, TexRow & texrow,
822 LatexRunParams const & runparams)
824 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
826 bool return_value = false;
830 // well we have to check if we are in an inset with unlimited
831 // lenght (all in one row) if that is true then we don't allow
832 // any special options in the paragraph and also we don't allow
833 // any environment other then "Standard" to be valid!
835 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
838 style = bparams.getLyXTextClass().defaultLayout();
845 // Maybe we have to create a optional argument.
848 // FIXME: can we actually skip this check and just call
849 // beginningOfBody() ??
850 if (style->labeltype != LABEL_MANUAL) {
853 body_pos = beginningOfBody();
856 unsigned int column = 0;
861 basefont = getLabelFont(bparams, outerfont);
863 basefont = getLayoutFont(bparams, outerfont);
866 bool moving_arg = runparams.moving_arg;
867 moving_arg |= style->needprotect;
869 // Which font is currently active?
870 LyXFont running_font(basefont);
871 // Do we have an open font change?
872 bool open_font = false;
874 Change::Type running_change = Change::UNCHANGED;
876 texrow.start(id(), 0);
878 // if the paragraph is empty, the loop will not be entered at all
880 if (style->isCommand()) {
885 column += startTeXParParams(bparams, os, moving_arg);
889 for (pos_type i = 0; i < size(); ++i) {
891 // First char in paragraph or after label?
895 column += running_font.latexWriteEndChanges(os, basefont, basefont);
898 basefont = getLayoutFont(bparams, outerfont);
899 running_font = basefont;
903 if (style->isCommand()) {
909 column += startTeXParParams(bparams, os,
913 value_type c = getChar(i);
915 // Fully instantiated font
916 LyXFont font = getFont(bparams, i, outerfont);
918 LyXFont const last_font = running_font;
920 // Spaces at end of font change are simulated to be
921 // outside font change, i.e. we write "\textXX{text} "
922 // rather than "\textXX{text }". (Asger)
923 if (open_font && c == ' ' && i <= size() - 2) {
924 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
925 if (next_font != running_font
926 && next_font != font) {
931 // We end font definition before blanks
933 (font != running_font ||
934 font.language() != running_font.language()))
936 column += running_font.latexWriteEndChanges(os,
938 (i == body_pos-1) ? basefont : font);
939 running_font = basefont;
943 // Blanks are printed before start of fontswitch
945 // Do not print the separation of the optional argument
946 if (i != body_pos - 1) {
947 pimpl_->simpleTeXBlanks(os, texrow, i,
948 column, font, *style);
952 // Do we need to change font?
953 if ((font != running_font ||
954 font.language() != running_font.language()) &&
957 column += font.latexWriteStartChanges(os, basefont,
963 Change::Type change = pimpl_->lookupChange(i);
965 column += Changes::latexMarkChange(os, running_change, change);
966 running_change = change;
968 LatexRunParams rp = runparams;
969 rp.moving_arg = moving_arg;
970 rp.free_spacing = style->free_spacing;
971 pimpl_->simpleTeXSpecialChars(buf, bparams,
972 os, texrow, runparams,
974 basefont, outerfont, open_font,
976 *style, i, column, c);
979 column += Changes::latexMarkChange(os,
980 running_change, Change::UNCHANGED);
982 // If we have an open font definition, we have to close it
984 #ifdef FIXED_LANGUAGE_END_DETECTION
987 .latexWriteEndChanges(os, basefont,
988 next_->getFont(bparams,
991 running_font.latexWriteEndChanges(os, basefont,
996 //#warning For now we ALWAYS have to close the foreign font settings if they are
997 //#warning there as we start another \selectlanguage with the next paragraph if
998 //#warning we are in need of this. This should be fixed sometime (Jug)
1000 running_font.latexWriteEndChanges(os, basefont, basefont);
1004 // Needed if there is an optional argument but no contents.
1005 if (body_pos > 0 && body_pos == size()) {
1007 return_value = false;
1011 column += endTeXParParams(bparams, os, moving_arg);
1014 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1015 return return_value;
1021 bool Paragraph::isHfill(pos_type pos) const
1023 return IsInsetChar(getChar(pos))
1024 && getInset(pos)->lyxCode() == InsetOld::HFILL_CODE;
1028 bool Paragraph::isInset(pos_type pos) const
1030 return IsInsetChar(getChar(pos));
1034 bool Paragraph::isNewline(pos_type pos) const
1036 return IsInsetChar(getChar(pos))
1037 && getInset(pos)->lyxCode() == InsetOld::NEWLINE_CODE;
1041 bool Paragraph::isSeparator(pos_type pos) const
1043 return IsSeparatorChar(getChar(pos));
1047 bool Paragraph::isLineSeparator(pos_type pos) const
1049 value_type const c = getChar(pos);
1050 return IsLineSeparatorChar(c)
1051 || (IsInsetChar(c) && getInset(pos) &&
1052 getInset(pos)->isLineSeparator());
1056 bool Paragraph::isKomma(pos_type pos) const
1058 return IsKommaChar(getChar(pos));
1062 /// Used by the spellchecker
1063 bool Paragraph::isLetter(pos_type pos) const
1065 value_type const c = getChar(pos);
1066 if (IsLetterChar(c))
1069 return getInset(pos)->isLetter();
1070 // We want to pass the ' and escape chars to ispell
1071 string const extra = lyxrc.isp_esc_chars + '\'';
1072 return contains(extra, c);
1076 bool Paragraph::isWord(pos_type pos) const
1078 return IsWordChar(getChar(pos)) ;
1083 Paragraph::getParLanguage(BufferParams const & bparams) const
1086 return getFirstFontSettings().language();
1087 #warning FIXME we should check the prev par as well (Lgb)
1088 return bparams.language;
1092 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1094 return lyxrc.rtl_support
1095 && getParLanguage(bparams)->RightToLeft()
1096 && !(inInset() && inInset()->owner() &&
1097 inInset()->owner()->lyxCode() == InsetOld::ERT_CODE);
1101 void Paragraph::changeLanguage(BufferParams const & bparams,
1102 Language const * from, Language const * to)
1104 for (pos_type i = 0; i < size(); ++i) {
1105 LyXFont font = getFontSettings(bparams, i);
1106 if (font.language() == from) {
1107 font.setLanguage(to);
1114 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1116 Language const * doc_language = bparams.language;
1117 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1118 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1120 for (; cit != end; ++cit)
1121 if (cit->font().language() != ignore_language &&
1122 cit->font().language() != latex_language &&
1123 cit->font().language() != doc_language)
1129 // Convert the paragraph to a string.
1130 // Used for building the table of contents
1131 string const Paragraph::asString(Buffer const * buffer, bool label) const
1135 if (label && !params().labelString().empty())
1136 s += params().labelString() + ' ';
1138 for (pos_type i = 0; i < size(); ++i) {
1139 value_type c = getChar(i);
1142 else if (c == META_INSET &&
1143 getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
1145 getInset(i)->ascii(buffer, ost);
1146 s += subst(STRCONV(ost.str()),'\n',' ');
1152 // This should really be done by the caller and not here.
1153 string ret(asString(buffer, 0, size(), label));
1154 return subst(ret, '\n', ' ');
1159 string const Paragraph::asString(Buffer const * buffer,
1160 pos_type beg, pos_type end, bool label) const
1164 if (beg == 0 && label && !params().labelString().empty())
1165 os << params().labelString() << ' ';
1167 for (pos_type i = beg; i < end; ++i) {
1168 value_type const c = getUChar(buffer->params, i);
1171 else if (c == META_INSET)
1172 getInset(i)->ascii(buffer, os);
1175 return STRCONV(os.str());
1179 void Paragraph::setInsetOwner(UpdatableInset * inset)
1181 pimpl_->inset_owner = inset;
1182 InsetList::iterator it = insetlist.begin();
1183 InsetList::iterator end = insetlist.end();
1184 for (; it != end; ++it)
1186 it->inset->setOwner(inset);
1190 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1192 insetlist.deleteInsetsLyXText(bv);
1196 void Paragraph::setContentsFromPar(Paragraph const & par)
1198 pimpl_->setContentsFromPar(par);
1202 void Paragraph::trackChanges(Change::Type type)
1204 pimpl_->trackChanges(type);
1208 void Paragraph::untrackChanges()
1210 pimpl_->untrackChanges();
1214 void Paragraph::cleanChanges()
1216 pimpl_->cleanChanges();
1220 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1222 Assert(!size() || pos < size());
1223 return pimpl_->lookupChange(pos);
1227 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1229 Assert(!size() || pos < size());
1230 return pimpl_->lookupChangeFull(pos);
1234 bool Paragraph::isChanged(pos_type start, pos_type end) const
1236 return pimpl_->isChanged(start, end);
1240 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1242 return pimpl_->isChangeEdited(start, end);
1246 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1248 pimpl_->setChange(pos, type);
1253 void Paragraph::markErased()
1255 pimpl_->markErased();
1259 void Paragraph::acceptChange(pos_type start, pos_type end)
1261 return pimpl_->acceptChange(start, end);
1265 void Paragraph::rejectChange(pos_type start, pos_type end)
1267 return pimpl_->rejectChange(start, end);
1271 lyx::pos_type Paragraph::size() const
1273 return pimpl_->size();
1277 bool Paragraph::empty() const
1279 return pimpl_->empty();
1283 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1285 return pimpl_->getChar(pos);
1289 int Paragraph::id() const
1295 void Paragraph::id(int i)
1301 LyXLayout_ptr const & Paragraph::layout() const
1304 InsetOld * inset = inInset();
1305 if (inset && inset->lyxCode() == InsetOld::ENVIRONMENT_CODE)
1306 return static_cast<InsetEnvironment*>(inset)->layout();
1312 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1314 layout_ = new_layout;
1318 UpdatableInset * Paragraph::inInset() const
1320 return pimpl_->inset_owner;
1324 void Paragraph::clearContents()
1329 void Paragraph::setChar(pos_type pos, value_type c)
1331 pimpl_->setChar(pos, c);
1335 ParagraphParameters & Paragraph::params()
1337 return pimpl_->params;
1341 ParagraphParameters const & Paragraph::params() const
1343 return pimpl_->params;
1347 bool Paragraph::isFreeSpacing() const
1349 if (layout()->free_spacing)
1352 // for now we just need this, later should we need this in some
1353 // other way we can always add a function to InsetOld too.
1354 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1355 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
1360 bool Paragraph::allowEmpty() const
1362 if (layout()->keepempty)
1364 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1365 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;