]> git.lyx.org Git - features.git/commitdiff
Fix 480937a103708a651/lyxgit, second attempt.
authorGünter Milde <milde@lyx.org>
Thu, 12 Nov 2015 15:55:04 +0000 (16:55 +0100)
committerGünter Milde <milde@lyx.org>
Thu, 12 Nov 2015 15:55:04 +0000 (16:55 +0100)
Prevent encoding changes whenever the TeX engine is XeTeX or LuaTeX,
as XeTeX/LuaTeX use only one encoding per document:

* with useNonTeXFonts: "utf8plain",
* with XeTeX and TeX fonts: "ascii" (inputenc fails),
* with LuaTeX and TeX fonts: only one encoding accepted by luainputenc.

+1 no needless encoding switches
+1 runparams.encoding matches the correct encoding at any time
+1 less complicated code.

-1 there may still be problems with CJK (possibly impossible to
   solve for Xe/LuaTeX with TeX fonts).

For LuaTeX & TeX fonts, the complete document uses the encoding
of the global document language.

See also #9740.

src/BufferParams.cpp
src/Font.cpp
src/LaTeXFeatures.cpp
src/Paragraph.cpp
src/output_latex.cpp

index c7ec167709746eef17d89bb687455435b5e7d818..fa2f97bb87869c41ffa336834b4c8634e47ccbb0 100644 (file)
@@ -2941,15 +2941,13 @@ docstring BufferParams::getGraphicsDriver(string const & package) const
 void BufferParams::writeEncodingPreamble(otexstream & os,
                                         LaTeXFeatures & features) const
 {
-       // "inputenc" package not required with non-TeX fonts.
-       if (useNonTeXFonts)
-               return;
-       // "inputenc"  fails with XeTeX (even in 8-bit compatiblitly mode) and with TeX fonts,
-       // (this is a bug in the "inputenc" package see #9740).
-       if (features.runparams().flavor == OutputParams::XETEX)
+       // XeTeX/LuaTeX: (see also #9740)
+       // With Unicode fonts we use utf8-plain without encoding package.
+       // With TeX fonts, we cannot use utf8-plain, but "inputenc" fails.
+       // XeTeX must use ASCII encoding, for LuaTeX, we load
+       // "luainputenc" (see below).
+       if (useNonTeXFonts || features.runparams().flavor == OutputParams::XETEX)
                return;
-       // For LuaTeX with TeX fonts, we can load
-       // the "luainputenc" package with the specified encoding(s) (see below).
 
        if (inputenc == "auto") {
                string const doc_encoding =
@@ -2957,10 +2955,12 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
                Encoding::Package const package =
                        language->encoding()->package();
 
-               // Create a list with all the input encodings used
-               // in the document
-               set<string> encodings =
-                       features.getEncodingSet(doc_encoding);
+               // Create list of inputenc options:
+               set<string> encodings;
+               // luainputenc fails with more than one encoding
+               if (!features.runparams().isFullUnicode()) // if we reach this point, this means LuaTeX with TeX fonts
+                       // list all input encodings used in the document
+                       encodings = features.getEncodingSet(doc_encoding);
 
                // If the "japanese" package (i.e. pLaTeX) is used,
                // inputenc must be omitted.
index f0814a3a3eb94103dbb8dd202a87595a3da88475..70bc25578baa03a558026a6d7603038c24894a34 100644 (file)
@@ -327,6 +327,7 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
                }
        }
 
+       // FIXME: skip this for XeTeX/LuaTeX? With nonTeXfonts or always?
        if (language()->encoding()->package() == Encoding::CJK) {
                pair<bool, int> const c = switchEncoding(os, bparams,
                                runparams, *(language()->encoding()));
index 5405ce0faf53b14b43464d3cf473f6fbab3d87e5..feab83769981c4c9416dafbb7d6a9e70c5cd9132 100644 (file)
@@ -711,8 +711,9 @@ set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
 
 void LaTeXFeatures::getFontEncodings(vector<string> & encodings) const
 {
-       // these must be loaded if glyphs of this script
-       // are used (notwithstanding the language)
+       // these must be loaded if glyphs of this script are used
+       // unless a language providing them is used in the document
+       // FIXME: currently the option is written twice in this case
        if (mustProvide("textgreek"))
                encodings.insert(encodings.begin(), "LGR");
        if (mustProvide("textcyr"))
index 2d3391885df625fc81e4f74da40ed25ac1932fce..ae2e6def1ff6ebda935983c446d775ee5f96d796 100644 (file)
@@ -2567,8 +2567,7 @@ void Paragraph::latex(BufferParams const & bparams,
        if (allowcust && d->endTeXParParams(bparams, os, runparams)
            && runparams.encoding != prev_encoding) {
                runparams.encoding = prev_encoding;
-               if (runparams.flavor != OutputParams::XETEX) // see BufferParams::encoding
-                       os << setEncoding(prev_encoding->iconvName());
+               os << setEncoding(prev_encoding->iconvName());
        }
 
        LYXERR(Debug::LATEX, "Paragraph::latex... done " << this);
index db6b890f14f11ab810b812ca8b5859159cbd1709..ee6fc313207259b40db544c40f26900fd813a1a2 100644 (file)
@@ -249,8 +249,7 @@ static void finishEnvironment(otexstream & os, OutputParams const & runparams,
                state->prev_env_language_ = data.par_language;
                if (runparams.encoding != data.prev_encoding) {
                        runparams.encoding = data.prev_encoding;
-                       if (runparams.flavor != OutputParams::XETEX) // see BufferParams::encoding
-                               os << setEncoding(data.prev_encoding->iconvName());
+                       os << setEncoding(data.prev_encoding->iconvName());
                }
        }
 
@@ -259,8 +258,7 @@ static void finishEnvironment(otexstream & os, OutputParams const & runparams,
                state->prev_env_language_ = data.par_language;
                if (runparams.encoding != data.prev_encoding) {
                        runparams.encoding = data.prev_encoding;
-                       if (runparams.flavor != OutputParams::XETEX) // see BufferParams::encoding
-                               os << setEncoding(data.prev_encoding->iconvName());
+                       os << setEncoding(data.prev_encoding->iconvName());
                }
        }
 
@@ -772,6 +770,7 @@ void TeXOnePar(Buffer const & buf,
        // encoding, since this only affects the position of the outputted
        // \inputencoding command; the encoding switch will occur when necessary
        if (bparams.inputenc == "auto"
+               && !runparams.isFullUnicode() // Xe/LuaTeX use one document-wide encoding  (see also switchEncoding())
                && runparams.encoding->package() != Encoding::none) {
                // Look ahead for future encoding changes.
                // We try to output them at the beginning of the paragraph,
@@ -884,8 +883,7 @@ void TeXOnePar(Buffer const & buf,
                        latexArgInsets(par, os, runparams, style.postcommandargs(), "post:");
                if (runparams.encoding != prev_encoding) {
                        runparams.encoding = prev_encoding;
-                       if (runparams.flavor != OutputParams::XETEX) // see BufferParams::encoding
-                               os << setEncoding(prev_encoding->iconvName());
+                       os << setEncoding(prev_encoding->iconvName());
                }
        }
 
@@ -1043,13 +1041,13 @@ void TeXOnePar(Buffer const & buf,
        }
 
        // If this is the last paragraph, and a local_font was set upon entering
-       // the inset, and we're using "auto" or "default" encoding, the encoding
+       // the inset, and we're using "auto" or "default" encoding, and not
+       // compiling with XeTeX or LuaTeX, the encoding
        // should be set back to that local_font's encoding.
-       // However, do not change the encoding when non-TeX fonts are used.
        if (runparams.isLastPar && runparams_in.local_font != 0
            && runparams_in.encoding != runparams_in.local_font->language()->encoding()
            && (bparams.inputenc == "auto" || bparams.inputenc == "default")
-               && runparams.flavor != OutputParams::XETEX // see BufferParams::encoding
+               && !runparams.isFullUnicode()
           ) {
                runparams_in.encoding = runparams_in.local_font->language()->encoding();
                os << setEncoding(runparams_in.encoding->iconvName());
@@ -1288,6 +1286,13 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
                   OutputParams const & runparams, Encoding const & newEnc,
                   bool force)
 {
+       // XeTeX/LuaTeX use only one encoding per document:
+       // * with useNonTeXFonts: "utf8plain",
+       // * with XeTeX and TeX fonts: "ascii" (inputenc fails),
+       // * with LuaTeX and TeX fonts: only one encoding accepted by luainputenc.
+       if (runparams.isFullUnicode())
+               return make_pair(false, 0);
+
        Encoding const & oldEnc = *runparams.encoding;
        bool moving_arg = runparams.moving_arg;
        // If we switch from/to CJK, we need to switch anyway, despite custom inputenc