]> git.lyx.org Git - features.git/blobdiff - src/LaTeXFonts.cpp
InsetIndex: when building the IndexNode tree, ignore IndexEntry when empty
[features.git] / src / LaTeXFonts.cpp
index 422c8c7ca36a42a82c26d071afa0d81d264a0040..c9d030e8c343af500af6d0ac204da4c988bcbb43 100644 (file)
@@ -35,30 +35,30 @@ namespace lyx {
 LaTeXFonts latexfonts;
 
 
-LaTeXFont LaTeXFont::altFont(docstring const & name)
+LaTeXFont LaTeXFont::altFont(docstring const & name) const
 {
        return theLaTeXFonts().getAltFont(name);
 }
 
 
-bool LaTeXFont::available(bool ot1, bool nomath)
+bool LaTeXFont::available(bool ot1, bool nomath) const
 {
        if (nomath && !nomathfont_.empty())
                return altFont(nomathfont_).available(ot1, 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()) {
-               for (size_t i = 0; i < altfonts_.size(); ++i) {
-                       if (altFont(altfonts_[i]).available(ot1, nomath))
+               for (auto const & name : altfonts_) {
+                       if (altFont(name).available(ot1, nomath))
                                return true;
                }
        }
@@ -66,9 +66,9 @@ bool LaTeXFont::available(bool ot1, bool nomath)
 }
 
 
-bool LaTeXFont::providesNoMath(bool ot1, bool complete)
+bool LaTeXFont::providesNoMath(bool ot1, bool complete) const
 {
-       docstring const usedfont = getUsedFont(ot1, complete, false);
+       docstring const usedfont = getUsedFont(ot1, complete, false, false);
 
        if (usedfont.empty())
                return false;
@@ -79,9 +79,9 @@ bool LaTeXFont::providesNoMath(bool ot1, bool complete)
 }
 
 
-bool LaTeXFont::providesOSF(bool ot1, bool complete, bool nomath)
+bool LaTeXFont::providesOSF(bool ot1, bool complete, bool nomath) const
 {
-       docstring const usedfont = getUsedFont(ot1, complete, nomath);
+       docstring const usedfont = getUsedFont(ot1, complete, nomath, false);
 
        if (usedfont.empty())
                return false;
@@ -96,9 +96,9 @@ bool LaTeXFont::providesOSF(bool ot1, bool complete, bool nomath)
 }
 
 
-bool LaTeXFont::providesSC(bool ot1, bool complete, bool nomath)
+bool LaTeXFont::providesSC(bool ot1, bool complete, bool nomath) const
 {
-       docstring const usedfont = getUsedFont(ot1, complete, nomath);
+       docstring const usedfont = getUsedFont(ot1, complete, nomath, false);
 
        if (usedfont.empty())
                return false;
@@ -111,9 +111,9 @@ bool LaTeXFont::providesSC(bool ot1, bool complete, bool nomath)
 }
 
 
-bool LaTeXFont::hasMonolithicExpertSet(bool ot1, bool complete, bool nomath)
+bool LaTeXFont::hasMonolithicExpertSet(bool ot1, bool complete, bool nomath) const
 {
-       docstring const usedfont = getUsedFont(ot1, complete, nomath);
+       docstring const usedfont = getUsedFont(ot1, complete, nomath, false);
 
        if (usedfont.empty())
                return false;
@@ -124,9 +124,9 @@ bool LaTeXFont::hasMonolithicExpertSet(bool ot1, bool complete, bool nomath)
 }
 
 
-bool LaTeXFont::providesScale(bool ot1, bool complete, bool nomath)
+bool LaTeXFont::providesScale(bool ot1, bool complete, bool nomath) const
 {
-       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::provides(std::string const & name, bool ot1, bool complete, bool nomath)
+
+bool LaTeXFont::providesMoreOptions(bool ot1, bool complete, bool nomath) const
 {
-       docstring const usedfont = getUsedFont(ot1, complete, 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) const
+{
+       docstring const usedfont = getUsedFont(ot1, complete, nomath, false);
 
        if (usedfont.empty())
                return false;
@@ -148,17 +163,19 @@ bool LaTeXFont::provides(std::string const & name, bool ot1, bool complete, bool
        else if (provides_.empty())
                return false;
 
-       for (size_t i = 0; i < provides_.size(); ++i) {
-               if (provides_[i] == name)
+       for (auto const & provide : provides_) {
+               if (provide == name)
                        return true;
        }
        return false;
 }
 
 
-docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath)
+docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath, bool osf) const
 {
-       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,27 +183,27 @@ 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_;
        }
        else if (!altfonts_.empty()) {
-               for (size_t i = 0; i < altfonts_.size(); ++i) {
-                       LaTeXFont altf = altFont(altfonts_[i]);
+               for (auto const & name : altfonts_) {
+                       LaTeXFont altf = altFont(name);
                        if (altf.available(ot1, nomath))
-                               return altf.getUsedFont(ot1, complete, nomath);
+                               return altf.getUsedFont(ot1, complete, nomath, osf);
                }
        }
 
@@ -194,22 +211,22 @@ docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath)
 }
 
 
-docstring const LaTeXFont::getUsedPackage(bool ot1, bool complete, bool nomath)
+docstring const LaTeXFont::getUsedPackage(bool ot1, bool complete, bool nomath) const
 {
-       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();
 }
 
 
-string const LaTeXFont::getAvailablePackage(bool dryrun)
+string const LaTeXFont::getAvailablePackage(bool dryrun) const
 {
        if (package_.empty())
                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, string const extraopts, bool nomath)
+                                         int scale, string const & extraopts, bool nomath) const
 {
        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())
@@ -264,7 +282,7 @@ string const LaTeXFont::getPackageOptions(bool ot1, bool complete, bool sc, bool
                            convert<std::string>(float(scale) / 100));
        }
 
-       if (moreopts_ && !extraopts.empty()) {
+       if (moreopts && !extraopts.empty()) {
                if (!os.str().empty())
                        os << ',';
                os << extraopts;
@@ -274,12 +292,11 @@ string const LaTeXFont::getPackageOptions(bool ot1, bool complete, bool sc, bool
 
 
 string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool sc,
-                                    bool osf, bool nomath, string const extraopts,
-                                    int const & scale)
+                                    bool osf, bool nomath, string const & extraopts, int scale) const
 {
        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_)
@@ -298,7 +315,7 @@ 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);
@@ -311,6 +328,15 @@ string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool
        if (osf && providesOSF(ot1, complete, nomath) && !osffont_.empty())
                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<std::string>(float(scale) / 100)) << '\n';
+               if (contains(scalecmd_, '@'))
+                       os << "\\makeatother\n";
+       }
 
        if (!preamble_.empty())
                os << to_utf8(preamble_);
@@ -341,15 +367,17 @@ bool LaTeXFont::readFont(Lexer & lex)
                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
@@ -367,14 +395,16 @@ bool LaTeXFont::readFont(Lexer & lex)
                { "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 }
@@ -436,6 +466,9 @@ bool LaTeXFont::readFont(Lexer & lex)
                case LF_OSFDEFAULT:
                        lex >> osfdefault_;
                        break;
+               case LF_OSFFONTONLY:
+                       lex >> osffontonly_;
+                       break;
                case LF_OSFSCOPTION:
                        lex >> osfscoption_;
                        break;
@@ -445,8 +478,8 @@ 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(from_ascii("EndPreamble"));
@@ -458,7 +491,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_;
@@ -485,9 +521,10 @@ bool LaTeXFont::readFont(Lexer & lex)
 
 bool LaTeXFont::read(Lexer & lex)
 {
-       switchdefault_ = 0;
-       osfdefault_ = 0;
-       moreopts_ = 0;
+       switchdefault_ = false;
+       osfdefault_ = false;
+       moreopts_ = false;
+       osffontonly_ = false;
 
        if (!lex.next()) {
                lex.printError("No name given for LaTeX font: `$$Token'.");