Apply RIBBI bits to all kinds of fonts
This commit is contained in:
parent
a3e14643a1
commit
16d899a2be
@ -1271,19 +1271,18 @@ def instantiateVariableFont(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if "fvar" not in varfont:
|
# Set Regular/Italic/Bold/Bold Italic bits as appropriate, after the name
|
||||||
# For statics, we should set various bits to mark them as
|
# table has been updated.
|
||||||
# Regular/Italic/Bold/BoldItalic as appropriate.
|
setRibbiBits(varfont)
|
||||||
setRibbiBits(varfont)
|
|
||||||
|
|
||||||
return varfont
|
return varfont
|
||||||
|
|
||||||
|
|
||||||
def setRibbiBits(staticFont):
|
def setRibbiBits(font):
|
||||||
"""Set the `head.macStyle` and `OS/2.fsSelection` style bits
|
"""Set the `head.macStyle` and `OS/2.fsSelection` style bits
|
||||||
appropriately."""
|
appropriately."""
|
||||||
|
|
||||||
english_ribbi_style = staticFont["name"].getName(2, 3, 1, 0x409)
|
english_ribbi_style = font["name"].getName(2, 3, 1, 0x409)
|
||||||
if english_ribbi_style is None:
|
if english_ribbi_style is None:
|
||||||
log.warning(
|
log.warning(
|
||||||
"Cannot set RIBBI bits because there is no Windows Unicode BMP name ID 2."
|
"Cannot set RIBBI bits because there is no Windows Unicode BMP name ID 2."
|
||||||
@ -1291,14 +1290,21 @@ def setRibbiBits(staticFont):
|
|||||||
return
|
return
|
||||||
|
|
||||||
styleMapStyleName = english_ribbi_style.toStr().lower()
|
styleMapStyleName = english_ribbi_style.toStr().lower()
|
||||||
if styleMapStyleName == "bold":
|
if styleMapStyleName not in {"regular", "bold", "italic", "bold italic"}:
|
||||||
staticFont["head"].macStyle = 0b01
|
log.warning(
|
||||||
elif styleMapStyleName == "bold italic":
|
"Cannot set RIBBI bits because the Windows Unicode BMP name ID 2 is "
|
||||||
staticFont["head"].macStyle = 0b11
|
"something other than Regular/Italic/Bold/Bold Italic."
|
||||||
elif styleMapStyleName == "italic":
|
)
|
||||||
staticFont["head"].macStyle = 0b10
|
return
|
||||||
|
|
||||||
selection = staticFont["OS/2"].fsSelection
|
if styleMapStyleName == "bold":
|
||||||
|
font["head"].macStyle = 0b01
|
||||||
|
elif styleMapStyleName == "bold italic":
|
||||||
|
font["head"].macStyle = 0b11
|
||||||
|
elif styleMapStyleName == "italic":
|
||||||
|
font["head"].macStyle = 0b10
|
||||||
|
|
||||||
|
selection = font["OS/2"].fsSelection
|
||||||
# First clear...
|
# First clear...
|
||||||
selection &= ~(1 << 0)
|
selection &= ~(1 << 0)
|
||||||
selection &= ~(1 << 5)
|
selection &= ~(1 << 5)
|
||||||
@ -1313,7 +1319,7 @@ def setRibbiBits(staticFont):
|
|||||||
elif styleMapStyleName == "bold italic":
|
elif styleMapStyleName == "bold italic":
|
||||||
selection |= 1 << 0
|
selection |= 1 << 0
|
||||||
selection |= 1 << 5
|
selection |= 1 << 5
|
||||||
staticFont["OS/2"].fsSelection = selection
|
font["OS/2"].fsSelection = selection
|
||||||
|
|
||||||
|
|
||||||
def splitAxisLocationAndRanges(axisLimits, rangeType=AxisRange):
|
def splitAxisLocationAndRanges(axisLimits, rangeType=AxisRange):
|
||||||
|
1830
Tests/varLib/instancer/data/STATInstancerTest.ttx
Normal file
1830
Tests/varLib/instancer/data/STATInstancerTest.ttx
Normal file
File diff suppressed because it is too large
Load Diff
@ -1975,3 +1975,35 @@ def test_main_exit_multiple_limits(varfont, tmpdir, capsys):
|
|||||||
captured = capsys.readouterr()
|
captured = capsys.readouterr()
|
||||||
|
|
||||||
assert "Specified multiple limits for the same axis" in captured.err
|
assert "Specified multiple limits for the same axis" in captured.err
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_ribbi_bits():
|
||||||
|
varfont = ttLib.TTFont()
|
||||||
|
varfont.importXML(os.path.join(TESTDATA, "STATInstancerTest.ttx"))
|
||||||
|
|
||||||
|
for location in [instance.coordinates for instance in varfont["fvar"].instances]:
|
||||||
|
instance = instancer.instantiateVariableFont(
|
||||||
|
varfont, location, updateFontNames=True
|
||||||
|
)
|
||||||
|
name_id_2 = instance["name"].getDebugName(2)
|
||||||
|
mac_style = instance["head"].macStyle
|
||||||
|
fs_selection = instance["OS/2"].fsSelection & 0b1100001 # Just bits 0, 5, 6
|
||||||
|
|
||||||
|
if location["ital"] == 0:
|
||||||
|
if location["wght"] == 700:
|
||||||
|
assert name_id_2 == "Bold", location
|
||||||
|
assert mac_style == 0b01, location
|
||||||
|
assert fs_selection == 0b0100000, location
|
||||||
|
else:
|
||||||
|
assert name_id_2 == "Regular", location
|
||||||
|
assert mac_style == 0b00, location
|
||||||
|
assert fs_selection == 0b1000000, location
|
||||||
|
else:
|
||||||
|
if location["wght"] == 700:
|
||||||
|
assert name_id_2 == "Bold Italic", location
|
||||||
|
assert mac_style == 0b11, location
|
||||||
|
assert fs_selection == 0b0100001, location
|
||||||
|
else:
|
||||||
|
assert name_id_2 == "Italic", location
|
||||||
|
assert mac_style == 0b10, location
|
||||||
|
assert fs_selection == 0b0000001, location
|
||||||
|
Loading…
x
Reference in New Issue
Block a user