]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFonts.cpp
Accelerators
[lyx.git] / src / LaTeXFonts.cpp
index 12c0856c5db4c7bd1e16ef4b388bb070715d239b..00e19fa57dce537979b854e4652a52b6f7c46f48 100644 (file)
@@ -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,13 +134,13 @@ 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);
+       docstring const usedfont = getUsedFont(ot1, complete, nomath, false);
 
        if (usedfont.empty())
                return false;
@@ -154,7 +154,7 @@ bool LaTeXFont::providesMoreOptions(bool ot1, bool complete, bool nomath)
 
 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;
@@ -171,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_;
@@ -201,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);
                }
        }
 
@@ -211,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();
@@ -295,7 +297,7 @@ string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool
 {
        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_)
@@ -327,6 +329,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_);
@@ -357,6 +368,7 @@ bool LaTeXFont::readFont(Lexer & lex)
                LF_NOMATHFONT,
                LF_OSFDEFAULT,
                LF_OSFFONT,
+               LF_OSFFONTONLY,
                LF_OSFOPTION,
                LF_OSFSCOPTION,
                LF_OT1_FONT,
@@ -366,6 +378,7 @@ bool LaTeXFont::readFont(Lexer & lex)
                LF_PREAMBLE,
                LF_PROVIDES,
                LF_REQUIRES,
+               LF_SCALECMD,
                LF_SCALEOPTION,
                LF_SCOPTION,
                LF_SWITCHDEFAULT
@@ -383,6 +396,7 @@ 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 },
@@ -391,6 +405,7 @@ bool LaTeXFont::readFont(Lexer & lex)
                { "preamble",             LF_PREAMBLE },
                { "provides",             LF_PROVIDES },
                { "requires",             LF_REQUIRES },
+               { "scalecommand",         LF_SCALECMD },
                { "scaleoption",          LF_SCALEOPTION },
                { "scoption",             LF_SCOPTION },
                { "switchdefault",        LF_SWITCHDEFAULT }
@@ -452,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;
@@ -476,6 +494,9 @@ bool LaTeXFont::readFont(Lexer & lex)
                case LF_REQUIRES:
                        lex >> required_;
                        break;
+               case LF_SCALECMD:
+                       lex >> scalecmd_;
+                       break;
                case LF_SCALEOPTION:
                        lex >> scaleoption_;
                        break;
@@ -504,6 +525,7 @@ 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'.");