]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph_pimpl.C
Fix loop when opening TOC widget in an empty document, basically by Richard Heck.
[lyx.git] / src / paragraph_pimpl.C
index 900837a49a80d2c26e790ef0de5d81f4f2f965e5..d9d709156055f85d3d0611e6d33bc35a98155f99 100644 (file)
@@ -58,18 +58,6 @@ special_phrase const special_phrases[] = {
 
 size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase);
 
-
-/// Get the real encoding of a character with font \p font.
-/// doc_encoding == bparams.encoding(), but we use a precomputed variable
-/// since bparams.encoding() is expensive
-inline Encoding const & getEncoding(BufferParams const & bparams,
-               Encoding const & doc_encoding, LyXFont const & font)
-{
-       if (bparams.inputenc == "auto" || bparams.inputenc == "default")
-               return *(font.language()->encoding());
-       return doc_encoding;
-}
-
 } // namespace anon
 
 
@@ -397,8 +385,7 @@ int Paragraph::Pimpl::latexSurrogatePair(odocstream & os, value_type c,
 }
 
 
-bool Paragraph::Pimpl::simpleTeXBlanks(BufferParams const & bparams,
-                                       Encoding const & doc_encoding,
+bool Paragraph::Pimpl::simpleTeXBlanks(Encoding const & encoding,
                                        odocstream & os, TexRow & texrow,
                                        pos_type & i,
                                       unsigned int & column,
@@ -412,7 +399,6 @@ bool Paragraph::Pimpl::simpleTeXBlanks(BufferParams const & bparams,
                char_type next = getChar(i + 1);
                if (Encodings::isCombiningChar(next)) {
                        // This space has an accent, so we must always output it.
-                       Encoding const & encoding = getEncoding(bparams, doc_encoding, font);
                        column += latexSurrogatePair(os, ' ', next, encoding) - 1;
                        ++i;
                        return true;
@@ -478,11 +464,9 @@ bool Paragraph::Pimpl::isTextAt(string const & str, pos_type pos) const
 
 void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
                                             BufferParams const & bparams,
-                                            Encoding const & doc_encoding,
                                             odocstream & os,
                                             TexRow & texrow,
                                             OutputParams const & runparams,
-                                            LyXFont & font,
                                             LyXFont & running_font,
                                             LyXFont & basefont,
                                             LyXFont const & outerfont,
@@ -524,15 +508,16 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
                        } else {
                                if (open_font) {
                                        column += running_font.latexWriteEndChanges(
-                                               os, basefont, basefont, bparams);
+                                               os, basefont, basefont);
                                        open_font = false;
                                }
-                               basefont = owner_->getLayoutFont(bparams, outerfont);
-                               running_font = basefont;
 
-                               if (font.family() == LyXFont::TYPEWRITER_FAMILY)
+                               if (running_font.family() == LyXFont::TYPEWRITER_FAMILY)
                                        os << '~';
 
+                               basefont = owner_->getLayoutFont(bparams, outerfont);
+                               running_font = basefont;
+
                                if (runparams.moving_arg)
                                        os << "\\protect ";
 
@@ -578,7 +563,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
                // some insets cannot be inside a font change command
                if (open_font && inset->noFontChange()) {
                        column += running_font.latexWriteEndChanges(
-                                       os, basefont, basefont, bparams);
+                                       os, basefont, basefont);
                        open_font = false;
                        basefont = owner_->getLayoutFont(bparams, outerfont);
                        running_font = basefont;
@@ -634,7 +619,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
                                break;
                        }
                        // Typewriter font also has them
-                       if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
+                       if (running_font.family() == LyXFont::TYPEWRITER_FAMILY) {
                                os.put(c);
                                break;
                        }
@@ -657,9 +642,9 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
                        break;
 
                case '-': // "--" in Typewriter mode -> "-{}-"
-                       if (i <= size() - 2
-                           && getChar(i + 1) == '-'
-                           && font.family() == LyXFont::TYPEWRITER_FAMILY) {
+                       if (i <= size() - 2 &&
+                           getChar(i + 1) == '-' &&
+                           running_font.family() == LyXFont::TYPEWRITER_FAMILY) {
                                os << "-{}";
                                column += 2;
                        } else {
@@ -711,7 +696,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
                        // I assume this is hack treating typewriter as verbatim
                        // FIXME UNICODE: This can fail if c cannot be encoded
                        // in the current encoding.
-                       if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
+                       if (running_font.family() == LyXFont::TYPEWRITER_FAMILY) {
                                if (c != '\0') {
                                        os.put(c);
                                }
@@ -738,7 +723,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
                        }
 
                        if (pnr == phrases_nr && c != '\0') {
-                               Encoding const & encoding = getEncoding(bparams, doc_encoding, font);
+                               Encoding const & encoding = *(runparams.encoding);
                                if (i < size() - 1) {
                                        char_type next = getChar(i + 1);
                                        if (Encodings::isCombiningChar(next)) {
@@ -785,11 +770,11 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features,
        FontList::const_iterator fend = fontlist.end();
        for (; fcit != fend; ++fcit) {
                if (fcit->font().noun() == LyXFont::ON) {
-                       lyxerr[Debug::LATEX] << "font.noun: "
+                       LYXERR(Debug::LATEX) << "font.noun: "
                                             << fcit->font().noun()
                                             << endl;
                        features.require("noun");
-                       lyxerr[Debug::LATEX] << "Noun enabled. Font: "
+                       LYXERR(Debug::LATEX) << "Noun enabled. Font: "
                                             << to_utf8(fcit->font().stateText(0))
                                             << endl;
                }
@@ -804,7 +789,7 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features,
                        break;
                default:
                        features.require("color");
-                       lyxerr[Debug::LATEX] << "Color enabled. Font: "
+                       LYXERR(Debug::LATEX) << "Color enabled. Font: "
                                             << to_utf8(fcit->font().stateText(0))
                                             << endl;
                }
@@ -815,7 +800,7 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features,
                    language != latex_language)
                {
                        features.useLanguage(language);
-                       lyxerr[Debug::LATEX] << "Found language "
+                       LYXERR(Debug::LATEX) << "Found language "
                                             << language->babel() << endl;
                }
        }
@@ -836,7 +821,6 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features,
        }
 
        // then the contents
-       Encoding const & doc_encoding = bparams.encoding();
        for (pos_type i = 0; i < size() ; ++i) {
                for (size_t pnr = 0; pnr < phrases_nr; ++pnr) {
                        if (!special_phrases[pnr].builtin
@@ -845,12 +829,7 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features,
                                break;
                        }
                }
-               // We do not need the completely realized font, since we are
-               // only interested in the language, and that is never inherited.
-               // Therefore we can use getFontSettings instead of getFont.
-               LyXFont const & font = owner_->getFontSettings(bparams, i);
-               Encoding const & encoding = getEncoding(bparams, doc_encoding, font);
-               encoding.validate(getChar(i), features);
+               Encodings::validate(getChar(i), features);
        }
 }