1
1
mirror of https://github.com/rsms/inter.git synced 2024-11-28 22:13:40 +03:00

change STAT table records to version 1 when possible, to make things work with Microsoft Word et al

This commit is contained in:
Rasmus Andersson 2023-11-18 18:01:49 -08:00
parent 708a089297
commit 97ff35b54c

View File

@ -54,32 +54,37 @@ def stat_axes_format_2(is_italic):
dict(nominalValue=900, rangeMinValue=850, rangeMaxValue=900, name="Black"), dict(nominalValue=900, rangeMinValue=850, rangeMaxValue=900, name="Black"),
]), ]),
dict(name="Italic", tag="ital", ordering=2, values=[ dict(name="Italic", tag="ital", ordering=2, values=[
dict(value=1, name="Italic") if is_italic else \ dict(value=1, name="Italic", linkedValue=0) if is_italic else \
dict(value=0, name="Roman", flags=FLAG_DEFAULT, linkedValue=1), dict(value=0, name="Roman", flags=FLAG_DEFAULT),
]), ]),
] ]
# # stat_axes_format_3 is used for making a STAT table with format 1 & 3 records # stat_axes_format_3 is used for making a STAT table with format 1 & 3 records
# def stat_axes_format_3(is_italic): def stat_axes_format_3(is_italic):
# # see https://learn.microsoft.com/en-us/typography/opentype/spec/ # see https://learn.microsoft.com/en-us/typography/opentype/spec/
# # stat#axis-value-table-format-3 # stat#axis-value-table-format-3
# suffix = " Italic" if is_italic else "" return [
# return [ dict(name="Optical Size", tag="opsz", values=[
# { "name": "Optical Size", "tag": "opsz" }, dict(value=OPSZ_MIN, name="Text"),
# { "name": "Weight", "tag": "wght", "values": [ dict(value=OPSZ_MAX, name="Display"),
# { "name": "Thin"+suffix, "value": 100, "linkedValue": 400 }, ]),
# { "name": "ExtraLight"+suffix, "value": 200, "linkedValue": 500 }, dict(name="Weight", tag="wght", values=[
# { "name": "Light"+suffix, "value": 300, "linkedValue": 600 }, dict(name="Thin", value=100 ),
# { "name": "Regular"+suffix, "value": 400, "linkedValue": 700, dict(name="ExtraLight", value=200 ),
# "flags":FLAG_DEFAULT }, dict(name="Light", value=300 ),
# { "name": "Medium"+suffix, "value": 500, "linkedValue": 800 }, dict(name="Regular", value=400, linkedValue=700, flags=FLAG_DEFAULT ),
# { "name": "SemiBold"+suffix, "value": 600, "linkedValue": 900 }, dict(name="Medium", value=500 ),
# { "name": "Bold"+suffix, "value": 700 }, dict(name="SemiBold", value=600 ),
# { "name": "ExtraBold"+suffix, "value": 800 }, dict(name="Bold", value=700 ),
# { "name": "Black"+suffix, "value": 900 }, dict(name="ExtraBold", value=800 ),
# ]}, dict(name="Black", value=900 ),
# ] ]),
dict(name="Italic", tag="ital", values=[
dict(value=1, name="Italic") if is_italic else \
dict(value=0, name="Roman", flags=FLAG_DEFAULT),
]),
]
# # STAT_AXES is used for making a STAT table with format 4 records # # STAT_AXES is used for making a STAT table with format 4 records
@ -313,26 +318,38 @@ def gen_stat(ttfont):
# bugs out. See https://github.com/rsms/inter/issues/577 # bugs out. See https://github.com/rsms/inter/issues/577
# #
# build a version 1.1 STAT table with format 2 records: # build a version 1.1 STAT table with format 2 records:
buildStatTable(ttfont, stat_axes_format_2(font_is_italic(ttfont))) #buildStatTable(ttfont, stat_axes_format_2(font_is_italic(ttfont)))
# #
# build a version 1.1 STAT table with format 1 and 3 records: # build a version 1.1 STAT table with format 1 and 3 records:
#buildStatTable(ttfont, stat_axes_format_3(font_is_italic(ttfont))) buildStatTable(ttfont, stat_axes_format_3(font_is_italic(ttfont)))
# #
# build a version 1.2 STAT table with format 4 records: # build a version 1.2 STAT table with format 4 records:
#locations = stat_locations(font_is_italic(ttfont)) #locations = stat_locations(font_is_italic(ttfont))
#buildStatTable(ttfont, STAT_AXES, locations=locations) #buildStatTable(ttfont, STAT_AXES, locations=locations)
def fixup_fvar(ttfont): def check_fvar(ttfont):
fvar = ttfont['fvar'] fvar = ttfont['fvar']
error = False
for i in fvar.instances: for i in fvar.instances:
wght = round(i.coordinates['wght'] / 100) * 100 actual_wght = i.coordinates['wght']
expected_wght = round(actual_wght / 100) * 100
if expected_wght != actual_wght:
print(f"unexpected wght {actual_wght} (expected {expected_wght})",
ttfont, i.coordinates)
error = True
# def fixup_fvar(ttfont):
# fvar = ttfont['fvar']
# for i in fvar.instances:
# wght = round(i.coordinates['wght'] / 100) * 100
# print(f"wght {i.coordinates['wght']} -> {wght}") # print(f"wght {i.coordinates['wght']} -> {wght}")
i.coordinates['wght'] = wght # #i.coordinates['wght'] = wght
# for a in fvar.axes: # # for a in fvar.axes:
# if a.axisTag == "wght": # # if a.axisTag == "wght":
# a.defaultValue = 400 # # a.defaultValue = 400
# break # # break
# def fixup_os2(ttfont): # def fixup_os2(ttfont):
@ -378,8 +395,8 @@ def main():
# build STAT table # build STAT table
gen_stat(ttfont) gen_stat(ttfont)
# fixup fvar table # check fvar table
fixup_fvar(ttfont) check_fvar(ttfont)
# # fixup OS/2 table (set usWeightClass) # # fixup OS/2 table (set usWeightClass)
# fixup_os2(ttfont) # fixup_os2(ttfont)