[LyX/master] LaTeXFonts: Add ScaleCommand

Juergen Spitzmueller spitz at lyx.org
Thu Jul 9 09:22:38 UTC 2020


commit 780d9a5f4cc553797ec95e49300cf06325ff1341
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Thu Jul 9 11:41:21 2020 +0200

    LaTeXFonts: Add ScaleCommand
    
    This is needed to add support for scaling to fonts that are switched
    via command
---
 lib/latexfonts     |    4 +++-
 src/LaTeXFonts.cpp |   16 +++++++++++++++-
 src/LaTeXFonts.h   |    4 ++++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/lib/latexfonts b/lib/latexfonts
index eaf9e4c..e3b134f 100644
--- a/lib/latexfonts
+++ b/lib/latexfonts
@@ -23,6 +23,7 @@
 #	ScOption           <option for true smallcaps support>
 #	OsfScOption        <option for combined osf and true smallcaps support>
 #	ScaleOption        <option for font scaling>
+#	ScaleCommand       <command sequence to set scale value of the font>
 #       MoreOptions        <0|1>
 #	Provides           <features provided by the font packages (comma-separated)>
 #	Preamble
@@ -75,7 +76,8 @@
 # * Set OsfDefault to true for fonts which have Old Style Figures by
 #   default and provide an option for lining figures. Pass this option
 #   to OsfOption.
-# * ScaleOption supports the placeholder $$val for the scale value.
+# * ScaleOption and ScaleCommand support the placeholder $$val for the
+#   scale value.
 # * If MoreOptions is true, then the user can insert additional options to
 #   the font package via the Document Settings.
 # * The Preamble code is output immediately after the respective font
diff --git a/src/LaTeXFonts.cpp b/src/LaTeXFonts.cpp
index e58b55f..00e19fa 100644
--- a/src/LaTeXFonts.cpp
+++ b/src/LaTeXFonts.cpp
@@ -134,7 +134,7 @@ 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());
 }
 
 
@@ -329,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_);
@@ -369,6 +378,7 @@ bool LaTeXFont::readFont(Lexer & lex)
 		LF_PREAMBLE,
 		LF_PROVIDES,
 		LF_REQUIRES,
+		LF_SCALECMD,
 		LF_SCALEOPTION,
 		LF_SCOPTION,
 		LF_SWITCHDEFAULT
@@ -395,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 }
@@ -483,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;
diff --git a/src/LaTeXFonts.h b/src/LaTeXFonts.h
index a6d875d..116ef08 100644
--- a/src/LaTeXFonts.h
+++ b/src/LaTeXFonts.h
@@ -57,6 +57,8 @@ public:
 	docstring const & osfscoption() { return osfscoption_; }
 	/// A package option for font scaling
 	docstring const & scaleoption() { return scaleoption_; }
+	/// A macro for font scaling
+	docstring const & scalecmd() { return scalecmd_; }
 	/// Does this provide additional options?
 	bool providesMoreOptions(bool ot1, bool complete, bool nomath);
 	/// Alternative requirement to test for
@@ -141,6 +143,8 @@ private:
 	///
 	docstring scaleoption_;
 	///
+	docstring scalecmd_;
+	///
 	std::vector<std::string> provides_;
 	///
 	docstring required_;


More information about the lyx-cvs mailing list