3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Richard Heck (XHTML output)
9 * \author Jean-Marc Lasgouttes
10 * \author Angus Leeming
12 * \author André Pönitz
14 * \author Jürgen Vigna
16 * Full author contact details are available in file CREDITS.
21 #include "Paragraph.h"
23 #include "LayoutFile.h"
25 #include "BufferParams.h"
29 #include "InsetList.h"
31 #include "LaTeXFeatures.h"
37 #include "OutputParams.h"
38 #include "output_latex.h"
39 #include "output_xhtml.h"
40 #include "ParagraphParameters.h"
41 #include "SpellChecker.h"
43 #include "TextClass.h"
47 #include "WordLangTuple.h"
50 #include "frontends/alert.h"
52 #include "insets/InsetBibitem.h"
53 #include "insets/InsetLabel.h"
55 #include "support/debug.h"
56 #include "support/docstring_list.h"
57 #include "support/ExceptionMessage.h"
58 #include "support/gettext.h"
59 #include "support/lassert.h"
60 #include "support/lstrings.h"
61 #include "support/textutils.h"
67 using namespace lyx::support;
72 /// Inset identifier (above 0x10ffff, for ucs-4)
73 char_type const META_INSET = 0x200001;
76 /////////////////////////////////////////////////////////////////////
80 /////////////////////////////////////////////////////////////////////
82 class Paragraph::Private
86 Private(Paragraph * owner, Layout const & layout);
87 /// "Copy constructor"
88 Private(Private const &, Paragraph * owner);
89 /// Copy constructor from \p beg to \p end
90 Private(Private const &, Paragraph * owner, pos_type beg, pos_type end);
93 void insertChar(pos_type pos, char_type c, Change const & change);
95 /// Output the surrogate pair formed by \p c and \p next to \p os.
96 /// \return the number of characters written.
97 int latexSurrogatePair(odocstream & os, char_type c, char_type next,
98 OutputParams const &);
100 /// Output a space in appropriate formatting (or a surrogate pair
101 /// if the next character is a combining character).
102 /// \return whether a surrogate pair was output.
103 bool simpleTeXBlanks(OutputParams const &,
104 odocstream &, TexRow & texrow,
106 unsigned int & column,
108 Layout const & style);
110 /// Output consecutive unicode chars, belonging to the same script as
111 /// specified by the latex macro \p ltx, to \p os starting from \p i.
112 /// \return the number of characters written.
113 int writeScriptChars(odocstream & os, docstring const & ltx,
114 Change const &, Encoding const &, pos_type & i);
116 /// This could go to ParagraphParameters if we want to.
117 int startTeXParParams(BufferParams const &, odocstream &, TexRow &,
118 OutputParams const &) const;
120 /// This could go to ParagraphParameters if we want to.
121 int endTeXParParams(BufferParams const &, odocstream &, TexRow &,
122 OutputParams const &) const;
125 void latexInset(BufferParams const &,
127 TexRow & texrow, OutputParams &,
130 Font const & outerfont,
132 Change & running_change,
133 Layout const & style,
135 unsigned int & column);
138 void latexSpecialChar(
140 OutputParams const & runparams,
141 Font const & running_font,
142 Change const & running_change,
143 Layout const & style,
145 unsigned int & column);
152 unsigned int & column);
154 bool latexSpecialTypewriter(
158 unsigned int & column);
160 bool latexSpecialPhrase(
163 unsigned int & column,
164 OutputParams const & runparams);
167 void validate(LaTeXFeatures & features) const;
169 /// Checks if the paragraph contains only text and no inset or font change.
170 bool onlyText(Buffer const & buf, Font const & outerfont,
171 pos_type initial) const;
173 /// match a string against a particular point in the paragraph
174 bool isTextAt(string const & str, pos_type pos) const;
177 InsetCode ownerCode() const
179 return inset_owner_ ? inset_owner_->lyxCode() : NO_CODE;
182 /// Which Paragraph owns us?
186 Inset const * inset_owner_;
194 static unsigned int paragraph_id;
196 ParagraphParameters params_;
198 /// for recording and looking up changes
202 InsetList insetlist_;
205 pos_type begin_of_body_;
207 typedef docstring TextContainer;
211 typedef std::set<docstring> Words;
215 Layout const * layout_;
219 // Initialization of the counter for the paragraph id's,
220 unsigned int Paragraph::Private::paragraph_id = 0;
224 struct special_phrase {
230 special_phrase const special_phrases[] = {
231 { "LyX", from_ascii("\\LyX{}"), false },
232 { "TeX", from_ascii("\\TeX{}"), true },
233 { "LaTeX2e", from_ascii("\\LaTeXe{}"), true },
234 { "LaTeX", from_ascii("\\LaTeX{}"), true },
237 size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase);
242 Paragraph::Private::Private(Paragraph * owner, Layout const & layout)
243 : owner_(owner), inset_owner_(0), begin_of_body_(0), layout_(&layout)
245 id_ = paragraph_id++;
250 Paragraph::Private::Private(Private const & p, Paragraph * owner)
251 : owner_(owner), inset_owner_(p.inset_owner_), fontlist_(p.fontlist_),
252 params_(p.params_), changes_(p.changes_), insetlist_(p.insetlist_),
253 begin_of_body_(p.begin_of_body_), text_(p.text_), words_(p.words_),
256 id_ = paragraph_id++;
260 Paragraph::Private::Private(Private const & p, Paragraph * owner,
261 pos_type beg, pos_type end)
262 : owner_(owner), inset_owner_(p.inset_owner_),
263 params_(p.params_), changes_(p.changes_),
264 insetlist_(p.insetlist_, beg, end),
265 begin_of_body_(p.begin_of_body_), words_(p.words_),
268 id_ = paragraph_id++;
269 if (beg >= pos_type(p.text_.size()))
271 text_ = p.text_.substr(beg, end - beg);
273 FontList::const_iterator fcit = fontlist_.begin();
274 FontList::const_iterator fend = fontlist_.end();
275 for (; fcit != fend; ++fcit) {
276 if (fcit->pos() < beg)
278 if (fcit->pos() >= end) {
279 // Add last entry in the fontlist_.
280 fontlist_.set(text_.size() - 1, fcit->font());
283 // Add a new entry in the fontlist_.
284 fontlist_.set(fcit->pos() - beg, fcit->font());
289 void Paragraph::addChangesToToc(DocIterator const & cdit,
290 Buffer const & buf) const
292 d->changes_.addToToc(cdit, buf);
296 bool Paragraph::isDeleted(pos_type start, pos_type end) const
298 LASSERT(start >= 0 && start <= size(), /**/);
299 LASSERT(end > start && end <= size() + 1, /**/);
301 return d->changes_.isDeleted(start, end);
305 bool Paragraph::isChanged(pos_type start, pos_type end) const
307 LASSERT(start >= 0 && start <= size(), /**/);
308 LASSERT(end > start && end <= size() + 1, /**/);
310 return d->changes_.isChanged(start, end);
314 bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const
316 // keep the logic here in sync with the logic of eraseChars()
320 Change const change = d->changes_.lookup(size());
321 return change.inserted() && change.currentAuthor();
325 void Paragraph::setChange(Change const & change)
327 // beware of the imaginary end-of-par character!
328 d->changes_.set(change, 0, size() + 1);
331 * Propagate the change recursively - but not in case of DELETED!
333 * Imagine that your co-author makes changes in an existing inset. He
334 * sends your document to you and you come to the conclusion that the
335 * inset should go completely. If you erase it, LyX must not delete all
336 * text within the inset. Otherwise, the change tracked insertions of
337 * your co-author get lost and there is no way to restore them later.
339 * Conclusion: An inset's content should remain untouched if you delete it
342 if (!change.deleted()) {
343 for (pos_type pos = 0; pos < size(); ++pos) {
344 if (Inset * inset = getInset(pos))
345 inset->setChange(change);
351 void Paragraph::setChange(pos_type pos, Change const & change)
353 LASSERT(pos >= 0 && pos <= size(), /**/);
354 d->changes_.set(change, pos);
356 // see comment in setChange(Change const &) above
357 if (!change.deleted() && pos < size())
358 if (Inset * inset = getInset(pos))
359 inset->setChange(change);
363 Change const & Paragraph::lookupChange(pos_type pos) const
365 LASSERT(pos >= 0 && pos <= size(), /**/);
366 return d->changes_.lookup(pos);
370 void Paragraph::acceptChanges(pos_type start, pos_type end)
372 LASSERT(start >= 0 && start <= size(), /**/);
373 LASSERT(end > start && end <= size() + 1, /**/);
375 for (pos_type pos = start; pos < end; ++pos) {
376 switch (lookupChange(pos).type) {
377 case Change::UNCHANGED:
378 // accept changes in nested inset
379 if (Inset * inset = getInset(pos))
380 inset->acceptChanges();
383 case Change::INSERTED:
384 d->changes_.set(Change(Change::UNCHANGED), pos);
385 // also accept changes in nested inset
386 if (Inset * inset = getInset(pos))
387 inset->acceptChanges();
390 case Change::DELETED:
391 // Suppress access to non-existent
392 // "end-of-paragraph char"
394 eraseChar(pos, false);
405 void Paragraph::rejectChanges(pos_type start, pos_type end)
407 LASSERT(start >= 0 && start <= size(), /**/);
408 LASSERT(end > start && end <= size() + 1, /**/);
410 for (pos_type pos = start; pos < end; ++pos) {
411 switch (lookupChange(pos).type) {
412 case Change::UNCHANGED:
413 // reject changes in nested inset
414 if (Inset * inset = getInset(pos))
415 inset->rejectChanges();
418 case Change::INSERTED:
419 // Suppress access to non-existent
420 // "end-of-paragraph char"
422 eraseChar(pos, false);
428 case Change::DELETED:
429 d->changes_.set(Change(Change::UNCHANGED), pos);
431 // Do NOT reject changes within a deleted inset!
432 // There may be insertions of a co-author inside of it!
440 void Paragraph::Private::insertChar(pos_type pos, char_type c,
441 Change const & change)
443 LASSERT(pos >= 0 && pos <= int(text_.size()), /**/);
446 changes_.insert(change, pos);
448 // This is actually very common when parsing buffers (and
449 // maybe inserting ascii text)
450 if (pos == pos_type(text_.size())) {
451 // when appending characters, no need to update tables
456 text_.insert(text_.begin() + pos, c);
458 // Update the font table.
459 fontlist_.increasePosAfterPos(pos);
462 insetlist_.increasePosAfterPos(pos);
466 bool Paragraph::insertInset(pos_type pos, Inset * inset,
467 Change const & change)
469 LASSERT(inset, /**/);
470 LASSERT(pos >= 0 && pos <= size(), /**/);
472 // Paragraph::insertInset() can be used in cut/copy/paste operation where
473 // d->inset_owner_ is not set yet.
474 if (d->inset_owner_ && !d->inset_owner_->insetAllowed(inset->lyxCode()))
477 d->insertChar(pos, META_INSET, change);
478 LASSERT(d->text_[pos] == META_INSET, /**/);
480 // Add a new entry in the insetlist_.
481 d->insetlist_.insert(inset, pos);
486 bool Paragraph::eraseChar(pos_type pos, bool trackChanges)
488 LASSERT(pos >= 0 && pos <= size(), return false);
490 // keep the logic here in sync with the logic of isMergedOnEndOfParDeletion()
493 Change change = d->changes_.lookup(pos);
495 // set the character to DELETED if
496 // a) it was previously unchanged or
497 // b) it was inserted by a co-author
499 if (!change.changed() ||
500 (change.inserted() && !change.currentAuthor())) {
501 setChange(pos, Change(Change::DELETED));
505 if (change.deleted())
509 // Don't physically access the imaginary end-of-paragraph character.
510 // eraseChar() can only mark it as DELETED. A physical deletion of
511 // end-of-par must be handled externally.
517 d->changes_.erase(pos);
519 // if it is an inset, delete the inset entry
520 if (d->text_[pos] == META_INSET)
521 d->insetlist_.erase(pos);
523 d->text_.erase(d->text_.begin() + pos);
525 // Update the fontlist_
526 d->fontlist_.erase(pos);
528 // Update the insetlist_
529 d->insetlist_.decreasePosAfterPos(pos);
535 int Paragraph::eraseChars(pos_type start, pos_type end, bool trackChanges)
537 LASSERT(start >= 0 && start <= size(), /**/);
538 LASSERT(end >= start && end <= size() + 1, /**/);
541 for (pos_type count = end - start; count; --count) {
542 if (!eraseChar(i, trackChanges))
549 int Paragraph::Private::latexSurrogatePair(odocstream & os, char_type c,
550 char_type next, OutputParams const & runparams)
552 // Writing next here may circumvent a possible font change between
553 // c and next. Since next is only output if it forms a surrogate pair
554 // with c we can ignore this:
555 // A font change inside a surrogate pair does not make sense and is
556 // hopefully impossible to input.
557 // FIXME: change tracking
558 // Is this correct WRT change tracking?
559 Encoding const & encoding = *(runparams.encoding);
560 docstring const latex1 = encoding.latexChar(next);
561 docstring const latex2 = encoding.latexChar(c);
562 if (docstring(1, next) == latex1) {
563 // the encoding supports the combination
564 os << latex2 << latex1;
565 return latex1.length() + latex2.length();
566 } else if (runparams.local_font &&
567 runparams.local_font->language()->lang() == "polutonikogreek") {
568 // polutonikogreek only works without the brackets
569 os << latex1 << latex2;
570 return latex1.length() + latex2.length();
572 os << latex1 << '{' << latex2 << '}';
573 return latex1.length() + latex2.length() + 2;
577 bool Paragraph::Private::simpleTeXBlanks(OutputParams const & runparams,
578 odocstream & os, TexRow & texrow,
580 unsigned int & column,
582 Layout const & style)
584 if (style.pass_thru || runparams.verbatim)
587 if (i + 1 < int(text_.size())) {
588 char_type next = text_[i + 1];
589 if (Encodings::isCombiningChar(next)) {
590 // This space has an accent, so we must always output it.
591 column += latexSurrogatePair(os, ' ', next, runparams) - 1;
596 if (runparams.linelen > 0
597 && column > runparams.linelen
599 && text_[i - 1] != ' '
600 && (i + 1 < int(text_.size()))
601 // same in FreeSpacing mode
602 && !owner_->isFreeSpacing()
603 // In typewriter mode, we want to avoid
604 // ! . ? : at the end of a line
605 && !(font.fontInfo().family() == TYPEWRITER_FAMILY
606 && (text_[i - 1] == '.'
607 || text_[i - 1] == '?'
608 || text_[i - 1] == ':'
609 || text_[i - 1] == '!'))) {
612 texrow.start(owner_->id(), i + 1);
614 } else if (style.free_spacing) {
623 int Paragraph::Private::writeScriptChars(odocstream & os,
624 docstring const & ltx,
625 Change const & runningChange,
626 Encoding const & encoding,
629 // FIXME: modifying i here is not very nice...
631 // We only arrive here when a proper language for character text_[i] has
632 // not been specified (i.e., it could not be translated in the current
633 // latex encoding) or its latex translation has been forced, and it
634 // belongs to a known script.
635 // Parameter ltx contains the latex translation of text_[i] as specified
636 // in the unicodesymbols file and is something like "\textXXX{<spec>}".
637 // The latex macro name "textXXX" specifies the script to which text_[i]
638 // belongs and we use it in order to check whether characters from the
639 // same script immediately follow, such that we can collect them in a
640 // single "\textXXX" macro. So, we have to retain "\textXXX{<spec>"
641 // for the first char but only "<spec>" for all subsequent chars.
642 docstring::size_type const brace1 = ltx.find_first_of(from_ascii("{"));
643 docstring::size_type const brace2 = ltx.find_last_of(from_ascii("}"));
644 string script = to_ascii(ltx.substr(1, brace1 - 1));
647 bool closing_brace = true;
648 if (script == "textgreek" && encoding.latexName() == "iso-8859-7") {
649 // Correct encoding is being used, so we can avoid \textgreek.
652 closing_brace = false;
654 os << ltx.substr(pos, length);
655 int size = text_.size();
656 while (i + 1 < size) {
657 char_type const next = text_[i + 1];
658 // Stop here if next character belongs to another script
659 // or there is a change in change tracking status.
660 if (!Encodings::isKnownScriptChar(next, script) ||
661 runningChange != owner_->lookupChange(i + 1))
665 FontList::const_iterator cit = fontlist_.begin();
666 FontList::const_iterator end = fontlist_.end();
667 for (; cit != end; ++cit) {
668 if (cit->pos() >= i && !found) {
669 prev_font = cit->font();
672 if (cit->pos() >= i + 1)
675 // Stop here if there is a font attribute or encoding change.
676 if (found && cit != end && prev_font != cit->font())
678 docstring const latex = encoding.latexChar(next);
679 docstring::size_type const b1 =
680 latex.find_first_of(from_ascii("{"));
681 docstring::size_type const b2 =
682 latex.find_last_of(from_ascii("}"));
683 int const len = b2 - b1 - 1;
684 os << latex.substr(b1 + 1, len);
696 bool Paragraph::Private::isTextAt(string const & str, pos_type pos) const
698 pos_type const len = str.length();
700 // is the paragraph large enough?
701 if (pos + len > int(text_.size()))
704 // does the wanted text start at point?
705 for (string::size_type i = 0; i < str.length(); ++i) {
706 // Caution: direct comparison of characters works only
707 // because str is pure ASCII.
708 if (str[i] != text_[pos + i])
712 return fontlist_.hasChangeInRange(pos, len);
716 void Paragraph::Private::latexInset(
717 BufferParams const & bparams,
720 OutputParams & runparams,
723 Font const & outerfont,
725 Change & running_change,
726 Layout const & style,
728 unsigned int & column)
730 Inset * inset = owner_->getInset(i);
731 LASSERT(inset, /**/);
733 if (style.pass_thru) {
734 inset->plaintext(os, runparams);
738 // FIXME: move this to InsetNewline::latex
739 if (inset->lyxCode() == NEWLINE_CODE) {
740 // newlines are handled differently here than
741 // the default in simpleTeXSpecialChars().
742 if (!style.newline_allowed) {
746 column += running_font.latexWriteEndChanges(
747 os, bparams, runparams,
752 if (running_font.fontInfo().family() == TYPEWRITER_FAMILY)
755 basefont = owner_->getLayoutFont(bparams, outerfont);
756 running_font = basefont;
758 if (runparams.moving_arg)
763 texrow.start(owner_->id(), i + 1);
767 if (owner_->isDeleted(i)) {
768 if( ++runparams.inDeletedInset == 1)
769 runparams.changeOfDeletedInset = owner_->lookupChange(i);
772 if (inset->canTrackChanges()) {
773 column += Changes::latexMarkChange(os, bparams, running_change,
774 Change(Change::UNCHANGED), runparams);
775 running_change = Change(Change::UNCHANGED);
779 odocstream::pos_type const len = os.tellp();
781 if (inset->forceLTR()
782 && running_font.isRightToLeft()
783 // ERT is an exception, it should be output with no
784 // decorations at all
785 && inset->lyxCode() != ERT_CODE) {
786 if (running_font.language()->lang() == "farsi")
793 // FIXME: Bug: we can have an empty font change here!
794 // if there has just been a font change, we are going to close it
795 // right now, which means stupid latex code like \textsf{}. AFAIK,
796 // this does not harm dvi output. A minor bug, thus (JMarc)
798 // Some insets cannot be inside a font change command.
799 // However, even such insets *can* be placed in \L or \R
800 // or their equivalents (for RTL language switches), so we don't
801 // close the language in those cases.
802 // ArabTeX, though, cannot handle this special behavior, it seems.
803 bool arabtex = basefont.language()->lang() == "arabic_arabtex"
804 || running_font.language()->lang() == "arabic_arabtex";
805 if (open_font && inset->noFontChange()) {
806 bool closeLanguage = arabtex
807 || basefont.isRightToLeft() == running_font.isRightToLeft();
808 unsigned int count = running_font.latexWriteEndChanges(os,
809 bparams, runparams, basefont, basefont, closeLanguage);
811 // if any font properties were closed, update the running_font,
812 // making sure, however, to leave the language as it was
814 // FIXME: probably a better way to keep track of the old
815 // language, than copying the entire font?
816 Font const copy_font(running_font);
817 basefont = owner_->getLayoutFont(bparams, outerfont);
818 running_font = basefont;
820 running_font.setLanguage(copy_font.language());
821 // leave font open if language is still open
822 open_font = (running_font.language() == basefont.language());
824 runparams.local_font = &basefont;
831 tmp = inset->latex(os, runparams);
832 } catch (EncodingException & e) {
833 // add location information and throw again.
840 if (running_font.language()->lang() == "farsi")
847 for (int j = 0; j < tmp; ++j)
850 texrow.start(owner_->id(), i + 1);
853 column += os.tellp() - len;
856 if (owner_->isDeleted(i))
857 --runparams.inDeletedInset;
861 void Paragraph::Private::latexSpecialChar(
863 OutputParams const & runparams,
864 Font const & running_font,
865 Change const & running_change,
866 Layout const & style,
868 unsigned int & column)
870 char_type const c = text_[i];
872 if (style.pass_thru) {
874 // FIXME UNICODE: This can fail if c cannot
875 // be encoded in the current encoding.
880 if (runparams.verbatim) {
881 // FIXME UNICODE: This can fail if c cannot
882 // be encoded in the current encoding.
887 // If T1 font encoding is used, use the special
888 // characters it provides.
889 // NOTE: some languages reset the font encoding
891 if (!running_font.language()->internalFontEncoding()
892 && lyxrc.fontenc == "T1" && latexSpecialT1(c, os, i, column))
895 // \tt font needs special treatment
896 if (running_font.fontInfo().family() == TYPEWRITER_FAMILY
897 && latexSpecialTypewriter(c, os, i, column))
900 // Otherwise, we use what LaTeX provides us.
903 os << "\\textbackslash{}";
907 os << "\\textless{}";
911 os << "\\textgreater{}";
922 os << "\\char`\\\"{}";
927 case '%': case '#': case '{':
935 os << "\\textasciitilde{}";
940 os << "\\textasciicircum{}";
947 // avoid being mistaken for optional arguments
955 // Blanks are printed before font switching.
956 // Sure? I am not! (try nice-latex)
957 // I am sure it's correct. LyX might be smarter
958 // in the future, but for now, nothing wrong is
964 if (latexSpecialPhrase(os, i, column, runparams))
970 Encoding const & encoding = *(runparams.encoding);
971 if (i + 1 < int(text_.size())) {
972 char_type next = text_[i + 1];
973 if (Encodings::isCombiningChar(next)) {
974 column += latexSurrogatePair(os, c, next, runparams) - 1;
980 docstring const latex = encoding.latexChar(c);
981 if (Encodings::isKnownScriptChar(c, script)
982 && prefixIs(latex, from_ascii("\\" + script)))
983 column += writeScriptChars(os, latex,
984 running_change, encoding, i) - 1;
985 else if (latex.length() > 1 && latex[latex.length() - 1] != '}') {
986 // Prevent eating of a following
987 // space or command corruption by
988 // following characters
989 column += latex.length() + 1;
992 column += latex.length() - 1;
1000 bool Paragraph::Private::latexSpecialT1(char_type const c, odocstream & os,
1001 pos_type i, unsigned int & column)
1007 // In T1 encoding, these characters exist
1008 // but we should avoid ligatures
1009 if (i + 1 >= int(text_.size()) || text_[i + 1] != c)
1011 os << "\\textcompwordmark{}";
1018 // soul.sty breaks with \char`\"
1019 os << "\\textquotedbl{}";
1028 bool Paragraph::Private::latexSpecialTypewriter(char_type const c, odocstream & os,
1029 pos_type i, unsigned int & column)
1033 // within \ttfamily, "--" is merged to "-" (no endash)
1034 // so we avoid this rather irritating ligature
1035 if (i + 1 < int(text_.size()) && text_[i + 1] == '-') {
1042 // everything else has to be checked separately
1043 // (depending on the encoding)
1050 bool Paragraph::Private::latexSpecialPhrase(odocstream & os, pos_type & i,
1051 unsigned int & column, OutputParams const & runparams)
1053 // FIXME: if we have "LaTeX" with a font
1054 // change in the middle (before the 'T', then
1055 // the "TeX" part is still special cased.
1056 // Really we should only operate this on
1057 // "words" for some definition of word
1059 for (size_t pnr = 0; pnr < phrases_nr; ++pnr) {
1060 if (!isTextAt(special_phrases[pnr].phrase, i))
1062 if (runparams.moving_arg)
1064 os << special_phrases[pnr].macro;
1065 i += special_phrases[pnr].phrase.length() - 1;
1066 column += special_phrases[pnr].macro.length() - 1;
1073 void Paragraph::Private::validate(LaTeXFeatures & features) const
1075 if (layout_->inpreamble && inset_owner_) {
1076 Buffer const & buf = inset_owner_->buffer();
1077 BufferParams const & bp = buf.params();
1080 odocstringstream ods;
1081 owner_->latex(bp, f, ods, tr, features.runparams());
1082 docstring d = ods.str();
1084 features.addPreambleSnippet(to_utf8(d));
1087 // check the params.
1088 if (!params_.spacing().isDefault())
1089 features.require("setspace");
1092 features.useLayout(layout_->name());
1095 fontlist_.validate(features);
1097 // then the indentation
1098 if (!params_.leftIndent().zero())
1099 features.require("ParagraphLeftIndent");
1102 InsetList::const_iterator icit = insetlist_.begin();
1103 InsetList::const_iterator iend = insetlist_.end();
1104 for (; icit != iend; ++icit) {
1106 icit->inset->validate(features);
1107 if (layout_->needprotect &&
1108 icit->inset->lyxCode() == FOOT_CODE)
1109 features.require("NeedLyXFootnoteCode");
1113 // then the contents
1114 for (pos_type i = 0; i < int(text_.size()) ; ++i) {
1115 for (size_t pnr = 0; pnr < phrases_nr; ++pnr) {
1116 if (!special_phrases[pnr].builtin
1117 && isTextAt(special_phrases[pnr].phrase, i)) {
1118 features.require(special_phrases[pnr].phrase);
1122 Encodings::validate(text_[i], features);
1126 /////////////////////////////////////////////////////////////////////
1130 /////////////////////////////////////////////////////////////////////
1133 Layout const emptyParagraphLayout;
1136 Paragraph::Paragraph()
1137 : d(new Paragraph::Private(this, emptyParagraphLayout))
1144 Paragraph::Paragraph(Paragraph const & par)
1145 : itemdepth(par.itemdepth),
1146 d(new Paragraph::Private(*par.d, this))
1152 Paragraph::Paragraph(Paragraph const & par, pos_type beg, pos_type end)
1153 : itemdepth(par.itemdepth),
1154 d(new Paragraph::Private(*par.d, this, beg, end))
1160 Paragraph & Paragraph::operator=(Paragraph const & par)
1162 // needed as we will destroy the private part before copying it
1164 itemdepth = par.itemdepth;
1168 d = new Private(*par.d, this);
1175 Paragraph::~Paragraph()
1184 // this shall be called just before every "os << ..." action.
1185 void flushString(ostream & os, docstring & s)
1194 void Paragraph::write(ostream & os, BufferParams const & bparams,
1195 depth_type & dth) const
1197 // The beginning or end of a deeper (i.e. nested) area?
1198 if (dth != d->params_.depth()) {
1199 if (d->params_.depth() > dth) {
1200 while (d->params_.depth() > dth) {
1201 os << "\n\\begin_deeper";
1205 while (d->params_.depth() < dth) {
1206 os << "\n\\end_deeper";
1212 // First write the layout
1213 os << "\n\\begin_layout " << to_utf8(d->layout_->name()) << '\n';
1215 d->params_.write(os);
1217 Font font1(inherit_font, bparams.language);
1219 Change running_change = Change(Change::UNCHANGED);
1221 // this string is used as a buffer to avoid repetitive calls
1222 // to to_utf8(), which turn out to be expensive (JMarc)
1223 docstring write_buffer;
1226 for (pos_type i = 0; i <= size(); ++i) {
1228 Change const change = lookupChange(i);
1229 if (change != running_change)
1230 flushString(os, write_buffer);
1231 Changes::lyxMarkChange(os, bparams, column, running_change, change);
1232 running_change = change;
1237 // Write font changes (ignore spelling markers)
1238 Font font2 = getFontSettings(bparams, i);
1239 font2.setMisspelled(false);
1240 if (font2 != font1) {
1241 flushString(os, write_buffer);
1242 font2.lyxWriteChanges(font1, os);
1247 char_type const c = d->text_[i];
1250 if (Inset const * inset = getInset(i)) {
1251 flushString(os, write_buffer);
1252 if (inset->directWrite()) {
1253 // international char, let it write
1254 // code directly so it's shorter in
1260 os << "\\begin_inset ";
1262 os << "\n\\end_inset\n\n";
1268 flushString(os, write_buffer);
1269 os << "\n\\backslash\n";
1273 flushString(os, write_buffer);
1274 if (i + 1 < size() && d->text_[i + 1] == ' ') {
1281 if ((column > 70 && c == ' ')
1283 flushString(os, write_buffer);
1287 // this check is to amend a bug. LyX sometimes
1288 // inserts '\0' this could cause problems.
1290 write_buffer.push_back(c);
1292 LYXERR0("NUL char in structure.");
1298 flushString(os, write_buffer);
1299 os << "\n\\end_layout\n";
1303 void Paragraph::validate(LaTeXFeatures & features) const
1305 d->validate(features);
1309 void Paragraph::insert(pos_type start, docstring const & str,
1310 Font const & font, Change const & change)
1312 for (size_t i = 0, n = str.size(); i != n ; ++i)
1313 insertChar(start + i, str[i], font, change);
1317 void Paragraph::appendChar(char_type c, Font const & font,
1318 Change const & change)
1321 d->changes_.insert(change, d->text_.size());
1322 // when appending characters, no need to update tables
1323 d->text_.push_back(c);
1324 setFont(d->text_.size() - 1, font);
1328 void Paragraph::appendString(docstring const & s, Font const & font,
1329 Change const & change)
1331 pos_type end = s.size();
1332 size_t oldsize = d->text_.size();
1333 size_t newsize = oldsize + end;
1334 size_t capacity = d->text_.capacity();
1335 if (newsize >= capacity)
1336 d->text_.reserve(max(capacity + 100, newsize));
1338 // when appending characters, no need to update tables
1341 // FIXME: Optimize this!
1342 for (size_t i = oldsize; i != newsize; ++i) {
1344 d->changes_.insert(change, i);
1346 d->fontlist_.set(oldsize, font);
1347 d->fontlist_.set(newsize - 1, font);
1351 void Paragraph::insertChar(pos_type pos, char_type c,
1354 d->insertChar(pos, c, Change(trackChanges ?
1355 Change::INSERTED : Change::UNCHANGED));
1359 void Paragraph::insertChar(pos_type pos, char_type c,
1360 Font const & font, bool trackChanges)
1362 d->insertChar(pos, c, Change(trackChanges ?
1363 Change::INSERTED : Change::UNCHANGED));
1368 void Paragraph::insertChar(pos_type pos, char_type c,
1369 Font const & font, Change const & change)
1371 d->insertChar(pos, c, change);
1376 bool Paragraph::insertInset(pos_type pos, Inset * inset,
1377 Font const & font, Change const & change)
1379 bool const success = insertInset(pos, inset, change);
1380 // Set the font/language of the inset...
1386 void Paragraph::resetFonts(Font const & font)
1388 d->fontlist_.clear();
1389 d->fontlist_.set(0, font);
1390 d->fontlist_.set(d->text_.size() - 1, font);
1393 // Gets uninstantiated font setting at position.
1394 Font const & Paragraph::getFontSettings(BufferParams const & bparams,
1398 LYXERR0("pos: " << pos << " size: " << size());
1399 LASSERT(pos <= size(), /**/);
1402 FontList::const_iterator cit = d->fontlist_.fontIterator(pos);
1403 if (cit != d->fontlist_.end())
1406 if (pos == size() && !empty())
1407 return getFontSettings(bparams, pos - 1);
1409 // Optimisation: avoid a full font instantiation if there is no
1410 // language change from previous call.
1411 static Font previous_font;
1412 static Language const * previous_lang = 0;
1413 Language const * lang = getParLanguage(bparams);
1414 if (lang != previous_lang) {
1415 previous_lang = lang;
1416 previous_font = Font(inherit_font, lang);
1418 return previous_font;
1422 FontSpan Paragraph::fontSpan(pos_type pos) const
1424 LASSERT(pos <= size(), /**/);
1427 FontList::const_iterator cit = d->fontlist_.begin();
1428 FontList::const_iterator end = d->fontlist_.end();
1429 for (; cit != end; ++cit) {
1430 if (cit->pos() >= pos) {
1431 if (pos >= beginOfBody())
1432 return FontSpan(max(start, beginOfBody()),
1435 return FontSpan(start,
1436 min(beginOfBody() - 1,
1439 start = cit->pos() + 1;
1442 // This should not happen, but if so, we take no chances.
1443 // LYXERR0("Paragraph::getEndPosOfFontSpan: This should not happen!");
1444 return FontSpan(pos, pos);
1448 // Gets uninstantiated font setting at position 0
1449 Font const & Paragraph::getFirstFontSettings(BufferParams const & bparams) const
1451 if (!empty() && !d->fontlist_.empty())
1452 return d->fontlist_.begin()->font();
1454 // Optimisation: avoid a full font instantiation if there is no
1455 // language change from previous call.
1456 static Font previous_font;
1457 static Language const * previous_lang = 0;
1458 if (bparams.language != previous_lang) {
1459 previous_lang = bparams.language;
1460 previous_font = Font(inherit_font, bparams.language);
1463 return previous_font;
1467 // Gets the fully instantiated font at a given position in a paragraph
1468 // This is basically the same function as Text::GetFont() in text2.cpp.
1469 // The difference is that this one is used for generating the LaTeX file,
1470 // and thus cosmetic "improvements" are disallowed: This has to deliver
1471 // the true picture of the buffer. (Asger)
1472 Font const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
1473 Font const & outerfont) const
1475 LASSERT(pos >= 0, /**/);
1477 Font font = getFontSettings(bparams, pos);
1479 pos_type const body_pos = beginOfBody();
1480 FontInfo & fi = font.fontInfo();
1482 fi.realize(d->layout_->labelfont);
1484 fi.realize(d->layout_->font);
1486 fi.realize(outerfont.fontInfo());
1487 fi.realize(bparams.getFont().fontInfo());
1493 Font const Paragraph::getLabelFont
1494 (BufferParams const & bparams, Font const & outerfont) const
1496 FontInfo tmpfont = d->layout_->labelfont;
1497 tmpfont.realize(outerfont.fontInfo());
1498 tmpfont.realize(bparams.getFont().fontInfo());
1499 return Font(tmpfont, getParLanguage(bparams));
1503 Font const Paragraph::getLayoutFont
1504 (BufferParams const & bparams, Font const & outerfont) const
1506 FontInfo tmpfont = d->layout_->font;
1507 tmpfont.realize(outerfont.fontInfo());
1508 tmpfont.realize(bparams.getFont().fontInfo());
1509 return Font(tmpfont, getParLanguage(bparams));
1513 /// Returns the height of the highest font in range
1514 FontSize Paragraph::highestFontInRange
1515 (pos_type startpos, pos_type endpos, FontSize def_size) const
1517 return d->fontlist_.highestInRange(startpos, endpos, def_size);
1521 char_type Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
1523 char_type c = d->text_[pos];
1524 if (!lyxrc.rtl_support)
1554 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
1560 void Paragraph::setFont(pos_type pos, Font const & font)
1562 LASSERT(pos <= size(), /**/);
1564 // First, reduce font against layout/label font
1565 // Update: The setCharFont() routine in text2.cpp already
1566 // reduces font, so we don't need to do that here. (Asger)
1568 d->fontlist_.set(pos, font);
1572 void Paragraph::makeSameLayout(Paragraph const & par)
1574 d->layout_ = par.d->layout_;
1575 d->params_ = par.d->params_;
1579 bool Paragraph::stripLeadingSpaces(bool trackChanges)
1581 if (isFreeSpacing())
1587 while (pos < size() && (isNewline(pos) || isLineSeparator(pos))) {
1588 if (eraseChar(pos, trackChanges))
1594 return count > 0 || pos > 0;
1598 bool Paragraph::hasSameLayout(Paragraph const & par) const
1600 return par.d->layout_ == d->layout_
1601 && d->params_.sameLayout(par.d->params_);
1605 depth_type Paragraph::getDepth() const
1607 return d->params_.depth();
1611 depth_type Paragraph::getMaxDepthAfter() const
1613 if (d->layout_->isEnvironment())
1614 return d->params_.depth() + 1;
1616 return d->params_.depth();
1620 char Paragraph::getAlign() const
1622 if (d->params_.align() == LYX_ALIGN_LAYOUT)
1623 return d->layout_->align;
1625 return d->params_.align();
1629 docstring const & Paragraph::labelString() const
1631 return d->params_.labelString();
1635 // the next two functions are for the manual labels
1636 docstring const Paragraph::getLabelWidthString() const
1638 if (d->layout_->margintype == MARGIN_MANUAL
1639 || d->layout_->latextype == LATEX_BIB_ENVIRONMENT)
1640 return d->params_.labelWidthString();
1642 return _("Senseless with this layout!");
1646 void Paragraph::setLabelWidthString(docstring const & s)
1648 d->params_.labelWidthString(s);
1652 docstring Paragraph::expandLabel(Layout const & layout,
1653 BufferParams const & bparams, bool process_appendix) const
1655 DocumentClass const & tclass = bparams.documentClass();
1656 string const & lang = getParLanguage(bparams)->code();
1657 bool const in_appendix = process_appendix && d->params_.appendix();
1658 docstring fmt = translateIfPossible(layout.labelstring(in_appendix), lang);
1660 if (fmt.empty() && layout.labeltype == LABEL_COUNTER
1661 && !layout.counter.empty())
1662 return tclass.counters().theCounter(layout.counter, lang);
1664 // handle 'inherited level parts' in 'fmt',
1665 // i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
1666 size_t const i = fmt.find('@', 0);
1667 if (i != docstring::npos) {
1668 size_t const j = fmt.find('@', i + 1);
1669 if (j != docstring::npos) {
1670 docstring parent(fmt, i + 1, j - i - 1);
1671 docstring label = from_ascii("??");
1672 if (tclass.hasLayout(parent))
1673 docstring label = expandLabel(tclass[parent], bparams,
1675 fmt = docstring(fmt, 0, i) + label
1676 + docstring(fmt, j + 1, docstring::npos);
1680 return tclass.counters().counterLabel(fmt, lang);
1684 void Paragraph::applyLayout(Layout const & new_layout)
1686 d->layout_ = &new_layout;
1687 LyXAlignment const oldAlign = d->params_.align();
1689 if (!(oldAlign & d->layout_->alignpossible)) {
1690 frontend::Alert::warning(_("Alignment not permitted"),
1691 _("The new layout does not permit the alignment previously used.\nSetting to default."));
1692 d->params_.align(LYX_ALIGN_LAYOUT);
1697 pos_type Paragraph::beginOfBody() const
1699 return d->begin_of_body_;
1703 void Paragraph::setBeginOfBody()
1705 if (d->layout_->labeltype != LABEL_MANUAL) {
1706 d->begin_of_body_ = 0;
1710 // Unroll the first two cycles of the loop
1711 // and remember the previous character to
1712 // remove unnecessary getChar() calls
1714 pos_type end = size();
1715 if (i < end && !isNewline(i)) {
1717 char_type previous_char = 0;
1720 previous_char = d->text_[i];
1721 if (!isNewline(i)) {
1723 while (i < end && previous_char != ' ') {
1728 previous_char = temp;
1734 d->begin_of_body_ = i;
1738 bool Paragraph::allowParagraphCustomization() const
1740 return inInset().allowParagraphCustomization();
1744 bool Paragraph::usePlainLayout() const
1746 return inInset().usePlainLayout();
1752 // paragraphs inside floats need different alignment tags to avoid
1755 bool noTrivlistCentering(InsetCode code)
1757 return code == FLOAT_CODE
1758 || code == WRAP_CODE
1759 || code == CELL_CODE;
1763 string correction(string const & orig)
1765 if (orig == "flushleft")
1766 return "raggedright";
1767 if (orig == "flushright")
1768 return "raggedleft";
1769 if (orig == "center")
1775 string const corrected_env(string const & suffix, string const & env,
1776 InsetCode code, bool const lastpar)
1778 string output = suffix + "{";
1779 if (noTrivlistCentering(code)) {
1781 // the last paragraph in non-trivlist-aligned
1782 // context is special (to avoid unwanted whitespace)
1783 if (suffix == "\\begin")
1784 return "\\" + correction(env) + "{}";
1787 output += correction(env);
1791 if (suffix == "\\begin")
1797 void adjust_row_column(string const & str, TexRow & texrow, int & column)
1799 if (!contains(str, "\n"))
1800 column += str.size();
1804 column = rsplit(str, tmp, '\n').size();
1811 int Paragraph::Private::startTeXParParams(BufferParams const & bparams,
1812 odocstream & os, TexRow & texrow,
1813 OutputParams const & runparams) const
1817 if (params_.noindent()) {
1818 os << "\\noindent ";
1822 LyXAlignment const curAlign = params_.align();
1824 if (curAlign == layout_->align)
1828 case LYX_ALIGN_NONE:
1829 case LYX_ALIGN_BLOCK:
1830 case LYX_ALIGN_LAYOUT:
1831 case LYX_ALIGN_SPECIAL:
1833 case LYX_ALIGN_LEFT:
1834 case LYX_ALIGN_RIGHT:
1835 case LYX_ALIGN_CENTER:
1836 if (runparams.moving_arg) {
1843 string const begin_tag = "\\begin";
1844 InsetCode code = ownerCode();
1845 bool const lastpar = runparams.isLastPar;
1848 case LYX_ALIGN_NONE:
1849 case LYX_ALIGN_BLOCK:
1850 case LYX_ALIGN_LAYOUT:
1851 case LYX_ALIGN_SPECIAL:
1853 case LYX_ALIGN_LEFT: {
1855 if (owner_->getParLanguage(bparams)->babel() != "hebrew")
1856 output = corrected_env(begin_tag, "flushleft", code, lastpar);
1858 output = corrected_env(begin_tag, "flushright", code, lastpar);
1859 os << from_ascii(output);
1860 adjust_row_column(output, texrow, column);
1862 } case LYX_ALIGN_RIGHT: {
1864 if (owner_->getParLanguage(bparams)->babel() != "hebrew")
1865 output = corrected_env(begin_tag, "flushright", code, lastpar);
1867 output = corrected_env(begin_tag, "flushleft", code, lastpar);
1868 os << from_ascii(output);
1869 adjust_row_column(output, texrow, column);
1871 } case LYX_ALIGN_CENTER: {
1873 output = corrected_env(begin_tag, "center", code, lastpar);
1874 os << from_ascii(output);
1875 adjust_row_column(output, texrow, column);
1884 int Paragraph::Private::endTeXParParams(BufferParams const & bparams,
1885 odocstream & os, TexRow & texrow,
1886 OutputParams const & runparams) const
1890 LyXAlignment const curAlign = params_.align();
1892 if (curAlign == layout_->align)
1896 case LYX_ALIGN_NONE:
1897 case LYX_ALIGN_BLOCK:
1898 case LYX_ALIGN_LAYOUT:
1899 case LYX_ALIGN_SPECIAL:
1901 case LYX_ALIGN_LEFT:
1902 case LYX_ALIGN_RIGHT:
1903 case LYX_ALIGN_CENTER:
1904 if (runparams.moving_arg) {
1911 string const end_tag = "\n\\par\\end";
1912 InsetCode code = ownerCode();
1913 bool const lastpar = runparams.isLastPar;
1916 case LYX_ALIGN_NONE:
1917 case LYX_ALIGN_BLOCK:
1918 case LYX_ALIGN_LAYOUT:
1919 case LYX_ALIGN_SPECIAL:
1921 case LYX_ALIGN_LEFT: {
1923 if (owner_->getParLanguage(bparams)->babel() != "hebrew")
1924 output = corrected_env(end_tag, "flushleft", code, lastpar);
1926 output = corrected_env(end_tag, "flushright", code, lastpar);
1927 os << from_ascii(output);
1928 adjust_row_column(output, texrow, column);
1930 } case LYX_ALIGN_RIGHT: {
1932 if (owner_->getParLanguage(bparams)->babel() != "hebrew")
1933 output = corrected_env(end_tag, "flushright", code, lastpar);
1935 output = corrected_env(end_tag, "flushleft", code, lastpar);
1936 os << from_ascii(output);
1937 adjust_row_column(output, texrow, column);
1939 } case LYX_ALIGN_CENTER: {
1941 output = corrected_env(end_tag, "center", code, lastpar);
1942 os << from_ascii(output);
1943 adjust_row_column(output, texrow, column);
1952 // This one spits out the text of the paragraph
1953 bool Paragraph::latex(BufferParams const & bparams,
1954 Font const & outerfont,
1955 odocstream & os, TexRow & texrow,
1956 OutputParams const & runparams,
1957 int start_pos, int end_pos) const
1959 LYXERR(Debug::LATEX, "Paragraph::latex... " << this);
1961 if (layout().inpreamble)
1964 bool return_value = false;
1966 bool const allowcust = allowParagraphCustomization();
1968 // FIXME This check should not be needed. Perhaps issue an
1969 // error if it triggers.
1970 Layout const & style = inInset().forcePlainLayout() ?
1971 bparams.documentClass().plainLayout() : *d->layout_;
1973 // Current base font for all inherited font changes, without any
1974 // change caused by an individual character, except for the language:
1975 // It is set to the language of the first character.
1976 // As long as we are in the label, this font is the base font of the
1977 // label. Before the first body character it is set to the base font
1981 // Maybe we have to create a optional argument.
1982 pos_type body_pos = beginOfBody();
1983 unsigned int column = 0;
1988 basefont = getLabelFont(bparams, outerfont);
1990 basefont = getLayoutFont(bparams, outerfont);
1993 // Which font is currently active?
1994 Font running_font(basefont);
1995 // Do we have an open font change?
1996 bool open_font = false;
1998 Change runningChange = Change(Change::UNCHANGED);
2000 Encoding const * const prev_encoding = runparams.encoding;
2002 texrow.start(id(), 0);
2004 // if the paragraph is empty, the loop will not be entered at all
2006 if (style.isCommand()) {
2011 column += d->startTeXParParams(bparams, os, texrow,
2015 for (pos_type i = 0; i < size(); ++i) {
2016 // First char in paragraph or after label?
2017 if (i == body_pos) {
2020 column += running_font.latexWriteEndChanges(
2021 os, bparams, runparams,
2022 basefont, basefont);
2025 basefont = getLayoutFont(bparams, outerfont);
2026 running_font = basefont;
2028 column += Changes::latexMarkChange(os, bparams,
2029 runningChange, Change(Change::UNCHANGED),
2031 runningChange = Change(Change::UNCHANGED);
2036 if (style.isCommand()) {
2042 column += d->startTeXParParams(bparams, os,
2047 Change const & change = runparams.inDeletedInset ? runparams.changeOfDeletedInset
2050 if (bparams.outputChanges && runningChange != change) {
2052 column += running_font.latexWriteEndChanges(
2053 os, bparams, runparams, basefont, basefont);
2056 basefont = getLayoutFont(bparams, outerfont);
2057 running_font = basefont;
2059 column += Changes::latexMarkChange(os, bparams, runningChange,
2061 runningChange = change;
2064 // do not output text which is marked deleted
2065 // if change tracking output is disabled
2066 if (!bparams.outputChanges && change.deleted()) {
2072 // Fully instantiated font
2073 Font const font = getFont(bparams, i, outerfont);
2075 Font const last_font = running_font;
2077 // Do we need to close the previous font?
2079 (font != running_font ||
2080 font.language() != running_font.language()))
2082 column += running_font.latexWriteEndChanges(
2083 os, bparams, runparams, basefont,
2084 (i == body_pos-1) ? basefont : font);
2085 running_font = basefont;
2089 // close babel's font environment before opening CJK.
2090 if (!running_font.language()->babel().empty() &&
2091 font.language()->encoding()->package() == Encoding::CJK) {
2092 string end_tag = subst(lyxrc.language_command_end,
2094 running_font.language()->babel());
2095 os << from_ascii(end_tag);
2096 column += end_tag.length();
2099 // Switch file encoding if necessary (and allowed)
2100 if (!runparams.verbatim &&
2101 runparams.encoding->package() != Encoding::none &&
2102 font.language()->encoding()->package() != Encoding::none) {
2103 pair<bool, int> const enc_switch = switchEncoding(os, bparams,
2104 runparams, *(font.language()->encoding()));
2105 if (enc_switch.first) {
2106 column += enc_switch.second;
2107 runparams.encoding = font.language()->encoding();
2111 char_type const c = d->text_[i];
2113 // Do we need to change font?
2114 if ((font != running_font ||
2115 font.language() != running_font.language()) &&
2118 odocstringstream ods;
2119 column += font.latexWriteStartChanges(ods, bparams,
2120 runparams, basefont,
2122 running_font = font;
2124 docstring fontchange = ods.str();
2125 // check whether the fontchange ends with a \\textcolor
2126 // modifier and the text starts with a space (bug 4473)
2127 docstring const last_modifier = rsplit(fontchange, '\\');
2128 if (prefixIs(last_modifier, from_ascii("textcolor")) && c == ' ')
2129 os << fontchange << from_ascii("{}");
2130 // check if the fontchange ends with a trailing blank
2131 // (like "\small " (see bug 3382)
2132 else if (suffixIs(fontchange, ' ') && c == ' ')
2133 os << fontchange.substr(0, fontchange.size() - 1)
2134 << from_ascii("{}");
2139 // FIXME: think about end_pos implementation...
2140 if (c == ' ' && i >= start_pos && (end_pos == -1 || i < end_pos)) {
2141 // FIXME: integrate this case in latexSpecialChar
2142 // Do not print the separation of the optional argument
2143 // if style.pass_thru is false. This works because
2144 // latexSpecialChar ignores spaces if
2145 // style.pass_thru is false.
2146 if (i != body_pos - 1) {
2147 if (d->simpleTeXBlanks(
2148 runparams, os, texrow,
2149 i, column, font, style)) {
2150 // A surrogate pair was output. We
2151 // must not call latexSpecialChar
2152 // in this iteration, since it would output
2153 // the combining character again.
2160 OutputParams rp = runparams;
2161 rp.free_spacing = style.free_spacing;
2162 rp.local_font = &font;
2163 rp.intitle = style.intitle;
2165 // Two major modes: LaTeX or plain
2166 // Handle here those cases common to both modes
2167 // and then split to handle the two modes separately.
2168 if (c == META_INSET) {
2169 if (i >= start_pos && (end_pos == -1 || i < end_pos)) {
2170 d->latexInset(bparams, os,
2171 texrow, rp, running_font,
2172 basefont, outerfont, open_font,
2173 runningChange, style, i, column);
2176 if (i >= start_pos && (end_pos == -1 || i < end_pos)) {
2178 d->latexSpecialChar(os, rp, running_font, runningChange,
2180 } catch (EncodingException & e) {
2181 if (runparams.dryrun) {
2182 os << "<" << _("LyX Warning: ")
2183 << _("uncodable character") << " '";
2187 // add location information and throw again.
2196 // Set the encoding to that returned from latexSpecialChar (see
2197 // comment for encoding member in OutputParams.h)
2198 runparams.encoding = rp.encoding;
2201 // If we have an open font definition, we have to close it
2203 #ifdef FIXED_LANGUAGE_END_DETECTION
2206 .latexWriteEndChanges(os, bparams, runparams,
2208 next_->getFont(bparams, 0, outerfont));
2210 running_font.latexWriteEndChanges(os, bparams,
2211 runparams, basefont, basefont);
2214 //FIXME: For now we ALWAYS have to close the foreign font settings if they are
2215 //FIXME: there as we start another \selectlanguage with the next paragraph if
2216 //FIXME: we are in need of this. This should be fixed sometime (Jug)
2217 running_font.latexWriteEndChanges(os, bparams, runparams,
2218 basefont, basefont);
2222 column += Changes::latexMarkChange(os, bparams, runningChange,
2223 Change(Change::UNCHANGED), runparams);
2225 // Needed if there is an optional argument but no contents.
2226 if (body_pos > 0 && body_pos == size()) {
2228 return_value = false;
2231 if (allowcust && d->endTeXParParams(bparams, os, texrow, runparams)
2232 && runparams.encoding != prev_encoding) {
2233 runparams.encoding = prev_encoding;
2234 if (!bparams.useXetex)
2235 os << setEncoding(prev_encoding->iconvName());
2238 LYXERR(Debug::LATEX, "Paragraph::latex... done " << this);
2239 return return_value;
2243 bool Paragraph::emptyTag() const
2245 for (pos_type i = 0; i < size(); ++i) {
2246 if (Inset const * inset = getInset(i)) {
2247 InsetCode lyx_code = inset->lyxCode();
2248 // FIXME testing like that is wrong. What is
2250 if (lyx_code != TOC_CODE &&
2251 lyx_code != INCLUDE_CODE &&
2252 lyx_code != GRAPHICS_CODE &&
2253 lyx_code != ERT_CODE &&
2254 lyx_code != LISTINGS_CODE &&
2255 lyx_code != FLOAT_CODE &&
2256 lyx_code != TABULAR_CODE) {
2260 char_type c = d->text_[i];
2261 if (c != ' ' && c != '\t')
2269 string Paragraph::getID(Buffer const & buf, OutputParams const & runparams)
2272 for (pos_type i = 0; i < size(); ++i) {
2273 if (Inset const * inset = getInset(i)) {
2274 InsetCode lyx_code = inset->lyxCode();
2275 if (lyx_code == LABEL_CODE) {
2276 InsetLabel const * const il = static_cast<InsetLabel const *>(inset);
2277 docstring const & id = il->getParam("name");
2278 return "id='" + to_utf8(sgml::cleanID(buf, runparams, id)) + "'";
2286 pos_type Paragraph::firstWordDocBook(odocstream & os, OutputParams const & runparams)
2290 for (i = 0; i < size(); ++i) {
2291 if (Inset const * inset = getInset(i)) {
2292 inset->docbook(os, runparams);
2294 char_type c = d->text_[i];
2297 os << sgml::escapeChar(c);
2304 pos_type Paragraph::firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runparams)
2308 for (i = 0; i < size(); ++i) {
2309 if (Inset const * inset = getInset(i)) {
2310 inset->xhtml(xs, runparams);
2312 char_type c = d->text_[i];
2315 xs << html::escapeChar(c);
2322 bool Paragraph::Private::onlyText(Buffer const & buf, Font const & outerfont, pos_type initial) const
2325 pos_type size = text_.size();
2326 for (pos_type i = initial; i < size; ++i) {
2327 Font font = owner_->getFont(buf.params(), i, outerfont);
2328 if (text_[i] == META_INSET)
2330 if (i != initial && font != font_old)
2339 void Paragraph::simpleDocBookOnePar(Buffer const & buf,
2341 OutputParams const & runparams,
2342 Font const & outerfont,
2343 pos_type initial) const
2345 bool emph_flag = false;
2347 Layout const & style = *d->layout_;
2349 style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
2351 if (style.pass_thru && !d->onlyText(buf, outerfont, initial))
2354 // parsing main loop
2355 for (pos_type i = initial; i < size(); ++i) {
2356 Font font = getFont(buf.params(), i, outerfont);
2358 // handle <emphasis> tag
2359 if (font_old.emph() != font.fontInfo().emph()) {
2360 if (font.fontInfo().emph() == FONT_ON) {
2363 } else if (i != initial) {
2364 os << "</emphasis>";
2369 if (Inset const * inset = getInset(i)) {
2370 inset->docbook(os, runparams);
2372 char_type c = d->text_[i];
2374 if (style.pass_thru)
2377 os << sgml::escapeChar(c);
2379 font_old = font.fontInfo();
2383 os << "</emphasis>";
2386 if (style.free_spacing)
2388 if (style.pass_thru && !d->onlyText(buf, outerfont, initial))
2393 docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
2395 OutputParams const & runparams,
2396 Font const & outerfont,
2398 pos_type initial) const
2402 bool emph_flag = false;
2403 bool bold_flag = false;
2404 std::string closing_tag;
2406 Layout const & style = *d->layout_;
2408 style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
2410 // parsing main loop
2411 for (pos_type i = initial; i < size(); ++i) {
2412 Font font = getFont(buf.params(), i, outerfont);
2415 if (font_old.emph() != font.fontInfo().emph()) {
2416 if (font.fontInfo().emph() == FONT_ON) {
2417 xs << StartTag("em");
2419 } else if (emph_flag && i != initial) {
2425 if (font_old.series() != font.fontInfo().series()) {
2426 if (font.fontInfo().series() == BOLD_SERIES) {
2427 xs << StartTag("strong");
2429 } else if (bold_flag && i != initial) {
2430 xs << EndTag("strong");
2435 // Other such tags? What about the other text ranges?
2437 Inset const * inset = getInset(i);
2439 InsetCommand const * ic = inset->asInsetCommand();
2440 InsetLayout const & il = inset->getLayout();
2441 if (!fortoc || il.isInToc() || (ic && ic->isInToc())) {
2442 OutputParams np = runparams;
2443 if (!il.htmlisblock())
2444 np.html_in_par = true;
2445 retval += inset->xhtml(xs, np);
2448 char_type c = d->text_[i];
2450 if (style.pass_thru)
2452 else if (c == '-') {
2455 if (j < size() && d->text_[j] == '-') {
2457 if (j < size() && d->text_[j] == '-') {
2458 str += from_ascii("—");
2461 str += from_ascii("–");
2467 // We don't want to escape the entities. Note that
2468 // it is safe to do this, since str can otherwise
2469 // only be "-". E.g., it can't be "<".
2470 xs << XHTMLStream::NextRaw() << str;
2474 font_old = font.fontInfo();
2482 bool Paragraph::isHfill(pos_type pos) const
2484 Inset const * inset = getInset(pos);
2485 return inset && (inset->lyxCode() == SPACE_CODE &&
2486 inset->isStretchableSpace());
2490 bool Paragraph::isNewline(pos_type pos) const
2492 Inset const * inset = getInset(pos);
2493 return inset && inset->lyxCode() == NEWLINE_CODE;
2497 bool Paragraph::isLineSeparator(pos_type pos) const
2499 char_type const c = d->text_[pos];
2500 if (isLineSeparatorChar(c))
2502 Inset const * inset = getInset(pos);
2503 return inset && inset->isLineSeparator();
2507 bool Paragraph::isWordSeparator(pos_type pos) const
2509 if (Inset const * inset = getInset(pos))
2510 return !inset->isLetter();
2511 char_type const c = d->text_[pos];
2512 // We want to pass the ' and escape chars to the spellchecker
2513 static docstring const quote = from_utf8(lyxrc.spellchecker_esc_chars + '\'');
2514 return (!isLetterChar(c) && !isDigit(c) && !contains(quote, c))
2519 bool Paragraph::isChar(pos_type pos) const
2521 if (Inset const * inset = getInset(pos))
2522 return inset->isChar();
2523 char_type const c = d->text_[pos];
2524 return !isLetterChar(c) && !isDigit(c) && !lyx::isSpace(c);
2528 bool Paragraph::isSpace(pos_type pos) const
2530 if (Inset const * inset = getInset(pos))
2531 return inset->isSpace();
2532 char_type const c = d->text_[pos];
2533 return lyx::isSpace(c);
2538 Paragraph::getParLanguage(BufferParams const & bparams) const
2541 return getFirstFontSettings(bparams).language();
2542 // FIXME: we should check the prev par as well (Lgb)
2543 return bparams.language;
2547 bool Paragraph::isRTL(BufferParams const & bparams) const
2549 return lyxrc.rtl_support
2550 && getParLanguage(bparams)->rightToLeft()
2551 && !inInset().getLayout().forceLTR();
2555 void Paragraph::changeLanguage(BufferParams const & bparams,
2556 Language const * from, Language const * to)
2558 // change language including dummy font change at the end
2559 for (pos_type i = 0; i <= size(); ++i) {
2560 Font font = getFontSettings(bparams, i);
2561 if (font.language() == from) {
2562 font.setLanguage(to);
2569 bool Paragraph::isMultiLingual(BufferParams const & bparams) const
2571 Language const * doc_language = bparams.language;
2572 FontList::const_iterator cit = d->fontlist_.begin();
2573 FontList::const_iterator end = d->fontlist_.end();
2575 for (; cit != end; ++cit)
2576 if (cit->font().language() != ignore_language &&
2577 cit->font().language() != latex_language &&
2578 cit->font().language() != doc_language)
2584 docstring Paragraph::asString(int options) const
2586 return asString(0, size(), options);
2590 docstring Paragraph::asString(pos_type beg, pos_type end, int options) const
2592 odocstringstream os;
2595 && options & AS_STR_LABEL
2596 && !d->params_.labelString().empty())
2597 os << d->params_.labelString() << ' ';
2599 for (pos_type i = beg; i < end; ++i) {
2600 char_type const c = d->text_[i];
2601 if (isPrintable(c) || c == '\t'
2602 || (c == '\n' && (options & AS_STR_NEWLINES)))
2604 else if (c == META_INSET && (options & AS_STR_INSETS)) {
2605 getInset(i)->tocString(os);
2606 if (getInset(i)->asInsetMath())
2615 docstring Paragraph::stringify(pos_type beg, pos_type end, int options, OutputParams & runparams) const
2617 odocstringstream os;
2620 && options & AS_STR_LABEL
2621 && !d->params_.labelString().empty())
2622 os << d->params_.labelString() << ' ';
2624 for (pos_type i = beg; i < end; ++i) {
2625 char_type const c = d->text_[i];
2626 if (isPrintable(c) || c == '\t'
2627 || (c == '\n' && (options & AS_STR_NEWLINES)))
2629 else if (c == META_INSET && (options & AS_STR_INSETS)) {
2630 getInset(i)->plaintext(os, runparams);
2638 void Paragraph::setInsetOwner(Inset const * inset)
2640 d->inset_owner_ = inset;
2644 int Paragraph::id() const
2650 Layout const & Paragraph::layout() const
2656 void Paragraph::setLayout(Layout const & layout)
2658 d->layout_ = &layout;
2662 void Paragraph::setDefaultLayout(DocumentClass const & tc)
2664 setLayout(tc.defaultLayout());
2668 void Paragraph::setPlainLayout(DocumentClass const & tc)
2670 setLayout(tc.plainLayout());
2674 void Paragraph::setPlainOrDefaultLayout(DocumentClass const & tclass)
2676 if (usePlainLayout())
2677 setPlainLayout(tclass);
2679 setDefaultLayout(tclass);
2683 Inset const & Paragraph::inInset() const
2685 LASSERT(d->inset_owner_, throw ExceptionMessage(BufferException,
2686 _("Memory problem"), _("Paragraph not properly initialized")));
2687 return *d->inset_owner_;
2691 ParagraphParameters & Paragraph::params()
2697 ParagraphParameters const & Paragraph::params() const
2703 bool Paragraph::isFreeSpacing() const
2705 if (d->layout_->free_spacing)
2707 return d->inset_owner_ && d->inset_owner_->isFreeSpacing();
2711 bool Paragraph::allowEmpty() const
2713 if (d->layout_->keepempty)
2715 return d->inset_owner_ && d->inset_owner_->allowEmpty();
2719 char_type Paragraph::transformChar(char_type c, pos_type pos) const
2721 if (!Encodings::isArabicChar(c))
2724 char_type prev_char = ' ';
2725 char_type next_char = ' ';
2727 for (pos_type i = pos - 1; i >= 0; --i) {
2728 char_type const par_char = d->text_[i];
2729 if (!Encodings::isArabicComposeChar(par_char)) {
2730 prev_char = par_char;
2735 for (pos_type i = pos + 1, end = size(); i < end; ++i) {
2736 char_type const par_char = d->text_[i];
2737 if (!Encodings::isArabicComposeChar(par_char)) {
2738 next_char = par_char;
2743 if (Encodings::isArabicChar(next_char)) {
2744 if (Encodings::isArabicChar(prev_char) &&
2745 !Encodings::isArabicSpecialChar(prev_char))
2746 return Encodings::transformChar(c, Encodings::FORM_MEDIAL);
2748 return Encodings::transformChar(c, Encodings::FORM_INITIAL);
2750 if (Encodings::isArabicChar(prev_char) &&
2751 !Encodings::isArabicSpecialChar(prev_char))
2752 return Encodings::transformChar(c, Encodings::FORM_FINAL);
2754 return Encodings::transformChar(c, Encodings::FORM_ISOLATED);
2759 int Paragraph::checkBiblio(Buffer const & buffer)
2762 // This is getting more and more a mess. ...We really should clean
2763 // up this bibitem issue for 1.6. See also bug 2743.
2765 // Add bibitem insets if necessary
2766 if (d->layout_->labeltype != LABEL_BIBLIO)
2769 bool hasbibitem = !d->insetlist_.empty()
2770 // Insist on it being in pos 0
2771 && d->text_[0] == META_INSET
2772 && d->insetlist_.begin()->inset->lyxCode() == BIBITEM_CODE;
2774 bool track_changes = buffer.params().trackChanges;
2779 // remove a bibitem in pos != 0
2780 // restore it later in pos 0 if necessary
2781 // (e.g. if a user inserts contents _before_ the item)
2782 // we're assuming there's only one of these, which there
2784 int erasedInsetPosition = -1;
2785 InsetList::iterator it = d->insetlist_.begin();
2786 InsetList::iterator end = d->insetlist_.end();
2787 for (; it != end; ++it)
2788 if (it->inset->lyxCode() == BIBITEM_CODE
2790 InsetBibitem * olditem = static_cast<InsetBibitem *>(it->inset);
2791 oldkey = olditem->getParam("key");
2792 oldlabel = olditem->getParam("label");
2793 erasedInsetPosition = it->pos;
2794 eraseChar(erasedInsetPosition, track_changes);
2798 // There was an InsetBibitem at the beginning, and we didn't
2799 // have to erase one.
2800 if (hasbibitem && erasedInsetPosition < 0)
2803 // There was an InsetBibitem at the beginning and we did have to
2804 // erase one. So we give its properties to the beginning inset.
2806 InsetBibitem * inset =
2807 static_cast<InsetBibitem *>(d->insetlist_.begin()->inset);
2808 if (!oldkey.empty())
2809 inset->setParam("key", oldkey);
2810 inset->setParam("label", oldlabel);
2811 return -erasedInsetPosition;
2814 // There was no inset at the beginning, so we need to create one with
2815 // the key and label of the one we erased.
2816 InsetBibitem * inset =
2817 new InsetBibitem(const_cast<Buffer *>(&buffer), InsetCommandParams(BIBITEM_CODE));
2818 // restore values of previously deleted item in this par.
2819 if (!oldkey.empty())
2820 inset->setParam("key", oldkey);
2821 inset->setParam("label", oldlabel);
2822 insertInset(0, static_cast<Inset *>(inset),
2823 Change(track_changes ? Change::INSERTED : Change::UNCHANGED));
2829 void Paragraph::checkAuthors(AuthorList const & authorList)
2831 d->changes_.checkAuthors(authorList);
2835 bool Paragraph::isChanged(pos_type pos) const
2837 return lookupChange(pos).changed();
2841 bool Paragraph::isInserted(pos_type pos) const
2843 return lookupChange(pos).inserted();
2847 bool Paragraph::isDeleted(pos_type pos) const
2849 return lookupChange(pos).deleted();
2853 InsetList const & Paragraph::insetList() const
2855 return d->insetlist_;
2859 void Paragraph::setBuffer(Buffer & b)
2861 d->insetlist_.setBuffer(b);
2865 Inset * Paragraph::releaseInset(pos_type pos)
2867 Inset * inset = d->insetlist_.release(pos);
2868 /// does not honour change tracking!
2869 eraseChar(pos, false);
2874 Inset * Paragraph::getInset(pos_type pos)
2876 return (pos < pos_type(d->text_.size()) && d->text_[pos] == META_INSET)
2877 ? d->insetlist_.get(pos) : 0;
2881 Inset const * Paragraph::getInset(pos_type pos) const
2883 return (pos < pos_type(d->text_.size()) && d->text_[pos] == META_INSET)
2884 ? d->insetlist_.get(pos) : 0;
2888 void Paragraph::changeCase(BufferParams const & bparams, pos_type pos,
2889 pos_type & right, TextCase action)
2891 // process sequences of modified characters; in change
2892 // tracking mode, this approach results in much better
2893 // usability than changing case on a char-by-char basis
2896 bool const trackChanges = bparams.trackChanges;
2898 bool capitalize = true;
2900 for (; pos < right; ++pos) {
2901 char_type oldChar = d->text_[pos];
2902 char_type newChar = oldChar;
2904 // ignore insets and don't play with deleted text!
2905 if (oldChar != META_INSET && !isDeleted(pos)) {
2907 case text_lowercase:
2908 newChar = lowercase(oldChar);
2910 case text_capitalization:
2912 newChar = uppercase(oldChar);
2916 case text_uppercase:
2917 newChar = uppercase(oldChar);
2922 if (isWordSeparator(pos) || isDeleted(pos)) {
2923 // permit capitalization again
2927 if (oldChar != newChar) {
2929 if (pos != right - 1)
2931 // step behind the changing area
2935 int erasePos = pos - changes.size();
2936 for (size_t i = 0; i < changes.size(); i++) {
2937 insertChar(pos, changes[i],
2938 getFontSettings(bparams,
2941 if (!eraseChar(erasePos, trackChanges)) {
2944 ++right; // expand selection
2952 bool Paragraph::find(docstring const & str, bool cs, bool mw,
2953 pos_type pos, bool del) const
2955 int const strsize = str.length();
2957 pos_type const parsize = d->text_.size();
2958 for (i = 0; pos + i < parsize; ++i) {
2961 if (cs && str[i] != d->text_[pos + i])
2963 if (!cs && uppercase(str[i]) != uppercase(d->text_[pos + i]))
2965 if (!del && isDeleted(pos + i))
2972 // if necessary, check whether string matches word
2974 if (pos > 0 && !isWordSeparator(pos - 1))
2976 if (pos + strsize < parsize
2977 && !isWordSeparator(pos + strsize))
2985 char_type Paragraph::getChar(pos_type pos) const
2987 return d->text_[pos];
2991 pos_type Paragraph::size() const
2993 return d->text_.size();
2997 bool Paragraph::empty() const
2999 return d->text_.empty();
3003 bool Paragraph::isInset(pos_type pos) const
3005 return d->text_[pos] == META_INSET;
3009 bool Paragraph::isSeparator(pos_type pos) const
3011 //FIXME: Are we sure this can be the only separator?
3012 return d->text_[pos] == ' ';
3016 void Paragraph::deregisterWords()
3018 Private::Words::const_iterator it;
3019 WordList & wl = theWordList();
3020 for (it = d->words_.begin(); it != d->words_.end(); ++it)
3026 void Paragraph::locateWord(pos_type & from, pos_type & to,
3027 word_location const loc) const
3030 case WHOLE_WORD_STRICT:
3031 if (from == 0 || from == size()
3032 || isWordSeparator(from)
3033 || isWordSeparator(from - 1)) {
3037 // no break here, we go to the next
3040 // If we are already at the beginning of a word, do nothing
3041 if (!from || isWordSeparator(from - 1))
3043 // no break here, we go to the next
3046 // always move the cursor to the beginning of previous word
3047 while (from && !isWordSeparator(from - 1))
3051 LYXERR0("Paragraph::locateWord: NEXT_WORD not implemented yet");
3054 // no need to move the 'from' cursor
3058 while (to < size() && !isWordSeparator(to))
3063 void Paragraph::collectWords()
3065 pos_type n = size();
3066 for (pos_type pos = 0; pos < n; ++pos) {
3067 if (isWordSeparator(pos))
3069 pos_type from = pos;
3070 locateWord(from, pos, WHOLE_WORD);
3071 if (pos - from >= 6) {
3072 docstring word = asString(from, pos, AS_STR_NONE);
3073 d->words_.insert(word);
3079 void Paragraph::registerWords()
3081 Private::Words::const_iterator it;
3082 WordList & wl = theWordList();
3083 for (it = d->words_.begin(); it != d->words_.end(); ++it)
3088 void Paragraph::updateWords()
3096 bool Paragraph::spellCheck(pos_type & from, pos_type & to, WordLangTuple & wl,
3097 docstring_list & suggestions, bool do_suggestion) const
3099 SpellChecker * speller = theSpellChecker();
3103 locateWord(from, to, WHOLE_WORD);
3104 if (from == to || from >= pos_type(d->text_.size()))
3107 docstring word = asString(from, to, AS_STR_INSETS);
3108 string const lang_code = lyxrc.spellchecker_alt_lang.empty()
3109 ? getFontSettings(d->inset_owner_->buffer().params(), from).language()->code()
3110 : lyxrc.spellchecker_alt_lang;
3111 wl = WordLangTuple(word, lang_code);
3112 SpellChecker::Result res = speller->check(wl);
3113 // Just ignore any error that the spellchecker reports.
3114 // FIXME: we should through out an exception and catch it in the GUI to
3115 // display the error.
3116 if (!speller->error().empty())
3119 bool const misspelled = res != SpellChecker::OK
3120 && res != SpellChecker::IGNORED_WORD;
3122 if (lyxrc.spellcheck_continuously)
3123 d->fontlist_.setMisspelled(from, to, misspelled);
3125 if (misspelled && do_suggestion)
3126 speller->suggest(wl, suggestions);
3128 suggestions.clear();
3134 bool Paragraph::isMisspelled(pos_type pos) const
3136 pos_type from = pos;
3139 docstring_list suggestions;
3140 return spellCheck(from, to, wl, suggestions, false);