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"
19 #include "bufferparams.h"
22 #include "BufferView.h"
24 #include "ParameterStruct.h"
28 #include "insets/insetbibitem.h"
29 #include "insets/insetoptarg.h"
31 #include "support/filetools.h"
32 #include "support/lstrings.h"
33 #include "support/lyxmanip.h"
34 #include "support/FileInfo.h"
35 #include "support/LAssert.h"
36 #include "support/textutils.h"
47 using std::lower_bound;
48 using std::upper_bound;
53 // this is a minibuffer
58 LyXFont minibuffer_font;
59 Inset * minibuffer_inset;
64 extern BufferView * current_view;
67 Paragraph::Paragraph()
68 : pimpl_(new Paragraph::Pimpl(this))
81 // This constructor inserts the new paragraph in a list.
82 // It is placed after par.
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';
169 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
171 Change running_change = Change(Change::UNCHANGED);
172 lyx::time_type const curtime(lyx::current_time());
175 for (pos_type i = 0; i < size(); ++i) {
181 Change change = pimpl_->lookupChangeFull(i);
182 Changes::lyxMarkChange(os, column, curtime, running_change, change);
183 running_change = change;
185 // Write font changes
186 LyXFont font2 = getFontSettings(bparams, i);
187 if (font2 != font1) {
188 font2.lyxWriteChanges(font1, os);
193 value_type const c = getChar(i);
197 Inset const * inset = getInset(i);
199 if (inset->directWrite()) {
200 // international char, let it write
201 // code directly so it's shorter in
203 inset->write(buf, os);
205 os << "\n\\begin_inset ";
206 inset->write(buf, os);
207 os << "\n\\end_inset \n\n";
213 os << "\n\\newline \n";
217 os << "\n\\backslash \n";
221 if (i + 1 < size() && getChar(i + 1) == ' ') {
228 if ((column > 70 && c == ' ')
233 // this check is to amend a bug. LyX sometimes
234 // inserts '\0' this could cause problems.
238 lyxerr << "ERROR (Paragraph::writeFile):"
239 " NULL char in structure." << endl;
245 // to make reading work properly
247 running_change = pimpl_->lookupChange(0);
248 Changes::lyxMarkChange(os, column, curtime,
249 Change(Change::UNCHANGED), running_change);
251 Changes::lyxMarkChange(os, column, curtime,
252 running_change, Change(Change::UNCHANGED));
256 void Paragraph::validate(LaTeXFeatures & features) const
258 pimpl_->validate(features, *layout());
262 // First few functions needed for cut and paste and paragraph breaking.
263 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
265 BufferParams bparams = buffer.params;
267 minibuffer_char = getChar(pos);
268 minibuffer_font = getFontSettings(bparams, pos);
269 minibuffer_inset = 0;
270 if (minibuffer_char == Paragraph::META_INSET) {
272 minibuffer_inset = getInset(pos)->clone(buffer);
274 minibuffer_inset = 0;
275 minibuffer_char = ' ';
276 // This reflects what GetInset() does (ARRae)
282 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
284 minibuffer_char = getChar(pos);
285 minibuffer_font = getFontSettings(bparams, pos);
286 minibuffer_inset = 0;
287 if (minibuffer_char == Paragraph::META_INSET) {
289 // the inset is not in a paragraph anymore
290 minibuffer_inset = insetlist.release(pos);
291 minibuffer_inset->parOwner(0);
293 minibuffer_inset = 0;
294 minibuffer_char = ' ';
295 // This reflects what GetInset() does (ARRae)
300 // Erase(pos); now the caller is responsible for that.
304 bool Paragraph::insertFromMinibuffer(pos_type pos)
306 if (minibuffer_char == Paragraph::META_INSET) {
307 if (!insetAllowed(minibuffer_inset->lyxCode())) {
310 insertInset(pos, minibuffer_inset, minibuffer_font);
312 LyXFont f = minibuffer_font;
313 if (!checkInsertChar(f)) {
316 insertChar(pos, minibuffer_char, f);
324 void Paragraph::eraseIntern(lyx::pos_type pos)
326 pimpl_->eraseIntern(pos);
330 void Paragraph::erase(pos_type pos)
336 bool Paragraph::erase(pos_type start, pos_type end)
338 return pimpl_->erase(start, end);
342 bool Paragraph::checkInsertChar(LyXFont & font)
344 if (pimpl_->inset_owner)
345 return pimpl_->inset_owner->checkInsertChar(font);
350 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
352 LyXFont const f(LyXFont::ALL_INHERIT);
353 insertChar(pos, c, f);
357 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
358 LyXFont const & font, Change change)
360 pimpl_->insertChar(pos, c, font, change);
364 void Paragraph::insertInset(pos_type pos, Inset * inset)
366 LyXFont const f(LyXFont::ALL_INHERIT);
367 insertInset(pos, inset, f);
371 void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font, Change change)
373 pimpl_->insertInset(pos, inset, font, change);
377 bool Paragraph::insetAllowed(Inset::Code code)
379 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
380 if (pimpl_->inset_owner)
381 return pimpl_->inset_owner->insetAllowed(code);
386 Inset * Paragraph::getInset(pos_type pos)
388 lyx::Assert(pos < size());
389 return insetlist.get(pos);
393 Inset const * Paragraph::getInset(pos_type pos) const
395 lyx::Assert(pos < size());
396 return insetlist.get(pos);
400 // Gets uninstantiated font setting at position.
401 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
404 lyx::Assert(pos <= size());
406 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
407 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
408 for (; cit != end; ++cit) {
409 if (cit->pos() >= pos)
415 retfont = cit->font();
416 else if (pos == size() && !empty())
417 retfont = getFontSettings(bparams, pos - 1);
419 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
425 // Gets uninstantiated font setting at position 0
426 LyXFont const Paragraph::getFirstFontSettings() const
428 if (!empty() && !pimpl_->fontlist.empty())
429 return pimpl_->fontlist[0].font();
431 return LyXFont(LyXFont::ALL_INHERIT);
435 // Gets the fully instantiated font at a given position in a paragraph
436 // This is basically the same function as LyXText::GetFont() in text2.C.
437 // The difference is that this one is used for generating the LaTeX file,
438 // and thus cosmetic "improvements" are disallowed: This has to deliver
439 // the true picture of the buffer. (Asger)
440 // If position is -1, we get the layout font of the paragraph.
441 // If position is -2, we get the font of the manual label of the paragraph.
442 LyXFont const Paragraph::getFont(BufferParams const & bparams,
445 lyx::Assert(pos >= 0);
447 LyXLayout_ptr const & lout = layout();
449 pos_type const body_pos = beginningOfBody();
453 layoutfont = lout->labelfont;
455 layoutfont = lout->font;
457 LyXFont tmpfont = getFontSettings(bparams, pos);
458 tmpfont.realize(layoutfont);
460 return pimpl_->realizeFont(tmpfont, bparams);
464 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams) const
466 LyXLayout_ptr const & lout = layout();
468 LyXFont tmpfont = lout->labelfont;
469 tmpfont.setLanguage(getParLanguage(bparams));
471 return pimpl_->realizeFont(tmpfont, bparams);
475 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams) const
477 LyXLayout_ptr const & lout = layout();
479 LyXFont tmpfont = lout->font;
480 tmpfont.setLanguage(getParLanguage(bparams));
482 return pimpl_->realizeFont(tmpfont, bparams);
486 /// Returns the height of the highest font in range
488 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
489 LyXFont::FONT_SIZE const def_size) const
491 if (pimpl_->fontlist.empty())
494 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
495 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
496 for (; end_it != end; ++end_it) {
497 if (end_it->pos() >= endpos)
504 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
505 for (; cit != end; ++cit) {
506 if (cit->pos() >= startpos)
510 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
511 for (; cit != end_it; ++cit) {
512 LyXFont::FONT_SIZE size = cit->font().size();
513 if (size == LyXFont::INHERIT_SIZE)
515 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
522 Paragraph::value_type
523 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
525 value_type c = getChar(pos);
526 if (!lyxrc.rtl_support)
556 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
563 void Paragraph::setFont(pos_type pos, LyXFont const & font)
565 lyx::Assert(pos <= size());
567 // First, reduce font against layout/label font
568 // Update: The SetCharFont() routine in text2.C already
569 // reduces font, so we don't need to do that here. (Asger)
570 // No need to simplify this because it will disappear
571 // in a new kernel. (Asger)
572 // Next search font table
574 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
575 Pimpl::FontList::iterator it = beg;
576 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
577 for (; it != endit; ++it) {
578 if (it->pos() >= pos)
581 unsigned int i = std::distance(beg, it);
582 bool notfound = (it == endit);
584 if (!notfound && pimpl_->fontlist[i].font() == font)
587 bool begin = pos == 0 || notfound ||
588 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
589 // Is position pos is a beginning of a font block?
590 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
591 // Is position pos is the end of a font block?
592 if (begin && end) { // A single char block
593 if (i + 1 < pimpl_->fontlist.size() &&
594 pimpl_->fontlist[i + 1].font() == font) {
595 // Merge the singleton block with the next block
596 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
597 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
598 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
599 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
600 // Merge the singleton block with the previous block
601 pimpl_->fontlist[i - 1].pos(pos);
602 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
604 pimpl_->fontlist[i].font(font);
606 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
607 pimpl_->fontlist[i - 1].pos(pos);
609 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
610 Pimpl::FontTable(pos, font));
612 pimpl_->fontlist[i].pos(pos - 1);
613 if (!(i + 1 < pimpl_->fontlist.size() &&
614 pimpl_->fontlist[i + 1].font() == font))
615 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
616 Pimpl::FontTable(pos, font));
617 } else { // The general case. The block is splitted into 3 blocks
618 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
619 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
620 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
621 Pimpl::FontTable(pos, font));
627 void Paragraph::next(Paragraph * p)
633 // This function is able to hide closed footnotes.
634 Paragraph * Paragraph::next()
640 Paragraph const * Paragraph::next() const
646 void Paragraph::previous(Paragraph * p)
652 // This function is able to hide closed footnotes.
653 Paragraph * Paragraph::previous()
659 // This function is able to hide closed footnotes.
660 Paragraph const * Paragraph::previous() const
667 void Paragraph::makeSameLayout(Paragraph const * par)
669 layout(par->layout());
671 params() = par->params();
675 int Paragraph::stripLeadingSpaces()
677 if (layout()->free_spacing || isFreeSpacing())
681 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
682 pimpl_->eraseIntern(0);
690 bool Paragraph::hasSameLayout(Paragraph const * par) const
693 par->layout() == layout() &&
694 params().sameLayout(par->params());
698 int Paragraph::getEndLabel() const
700 Paragraph const * par = this;
701 depth_type par_depth = getDepth();
703 LyXLayout_ptr const & layout = par->layout();
704 int const endlabeltype = layout->endlabeltype;
706 if (endlabeltype != END_LABEL_NO_LABEL) {
710 depth_type const next_depth = next_->getDepth();
711 if (par_depth > next_depth ||
712 (par_depth == next_depth
713 && layout != next_->layout()))
719 par = par->outerHook();
721 par_depth = par->getDepth();
723 return END_LABEL_NO_LABEL;
727 Paragraph::depth_type Paragraph::getDepth() const
729 return params().depth();
733 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
735 if (layout()->isEnvironment())
736 return params().depth() + 1;
738 return params().depth();
742 char Paragraph::getAlign() const
744 return params().align();
748 string const & Paragraph::getLabelstring() const
750 return params().labelString();
754 // the next two functions are for the manual labels
755 string const Paragraph::getLabelWidthString() const
757 if (!params().labelWidthString().empty())
758 return params().labelWidthString();
760 return _("Senseless with this layout!");
764 void Paragraph::setLabelWidthString(string const & s)
766 params().labelWidthString(s);
770 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
773 params().labelWidthString(string());
774 params().align(LYX_ALIGN_LAYOUT);
775 params().spaceTop(VSpace(VSpace::NONE));
776 params().spaceBottom(VSpace(VSpace::NONE));
777 params().spacing(Spacing(Spacing::Default));
781 int Paragraph::beginningOfBody() const
783 if (layout()->labeltype != LABEL_MANUAL)
786 // Unroll the first two cycles of the loop
787 // and remember the previous character to
788 // remove unnecessary GetChar() calls
790 if (i < size() && getChar(i) != Paragraph::META_NEWLINE) {
792 char previous_char = 0;
795 && (previous_char = getChar(i)) != Paragraph::META_NEWLINE) {
796 // Yes, this ^ is supposed to be "= " not "=="
799 && previous_char != ' '
800 && (temp = getChar(i)) != Paragraph::META_NEWLINE) {
802 previous_char = temp;
811 Paragraph * Paragraph::depthHook(depth_type depth)
813 Paragraph * newpar = this;
816 newpar = newpar->previous();
817 } while (newpar && newpar->getDepth() > depth);
820 if (previous() || getDepth())
821 lyxerr << "ERROR (Paragraph::DepthHook): "
830 Paragraph const * Paragraph::depthHook(depth_type depth) const
832 Paragraph const * newpar = this;
835 newpar = newpar->previous();
836 } while (newpar && newpar->getDepth() > depth);
839 if (previous() || getDepth())
840 lyxerr << "ERROR (Paragraph::DepthHook): "
849 Paragraph * Paragraph::outerHook()
853 return depthHook(depth_type(getDepth() - 1));
857 Paragraph const * Paragraph::outerHook() const
861 return depthHook(depth_type(getDepth() - 1));
865 // returns -1 if inset not found
866 int Paragraph::getPositionOfInset(Inset const * inset) const
869 InsetList::iterator it = insetlist.begin();
870 InsetList::iterator end = insetlist.end();
871 for (; it != end; ++it)
872 if (it.getInset() == inset)
878 InsetBibitem * Paragraph::bibitem()
880 InsetList::iterator it = insetlist.begin();
881 if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
882 return static_cast<InsetBibitem *>(it.getInset());
888 // This could go to ParagraphParameters if we want to
889 int Paragraph::startTeXParParams(BufferParams const & bparams,
890 ostream & os, bool moving_arg) const
894 if (params().noindent()) {
899 switch (params().align()) {
901 case LYX_ALIGN_BLOCK:
902 case LYX_ALIGN_LAYOUT:
903 case LYX_ALIGN_SPECIAL:
906 case LYX_ALIGN_RIGHT:
907 case LYX_ALIGN_CENTER:
915 switch (params().align()) {
917 case LYX_ALIGN_BLOCK:
918 case LYX_ALIGN_LAYOUT:
919 case LYX_ALIGN_SPECIAL:
922 if (getParLanguage(bparams)->babel() != "hebrew") {
923 os << "\\begin{flushleft}";
926 os << "\\begin{flushright}";
930 case LYX_ALIGN_RIGHT:
931 if (getParLanguage(bparams)->babel() != "hebrew") {
932 os << "\\begin{flushright}";
935 os << "\\begin{flushleft}";
939 case LYX_ALIGN_CENTER:
940 os << "\\begin{center}";
949 // This could go to ParagraphParameters if we want to
950 int Paragraph::endTeXParParams(BufferParams const & bparams,
951 ostream & os, bool moving_arg) const
955 switch (params().align()) {
957 case LYX_ALIGN_BLOCK:
958 case LYX_ALIGN_LAYOUT:
959 case LYX_ALIGN_SPECIAL:
962 case LYX_ALIGN_RIGHT:
963 case LYX_ALIGN_CENTER:
971 switch (params().align()) {
973 case LYX_ALIGN_BLOCK:
974 case LYX_ALIGN_LAYOUT:
975 case LYX_ALIGN_SPECIAL:
978 if (getParLanguage(bparams)->babel() != "hebrew") {
979 os << "\\end{flushleft}";
982 os << "\\end{flushright}";
986 case LYX_ALIGN_RIGHT:
987 if (getParLanguage(bparams)->babel() != "hebrew") {
988 os << "\\end{flushright}";
991 os << "\\end{flushleft}";
995 case LYX_ALIGN_CENTER:
996 os << "\\end{center}";
1004 // This one spits out the text of the paragraph
1005 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
1006 BufferParams const & bparams,
1007 ostream & os, TexRow & texrow,
1010 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
1012 bool return_value = false;
1014 LyXLayout_ptr style;
1016 // well we have to check if we are in an inset with unlimited
1017 // lenght (all in one row) if that is true then we don't allow
1018 // any special options in the paragraph and also we don't allow
1019 // any environment other then "Standard" to be valid!
1021 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
1024 style = bparams.getLyXTextClass().defaultLayout();
1031 // Maybe we have to create a optional argument.
1034 // FIXME: can we actually skip this check and just call
1035 // beginningOfBody() ??
1036 if (style->labeltype != LABEL_MANUAL) {
1039 body_pos = beginningOfBody();
1042 unsigned int column = 0;
1047 basefont = getLabelFont(bparams);
1049 basefont = getLayoutFont(bparams);
1052 moving_arg |= style->needprotect;
1054 // Which font is currently active?
1055 LyXFont running_font(basefont);
1056 // Do we have an open font change?
1057 bool open_font = false;
1059 Change::Type running_change = Change::UNCHANGED;
1061 texrow.start(this, 0);
1063 // if the paragraph is empty, the loop will not be entered at all
1065 if (style->isCommand()) {
1070 column += startTeXParParams(bparams, os, moving_arg);
1074 for (pos_type i = 0; i < size(); ++i) {
1076 // First char in paragraph or after label?
1077 if (i == body_pos) {
1080 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1083 basefont = getLayoutFont(bparams);
1084 running_font = basefont;
1088 if (style->isCommand()) {
1094 column += startTeXParParams(bparams, os,
1098 value_type c = getChar(i);
1100 // Fully instantiated font
1101 LyXFont font = getFont(bparams, i);
1103 LyXFont const last_font = running_font;
1105 // Spaces at end of font change are simulated to be
1106 // outside font change, i.e. we write "\textXX{text} "
1107 // rather than "\textXX{text }". (Asger)
1108 if (open_font && c == ' ' && i <= size() - 2) {
1109 LyXFont const & next_font = getFont(bparams, i + 1);
1110 if (next_font != running_font
1111 && next_font != font) {
1116 // We end font definition before blanks
1118 (font != running_font ||
1119 font.language() != running_font.language()))
1121 column += running_font.latexWriteEndChanges(os,
1123 (i == body_pos-1) ? basefont : font);
1124 running_font = basefont;
1128 // Blanks are printed before start of fontswitch
1130 // Do not print the separation of the optional argument
1131 if (i != body_pos - 1) {
1132 pimpl_->simpleTeXBlanks(os, texrow, i,
1133 column, font, *style);
1137 // Do we need to change font?
1138 if ((font != running_font ||
1139 font.language() != running_font.language()) &&
1142 column += font.latexWriteStartChanges(os, basefont,
1144 running_font = font;
1148 Change::Type change = pimpl_->lookupChange(i);
1150 column += Changes::latexMarkChange(os, running_change, change);
1151 running_change = change;
1153 if (c == Paragraph::META_NEWLINE) {
1154 // newlines are handled differently here than
1155 // the default in SimpleTeXSpecialChars().
1156 if (!style->newline_allowed) {
1160 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1163 basefont = getLayoutFont(bparams);
1164 running_font = basefont;
1165 if (font.family() ==
1166 LyXFont::TYPEWRITER_FAMILY) {
1175 texrow.start(this, i + 1);
1178 pimpl_->simpleTeXSpecialChars(buf, bparams,
1179 os, texrow, moving_arg,
1181 basefont, open_font,
1183 *style, i, column, c);
1187 column += Changes::latexMarkChange(os,
1188 running_change, Change::UNCHANGED);
1190 // If we have an open font definition, we have to close it
1192 #ifdef FIXED_LANGUAGE_END_DETECTION
1195 .latexWriteEndChanges(os, basefont,
1196 next_->getFont(bparams,
1199 running_font.latexWriteEndChanges(os, basefont,
1203 #ifdef WITH_WARNINGS
1204 //#warning For now we ALWAYS have to close the foreign font settings if they are
1205 //#warning there as we start another \selectlanguage with the next paragraph if
1206 //#warning we are in need of this. This should be fixed sometime (Jug)
1208 running_font.latexWriteEndChanges(os, basefont, basefont);
1212 // Needed if there is an optional argument but no contents.
1213 if (body_pos > 0 && body_pos == size()) {
1215 return_value = false;
1219 column += endTeXParParams(bparams, os, moving_arg);
1222 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1223 return return_value;
1229 bool Paragraph::isHfill(pos_type pos) const
1231 return IsInsetChar(getChar(pos))
1232 && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
1236 bool Paragraph::isInset(pos_type pos) const
1238 return IsInsetChar(getChar(pos));
1242 bool Paragraph::isNewline(pos_type pos) const
1244 return pos >= 0 && IsNewlineChar(getChar(pos));
1248 bool Paragraph::isSeparator(pos_type pos) const
1250 return IsSeparatorChar(getChar(pos));
1254 bool Paragraph::isLineSeparator(pos_type pos) const
1256 value_type const c = getChar(pos);
1257 return IsLineSeparatorChar(c)
1258 || (IsInsetChar(c) && getInset(pos) &&
1259 getInset(pos)->isLineSeparator());
1263 bool Paragraph::isKomma(pos_type pos) const
1265 return IsKommaChar(getChar(pos));
1269 /// Used by the spellchecker
1270 bool Paragraph::isLetter(pos_type pos) const
1272 value_type const c = getChar(pos);
1273 if (IsLetterChar(c))
1276 return getInset(pos)->isLetter();
1277 // We want to pass the ' and escape chars to ispell
1278 string const extra = lyxrc.isp_esc_chars + '\'';
1279 return contains(extra, c);
1283 bool Paragraph::isWord(pos_type pos) const
1285 return IsWordChar(getChar(pos)) ;
1290 Paragraph::getParLanguage(BufferParams const & bparams) const
1293 return getFirstFontSettings().language();
1294 } else if (previous_)
1295 return previous_->getParLanguage(bparams);
1297 return bparams.language;
1301 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1303 return lyxrc.rtl_support
1304 && getParLanguage(bparams)->RightToLeft()
1305 && !(inInset() && inInset()->owner() &&
1306 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
1310 void Paragraph::changeLanguage(BufferParams const & bparams,
1311 Language const * from, Language const * to)
1313 for (pos_type i = 0; i < size(); ++i) {
1314 LyXFont font = getFontSettings(bparams, i);
1315 if (font.language() == from) {
1316 font.setLanguage(to);
1323 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1325 Language const * doc_language = bparams.language;
1326 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1327 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1329 for (; cit != end; ++cit)
1330 if (cit->font().language() != ignore_language &&
1331 cit->font().language() != latex_language &&
1332 cit->font().language() != doc_language)
1338 // Convert the paragraph to a string.
1339 // Used for building the table of contents
1340 string const Paragraph::asString(Buffer const * buffer, bool label) const
1343 if (label && !params().labelString().empty())
1344 s += params().labelString() + ' ';
1346 for (pos_type i = 0; i < size(); ++i) {
1347 value_type c = getChar(i);
1350 else if (c == META_INSET &&
1351 getInset(i)->lyxCode() == Inset::MATH_CODE) {
1353 getInset(i)->ascii(buffer, ost);
1354 s += subst(STRCONV(ost.str()),'\n',' ');
1362 string const Paragraph::asString(Buffer const * buffer,
1363 pos_type beg, pos_type end, bool label) const
1367 if (beg == 0 && label && !params().labelString().empty())
1368 os << params().labelString() << ' ';
1370 for (pos_type i = beg; i < end; ++i) {
1371 value_type const c = getUChar(buffer->params, i);
1374 else if (c == META_NEWLINE)
1376 else if (c == META_INSET)
1377 getInset(i)->ascii(buffer, os);
1380 return STRCONV(os.str());
1384 void Paragraph::setInsetOwner(Inset * i)
1386 pimpl_->inset_owner = i;
1387 InsetList::iterator it = insetlist.begin();
1388 InsetList::iterator end = insetlist.end();
1389 for (; it != end; ++it)
1391 it.getInset()->setOwner(i);
1395 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1398 insetlist.deleteInsetsLyXText(bv);
1402 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1405 insetlist.resizeInsetsLyXText(bv);
1409 void Paragraph::setContentsFromPar(Paragraph * par)
1411 pimpl_->setContentsFromPar(par);
1415 void Paragraph::trackChanges(Change::Type type)
1417 pimpl_->trackChanges(type);
1421 void Paragraph::untrackChanges()
1423 pimpl_->untrackChanges();
1427 void Paragraph::cleanChanges()
1429 pimpl_->cleanChanges();
1433 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1435 lyx::Assert(!size() || pos < size());
1436 return pimpl_->lookupChange(pos);
1440 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1442 lyx::Assert(!size() || pos < size());
1443 return pimpl_->lookupChangeFull(pos);
1447 bool Paragraph::isChanged(pos_type start, pos_type end) const
1449 return pimpl_->isChanged(start, end);
1453 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1455 return pimpl_->isChangeEdited(start, end);
1459 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1461 pimpl_->setChange(pos, type);
1466 void Paragraph::markErased()
1468 pimpl_->markErased();
1472 void Paragraph::acceptChange(pos_type start, pos_type end)
1474 return pimpl_->acceptChange(start, end);
1478 void Paragraph::rejectChange(pos_type start, pos_type end)
1480 return pimpl_->rejectChange(start, end);
1484 lyx::pos_type Paragraph::size() const
1486 return pimpl_->size();
1490 bool Paragraph::empty() const
1492 return pimpl_->empty();
1496 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1498 return pimpl_->getChar(pos);
1502 int Paragraph::id() const
1508 LyXLayout_ptr const & Paragraph::layout() const
1514 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1516 layout_ = new_layout;
1520 bool Paragraph::isFirstInSequence() const
1522 Paragraph const * dhook = depthHook(getDepth());
1523 return (dhook == this
1524 || dhook->layout() != layout()
1525 || dhook->getDepth() != getDepth());
1529 Inset * Paragraph::inInset() const
1531 return pimpl_->inset_owner;
1535 void Paragraph::clearContents()
1540 void Paragraph::setChar(pos_type pos, value_type c)
1542 pimpl_->setChar(pos, c);
1546 ParagraphParameters & Paragraph::params()
1548 return pimpl_->params;
1552 ParagraphParameters const & Paragraph::params() const
1554 return pimpl_->params;
1558 bool Paragraph::isFreeSpacing() const
1560 // for now we just need this, later should we need this in some
1561 // other way we can always add a function to Inset::() too.
1562 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1563 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);