Am Montag, 15. Juli 2019, 07:58:06 CEST schrieb Jürgen Spitzmüller: > Here, the code is kept in preamble (with no font added to the GUI), > which is expected, since the conversion of this font is done before the > file format that adds the extra options. And in this case, the preamble > is maintained. So another conversion would be needed.
Here too
> Furthermore, however, extra option handling is not yet implemented in
> the conversion routine, which then would need to detect the current
> conversion format. This is not too difficult to implement, but a
> problem I don't know how to handle is the default option that is used
> for font name detection (fm.getfontname(pkg, options)). At conversion
> time, we do not know if there is a default option, and which. So we
> cannot differentiate the default option from other options easily.
>
The attached seems to work.
Kornel
diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py
index dd7e31c..2a238f3 100644
--- a/lib/lyx2lyx/lyx_2_4.py
+++ b/lib/lyx2lyx/lyx_2_4.py
@@ -172,11 +172,11 @@ def createFontMapping(fontlist):
'NotoSansThin,thin', 'NotoSansLight,light',
'NotoSansExtralight,extralight'],
"sans", "sf", "noto-sans", "scaled")
fm.expandFontMapping(['NotoMonoRegular,regular'], "typewriter", "tt", "noto-mono", "scaled")
elif font == 'Cantarell':
- fm.expandFontMapping(['cantarell,defaultsans'],
+ fm.expandFontMapping(['cantarell,default'],
"sans", "sf", "cantarell", "scaled", "oldstyle")
return fm
def convert_fonts(document, fm, osfoption = "osf"):
" Handle font definition (LaTeX preamble -> native) "
@@ -212,15 +212,41 @@ def convert_fonts(document, fm, osfoption = "osf"):
continue
if not pkg in fm.pkginmap:
continue
# determine fontname
- fn = fm.getfontname(pkg, options)
+ extraopts = []
+ while True:
+ options2 = []
+ # the copy is needed, because fm.getfontname sorts options
+ for value in options:
+ options2.append(value)
+ fn = fm.getfontname(pkg, options2)
+ if fn == None:
+ if 0 < len(options):
+ # print("removing %s" % (options[0]))
+ extraopts.append(options[0])
+ del options[0]
+ continue
+ else:
+ break
+ else:
+ break
if fn == None:
continue
del document.preamble[i]
fontinfo = fm.font2pkgmap[fn]
+ if 0 < len(extraopts):
+ font_tag = "\\font_" + fontinfo.fonttype + "_opts"
+ font_opts = font_tag + " \"" + ",".join(extraopts) + '"'
+ #print("entry = %s" % (font_opts))
+ fontinfo.options = extraopts
+ opts = find_token(document.header, font_tag)
+ if opts != -1:
+ document.header[opts] = font_opts
+ else:
+ document.header.insert(-1,font_opts)
if fontinfo.scaletype == None:
fontscale = None
else:
fontscale = "\\font_" + fontinfo.scaletype + "_scale"
fontinfo.scaleval = oscale
signature.asc
Description: This is a digitally signed message part.
