X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FParagraph.cpp;h=e46faab4b922848e6487ea7077d4ab64f138aa4b;hb=97e5041a4abfec0820b8c8662577e83ce0e6c3cd;hp=34a1c6aa5cdfd24eebf05a35195f2c14d7bf1221;hpb=237c713046fd59ce7364cd73b26b40291f3c5dbb;p=lyx.git diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 34a1c6aa5c..e46faab4b9 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -109,7 +109,7 @@ public: /// specified by the latex macro \p ltx, to \p os starting from \p i. /// \return the number of characters written. int writeScriptChars(odocstream & os, docstring const & ltx, - Change &, Encoding const &, pos_type & i); + Change const &, Encoding const &, pos_type & i); /// This could go to ParagraphParameters if we want to. int startTeXParParams(BufferParams const &, odocstream &, TexRow &, @@ -135,9 +135,9 @@ public: /// void latexSpecialChar( odocstream & os, - OutputParams & runparams, - Font & running_font, - Change & running_change, + OutputParams const & runparams, + Font const & running_font, + Change const & running_change, Layout const & style, pos_type & i, unsigned int & column); @@ -146,20 +146,20 @@ public: bool latexSpecialT1( char_type const c, odocstream & os, - pos_type & i, + pos_type i, unsigned int & column); /// bool latexSpecialTypewriter( char_type const c, odocstream & os, - pos_type & i, + pos_type i, unsigned int & column); /// bool latexSpecialPhrase( odocstream & os, pos_type & i, unsigned int & column, - OutputParams & runparams); + OutputParams const & runparams); /// void validate(LaTeXFeatures & features, @@ -457,7 +457,7 @@ bool Paragraph::insertInset(pos_type pos, Inset * inset, // Paragraph::insertInset() can be used in cut/copy/paste operation where // d->inset_owner_ is not set yet. - if (d->inset_owner_ && d->inset_owner_->insetAllowed(inset->lyxCode())) + if (d->inset_owner_ && !d->inset_owner_->insetAllowed(inset->lyxCode())) return false; d->insertChar(pos, META_INSET, change); @@ -603,7 +603,7 @@ bool Paragraph::Private::simpleTeXBlanks(OutputParams const & runparams, int Paragraph::Private::writeScriptChars(odocstream & os, docstring const & ltx, - Change & runningChange, + Change const & runningChange, Encoding const & encoding, pos_type & i) { @@ -840,9 +840,9 @@ void Paragraph::Private::latexInset( void Paragraph::Private::latexSpecialChar( odocstream & os, - OutputParams & runparams, - Font & running_font, - Change & running_change, + OutputParams const & runparams, + Font const & running_font, + Change const & running_change, Layout const & style, pos_type & i, unsigned int & column) @@ -970,7 +970,7 @@ void Paragraph::Private::latexSpecialChar( bool Paragraph::Private::latexSpecialT1(char_type const c, odocstream & os, - pos_type & i, unsigned int & column) + pos_type i, unsigned int & column) { switch (c) { case '>': @@ -998,7 +998,7 @@ bool Paragraph::Private::latexSpecialT1(char_type const c, odocstream & os, bool Paragraph::Private::latexSpecialTypewriter(char_type const c, odocstream & os, - pos_type & i, unsigned int & column) + pos_type i, unsigned int & column) { switch (c) { case '-': @@ -1020,7 +1020,7 @@ bool Paragraph::Private::latexSpecialTypewriter(char_type const c, odocstream & bool Paragraph::Private::latexSpecialPhrase(odocstream & os, pos_type & i, - unsigned int & column, OutputParams & runparams) + unsigned int & column, OutputParams const & runparams) { // FIXME: if we have "LaTeX" with a font // change in the middle (before the 'T', then @@ -1178,7 +1178,7 @@ void Paragraph::write(ostream & os, BufferParams const & bparams, break; // Write font changes - Font font2 = getFontSettings(bparams, i); + Font const & font2 = getFontSettings(bparams, i); if (font2 != font1) { font2.lyxWriteChanges(font1, os); column = 0; @@ -1327,7 +1327,7 @@ void Paragraph::resetFonts(Font const & font) } // Gets uninstantiated font setting at position. -Font const Paragraph::getFontSettings(BufferParams const & bparams, +Font const & Paragraph::getFontSettings(BufferParams const & bparams, pos_type pos) const { if (pos > size()) { @@ -1342,7 +1342,16 @@ Font const Paragraph::getFontSettings(BufferParams const & bparams, if (pos == size() && !empty()) return getFontSettings(bparams, pos - 1); - return Font(inherit_font, getParLanguage(bparams)); + // Optimisation: avoid a full font instantiation if there is no + // language change from previous call. + static Font previous_font; + static Language const * previous_lang = 0; + Language const * lang = getParLanguage(bparams); + if (lang != previous_lang) { + previous_lang = lang; + previous_font = Font(inherit_font, lang); + } + return previous_font; } @@ -1373,12 +1382,21 @@ FontSpan Paragraph::fontSpan(pos_type pos) const // Gets uninstantiated font setting at position 0 -Font const Paragraph::getFirstFontSettings(BufferParams const & bparams) const +Font const & Paragraph::getFirstFontSettings(BufferParams const & bparams) const { if (!empty() && !d->fontlist_.empty()) return d->fontlist_.begin()->font(); - return Font(inherit_font, bparams.language); + // Optimisation: avoid a full font instantiation if there is no + // language change from previous call. + static Font previous_font; + static Language const * previous_lang = 0; + if (bparams.language != previous_lang) { + previous_lang = bparams.language; + previous_font = Font(inherit_font, bparams.language); + } + + return previous_font; } @@ -1395,13 +1413,14 @@ Font const Paragraph::getFont(BufferParams const & bparams, pos_type pos, Font font = getFontSettings(bparams, pos); pos_type const body_pos = beginOfBody(); + FontInfo & fi = font.fontInfo(); if (pos < body_pos) - font.fontInfo().realize(d->layout_->labelfont); + fi.realize(d->layout_->labelfont); else - font.fontInfo().realize(d->layout_->font); + fi.realize(d->layout_->font); - font.fontInfo().realize(outerfont.fontInfo()); - font.fontInfo().realize(bparams.getFont().fontInfo()); + fi.realize(outerfont.fontInfo()); + fi.realize(bparams.getFont().fontInfo()); return font; }