3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
11 * \author André Pönitz
13 * \author Jürgen Vigna
15 * Full author contact details are available in file CREDITS.
20 #include "paragraph.h"
21 #include "paragraph_pimpl.h"
24 #include "bufferparams.h"
25 #include "BufferView.h"
31 #include "latexrunparams.h"
34 #include "paragraph_funcs.h"
35 #include "ParameterStruct.h"
40 #include "insets/insetbibitem.h"
41 #include "insets/insetoptarg.h"
42 #include "insets/insetenv.h"
44 #include "support/filetools.h"
45 #include "support/lstrings.h"
46 #include "support/lyxmanip.h"
47 #include "support/FileInfo.h"
48 #include "support/LAssert.h"
49 #include "support/textutils.h"
56 using namespace lyx::support;
62 using std::lower_bound;
63 using std::upper_bound;
68 Paragraph::Paragraph()
69 : pimpl_(new Paragraph::Pimpl(this))
77 Paragraph::Paragraph(Paragraph const & lp)
78 : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
82 // this is because of the dummy layout of the paragraphs that
84 layout_ = lp.layout();
86 // copy everything behind the break-position to the new paragraph
87 insetlist = lp.insetlist;
88 InsetList::iterator it = insetlist.begin();
89 InsetList::iterator end = insetlist.end();
90 for (; it != end; ++it) {
91 // currently we hold Inset*, not InsetBase*
92 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
93 // tell the new inset who is the boss now
94 it->inset->parOwner(this);
99 void Paragraph::operator=(Paragraph const & lp)
101 // needed as we will destroy the pimpl_ before copying it
105 lyxerr << "Paragraph::operator=()" << endl;
108 pimpl_ = new Pimpl(*lp.pimpl_, this);
110 enumdepth = lp.enumdepth;
111 itemdepth = lp.itemdepth;
112 // this is because of the dummy layout of the paragraphs that
114 layout_ = lp.layout();
116 // copy everything behind the break-position to the new paragraph
117 insetlist = lp.insetlist;
118 InsetList::iterator it = insetlist.begin();
119 InsetList::iterator end = insetlist.end();
120 for (; it != end; ++it) {
121 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
122 // tell the new inset who is the boss now
123 it->inset->parOwner(this);
127 // the destructor removes the new paragraph from the list
128 Paragraph::~Paragraph()
132 //lyxerr << "Paragraph::paragraph_id = "
133 // << Paragraph::paragraph_id << endl;
137 void Paragraph::write(Buffer const * buf, ostream & os,
138 BufferParams const & bparams,
139 depth_type & dth) const
141 // The beginning or end of a deeper (i.e. nested) area?
142 if (dth != params().depth()) {
143 if (params().depth() > dth) {
144 while (params().depth() > dth) {
145 os << "\n\\begin_deeper ";
149 while (params().depth() < dth) {
150 os << "\n\\end_deeper ";
156 // First write the layout
157 os << "\n\\begin_layout " << layout()->name() << '\n';
161 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
163 Change running_change = Change(Change::UNCHANGED);
164 lyx::time_type const curtime(lyx::current_time());
167 for (pos_type i = 0; i < size(); ++i) {
173 Change change = pimpl_->lookupChangeFull(i);
174 Changes::lyxMarkChange(os, column, curtime, running_change, change);
175 running_change = change;
177 // Write font changes
178 LyXFont font2 = getFontSettings(bparams, i);
179 if (font2 != font1) {
180 font2.lyxWriteChanges(font1, os);
185 value_type const c = getChar(i);
189 InsetOld const * inset = getInset(i);
191 if (inset->directWrite()) {
192 // international char, let it write
193 // code directly so it's shorter in
195 inset->write(buf, os);
197 os << "\n\\begin_inset ";
198 inset->write(buf, os);
199 os << "\n\\end_inset \n\n";
205 os << "\n\\backslash \n";
209 if (i + 1 < size() && getChar(i + 1) == ' ') {
216 if ((column > 70 && c == ' ')
221 // this check is to amend a bug. LyX sometimes
222 // inserts '\0' this could cause problems.
226 lyxerr << "ERROR (Paragraph::writeFile):"
227 " NULL char in structure." << endl;
233 // to make reading work properly
235 running_change = pimpl_->lookupChange(0);
236 Changes::lyxMarkChange(os, column, curtime,
237 Change(Change::UNCHANGED), running_change);
239 Changes::lyxMarkChange(os, column, curtime,
240 running_change, Change(Change::UNCHANGED));
242 os << "\n\\end_layout\n";
246 void Paragraph::validate(LaTeXFeatures & features) const
248 pimpl_->validate(features, *layout());
252 void Paragraph::eraseIntern(lyx::pos_type pos)
254 pimpl_->eraseIntern(pos);
258 bool Paragraph::erase(pos_type pos)
260 return pimpl_->erase(pos);
264 int Paragraph::erase(pos_type start, pos_type end)
266 return pimpl_->erase(start, end);
270 bool Paragraph::checkInsertChar(LyXFont & font)
272 if (pimpl_->inset_owner)
273 return pimpl_->inset_owner->checkInsertChar(font);
278 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
280 insertChar(pos, c, LyXFont(LyXFont::ALL_INHERIT));
284 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
285 LyXFont const & font, Change change)
287 pimpl_->insertChar(pos, c, font, change);
291 void Paragraph::insertInset(pos_type pos, InsetOld * inset)
293 insertInset(pos, inset, LyXFont(LyXFont::ALL_INHERIT));
297 void Paragraph::insertInset(pos_type pos, InsetOld * inset,
298 LyXFont const & font, Change change)
300 pimpl_->insertInset(pos, inset, font, change);
304 bool Paragraph::insetAllowed(InsetOld::Code code)
306 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
307 if (pimpl_->inset_owner)
308 return pimpl_->inset_owner->insetAllowed(code);
313 InsetOld * Paragraph::getInset(pos_type pos)
315 Assert(pos < size());
316 return insetlist.get(pos);
320 InsetOld const * Paragraph::getInset(pos_type pos) const
322 Assert(pos < size());
323 return insetlist.get(pos);
327 // Gets uninstantiated font setting at position.
328 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
331 Assert(pos <= size());
333 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
334 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
335 for (; cit != end; ++cit)
336 if (cit->pos() >= pos)
342 if (pos == size() && !empty())
343 return getFontSettings(bparams, pos - 1);
345 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
349 lyx::pos_type Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const
351 Assert(pos <= size());
353 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
354 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
355 for (; cit != end; ++cit)
356 if (cit->pos() >= pos)
359 // This should not happen, but if so, we take no chances.
360 //lyxerr << "Paragraph::getEndPosOfFontSpan: This should not happen!"
366 // Gets uninstantiated font setting at position 0
367 LyXFont const Paragraph::getFirstFontSettings() const
369 if (!empty() && !pimpl_->fontlist.empty())
370 return pimpl_->fontlist[0].font();
372 return LyXFont(LyXFont::ALL_INHERIT);
376 // Gets the fully instantiated font at a given position in a paragraph
377 // This is basically the same function as LyXText::GetFont() in text2.C.
378 // The difference is that this one is used for generating the LaTeX file,
379 // and thus cosmetic "improvements" are disallowed: This has to deliver
380 // the true picture of the buffer. (Asger)
381 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
382 LyXFont const & outerfont) const
386 LyXLayout_ptr const & lout = layout();
388 pos_type const body_pos = beginningOfBody();
392 layoutfont = lout->labelfont;
394 layoutfont = lout->font;
396 LyXFont tmpfont = getFontSettings(bparams, pos);
397 tmpfont.realize(layoutfont);
398 tmpfont.realize(outerfont);
399 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
405 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
406 LyXFont const & outerfont) const
408 LyXFont tmpfont = layout()->labelfont;
409 tmpfont.setLanguage(getParLanguage(bparams));
410 tmpfont.realize(outerfont);
411 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
416 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
417 LyXFont const & outerfont) const
419 LyXFont tmpfont = layout()->font;
420 tmpfont.setLanguage(getParLanguage(bparams));
421 tmpfont.realize(outerfont);
422 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
427 /// Returns the height of the highest font in range
429 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
430 LyXFont::FONT_SIZE const def_size) const
432 if (pimpl_->fontlist.empty())
435 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
436 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
437 for (; end_it != end; ++end_it) {
438 if (end_it->pos() >= endpos)
445 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
446 for (; cit != end; ++cit) {
447 if (cit->pos() >= startpos)
451 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
452 for (; cit != end_it; ++cit) {
453 LyXFont::FONT_SIZE size = cit->font().size();
454 if (size == LyXFont::INHERIT_SIZE)
456 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
463 Paragraph::value_type
464 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
466 value_type c = getChar(pos);
467 if (!lyxrc.rtl_support)
497 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
504 void Paragraph::setFont(pos_type pos, LyXFont const & font)
506 Assert(pos <= size());
508 // First, reduce font against layout/label font
509 // Update: The SetCharFont() routine in text2.C already
510 // reduces font, so we don't need to do that here. (Asger)
511 // No need to simplify this because it will disappear
512 // in a new kernel. (Asger)
513 // Next search font table
515 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
516 Pimpl::FontList::iterator it = beg;
517 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
518 for (; it != endit; ++it) {
519 if (it->pos() >= pos)
522 unsigned int i = std::distance(beg, it);
523 bool notfound = (it == endit);
525 if (!notfound && pimpl_->fontlist[i].font() == font)
528 bool begin = pos == 0 || notfound ||
529 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
530 // Is position pos is a beginning of a font block?
531 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
532 // Is position pos is the end of a font block?
533 if (begin && end) { // A single char block
534 if (i + 1 < pimpl_->fontlist.size() &&
535 pimpl_->fontlist[i + 1].font() == font) {
536 // Merge the singleton block with the next block
537 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
538 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
539 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
540 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
541 // Merge the singleton block with the previous block
542 pimpl_->fontlist[i - 1].pos(pos);
543 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
545 pimpl_->fontlist[i].font(font);
547 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
548 pimpl_->fontlist[i - 1].pos(pos);
550 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
551 Pimpl::FontTable(pos, font));
553 pimpl_->fontlist[i].pos(pos - 1);
554 if (!(i + 1 < pimpl_->fontlist.size() &&
555 pimpl_->fontlist[i + 1].font() == font))
556 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
557 Pimpl::FontTable(pos, font));
558 } else { // The general case. The block is splitted into 3 blocks
559 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
560 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
561 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
562 Pimpl::FontTable(pos, font));
567 void Paragraph::makeSameLayout(Paragraph const & par)
569 layout(par.layout());
571 params() = par.params();
575 int Paragraph::stripLeadingSpaces()
581 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
582 pimpl_->eraseIntern(0);
590 bool Paragraph::hasSameLayout(Paragraph const & par) const
593 par.layout() == layout() &&
594 params().sameLayout(par.params());
598 Paragraph::depth_type Paragraph::getDepth() const
600 return params().depth();
604 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
606 if (layout()->isEnvironment())
607 return params().depth() + 1;
609 return params().depth();
613 char Paragraph::getAlign() const
615 return params().align();
619 string const & Paragraph::getLabelstring() const
621 return params().labelString();
625 // the next two functions are for the manual labels
626 string const Paragraph::getLabelWidthString() const
628 if (!params().labelWidthString().empty())
629 return params().labelWidthString();
631 return _("Senseless with this layout!");
635 void Paragraph::setLabelWidthString(string const & s)
637 params().labelWidthString(s);
641 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
644 params().labelWidthString(string());
645 params().align(LYX_ALIGN_LAYOUT);
646 params().spaceTop(VSpace(VSpace::NONE));
647 params().spaceBottom(VSpace(VSpace::NONE));
648 params().spacing(Spacing(Spacing::Default));
652 int Paragraph::beginningOfBody() const
654 if (layout()->labeltype != LABEL_MANUAL)
657 // Unroll the first two cycles of the loop
658 // and remember the previous character to
659 // remove unnecessary GetChar() calls
661 if (i < size() && !isNewline(i)) {
663 char previous_char = 0;
666 previous_char = getChar(i);
669 while (i < size() && previous_char != ' ') {
675 previous_char = temp;
685 // returns -1 if inset not found
686 int Paragraph::getPositionOfInset(InsetOld const * inset) const
689 InsetList::const_iterator it = insetlist.begin();
690 InsetList::const_iterator end = insetlist.end();
691 for (; it != end; ++it)
692 if (it->inset == inset)
698 InsetBibitem * Paragraph::bibitem() const
700 InsetList::const_iterator it = insetlist.begin();
701 if (it != insetlist.end() && it->inset->lyxCode() == InsetOld::BIBTEX_CODE)
702 return static_cast<InsetBibitem *>(it->inset);
708 // This could go to ParagraphParameters if we want to
709 int Paragraph::startTeXParParams(BufferParams const & bparams,
710 ostream & os, bool moving_arg) const
714 if (params().noindent()) {
719 switch (params().align()) {
721 case LYX_ALIGN_BLOCK:
722 case LYX_ALIGN_LAYOUT:
723 case LYX_ALIGN_SPECIAL:
726 case LYX_ALIGN_RIGHT:
727 case LYX_ALIGN_CENTER:
735 switch (params().align()) {
737 case LYX_ALIGN_BLOCK:
738 case LYX_ALIGN_LAYOUT:
739 case LYX_ALIGN_SPECIAL:
742 if (getParLanguage(bparams)->babel() != "hebrew") {
743 os << "\\begin{flushleft}";
746 os << "\\begin{flushright}";
750 case LYX_ALIGN_RIGHT:
751 if (getParLanguage(bparams)->babel() != "hebrew") {
752 os << "\\begin{flushright}";
755 os << "\\begin{flushleft}";
759 case LYX_ALIGN_CENTER:
760 os << "\\begin{center}";
769 // This could go to ParagraphParameters if we want to
770 int Paragraph::endTeXParParams(BufferParams const & bparams,
771 ostream & os, bool moving_arg) const
775 switch (params().align()) {
777 case LYX_ALIGN_BLOCK:
778 case LYX_ALIGN_LAYOUT:
779 case LYX_ALIGN_SPECIAL:
782 case LYX_ALIGN_RIGHT:
783 case LYX_ALIGN_CENTER:
791 switch (params().align()) {
793 case LYX_ALIGN_BLOCK:
794 case LYX_ALIGN_LAYOUT:
795 case LYX_ALIGN_SPECIAL:
798 if (getParLanguage(bparams)->babel() != "hebrew") {
799 os << "\\end{flushleft}";
802 os << "\\end{flushright}";
806 case LYX_ALIGN_RIGHT:
807 if (getParLanguage(bparams)->babel() != "hebrew") {
808 os << "\\end{flushright}";
811 os << "\\end{flushleft}";
815 case LYX_ALIGN_CENTER:
816 os << "\\end{center}";
824 // This one spits out the text of the paragraph
825 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
826 BufferParams const & bparams,
827 LyXFont const & outerfont,
828 ostream & os, TexRow & texrow,
829 LatexRunParams const & runparams)
831 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
833 bool return_value = false;
837 // well we have to check if we are in an inset with unlimited
838 // lenght (all in one row) if that is true then we don't allow
839 // any special options in the paragraph and also we don't allow
840 // any environment other then "Standard" to be valid!
842 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
845 style = bparams.getLyXTextClass().defaultLayout();
852 // Maybe we have to create a optional argument.
855 // FIXME: can we actually skip this check and just call
856 // beginningOfBody() ??
857 if (style->labeltype != LABEL_MANUAL) {
860 body_pos = beginningOfBody();
863 unsigned int column = 0;
868 basefont = getLabelFont(bparams, outerfont);
870 basefont = getLayoutFont(bparams, outerfont);
873 bool moving_arg = runparams.moving_arg;
874 moving_arg |= style->needprotect;
876 // Which font is currently active?
877 LyXFont running_font(basefont);
878 // Do we have an open font change?
879 bool open_font = false;
881 Change::Type running_change = Change::UNCHANGED;
883 texrow.start(id(), 0);
885 // if the paragraph is empty, the loop will not be entered at all
887 if (style->isCommand()) {
892 column += startTeXParParams(bparams, os, moving_arg);
896 for (pos_type i = 0; i < size(); ++i) {
898 // First char in paragraph or after label?
902 column += running_font.latexWriteEndChanges(os, basefont, basefont);
905 basefont = getLayoutFont(bparams, outerfont);
906 running_font = basefont;
910 if (style->isCommand()) {
916 column += startTeXParParams(bparams, os,
920 value_type c = getChar(i);
922 // Fully instantiated font
923 LyXFont font = getFont(bparams, i, outerfont);
925 LyXFont const last_font = running_font;
927 // Spaces at end of font change are simulated to be
928 // outside font change, i.e. we write "\textXX{text} "
929 // rather than "\textXX{text }". (Asger)
930 if (open_font && c == ' ' && i <= size() - 2) {
931 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
932 if (next_font != running_font
933 && next_font != font) {
938 // We end font definition before blanks
940 (font != running_font ||
941 font.language() != running_font.language()))
943 column += running_font.latexWriteEndChanges(os,
945 (i == body_pos-1) ? basefont : font);
946 running_font = basefont;
950 // Blanks are printed before start of fontswitch
952 // Do not print the separation of the optional argument
953 if (i != body_pos - 1) {
954 pimpl_->simpleTeXBlanks(os, texrow, i,
955 column, font, *style);
959 // Do we need to change font?
960 if ((font != running_font ||
961 font.language() != running_font.language()) &&
964 column += font.latexWriteStartChanges(os, basefont,
970 Change::Type change = pimpl_->lookupChange(i);
972 column += Changes::latexMarkChange(os, running_change, change);
973 running_change = change;
975 LatexRunParams rp = runparams;
976 rp.moving_arg = moving_arg;
977 rp.free_spacing = style->free_spacing;
978 pimpl_->simpleTeXSpecialChars(buf, bparams,
979 os, texrow, runparams,
981 basefont, outerfont, open_font,
983 *style, i, column, c);
986 column += Changes::latexMarkChange(os,
987 running_change, Change::UNCHANGED);
989 // If we have an open font definition, we have to close it
991 #ifdef FIXED_LANGUAGE_END_DETECTION
994 .latexWriteEndChanges(os, basefont,
995 next_->getFont(bparams,
998 running_font.latexWriteEndChanges(os, basefont,
1002 #ifdef WITH_WARNINGS
1003 //#warning For now we ALWAYS have to close the foreign font settings if they are
1004 //#warning there as we start another \selectlanguage with the next paragraph if
1005 //#warning we are in need of this. This should be fixed sometime (Jug)
1007 running_font.latexWriteEndChanges(os, basefont, basefont);
1011 // Needed if there is an optional argument but no contents.
1012 if (body_pos > 0 && body_pos == size()) {
1014 return_value = false;
1018 column += endTeXParParams(bparams, os, moving_arg);
1021 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1022 return return_value;
1028 bool Paragraph::isHfill(pos_type pos) const
1030 return IsInsetChar(getChar(pos))
1031 && getInset(pos)->lyxCode() == InsetOld::HFILL_CODE;
1035 bool Paragraph::isInset(pos_type pos) const
1037 return IsInsetChar(getChar(pos));
1041 bool Paragraph::isNewline(pos_type pos) const
1043 return IsInsetChar(getChar(pos))
1044 && getInset(pos)->lyxCode() == InsetOld::NEWLINE_CODE;
1048 bool Paragraph::isSeparator(pos_type pos) const
1050 return IsSeparatorChar(getChar(pos));
1054 bool Paragraph::isLineSeparator(pos_type pos) const
1056 value_type const c = getChar(pos);
1057 return IsLineSeparatorChar(c)
1058 || (IsInsetChar(c) && getInset(pos) &&
1059 getInset(pos)->isLineSeparator());
1063 bool Paragraph::isKomma(pos_type pos) const
1065 return IsKommaChar(getChar(pos));
1069 /// Used by the spellchecker
1070 bool Paragraph::isLetter(pos_type pos) const
1072 value_type const c = getChar(pos);
1073 if (IsLetterChar(c))
1076 return getInset(pos)->isLetter();
1077 // We want to pass the ' and escape chars to ispell
1078 string const extra = lyxrc.isp_esc_chars + '\'';
1079 return contains(extra, c);
1083 bool Paragraph::isWord(pos_type pos) const
1085 return IsWordChar(getChar(pos)) ;
1090 Paragraph::getParLanguage(BufferParams const & bparams) const
1093 return getFirstFontSettings().language();
1094 #warning FIXME we should check the prev par as well (Lgb)
1095 return bparams.language;
1099 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1101 return lyxrc.rtl_support
1102 && getParLanguage(bparams)->RightToLeft()
1103 && !(inInset() && inInset()->owner() &&
1104 inInset()->owner()->lyxCode() == InsetOld::ERT_CODE);
1108 void Paragraph::changeLanguage(BufferParams const & bparams,
1109 Language const * from, Language const * to)
1111 for (pos_type i = 0; i < size(); ++i) {
1112 LyXFont font = getFontSettings(bparams, i);
1113 if (font.language() == from) {
1114 font.setLanguage(to);
1121 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1123 Language const * doc_language = bparams.language;
1124 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1125 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1127 for (; cit != end; ++cit)
1128 if (cit->font().language() != ignore_language &&
1129 cit->font().language() != latex_language &&
1130 cit->font().language() != doc_language)
1136 // Convert the paragraph to a string.
1137 // Used for building the table of contents
1138 string const Paragraph::asString(Buffer const * buffer, bool label) const
1142 if (label && !params().labelString().empty())
1143 s += params().labelString() + ' ';
1145 for (pos_type i = 0; i < size(); ++i) {
1146 value_type c = getChar(i);
1149 else if (c == META_INSET &&
1150 getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
1152 getInset(i)->ascii(buffer, ost);
1153 s += subst(STRCONV(ost.str()),'\n',' ');
1159 // This should really be done by the caller and not here.
1160 string ret(asString(buffer, 0, size(), label));
1161 return subst(ret, '\n', ' ');
1166 string const Paragraph::asString(Buffer const * buffer,
1167 pos_type beg, pos_type end, bool label) const
1171 if (beg == 0 && label && !params().labelString().empty())
1172 os << params().labelString() << ' ';
1174 for (pos_type i = beg; i < end; ++i) {
1175 value_type const c = getUChar(buffer->params, i);
1178 else if (c == META_INSET)
1179 getInset(i)->ascii(buffer, os);
1182 return STRCONV(os.str());
1186 void Paragraph::setInsetOwner(UpdatableInset * inset)
1188 pimpl_->inset_owner = inset;
1189 InsetList::iterator it = insetlist.begin();
1190 InsetList::iterator end = insetlist.end();
1191 for (; it != end; ++it)
1193 it->inset->setOwner(inset);
1197 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1199 insetlist.deleteInsetsLyXText(bv);
1203 void Paragraph::setContentsFromPar(Paragraph const & par)
1205 pimpl_->setContentsFromPar(par);
1209 void Paragraph::trackChanges(Change::Type type)
1211 pimpl_->trackChanges(type);
1215 void Paragraph::untrackChanges()
1217 pimpl_->untrackChanges();
1221 void Paragraph::cleanChanges()
1223 pimpl_->cleanChanges();
1227 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1229 Assert(!size() || pos < size());
1230 return pimpl_->lookupChange(pos);
1234 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1236 Assert(!size() || pos < size());
1237 return pimpl_->lookupChangeFull(pos);
1241 bool Paragraph::isChanged(pos_type start, pos_type end) const
1243 return pimpl_->isChanged(start, end);
1247 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1249 return pimpl_->isChangeEdited(start, end);
1253 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1255 pimpl_->setChange(pos, type);
1260 void Paragraph::markErased()
1262 pimpl_->markErased();
1266 void Paragraph::acceptChange(pos_type start, pos_type end)
1268 return pimpl_->acceptChange(start, end);
1272 void Paragraph::rejectChange(pos_type start, pos_type end)
1274 return pimpl_->rejectChange(start, end);
1278 lyx::pos_type Paragraph::size() const
1280 return pimpl_->size();
1284 bool Paragraph::empty() const
1286 return pimpl_->empty();
1290 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1292 return pimpl_->getChar(pos);
1296 int Paragraph::id() const
1302 void Paragraph::id(int i)
1308 LyXLayout_ptr const & Paragraph::layout() const
1311 InsetOld * inset = inInset();
1312 if (inset && inset->lyxCode() == InsetOld::ENVIRONMENT_CODE)
1313 return static_cast<InsetEnvironment*>(inset)->layout();
1319 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1321 layout_ = new_layout;
1325 UpdatableInset * Paragraph::inInset() const
1327 return pimpl_->inset_owner;
1331 void Paragraph::clearContents()
1336 void Paragraph::setChar(pos_type pos, value_type c)
1338 pimpl_->setChar(pos, c);
1342 ParagraphParameters & Paragraph::params()
1344 return pimpl_->params;
1348 ParagraphParameters const & Paragraph::params() const
1350 return pimpl_->params;
1354 bool Paragraph::isFreeSpacing() const
1356 if (layout()->free_spacing)
1359 // for now we just need this, later should we need this in some
1360 // other way we can always add a function to InsetOld too.
1361 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1362 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
1367 bool Paragraph::allowEmpty() const
1369 if (layout()->keepempty)
1371 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1372 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;