]> git.lyx.org Git - features.git/commitdiff
lyx2lyx: Support conversion of fonts from preamble with extra opts
authorJuergen Spitzmueller <spitz@lyx.org>
Mon, 15 Jul 2019 08:34:19 +0000 (10:34 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:36 +0000 (15:48 +0200)
lib/lyx2lyx/lyx_2_4.py

index dd7e31ca55721eae098b33766ca29957fb46479c..d5b718e0adbcb2bd5d8537f95909aa6415430cdd 100644 (file)
@@ -184,6 +184,9 @@ def convert_fonts(document, fm, osfoption = "osf"):
     rpkg = re.compile(r'^\\usepackage(\[([^\]]*)\])?\{([^\}]+)\}')
     rscaleopt = re.compile(r'^scaled?=(.*)')
 
+    # Check whether we go beyond font option feature introduction
+    haveFontOpts = document.end_format > 580
+
     i = 0
     while i < len(document.preamble):
         i = find_re(document.preamble, rpkg, i+1)
@@ -214,7 +217,23 @@ def convert_fonts(document, fm, osfoption = "osf"):
         if not pkg in fm.pkginmap:
             continue
         # determine fontname
-        fn = fm.getfontname(pkg, options)
+        fn = None
+        if haveFontOpts:
+            # Try with name-option combination first
+            # (only one default option supported currently)
+            o = 0
+            while o < len(options):
+                opt = options[o]
+                fn = fm.getfontname(pkg, [opt])
+                if fn != None:
+                    del options[o]
+                    break
+                o += 1
+                continue
+            if fn == None:
+                fn = fm.getfontname(pkg, [])
+        else:
+            fn = fm.getfontname(pkg, options)
         if fn == None:
             continue
         del document.preamble[i]
@@ -255,6 +274,20 @@ def convert_fonts(document, fm, osfoption = "osf"):
             words = val.split() # ! splits also values like '"DejaVu Sans"'
             words[0] = '"' + fn + '"'
             document.header[j] = ft + ' ' + ' '.join(words)
+        if haveFontOpts and fontinfo.fonttype != "math":
+            fotag = "\\font_" + fontinfo.fonttype + "_opts"
+            fo = find_token(document.header, fotag)
+            if fo != -1:
+                document.header[fo] = fotag + " \"" + ",".join(options) + "\""
+            else:
+                # Sensible place to insert tag
+                fo = find_token(document.header, "\\font_sf_scale")
+                if fo == -1:
+                    document.warning("Malformed LyX document! Missing \\font_sf_scale")
+                else:
+                    document.header.insert(fo, fotag + " \"" + ",".join(options) + "\"")
+
+
 
 def revert_fonts(document, fm, fontmap, OnlyWithXOpts = False, WithXOpts = False):
     " Revert native font definition to LaTeX "
@@ -2916,7 +2949,7 @@ convert = [
            [579, []],
            [580, []],
            [581, [convert_osf]],
-           [582, [convert_CantarellFont]],
+           [582, [convert_AdobeFonts,convert_latexFonts,convert_notoFonts,convert_CantarellFont]],# old font re-converterted due to extra options
           ]
 
 revert =  [[581, [revert_CantarellFont]],