X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FFont.cpp;h=ee05efabbe045576788e18180556b59ecaf46c92;hb=71b8019d56142397994e0ef2d4244ada51f199d5;hp=7e8b3f4f2bcc2e9d8200b14305a0a848adb0460c;hpb=9aa0fe91f6f39ffd889af02e7bb00b7eef585abc;p=lyx.git diff --git a/src/Font.cpp b/src/Font.cpp index 7e8b3f4f2b..ee05efabbe 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -25,6 +25,7 @@ #include "LyXRC.h" #include "output_latex.h" #include "OutputParams.h" +#include "texstream.h" #include "support/lassert.h" #include "support/convert.h" @@ -93,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) @@ -165,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()])); @@ -240,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"; } @@ -286,6 +293,7 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams, tmp += "{"; os << from_ascii(tmp); count += tmp.length(); + pushLanguageName(language()->polyglossia(), true); } else if (language()->encoding()->package() != Encoding::CJK) { os << '{'; count += 1; @@ -321,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; @@ -337,20 +347,10 @@ 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")) { - os << "{\\beginL "; - count += 9; - } - FontInfo f = bits_; f.reduce(base.bits_); + FontInfo p = bits_; + p.reduce(prev.bits_); if (f.family() != INHERIT_FAMILY) { os << '\\' @@ -374,10 +374,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. @@ -390,6 +396,26 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams, env = true; //We have opened a new environment } */ + // If the current language is Hebrew, Arabic, or Farsi + // the numbers are written Left-to-Right. ArabTeX package + // and bidi (polyglossia with XeTeX) reorder the number automatically + // but the packages used for Hebrew and Farsi (Arabi) do not. + if (!(runparams.use_polyglossia && runparams.flavor == OutputParams::XETEX) + && !runparams.pass_thru + && bits_.number() == FONT_ON + && prev.fontInfo().number() != FONT_ON + && (language()->lang() == "hebrew" + || language()->lang() == "farsi" + || language()->lang() == "arabic_arabi")) { + if (runparams.use_polyglossia) { + // LuaTeX/luabidi + os << "\\LR{"; + count += 5; + } else { + os << "{\\beginL "; + count += 9; + } + } if (f.emph() == FONT_ON) { os << "\\emph{"; count += 6; @@ -420,17 +446,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; @@ -446,6 +483,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; @@ -472,7 +510,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. @@ -490,6 +528,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; } @@ -504,6 +547,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; @@ -517,14 +565,23 @@ 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")) { - os << "\\endL}"; - count += 6; + // and bidi (polyglossia with XeTeX) reorder the number automatically + // but the packages used for Hebrew and Farsi (Arabi) do not. + if (!(runparams.use_polyglossia && runparams.flavor == OutputParams::XETEX) + && !runparams.pass_thru + && bits_.number() == FONT_ON + && next.fontInfo().number() != FONT_ON + && (language()->lang() == "hebrew" + || language()->lang() == "farsi" + || language()->lang() == "arabic_arabi")) { + if (runparams.use_polyglossia) { + // LuaTeX/luabidi + os << "}"; + count += 1; + } else { + os << "\\endL}"; + count += 6; + } } if (open_encoding_) { @@ -544,6 +601,11 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams, && language()->encoding()->package() != Encoding::CJK) { os << '}'; ++count; + bool const using_begin_end = + runparams.use_polyglossia || + !lyxrc.language_command_end.empty(); + if (using_begin_end) + popLanguageName(); } return count; @@ -563,6 +625,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' @@ -605,10 +668,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); @@ -619,6 +682,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") @@ -674,7 +739,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()); @@ -695,6 +765,19 @@ void Font::validate(LaTeXFeatures & features) const case Color_latex: case Color_notelabel: break; + case Color_brown: + case Color_darkgray: + case Color_gray: + case Color_lightgray: + case Color_lime: + case Color_olive: + case Color_orange: + case Color_pink: + case Color_purple: + case Color_teal: + case Color_violet: + features.require("xcolor"); + break; default: features.require("color"); LYXERR(Debug::LATEX, "Color enabled. Font: " << to_utf8(stateText(0))); @@ -733,6 +816,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()