]> git.lyx.org Git - lyx.git/blobdiff - src/Font.cpp
Reset dim width when computing MathRow metrics
[lyx.git] / src / Font.cpp
index 95d015b86749967a0f5f1a12a0a623e0e07249a6..b810e454d4c65335bed03d0bef5c613698d9f9ec 100644 (file)
@@ -94,7 +94,7 @@ char const * LaTeXSizeNames[NUM_SIZE + 4] =
 { "tiny", "scriptsize", "footnotesize", "small", "normalsize", "large",
   "Large", "LARGE", "huge", "Huge", "error8", "error9", "error10", "error11" };
 
-} // namespace anon
+} // namespace
 
 
 Font::Font(FontInfo bits, Language const * l)
@@ -166,8 +166,11 @@ docstring const stateText(FontInfo const & f)
                os << bformat(_("Underline %1$s, "),
                              _(GUIMiscNames[f.underbar()]));
        if (f.strikeout() != FONT_INHERIT)
-               os << bformat(_("Strikeout %1$s, "),
+               os << bformat(_("Strike out %1$s, "),
                              _(GUIMiscNames[f.strikeout()]));
+       if (f.xout() != FONT_INHERIT)
+               os << bformat(_("Cross out %1$s, "),
+                             _(GUIMiscNames[f.xout()]));
        if (f.uuline() != FONT_INHERIT)
                os << bformat(_("Double underline %1$s, "),
                              _(GUIMiscNames[f.uuline()]));
@@ -241,6 +244,9 @@ void Font::lyxWriteChanges(Font const & orgfont,
        if (orgfont.fontInfo().strikeout() != bits_.strikeout()) {
                os << "\\strikeout " << LyXMiscNames[bits_.strikeout()] << "\n";
        }
+       if (orgfont.fontInfo().xout() != bits_.xout()) {
+               os << "\\xout " << LyXMiscNames[bits_.xout()] << "\n";
+       }
        if (orgfont.fontInfo().uuline() != bits_.uuline()) {
                os << "\\uuline " << LyXMiscNames[bits_.uuline()] << "\n";
        }
@@ -287,7 +293,7 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
                        tmp += "{";
                        os << from_ascii(tmp);
                        count += tmp.length();
-                       pushPolyglossiaLang(language()->polyglossia());
+                       pushLanguageName(language()->polyglossia(), true);
                } else if (language()->encoding()->package() != Encoding::CJK) {
                        os << '{';
                        count += 1;
@@ -323,6 +329,8 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
                                      "$$lang", language()->babel());
                        os << from_ascii(tmp);
                        count += tmp.length();
+                       if (!lyxrc.language_command_end.empty())
+                               pushLanguageName(language()->babel(), true);
                } else if (language()->encoding()->package() != Encoding::CJK) {
                        os << '{';
                        count += 1;
@@ -341,18 +349,23 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
 
        // If the current language is Hebrew, Arabic, or Farsi
        // the numbers are written Left-to-Right. ArabTeX package
-       // reorders the number automatically but the packages used
-       // for Hebrew and Farsi (Arabi) do not.
-       if (bits_.number() == FONT_ON && prev.fontInfo().number() != FONT_ON
-               && (language()->lang() == "hebrew"
-                       || language()->lang() == "farsi" 
-                       || language()->lang() == "arabic_arabi")) {
+       // and bidi (polyglossia) reorder the number automatically
+       // but the packages used for Hebrew and Farsi (Arabi) do not.
+       if (!runparams.use_polyglossia
+           && !runparams.pass_thru
+           && bits_.number() == FONT_ON
+           && prev.fontInfo().number() != FONT_ON
+           && (language()->lang() == "hebrew"
+               || language()->lang() == "farsi"
+               || language()->lang() == "arabic_arabi")) {
                os << "{\\beginL ";
                count += 9;
        }
 
        FontInfo f = bits_;
        f.reduce(base.bits_);
+       FontInfo p = bits_;
+       p.reduce(prev.bits_);
 
        if (f.family() != INHERIT_FAMILY) {
                os << '\\'
@@ -376,10 +389,16 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
                env = true; //We have opened a new environment
        }
        if (f.color() != Color_inherit && f.color() != Color_ignore) {
-               os << "\\textcolor{"
-                  << from_ascii(lcolor.getLaTeXName(f.color()))
-                  << "}{";
-               count += lcolor.getLaTeXName(f.color()).length() + 13;
+               if (f.color() == Color_none && p.color() != Color_none) {
+                       // Color none: Close previous color, if any
+                       os << '}';
+                       ++count;
+               } else if (f.color() != Color_none) {
+                       os << "\\textcolor{"
+                          << from_ascii(lcolor.getLaTeXName(f.color()))
+                          << "}{";
+                       count += lcolor.getLaTeXName(f.color()).length() + 13;
+               }
                env = true; //We have opened a new environment
        }
        // FIXME: uncomment this when we support background.
@@ -422,17 +441,28 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
                count += 10;
                ++runparams.inulemcmd;
        }
+       if (f.uuline() == FONT_ON) {
+               os << "\\uuline{";
+               count += 11;
+               ++runparams.inulemcmd;
+       }
        if (f.strikeout() == FONT_ON) {
                os << "\\sout{";
                count += 9;
                ++runparams.inulemcmd;
        }
-       if (f.uuline() == FONT_ON) {
-               os << "\\uuline{";
-               count += 11;
+       if (f.xout() == FONT_ON) {
+               os << "\\xout{";
+               count += 9;
                ++runparams.inulemcmd;
        }
        if (f.uwave() == FONT_ON) {
+               if (runparams.inulemcmd) {
+                       // needed with nested uwave in xout
+                       // see https://tex.stackexchange.com/a/263042
+                       os << "\\ULdepth=1000pt";
+                       count += 15;
+               }
                os << "\\uwave{";
                count += 10;
                ++runparams.inulemcmd;
@@ -448,6 +478,7 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
                                  OutputParams const & runparams,
                                  Font const & base,
                                  Font const & next,
+                                 bool & needPar,
                                  bool const & closeLanguage) const
 {
        int count = 0;
@@ -474,7 +505,7 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
                ++count;
                env = true; // Size change need not bother about closing env.
        }
-       if (f.color() != Color_inherit && f.color() != Color_ignore) {
+       if (f.color() != Color_inherit && f.color() != Color_ignore && f.color() != Color_none) {
                os << '}';
                ++count;
                env = true; // Size change need not bother about closing env.
@@ -492,6 +523,11 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
        if (f.size() != FONT_SIZE_INHERIT) {
                // We only have to close if only size changed
                if (!env) {
+                       if (needPar && !closeLanguage) {
+                               os << "\\par";
+                               count += 4;
+                               needPar = false;
+                       }
                        os << '}';
                        ++count;
                }
@@ -506,6 +542,11 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
                ++count;
                --runparams.inulemcmd;
        }
+       if (f.xout() == FONT_ON) {
+               os << '}';
+               ++count;
+               --runparams.inulemcmd;
+       }
        if (f.uuline() == FONT_ON) {
                os << '}';
                ++count;
@@ -519,12 +560,15 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
 
        // If the current language is Hebrew, Arabic, or Farsi
        // the numbers are written Left-to-Right. ArabTeX package
-       // reorders the number automatically but the packages used
-       // for Hebrew and Farsi (Arabi) do not.
-       if (bits_.number() == FONT_ON && next.fontInfo().number() != FONT_ON
-               && (language()->lang() == "hebrew"
-                       || language()->lang() == "farsi"
-                       || language()->lang() == "arabic_arabi")) {
+       // and bidi (polyglossia) reorder the number automatically
+       // but the packages used for Hebrew and Farsi (Arabi) do not.
+       if (!runparams.use_polyglossia
+           && !runparams.pass_thru
+           && bits_.number() == FONT_ON
+           && next.fontInfo().number() != FONT_ON
+           && (language()->lang() == "hebrew"
+               || language()->lang() == "farsi"
+               || language()->lang() == "arabic_arabi")) {
                os << "\\endL}";
                count += 6;
        }
@@ -546,8 +590,11 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
            && language()->encoding()->package() != Encoding::CJK) {
                os << '}';
                ++count;
-               if (runparams.use_polyglossia)
-                       popPolyglossiaLang();
+               bool const using_begin_end =
+                       runparams.use_polyglossia ||
+                               !lyxrc.language_command_end.empty();
+               if (using_begin_end)
+                       popLanguageName();
        }
 
        return count;
@@ -567,6 +614,7 @@ string Font::toString(bool const toggle) const
           << "emph " << bits_.emph() << '\n'
           << "underbar " << bits_.underbar() << '\n'
           << "strikeout " << bits_.strikeout() << '\n'
+          << "xout " << bits_.xout() << '\n'
           << "uuline " << bits_.uuline() << '\n'
           << "uwave " << bits_.uwave() << '\n'
           << "noun " << bits_.noun() << '\n'
@@ -609,10 +657,10 @@ bool Font::fromString(string const & data, bool & toggle)
                        int const next = lex.getInteger();
                        bits_.setSize(FontSize(next));
 
-               } else if (token == "emph" || token == "underbar" ||
-                          token == "noun" || token == "number" ||
-                          token == "uuline" || token == "uwave" ||
-                          token == "strikeout") {
+               } else if (token == "emph" || token == "underbar"
+                       || token == "noun" || token == "number"
+                       || token == "uuline" || token == "uwave"
+                       || token == "strikeout" || token == "xout") {
 
                        int const next = lex.getInteger();
                        FontState const misc = FontState(next);
@@ -623,6 +671,8 @@ bool Font::fromString(string const & data, bool & toggle)
                                bits_.setUnderbar(misc);
                        else if (token == "strikeout")
                                bits_.setStrikeout(misc);
+                       else if (token == "xout")
+                               bits_.setXout(misc);
                        else if (token == "uuline")
                                bits_.setUuline(misc);
                        else if (token == "uwave")
@@ -678,7 +728,12 @@ void Font::validate(LaTeXFeatures & features) const
        if (bits_.strikeout() == FONT_ON) {
                LYXERR(Debug::LATEX, "font.strikeout: " << bits_.strikeout());
                features.require("ulem");
-               LYXERR(Debug::LATEX, "Strikeout enabled. Font: " << to_utf8(stateText(0)));
+               LYXERR(Debug::LATEX, "Strike out enabled. Font: " << to_utf8(stateText(0)));
+       }
+       if (bits_.xout() == FONT_ON) {
+               LYXERR(Debug::LATEX, "font.xout: " << bits_.xout());
+               features.require("ulem");
+               LYXERR(Debug::LATEX, "Cross out enabled. Font: " << to_utf8(stateText(0)));
        }
        if (bits_.uuline() == FONT_ON) {
                LYXERR(Debug::LATEX, "font.uuline: " << bits_.uuline());
@@ -750,6 +805,7 @@ ostream & operator<<(ostream & os, FontInfo const & f)
                << " emph " << f.emph()
                << " underbar " << f.underbar()
                << " strikeout " << f.strikeout()
+               << " xout " << f.xout()
                << " uuline " << f.uuline()
                << " uwave " << f.uwave()
                << " noun " << f.noun()