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 Paragraph::Paragraph(Paragraph * par)
84 : pimpl_(new Paragraph::Pimpl(this))
89 // double linked list begin
92 next_->previous_ = this;
94 previous_->next_ = this;
102 Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
103 : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
111 // this is because of the dummy layout of the paragraphs that
113 layout_ = lp.layout();
115 // copy everything behind the break-position to the new paragraph
116 insetlist = lp.insetlist;
117 InsetList::iterator it = insetlist.begin();
118 InsetList::iterator end = insetlist.end();
119 for (; it != end; ++it) {
120 it.setInset(it.getInset()->clone(*current_view->buffer(),
122 // tell the new inset who is the boss now
123 it.getInset()->parOwner(this);
128 // the destructor removes the new paragraph from the list
129 Paragraph::~Paragraph()
133 previous_->next_ = next_;
135 next_->previous_ = previous_;
140 //lyxerr << "Paragraph::paragraph_id = "
141 // << Paragraph::paragraph_id << endl;
145 void Paragraph::write(Buffer const * buf, ostream & os,
146 BufferParams const & bparams,
147 depth_type & dth) const
149 // The beginning or end of a deeper (i.e. nested) area?
150 if (dth != params().depth()) {
151 if (params().depth() > dth) {
152 while (params().depth() > dth) {
153 os << "\n\\begin_deeper ";
157 while (params().depth() < dth) {
158 os << "\n\\end_deeper ";
164 // First write the layout
165 os << "\n\\layout " << layout()->name() << '\n';
167 // Maybe some vertical spaces.
168 if (params().spaceTop().kind() != VSpace::NONE)
169 os << "\\added_space_top "
170 << params().spaceTop().asLyXCommand() << ' ';
171 if (params().spaceBottom().kind() != VSpace::NONE)
172 os << "\\added_space_bottom "
173 << params().spaceBottom().asLyXCommand() << ' ';
175 // Maybe the paragraph has special spacing
176 params().spacing().writeFile(os, true);
178 // The labelwidth string used in lists.
179 if (!params().labelWidthString().empty())
180 os << "\\labelwidthstring "
181 << params().labelWidthString() << '\n';
183 // Lines above or below?
184 if (params().lineTop())
186 if (params().lineBottom())
187 os << "\\line_bottom ";
189 // Pagebreaks above or below?
190 if (params().pagebreakTop())
191 os << "\\pagebreak_top ";
192 if (params().pagebreakBottom())
193 os << "\\pagebreak_bottom ";
195 // Start of appendix?
196 if (params().startOfAppendix())
197 os << "\\start_of_appendix ";
200 if (params().noindent())
203 // Do we have a manual left indent?
204 if (!params().leftIndent().zero())
205 os << "\\leftindent " << params().leftIndent().asString()
209 if (params().align() != LYX_ALIGN_LAYOUT) {
211 switch (params().align()) {
212 case LYX_ALIGN_LEFT: h = 1; break;
213 case LYX_ALIGN_RIGHT: h = 2; break;
214 case LYX_ALIGN_CENTER: h = 3; break;
215 default: h = 0; break;
217 os << "\\align " << string_align[h] << ' ';
220 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
222 Change running_change = Change(Change::UNCHANGED);
223 lyx::time_type const curtime(lyx::current_time());
226 for (pos_type i = 0; i < size(); ++i) {
232 Change change = pimpl_->lookupChangeFull(i);
233 Changes::lyxMarkChange(os, column, curtime, running_change, change);
234 running_change = change;
236 // Write font changes
237 LyXFont font2 = getFontSettings(bparams, i);
238 if (font2 != font1) {
239 font2.lyxWriteChanges(font1, os);
244 value_type const c = getChar(i);
248 Inset const * inset = getInset(i);
250 if (inset->directWrite()) {
251 // international char, let it write
252 // code directly so it's shorter in
254 inset->write(buf, os);
256 os << "\n\\begin_inset ";
257 inset->write(buf, os);
258 os << "\n\\end_inset \n\n";
264 os << "\n\\newline \n";
268 os << "\n\\hfill \n";
272 os << "\n\\backslash \n";
276 if (i + 1 < size() && getChar(i + 1) == ' ') {
283 if ((column > 70 && c == ' ')
288 // this check is to amend a bug. LyX sometimes
289 // inserts '\0' this could cause problems.
293 lyxerr << "ERROR (Paragraph::writeFile):"
294 " NULL char in structure." << endl;
300 // to make reading work properly
302 running_change = pimpl_->lookupChange(0);
303 Changes::lyxMarkChange(os, column, curtime,
304 Change(Change::UNCHANGED), running_change);
306 Changes::lyxMarkChange(os, column, curtime,
307 running_change, Change(Change::UNCHANGED));
311 void Paragraph::validate(LaTeXFeatures & features) const
313 pimpl_->validate(features, *layout());
317 // First few functions needed for cut and paste and paragraph breaking.
318 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
320 BufferParams bparams = buffer.params;
322 minibuffer_char = getChar(pos);
323 minibuffer_font = getFontSettings(bparams, pos);
324 minibuffer_inset = 0;
325 if (minibuffer_char == Paragraph::META_INSET) {
327 minibuffer_inset = getInset(pos)->clone(buffer);
329 minibuffer_inset = 0;
330 minibuffer_char = ' ';
331 // This reflects what GetInset() does (ARRae)
337 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
339 minibuffer_char = getChar(pos);
340 minibuffer_font = getFontSettings(bparams, pos);
341 minibuffer_inset = 0;
342 if (minibuffer_char == Paragraph::META_INSET) {
344 // the inset is not in a paragraph anymore
345 minibuffer_inset = insetlist.release(pos);
346 minibuffer_inset->parOwner(0);
348 minibuffer_inset = 0;
349 minibuffer_char = ' ';
350 // This reflects what GetInset() does (ARRae)
355 // Erase(pos); now the caller is responsible for that.
359 bool Paragraph::insertFromMinibuffer(pos_type pos)
361 if (minibuffer_char == Paragraph::META_INSET) {
362 if (!insetAllowed(minibuffer_inset->lyxCode())) {
365 insertInset(pos, minibuffer_inset, minibuffer_font);
367 LyXFont f = minibuffer_font;
368 if (!checkInsertChar(f)) {
371 insertChar(pos, minibuffer_char, f);
379 void Paragraph::eraseIntern(lyx::pos_type pos)
381 pimpl_->eraseIntern(pos);
385 void Paragraph::erase(pos_type pos)
391 bool Paragraph::erase(pos_type start, pos_type end)
393 return pimpl_->erase(start, end);
397 bool Paragraph::checkInsertChar(LyXFont & font)
399 if (pimpl_->inset_owner)
400 return pimpl_->inset_owner->checkInsertChar(font);
405 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
407 LyXFont const f(LyXFont::ALL_INHERIT);
408 insertChar(pos, c, f);
412 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
413 LyXFont const & font, Change change)
415 pimpl_->insertChar(pos, c, font, change);
419 void Paragraph::insertInset(pos_type pos, Inset * inset)
421 LyXFont const f(LyXFont::ALL_INHERIT);
422 insertInset(pos, inset, f);
426 void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font, Change change)
428 pimpl_->insertInset(pos, inset, font, change);
432 bool Paragraph::insetAllowed(Inset::Code code)
434 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
436 if (pimpl_->inset_owner)
437 return pimpl_->inset_owner->insetAllowed(code);
442 Inset * Paragraph::getInset(pos_type pos)
444 lyx::Assert(pos < size());
446 return insetlist.get(pos);
450 Inset const * Paragraph::getInset(pos_type pos) const
452 lyx::Assert(pos < size());
454 return insetlist.get(pos);
458 // Gets uninstantiated font setting at position.
459 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
462 lyx::Assert(pos <= size());
464 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
465 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
466 for (; cit != end; ++cit) {
467 if (cit->pos() >= pos)
473 retfont = cit->font();
474 } else if (pos == size() && !empty()) {
475 retfont = getFontSettings(bparams, pos - 1);
477 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
483 // Gets uninstantiated font setting at position 0
484 LyXFont const Paragraph::getFirstFontSettings() const
486 if (!empty() && !pimpl_->fontlist.empty())
487 return pimpl_->fontlist[0].font();
489 return LyXFont(LyXFont::ALL_INHERIT);
493 // Gets the fully instantiated font at a given position in a paragraph
494 // This is basically the same function as LyXText::GetFont() in text2.C.
495 // The difference is that this one is used for generating the LaTeX file,
496 // and thus cosmetic "improvements" are disallowed: This has to deliver
497 // the true picture of the buffer. (Asger)
498 // If position is -1, we get the layout font of the paragraph.
499 // If position is -2, we get the font of the manual label of the paragraph.
500 LyXFont const Paragraph::getFont(BufferParams const & bparams,
503 lyx::Assert(pos >= 0);
505 LyXLayout_ptr const & lout = layout();
507 pos_type const main_body = beginningOfMainBody();
511 layoutfont = lout->labelfont;
513 layoutfont = lout->font;
515 LyXFont tmpfont = getFontSettings(bparams, pos);
516 tmpfont.realize(layoutfont);
518 return pimpl_->realizeFont(tmpfont, bparams);
522 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams) const
524 LyXLayout_ptr const & lout = layout();
526 LyXFont tmpfont = lout->labelfont;
527 tmpfont.setLanguage(getParLanguage(bparams));
529 return pimpl_->realizeFont(tmpfont, bparams);
533 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams) const
535 LyXLayout_ptr const & lout = layout();
537 LyXFont tmpfont = lout->font;
538 tmpfont.setLanguage(getParLanguage(bparams));
540 return pimpl_->realizeFont(tmpfont, bparams);
544 /// Returns the height of the highest font in range
546 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
547 LyXFont::FONT_SIZE const def_size) const
549 if (pimpl_->fontlist.empty())
552 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
553 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
554 for (; end_it != end; ++end_it) {
555 if (end_it->pos() >= endpos)
562 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
563 for (; cit != end; ++cit) {
564 if (cit->pos() >= startpos)
568 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
569 for (; cit != end_it; ++cit) {
570 LyXFont::FONT_SIZE size = cit->font().size();
571 if (size == LyXFont::INHERIT_SIZE)
573 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
580 Paragraph::value_type
581 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
583 value_type c = getChar(pos);
584 if (!lyxrc.rtl_support)
614 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
621 void Paragraph::setFont(pos_type pos, LyXFont const & font)
623 lyx::Assert(pos <= size());
625 // First, reduce font against layout/label font
626 // Update: The SetCharFont() routine in text2.C already
627 // reduces font, so we don't need to do that here. (Asger)
628 // No need to simplify this because it will disappear
629 // in a new kernel. (Asger)
630 // Next search font table
632 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
633 Pimpl::FontList::iterator it = beg;
634 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
635 for (; it != endit; ++it) {
636 if (it->pos() >= pos)
639 unsigned int i = std::distance(beg, it);
640 bool notfound = (it == endit);
642 if (!notfound && pimpl_->fontlist[i].font() == font)
645 bool begin = pos == 0 || notfound ||
646 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
647 // Is position pos is a beginning of a font block?
648 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
649 // Is position pos is the end of a font block?
650 if (begin && end) { // A single char block
651 if (i + 1 < pimpl_->fontlist.size() &&
652 pimpl_->fontlist[i + 1].font() == font) {
653 // Merge the singleton block with the next block
654 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
655 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
656 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
657 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
658 // Merge the singleton block with the previous block
659 pimpl_->fontlist[i - 1].pos(pos);
660 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
662 pimpl_->fontlist[i].font(font);
664 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
665 pimpl_->fontlist[i - 1].pos(pos);
667 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
668 Pimpl::FontTable(pos, font));
670 pimpl_->fontlist[i].pos(pos - 1);
671 if (!(i + 1 < pimpl_->fontlist.size() &&
672 pimpl_->fontlist[i + 1].font() == font))
673 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
674 Pimpl::FontTable(pos, font));
675 } else { // The general case. The block is splitted into 3 blocks
676 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
677 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
678 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
679 Pimpl::FontTable(pos, font));
685 void Paragraph::next(Paragraph * p)
691 // This function is able to hide closed footnotes.
692 Paragraph * Paragraph::next()
698 Paragraph const * Paragraph::next() const
704 void Paragraph::previous(Paragraph * p)
710 // This function is able to hide closed footnotes.
711 Paragraph * Paragraph::previous()
717 // This function is able to hide closed footnotes.
718 Paragraph const * Paragraph::previous() const
725 void Paragraph::makeSameLayout(Paragraph const * par)
727 layout(par->layout());
729 params() = par->params();
733 int Paragraph::stripLeadingSpaces()
735 if (layout()->free_spacing ||
741 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
742 pimpl_->eraseIntern(0);
750 bool Paragraph::hasSameLayout(Paragraph const * par) const
753 par->layout() == layout() &&
754 params().sameLayout(par->params());
758 int Paragraph::getEndLabel() const
760 Paragraph const * par = this;
761 depth_type par_depth = getDepth();
763 LyXLayout_ptr const & layout = par->layout();
764 int const endlabeltype = layout->endlabeltype;
766 if (endlabeltype != END_LABEL_NO_LABEL) {
770 depth_type const next_depth = next_->getDepth();
771 if (par_depth > next_depth ||
772 (par_depth == next_depth
773 && layout != next_->layout()))
779 par = par->outerHook();
781 par_depth = par->getDepth();
783 return END_LABEL_NO_LABEL;
787 Paragraph::depth_type Paragraph::getDepth() const
789 return params().depth();
793 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
795 bool const isenv = layout()->isEnvironment();
798 return params().depth() + 1;
800 return params().depth();
804 char Paragraph::getAlign() const
806 return params().align();
810 string const & Paragraph::getLabelstring() const
812 return params().labelString();
816 // the next two functions are for the manual labels
817 string const Paragraph::getLabelWidthString() const
819 if (!params().labelWidthString().empty())
820 return params().labelWidthString();
822 return _("Senseless with this layout!");
826 void Paragraph::setLabelWidthString(string const & s)
828 params().labelWidthString(s);
832 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
835 params().labelWidthString(string());
836 params().align(LYX_ALIGN_LAYOUT);
837 params().spaceTop(VSpace(VSpace::NONE));
838 params().spaceBottom(VSpace(VSpace::NONE));
839 params().spacing(Spacing(Spacing::Default));
843 // if the layout of a paragraph contains a manual label, the beginning of the
844 // main body is the beginning of the second word. This is what the par-
845 // function returns. If the layout does not contain a label, the main
846 // body always starts with position 0. This differentiation is necessary,
847 // because there cannot be a newline or a blank <= the beginning of the
850 int Paragraph::beginningOfMainBody() const
852 if (layout()->labeltype != LABEL_MANUAL)
855 // Unroll the first two cycles of the loop
856 // and remember the previous character to
857 // remove unnecessary GetChar() calls
859 if (i < size() && getChar(i) != Paragraph::META_NEWLINE) {
861 char previous_char = 0;
864 && (previous_char = getChar(i)) != Paragraph::META_NEWLINE) {
865 // Yes, this ^ is supposed to be "= " not "=="
868 && previous_char != ' '
869 && (temp = getChar(i)) != Paragraph::META_NEWLINE) {
871 previous_char = temp;
880 Paragraph * Paragraph::depthHook(depth_type depth)
882 Paragraph * newpar = this;
885 newpar = newpar->previous();
886 } while (newpar && newpar->getDepth() > depth);
889 if (previous() || getDepth())
890 lyxerr << "ERROR (Paragraph::DepthHook): "
899 Paragraph const * Paragraph::depthHook(depth_type depth) const
901 Paragraph const * newpar = this;
904 newpar = newpar->previous();
905 } while (newpar && newpar->getDepth() > depth);
908 if (previous() || getDepth())
909 lyxerr << "ERROR (Paragraph::DepthHook): "
918 Paragraph * Paragraph::outerHook()
922 return depthHook(depth_type(getDepth() - 1));
926 Paragraph const * Paragraph::outerHook() const
930 return depthHook(depth_type(getDepth() - 1));
934 // returns -1 if inset not found
935 int Paragraph::getPositionOfInset(Inset const * inset) const
938 InsetList::iterator it = insetlist.begin();
939 InsetList::iterator end = insetlist.end();
940 for (; it != end; ++it)
941 if (it.getInset() == inset)
947 InsetBibitem * Paragraph::bibitem()
949 InsetList::iterator it = insetlist.begin();
950 if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
951 return static_cast<InsetBibitem *>(it.getInset());
957 // This could go to ParagraphParameters if we want to
958 int Paragraph::startTeXParParams(BufferParams const & bparams,
959 ostream & os, bool moving_arg) const
963 if (params().noindent()) {
968 switch (params().align()) {
970 case LYX_ALIGN_BLOCK:
971 case LYX_ALIGN_LAYOUT:
972 case LYX_ALIGN_SPECIAL:
975 case LYX_ALIGN_RIGHT:
976 case LYX_ALIGN_CENTER:
984 switch (params().align()) {
986 case LYX_ALIGN_BLOCK:
987 case LYX_ALIGN_LAYOUT:
988 case LYX_ALIGN_SPECIAL:
991 if (getParLanguage(bparams)->babel() != "hebrew") {
992 os << "\\begin{flushleft}";
995 os << "\\begin{flushright}";
999 case LYX_ALIGN_RIGHT:
1000 if (getParLanguage(bparams)->babel() != "hebrew") {
1001 os << "\\begin{flushright}";
1004 os << "\\begin{flushleft}";
1008 case LYX_ALIGN_CENTER:
1009 os << "\\begin{center}";
1018 // This could go to ParagraphParameters if we want to
1019 int Paragraph::endTeXParParams(BufferParams const & bparams,
1020 ostream & os, bool moving_arg) const
1024 switch (params().align()) {
1025 case LYX_ALIGN_NONE:
1026 case LYX_ALIGN_BLOCK:
1027 case LYX_ALIGN_LAYOUT:
1028 case LYX_ALIGN_SPECIAL:
1030 case LYX_ALIGN_LEFT:
1031 case LYX_ALIGN_RIGHT:
1032 case LYX_ALIGN_CENTER:
1040 switch (params().align()) {
1041 case LYX_ALIGN_NONE:
1042 case LYX_ALIGN_BLOCK:
1043 case LYX_ALIGN_LAYOUT:
1044 case LYX_ALIGN_SPECIAL:
1046 case LYX_ALIGN_LEFT:
1047 if (getParLanguage(bparams)->babel() != "hebrew") {
1048 os << "\\end{flushleft}";
1051 os << "\\end{flushright}";
1055 case LYX_ALIGN_RIGHT:
1056 if (getParLanguage(bparams)->babel() != "hebrew") {
1057 os << "\\end{flushright}";
1060 os << "\\end{flushleft}";
1064 case LYX_ALIGN_CENTER:
1065 os << "\\end{center}";
1073 // This one spits out the text of the paragraph
1074 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
1075 BufferParams const & bparams,
1076 ostream & os, TexRow & texrow,
1079 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
1081 bool return_value = false;
1083 LyXLayout_ptr style;
1085 // well we have to check if we are in an inset with unlimited
1086 // lenght (all in one row) if that is true then we don't allow
1087 // any special options in the paragraph and also we don't allow
1088 // any environment other then "Standard" to be valid!
1090 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
1093 style = bparams.getLyXTextClass().defaultLayout();
1100 // Maybe we have to create a optional argument.
1103 // FIXME: can we actually skip this check and just call
1104 // beginningOfMainBody() ??
1105 if (style->labeltype != LABEL_MANUAL) {
1108 main_body = beginningOfMainBody();
1111 unsigned int column = 0;
1113 if (main_body > 0) {
1116 basefont = getLabelFont(bparams);
1118 basefont = getLayoutFont(bparams);
1121 moving_arg |= style->needprotect;
1123 // Which font is currently active?
1124 LyXFont running_font(basefont);
1125 // Do we have an open font change?
1126 bool open_font = false;
1128 Change::Type running_change = Change::UNCHANGED;
1130 texrow.start(this, 0);
1132 // if the paragraph is empty, the loop will not be entered at all
1134 if (style->isCommand()) {
1139 column += startTeXParParams(bparams, os, moving_arg);
1143 for (pos_type i = 0; i < size(); ++i) {
1145 // First char in paragraph or after label?
1146 if (i == main_body) {
1147 if (main_body > 0) {
1149 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1152 basefont = getLayoutFont(bparams);
1153 running_font = basefont;
1157 if (style->isCommand()) {
1163 column += startTeXParParams(bparams, os,
1167 value_type c = getChar(i);
1169 // Fully instantiated font
1170 LyXFont font = getFont(bparams, i);
1172 LyXFont const last_font = running_font;
1174 // Spaces at end of font change are simulated to be
1175 // outside font change, i.e. we write "\textXX{text} "
1176 // rather than "\textXX{text }". (Asger)
1177 if (open_font && c == ' ' && i <= size() - 2) {
1178 LyXFont const & next_font = getFont(bparams, i + 1);
1179 if (next_font != running_font
1180 && next_font != font) {
1185 // We end font definition before blanks
1187 (font != running_font ||
1188 font.language() != running_font.language()))
1190 column += running_font.latexWriteEndChanges(os,
1192 (i == main_body-1) ? basefont : font);
1193 running_font = basefont;
1197 // Blanks are printed before start of fontswitch
1199 // Do not print the separation of the optional argument
1200 if (i != main_body - 1) {
1201 pimpl_->simpleTeXBlanks(os, texrow, i,
1202 column, font, *style);
1206 // Do we need to change font?
1207 if ((font != running_font ||
1208 font.language() != running_font.language()) &&
1211 column += font.latexWriteStartChanges(os, basefont,
1213 running_font = font;
1217 Change::Type change = pimpl_->lookupChange(i);
1219 column += Changes::latexMarkChange(os, running_change, change);
1220 running_change = change;
1222 if (c == Paragraph::META_NEWLINE) {
1223 // newlines are handled differently here than
1224 // the default in SimpleTeXSpecialChars().
1225 if (!style->newline_allowed) {
1229 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1232 basefont = getLayoutFont(bparams);
1233 running_font = basefont;
1234 if (font.family() ==
1235 LyXFont::TYPEWRITER_FAMILY) {
1244 texrow.start(this, i + 1);
1247 pimpl_->simpleTeXSpecialChars(buf, bparams,
1248 os, texrow, moving_arg,
1250 basefont, open_font,
1252 *style, i, column, c);
1256 column += Changes::latexMarkChange(os,
1257 running_change, Change::UNCHANGED);
1259 // If we have an open font definition, we have to close it
1261 #ifdef FIXED_LANGUAGE_END_DETECTION
1264 .latexWriteEndChanges(os, basefont,
1265 next_->getFont(bparams,
1268 running_font.latexWriteEndChanges(os, basefont,
1272 #ifdef WITH_WARNINGS
1273 //#warning For now we ALWAYS have to close the foreign font settings if they are
1274 //#warning there as we start another \selectlanguage with the next paragraph if
1275 //#warning we are in need of this. This should be fixed sometime (Jug)
1277 running_font.latexWriteEndChanges(os, basefont, basefont);
1281 // Needed if there is an optional argument but no contents.
1282 if (main_body > 0 && main_body == size()) {
1284 return_value = false;
1288 column += endTeXParParams(bparams, os, moving_arg);
1291 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1292 return return_value;
1298 bool Paragraph::isHfill(pos_type pos) const
1300 return IsHfillChar(getChar(pos));
1304 bool Paragraph::isInset(pos_type pos) const
1306 return IsInsetChar(getChar(pos));
1310 bool Paragraph::isNewline(pos_type pos) const
1312 return pos >= 0 && IsNewlineChar(getChar(pos));
1316 bool Paragraph::isSeparator(pos_type pos) const
1318 return IsSeparatorChar(getChar(pos));
1322 bool Paragraph::isLineSeparator(pos_type pos) const
1324 value_type const c = getChar(pos);
1325 return IsLineSeparatorChar(c)
1326 || (IsInsetChar(c) && getInset(pos) &&
1327 getInset(pos)->isLineSeparator());
1331 bool Paragraph::isKomma(pos_type pos) const
1333 return IsKommaChar(getChar(pos));
1337 /// Used by the spellchecker
1338 bool Paragraph::isLetter(pos_type pos) const
1340 value_type const c = getChar(pos);
1341 if (IsLetterChar(c))
1344 return getInset(pos)->isLetter();
1345 // We want to pass the ' and escape chars to ispell
1346 string const extra = lyxrc.isp_esc_chars + '\'';
1347 return contains(extra, c);
1351 bool Paragraph::isWord(pos_type pos) const
1353 return IsWordChar(getChar(pos)) ;
1358 Paragraph::getParLanguage(BufferParams const & bparams) const
1361 return getFirstFontSettings().language();
1362 } else if (previous_)
1363 return previous_->getParLanguage(bparams);
1365 return bparams.language;
1369 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1371 return lyxrc.rtl_support
1372 && getParLanguage(bparams)->RightToLeft()
1373 && !(inInset() && inInset()->owner() &&
1374 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
1378 void Paragraph::changeLanguage(BufferParams const & bparams,
1379 Language const * from, Language const * to)
1381 for (pos_type i = 0; i < size(); ++i) {
1382 LyXFont font = getFontSettings(bparams, i);
1383 if (font.language() == from) {
1384 font.setLanguage(to);
1391 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1393 Language const * doc_language = bparams.language;
1394 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1395 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1397 for (; cit != end; ++cit)
1398 if (cit->font().language() != ignore_language &&
1399 cit->font().language() != latex_language &&
1400 cit->font().language() != doc_language)
1406 // Convert the paragraph to a string.
1407 // Used for building the table of contents
1408 string const Paragraph::asString(Buffer const * buffer, bool label) const
1411 if (label && !params().labelString().empty())
1412 s += params().labelString() + ' ';
1414 for (pos_type i = 0; i < size(); ++i) {
1415 value_type c = getChar(i);
1418 else if (c == META_INSET &&
1419 getInset(i)->lyxCode() == Inset::MATH_CODE) {
1421 getInset(i)->ascii(buffer, ost);
1422 s += subst(STRCONV(ost.str()),'\n',' ');
1430 string const Paragraph::asString(Buffer const * buffer,
1431 pos_type beg, pos_type end, bool label) const
1435 if (beg == 0 && label && !params().labelString().empty())
1436 ost << params().labelString() << ' ';
1438 for (pos_type i = beg; i < end; ++i) {
1439 value_type const c = getUChar(buffer->params, i);
1442 else if (c == META_NEWLINE)
1444 else if (c == META_HFILL)
1446 else if (c == META_INSET) {
1447 getInset(i)->ascii(buffer, ost);
1451 return STRCONV(ost.str());
1455 void Paragraph::setInsetOwner(Inset * i)
1457 pimpl_->inset_owner = i;
1458 InsetList::iterator it = insetlist.begin();
1459 InsetList::iterator end = insetlist.end();
1460 for (; it != end; ++it) {
1462 it.getInset()->setOwner(i);
1467 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1470 insetlist.deleteInsetsLyXText(bv);
1474 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1477 insetlist.resizeInsetsLyXText(bv);
1481 void Paragraph::setContentsFromPar(Paragraph * par)
1483 pimpl_->setContentsFromPar(par);
1487 void Paragraph::trackChanges(Change::Type type)
1489 pimpl_->trackChanges(type);
1493 void Paragraph::untrackChanges()
1495 pimpl_->untrackChanges();
1499 void Paragraph::cleanChanges()
1501 pimpl_->cleanChanges();
1505 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1507 lyx::Assert(!size() || pos < size());
1508 return pimpl_->lookupChange(pos);
1512 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1514 lyx::Assert(!size() || pos < size());
1515 return pimpl_->lookupChangeFull(pos);
1519 bool Paragraph::isChanged(pos_type start, pos_type end) const
1521 return pimpl_->isChanged(start, end);
1525 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1527 return pimpl_->isChangeEdited(start, end);
1531 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1533 pimpl_->setChange(pos, type);
1538 void Paragraph::markErased()
1540 pimpl_->markErased();
1544 void Paragraph::acceptChange(pos_type start, pos_type end)
1546 return pimpl_->acceptChange(start, end);
1550 void Paragraph::rejectChange(pos_type start, pos_type end)
1552 return pimpl_->rejectChange(start, end);
1556 lyx::pos_type Paragraph::size() const
1558 return pimpl_->size();
1562 bool Paragraph::empty() const
1564 return pimpl_->empty();
1568 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1570 return pimpl_->getChar(pos);
1574 int Paragraph::id() const
1580 LyXLayout_ptr const & Paragraph::layout() const
1586 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1588 layout_ = new_layout;
1592 bool Paragraph::isFirstInSequence() const
1594 Paragraph const * dhook = depthHook(getDepth());
1595 return (dhook == this
1596 || dhook->layout() != layout()
1597 || dhook->getDepth() != getDepth());
1601 Inset * Paragraph::inInset() const
1603 return pimpl_->inset_owner;
1607 void Paragraph::clearContents()
1612 void Paragraph::setChar(pos_type pos, value_type c)
1614 pimpl_->setChar(pos, c);
1618 ParagraphParameters & Paragraph::params()
1620 return pimpl_->params;
1624 ParagraphParameters const & Paragraph::params() const
1626 return pimpl_->params;
1630 bool Paragraph::isFreeSpacing() const
1632 // for now we just need this, later should we need this in some
1633 // other way we can always add a function to Inset::() too.
1634 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1635 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);