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_;
195 ParagraphParameters params_;
197 /// for recording and looking up changes
201 InsetList insetlist_;
204 pos_type begin_of_body_;
206 typedef docstring TextContainer;
210 typedef set<docstring> Words;
212 map<Language, Words> words_;
214 Layout const * layout_;
220 struct special_phrase {
226 special_phrase const special_phrases[] = {
227 { "LyX", from_ascii("\\LyX{}"), false },
228 { "TeX", from_ascii("\\TeX{}"), true },
229 { "LaTeX2e", from_ascii("\\LaTeXe{}"), true },
230 { "LaTeX", from_ascii("\\LaTeX{}"), true },
233 size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase);
238 Paragraph::Private::Private(Paragraph * owner, Layout const & layout)
239 : owner_(owner), inset_owner_(0), id_(-1), begin_of_body_(0), layout_(&layout)
245 Paragraph::Private::Private(Private const & p, Paragraph * owner)
246 : owner_(owner), inset_owner_(p.inset_owner_), fontlist_(p.fontlist_),
247 id_(p.id_), params_(p.params_), changes_(p.changes_), insetlist_(p.insetlist_),
248 begin_of_body_(p.begin_of_body_), text_(p.text_), words_(p.words_),
254 Paragraph::Private::Private(Private const & p, Paragraph * owner,
255 pos_type beg, pos_type end)
256 : owner_(owner), inset_owner_(p.inset_owner_),
257 params_(p.params_), changes_(p.changes_),
258 insetlist_(p.insetlist_, beg, end),
259 begin_of_body_(p.begin_of_body_), words_(p.words_),
262 if (beg >= pos_type(p.text_.size()))
264 text_ = p.text_.substr(beg, end - beg);
266 FontList::const_iterator fcit = fontlist_.begin();
267 FontList::const_iterator fend = fontlist_.end();
268 for (; fcit != fend; ++fcit) {
269 if (fcit->pos() < beg)
271 if (fcit->pos() >= end) {
272 // Add last entry in the fontlist_.
273 fontlist_.set(text_.size() - 1, fcit->font());
276 // Add a new entry in the fontlist_.
277 fontlist_.set(fcit->pos() - beg, fcit->font());
282 void Paragraph::addChangesToToc(DocIterator const & cdit,
283 Buffer const & buf) const
285 d->changes_.addToToc(cdit, buf);
289 bool Paragraph::isDeleted(pos_type start, pos_type end) const
291 LASSERT(start >= 0 && start <= size(), /**/);
292 LASSERT(end > start && end <= size() + 1, /**/);
294 return d->changes_.isDeleted(start, end);
298 bool Paragraph::isChanged(pos_type start, pos_type end) const
300 LASSERT(start >= 0 && start <= size(), /**/);
301 LASSERT(end > start && end <= size() + 1, /**/);
303 return d->changes_.isChanged(start, end);
307 bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const
309 // keep the logic here in sync with the logic of eraseChars()
313 Change const change = d->changes_.lookup(size());
314 return change.inserted() && change.currentAuthor();
318 void Paragraph::setChange(Change const & change)
320 // beware of the imaginary end-of-par character!
321 d->changes_.set(change, 0, size() + 1);
324 * Propagate the change recursively - but not in case of DELETED!
326 * Imagine that your co-author makes changes in an existing inset. He
327 * sends your document to you and you come to the conclusion that the
328 * inset should go completely. If you erase it, LyX must not delete all
329 * text within the inset. Otherwise, the change tracked insertions of
330 * your co-author get lost and there is no way to restore them later.
332 * Conclusion: An inset's content should remain untouched if you delete it
335 if (!change.deleted()) {
336 for (pos_type pos = 0; pos < size(); ++pos) {
337 if (Inset * inset = getInset(pos))
338 inset->setChange(change);
344 void Paragraph::setChange(pos_type pos, Change const & change)
346 LASSERT(pos >= 0 && pos <= size(), /**/);
347 d->changes_.set(change, pos);
349 // see comment in setChange(Change const &) above
350 if (!change.deleted() && pos < size())
351 if (Inset * inset = getInset(pos))
352 inset->setChange(change);
356 Change const & Paragraph::lookupChange(pos_type pos) const
358 LASSERT(pos >= 0 && pos <= size(), /**/);
359 return d->changes_.lookup(pos);
363 void Paragraph::acceptChanges(pos_type start, pos_type end)
365 LASSERT(start >= 0 && start <= size(), /**/);
366 LASSERT(end > start && end <= size() + 1, /**/);
368 for (pos_type pos = start; pos < end; ++pos) {
369 switch (lookupChange(pos).type) {
370 case Change::UNCHANGED:
371 // accept changes in nested inset
372 if (Inset * inset = getInset(pos))
373 inset->acceptChanges();
376 case Change::INSERTED:
377 d->changes_.set(Change(Change::UNCHANGED), pos);
378 // also accept changes in nested inset
379 if (Inset * inset = getInset(pos))
380 inset->acceptChanges();
383 case Change::DELETED:
384 // Suppress access to non-existent
385 // "end-of-paragraph char"
387 eraseChar(pos, false);
398 void Paragraph::rejectChanges(pos_type start, pos_type end)
400 LASSERT(start >= 0 && start <= size(), /**/);
401 LASSERT(end > start && end <= size() + 1, /**/);
403 for (pos_type pos = start; pos < end; ++pos) {
404 switch (lookupChange(pos).type) {
405 case Change::UNCHANGED:
406 // reject changes in nested inset
407 if (Inset * inset = getInset(pos))
408 inset->rejectChanges();
411 case Change::INSERTED:
412 // Suppress access to non-existent
413 // "end-of-paragraph char"
415 eraseChar(pos, false);
421 case Change::DELETED:
422 d->changes_.set(Change(Change::UNCHANGED), pos);
424 // Do NOT reject changes within a deleted inset!
425 // There may be insertions of a co-author inside of it!
433 void Paragraph::Private::insertChar(pos_type pos, char_type c,
434 Change const & change)
436 LASSERT(pos >= 0 && pos <= int(text_.size()), /**/);
439 changes_.insert(change, pos);
441 // This is actually very common when parsing buffers (and
442 // maybe inserting ascii text)
443 if (pos == pos_type(text_.size())) {
444 // when appending characters, no need to update tables
449 text_.insert(text_.begin() + pos, c);
451 // Update the font table.
452 fontlist_.increasePosAfterPos(pos);
455 insetlist_.increasePosAfterPos(pos);
459 bool Paragraph::insertInset(pos_type pos, Inset * inset,
460 Change const & change)
462 LASSERT(inset, /**/);
463 LASSERT(pos >= 0 && pos <= size(), /**/);
465 // Paragraph::insertInset() can be used in cut/copy/paste operation where
466 // d->inset_owner_ is not set yet.
467 if (d->inset_owner_ && !d->inset_owner_->insetAllowed(inset->lyxCode()))
470 d->insertChar(pos, META_INSET, change);
471 LASSERT(d->text_[pos] == META_INSET, /**/);
473 // Add a new entry in the insetlist_.
474 d->insetlist_.insert(inset, pos);
479 bool Paragraph::eraseChar(pos_type pos, bool trackChanges)
481 LASSERT(pos >= 0 && pos <= size(), return false);
483 // keep the logic here in sync with the logic of isMergedOnEndOfParDeletion()
486 Change change = d->changes_.lookup(pos);
488 // set the character to DELETED if
489 // a) it was previously unchanged or
490 // b) it was inserted by a co-author
492 if (!change.changed() ||
493 (change.inserted() && !change.currentAuthor())) {
494 setChange(pos, Change(Change::DELETED));
498 if (change.deleted())
502 // Don't physically access the imaginary end-of-paragraph character.
503 // eraseChar() can only mark it as DELETED. A physical deletion of
504 // end-of-par must be handled externally.
510 d->changes_.erase(pos);
512 // if it is an inset, delete the inset entry
513 if (d->text_[pos] == META_INSET)
514 d->insetlist_.erase(pos);
516 d->text_.erase(d->text_.begin() + pos);
518 // Update the fontlist_
519 d->fontlist_.erase(pos);
521 // Update the insetlist_
522 d->insetlist_.decreasePosAfterPos(pos);
528 int Paragraph::eraseChars(pos_type start, pos_type end, bool trackChanges)
530 LASSERT(start >= 0 && start <= size(), /**/);
531 LASSERT(end >= start && end <= size() + 1, /**/);
534 for (pos_type count = end - start; count; --count) {
535 if (!eraseChar(i, trackChanges))
542 int Paragraph::Private::latexSurrogatePair(odocstream & os, char_type c,
543 char_type next, OutputParams const & runparams)
545 // Writing next here may circumvent a possible font change between
546 // c and next. Since next is only output if it forms a surrogate pair
547 // with c we can ignore this:
548 // A font change inside a surrogate pair does not make sense and is
549 // hopefully impossible to input.
550 // FIXME: change tracking
551 // Is this correct WRT change tracking?
552 Encoding const & encoding = *(runparams.encoding);
553 docstring const latex1 = encoding.latexChar(next);
554 docstring const latex2 = encoding.latexChar(c);
555 if (docstring(1, next) == latex1) {
556 // the encoding supports the combination
557 os << latex2 << latex1;
558 return latex1.length() + latex2.length();
559 } else if (runparams.local_font &&
560 runparams.local_font->language()->lang() == "polutonikogreek") {
561 // polutonikogreek only works without the brackets
562 os << latex1 << latex2;
563 return latex1.length() + latex2.length();
565 os << latex1 << '{' << latex2 << '}';
566 return latex1.length() + latex2.length() + 2;
570 bool Paragraph::Private::simpleTeXBlanks(OutputParams const & runparams,
571 odocstream & os, TexRow & texrow,
573 unsigned int & column,
575 Layout const & style)
577 if (style.pass_thru || runparams.verbatim)
580 if (i + 1 < int(text_.size())) {
581 char_type next = text_[i + 1];
582 if (Encodings::isCombiningChar(next)) {
583 // This space has an accent, so we must always output it.
584 column += latexSurrogatePair(os, ' ', next, runparams) - 1;
589 if (runparams.linelen > 0
590 && column > runparams.linelen
592 && text_[i - 1] != ' '
593 && (i + 1 < int(text_.size()))
594 // same in FreeSpacing mode
595 && !owner_->isFreeSpacing()
596 // In typewriter mode, we want to avoid
597 // ! . ? : at the end of a line
598 && !(font.fontInfo().family() == TYPEWRITER_FAMILY
599 && (text_[i - 1] == '.'
600 || text_[i - 1] == '?'
601 || text_[i - 1] == ':'
602 || text_[i - 1] == '!'))) {
605 texrow.start(owner_->id(), i + 1);
607 } else if (style.free_spacing) {
616 int Paragraph::Private::writeScriptChars(odocstream & os,
617 docstring const & ltx,
618 Change const & runningChange,
619 Encoding const & encoding,
622 // FIXME: modifying i here is not very nice...
624 // We only arrive here when a proper language for character text_[i] has
625 // not been specified (i.e., it could not be translated in the current
626 // latex encoding) or its latex translation has been forced, and it
627 // belongs to a known script.
628 // Parameter ltx contains the latex translation of text_[i] as specified
629 // in the unicodesymbols file and is something like "\textXXX{<spec>}".
630 // The latex macro name "textXXX" specifies the script to which text_[i]
631 // belongs and we use it in order to check whether characters from the
632 // same script immediately follow, such that we can collect them in a
633 // single "\textXXX" macro. So, we have to retain "\textXXX{<spec>"
634 // for the first char but only "<spec>" for all subsequent chars.
635 docstring::size_type const brace1 = ltx.find_first_of(from_ascii("{"));
636 docstring::size_type const brace2 = ltx.find_last_of(from_ascii("}"));
637 string script = to_ascii(ltx.substr(1, brace1 - 1));
640 bool closing_brace = true;
641 if (script == "textgreek" && encoding.latexName() == "iso-8859-7") {
642 // Correct encoding is being used, so we can avoid \textgreek.
645 closing_brace = false;
647 os << ltx.substr(pos, length);
648 int size = text_.size();
649 while (i + 1 < size) {
650 char_type const next = text_[i + 1];
651 // Stop here if next character belongs to another script
652 // or there is a change in change tracking status.
653 if (!Encodings::isKnownScriptChar(next, script) ||
654 runningChange != owner_->lookupChange(i + 1))
658 FontList::const_iterator cit = fontlist_.begin();
659 FontList::const_iterator end = fontlist_.end();
660 for (; cit != end; ++cit) {
661 if (cit->pos() >= i && !found) {
662 prev_font = cit->font();
665 if (cit->pos() >= i + 1)
668 // Stop here if there is a font attribute or encoding change.
669 if (found && cit != end && prev_font != cit->font())
671 docstring const latex = encoding.latexChar(next);
672 docstring::size_type const b1 =
673 latex.find_first_of(from_ascii("{"));
674 docstring::size_type const b2 =
675 latex.find_last_of(from_ascii("}"));
676 int const len = b2 - b1 - 1;
677 os << latex.substr(b1 + 1, len);
689 bool Paragraph::Private::isTextAt(string const & str, pos_type pos) const
691 pos_type const len = str.length();
693 // is the paragraph large enough?
694 if (pos + len > int(text_.size()))
697 // does the wanted text start at point?
698 for (string::size_type i = 0; i < str.length(); ++i) {
699 // Caution: direct comparison of characters works only
700 // because str is pure ASCII.
701 if (str[i] != text_[pos + i])
705 return fontlist_.hasChangeInRange(pos, len);
709 void Paragraph::Private::latexInset(
710 BufferParams const & bparams,
713 OutputParams & runparams,
716 Font const & outerfont,
718 Change & running_change,
719 Layout const & style,
721 unsigned int & column)
723 Inset * inset = owner_->getInset(i);
724 LASSERT(inset, /**/);
726 if (style.pass_thru) {
727 inset->plaintext(os, runparams);
731 // FIXME: move this to InsetNewline::latex
732 if (inset->lyxCode() == NEWLINE_CODE) {
733 // newlines are handled differently here than
734 // the default in simpleTeXSpecialChars().
735 if (!style.newline_allowed) {
739 column += running_font.latexWriteEndChanges(
740 os, bparams, runparams,
745 if (running_font.fontInfo().family() == TYPEWRITER_FAMILY)
748 basefont = owner_->getLayoutFont(bparams, outerfont);
749 running_font = basefont;
751 if (runparams.moving_arg)
756 texrow.start(owner_->id(), i + 1);
760 if (owner_->isDeleted(i)) {
761 if( ++runparams.inDeletedInset == 1)
762 runparams.changeOfDeletedInset = owner_->lookupChange(i);
765 if (inset->canTrackChanges()) {
766 column += Changes::latexMarkChange(os, bparams, running_change,
767 Change(Change::UNCHANGED), runparams);
768 running_change = Change(Change::UNCHANGED);
772 odocstream::pos_type const len = os.tellp();
774 if (inset->forceLTR()
775 && running_font.isRightToLeft()
776 // ERT is an exception, it should be output with no
777 // decorations at all
778 && inset->lyxCode() != ERT_CODE) {
779 if (running_font.language()->lang() == "farsi")
786 // FIXME: Bug: we can have an empty font change here!
787 // if there has just been a font change, we are going to close it
788 // right now, which means stupid latex code like \textsf{}. AFAIK,
789 // this does not harm dvi output. A minor bug, thus (JMarc)
791 // Some insets cannot be inside a font change command.
792 // However, even such insets *can* be placed in \L or \R
793 // or their equivalents (for RTL language switches), so we don't
794 // close the language in those cases.
795 // ArabTeX, though, cannot handle this special behavior, it seems.
796 bool arabtex = basefont.language()->lang() == "arabic_arabtex"
797 || running_font.language()->lang() == "arabic_arabtex";
798 if (open_font && inset->noFontChange()) {
799 bool closeLanguage = arabtex
800 || basefont.isRightToLeft() == running_font.isRightToLeft();
801 unsigned int count = running_font.latexWriteEndChanges(os,
802 bparams, runparams, basefont, basefont, closeLanguage);
804 // if any font properties were closed, update the running_font,
805 // making sure, however, to leave the language as it was
807 // FIXME: probably a better way to keep track of the old
808 // language, than copying the entire font?
809 Font const copy_font(running_font);
810 basefont = owner_->getLayoutFont(bparams, outerfont);
811 running_font = basefont;
813 running_font.setLanguage(copy_font.language());
814 // leave font open if language is still open
815 open_font = (running_font.language() == basefont.language());
817 runparams.local_font = &basefont;
824 tmp = inset->latex(os, runparams);
825 } catch (EncodingException & e) {
826 // add location information and throw again.
833 if (running_font.language()->lang() == "farsi")
840 for (int j = 0; j < tmp; ++j)
843 texrow.start(owner_->id(), i + 1);
846 column += os.tellp() - len;
849 if (owner_->isDeleted(i))
850 --runparams.inDeletedInset;
854 void Paragraph::Private::latexSpecialChar(
856 OutputParams const & runparams,
857 Font const & running_font,
858 Change const & running_change,
859 Layout const & style,
861 unsigned int & column)
863 char_type const c = text_[i];
865 if (style.pass_thru) {
867 // FIXME UNICODE: This can fail if c cannot
868 // be encoded in the current encoding.
873 if (runparams.verbatim) {
874 // FIXME UNICODE: This can fail if c cannot
875 // be encoded in the current encoding.
880 // If T1 font encoding is used, use the special
881 // characters it provides.
882 // NOTE: some languages reset the font encoding
884 if (!running_font.language()->internalFontEncoding()
885 && lyxrc.fontenc == "T1" && latexSpecialT1(c, os, i, column))
888 // \tt font needs special treatment
889 if (running_font.fontInfo().family() == TYPEWRITER_FAMILY
890 && latexSpecialTypewriter(c, os, i, column))
893 // Otherwise, we use what LaTeX provides us.
896 os << "\\textbackslash{}";
900 os << "\\textless{}";
904 os << "\\textgreater{}";
915 os << "\\char`\\\"{}";
920 case '%': case '#': case '{':
928 os << "\\textasciitilde{}";
933 os << "\\textasciicircum{}";
940 // avoid being mistaken for optional arguments
948 // Blanks are printed before font switching.
949 // Sure? I am not! (try nice-latex)
950 // I am sure it's correct. LyX might be smarter
951 // in the future, but for now, nothing wrong is
957 if (latexSpecialPhrase(os, i, column, runparams))
963 Encoding const & encoding = *(runparams.encoding);
964 if (i + 1 < int(text_.size())) {
965 char_type next = text_[i + 1];
966 if (Encodings::isCombiningChar(next)) {
967 column += latexSurrogatePair(os, c, next, runparams) - 1;
973 docstring const latex = encoding.latexChar(c);
974 if (Encodings::isKnownScriptChar(c, script)
975 && prefixIs(latex, from_ascii("\\" + script)))
976 column += writeScriptChars(os, latex,
977 running_change, encoding, i) - 1;
978 else if (latex.length() > 1 && latex[latex.length() - 1] != '}') {
979 // Prevent eating of a following
980 // space or command corruption by
981 // following characters
982 column += latex.length() + 1;
985 column += latex.length() - 1;
993 bool Paragraph::Private::latexSpecialT1(char_type const c, odocstream & os,
994 pos_type i, unsigned int & column)
1000 // In T1 encoding, these characters exist
1001 // but we should avoid ligatures
1002 if (i + 1 >= int(text_.size()) || text_[i + 1] != c)
1004 os << "\\textcompwordmark{}";
1011 // soul.sty breaks with \char`\"
1012 os << "\\textquotedbl{}";
1021 bool Paragraph::Private::latexSpecialTypewriter(char_type const c, odocstream & os,
1022 pos_type i, unsigned int & column)
1026 // within \ttfamily, "--" is merged to "-" (no endash)
1027 // so we avoid this rather irritating ligature
1028 if (i + 1 < int(text_.size()) && text_[i + 1] == '-') {
1035 // everything else has to be checked separately
1036 // (depending on the encoding)
1043 bool Paragraph::Private::latexSpecialPhrase(odocstream & os, pos_type & i,
1044 unsigned int & column, OutputParams const & runparams)
1046 // FIXME: if we have "LaTeX" with a font
1047 // change in the middle (before the 'T', then
1048 // the "TeX" part is still special cased.
1049 // Really we should only operate this on
1050 // "words" for some definition of word
1052 for (size_t pnr = 0; pnr < phrases_nr; ++pnr) {
1053 if (!isTextAt(special_phrases[pnr].phrase, i))
1055 if (runparams.moving_arg)
1057 os << special_phrases[pnr].macro;
1058 i += special_phrases[pnr].phrase.length() - 1;
1059 column += special_phrases[pnr].macro.length() - 1;
1066 void Paragraph::Private::validate(LaTeXFeatures & features) const
1068 if (layout_->inpreamble && inset_owner_) {
1069 Buffer const & buf = inset_owner_->buffer();
1070 BufferParams const & bp = buf.params();
1073 odocstringstream ods;
1074 owner_->latex(bp, f, ods, tr, features.runparams());
1075 docstring d = ods.str();
1077 features.addPreambleSnippet(to_utf8(d));
1080 // check the params.
1081 if (!params_.spacing().isDefault())
1082 features.require("setspace");
1085 features.useLayout(layout_->name());
1088 fontlist_.validate(features);
1090 // then the indentation
1091 if (!params_.leftIndent().zero())
1092 features.require("ParagraphLeftIndent");
1095 InsetList::const_iterator icit = insetlist_.begin();
1096 InsetList::const_iterator iend = insetlist_.end();
1097 for (; icit != iend; ++icit) {
1099 icit->inset->validate(features);
1100 if (layout_->needprotect &&
1101 icit->inset->lyxCode() == FOOT_CODE)
1102 features.require("NeedLyXFootnoteCode");
1106 // then the contents
1107 for (pos_type i = 0; i < int(text_.size()) ; ++i) {
1108 for (size_t pnr = 0; pnr < phrases_nr; ++pnr) {
1109 if (!special_phrases[pnr].builtin
1110 && isTextAt(special_phrases[pnr].phrase, i)) {
1111 features.require(special_phrases[pnr].phrase);
1115 Encodings::validate(text_[i], features);
1119 /////////////////////////////////////////////////////////////////////
1123 /////////////////////////////////////////////////////////////////////
1126 Layout const emptyParagraphLayout;
1129 Paragraph::Paragraph()
1130 : d(new Paragraph::Private(this, emptyParagraphLayout))
1137 Paragraph::Paragraph(Paragraph const & par)
1138 : itemdepth(par.itemdepth),
1139 d(new Paragraph::Private(*par.d, this))
1145 Paragraph::Paragraph(Paragraph const & par, pos_type beg, pos_type end)
1146 : itemdepth(par.itemdepth),
1147 d(new Paragraph::Private(*par.d, this, beg, end))
1153 Paragraph & Paragraph::operator=(Paragraph const & par)
1155 // needed as we will destroy the private part before copying it
1157 itemdepth = par.itemdepth;
1161 d = new Private(*par.d, this);
1168 Paragraph::~Paragraph()
1177 // this shall be called just before every "os << ..." action.
1178 void flushString(ostream & os, docstring & s)
1187 void Paragraph::write(ostream & os, BufferParams const & bparams,
1188 depth_type & dth) const
1190 // The beginning or end of a deeper (i.e. nested) area?
1191 if (dth != d->params_.depth()) {
1192 if (d->params_.depth() > dth) {
1193 while (d->params_.depth() > dth) {
1194 os << "\n\\begin_deeper";
1198 while (d->params_.depth() < dth) {
1199 os << "\n\\end_deeper";
1205 // First write the layout
1206 os << "\n\\begin_layout " << to_utf8(d->layout_->name()) << '\n';
1208 d->params_.write(os);
1210 Font font1(inherit_font, bparams.language);
1212 Change running_change = Change(Change::UNCHANGED);
1214 // this string is used as a buffer to avoid repetitive calls
1215 // to to_utf8(), which turn out to be expensive (JMarc)
1216 docstring write_buffer;
1219 for (pos_type i = 0; i <= size(); ++i) {
1221 Change const change = lookupChange(i);
1222 if (change != running_change)
1223 flushString(os, write_buffer);
1224 Changes::lyxMarkChange(os, bparams, column, running_change, change);
1225 running_change = change;
1230 // Write font changes (ignore spelling markers)
1231 Font font2 = getFontSettings(bparams, i);
1232 font2.setMisspelled(false);
1233 if (font2 != font1) {
1234 flushString(os, write_buffer);
1235 font2.lyxWriteChanges(font1, os);
1240 char_type const c = d->text_[i];
1243 if (Inset const * inset = getInset(i)) {
1244 flushString(os, write_buffer);
1245 if (inset->directWrite()) {
1246 // international char, let it write
1247 // code directly so it's shorter in
1253 os << "\\begin_inset ";
1255 os << "\n\\end_inset\n\n";
1261 flushString(os, write_buffer);
1262 os << "\n\\backslash\n";
1266 flushString(os, write_buffer);
1267 if (i + 1 < size() && d->text_[i + 1] == ' ') {
1274 if ((column > 70 && c == ' ')
1276 flushString(os, write_buffer);
1280 // this check is to amend a bug. LyX sometimes
1281 // inserts '\0' this could cause problems.
1283 write_buffer.push_back(c);
1285 LYXERR0("NUL char in structure.");
1291 flushString(os, write_buffer);
1292 os << "\n\\end_layout\n";
1296 void Paragraph::validate(LaTeXFeatures & features) const
1298 d->validate(features);
1302 void Paragraph::insert(pos_type start, docstring const & str,
1303 Font const & font, Change const & change)
1305 for (size_t i = 0, n = str.size(); i != n ; ++i)
1306 insertChar(start + i, str[i], font, change);
1310 void Paragraph::appendChar(char_type c, Font const & font,
1311 Change const & change)
1314 d->changes_.insert(change, d->text_.size());
1315 // when appending characters, no need to update tables
1316 d->text_.push_back(c);
1317 setFont(d->text_.size() - 1, font);
1321 void Paragraph::appendString(docstring const & s, Font const & font,
1322 Change const & change)
1324 pos_type end = s.size();
1325 size_t oldsize = d->text_.size();
1326 size_t newsize = oldsize + end;
1327 size_t capacity = d->text_.capacity();
1328 if (newsize >= capacity)
1329 d->text_.reserve(max(capacity + 100, newsize));
1331 // when appending characters, no need to update tables
1334 // FIXME: Optimize this!
1335 for (size_t i = oldsize; i != newsize; ++i) {
1337 d->changes_.insert(change, i);
1339 d->fontlist_.set(oldsize, font);
1340 d->fontlist_.set(newsize - 1, font);
1344 void Paragraph::insertChar(pos_type pos, char_type c,
1347 d->insertChar(pos, c, Change(trackChanges ?
1348 Change::INSERTED : Change::UNCHANGED));
1352 void Paragraph::insertChar(pos_type pos, char_type c,
1353 Font const & font, bool trackChanges)
1355 d->insertChar(pos, c, Change(trackChanges ?
1356 Change::INSERTED : Change::UNCHANGED));
1361 void Paragraph::insertChar(pos_type pos, char_type c,
1362 Font const & font, Change const & change)
1364 d->insertChar(pos, c, change);
1369 bool Paragraph::insertInset(pos_type pos, Inset * inset,
1370 Font const & font, Change const & change)
1372 bool const success = insertInset(pos, inset, change);
1373 // Set the font/language of the inset...
1379 void Paragraph::resetFonts(Font const & font)
1381 d->fontlist_.clear();
1382 d->fontlist_.set(0, font);
1383 d->fontlist_.set(d->text_.size() - 1, font);
1386 // Gets uninstantiated font setting at position.
1387 Font const & Paragraph::getFontSettings(BufferParams const & bparams,
1391 LYXERR0("pos: " << pos << " size: " << size());
1392 LASSERT(pos <= size(), /**/);
1395 FontList::const_iterator cit = d->fontlist_.fontIterator(pos);
1396 if (cit != d->fontlist_.end())
1399 if (pos == size() && !empty())
1400 return getFontSettings(bparams, pos - 1);
1402 // Optimisation: avoid a full font instantiation if there is no
1403 // language change from previous call.
1404 static Font previous_font;
1405 static Language const * previous_lang = 0;
1406 Language const * lang = getParLanguage(bparams);
1407 if (lang != previous_lang) {
1408 previous_lang = lang;
1409 previous_font = Font(inherit_font, lang);
1411 return previous_font;
1415 FontSpan Paragraph::fontSpan(pos_type pos) const
1417 LASSERT(pos <= size(), /**/);
1420 FontList::const_iterator cit = d->fontlist_.begin();
1421 FontList::const_iterator end = d->fontlist_.end();
1422 for (; cit != end; ++cit) {
1423 if (cit->pos() >= pos) {
1424 if (pos >= beginOfBody())
1425 return FontSpan(max(start, beginOfBody()),
1428 return FontSpan(start,
1429 min(beginOfBody() - 1,
1432 start = cit->pos() + 1;
1435 // This should not happen, but if so, we take no chances.
1436 // LYXERR0("Paragraph::getEndPosOfFontSpan: This should not happen!");
1437 return FontSpan(pos, pos);
1441 // Gets uninstantiated font setting at position 0
1442 Font const & Paragraph::getFirstFontSettings(BufferParams const & bparams) const
1444 if (!empty() && !d->fontlist_.empty())
1445 return d->fontlist_.begin()->font();
1447 // Optimisation: avoid a full font instantiation if there is no
1448 // language change from previous call.
1449 static Font previous_font;
1450 static Language const * previous_lang = 0;
1451 if (bparams.language != previous_lang) {
1452 previous_lang = bparams.language;
1453 previous_font = Font(inherit_font, bparams.language);
1456 return previous_font;
1460 // Gets the fully instantiated font at a given position in a paragraph
1461 // This is basically the same function as Text::GetFont() in text2.cpp.
1462 // The difference is that this one is used for generating the LaTeX file,
1463 // and thus cosmetic "improvements" are disallowed: This has to deliver
1464 // the true picture of the buffer. (Asger)
1465 Font const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
1466 Font const & outerfont) const
1468 LASSERT(pos >= 0, /**/);
1470 Font font = getFontSettings(bparams, pos);
1472 pos_type const body_pos = beginOfBody();
1473 FontInfo & fi = font.fontInfo();
1475 fi.realize(d->layout_->labelfont);
1477 fi.realize(d->layout_->font);
1479 fi.realize(outerfont.fontInfo());
1480 fi.realize(bparams.getFont().fontInfo());
1486 Font const Paragraph::getLabelFont
1487 (BufferParams const & bparams, Font const & outerfont) const
1489 FontInfo tmpfont = d->layout_->labelfont;
1490 tmpfont.realize(outerfont.fontInfo());
1491 tmpfont.realize(bparams.getFont().fontInfo());
1492 return Font(tmpfont, getParLanguage(bparams));
1496 Font const Paragraph::getLayoutFont
1497 (BufferParams const & bparams, Font const & outerfont) const
1499 FontInfo tmpfont = d->layout_->font;
1500 tmpfont.realize(outerfont.fontInfo());
1501 tmpfont.realize(bparams.getFont().fontInfo());
1502 return Font(tmpfont, getParLanguage(bparams));
1506 /// Returns the height of the highest font in range
1507 FontSize Paragraph::highestFontInRange
1508 (pos_type startpos, pos_type endpos, FontSize def_size) const
1510 return d->fontlist_.highestInRange(startpos, endpos, def_size);
1514 char_type Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
1516 char_type c = d->text_[pos];
1517 if (!lyxrc.rtl_support)
1547 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
1553 void Paragraph::setFont(pos_type pos, Font const & font)
1555 LASSERT(pos <= size(), /**/);
1557 // First, reduce font against layout/label font
1558 // Update: The setCharFont() routine in text2.cpp already
1559 // reduces font, so we don't need to do that here. (Asger)
1561 d->fontlist_.set(pos, font);
1565 void Paragraph::makeSameLayout(Paragraph const & par)
1567 d->layout_ = par.d->layout_;
1568 d->params_ = par.d->params_;
1572 bool Paragraph::stripLeadingSpaces(bool trackChanges)
1574 if (isFreeSpacing())
1580 while (pos < size() && (isNewline(pos) || isLineSeparator(pos))) {
1581 if (eraseChar(pos, trackChanges))
1587 return count > 0 || pos > 0;
1591 bool Paragraph::hasSameLayout(Paragraph const & par) const
1593 return par.d->layout_ == d->layout_
1594 && d->params_.sameLayout(par.d->params_);
1598 depth_type Paragraph::getDepth() const
1600 return d->params_.depth();
1604 depth_type Paragraph::getMaxDepthAfter() const
1606 if (d->layout_->isEnvironment())
1607 return d->params_.depth() + 1;
1609 return d->params_.depth();
1613 char Paragraph::getAlign() const
1615 if (d->params_.align() == LYX_ALIGN_LAYOUT)
1616 return d->layout_->align;
1618 return d->params_.align();
1622 docstring const & Paragraph::labelString() const
1624 return d->params_.labelString();
1628 // the next two functions are for the manual labels
1629 docstring const Paragraph::getLabelWidthString() const
1631 if (d->layout_->margintype == MARGIN_MANUAL
1632 || d->layout_->latextype == LATEX_BIB_ENVIRONMENT)
1633 return d->params_.labelWidthString();
1635 return _("Senseless with this layout!");
1639 void Paragraph::setLabelWidthString(docstring const & s)
1641 d->params_.labelWidthString(s);
1645 docstring Paragraph::expandLabel(Layout const & layout,
1646 BufferParams const & bparams, bool process_appendix) const
1648 DocumentClass const & tclass = bparams.documentClass();
1649 string const & lang = getParLanguage(bparams)->code();
1650 bool const in_appendix = process_appendix && d->params_.appendix();
1651 docstring fmt = translateIfPossible(layout.labelstring(in_appendix), lang);
1653 if (fmt.empty() && layout.labeltype == LABEL_COUNTER
1654 && !layout.counter.empty())
1655 return tclass.counters().theCounter(layout.counter, lang);
1657 // handle 'inherited level parts' in 'fmt',
1658 // i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
1659 size_t const i = fmt.find('@', 0);
1660 if (i != docstring::npos) {
1661 size_t const j = fmt.find('@', i + 1);
1662 if (j != docstring::npos) {
1663 docstring parent(fmt, i + 1, j - i - 1);
1664 docstring label = from_ascii("??");
1665 if (tclass.hasLayout(parent))
1666 docstring label = expandLabel(tclass[parent], bparams,
1668 fmt = docstring(fmt, 0, i) + label
1669 + docstring(fmt, j + 1, docstring::npos);
1673 return tclass.counters().counterLabel(fmt, lang);
1677 void Paragraph::applyLayout(Layout const & new_layout)
1679 d->layout_ = &new_layout;
1680 LyXAlignment const oldAlign = d->params_.align();
1682 if (!(oldAlign & d->layout_->alignpossible)) {
1683 frontend::Alert::warning(_("Alignment not permitted"),
1684 _("The new layout does not permit the alignment previously used.\nSetting to default."));
1685 d->params_.align(LYX_ALIGN_LAYOUT);
1690 pos_type Paragraph::beginOfBody() const
1692 return d->begin_of_body_;
1696 void Paragraph::setBeginOfBody()
1698 if (d->layout_->labeltype != LABEL_MANUAL) {
1699 d->begin_of_body_ = 0;
1703 // Unroll the first two cycles of the loop
1704 // and remember the previous character to
1705 // remove unnecessary getChar() calls
1707 pos_type end = size();
1708 if (i < end && !isNewline(i)) {
1710 char_type previous_char = 0;
1713 previous_char = d->text_[i];
1714 if (!isNewline(i)) {
1716 while (i < end && previous_char != ' ') {
1721 previous_char = temp;
1727 d->begin_of_body_ = i;
1731 bool Paragraph::allowParagraphCustomization() const
1733 return inInset().allowParagraphCustomization();
1737 bool Paragraph::usePlainLayout() const
1739 return inInset().usePlainLayout();
1745 // paragraphs inside floats need different alignment tags to avoid
1748 bool noTrivlistCentering(InsetCode code)
1750 return code == FLOAT_CODE
1751 || code == WRAP_CODE
1752 || code == CELL_CODE;
1756 string correction(string const & orig)
1758 if (orig == "flushleft")
1759 return "raggedright";
1760 if (orig == "flushright")
1761 return "raggedleft";
1762 if (orig == "center")
1768 string const corrected_env(string const & suffix, string const & env,
1769 InsetCode code, bool const lastpar)
1771 string output = suffix + "{";
1772 if (noTrivlistCentering(code)) {
1774 // the last paragraph in non-trivlist-aligned
1775 // context is special (to avoid unwanted whitespace)
1776 if (suffix == "\\begin")
1777 return "\\" + correction(env) + "{}";
1780 output += correction(env);
1784 if (suffix == "\\begin")
1790 void adjust_row_column(string const & str, TexRow & texrow, int & column)
1792 if (!contains(str, "\n"))
1793 column += str.size();
1797 column = rsplit(str, tmp, '\n').size();
1804 int Paragraph::Private::startTeXParParams(BufferParams const & bparams,
1805 odocstream & os, TexRow & texrow,
1806 OutputParams const & runparams) const
1810 if (params_.noindent()) {
1811 os << "\\noindent ";
1815 LyXAlignment const curAlign = params_.align();
1817 if (curAlign == layout_->align)
1821 case LYX_ALIGN_NONE:
1822 case LYX_ALIGN_BLOCK:
1823 case LYX_ALIGN_LAYOUT:
1824 case LYX_ALIGN_SPECIAL:
1826 case LYX_ALIGN_LEFT:
1827 case LYX_ALIGN_RIGHT:
1828 case LYX_ALIGN_CENTER:
1829 if (runparams.moving_arg) {
1836 string const begin_tag = "\\begin";
1837 InsetCode code = ownerCode();
1838 bool const lastpar = runparams.isLastPar;
1841 case LYX_ALIGN_NONE:
1842 case LYX_ALIGN_BLOCK:
1843 case LYX_ALIGN_LAYOUT:
1844 case LYX_ALIGN_SPECIAL:
1846 case LYX_ALIGN_LEFT: {
1848 if (owner_->getParLanguage(bparams)->babel() != "hebrew")
1849 output = corrected_env(begin_tag, "flushleft", code, lastpar);
1851 output = corrected_env(begin_tag, "flushright", code, lastpar);
1852 os << from_ascii(output);
1853 adjust_row_column(output, texrow, column);
1855 } case LYX_ALIGN_RIGHT: {
1857 if (owner_->getParLanguage(bparams)->babel() != "hebrew")
1858 output = corrected_env(begin_tag, "flushright", code, lastpar);
1860 output = corrected_env(begin_tag, "flushleft", code, lastpar);
1861 os << from_ascii(output);
1862 adjust_row_column(output, texrow, column);
1864 } case LYX_ALIGN_CENTER: {
1866 output = corrected_env(begin_tag, "center", code, lastpar);
1867 os << from_ascii(output);
1868 adjust_row_column(output, texrow, column);
1877 int Paragraph::Private::endTeXParParams(BufferParams const & bparams,
1878 odocstream & os, TexRow & texrow,
1879 OutputParams const & runparams) const
1883 LyXAlignment const curAlign = params_.align();
1885 if (curAlign == layout_->align)
1889 case LYX_ALIGN_NONE:
1890 case LYX_ALIGN_BLOCK:
1891 case LYX_ALIGN_LAYOUT:
1892 case LYX_ALIGN_SPECIAL:
1894 case LYX_ALIGN_LEFT:
1895 case LYX_ALIGN_RIGHT:
1896 case LYX_ALIGN_CENTER:
1897 if (runparams.moving_arg) {
1904 string const end_tag = "\n\\par\\end";
1905 InsetCode code = ownerCode();
1906 bool const lastpar = runparams.isLastPar;
1909 case LYX_ALIGN_NONE:
1910 case LYX_ALIGN_BLOCK:
1911 case LYX_ALIGN_LAYOUT:
1912 case LYX_ALIGN_SPECIAL:
1914 case LYX_ALIGN_LEFT: {
1916 if (owner_->getParLanguage(bparams)->babel() != "hebrew")
1917 output = corrected_env(end_tag, "flushleft", code, lastpar);
1919 output = corrected_env(end_tag, "flushright", code, lastpar);
1920 os << from_ascii(output);
1921 adjust_row_column(output, texrow, column);
1923 } case LYX_ALIGN_RIGHT: {
1925 if (owner_->getParLanguage(bparams)->babel() != "hebrew")
1926 output = corrected_env(end_tag, "flushright", code, lastpar);
1928 output = corrected_env(end_tag, "flushleft", code, lastpar);
1929 os << from_ascii(output);
1930 adjust_row_column(output, texrow, column);
1932 } case LYX_ALIGN_CENTER: {
1934 output = corrected_env(end_tag, "center", code, lastpar);
1935 os << from_ascii(output);
1936 adjust_row_column(output, texrow, column);
1945 // This one spits out the text of the paragraph
1946 bool Paragraph::latex(BufferParams const & bparams,
1947 Font const & outerfont,
1948 odocstream & os, TexRow & texrow,
1949 OutputParams const & runparams,
1950 int start_pos, int end_pos) const
1952 LYXERR(Debug::LATEX, "Paragraph::latex... " << this);
1954 if (layout().inpreamble)
1957 bool return_value = false;
1959 bool const allowcust = allowParagraphCustomization();
1961 // FIXME This check should not be needed. Perhaps issue an
1962 // error if it triggers.
1963 Layout const & style = inInset().forcePlainLayout() ?
1964 bparams.documentClass().plainLayout() : *d->layout_;
1966 // Current base font for all inherited font changes, without any
1967 // change caused by an individual character, except for the language:
1968 // It is set to the language of the first character.
1969 // As long as we are in the label, this font is the base font of the
1970 // label. Before the first body character it is set to the base font
1974 // Maybe we have to create a optional argument.
1975 pos_type body_pos = beginOfBody();
1976 unsigned int column = 0;
1981 basefont = getLabelFont(bparams, outerfont);
1983 basefont = getLayoutFont(bparams, outerfont);
1986 // Which font is currently active?
1987 Font running_font(basefont);
1988 // Do we have an open font change?
1989 bool open_font = false;
1991 Change runningChange = Change(Change::UNCHANGED);
1993 Encoding const * const prev_encoding = runparams.encoding;
1995 texrow.start(id(), 0);
1997 // if the paragraph is empty, the loop will not be entered at all
1999 if (style.isCommand()) {
2004 column += d->startTeXParParams(bparams, os, texrow,
2008 for (pos_type i = 0; i < size(); ++i) {
2009 // First char in paragraph or after label?
2010 if (i == body_pos) {
2013 column += running_font.latexWriteEndChanges(
2014 os, bparams, runparams,
2015 basefont, basefont);
2018 basefont = getLayoutFont(bparams, outerfont);
2019 running_font = basefont;
2021 column += Changes::latexMarkChange(os, bparams,
2022 runningChange, Change(Change::UNCHANGED),
2024 runningChange = Change(Change::UNCHANGED);
2029 if (style.isCommand()) {
2035 column += d->startTeXParParams(bparams, os,
2040 Change const & change = runparams.inDeletedInset ? runparams.changeOfDeletedInset
2043 if (bparams.outputChanges && runningChange != change) {
2045 column += running_font.latexWriteEndChanges(
2046 os, bparams, runparams, basefont, basefont);
2049 basefont = getLayoutFont(bparams, outerfont);
2050 running_font = basefont;
2052 column += Changes::latexMarkChange(os, bparams, runningChange,
2054 runningChange = change;
2057 // do not output text which is marked deleted
2058 // if change tracking output is disabled
2059 if (!bparams.outputChanges && change.deleted()) {
2065 // Fully instantiated font
2066 Font const font = getFont(bparams, i, outerfont);
2068 Font const last_font = running_font;
2070 // Do we need to close the previous font?
2072 (font != running_font ||
2073 font.language() != running_font.language()))
2075 column += running_font.latexWriteEndChanges(
2076 os, bparams, runparams, basefont,
2077 (i == body_pos-1) ? basefont : font);
2078 running_font = basefont;
2082 // close babel's font environment before opening CJK.
2083 if (!running_font.language()->babel().empty() &&
2084 font.language()->encoding()->package() == Encoding::CJK) {
2085 string end_tag = subst(lyxrc.language_command_end,
2087 running_font.language()->babel());
2088 os << from_ascii(end_tag);
2089 column += end_tag.length();
2092 // Switch file encoding if necessary (and allowed)
2093 if (!runparams.verbatim &&
2094 runparams.encoding->package() != Encoding::none &&
2095 font.language()->encoding()->package() != Encoding::none) {
2096 pair<bool, int> const enc_switch = switchEncoding(os, bparams,
2097 runparams, *(font.language()->encoding()));
2098 if (enc_switch.first) {
2099 column += enc_switch.second;
2100 runparams.encoding = font.language()->encoding();
2104 char_type const c = d->text_[i];
2106 // Do we need to change font?
2107 if ((font != running_font ||
2108 font.language() != running_font.language()) &&
2111 odocstringstream ods;
2112 column += font.latexWriteStartChanges(ods, bparams,
2113 runparams, basefont,
2115 running_font = font;
2117 docstring fontchange = ods.str();
2118 // check whether the fontchange ends with a \\textcolor
2119 // modifier and the text starts with a space (bug 4473)
2120 docstring const last_modifier = rsplit(fontchange, '\\');
2121 if (prefixIs(last_modifier, from_ascii("textcolor")) && c == ' ')
2122 os << fontchange << from_ascii("{}");
2123 // check if the fontchange ends with a trailing blank
2124 // (like "\small " (see bug 3382)
2125 else if (suffixIs(fontchange, ' ') && c == ' ')
2126 os << fontchange.substr(0, fontchange.size() - 1)
2127 << from_ascii("{}");
2132 // FIXME: think about end_pos implementation...
2133 if (c == ' ' && i >= start_pos && (end_pos == -1 || i < end_pos)) {
2134 // FIXME: integrate this case in latexSpecialChar
2135 // Do not print the separation of the optional argument
2136 // if style.pass_thru is false. This works because
2137 // latexSpecialChar ignores spaces if
2138 // style.pass_thru is false.
2139 if (i != body_pos - 1) {
2140 if (d->simpleTeXBlanks(
2141 runparams, os, texrow,
2142 i, column, font, style)) {
2143 // A surrogate pair was output. We
2144 // must not call latexSpecialChar
2145 // in this iteration, since it would output
2146 // the combining character again.
2153 OutputParams rp = runparams;
2154 rp.free_spacing = style.free_spacing;
2155 rp.local_font = &font;
2156 rp.intitle = style.intitle;
2158 // Two major modes: LaTeX or plain
2159 // Handle here those cases common to both modes
2160 // and then split to handle the two modes separately.
2161 if (c == META_INSET) {
2162 if (i >= start_pos && (end_pos == -1 || i < end_pos)) {
2163 d->latexInset(bparams, os,
2164 texrow, rp, running_font,
2165 basefont, outerfont, open_font,
2166 runningChange, style, i, column);
2169 if (i >= start_pos && (end_pos == -1 || i < end_pos)) {
2171 d->latexSpecialChar(os, rp, running_font, runningChange,
2173 } catch (EncodingException & e) {
2174 if (runparams.dryrun) {
2175 os << "<" << _("LyX Warning: ")
2176 << _("uncodable character") << " '";
2180 // add location information and throw again.
2189 // Set the encoding to that returned from latexSpecialChar (see
2190 // comment for encoding member in OutputParams.h)
2191 runparams.encoding = rp.encoding;
2194 // If we have an open font definition, we have to close it
2196 #ifdef FIXED_LANGUAGE_END_DETECTION
2199 .latexWriteEndChanges(os, bparams, runparams,
2201 next_->getFont(bparams, 0, outerfont));
2203 running_font.latexWriteEndChanges(os, bparams,
2204 runparams, basefont, basefont);
2207 //FIXME: For now we ALWAYS have to close the foreign font settings if they are
2208 //FIXME: there as we start another \selectlanguage with the next paragraph if
2209 //FIXME: we are in need of this. This should be fixed sometime (Jug)
2210 running_font.latexWriteEndChanges(os, bparams, runparams,
2211 basefont, basefont);
2215 column += Changes::latexMarkChange(os, bparams, runningChange,
2216 Change(Change::UNCHANGED), runparams);
2218 // Needed if there is an optional argument but no contents.
2219 if (body_pos > 0 && body_pos == size()) {
2221 return_value = false;
2224 if (allowcust && d->endTeXParParams(bparams, os, texrow, runparams)
2225 && runparams.encoding != prev_encoding) {
2226 runparams.encoding = prev_encoding;
2227 if (!bparams.useXetex)
2228 os << setEncoding(prev_encoding->iconvName());
2231 LYXERR(Debug::LATEX, "Paragraph::latex... done " << this);
2232 return return_value;
2236 bool Paragraph::emptyTag() const
2238 for (pos_type i = 0; i < size(); ++i) {
2239 if (Inset const * inset = getInset(i)) {
2240 InsetCode lyx_code = inset->lyxCode();
2241 // FIXME testing like that is wrong. What is
2243 if (lyx_code != TOC_CODE &&
2244 lyx_code != INCLUDE_CODE &&
2245 lyx_code != GRAPHICS_CODE &&
2246 lyx_code != ERT_CODE &&
2247 lyx_code != LISTINGS_CODE &&
2248 lyx_code != FLOAT_CODE &&
2249 lyx_code != TABULAR_CODE) {
2253 char_type c = d->text_[i];
2254 if (c != ' ' && c != '\t')
2262 string Paragraph::getID(Buffer const & buf, OutputParams const & runparams)
2265 for (pos_type i = 0; i < size(); ++i) {
2266 if (Inset const * inset = getInset(i)) {
2267 InsetCode lyx_code = inset->lyxCode();
2268 if (lyx_code == LABEL_CODE) {
2269 InsetLabel const * const il = static_cast<InsetLabel const *>(inset);
2270 docstring const & id = il->getParam("name");
2271 return "id='" + to_utf8(sgml::cleanID(buf, runparams, id)) + "'";
2279 pos_type Paragraph::firstWordDocBook(odocstream & os, OutputParams const & runparams)
2283 for (i = 0; i < size(); ++i) {
2284 if (Inset const * inset = getInset(i)) {
2285 inset->docbook(os, runparams);
2287 char_type c = d->text_[i];
2290 os << sgml::escapeChar(c);
2297 pos_type Paragraph::firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runparams)
2301 for (i = 0; i < size(); ++i) {
2302 if (Inset const * inset = getInset(i)) {
2303 inset->xhtml(xs, runparams);
2305 char_type c = d->text_[i];
2315 bool Paragraph::Private::onlyText(Buffer const & buf, Font const & outerfont, pos_type initial) const
2318 pos_type size = text_.size();
2319 for (pos_type i = initial; i < size; ++i) {
2320 Font font = owner_->getFont(buf.params(), i, outerfont);
2321 if (text_[i] == META_INSET)
2323 if (i != initial && font != font_old)
2332 void Paragraph::simpleDocBookOnePar(Buffer const & buf,
2334 OutputParams const & runparams,
2335 Font const & outerfont,
2336 pos_type initial) const
2338 bool emph_flag = false;
2340 Layout const & style = *d->layout_;
2342 style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
2344 if (style.pass_thru && !d->onlyText(buf, outerfont, initial))
2347 // parsing main loop
2348 for (pos_type i = initial; i < size(); ++i) {
2349 Font font = getFont(buf.params(), i, outerfont);
2351 // handle <emphasis> tag
2352 if (font_old.emph() != font.fontInfo().emph()) {
2353 if (font.fontInfo().emph() == FONT_ON) {
2356 } else if (i != initial) {
2357 os << "</emphasis>";
2362 if (Inset const * inset = getInset(i)) {
2363 inset->docbook(os, runparams);
2365 char_type c = d->text_[i];
2367 if (style.pass_thru)
2370 os << sgml::escapeChar(c);
2372 font_old = font.fontInfo();
2376 os << "</emphasis>";
2379 if (style.free_spacing)
2381 if (style.pass_thru && !d->onlyText(buf, outerfont, initial))
2386 docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
2388 OutputParams const & runparams,
2389 Font const & outerfont,
2391 pos_type initial) const
2395 bool emph_flag = false;
2396 bool bold_flag = false;
2399 Layout const & style = *d->layout_;
2402 // generate a magic label for this paragraph
2403 string const attr = "id='" + magicLabel() + "'";
2404 xs << CompTag("a", attr);
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 void Paragraph::setId(int id)
2656 Layout const & Paragraph::layout() const
2662 void Paragraph::setLayout(Layout const & layout)
2664 d->layout_ = &layout;
2668 void Paragraph::setDefaultLayout(DocumentClass const & tc)
2670 setLayout(tc.defaultLayout());
2674 void Paragraph::setPlainLayout(DocumentClass const & tc)
2676 setLayout(tc.plainLayout());
2680 void Paragraph::setPlainOrDefaultLayout(DocumentClass const & tclass)
2682 if (usePlainLayout())
2683 setPlainLayout(tclass);
2685 setDefaultLayout(tclass);
2689 Inset const & Paragraph::inInset() const
2691 LASSERT(d->inset_owner_, throw ExceptionMessage(BufferException,
2692 _("Memory problem"), _("Paragraph not properly initialized")));
2693 return *d->inset_owner_;
2697 ParagraphParameters & Paragraph::params()
2703 ParagraphParameters const & Paragraph::params() const
2709 bool Paragraph::isFreeSpacing() const
2711 if (d->layout_->free_spacing)
2713 return d->inset_owner_ && d->inset_owner_->isFreeSpacing();
2717 bool Paragraph::allowEmpty() const
2719 if (d->layout_->keepempty)
2721 return d->inset_owner_ && d->inset_owner_->allowEmpty();
2725 char_type Paragraph::transformChar(char_type c, pos_type pos) const
2727 if (!Encodings::isArabicChar(c))
2730 char_type prev_char = ' ';
2731 char_type next_char = ' ';
2733 for (pos_type i = pos - 1; i >= 0; --i) {
2734 char_type const par_char = d->text_[i];
2735 if (!Encodings::isArabicComposeChar(par_char)) {
2736 prev_char = par_char;
2741 for (pos_type i = pos + 1, end = size(); i < end; ++i) {
2742 char_type const par_char = d->text_[i];
2743 if (!Encodings::isArabicComposeChar(par_char)) {
2744 next_char = par_char;
2749 if (Encodings::isArabicChar(next_char)) {
2750 if (Encodings::isArabicChar(prev_char) &&
2751 !Encodings::isArabicSpecialChar(prev_char))
2752 return Encodings::transformChar(c, Encodings::FORM_MEDIAL);
2754 return Encodings::transformChar(c, Encodings::FORM_INITIAL);
2756 if (Encodings::isArabicChar(prev_char) &&
2757 !Encodings::isArabicSpecialChar(prev_char))
2758 return Encodings::transformChar(c, Encodings::FORM_FINAL);
2760 return Encodings::transformChar(c, Encodings::FORM_ISOLATED);
2765 int Paragraph::checkBiblio(Buffer const & buffer)
2768 // This is getting more and more a mess. ...We really should clean
2769 // up this bibitem issue for 1.6. See also bug 2743.
2771 // Add bibitem insets if necessary
2772 if (d->layout_->labeltype != LABEL_BIBLIO)
2775 bool hasbibitem = !d->insetlist_.empty()
2776 // Insist on it being in pos 0
2777 && d->text_[0] == META_INSET
2778 && d->insetlist_.begin()->inset->lyxCode() == BIBITEM_CODE;
2780 bool track_changes = buffer.params().trackChanges;
2785 // remove a bibitem in pos != 0
2786 // restore it later in pos 0 if necessary
2787 // (e.g. if a user inserts contents _before_ the item)
2788 // we're assuming there's only one of these, which there
2790 int erasedInsetPosition = -1;
2791 InsetList::iterator it = d->insetlist_.begin();
2792 InsetList::iterator end = d->insetlist_.end();
2793 for (; it != end; ++it)
2794 if (it->inset->lyxCode() == BIBITEM_CODE
2796 InsetBibitem * olditem = static_cast<InsetBibitem *>(it->inset);
2797 oldkey = olditem->getParam("key");
2798 oldlabel = olditem->getParam("label");
2799 erasedInsetPosition = it->pos;
2800 eraseChar(erasedInsetPosition, track_changes);
2804 // There was an InsetBibitem at the beginning, and we didn't
2805 // have to erase one.
2806 if (hasbibitem && erasedInsetPosition < 0)
2809 // There was an InsetBibitem at the beginning and we did have to
2810 // erase one. So we give its properties to the beginning inset.
2812 InsetBibitem * inset =
2813 static_cast<InsetBibitem *>(d->insetlist_.begin()->inset);
2814 if (!oldkey.empty())
2815 inset->setParam("key", oldkey);
2816 inset->setParam("label", oldlabel);
2817 return -erasedInsetPosition;
2820 // There was no inset at the beginning, so we need to create one with
2821 // the key and label of the one we erased.
2822 InsetBibitem * inset =
2823 new InsetBibitem(const_cast<Buffer *>(&buffer), InsetCommandParams(BIBITEM_CODE));
2824 // restore values of previously deleted item in this par.
2825 if (!oldkey.empty())
2826 inset->setParam("key", oldkey);
2827 inset->setParam("label", oldlabel);
2828 insertInset(0, static_cast<Inset *>(inset),
2829 Change(track_changes ? Change::INSERTED : Change::UNCHANGED));
2835 void Paragraph::checkAuthors(AuthorList const & authorList)
2837 d->changes_.checkAuthors(authorList);
2841 bool Paragraph::isChanged(pos_type pos) const
2843 return lookupChange(pos).changed();
2847 bool Paragraph::isInserted(pos_type pos) const
2849 return lookupChange(pos).inserted();
2853 bool Paragraph::isDeleted(pos_type pos) const
2855 return lookupChange(pos).deleted();
2859 InsetList const & Paragraph::insetList() const
2861 return d->insetlist_;
2865 void Paragraph::setBuffer(Buffer & b)
2867 d->insetlist_.setBuffer(b);
2871 Inset * Paragraph::releaseInset(pos_type pos)
2873 Inset * inset = d->insetlist_.release(pos);
2874 /// does not honour change tracking!
2875 eraseChar(pos, false);
2880 Inset * Paragraph::getInset(pos_type pos)
2882 return (pos < pos_type(d->text_.size()) && d->text_[pos] == META_INSET)
2883 ? d->insetlist_.get(pos) : 0;
2887 Inset const * Paragraph::getInset(pos_type pos) const
2889 return (pos < pos_type(d->text_.size()) && d->text_[pos] == META_INSET)
2890 ? d->insetlist_.get(pos) : 0;
2894 void Paragraph::changeCase(BufferParams const & bparams, pos_type pos,
2895 pos_type & right, TextCase action)
2897 // process sequences of modified characters; in change
2898 // tracking mode, this approach results in much better
2899 // usability than changing case on a char-by-char basis
2902 bool const trackChanges = bparams.trackChanges;
2904 bool capitalize = true;
2906 for (; pos < right; ++pos) {
2907 char_type oldChar = d->text_[pos];
2908 char_type newChar = oldChar;
2910 // ignore insets and don't play with deleted text!
2911 if (oldChar != META_INSET && !isDeleted(pos)) {
2913 case text_lowercase:
2914 newChar = lowercase(oldChar);
2916 case text_capitalization:
2918 newChar = uppercase(oldChar);
2922 case text_uppercase:
2923 newChar = uppercase(oldChar);
2928 if (isWordSeparator(pos) || isDeleted(pos)) {
2929 // permit capitalization again
2933 if (oldChar != newChar) {
2935 if (pos != right - 1)
2937 // step behind the changing area
2941 int erasePos = pos - changes.size();
2942 for (size_t i = 0; i < changes.size(); i++) {
2943 insertChar(pos, changes[i],
2944 getFontSettings(bparams,
2947 if (!eraseChar(erasePos, trackChanges)) {
2950 ++right; // expand selection
2958 bool Paragraph::find(docstring const & str, bool cs, bool mw,
2959 pos_type pos, bool del) const
2961 int const strsize = str.length();
2963 pos_type const parsize = d->text_.size();
2964 for (i = 0; pos + i < parsize; ++i) {
2967 if (cs && str[i] != d->text_[pos + i])
2969 if (!cs && uppercase(str[i]) != uppercase(d->text_[pos + i]))
2971 if (!del && isDeleted(pos + i))
2978 // if necessary, check whether string matches word
2980 if (pos > 0 && !isWordSeparator(pos - 1))
2982 if (pos + strsize < parsize
2983 && !isWordSeparator(pos + strsize))
2991 char_type Paragraph::getChar(pos_type pos) const
2993 return d->text_[pos];
2997 pos_type Paragraph::size() const
2999 return d->text_.size();
3003 bool Paragraph::empty() const
3005 return d->text_.empty();
3009 bool Paragraph::isInset(pos_type pos) const
3011 return d->text_[pos] == META_INSET;
3015 bool Paragraph::isSeparator(pos_type pos) const
3017 //FIXME: Are we sure this can be the only separator?
3018 return d->text_[pos] == ' ';
3022 void Paragraph::deregisterWords()
3024 map<Language, Private::Words>::const_iterator itl;
3025 Private::Words::const_iterator it;
3026 for (itl = d->words_.begin(); itl != d->words_.end(); ++itl) {
3027 WordList * wl = theWordList(itl->first);
3028 for (it = (itl->second).begin(); it != (itl->second).end(); ++it)
3035 void Paragraph::locateWord(pos_type & from, pos_type & to,
3036 word_location const loc) const
3039 case WHOLE_WORD_STRICT:
3040 if (from == 0 || from == size()
3041 || isWordSeparator(from)
3042 || isWordSeparator(from - 1)) {
3046 // no break here, we go to the next
3049 // If we are already at the beginning of a word, do nothing
3050 if (!from || isWordSeparator(from - 1))
3052 // no break here, we go to the next
3055 // always move the cursor to the beginning of previous word
3056 while (from && !isWordSeparator(from - 1))
3060 LYXERR0("Paragraph::locateWord: NEXT_WORD not implemented yet");
3063 // no need to move the 'from' cursor
3067 while (to < size() && !isWordSeparator(to))
3072 void Paragraph::collectWords()
3074 pos_type n = size();
3075 for (pos_type pos = 0; pos < n; ++pos) {
3076 if (isWordSeparator(pos))
3078 pos_type from = pos;
3079 locateWord(from, pos, WHOLE_WORD);
3080 if (pos - from >= 6) {
3081 docstring word = asString(from, pos, AS_STR_NONE);
3082 FontList::const_iterator cit = d->fontlist_.fontIterator(pos);
3083 if (cit == d->fontlist_.end())
3085 Language const * lang = cit->font().language();
3086 d->words_[*lang].insert(word);
3092 void Paragraph::registerWords()
3094 map<Language, Private::Words>::const_iterator itl;
3095 Private::Words::const_iterator it;
3096 for (itl = d->words_.begin(); itl != d->words_.end(); ++itl) {
3097 WordList * wl = theWordList(itl->first);
3098 for (it = (itl->second).begin(); it != (itl->second).end(); ++it)
3104 void Paragraph::updateWords()
3112 bool Paragraph::spellCheck(pos_type & from, pos_type & to, WordLangTuple & wl,
3113 docstring_list & suggestions, bool do_suggestion) const
3115 SpellChecker * speller = theSpellChecker();
3119 locateWord(from, to, WHOLE_WORD);
3120 if (from == to || from >= pos_type(d->text_.size()))
3123 docstring word = asString(from, to, AS_STR_INSETS);
3124 string const lang_code = lyxrc.spellchecker_alt_lang.empty()
3125 ? getFontSettings(d->inset_owner_->buffer().params(), from).language()->code()
3126 : lyxrc.spellchecker_alt_lang;
3127 wl = WordLangTuple(word, lang_code);
3128 SpellChecker::Result res = speller->check(wl);
3129 // Just ignore any error that the spellchecker reports.
3130 // FIXME: we should through out an exception and catch it in the GUI to
3131 // display the error.
3132 if (!speller->error().empty())
3135 bool const misspelled = res != SpellChecker::OK
3136 && res != SpellChecker::IGNORED_WORD;
3138 if (lyxrc.spellcheck_continuously)
3139 d->fontlist_.setMisspelled(from, to, misspelled);
3141 if (misspelled && do_suggestion)
3142 speller->suggest(wl, suggestions);
3144 suggestions.clear();
3150 bool Paragraph::isMisspelled(pos_type pos) const
3152 pos_type from = pos;
3155 docstring_list suggestions;
3156 return spellCheck(from, to, wl, suggestions, false);
3160 string Paragraph::magicLabel() const
3163 ss << "magicparlabel-" << id();