]> git.lyx.org Git - features.git/commitdiff
tex2lyx: support fontspec scale option
authorUwe Stöhr <uwestoehr@lyx.org>
Mon, 25 Jun 2012 22:46:02 +0000 (00:46 +0200)
committerUwe Stöhr <uwestoehr@lyx.org>
Mon, 25 Jun 2012 22:46:02 +0000 (00:46 +0200)
Preamble.cpp:
 - support the font scaling
 - improve coding style

text.cpp: - improve logic/coding style

XeTeX-polyglossia.tex:
 - add scaling
 - change document so that it is compilable using the Libertine font

src/tex2lyx/Preamble.cpp
src/tex2lyx/test/XeTeX-polyglossia.tex
src/tex2lyx/text.cpp

index b40bf8f424dc71d80f9a7b2d3929982b1e28a0a7..e4dc4883a6e6d015d94e4341a870787ec90ea960 100644 (file)
@@ -1158,12 +1158,13 @@ void Preamble::parse(Parser & p, string const & forceclass,
                                // check if the option contains a variant, if yes, extract it
                                string::size_type pos_var = langopts.find("variant");
                                string::size_type i = langopts.find(',', pos_var);
+                               string::size_type k = langopts.find('=', pos_var);
                                if (pos_var != string::npos){
                                        string variant;
                                        if (i == string::npos)
-                                               variant = langopts.substr(pos_var + 8, langopts.length() - pos_var - 9);
+                                               variant = langopts.substr(k + 1, langopts.length() - k - 2);
                                        else
-                                               variant = langopts.substr(pos_var + 8, i - pos_var - 8);
+                                               variant = langopts.substr(k + 1, i - k - 1);
                                        h_language = variant;
                                }
                                p.verbatim_item();
@@ -1186,16 +1187,30 @@ void Preamble::parse(Parser & p, string const & forceclass,
                        h_font_roman = p.getArg('{', '}');
                }
 
-               else if (t.cs() == "setsansfont") {
-                       // we don't care about the option
-                       p.hasOpt() ? p.getOpt() : string();
-                       h_font_sans = p.getArg('{', '}');
-               }
-
-               else if (t.cs() == "setmonofont") {
-                       // we don't care about the option
-                       p.hasOpt() ? p.getOpt() : string();
-                       h_font_typewriter = p.getArg('{', '}');
+               else if (t.cs() == "setsansfont" || t.cs() == "setmonofont") {
+                       // LyX currently only supports the scale option
+                       string scale;
+                       if (p.hasOpt()) {
+                               string fontopts = p.getArg('[', ']');
+                               // check if the option contains a scaling, if yes, extract it
+                               string::size_type pos = fontopts.find("Scale");
+                               if (pos != string::npos) {
+                                       string::size_type i = fontopts.find(',');
+                                       if (i == string::npos)
+                                               scale = scale_as_percentage(fontopts.substr(pos + 1));
+                                       else
+                                               scale = scale_as_percentage(fontopts.substr(pos, i - pos));
+                               }
+                       }
+                       if (t.cs() == "setsansfont") {
+                               if (!scale.empty())
+                                       h_font_sf_scale = scale;
+                               h_font_sans = p.getArg('{', '}');
+                       } else {
+                               if (!scale.empty())
+                                       h_font_tt_scale = scale;
+                               h_font_typewriter = p.getArg('{', '}');
+                       }
                }
 
                else if (t.cs() == "date") {
index fb783c6651105d56137392d091e19554464f1e14..95c4c82b6d8a9e244b6bf14bb35fb191d75c9b07 100644 (file)
@@ -1,8 +1,8 @@
 \documentclass{article}
 \usepackage{fontspec}
-\setmainfont{Aharoni}
-\setsansfont[Mapping=tex-text]{AngsanaUPC}
-\setmonofont{Arial Black}
+\setmainfont[Mapping=tex-text]{Linux Libertine O}
+\setsansfont[Mapping=tex-text,Scale=0.75]{Linux Biolinum O}
+\setmonofont{Linux Biolinum O}
 \usepackage{xunicode}
 \usepackage{polyglossia}
 \setdefaultlanguage[variant=british, ordinalmonthday = false]{english}
@@ -14,7 +14,7 @@
 \part{df}
 
 1 English \textgreek[variant=ancient]{ancient Greek} English
-\textgreek[numerals=arabic, variant=ancient]{ancient Greek with Arabic numerals} English
+\textgreek[numerals=arabic, variant=ancient]{ancient G\textsf{reek} with Arabic numerals} English
 
 \begin{albanian}%
 
 2 Albanian \textgreek{Greek} Albanian \textsc{smallcaps}
 
 \end{albanian}%
-\begin{syriac}%
+\begin{hebrew}%
 
 \part{df}
 
-3 Syriac
+3 Hebrew
 
-\end{syriac}%
+\end{hebrew}%
 
 %empty language paragraph
 \begin{albanian}%
index beb37bd914fc2d9c071213c923961b0a527826c5..6d32c8b742be4bf3d21222f11fa9145e0c53e305 100644 (file)
@@ -3585,17 +3585,14 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                // check if the option contains a variant, if yes, extract it
                                string::size_type pos_var = langopts.find("variant");
                                string::size_type i = langopts.find(',');
-                               if (pos_var != string::npos){
+                               string::size_type k = langopts.find('=', pos_var);
+                               if (pos_var != string::npos && i == string::npos) {
                                        string variant;
-                                       if (i == string::npos) {
-                                               variant = langopts.substr(pos_var + 8, langopts.length() - pos_var - 9);
-                                               lang = polyglossia2lyx(variant);
-                                               parse_text_attributes(p, os, FLAG_ITEM, outer,
-                                                                         context, "\\lang",
-                                                                         context.font.language, lang);
-                                       }
-                                       else
-                                               handle_ert(os, t.asInput() + langopts, context);
+                                       variant = langopts.substr(k + 1, langopts.length() - k - 2);
+                                       lang = polyglossia2lyx(variant);
+                                       parse_text_attributes(p, os, FLAG_ITEM, outer,
+                                                                 context, "\\lang",
+                                                                 context.font.language, lang);
                                } else
                                        handle_ert(os, t.asInput() + langopts, context);
                        } else {