]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFonts.cpp
Remove unneeded method.
[lyx.git] / src / LaTeXFonts.cpp
index ce772bcc50e5a022fe71723d5975cdd7603dde72..b61c4c7fc509fbadbaf94f235f9fda56bf9104f6 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "support/convert.h"
 #include "support/debug.h"
+#include "support/docstream.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
@@ -88,7 +89,7 @@ bool LaTeXFont::providesOSF(bool ot1, bool complete, bool nomath)
                return altFont(usedfont).providesOSF(ot1, complete, nomath);
        else if (!osffont_.empty())
                return altFont(osffont_).available(ot1, nomath);
-       else if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_)))
+       else if (!available(ot1, nomath))
                return false;
 
        return (!osfoption_.empty() || !osfscoption_.empty());
@@ -103,13 +104,26 @@ bool LaTeXFont::providesSC(bool ot1, bool complete, bool nomath)
                return false;
        else if (usedfont != name_)
                return altFont(usedfont).providesSC(ot1, complete, nomath);
-       else if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_)))
+       else if (!available(ot1, nomath))
                return false;
 
        return (!scoption_.empty() || !osfscoption_.empty());
 }
 
 
+bool LaTeXFont::hasMonolithicExpertSet(bool ot1, bool complete, bool nomath)
+{
+       docstring const usedfont = getUsedFont(ot1, complete, nomath);
+
+       if (usedfont.empty())
+               return false;
+       else if (usedfont != name_)
+               return altFont(usedfont).hasMonolithicExpertSet(ot1, complete, nomath);
+       return (!osfoption_.empty() && !scoption_.empty() && osfoption_ == scoption_)
+               || (osfoption_.empty() && scoption_.empty() && !osfscoption_.empty());
+}
+
+
 bool LaTeXFont::providesScale(bool ot1, bool complete, bool nomath)
 {
        docstring const usedfont = getUsedFont(ot1, complete, nomath);
@@ -118,12 +132,26 @@ bool LaTeXFont::providesScale(bool ot1, bool complete, bool nomath)
                return false;
        else if (usedfont != name_)
                return altFont(usedfont).providesScale(ot1, complete, nomath);
-       else if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_)))
+       else if (!available(ot1, nomath))
                return false;
-
        return (!scaleoption_.empty());
 }
 
+
+bool LaTeXFont::providesMoreOptions(bool ot1, bool complete, bool nomath)
+{
+       docstring const usedfont = getUsedFont(ot1, complete, nomath);
+
+       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);
@@ -164,6 +192,11 @@ docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath)
        else if (!package_.empty()
                && LaTeXFeatures::isAvailable(to_ascii(package_)))
                        return name_;
+       else if (!preamble_.empty() && package_.empty()
+                && requires_.empty() && !switchdefault_
+                && altfonts_.empty()) {
+                       return name_;
+       }
        else if (!altfonts_.empty()) {
                for (size_t i = 0; i < altfonts_.size(); ++i) {
                        LaTeXFont altf = altFont(altfonts_[i]);
@@ -176,6 +209,15 @@ 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);
+       if (usedfont.empty())
+               return docstring();
+       return theLaTeXFonts().getLaTeXFont(usedfont).package();
+}
+
+
 string const LaTeXFont::getAvailablePackage(bool dryrun)
 {
        if (package_.empty())
@@ -201,15 +243,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())
@@ -236,12 +279,19 @@ string const LaTeXFont::getPackageOptions(bool ot1, bool complete, bool sc, bool
                os << subst(to_ascii(scaleoption_), "$$val",
                            convert<std::string>(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;
 
@@ -249,7 +299,8 @@ string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool
        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()) {
@@ -267,19 +318,33 @@ string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool
        } 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 (!preamble_.empty())
+               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 {
@@ -287,6 +352,7 @@ bool LaTeXFont::readFont(Lexer & lex)
                LF_COMPLETE_FONT,
                LF_END,
                LF_FAMILY,
+               LF_FONTENC,
                LF_GUINAME,
                LF_NOMATHFONT,
                LF_OSFDEFAULT,
@@ -294,8 +360,10 @@ bool LaTeXFont::readFont(Lexer & lex)
                LF_OSFOPTION,
                LF_OSFSCOPTION,
                LF_OT1_FONT,
+               LF_MOREOPTS,
                LF_PACKAGE,
-               LF_PACKAGEOPTION,
+               LF_PACKAGEOPTIONS,
+               LF_PREAMBLE,
                LF_PROVIDES,
                LF_REQUIRES,
                LF_SCALEOPTION,
@@ -309,7 +377,9 @@ 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 },
@@ -317,7 +387,8 @@ bool LaTeXFont::readFont(Lexer & lex)
                { "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 },
                { "scaleoption",          LF_SCALEOPTION },
@@ -341,7 +412,7 @@ bool LaTeXFont::readFont(Lexer & lex)
                        error = true;
                        continue;
 
-               default: 
+               default:
                        break;
                }
                switch (static_cast<LaTeXFontTags>(le)) {
@@ -363,6 +434,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;
@@ -384,8 +461,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(from_ascii("EndPreamble"));
                        break;
                case LF_PROVIDES: {
                        lex.eatLine();
@@ -402,6 +482,9 @@ bool LaTeXFont::readFont(Lexer & lex)
                case LF_SCOPTION:
                        lex >> scoption_;
                        break;
+               case LF_MOREOPTS:
+                       lex >> moreopts_;
+                       break;
                case LF_SWITCHDEFAULT:
                        lex >> switchdefault_;
                        break;
@@ -420,6 +503,7 @@ bool LaTeXFont::read(Lexer & lex)
 {
        switchdefault_ = 0;
        osfdefault_ = 0;
+       moreopts_ = 0;
 
        if (!lex.next()) {
                lex.printError("No name given for LaTeX font: `$$Token'.");
@@ -433,6 +517,9 @@ bool LaTeXFont::read(Lexer & lex)
                return false;
        }
 
+       if (fontenc_.empty())
+               fontenc_.push_back("T1");
+
        return true;
 }