Support MoreOptions for IBM Plex, Noto, and Adobe Source fonts

This commit is contained in:
Juergen Spitzmueller 2019-07-13 14:55:59 +02:00
parent 0738ff08ba
commit 04c2594c82
2 changed files with 242 additions and 79 deletions

View File

@ -172,6 +172,7 @@ Font IBMPlexSerif
GuiName "IBM Plex Serif"
Family rm
Package plex-serif
MoreOptions 1
EndFont
Font IBMPlexSerifThin
@ -179,6 +180,7 @@ Font IBMPlexSerifThin
Family rm
Package plex-serif
PackageOption thin
MoreOptions 1
EndFont
Font IBMPlexSerifExtraLight
@ -186,6 +188,7 @@ Font IBMPlexSerifExtraLight
Family rm
Package plex-serif
PackageOption extralight
MoreOptions 1
EndFont
Font IBMPlexSerifLight
@ -193,6 +196,7 @@ Font IBMPlexSerifLight
Family rm
Package plex-serif
PackageOption light
MoreOptions 1
EndFont
Font IBMPlexSerifSemibold
@ -200,12 +204,14 @@ Font IBMPlexSerifSemibold
Family rm
Package plex-serif
PackageOption semibold
MoreOptions 1
EndFont
Font ADOBESourceSerifPro
GuiName "Adobe Source Serif Pro"
Family rm
Package sourceserifpro
MoreOptions 1
EndFont
Font garamondx
@ -371,6 +377,7 @@ Font NotoSerifRegular
OsfDefault 0
OsfOption osf
AltFonts NotoSerifRegular1
MoreOptions 1
EndFont
AltFont NotoSerifRegular1
@ -380,6 +387,7 @@ AltFont NotoSerifRegular1
PackageOption regular
OsfDefault 1
OsfOption osf
MoreOptions 1
EndFont
Font NotoSerifMedium
@ -389,6 +397,7 @@ Font NotoSerifMedium
PackageOption medium
OsfDefault 0
OsfOption osf
MoreOptions 1
EndFont
Font NotoSerifThin
@ -398,6 +407,7 @@ Font NotoSerifThin
PackageOption thin
OsfDefault 0
OsfOption osf
MoreOptions 1
EndFont
Font NotoSerifLight
@ -407,6 +417,7 @@ Font NotoSerifLight
PackageOption light
OsfDefault 0
OsfOption osf
MoreOptions 1
EndFont
Font NotoSerifExtralight
@ -416,6 +427,7 @@ Font NotoSerifExtralight
PackageOption extralight
OsfDefault 0
OsfOption osf
MoreOptions 1
EndFont
Font NotoSerif-TLF
@ -430,6 +442,7 @@ AltFont noto
GuiName "Noto Serif"
Family rm
Package noto
MoreOptions 1
EndFont
Font palatino
@ -658,6 +671,7 @@ Font IBMPlexSans
Family sf
Package plex-sans
ScaleOption scale=$$val
MoreOptions 1
EndFont
Font IBMPlexSansCondensed
@ -666,6 +680,7 @@ Font IBMPlexSansCondensed
Package plex-sans
PackageOption condensed
ScaleOption scale=$$val
MoreOptions 1
EndFont
Font IBMPlexSansThin
@ -674,6 +689,7 @@ Font IBMPlexSansThin
Package plex-sans
PackageOption thin
ScaleOption scale=$$val
MoreOptions 1
EndFont
Font IBMPlexSansExtraLight
@ -682,6 +698,7 @@ Font IBMPlexSansExtraLight
Package plex-sans
PackageOption extralight
ScaleOption scale=$$val
MoreOptions 1
EndFont
Font IBMPlexSansLight
@ -690,6 +707,7 @@ Font IBMPlexSansLight
Package plex-sans
PackageOption light
ScaleOption scale=$$val
MoreOptions 1
EndFont
Font IBMPlexSansSemibold
@ -698,6 +716,7 @@ Font IBMPlexSansSemibold
Package plex-sans
PackageOption semibold
ScaleOption scale=$$val
MoreOptions 1
EndFont
Font ADOBESourceSansPro
@ -706,6 +725,7 @@ Font ADOBESourceSansPro
Package sourcesanspro
PackageOption osf
ScaleOption scaled=$$val
MoreOptions 1
EndFont
Font helvet
@ -787,6 +807,7 @@ Font NotoSansRegular
PackageOption regular
OsfDefault 0
OsfOption osf
MoreOptions 1
EndFont
Font NotoSansMedium
@ -797,6 +818,7 @@ Font NotoSansMedium
PackageOption medium
OsfDefault 0
OsfOption osf
MoreOptions 1
EndFont
Font NotoSansThin
@ -807,6 +829,7 @@ Font NotoSansThin
PackageOption thin
OsfDefault 0
OsfOption osf
MoreOptions 1
EndFont
Font NotoSansLight
@ -817,6 +840,7 @@ Font NotoSansLight
PackageOption light
OsfDefault 0
OsfOption osf
MoreOptions 1
EndFont
Font NotoSansExtralight
@ -827,6 +851,7 @@ Font NotoSansExtralight
PackageOption extralight
OsfDefault 0
OsfOption osf
MoreOptions 1
EndFont
Font NotoSans-TLF
@ -919,6 +944,7 @@ Font IBMPlexMono
Family tt
Package plex-mono
ScaleOption scale=$$val
MoreOptions 1
EndFont
Font IBMPlexMonoThin
@ -927,6 +953,7 @@ Font IBMPlexMonoThin
Package plex-mono
ScaleOption scale=$$val
PackageOption thin
MoreOptions 1
EndFont
Font IBMPlexMonoExtraLight
@ -935,6 +962,7 @@ Font IBMPlexMonoExtraLight
Package plex-mono
ScaleOption scale=$$val
PackageOption extralight
MoreOptions 1
EndFont
Font IBMPlexMonoLight
@ -943,6 +971,7 @@ Font IBMPlexMonoLight
Package plex-mono
ScaleOption scale=$$val
PackageOption light
MoreOptions 1
EndFont
Font IBMPlexMonoSemibold
@ -951,6 +980,7 @@ Font IBMPlexMonoSemibold
Package plex-mono
ScaleOption scale=$$val
PackageOption semibold
MoreOptions 1
EndFont
Font ADOBESourceCodePro
@ -958,6 +988,7 @@ Font ADOBESourceCodePro
Family tt
Package sourcecodepro
ScaleOption scaled=$$val
MoreOptions 1
EndFont
Font libertine-mono
@ -996,6 +1027,7 @@ Font NotoMonoRegular
Package noto-mono
OsfOption osf
PackageOption regular
MoreOptions 1
EndFont
Font NotoMono-TLF

View File

@ -234,7 +234,7 @@ def convert_fonts(document, fm):
words[0] = '"' + fn + '"'
document.header[j] = ft + ' ' + ' '.join(words)
def revert_fonts(document, fm, fontmap):
def revert_fonts(document, fm, fontmap, OnlyWithXOpts = False):
" Revert native font definition to LaTeX "
# fonlist := list of fonts created from the same package
# Empty package means that the font-name is the same as the package-name
@ -261,6 +261,24 @@ def revert_fonts(document, fm, fontmap):
val = fontinfo.package
if not val in fontmap:
fontmap[val] = []
x = -1
if OnlyWithXOpts:
if ft == "\\font_math":
return
regexp = re.compile(r'^\s*(\\font_roman_opts)\s+')
if ft == "\\font_sans":
regexp = re.compile(r'^\s*(\\font_sans_opts)\s+')
elif ft == "\\font_typewriter":
regexp = re.compile(r'^\s*(\\font_typewriter_opts)\s+')
x = find_re(document.header, regexp, 0)
if x == -1:
return
# We need to use this regex since split() does not handle quote protection
xopts = re.findall(r'[^"\s]\S*|".+?"', document.header[x])
opts = xopts[1].strip('"').split(",")
fontmap[val].extend(opts)
del document.header[x]
words[0] = '"default"'
document.header[i] = ft + ' ' + ' '.join(words)
if fontinfo.scaleopt != None:
@ -2293,14 +2311,13 @@ def revert_minionpro(document):
return
regexp = re.compile(r'(\\font_roman_opts)')
i = find_re(document.header, regexp, 0)
if i == -1:
x = find_re(document.header, regexp, 0)
if x == -1:
return
# We need to use this regex since split() does not handle quote protection
romanopts = re.findall(r'[^"\s]\S*|".+?"', document.header[i])
romanopts = re.findall(r'[^"\s]\S*|".+?"', document.header[x])
opts = romanopts[1].strip('"')
del document.header[i]
i = find_token(document.header, "\\font_roman", 0)
if i == -1:
@ -2326,6 +2343,7 @@ def revert_minionpro(document):
preamble += opts
preamble += "]{MinionPro}"
add_to_preamble(document, [preamble])
del document.header[x]
def revert_font_opts(document):
@ -2335,8 +2353,7 @@ def revert_font_opts(document):
if i == -1:
document.warning("Malformed LyX document: Missing \\use_non_tex_fonts.")
return
if not str2bool(get_value(document.header, "\\use_non_tex_fonts", i)):
return
NonTeXFonts = str2bool(get_value(document.header, "\\use_non_tex_fonts", i))
i = find_token(document.header, '\\language_package', 0)
if i == -1:
document.warning("Malformed LyX document: Missing \\language_package.")
@ -2351,25 +2368,26 @@ def revert_font_opts(document):
romanopts = re.findall(r'[^"\s]\S*|".+?"', document.header[i])
opts = romanopts[1].strip('"')
del document.header[i]
regexp = re.compile(r'(\\font_roman)')
i = find_re(document.header, regexp, 0)
if i != -1:
# We need to use this regex since split() does not handle quote protection
romanfont = re.findall(r'[^"\s]\S*|".+?"', document.header[i])
font = romanfont[2].strip('"')
romanfont[2] = '"default"'
document.header[i] = " ".join(romanfont)
if font != "default":
if Babel:
preamble = "\\babelfont{rm}["
else:
preamble = "\\setmainfont["
preamble += opts
preamble += ","
preamble += "Mapping=tex-text]{"
preamble += font
preamble += "}"
add_to_preamble(document, [preamble])
if NonTeXFonts:
regexp = re.compile(r'(\\font_roman)')
i = find_re(document.header, regexp, 0)
if i != -1:
# We need to use this regex since split() does not handle quote protection
romanfont = re.findall(r'[^"\s]\S*|".+?"', document.header[i])
font = romanfont[2].strip('"')
romanfont[2] = '"default"'
document.header[i] = " ".join(romanfont)
if font != "default":
if Babel:
preamble = "\\babelfont{rm}["
else:
preamble = "\\setmainfont["
preamble += opts
preamble += ","
preamble += "Mapping=tex-text]{"
preamble += font
preamble += "}"
add_to_preamble(document, [preamble])
# 2. Sans
regexp = re.compile(r'(\\font_sans_opts)')
@ -2380,33 +2398,34 @@ def revert_font_opts(document):
sfopts = re.findall(r'[^"\s]\S*|".+?"', document.header[i])
opts = sfopts[1].strip('"')
del document.header[i]
regexp = re.compile(r'(\\font_sf_scale)')
i = find_re(document.header, regexp, 0)
if i != -1:
scaleval = get_value(document.header, "\\font_sf_scale" , i).split()[1]
regexp = re.compile(r'(\\font_sans)')
i = find_re(document.header, regexp, 0)
if i != -1:
# We need to use this regex since split() does not handle quote protection
sffont = re.findall(r'[^"\s]\S*|".+?"', document.header[i])
font = sffont[2].strip('"')
sffont[2] = '"default"'
document.header[i] = " ".join(sffont)
if font != "default":
if Babel:
preamble = "\\babelfont{sf}["
else:
preamble = "\\setsansfont["
preamble += opts
preamble += ","
if scaleval != 100:
preamble += "Scale=0."
preamble += scaleval
if NonTeXFonts:
regexp = re.compile(r'(\\font_sf_scale)')
i = find_re(document.header, regexp, 0)
if i != -1:
scaleval = get_value(document.header, "\\font_sf_scale" , i).split()[1]
regexp = re.compile(r'(\\font_sans)')
i = find_re(document.header, regexp, 0)
if i != -1:
# We need to use this regex since split() does not handle quote protection
sffont = re.findall(r'[^"\s]\S*|".+?"', document.header[i])
font = sffont[2].strip('"')
sffont[2] = '"default"'
document.header[i] = " ".join(sffont)
if font != "default":
if Babel:
preamble = "\\babelfont{sf}["
else:
preamble = "\\setsansfont["
preamble += opts
preamble += ","
preamble += "Mapping=tex-text]{"
preamble += font
preamble += "}"
add_to_preamble(document, [preamble])
if scaleval != 100:
preamble += "Scale=0."
preamble += scaleval
preamble += ","
preamble += "Mapping=tex-text]{"
preamble += font
preamble += "}"
add_to_preamble(document, [preamble])
# 3. Typewriter
regexp = re.compile(r'(\\font_typewriter_opts)')
@ -2417,33 +2436,145 @@ def revert_font_opts(document):
ttopts = re.findall(r'[^"\s]\S*|".+?"', document.header[i])
opts = ttopts[1].strip('"')
del document.header[i]
regexp = re.compile(r'(\\font_tt_scale)')
i = find_re(document.header, regexp, 0)
if i != -1:
scaleval = get_value(document.header, "\\font_tt_scale" , i).split()[1]
regexp = re.compile(r'(\\font_typewriter)')
i = find_re(document.header, regexp, 0)
if i != -1:
# We need to use this regex since split() does not handle quote protection
ttfont = re.findall(r'[^"\s]\S*|".+?"', document.header[i])
font = ttfont[2].strip('"')
ttfont[2] = '"default"'
document.header[i] = " ".join(ttfont)
if font != "default":
if Babel:
preamble = "\\babelfont{tt}["
else:
preamble = "\\setmonofont["
preamble += opts
preamble += ","
if scaleval != 100:
preamble += "Scale=0."
preamble += scaleval
if NonTeXFonts:
regexp = re.compile(r'(\\font_tt_scale)')
i = find_re(document.header, regexp, 0)
if i != -1:
scaleval = get_value(document.header, "\\font_tt_scale" , i).split()[1]
regexp = re.compile(r'(\\font_typewriter)')
i = find_re(document.header, regexp, 0)
if i != -1:
# We need to use this regex since split() does not handle quote protection
ttfont = re.findall(r'[^"\s]\S*|".+?"', document.header[i])
font = ttfont[2].strip('"')
ttfont[2] = '"default"'
document.header[i] = " ".join(ttfont)
if font != "default":
if Babel:
preamble = "\\babelfont{tt}["
else:
preamble = "\\setmonofont["
preamble += opts
preamble += ","
preamble += "Mapping=tex-text]{"
preamble += font
preamble += "}"
add_to_preamble(document, [preamble])
if scaleval != 100:
preamble += "Scale=0."
preamble += scaleval
preamble += ","
preamble += "Mapping=tex-text]{"
preamble += font
preamble += "}"
add_to_preamble(document, [preamble])
def revert_plainNotoFonts_xopts(document):
" Revert native (straight) Noto font definition (with extra options) to LaTeX "
i = find_token(document.header, '\\use_non_tex_fonts', 0)
if i == -1:
document.warning("Malformed LyX document: Missing \\use_non_tex_fonts.")
return
if str2bool(get_value(document.header, "\\use_non_tex_fonts", i)):
return
regexp = re.compile(r'(\\font_roman_opts)')
x = find_re(document.header, regexp, 0)
if x == -1:
return
# We need to use this regex since split() does not handle quote protection
romanopts = re.findall(r'[^"\s]\S*|".+?"', document.header[x])
opts = romanopts[1].strip('"')
i = find_token(document.header, "\\font_roman", 0)
if i == -1:
return
# We need to use this regex since split() does not handle quote protection
romanfont = re.findall(r'[^"\s]\S*|".+?"', document.header[i])
roman = romanfont[1].strip('"')
if roman != "NotoSerif-TLF":
return
j = find_token(document.header, "\\font_sans", 0)
if j == -1:
return
# We need to use this regex since split() does not handle quote protection
sffont = re.findall(r'[^"\s]\S*|".+?"', document.header[j])
sf = sffont[1].strip('"')
if sf != "default":
return
j = find_token(document.header, "\\font_typewriter", 0)
if j == -1:
return
# We need to use this regex since split() does not handle quote protection
ttfont = re.findall(r'[^"\s]\S*|".+?"', document.header[j])
tt = ttfont[1].strip('"')
if tt != "default":
return
# So we have noto as "complete font"
romanfont[1] = '"default"'
document.header[i] = " ".join(romanfont)
preamble = "\\usepackage["
preamble += opts
preamble += "]{noto}"
add_to_preamble(document, [preamble])
del document.header[x]
def revert_notoFonts_xopts(document):
" Revert native (extended) Noto font definition (with extra options) to LaTeX "
i = find_token(document.header, '\\use_non_tex_fonts', 0)
if i == -1:
document.warning("Malformed LyX document: Missing \\use_non_tex_fonts.")
return
if str2bool(get_value(document.header, "\\use_non_tex_fonts", i)):
return
fontmap = dict()
fm = createFontMapping(['Noto'])
revert_fonts(document, fm, fontmap, True)
add_preamble_fonts(document, fontmap)
def revert_IBMFonts_xopts(document):
" Revert native IBM font definition (with extra options) to LaTeX "
i = find_token(document.header, '\\use_non_tex_fonts', 0)
if i == -1:
document.warning("Malformed LyX document: Missing \\use_non_tex_fonts.")
return
if str2bool(get_value(document.header, "\\use_non_tex_fonts", i)):
return
fontmap = dict()
fm = createFontMapping(['IBM'])
ft = ""
revert_fonts(document, fm, fontmap, True)
add_preamble_fonts(document, fontmap)
def revert_AdobeFonts_xopts(document):
" Revert native Adobe font definition (with extra options) to LaTeX "
i = find_token(document.header, '\\use_non_tex_fonts', 0)
if i == -1:
document.warning("Malformed LyX document: Missing \\use_non_tex_fonts.")
return
if str2bool(get_value(document.header, "\\use_non_tex_fonts", i)):
return
fontmap = dict()
fm = createFontMapping(['Adobe'])
ft = ""
revert_fonts(document, fm, fontmap, True)
add_preamble_fonts(document, fontmap)
##
@ -2490,7 +2621,7 @@ convert = [
[580, []]
]
revert = [[579, [revert_font_opts, revert_minionpro]],
revert = [[579, [revert_minionpro, revert_plainNotoFonts_xopts, revert_notoFonts_xopts, revert_IBMFonts_xopts, revert_AdobeFonts_xopts, revert_font_opts]], # keep revert_font_opts last!
[578, [revert_babelfont]],
[577, [revert_drs]],
[576, [revert_linggloss, revert_subexarg]],