X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLaTeXFonts.cpp;h=00e19fa57dce537979b854e4652a52b6f7c46f48;hb=bf25e8568db22625feb3affbf3e31df804dae916;hp=bc4151cb2502cb16c7888b0d0c71dc8db10cb955;hpb=670efa8f646218f2a378f0cc614c4c37a9f6b89a;p=lyx.git diff --git a/src/LaTeXFonts.cpp b/src/LaTeXFonts.cpp index bc4151cb25..00e19fa57d 100644 --- a/src/LaTeXFonts.cpp +++ b/src/LaTeXFonts.cpp @@ -48,12 +48,12 @@ bool LaTeXFont::available(bool ot1, bool nomath) else if (ot1 && !ot1font_.empty()) return (ot1font_ == "none") ? true : altFont(ot1font_).available(ot1, nomath); - else if (requires_.empty() && package_.empty()) + else if (required_.empty() && package_.empty()) return true; - else if (!requires_.empty() - && LaTeXFeatures::isAvailable(to_ascii(requires_))) + else if (!required_.empty() + && LaTeXFeatures::isAvailable(to_ascii(required_))) return true; - else if (requires_.empty() && !package_.empty() + else if (required_.empty() && !package_.empty() && LaTeXFeatures::isAvailable(to_ascii(package_))) return true; else if (!altfonts_.empty()) { @@ -68,7 +68,7 @@ bool LaTeXFont::available(bool ot1, bool nomath) bool LaTeXFont::providesNoMath(bool ot1, bool complete) { - docstring const usedfont = getUsedFont(ot1, complete, false); + docstring const usedfont = getUsedFont(ot1, complete, false, false); if (usedfont.empty()) return false; @@ -81,7 +81,7 @@ bool LaTeXFont::providesNoMath(bool ot1, bool complete) bool LaTeXFont::providesOSF(bool ot1, bool complete, bool nomath) { - docstring const usedfont = getUsedFont(ot1, complete, nomath); + docstring const usedfont = getUsedFont(ot1, complete, nomath, false); if (usedfont.empty()) return false; @@ -98,7 +98,7 @@ bool LaTeXFont::providesOSF(bool ot1, bool complete, bool nomath) bool LaTeXFont::providesSC(bool ot1, bool complete, bool nomath) { - docstring const usedfont = getUsedFont(ot1, complete, nomath); + docstring const usedfont = getUsedFont(ot1, complete, nomath, false); if (usedfont.empty()) return false; @@ -113,7 +113,7 @@ bool LaTeXFont::providesSC(bool ot1, bool complete, bool nomath) bool LaTeXFont::hasMonolithicExpertSet(bool ot1, bool complete, bool nomath) { - docstring const usedfont = getUsedFont(ot1, complete, nomath); + docstring const usedfont = getUsedFont(ot1, complete, nomath, false); if (usedfont.empty()) return false; @@ -126,7 +126,7 @@ bool LaTeXFont::hasMonolithicExpertSet(bool ot1, bool complete, bool nomath) bool LaTeXFont::providesScale(bool ot1, bool complete, bool nomath) { - docstring const usedfont = getUsedFont(ot1, complete, nomath); + docstring const usedfont = getUsedFont(ot1, complete, nomath, false); if (usedfont.empty()) return false; @@ -134,12 +134,27 @@ bool LaTeXFont::providesScale(bool ot1, bool complete, bool nomath) return altFont(usedfont).providesScale(ot1, complete, nomath); else if (!available(ot1, nomath)) return false; - return (!scaleoption_.empty()); + return (!scaleoption_.empty() || !scalecmd_.empty()); +} + + +bool LaTeXFont::providesMoreOptions(bool ot1, bool complete, bool nomath) +{ + docstring const usedfont = getUsedFont(ot1, complete, nomath, false); + + if (usedfont.empty()) + return false; + else if (usedfont != name_) + return altFont(usedfont).providesMoreOptions(ot1, complete, nomath); + else if (!available(ot1, nomath)) + return false; + + return (moreopts_); } bool LaTeXFont::provides(std::string const & name, bool ot1, bool complete, bool nomath) { - docstring const usedfont = getUsedFont(ot1, complete, nomath); + docstring const usedfont = getUsedFont(ot1, complete, nomath, false); if (usedfont.empty()) return false; @@ -156,9 +171,11 @@ bool LaTeXFont::provides(std::string const & name, bool ot1, bool complete, bool } -docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath) +docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath, bool osf) { - if (nomath && !nomathfont_.empty() && available(ot1, true)) + if (osf && osfFontOnly()) + return osffont_; + else if (nomath && !nomathfont_.empty() && available(ot1, true)) return nomathfont_; else if (ot1 && !ot1font_.empty()) return (ot1font_ == "none") ? docstring() : ot1font_; @@ -166,19 +183,19 @@ docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath) && altFont(completefont_).available(ot1, nomath)) return completefont_; else if (switchdefault_) { - if (requires_.empty() - || (!requires_.empty() - && LaTeXFeatures::isAvailable(to_ascii(requires_)))) + if (required_.empty() + || (!required_.empty() + && LaTeXFeatures::isAvailable(to_ascii(required_)))) return name_; } - else if (!requires_.empty() - && LaTeXFeatures::isAvailable(to_ascii(requires_))) + else if (!required_.empty() + && LaTeXFeatures::isAvailable(to_ascii(required_))) return name_; else if (!package_.empty() && LaTeXFeatures::isAvailable(to_ascii(package_))) return name_; else if (!preamble_.empty() && package_.empty() - && requires_.empty() && !switchdefault_ + && required_.empty() && !switchdefault_ && altfonts_.empty()) { return name_; } @@ -186,7 +203,7 @@ docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath) for (size_t i = 0; i < altfonts_.size(); ++i) { LaTeXFont altf = altFont(altfonts_[i]); if (altf.available(ot1, nomath)) - return altf.getUsedFont(ot1, complete, nomath); + return altf.getUsedFont(ot1, complete, nomath, osf); } } @@ -196,7 +213,7 @@ docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath) docstring const LaTeXFont::getUsedPackage(bool ot1, bool complete, bool nomath) { - docstring const usedfont = getUsedFont(ot1, complete, nomath); + docstring const usedfont = getUsedFont(ot1, complete, nomath, false); if (usedfont.empty()) return docstring(); return theLaTeXFonts().getLaTeXFont(usedfont).package(); @@ -209,7 +226,7 @@ string const LaTeXFont::getAvailablePackage(bool dryrun) return string(); string const package = to_ascii(package_); - if (!requires_.empty() && LaTeXFeatures::isAvailable(to_ascii(requires_))) + if (!required_.empty() && LaTeXFeatures::isAvailable(to_ascii(required_))) return package; else if (LaTeXFeatures::isAvailable(package)) return package; @@ -217,7 +234,7 @@ string const LaTeXFont::getAvailablePackage(bool dryrun) else if (dryrun) return package; - docstring const req = requires_.empty() ? package_ : requires_; + docstring const req = required_.empty() ? package_ : required_; frontend::Alert::warning(_("Font not available"), bformat(_("The LaTeX package `%1$s' needed for the font `%2$s'\n" "is not available on your system. LyX will fall back to the default font."), @@ -228,15 +245,16 @@ string const LaTeXFont::getAvailablePackage(bool dryrun) string const LaTeXFont::getPackageOptions(bool ot1, bool complete, bool sc, bool osf, - int scale, bool nomath) + int scale, string const & extraopts, bool nomath) { ostringstream os; bool const needosfopt = (osf != osfdefault_); bool const has_osf = providesOSF(ot1, complete, nomath); bool const has_sc = providesSC(ot1, complete, nomath); + bool const moreopts = providesMoreOptions(ot1, complete, nomath); - if (!packageoption_.empty()) - os << to_ascii(packageoption_); + if (!packageoptions_.empty()) + os << to_ascii(packageoptions_); if (sc && needosfopt && has_osf && has_sc) { if (!os.str().empty()) @@ -263,20 +281,28 @@ string const LaTeXFont::getPackageOptions(bool ot1, bool complete, bool sc, bool os << subst(to_ascii(scaleoption_), "$$val", convert(float(scale) / 100)); } + + if (moreopts && !extraopts.empty()) { + if (!os.str().empty()) + os << ','; + os << extraopts; + } return os.str(); } string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool sc, - bool osf, bool nomath, int const & scale) + bool osf, bool nomath, string const & extraopts, + int const & scale) { ostringstream os; - docstring const usedfont = getUsedFont(ot1, complete, nomath); + docstring const usedfont = getUsedFont(ot1, complete, nomath, osf); if (usedfont.empty()) return string(); else if (usedfont != name_) - return altFont(usedfont).getLaTeXCode(dryrun, ot1, complete, sc, osf, nomath, scale); + return altFont(usedfont).getLaTeXCode(dryrun, ot1, complete, sc, + osf, nomath, extraopts, scale); if (switchdefault_) { if (family_.empty()) { @@ -290,26 +316,46 @@ string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool frontend::Alert::warning(_("Font not available"), bformat(_("The LaTeX package `%1$s' needed for the font `%2$s'\n" "is not available on your system. LyX will fall back to the default font."), - requires_, guiname_), true); + required_, guiname_), true); } else { string const package = getAvailablePackage(dryrun); - string const packageopts = getPackageOptions(ot1, complete, sc, osf, scale, nomath); + string const packageopts = getPackageOptions(ot1, complete, sc, osf, scale, extraopts, nomath); if (packageopts.empty() && !package.empty()) os << "\\usepackage{" << package << "}\n"; else if (!packageopts.empty() && !package.empty()) os << "\\usepackage[" << packageopts << "]{" << package << "}\n"; } if (osf && providesOSF(ot1, complete, nomath) && !osffont_.empty()) - os << altFont(osffont_).getLaTeXCode(dryrun, ot1, complete, sc, osf, nomath, scale); + os << altFont(osffont_).getLaTeXCode(dryrun, ot1, complete, sc, osf, + nomath, extraopts, scale); + if (scale != 100 && !scalecmd_.empty() + && providesScale(ot1, complete, nomath)) { + if (contains(scalecmd_, '@')) + os << "\\makeatletter\n"; + os << subst(to_ascii(scalecmd_), "$$val", + convert(float(scale) / 100)) << '\n'; + if (contains(scalecmd_, '@')) + os << "\\makeatother\n"; + } if (!preamble_.empty()) - os << preamble_; + os << to_utf8(preamble_); return os.str(); } +bool LaTeXFont::hasFontenc(string const & name) const +{ + for (auto const & fe : fontenc_) { + if (fe == name) + return true; + } + return false; +} + + bool LaTeXFont::readFont(Lexer & lex) { enum LaTeXFontTags { @@ -317,18 +363,22 @@ bool LaTeXFont::readFont(Lexer & lex) LF_COMPLETE_FONT, LF_END, LF_FAMILY, + LF_FONTENC, LF_GUINAME, LF_NOMATHFONT, LF_OSFDEFAULT, LF_OSFFONT, + LF_OSFFONTONLY, LF_OSFOPTION, LF_OSFSCOPTION, LF_OT1_FONT, + LF_MOREOPTS, LF_PACKAGE, - LF_PACKAGEOPTION, + LF_PACKAGEOPTIONS, LF_PREAMBLE, LF_PROVIDES, LF_REQUIRES, + LF_SCALECMD, LF_SCALEOPTION, LF_SCOPTION, LF_SWITCHDEFAULT @@ -340,18 +390,22 @@ bool LaTeXFont::readFont(Lexer & lex) { "completefont", LF_COMPLETE_FONT }, { "endfont", LF_END }, { "family", LF_FAMILY }, + { "fontencoding", LF_FONTENC }, { "guiname", LF_GUINAME }, + { "moreoptions", LF_MOREOPTS }, { "nomathfont", LF_NOMATHFONT }, { "osfdefault", LF_OSFDEFAULT }, { "osffont", LF_OSFFONT }, + { "osffontonly", LF_OSFFONTONLY }, { "osfoption", LF_OSFOPTION }, { "osfscoption", LF_OSFSCOPTION }, { "ot1font", LF_OT1_FONT }, { "package", LF_PACKAGE }, - { "packageoption", LF_PACKAGEOPTION }, + { "packageoptions", LF_PACKAGEOPTIONS }, { "preamble", LF_PREAMBLE }, { "provides", LF_PROVIDES }, { "requires", LF_REQUIRES }, + { "scalecommand", LF_SCALECMD }, { "scaleoption", LF_SCALEOPTION }, { "scoption", LF_SCOPTION }, { "switchdefault", LF_SWITCHDEFAULT } @@ -373,7 +427,7 @@ bool LaTeXFont::readFont(Lexer & lex) error = true; continue; - default: + default: break; } switch (static_cast(le)) { @@ -395,6 +449,12 @@ bool LaTeXFont::readFont(Lexer & lex) case LF_GUINAME: lex >> guiname_; break; + case LF_FONTENC: { + lex.eatLine(); + string fe = lex.getString(); + fontenc_ = getVectorFromString(fe); + break; + } case LF_NOMATHFONT: lex >> nomathfont_; break; @@ -407,6 +467,9 @@ bool LaTeXFont::readFont(Lexer & lex) case LF_OSFDEFAULT: lex >> osfdefault_; break; + case LF_OSFFONTONLY: + lex >> osffontonly_; + break; case LF_OSFSCOPTION: lex >> osfscoption_; break; @@ -416,11 +479,11 @@ bool LaTeXFont::readFont(Lexer & lex) case LF_PACKAGE: lex >> package_; break; - case LF_PACKAGEOPTION: - lex >> packageoption_; + case LF_PACKAGEOPTIONS: + lex >> packageoptions_; break; case LF_PREAMBLE: - preamble_ = lex.getLongString("EndPreamble"); + preamble_ = lex.getLongString(from_ascii("EndPreamble")); break; case LF_PROVIDES: { lex.eatLine(); @@ -429,7 +492,10 @@ bool LaTeXFont::readFont(Lexer & lex) break; } case LF_REQUIRES: - lex >> requires_; + lex >> required_; + break; + case LF_SCALECMD: + lex >> scalecmd_; break; case LF_SCALEOPTION: lex >> scaleoption_; @@ -437,6 +503,9 @@ bool LaTeXFont::readFont(Lexer & lex) case LF_SCOPTION: lex >> scoption_; break; + case LF_MOREOPTS: + lex >> moreopts_; + break; case LF_SWITCHDEFAULT: lex >> switchdefault_; break; @@ -455,6 +524,8 @@ bool LaTeXFont::read(Lexer & lex) { switchdefault_ = 0; osfdefault_ = 0; + moreopts_ = 0; + osffontonly_ = 0; if (!lex.next()) { lex.printError("No name given for LaTeX font: `$$Token'."); @@ -468,6 +539,9 @@ bool LaTeXFont::read(Lexer & lex) return false; } + if (fontenc_.empty()) + fontenc_.push_back("T1"); + return true; }