X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FParagraph.cpp;h=2baa9b922e9ae4703fd3524f86c776835c5c56a8;hb=2f271f61bcd514da3ab5b44d2b7bf61e12ac0c44;hp=4a56d9669778fa686109db6ca801b22a4548dc7f;hpb=780bce0f96d5a1cccf62358de6c1a10ccdb3c949;p=lyx.git diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 4a56d96697..2baa9b922e 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -52,6 +52,7 @@ #include "support/lassert.h" #include "support/convert.h" #include "support/debug.h" +#include "support/ExceptionMessage.h" #include "support/gettext.h" #include "support/lstrings.h" #include "support/Messages.h" @@ -83,6 +84,8 @@ public: Private(Paragraph * owner, Layout const & layout); /// "Copy constructor" Private(Private const &, Paragraph * owner); + /// Copy constructor from \p beg to \p end + Private(Private const &, Paragraph * owner, pos_type beg, pos_type end); /// void insertChar(pos_type pos, char_type c, Change const & change); @@ -173,7 +176,7 @@ public: Paragraph * owner_; /// In which Inset? - Inset * inset_owner_; + Inset const * inset_owner_; /// FontList fontlist_; @@ -247,6 +250,35 @@ Paragraph::Private::Private(Private const & p, Paragraph * owner) } +Paragraph::Private::Private(Private const & p, Paragraph * owner, + pos_type beg, pos_type end) + : owner_(owner), inset_owner_(p.inset_owner_), + params_(p.params_), changes_(p.changes_), + insetlist_(p.insetlist_, beg, end), + begin_of_body_(p.begin_of_body_), words_(p.words_), + layout_(p.layout_) +{ + id_ = paragraph_id++; + if (beg >= pos_type(p.text_.size())) + return; + text_ = p.text_.substr(beg, end - beg); + + FontList::const_iterator fcit = fontlist_.begin(); + FontList::const_iterator fend = fontlist_.end(); + for (; fcit != fend; ++fcit) { + if (fcit->pos() < beg) + continue; + if (fcit->pos() >= end) { + // Add last entry in the fontlist_. + fontlist_.set(text_.size() - 1, fcit->font()); + break; + } + // Add a new entry in the fontlist_. + fontlist_.set(fcit->pos() - beg, fcit->font()); + } +} + + bool Paragraph::isChanged(pos_type start, pos_type end) const { LASSERT(start >= 0 && start <= size(), /**/); @@ -426,7 +458,7 @@ void Paragraph::insertInset(pos_type pos, Inset * inset, bool Paragraph::eraseChar(pos_type pos, bool trackChanges) { - LASSERT(pos >= 0 && pos <= size(), /**/); + LASSERT(pos >= 0 && pos <= size(), return false); // keep the logic here in sync with the logic of isMergedOnEndOfParDeletion() @@ -566,9 +598,10 @@ int Paragraph::Private::writeScriptChars(odocstream & os, // We only arrive here when a proper language for character text_[i] has // not been specified (i.e., it could not be translated in the current - // latex encoding) and it belongs to a known script. - // Parameter ltx contains the latex translation of text_[i] as specified in - // the unicodesymbols file and is something like "\textXXX{}". + // latex encoding) or its latex translation has been forced, and it + // belongs to a known script. + // Parameter ltx contains the latex translation of text_[i] as specified + // in the unicodesymbols file and is something like "\textXXX{}". // The latex macro name "textXXX" specifies the script to which text_[i] // belongs and we use it in order to check whether characters from the // same script immediately follow, such that we can collect them in a @@ -577,8 +610,16 @@ int Paragraph::Private::writeScriptChars(odocstream & os, docstring::size_type const brace1 = ltx.find_first_of(from_ascii("{")); docstring::size_type const brace2 = ltx.find_last_of(from_ascii("}")); string script = to_ascii(ltx.substr(1, brace1 - 1)); - int length = ltx.substr(0, brace2).length(); - os << ltx.substr(0, brace2); + int pos = 0; + int length = brace2; + bool closing_brace = true; + if (script == "textgreek" && encoding.latexName() == "iso-8859-7") { + // Correct encoding is being used, so we can avoid \textgreek. + pos = brace1 + 1; + length -= pos; + closing_brace = false; + } + os << ltx.substr(pos, length); int size = text_.size(); while (i + 1 < size) { char_type const next = text_[i + 1]; @@ -612,8 +653,10 @@ int Paragraph::Private::writeScriptChars(odocstream & os, length += len; ++i; } - os << '}'; - ++length; + if (closing_brace) { + os << '}'; + ++length; + } return length; } @@ -930,6 +973,11 @@ bool Paragraph::Private::latexSpecialT1(char_type const c, odocstream & os, case '|': os.put(c); return true; + case '\"': + // soul.sty breaks with \char`\" + os << "\\textquotedbl{}"; + column += 14; + return true; default: return false; } @@ -1049,6 +1097,14 @@ Paragraph::Paragraph(Paragraph const & par) } +Paragraph::Paragraph(Paragraph const & par, pos_type beg, pos_type end) + : itemdepth(par.itemdepth), + d(new Paragraph::Private(*par.d, this, beg, end)) +{ + registerWords(); +} + + Paragraph & Paragraph::operator=(Paragraph const & par) { // needed as we will destroy the private part before copying it @@ -1249,12 +1305,6 @@ void Paragraph::insertInset(pos_type pos, Inset * inset, } -bool Paragraph::insetAllowed(InsetCode code) -{ - return !d->inset_owner_ || d->inset_owner_->insetAllowed(code); -} - - void Paragraph::resetFonts(Font const & font) { d->fontlist_.clear(); @@ -1607,28 +1657,19 @@ void Paragraph::setBeginOfBody() bool Paragraph::forcePlainLayout() const { - Inset const * const inset = inInset(); - if (!inset) - return true; - return inset->forcePlainLayout(); + return inInset().forcePlainLayout(); } bool Paragraph::allowParagraphCustomization() const { - Inset const * const inset = inInset(); - if (!inset) - return true; - return inset->allowParagraphCustomization(); + return inInset().allowParagraphCustomization(); } bool Paragraph::usePlainLayout() const { - Inset const * const inset = inInset(); - if (!inset) - return false; - return inset->usePlainLayout(); + return inInset().usePlainLayout(); } @@ -1825,7 +1866,7 @@ bool Paragraph::latex(BufferParams const & bparams, bool asdefault = forcePlainLayout(); Layout const & style = asdefault ? - bparams.documentClass().emptyLayout() : + bparams.documentClass().plainLayout() : *d->layout_; // Current base font for all inherited font changes, without any @@ -2341,7 +2382,7 @@ docstring Paragraph::asString(pos_type beg, pos_type end, int options) const } -void Paragraph::setInsetOwner(Inset * inset) +void Paragraph::setInsetOwner(Inset const * inset) { d->inset_owner_ = inset; } @@ -2368,15 +2409,17 @@ void Paragraph::setLayout(Layout const & layout) void Paragraph::setPlainOrDefaultLayout(DocumentClass const & tclass) { if (usePlainLayout()) - setLayout(tclass.emptyLayout()); + setLayout(tclass.plainLayout()); else setLayout(tclass.defaultLayout()); } -Inset * Paragraph::inInset() const +Inset const & Paragraph::inInset() const { - return d->inset_owner_; + LASSERT(d->inset_owner_, throw ExceptionMessage(BufferException, + _("Memory problem"), _("Paragraph not properly initiliazed"))); + return *d->inset_owner_; } @@ -2554,6 +2597,12 @@ InsetList const & Paragraph::insetList() const } +void Paragraph::setBuffer(Buffer & b) +{ + d->insetlist_.setBuffer(b); +} + + Inset * Paragraph::releaseInset(pos_type pos) { Inset * inset = d->insetlist_.release(pos);