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"
18 #include "tex-strings.h"
20 #include "bufferparams.h"
23 #include "BufferView.h"
25 #include "ParameterStruct.h"
29 #include "insets/insetbibitem.h"
30 #include "insets/insetoptarg.h"
32 #include "support/filetools.h"
33 #include "support/lstrings.h"
34 #include "support/lyxmanip.h"
35 #include "support/FileInfo.h"
36 #include "support/LAssert.h"
37 #include "support/textutils.h"
48 using std::lower_bound;
49 using std::upper_bound;
54 // this is a minibuffer
59 LyXFont minibuffer_font;
60 Inset * minibuffer_inset;
65 extern BufferView * current_view;
68 Paragraph::Paragraph()
69 : pimpl_(new Paragraph::Pimpl(this))
82 // This constructor inserts the new paragraph in a list.
83 // It is placed after par.
84 Paragraph::Paragraph(Paragraph * par)
85 : pimpl_(new Paragraph::Pimpl(this))
90 // double linked list begin
93 next_->previous_ = this;
95 previous_->next_ = this;
103 Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
104 : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
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.setInset(it.getInset()->clone(*current_view->buffer(),
123 // tell the new inset who is the boss now
124 it.getInset()->parOwner(this);
129 // the destructor removes the new paragraph from the list
130 Paragraph::~Paragraph()
134 previous_->next_ = next_;
136 next_->previous_ = previous_;
141 //lyxerr << "Paragraph::paragraph_id = "
142 // << Paragraph::paragraph_id << endl;
146 void Paragraph::write(Buffer const * buf, ostream & os,
147 BufferParams const & bparams,
148 depth_type & dth) const
150 // The beginning or end of a deeper (i.e. nested) area?
151 if (dth != params().depth()) {
152 if (params().depth() > dth) {
153 while (params().depth() > dth) {
154 os << "\n\\begin_deeper ";
158 while (params().depth() < dth) {
159 os << "\n\\end_deeper ";
165 // First write the layout
166 os << "\n\\layout " << layout()->name() << '\n';
168 // Maybe some vertical spaces.
169 if (params().spaceTop().kind() != VSpace::NONE)
170 os << "\\added_space_top "
171 << params().spaceTop().asLyXCommand() << ' ';
172 if (params().spaceBottom().kind() != VSpace::NONE)
173 os << "\\added_space_bottom "
174 << params().spaceBottom().asLyXCommand() << ' ';
176 // Maybe the paragraph has special spacing
177 params().spacing().writeFile(os, true);
179 // The labelwidth string used in lists.
180 if (!params().labelWidthString().empty())
181 os << "\\labelwidthstring "
182 << params().labelWidthString() << '\n';
184 // Lines above or below?
185 if (params().lineTop())
187 if (params().lineBottom())
188 os << "\\line_bottom ";
190 // Pagebreaks above or below?
191 if (params().pagebreakTop())
192 os << "\\pagebreak_top ";
193 if (params().pagebreakBottom())
194 os << "\\pagebreak_bottom ";
196 // Start of appendix?
197 if (params().startOfAppendix())
198 os << "\\start_of_appendix ";
201 if (params().noindent())
204 // Do we have a manual left indent?
205 if (!params().leftIndent().zero())
206 os << "\\leftindent " << params().leftIndent().asString()
210 if (params().align() != LYX_ALIGN_LAYOUT) {
212 switch (params().align()) {
213 case LYX_ALIGN_LEFT: h = 1; break;
214 case LYX_ALIGN_RIGHT: h = 2; break;
215 case LYX_ALIGN_CENTER: h = 3; break;
216 default: h = 0; break;
218 os << "\\align " << string_align[h] << ' ';
221 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
223 Change running_change = Change(Change::UNCHANGED);
224 lyx::time_type const curtime(lyx::current_time());
227 for (pos_type i = 0; i < size(); ++i) {
233 Change change = pimpl_->lookupChangeFull(i);
234 Changes::lyxMarkChange(os, column, curtime, running_change, change);
235 running_change = change;
237 // Write font changes
238 LyXFont font2 = getFontSettings(bparams, i);
239 if (font2 != font1) {
240 font2.lyxWriteChanges(font1, os);
245 value_type const c = getChar(i);
249 Inset const * inset = getInset(i);
251 if (inset->directWrite()) {
252 // international char, let it write
253 // code directly so it's shorter in
255 inset->write(buf, os);
257 os << "\n\\begin_inset ";
258 inset->write(buf, os);
259 os << "\n\\end_inset \n\n";
265 os << "\n\\newline \n";
269 os << "\n\\hfill \n";
273 os << "\n\\backslash \n";
277 if (i + 1 < size() && getChar(i + 1) == ' ') {
284 if ((column > 70 && c == ' ')
289 // this check is to amend a bug. LyX sometimes
290 // inserts '\0' this could cause problems.
294 lyxerr << "ERROR (Paragraph::writeFile):"
295 " NULL char in structure." << endl;
301 // to make reading work properly
303 running_change = pimpl_->lookupChange(0);
304 Changes::lyxMarkChange(os, column, curtime,
305 Change(Change::UNCHANGED), running_change);
307 Changes::lyxMarkChange(os, column, curtime,
308 running_change, Change(Change::UNCHANGED));
312 void Paragraph::validate(LaTeXFeatures & features) const
314 pimpl_->validate(features, *layout());
318 // First few functions needed for cut and paste and paragraph breaking.
319 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
321 BufferParams bparams = buffer.params;
323 minibuffer_char = getChar(pos);
324 minibuffer_font = getFontSettings(bparams, pos);
325 minibuffer_inset = 0;
326 if (minibuffer_char == Paragraph::META_INSET) {
328 minibuffer_inset = getInset(pos)->clone(buffer);
330 minibuffer_inset = 0;
331 minibuffer_char = ' ';
332 // This reflects what GetInset() does (ARRae)
338 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
340 minibuffer_char = getChar(pos);
341 minibuffer_font = getFontSettings(bparams, pos);
342 minibuffer_inset = 0;
343 if (minibuffer_char == Paragraph::META_INSET) {
345 // the inset is not in a paragraph anymore
346 minibuffer_inset = insetlist.release(pos);
347 minibuffer_inset->parOwner(0);
349 minibuffer_inset = 0;
350 minibuffer_char = ' ';
351 // This reflects what GetInset() does (ARRae)
356 // Erase(pos); now the caller is responsible for that.
360 bool Paragraph::insertFromMinibuffer(pos_type pos)
362 if (minibuffer_char == Paragraph::META_INSET) {
363 if (!insetAllowed(minibuffer_inset->lyxCode())) {
366 insertInset(pos, minibuffer_inset, minibuffer_font);
368 LyXFont f = minibuffer_font;
369 if (!checkInsertChar(f)) {
372 insertChar(pos, minibuffer_char, f);
380 void Paragraph::eraseIntern(lyx::pos_type pos)
382 pimpl_->eraseIntern(pos);
386 void Paragraph::erase(pos_type pos)
392 bool Paragraph::erase(pos_type start, pos_type end)
394 return pimpl_->erase(start, end);
398 bool Paragraph::checkInsertChar(LyXFont & font)
400 if (pimpl_->inset_owner)
401 return pimpl_->inset_owner->checkInsertChar(font);
406 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
408 LyXFont const f(LyXFont::ALL_INHERIT);
409 insertChar(pos, c, f);
413 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
414 LyXFont const & font, Change change)
416 pimpl_->insertChar(pos, c, font, change);
420 void Paragraph::insertInset(pos_type pos, Inset * inset)
422 LyXFont const f(LyXFont::ALL_INHERIT);
423 insertInset(pos, inset, f);
427 void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font, Change change)
429 pimpl_->insertInset(pos, inset, font, change);
433 bool Paragraph::insetAllowed(Inset::Code code)
435 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
437 if (pimpl_->inset_owner)
438 return pimpl_->inset_owner->insetAllowed(code);
443 Inset * Paragraph::getInset(pos_type pos)
445 lyx::Assert(pos < size());
447 return insetlist.get(pos);
451 Inset const * Paragraph::getInset(pos_type pos) const
453 lyx::Assert(pos < size());
455 return insetlist.get(pos);
459 // Gets uninstantiated font setting at position.
460 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
463 lyx::Assert(pos <= size());
465 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
466 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
467 for (; cit != end; ++cit) {
468 if (cit->pos() >= pos)
474 retfont = cit->font();
475 } else if (pos == size() && !empty()) {
476 retfont = getFontSettings(bparams, pos - 1);
478 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
484 // Gets uninstantiated font setting at position 0
485 LyXFont const Paragraph::getFirstFontSettings() const
487 if (!empty() && !pimpl_->fontlist.empty())
488 return pimpl_->fontlist[0].font();
490 return LyXFont(LyXFont::ALL_INHERIT);
494 // Gets the fully instantiated font at a given position in a paragraph
495 // This is basically the same function as LyXText::GetFont() in text2.C.
496 // The difference is that this one is used for generating the LaTeX file,
497 // and thus cosmetic "improvements" are disallowed: This has to deliver
498 // the true picture of the buffer. (Asger)
499 // If position is -1, we get the layout font of the paragraph.
500 // If position is -2, we get the font of the manual label of the paragraph.
501 LyXFont const Paragraph::getFont(BufferParams const & bparams,
504 lyx::Assert(pos >= 0);
506 LyXLayout_ptr const & lout = layout();
508 pos_type const body_pos = beginningOfBody();
512 layoutfont = lout->labelfont;
514 layoutfont = lout->font;
516 LyXFont tmpfont = getFontSettings(bparams, pos);
517 tmpfont.realize(layoutfont);
519 return pimpl_->realizeFont(tmpfont, bparams);
523 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams) const
525 LyXLayout_ptr const & lout = layout();
527 LyXFont tmpfont = lout->labelfont;
528 tmpfont.setLanguage(getParLanguage(bparams));
530 return pimpl_->realizeFont(tmpfont, bparams);
534 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams) const
536 LyXLayout_ptr const & lout = layout();
538 LyXFont tmpfont = lout->font;
539 tmpfont.setLanguage(getParLanguage(bparams));
541 return pimpl_->realizeFont(tmpfont, bparams);
545 /// Returns the height of the highest font in range
547 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
548 LyXFont::FONT_SIZE const def_size) const
550 if (pimpl_->fontlist.empty())
553 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
554 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
555 for (; end_it != end; ++end_it) {
556 if (end_it->pos() >= endpos)
563 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
564 for (; cit != end; ++cit) {
565 if (cit->pos() >= startpos)
569 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
570 for (; cit != end_it; ++cit) {
571 LyXFont::FONT_SIZE size = cit->font().size();
572 if (size == LyXFont::INHERIT_SIZE)
574 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
581 Paragraph::value_type
582 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
584 value_type c = getChar(pos);
585 if (!lyxrc.rtl_support)
615 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
622 void Paragraph::setFont(pos_type pos, LyXFont const & font)
624 lyx::Assert(pos <= size());
626 // First, reduce font against layout/label font
627 // Update: The SetCharFont() routine in text2.C already
628 // reduces font, so we don't need to do that here. (Asger)
629 // No need to simplify this because it will disappear
630 // in a new kernel. (Asger)
631 // Next search font table
633 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
634 Pimpl::FontList::iterator it = beg;
635 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
636 for (; it != endit; ++it) {
637 if (it->pos() >= pos)
640 unsigned int i = std::distance(beg, it);
641 bool notfound = (it == endit);
643 if (!notfound && pimpl_->fontlist[i].font() == font)
646 bool begin = pos == 0 || notfound ||
647 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
648 // Is position pos is a beginning of a font block?
649 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
650 // Is position pos is the end of a font block?
651 if (begin && end) { // A single char block
652 if (i + 1 < pimpl_->fontlist.size() &&
653 pimpl_->fontlist[i + 1].font() == font) {
654 // Merge the singleton block with the next block
655 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
656 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
657 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
658 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
659 // Merge the singleton block with the previous block
660 pimpl_->fontlist[i - 1].pos(pos);
661 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
663 pimpl_->fontlist[i].font(font);
665 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
666 pimpl_->fontlist[i - 1].pos(pos);
668 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
669 Pimpl::FontTable(pos, font));
671 pimpl_->fontlist[i].pos(pos - 1);
672 if (!(i + 1 < pimpl_->fontlist.size() &&
673 pimpl_->fontlist[i + 1].font() == font))
674 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
675 Pimpl::FontTable(pos, font));
676 } else { // The general case. The block is splitted into 3 blocks
677 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
678 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
679 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
680 Pimpl::FontTable(pos, font));
686 void Paragraph::next(Paragraph * p)
692 // This function is able to hide closed footnotes.
693 Paragraph * Paragraph::next()
699 Paragraph const * Paragraph::next() const
705 void Paragraph::previous(Paragraph * p)
711 // This function is able to hide closed footnotes.
712 Paragraph * Paragraph::previous()
718 // This function is able to hide closed footnotes.
719 Paragraph const * Paragraph::previous() const
726 void Paragraph::makeSameLayout(Paragraph const * par)
728 layout(par->layout());
730 params() = par->params();
734 int Paragraph::stripLeadingSpaces()
736 if (layout()->free_spacing ||
742 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
743 pimpl_->eraseIntern(0);
751 bool Paragraph::hasSameLayout(Paragraph const * par) const
754 par->layout() == layout() &&
755 params().sameLayout(par->params());
759 int Paragraph::getEndLabel() const
761 Paragraph const * par = this;
762 depth_type par_depth = getDepth();
764 LyXLayout_ptr const & layout = par->layout();
765 int const endlabeltype = layout->endlabeltype;
767 if (endlabeltype != END_LABEL_NO_LABEL) {
771 depth_type const next_depth = next_->getDepth();
772 if (par_depth > next_depth ||
773 (par_depth == next_depth
774 && layout != next_->layout()))
780 par = par->outerHook();
782 par_depth = par->getDepth();
784 return END_LABEL_NO_LABEL;
788 Paragraph::depth_type Paragraph::getDepth() const
790 return params().depth();
794 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
796 bool const isenv = layout()->isEnvironment();
799 return params().depth() + 1;
801 return params().depth();
805 char Paragraph::getAlign() const
807 return params().align();
811 string const & Paragraph::getLabelstring() const
813 return params().labelString();
817 // the next two functions are for the manual labels
818 string const Paragraph::getLabelWidthString() const
820 if (!params().labelWidthString().empty())
821 return params().labelWidthString();
823 return _("Senseless with this layout!");
827 void Paragraph::setLabelWidthString(string const & s)
829 params().labelWidthString(s);
833 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
836 params().labelWidthString(string());
837 params().align(LYX_ALIGN_LAYOUT);
838 params().spaceTop(VSpace(VSpace::NONE));
839 params().spaceBottom(VSpace(VSpace::NONE));
840 params().spacing(Spacing(Spacing::Default));
844 int Paragraph::beginningOfBody() const
846 if (layout()->labeltype != LABEL_MANUAL)
849 // Unroll the first two cycles of the loop
850 // and remember the previous character to
851 // remove unnecessary GetChar() calls
853 if (i < size() && getChar(i) != Paragraph::META_NEWLINE) {
855 char previous_char = 0;
858 && (previous_char = getChar(i)) != Paragraph::META_NEWLINE) {
859 // Yes, this ^ is supposed to be "= " not "=="
862 && previous_char != ' '
863 && (temp = getChar(i)) != Paragraph::META_NEWLINE) {
865 previous_char = temp;
874 Paragraph * Paragraph::depthHook(depth_type depth)
876 Paragraph * newpar = this;
879 newpar = newpar->previous();
880 } while (newpar && newpar->getDepth() > depth);
883 if (previous() || getDepth())
884 lyxerr << "ERROR (Paragraph::DepthHook): "
893 Paragraph const * Paragraph::depthHook(depth_type depth) const
895 Paragraph const * newpar = this;
898 newpar = newpar->previous();
899 } while (newpar && newpar->getDepth() > depth);
902 if (previous() || getDepth())
903 lyxerr << "ERROR (Paragraph::DepthHook): "
912 Paragraph * Paragraph::outerHook()
916 return depthHook(depth_type(getDepth() - 1));
920 Paragraph const * Paragraph::outerHook() const
924 return depthHook(depth_type(getDepth() - 1));
928 // returns -1 if inset not found
929 int Paragraph::getPositionOfInset(Inset const * inset) const
932 InsetList::iterator it = insetlist.begin();
933 InsetList::iterator end = insetlist.end();
934 for (; it != end; ++it)
935 if (it.getInset() == inset)
941 InsetBibitem * Paragraph::bibitem()
943 InsetList::iterator it = insetlist.begin();
944 if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
945 return static_cast<InsetBibitem *>(it.getInset());
951 // This could go to ParagraphParameters if we want to
952 int Paragraph::startTeXParParams(BufferParams const & bparams,
953 ostream & os, bool moving_arg) const
957 if (params().noindent()) {
962 switch (params().align()) {
964 case LYX_ALIGN_BLOCK:
965 case LYX_ALIGN_LAYOUT:
966 case LYX_ALIGN_SPECIAL:
969 case LYX_ALIGN_RIGHT:
970 case LYX_ALIGN_CENTER:
978 switch (params().align()) {
980 case LYX_ALIGN_BLOCK:
981 case LYX_ALIGN_LAYOUT:
982 case LYX_ALIGN_SPECIAL:
985 if (getParLanguage(bparams)->babel() != "hebrew") {
986 os << "\\begin{flushleft}";
989 os << "\\begin{flushright}";
993 case LYX_ALIGN_RIGHT:
994 if (getParLanguage(bparams)->babel() != "hebrew") {
995 os << "\\begin{flushright}";
998 os << "\\begin{flushleft}";
1002 case LYX_ALIGN_CENTER:
1003 os << "\\begin{center}";
1012 // This could go to ParagraphParameters if we want to
1013 int Paragraph::endTeXParParams(BufferParams const & bparams,
1014 ostream & os, bool moving_arg) const
1018 switch (params().align()) {
1019 case LYX_ALIGN_NONE:
1020 case LYX_ALIGN_BLOCK:
1021 case LYX_ALIGN_LAYOUT:
1022 case LYX_ALIGN_SPECIAL:
1024 case LYX_ALIGN_LEFT:
1025 case LYX_ALIGN_RIGHT:
1026 case LYX_ALIGN_CENTER:
1034 switch (params().align()) {
1035 case LYX_ALIGN_NONE:
1036 case LYX_ALIGN_BLOCK:
1037 case LYX_ALIGN_LAYOUT:
1038 case LYX_ALIGN_SPECIAL:
1040 case LYX_ALIGN_LEFT:
1041 if (getParLanguage(bparams)->babel() != "hebrew") {
1042 os << "\\end{flushleft}";
1045 os << "\\end{flushright}";
1049 case LYX_ALIGN_RIGHT:
1050 if (getParLanguage(bparams)->babel() != "hebrew") {
1051 os << "\\end{flushright}";
1054 os << "\\end{flushleft}";
1058 case LYX_ALIGN_CENTER:
1059 os << "\\end{center}";
1067 // This one spits out the text of the paragraph
1068 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
1069 BufferParams const & bparams,
1070 ostream & os, TexRow & texrow,
1073 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
1075 bool return_value = false;
1077 LyXLayout_ptr style;
1079 // well we have to check if we are in an inset with unlimited
1080 // lenght (all in one row) if that is true then we don't allow
1081 // any special options in the paragraph and also we don't allow
1082 // any environment other then "Standard" to be valid!
1084 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
1087 style = bparams.getLyXTextClass().defaultLayout();
1094 // Maybe we have to create a optional argument.
1097 // FIXME: can we actually skip this check and just call
1098 // beginningOfBody() ??
1099 if (style->labeltype != LABEL_MANUAL) {
1102 body_pos = beginningOfBody();
1105 unsigned int column = 0;
1110 basefont = getLabelFont(bparams);
1112 basefont = getLayoutFont(bparams);
1115 moving_arg |= style->needprotect;
1117 // Which font is currently active?
1118 LyXFont running_font(basefont);
1119 // Do we have an open font change?
1120 bool open_font = false;
1122 Change::Type running_change = Change::UNCHANGED;
1124 texrow.start(this, 0);
1126 // if the paragraph is empty, the loop will not be entered at all
1128 if (style->isCommand()) {
1133 column += startTeXParParams(bparams, os, moving_arg);
1137 for (pos_type i = 0; i < size(); ++i) {
1139 // First char in paragraph or after label?
1140 if (i == body_pos) {
1143 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1146 basefont = getLayoutFont(bparams);
1147 running_font = basefont;
1151 if (style->isCommand()) {
1157 column += startTeXParParams(bparams, os,
1161 value_type c = getChar(i);
1163 // Fully instantiated font
1164 LyXFont font = getFont(bparams, i);
1166 LyXFont const last_font = running_font;
1168 // Spaces at end of font change are simulated to be
1169 // outside font change, i.e. we write "\textXX{text} "
1170 // rather than "\textXX{text }". (Asger)
1171 if (open_font && c == ' ' && i <= size() - 2) {
1172 LyXFont const & next_font = getFont(bparams, i + 1);
1173 if (next_font != running_font
1174 && next_font != font) {
1179 // We end font definition before blanks
1181 (font != running_font ||
1182 font.language() != running_font.language()))
1184 column += running_font.latexWriteEndChanges(os,
1186 (i == body_pos-1) ? basefont : font);
1187 running_font = basefont;
1191 // Blanks are printed before start of fontswitch
1193 // Do not print the separation of the optional argument
1194 if (i != body_pos - 1) {
1195 pimpl_->simpleTeXBlanks(os, texrow, i,
1196 column, font, *style);
1200 // Do we need to change font?
1201 if ((font != running_font ||
1202 font.language() != running_font.language()) &&
1205 column += font.latexWriteStartChanges(os, basefont,
1207 running_font = font;
1211 Change::Type change = pimpl_->lookupChange(i);
1213 column += Changes::latexMarkChange(os, running_change, change);
1214 running_change = change;
1216 if (c == Paragraph::META_NEWLINE) {
1217 // newlines are handled differently here than
1218 // the default in SimpleTeXSpecialChars().
1219 if (!style->newline_allowed) {
1223 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1226 basefont = getLayoutFont(bparams);
1227 running_font = basefont;
1228 if (font.family() ==
1229 LyXFont::TYPEWRITER_FAMILY) {
1238 texrow.start(this, i + 1);
1241 pimpl_->simpleTeXSpecialChars(buf, bparams,
1242 os, texrow, moving_arg,
1244 basefont, open_font,
1246 *style, i, column, c);
1250 column += Changes::latexMarkChange(os,
1251 running_change, Change::UNCHANGED);
1253 // If we have an open font definition, we have to close it
1255 #ifdef FIXED_LANGUAGE_END_DETECTION
1258 .latexWriteEndChanges(os, basefont,
1259 next_->getFont(bparams,
1262 running_font.latexWriteEndChanges(os, basefont,
1266 #ifdef WITH_WARNINGS
1267 //#warning For now we ALWAYS have to close the foreign font settings if they are
1268 //#warning there as we start another \selectlanguage with the next paragraph if
1269 //#warning we are in need of this. This should be fixed sometime (Jug)
1271 running_font.latexWriteEndChanges(os, basefont, basefont);
1275 // Needed if there is an optional argument but no contents.
1276 if (body_pos > 0 && body_pos == size()) {
1278 return_value = false;
1282 column += endTeXParParams(bparams, os, moving_arg);
1285 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1286 return return_value;
1292 bool Paragraph::isHfill(pos_type pos) const
1294 return IsHfillChar(getChar(pos));
1298 bool Paragraph::isInset(pos_type pos) const
1300 return IsInsetChar(getChar(pos));
1304 bool Paragraph::isNewline(pos_type pos) const
1306 return pos >= 0 && IsNewlineChar(getChar(pos));
1310 bool Paragraph::isSeparator(pos_type pos) const
1312 return IsSeparatorChar(getChar(pos));
1316 bool Paragraph::isLineSeparator(pos_type pos) const
1318 value_type const c = getChar(pos);
1319 return IsLineSeparatorChar(c)
1320 || (IsInsetChar(c) && getInset(pos) &&
1321 getInset(pos)->isLineSeparator());
1325 bool Paragraph::isKomma(pos_type pos) const
1327 return IsKommaChar(getChar(pos));
1331 /// Used by the spellchecker
1332 bool Paragraph::isLetter(pos_type pos) const
1334 value_type const c = getChar(pos);
1335 if (IsLetterChar(c))
1338 return getInset(pos)->isLetter();
1339 // We want to pass the ' and escape chars to ispell
1340 string const extra = lyxrc.isp_esc_chars + '\'';
1341 return contains(extra, c);
1345 bool Paragraph::isWord(pos_type pos) const
1347 return IsWordChar(getChar(pos)) ;
1352 Paragraph::getParLanguage(BufferParams const & bparams) const
1355 return getFirstFontSettings().language();
1356 } else if (previous_)
1357 return previous_->getParLanguage(bparams);
1359 return bparams.language;
1363 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1365 return lyxrc.rtl_support
1366 && getParLanguage(bparams)->RightToLeft()
1367 && !(inInset() && inInset()->owner() &&
1368 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
1372 void Paragraph::changeLanguage(BufferParams const & bparams,
1373 Language const * from, Language const * to)
1375 for (pos_type i = 0; i < size(); ++i) {
1376 LyXFont font = getFontSettings(bparams, i);
1377 if (font.language() == from) {
1378 font.setLanguage(to);
1385 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1387 Language const * doc_language = bparams.language;
1388 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1389 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1391 for (; cit != end; ++cit)
1392 if (cit->font().language() != ignore_language &&
1393 cit->font().language() != latex_language &&
1394 cit->font().language() != doc_language)
1400 // Convert the paragraph to a string.
1401 // Used for building the table of contents
1402 string const Paragraph::asString(Buffer const * buffer, bool label) const
1405 if (label && !params().labelString().empty())
1406 s += params().labelString() + ' ';
1408 for (pos_type i = 0; i < size(); ++i) {
1409 value_type c = getChar(i);
1412 else if (c == META_INSET &&
1413 getInset(i)->lyxCode() == Inset::MATH_CODE) {
1415 getInset(i)->ascii(buffer, ost);
1416 s += subst(STRCONV(ost.str()),'\n',' ');
1424 string const Paragraph::asString(Buffer const * buffer,
1425 pos_type beg, pos_type end, bool label) const
1429 if (beg == 0 && label && !params().labelString().empty())
1430 ost << params().labelString() << ' ';
1432 for (pos_type i = beg; i < end; ++i) {
1433 value_type const c = getUChar(buffer->params, i);
1436 else if (c == META_NEWLINE)
1438 else if (c == META_HFILL)
1440 else if (c == META_INSET) {
1441 getInset(i)->ascii(buffer, ost);
1445 return STRCONV(ost.str());
1449 void Paragraph::setInsetOwner(Inset * i)
1451 pimpl_->inset_owner = i;
1452 InsetList::iterator it = insetlist.begin();
1453 InsetList::iterator end = insetlist.end();
1454 for (; it != end; ++it) {
1456 it.getInset()->setOwner(i);
1461 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1464 insetlist.deleteInsetsLyXText(bv);
1468 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1471 insetlist.resizeInsetsLyXText(bv);
1475 void Paragraph::setContentsFromPar(Paragraph * par)
1477 pimpl_->setContentsFromPar(par);
1481 void Paragraph::trackChanges(Change::Type type)
1483 pimpl_->trackChanges(type);
1487 void Paragraph::untrackChanges()
1489 pimpl_->untrackChanges();
1493 void Paragraph::cleanChanges()
1495 pimpl_->cleanChanges();
1499 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1501 lyx::Assert(!size() || pos < size());
1502 return pimpl_->lookupChange(pos);
1506 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1508 lyx::Assert(!size() || pos < size());
1509 return pimpl_->lookupChangeFull(pos);
1513 bool Paragraph::isChanged(pos_type start, pos_type end) const
1515 return pimpl_->isChanged(start, end);
1519 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1521 return pimpl_->isChangeEdited(start, end);
1525 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1527 pimpl_->setChange(pos, type);
1532 void Paragraph::markErased()
1534 pimpl_->markErased();
1538 void Paragraph::acceptChange(pos_type start, pos_type end)
1540 return pimpl_->acceptChange(start, end);
1544 void Paragraph::rejectChange(pos_type start, pos_type end)
1546 return pimpl_->rejectChange(start, end);
1550 lyx::pos_type Paragraph::size() const
1552 return pimpl_->size();
1556 bool Paragraph::empty() const
1558 return pimpl_->empty();
1562 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1564 return pimpl_->getChar(pos);
1568 int Paragraph::id() const
1574 LyXLayout_ptr const & Paragraph::layout() const
1580 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1582 layout_ = new_layout;
1586 bool Paragraph::isFirstInSequence() const
1588 Paragraph const * dhook = depthHook(getDepth());
1589 return (dhook == this
1590 || dhook->layout() != layout()
1591 || dhook->getDepth() != getDepth());
1595 Inset * Paragraph::inInset() const
1597 return pimpl_->inset_owner;
1601 void Paragraph::clearContents()
1606 void Paragraph::setChar(pos_type pos, value_type c)
1608 pimpl_->setChar(pos, c);
1612 ParagraphParameters & Paragraph::params()
1614 return pimpl_->params;
1618 ParagraphParameters const & Paragraph::params() const
1620 return pimpl_->params;
1624 bool Paragraph::isFreeSpacing() const
1626 // for now we just need this, later should we need this in some
1627 // other way we can always add a function to Inset::() too.
1628 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1629 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);