]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Remove invalid comment.
[lyx.git] / src / Paragraph.cpp
index cc0587e02d881f985c89c2ddbf33acdcdb1b2a35..991ab14a7527d65083207e171b9e34b8fb720fce 100644 (file)
@@ -83,6 +83,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);
@@ -247,6 +249,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_),
+         insetlist_(p.insetlist_, beg, end),
+         params_(p.params_), changes_(p.changes_),
+         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(), /**/);
@@ -566,9 +597,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{<spec>}".
+       // 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{<spec>}".
        // 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 +609,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 +652,10 @@ int Paragraph::Private::writeScriptChars(odocstream & os,
                length += len;
                ++i;
        }
-       os << '}';
-       ++length;
+       if (closing_brace) {
+               os << '}';
+               ++length;
+       }
        return length;
 }
 
@@ -1049,6 +1091,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
@@ -1605,12 +1655,12 @@ void Paragraph::setBeginOfBody()
 }
 
 
-bool Paragraph::forceEmptyLayout() const
+bool Paragraph::forcePlainLayout() const
 {
        Inset const * const inset = inInset();
        if (!inset)
                return true;
-       return inset->forceEmptyLayout();
+       return inset->forcePlainLayout();
 }
 
 
@@ -1623,12 +1673,12 @@ bool Paragraph::allowParagraphCustomization() const
 }
 
 
-bool Paragraph::useEmptyLayout() const
+bool Paragraph::usePlainLayout() const
 {
        Inset const * const inset = inInset();
        if (!inset)
                return false;
-       return inset->useEmptyLayout();
+       return inset->usePlainLayout();
 }
 
 
@@ -1822,10 +1872,10 @@ bool Paragraph::latex(BufferParams const & bparams,
 
        bool return_value = false;
 
-       bool asdefault = forceEmptyLayout();
+       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
@@ -2039,7 +2089,7 @@ bool Paragraph::latex(BufferParams const & bparams,
                        }
                }
 
-               // Set the encoding to that returned from simpleTeXSpecialChars (see
+               // Set the encoding to that returned from latexSpecialChar (see
                // comment for encoding member in OutputParams.h)
                runparams.encoding = rp.encoding;
        }
@@ -2365,10 +2415,10 @@ void Paragraph::setLayout(Layout const & layout)
 }
 
 
-void Paragraph::setEmptyOrDefaultLayout(DocumentClass const & tclass)
+void Paragraph::setPlainOrDefaultLayout(DocumentClass const & tclass)
 {
-       if (useEmptyLayout())
-               setLayout(tclass.emptyLayout());
+       if (usePlainLayout())
+               setLayout(tclass.plainLayout());
        else
                setLayout(tclass.defaultLayout());
 }
@@ -2554,6 +2604,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);