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"
53 using std::lower_bound;
54 using std::upper_bound;
59 // this is a minibuffer
64 LyXFont minibuffer_font;
65 Inset * minibuffer_inset;
70 extern BufferView * current_view;
73 Paragraph::Paragraph()
74 : pimpl_(new Paragraph::Pimpl(this))
86 Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
87 : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
95 // this is because of the dummy layout of the paragraphs that
97 layout_ = lp.layout();
99 // copy everything behind the break-position to the new paragraph
100 insetlist = lp.insetlist;
101 InsetList::iterator it = insetlist.begin();
102 InsetList::iterator end = insetlist.end();
103 for (; it != end; ++it) {
104 it.setInset(it.getInset()->clone(*current_view->buffer(),
106 // tell the new inset who is the boss now
107 it.getInset()->parOwner(this);
112 // the destructor removes the new paragraph from the list
113 Paragraph::~Paragraph()
117 //lyxerr << "Paragraph::paragraph_id = "
118 // << Paragraph::paragraph_id << endl;
122 void Paragraph::write(Buffer const * buf, ostream & os,
123 BufferParams const & bparams,
124 depth_type & dth) const
126 // The beginning or end of a deeper (i.e. nested) area?
127 if (dth != params().depth()) {
128 if (params().depth() > dth) {
129 while (params().depth() > dth) {
130 os << "\n\\begin_deeper ";
134 while (params().depth() < dth) {
135 os << "\n\\end_deeper ";
141 // First write the layout
142 os << "\n\\layout " << layout()->name() << '\n';
146 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
148 Change running_change = Change(Change::UNCHANGED);
149 lyx::time_type const curtime(lyx::current_time());
152 for (pos_type i = 0; i < size(); ++i) {
158 Change change = pimpl_->lookupChangeFull(i);
159 Changes::lyxMarkChange(os, column, curtime, running_change, change);
160 running_change = change;
162 // Write font changes
163 LyXFont font2 = getFontSettings(bparams, i);
164 if (font2 != font1) {
165 font2.lyxWriteChanges(font1, os);
170 value_type const c = getChar(i);
174 Inset const * inset = getInset(i);
176 if (inset->directWrite()) {
177 // international char, let it write
178 // code directly so it's shorter in
180 inset->write(buf, os);
182 os << "\n\\begin_inset ";
183 inset->write(buf, os);
184 os << "\n\\end_inset \n\n";
190 os << "\n\\backslash \n";
194 if (i + 1 < size() && getChar(i + 1) == ' ') {
201 if ((column > 70 && c == ' ')
206 // this check is to amend a bug. LyX sometimes
207 // inserts '\0' this could cause problems.
211 lyxerr << "ERROR (Paragraph::writeFile):"
212 " NULL char in structure." << endl;
218 // to make reading work properly
220 running_change = pimpl_->lookupChange(0);
221 Changes::lyxMarkChange(os, column, curtime,
222 Change(Change::UNCHANGED), running_change);
224 Changes::lyxMarkChange(os, column, curtime,
225 running_change, Change(Change::UNCHANGED));
229 void Paragraph::validate(LaTeXFeatures & features) const
231 pimpl_->validate(features, *layout());
235 // First few functions needed for cut and paste and paragraph breaking.
236 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
238 BufferParams bparams = buffer.params;
240 minibuffer_char = getChar(pos);
241 minibuffer_font = getFontSettings(bparams, pos);
242 minibuffer_inset = 0;
243 if (minibuffer_char == Paragraph::META_INSET) {
245 minibuffer_inset = getInset(pos)->clone(buffer);
247 minibuffer_inset = 0;
248 minibuffer_char = ' ';
249 // This reflects what GetInset() does (ARRae)
255 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
257 minibuffer_char = getChar(pos);
258 minibuffer_font = getFontSettings(bparams, pos);
259 minibuffer_inset = 0;
260 if (minibuffer_char == Paragraph::META_INSET) {
262 // the inset is not in a paragraph anymore
263 minibuffer_inset = insetlist.release(pos);
264 minibuffer_inset->parOwner(0);
266 minibuffer_inset = 0;
267 minibuffer_char = ' ';
268 // This reflects what GetInset() does (ARRae)
273 // Erase(pos); now the caller is responsible for that.
277 bool Paragraph::insertFromMinibuffer(pos_type pos)
279 if (minibuffer_char == Paragraph::META_INSET) {
280 if (!insetAllowed(minibuffer_inset->lyxCode())) {
283 insertInset(pos, minibuffer_inset, minibuffer_font);
285 LyXFont f = minibuffer_font;
286 if (!checkInsertChar(f)) {
289 insertChar(pos, minibuffer_char, f);
297 void Paragraph::eraseIntern(lyx::pos_type pos)
299 pimpl_->eraseIntern(pos);
303 bool Paragraph::erase(pos_type pos)
305 return pimpl_->erase(pos);
309 int Paragraph::erase(pos_type start, pos_type end)
311 return pimpl_->erase(start, end);
315 bool Paragraph::checkInsertChar(LyXFont & font)
317 if (pimpl_->inset_owner)
318 return pimpl_->inset_owner->checkInsertChar(font);
323 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
325 LyXFont const f(LyXFont::ALL_INHERIT);
326 insertChar(pos, c, f);
330 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
331 LyXFont const & font, Change change)
333 pimpl_->insertChar(pos, c, font, change);
337 void Paragraph::insertInset(pos_type pos, Inset * inset)
339 LyXFont const f(LyXFont::ALL_INHERIT);
340 insertInset(pos, inset, f);
344 void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font, Change change)
346 pimpl_->insertInset(pos, inset, font, change);
350 bool Paragraph::insetAllowed(Inset::Code code)
352 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
353 if (pimpl_->inset_owner)
354 return pimpl_->inset_owner->insetAllowed(code);
359 Inset * Paragraph::getInset(pos_type pos)
361 lyx::Assert(pos < size());
362 return insetlist.get(pos);
366 Inset const * Paragraph::getInset(pos_type pos) const
368 lyx::Assert(pos < size());
369 return insetlist.get(pos);
373 // Gets uninstantiated font setting at position.
374 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
377 lyx::Assert(pos <= size());
379 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
380 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
381 for (; cit != end; ++cit) {
382 if (cit->pos() >= pos)
388 retfont = cit->font();
389 else if (pos == size() && !empty())
390 retfont = getFontSettings(bparams, pos - 1);
392 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
398 // Gets uninstantiated font setting at position 0
399 LyXFont const Paragraph::getFirstFontSettings() const
401 if (!empty() && !pimpl_->fontlist.empty())
402 return pimpl_->fontlist[0].font();
404 return LyXFont(LyXFont::ALL_INHERIT);
408 // Gets the fully instantiated font at a given position in a paragraph
409 // This is basically the same function as LyXText::GetFont() in text2.C.
410 // The difference is that this one is used for generating the LaTeX file,
411 // and thus cosmetic "improvements" are disallowed: This has to deliver
412 // the true picture of the buffer. (Asger)
413 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
414 LyXFont const & outerfont) const
416 lyx::Assert(pos >= 0);
418 LyXLayout_ptr const & lout = layout();
420 pos_type const body_pos = beginningOfBody();
424 layoutfont = lout->labelfont;
426 layoutfont = lout->font;
428 LyXFont tmpfont = getFontSettings(bparams, pos);
429 tmpfont.realize(layoutfont);
430 tmpfont.realize(outerfont);
432 return realizeFont(tmpfont, bparams);
436 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
437 LyXFont const & outerfont) const
439 LyXLayout_ptr const & lout = layout();
441 LyXFont tmpfont = lout->labelfont;
442 tmpfont.setLanguage(getParLanguage(bparams));
443 tmpfont.realize(outerfont);
445 return realizeFont(tmpfont, bparams);
449 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
450 LyXFont const & outerfont) const
452 LyXLayout_ptr const & lout = layout();
454 LyXFont tmpfont = lout->font;
455 tmpfont.setLanguage(getParLanguage(bparams));
456 tmpfont.realize(outerfont);
458 return realizeFont(tmpfont, bparams);
462 /// Returns the height of the highest font in range
464 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
465 LyXFont::FONT_SIZE const def_size) const
467 if (pimpl_->fontlist.empty())
470 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
471 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
472 for (; end_it != end; ++end_it) {
473 if (end_it->pos() >= endpos)
480 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
481 for (; cit != end; ++cit) {
482 if (cit->pos() >= startpos)
486 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
487 for (; cit != end_it; ++cit) {
488 LyXFont::FONT_SIZE size = cit->font().size();
489 if (size == LyXFont::INHERIT_SIZE)
491 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
498 Paragraph::value_type
499 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
501 value_type c = getChar(pos);
502 if (!lyxrc.rtl_support)
532 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
539 void Paragraph::setFont(pos_type pos, LyXFont const & font)
541 lyx::Assert(pos <= size());
543 // First, reduce font against layout/label font
544 // Update: The SetCharFont() routine in text2.C already
545 // reduces font, so we don't need to do that here. (Asger)
546 // No need to simplify this because it will disappear
547 // in a new kernel. (Asger)
548 // Next search font table
550 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
551 Pimpl::FontList::iterator it = beg;
552 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
553 for (; it != endit; ++it) {
554 if (it->pos() >= pos)
557 unsigned int i = std::distance(beg, it);
558 bool notfound = (it == endit);
560 if (!notfound && pimpl_->fontlist[i].font() == font)
563 bool begin = pos == 0 || notfound ||
564 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
565 // Is position pos is a beginning of a font block?
566 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
567 // Is position pos is the end of a font block?
568 if (begin && end) { // A single char block
569 if (i + 1 < pimpl_->fontlist.size() &&
570 pimpl_->fontlist[i + 1].font() == font) {
571 // Merge the singleton block with the next block
572 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
573 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
574 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
575 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
576 // Merge the singleton block with the previous block
577 pimpl_->fontlist[i - 1].pos(pos);
578 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
580 pimpl_->fontlist[i].font(font);
582 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
583 pimpl_->fontlist[i - 1].pos(pos);
585 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
586 Pimpl::FontTable(pos, font));
588 pimpl_->fontlist[i].pos(pos - 1);
589 if (!(i + 1 < pimpl_->fontlist.size() &&
590 pimpl_->fontlist[i + 1].font() == font))
591 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
592 Pimpl::FontTable(pos, font));
593 } else { // The general case. The block is splitted into 3 blocks
594 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
595 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
596 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
597 Pimpl::FontTable(pos, font));
602 void Paragraph::makeSameLayout(Paragraph const & par)
604 layout(par.layout());
606 params() = par.params();
610 int Paragraph::stripLeadingSpaces()
612 if (layout()->free_spacing || isFreeSpacing())
616 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
617 pimpl_->eraseIntern(0);
625 bool Paragraph::hasSameLayout(Paragraph const & par) const
628 par.layout() == layout() &&
629 params().sameLayout(par.params());
633 Paragraph::depth_type Paragraph::getDepth() const
635 return params().depth();
639 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
641 if (layout()->isEnvironment())
642 return params().depth() + 1;
644 return params().depth();
648 char Paragraph::getAlign() const
650 return params().align();
654 string const & Paragraph::getLabelstring() const
656 return params().labelString();
660 // the next two functions are for the manual labels
661 string const Paragraph::getLabelWidthString() const
663 if (!params().labelWidthString().empty())
664 return params().labelWidthString();
666 return _("Senseless with this layout!");
670 void Paragraph::setLabelWidthString(string const & s)
672 params().labelWidthString(s);
676 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
679 params().labelWidthString(string());
680 params().align(LYX_ALIGN_LAYOUT);
681 params().spaceTop(VSpace(VSpace::NONE));
682 params().spaceBottom(VSpace(VSpace::NONE));
683 params().spacing(Spacing(Spacing::Default));
687 int Paragraph::beginningOfBody() const
689 if (layout()->labeltype != LABEL_MANUAL)
692 // Unroll the first two cycles of the loop
693 // and remember the previous character to
694 // remove unnecessary GetChar() calls
696 if (i < size() && !isNewline(i)) {
698 char previous_char = 0;
701 previous_char = getChar(i);
704 while (i < size() && previous_char != ' ') {
710 previous_char = temp;
720 // returns -1 if inset not found
721 int Paragraph::getPositionOfInset(Inset const * inset) const
724 InsetList::iterator it = insetlist.begin();
725 InsetList::iterator end = insetlist.end();
726 for (; it != end; ++it)
727 if (it.getInset() == inset)
733 InsetBibitem * Paragraph::bibitem()
735 InsetList::iterator it = insetlist.begin();
736 if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
737 return static_cast<InsetBibitem *>(it.getInset());
743 // This could go to ParagraphParameters if we want to
744 int Paragraph::startTeXParParams(BufferParams const & bparams,
745 ostream & os, bool moving_arg) const
749 if (params().noindent()) {
754 switch (params().align()) {
756 case LYX_ALIGN_BLOCK:
757 case LYX_ALIGN_LAYOUT:
758 case LYX_ALIGN_SPECIAL:
761 case LYX_ALIGN_RIGHT:
762 case LYX_ALIGN_CENTER:
770 switch (params().align()) {
772 case LYX_ALIGN_BLOCK:
773 case LYX_ALIGN_LAYOUT:
774 case LYX_ALIGN_SPECIAL:
777 if (getParLanguage(bparams)->babel() != "hebrew") {
778 os << "\\begin{flushleft}";
781 os << "\\begin{flushright}";
785 case LYX_ALIGN_RIGHT:
786 if (getParLanguage(bparams)->babel() != "hebrew") {
787 os << "\\begin{flushright}";
790 os << "\\begin{flushleft}";
794 case LYX_ALIGN_CENTER:
795 os << "\\begin{center}";
804 // This could go to ParagraphParameters if we want to
805 int Paragraph::endTeXParParams(BufferParams const & bparams,
806 ostream & os, bool moving_arg) const
810 switch (params().align()) {
812 case LYX_ALIGN_BLOCK:
813 case LYX_ALIGN_LAYOUT:
814 case LYX_ALIGN_SPECIAL:
817 case LYX_ALIGN_RIGHT:
818 case LYX_ALIGN_CENTER:
826 switch (params().align()) {
828 case LYX_ALIGN_BLOCK:
829 case LYX_ALIGN_LAYOUT:
830 case LYX_ALIGN_SPECIAL:
833 if (getParLanguage(bparams)->babel() != "hebrew") {
834 os << "\\end{flushleft}";
837 os << "\\end{flushright}";
841 case LYX_ALIGN_RIGHT:
842 if (getParLanguage(bparams)->babel() != "hebrew") {
843 os << "\\end{flushright}";
846 os << "\\end{flushleft}";
850 case LYX_ALIGN_CENTER:
851 os << "\\end{center}";
859 // This one spits out the text of the paragraph
860 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
861 BufferParams const & bparams,
862 LyXFont const & outerfont,
863 ostream & os, TexRow & texrow,
864 LatexRunParams const & runparams)
866 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
868 bool return_value = false;
872 // well we have to check if we are in an inset with unlimited
873 // lenght (all in one row) if that is true then we don't allow
874 // any special options in the paragraph and also we don't allow
875 // any environment other then "Standard" to be valid!
877 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
880 style = bparams.getLyXTextClass().defaultLayout();
887 // Maybe we have to create a optional argument.
890 // FIXME: can we actually skip this check and just call
891 // beginningOfBody() ??
892 if (style->labeltype != LABEL_MANUAL) {
895 body_pos = beginningOfBody();
898 unsigned int column = 0;
903 basefont = getLabelFont(bparams, outerfont);
905 basefont = getLayoutFont(bparams, outerfont);
908 bool moving_arg = runparams.moving_arg;
909 moving_arg |= style->needprotect;
911 // Which font is currently active?
912 LyXFont running_font(basefont);
913 // Do we have an open font change?
914 bool open_font = false;
916 Change::Type running_change = Change::UNCHANGED;
918 texrow.start(id(), 0);
920 // if the paragraph is empty, the loop will not be entered at all
922 if (style->isCommand()) {
927 column += startTeXParParams(bparams, os, moving_arg);
931 for (pos_type i = 0; i < size(); ++i) {
933 // First char in paragraph or after label?
937 column += running_font.latexWriteEndChanges(os, basefont, basefont);
940 basefont = getLayoutFont(bparams, outerfont);
941 running_font = basefont;
945 if (style->isCommand()) {
951 column += startTeXParParams(bparams, os,
955 value_type c = getChar(i);
957 // Fully instantiated font
958 LyXFont font = getFont(bparams, i, outerfont);
960 LyXFont const last_font = running_font;
962 // Spaces at end of font change are simulated to be
963 // outside font change, i.e. we write "\textXX{text} "
964 // rather than "\textXX{text }". (Asger)
965 if (open_font && c == ' ' && i <= size() - 2) {
966 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
967 if (next_font != running_font
968 && next_font != font) {
973 // We end font definition before blanks
975 (font != running_font ||
976 font.language() != running_font.language()))
978 column += running_font.latexWriteEndChanges(os,
980 (i == body_pos-1) ? basefont : font);
981 running_font = basefont;
985 // Blanks are printed before start of fontswitch
987 // Do not print the separation of the optional argument
988 if (i != body_pos - 1) {
989 pimpl_->simpleTeXBlanks(os, texrow, i,
990 column, font, *style);
994 // Do we need to change font?
995 if ((font != running_font ||
996 font.language() != running_font.language()) &&
999 column += font.latexWriteStartChanges(os, basefont,
1001 running_font = font;
1005 Change::Type change = pimpl_->lookupChange(i);
1007 column += Changes::latexMarkChange(os, running_change, change);
1008 running_change = change;
1010 LatexRunParams rp = runparams;
1011 rp.moving_arg = moving_arg;
1012 rp.free_spacing = style->free_spacing;
1013 pimpl_->simpleTeXSpecialChars(buf, bparams,
1014 os, texrow, runparams,
1016 basefont, outerfont, open_font,
1018 *style, i, column, c);
1021 column += Changes::latexMarkChange(os,
1022 running_change, Change::UNCHANGED);
1024 // If we have an open font definition, we have to close it
1026 #ifdef FIXED_LANGUAGE_END_DETECTION
1029 .latexWriteEndChanges(os, basefont,
1030 next_->getFont(bparams,
1033 running_font.latexWriteEndChanges(os, basefont,
1037 #ifdef WITH_WARNINGS
1038 //#warning For now we ALWAYS have to close the foreign font settings if they are
1039 //#warning there as we start another \selectlanguage with the next paragraph if
1040 //#warning we are in need of this. This should be fixed sometime (Jug)
1042 running_font.latexWriteEndChanges(os, basefont, basefont);
1046 // Needed if there is an optional argument but no contents.
1047 if (body_pos > 0 && body_pos == size()) {
1049 return_value = false;
1053 column += endTeXParParams(bparams, os, moving_arg);
1056 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1057 return return_value;
1063 bool Paragraph::isHfill(pos_type pos) const
1065 return IsInsetChar(getChar(pos))
1066 && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
1070 bool Paragraph::isInset(pos_type pos) const
1072 return IsInsetChar(getChar(pos));
1076 bool Paragraph::isNewline(pos_type pos) const
1078 return IsInsetChar(getChar(pos))
1079 && getInset(pos)->lyxCode() == Inset::NEWLINE_CODE;
1083 bool Paragraph::isSeparator(pos_type pos) const
1085 return IsSeparatorChar(getChar(pos));
1089 bool Paragraph::isLineSeparator(pos_type pos) const
1091 value_type const c = getChar(pos);
1092 return IsLineSeparatorChar(c)
1093 || (IsInsetChar(c) && getInset(pos) &&
1094 getInset(pos)->isLineSeparator());
1098 bool Paragraph::isKomma(pos_type pos) const
1100 return IsKommaChar(getChar(pos));
1104 /// Used by the spellchecker
1105 bool Paragraph::isLetter(pos_type pos) const
1107 value_type const c = getChar(pos);
1108 if (IsLetterChar(c))
1111 return getInset(pos)->isLetter();
1112 // We want to pass the ' and escape chars to ispell
1113 string const extra = lyxrc.isp_esc_chars + '\'';
1114 return contains(extra, c);
1118 bool Paragraph::isWord(pos_type pos) const
1120 return IsWordChar(getChar(pos)) ;
1125 Paragraph::getParLanguage(BufferParams const & bparams) const
1128 return getFirstFontSettings().language();
1129 #warning FIXME we should check the prev par as well (Lgb)
1131 } else if (previous_) {
1132 return previous_->getParLanguage(bparams);
1135 return bparams.language;
1139 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1141 return lyxrc.rtl_support
1142 && getParLanguage(bparams)->RightToLeft()
1143 && !(inInset() && inInset()->owner() &&
1144 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
1148 void Paragraph::changeLanguage(BufferParams const & bparams,
1149 Language const * from, Language const * to)
1151 for (pos_type i = 0; i < size(); ++i) {
1152 LyXFont font = getFontSettings(bparams, i);
1153 if (font.language() == from) {
1154 font.setLanguage(to);
1161 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1163 Language const * doc_language = bparams.language;
1164 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1165 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1167 for (; cit != end; ++cit)
1168 if (cit->font().language() != ignore_language &&
1169 cit->font().language() != latex_language &&
1170 cit->font().language() != doc_language)
1176 // Convert the paragraph to a string.
1177 // Used for building the table of contents
1178 string const Paragraph::asString(Buffer const * buffer, bool label) const
1181 if (label && !params().labelString().empty())
1182 s += params().labelString() + ' ';
1184 for (pos_type i = 0; i < size(); ++i) {
1185 value_type c = getChar(i);
1188 else if (c == META_INSET &&
1189 getInset(i)->lyxCode() == Inset::MATH_CODE) {
1191 getInset(i)->ascii(buffer, ost);
1192 s += subst(STRCONV(ost.str()),'\n',' ');
1200 string const Paragraph::asString(Buffer const * buffer,
1201 pos_type beg, pos_type end, bool label) const
1205 if (beg == 0 && label && !params().labelString().empty())
1206 os << params().labelString() << ' ';
1208 for (pos_type i = beg; i < end; ++i) {
1209 value_type const c = getUChar(buffer->params, i);
1212 else if (c == META_INSET)
1213 getInset(i)->ascii(buffer, os);
1216 return STRCONV(os.str());
1220 void Paragraph::setInsetOwner(Inset * i)
1222 pimpl_->inset_owner = i;
1223 InsetList::iterator it = insetlist.begin();
1224 InsetList::iterator end = insetlist.end();
1225 for (; it != end; ++it)
1227 it.getInset()->setOwner(i);
1231 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1234 insetlist.deleteInsetsLyXText(bv);
1238 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1241 insetlist.resizeInsetsLyXText(bv);
1245 void Paragraph::setContentsFromPar(Paragraph const & par)
1247 pimpl_->setContentsFromPar(par);
1251 void Paragraph::trackChanges(Change::Type type)
1253 pimpl_->trackChanges(type);
1257 void Paragraph::untrackChanges()
1259 pimpl_->untrackChanges();
1263 void Paragraph::cleanChanges()
1265 pimpl_->cleanChanges();
1269 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1271 lyx::Assert(!size() || pos < size());
1272 return pimpl_->lookupChange(pos);
1276 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1278 lyx::Assert(!size() || pos < size());
1279 return pimpl_->lookupChangeFull(pos);
1283 bool Paragraph::isChanged(pos_type start, pos_type end) const
1285 return pimpl_->isChanged(start, end);
1289 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1291 return pimpl_->isChangeEdited(start, end);
1295 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1297 pimpl_->setChange(pos, type);
1302 void Paragraph::markErased()
1304 pimpl_->markErased();
1308 void Paragraph::acceptChange(pos_type start, pos_type end)
1310 return pimpl_->acceptChange(start, end);
1314 void Paragraph::rejectChange(pos_type start, pos_type end)
1316 return pimpl_->rejectChange(start, end);
1320 lyx::pos_type Paragraph::size() const
1322 return pimpl_->size();
1326 bool Paragraph::empty() const
1328 return pimpl_->empty();
1332 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1334 return pimpl_->getChar(pos);
1338 int Paragraph::id() const
1344 LyXLayout_ptr const & Paragraph::layout() const
1346 Inset * inset = inInset();
1347 if (inset && inset->lyxCode() == Inset::ENVIRONMENT_CODE)
1348 return static_cast<InsetEnvironment*>(inset)->layout();
1353 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1355 layout_ = new_layout;
1359 Inset * Paragraph::inInset() const
1361 return pimpl_->inset_owner;
1365 void Paragraph::clearContents()
1370 void Paragraph::setChar(pos_type pos, value_type c)
1372 pimpl_->setChar(pos, c);
1376 ParagraphParameters & Paragraph::params()
1378 return pimpl_->params;
1382 ParagraphParameters const & Paragraph::params() const
1384 return pimpl_->params;
1388 bool Paragraph::isFreeSpacing() const
1390 // for now we just need this, later should we need this in some
1391 // other way we can always add a function to Inset::() too.
1392 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1393 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);