]> git.lyx.org Git - lyx.git/blobdiff - src/BufferParams.cpp
Remove unneeded method.
[lyx.git] / src / BufferParams.cpp
index 0978b6fe7b54d68a0b1759a7f404f0c35aadf1f1..e1a279f3e1761dada9c7a8b8c33fd5ae3b179efc 100644 (file)
@@ -104,18 +104,6 @@ static char const * const tex_graphics[] = {
 
 namespace lyx {
 
-// XeTeX with TeX fonts:
-// run in 8-bit emulation mode and trick `inputenc` into working with XeTeX
-static docstring const xetex_pre_inputenc = from_ascii(
-       "\\XeTeXinputencoding \"bytes\" % current file\n"
-       "\\XeTeXdefaultencoding \"bytes\" % included files\n"
-       "\\makeatletter\n"
-       "\\let\\origUmathchar\\Umathchar\n"
-       "\\let\\Umathchar\\@undefined\n");
-static docstring const xetex_post_inputenc = from_ascii(
-       "\\let\\Umathchar\\origUmathchar\n"
-       "\\makeatother\n");
-
 // Local translators
 namespace {
 
@@ -431,7 +419,9 @@ BufferParams::BufferParams()
        use_microtype = false;
        use_dash_ligatures = true;
        fonts_expert_sc = false;
-       fonts_old_figures = false;
+       fonts_roman_osf = false;
+       fonts_sans_osf = false;
+       fonts_typewriter_osf = false;
        fonts_sans_scale[0] = 100;
        fonts_sans_scale[1] = 100;
        fonts_typewriter_scale[0] = 100;
@@ -844,8 +834,12 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                lex >> useNonTeXFonts;
        } else if (token == "\\font_sc") {
                lex >> fonts_expert_sc;
-       } else if (token == "\\font_osf") {
-               lex >> fonts_old_figures;
+       } else if (token == "\\font_roman_osf") {
+               lex >> fonts_roman_osf;
+       } else if (token == "\\font_sans_osf") {
+               lex >> fonts_sans_osf;
+       } else if (token == "\\font_typewriter_osf") {
+               lex >> fonts_typewriter_osf;
        } else if (token == "\\font_roman_opts") {
                lex >> font_roman_opts;
        } else if (token == "\\font_sf_scale") {
@@ -1269,7 +1263,9 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
           << "\n\\font_default_family " << fonts_default_family
           << "\n\\use_non_tex_fonts " << convert<string>(useNonTeXFonts)
           << "\n\\font_sc " << convert<string>(fonts_expert_sc)
-          << "\n\\font_osf " << convert<string>(fonts_old_figures);
+          << "\n\\font_roman_osf " << convert<string>(fonts_roman_osf)
+          << "\n\\font_sans_osf " << convert<string>(fonts_sans_osf)
+          << "\n\\font_typewriter_osf " << convert<string>(fonts_typewriter_osf);
        if (!font_roman_opts.empty())
                os << "\n\\font_roman_opts \"" << font_roman_opts << "\"";
        os << "\n\\font_sf_scale " << fonts_sans_scale[0]
@@ -1774,8 +1770,9 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                os << from_ascii(ams);
 
        if (useNonTeXFonts) {
-               // Babel loads fontspec itself
-               if (!features.isProvided("fontspec") && !features.useBabel())
+               // Babel (as of 2017/11/03) loads fontspec itself
+               if (!features.isProvided("fontspec")
+                   && !(features.useBabel() && features.isAvailable("babel-2017/11/03")))
                        os << "\\usepackage{fontspec}\n";
                if (features.mustProvide("unicode-math")
                    && features.isAvailable("unicode-math"))
@@ -2687,10 +2684,8 @@ FormatList const & BufferParams::exportableFormats(bool only_viewable) const
        if (useNonTeXFonts) {
                excludes.insert("latex");
                excludes.insert("pdflatex");
-       } else if (inputenc != "ascii" && inputenc != "utf8"
-                          && inputenc != "utf8x" && inputenc != "utf8-plain")
-                 // XeTeX with TeX fonts requires input encoding ascii or utf8
-                 // (https://www.tug.org/pipermail/xetex/2010-April/016452.html).
+       } else if (inputenc != "ascii" && inputenc != "utf8-plain")
+                 // XeTeX with TeX fonts requires input encoding ascii (#10600).
                  excludes.insert("xetex");
        FormatList result = theConverters().getReachable(backs[0], only_viewable,
                                                                                                         true, excludes);
@@ -2721,8 +2716,8 @@ vector<string> BufferParams::backends() const
                                v.push_back("pdflatex");
                                v.push_back("latex");
                        }
-                       if (useNonTeXFonts || inputenc == "ascii" || inputenc == "utf8"
-                           || inputenc == "utf8x" || inputenc == "utf8-plain")
+                       if (useNonTeXFonts 
+                               || inputenc == "ascii" || inputenc == "utf8-plain")
                                v.push_back("xetex");
                        v.push_back("luatex");
                        v.push_back("dviluatex");
@@ -3346,16 +3341,12 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
                        if (features.isRequired("japanese")
                            || features.isProvided("inputenc"))
                                break;
-                       if (features.runparams().flavor == OutputParams::XETEX)
-                               os << xetex_pre_inputenc;
                        os << "\\usepackage[" << from_ascii(encoding().latexName());
                        if (features.runparams().flavor == OutputParams::LUATEX
                            || features.runparams().flavor == OutputParams::DVILUATEX)
                                os << "]{luainputenc}\n";
                        else
                                os << "]{inputenc}\n";
-                       if (features.runparams().flavor == OutputParams::XETEX)
-                               os << xetex_post_inputenc;
                        break;
                }
        }
@@ -3408,42 +3399,47 @@ string const BufferParams::loadFonts(LaTeXFeatures & features) const
                // variants are understood by both engines. However,
                // we want to provide support for at least TeXLive 2009
                // (for XeTeX; LuaTeX is only supported as of v.2)
-               // Babel has its own higher-level interface on top of
-               // fontspec that is to be used.
-               bool const babel = features.useBabel();
+               // As of 2017/11/03, Babel has its own higher-level
+               // interface on top of fontspec that is to be used.
+               bool const babelfonts = features.useBabel()
+                               && features.isAvailable("babel-2017/11/03");
                string const texmapping =
                        (features.runparams().flavor == OutputParams::XETEX) ?
                        "Mapping=tex-text" : "Ligatures=TeX";
                if (fontsRoman() != "default") {
-                       if (babel)
+                       if (babelfonts)
                                os << "\\babelfont{rm}[";
                        else
                                os << "\\setmainfont[";
                        if (!font_roman_opts.empty())
                                os << font_roman_opts << ',';
                        os << texmapping;
-                       if (fonts_old_figures)
+                       if (fonts_roman_osf)
                                os << ",Numbers=OldStyle";
                        os << "]{" << parseFontName(fontsRoman()) << "}\n";
                }
                if (fontsSans() != "default") {
                        string const sans = parseFontName(fontsSans());
                        if (fontsSansScale() != 100) {
-                               if (babel)
+                               if (babelfonts)
                                        os << "\\babelfont{sf}";
                                else
                                        os << "\\setsansfont";
                                os << "[Scale="
                                   << float(fontsSansScale()) / 100 << ',';
+                               if (fonts_sans_osf)
+                                       os << "Numbers=OldStyle,";
                                if (!font_sans_opts.empty())
                                        os << font_sans_opts << ',';
                                os << texmapping << "]{"
                                   << sans << "}\n";
                        } else {
-                               if (babel)
+                               if (babelfonts)
                                        os << "\\babelfont{sf}[";
                                else
                                        os << "\\setsansfont[";
+                               if (fonts_sans_osf)
+                                       os << "Numbers=OldStyle,";
                                if (!font_sans_opts.empty())
                                        os << font_sans_opts << ',';
                                os << texmapping << "]{"
@@ -3453,23 +3449,34 @@ string const BufferParams::loadFonts(LaTeXFeatures & features) const
                if (fontsTypewriter() != "default") {
                        string const mono = parseFontName(fontsTypewriter());
                        if (fontsTypewriterScale() != 100) {
-                               if (babel)
+                               if (babelfonts)
                                        os << "\\babelfont{tt}";
                                else
                                        os << "\\setmonofont";
                                os << "[Scale="
                                   << float(fontsTypewriterScale()) / 100;
+                               if (fonts_typewriter_osf)
+                                       os << ",Numbers=OldStyle";
                                if (!font_typewriter_opts.empty())
                                        os << ',' << font_typewriter_opts;
                                os << "]{"
                                   << mono << "}\n";
                        } else {
-                               if (babel)
+                               if (babelfonts)
                                        os << "\\babelfont{tt}";
                                else
                                        os << "\\setmonofont";
-                               if (!font_typewriter_opts.empty())
-                                       os << '[' << font_typewriter_opts << ']';
+                               if (!font_typewriter_opts.empty() || fonts_typewriter_osf) {
+                                       os << '[';
+                                       if (fonts_typewriter_osf)
+                                               os << "Numbers=OldStyle";
+                                       if (!font_typewriter_opts.empty()) {
+                                               if (fonts_typewriter_osf)
+                                                       os << ',';
+                                               os << font_typewriter_opts;
+                                       }
+                                       os << ']';
+                               }
                                os << '{' << mono << "}\n";
                        }
                }
@@ -3484,22 +3491,22 @@ string const BufferParams::loadFonts(LaTeXFeatures & features) const
 
        // ROMAN FONTS
        os << theLaTeXFonts().getLaTeXFont(from_ascii(fontsRoman())).getLaTeXCode(
-               dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
+               dryrun, ot1, complete, fonts_expert_sc, fonts_roman_osf,
                nomath, font_roman_opts);
 
        // SANS SERIF
        os << theLaTeXFonts().getLaTeXFont(from_ascii(fontsSans())).getLaTeXCode(
-               dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
-               nomath, font_roman_opts, fontsSansScale());
+               dryrun, ot1, complete, fonts_expert_sc, fonts_sans_osf,
+               nomath, font_sans_opts, fontsSansScale());
 
        // MONOSPACED/TYPEWRITER
        os << theLaTeXFonts().getLaTeXFont(from_ascii(fontsTypewriter())).getLaTeXCode(
-               dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
-               nomath, font_roman_opts, fontsTypewriterScale());
+               dryrun, ot1, complete, fonts_expert_sc, fonts_typewriter_osf,
+               nomath, font_typewriter_opts, fontsTypewriterScale());
 
        // MATH
        os << theLaTeXFonts().getLaTeXFont(from_ascii(fontsMath())).getLaTeXCode(
-               dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
+               dryrun, ot1, complete, fonts_expert_sc, fonts_roman_osf,
                nomath);
 
        return os.str();