Skip to content

Commit

Permalink
Merge pull request #133 from m4rc1e/ops
Browse files Browse the repository at this point in the history
update name builders
  • Loading branch information
m4rc1e authored Apr 14, 2023
2 parents db5a94a + b8fc052 commit 98bdfcd
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Lib/axisregistry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ def _fvar_dflts(ttFont):
name = fallback.name
elided = fallback.value == axis_registry[
a.axisTag
].default_value and name not in ["Regular", "Italic"]
].default_value and name not in ["Regular", "Italic", "14pt"]
elif a.axisTag == "opsz":
name = f"{int(a.defaultValue)}pt"
elided = False
else:
name = None
elided = True # since we can't find a name for it, keep it elided
Expand Down Expand Up @@ -216,7 +219,9 @@ def build_stat(ttFont, sibling_ttFonts=[]):
}
)
if axis in LINKED_VALUES and fallback.value in LINKED_VALUES[axis]:
a["values"][-1]["linkedValue"] = LINKED_VALUES[axis][fallback.value]
linked_value = LINKED_VALUES[axis][fallback.value]
if any(f.value == linked_value for f in fallbacks):
a["values"][-1]["linkedValue"] = linked_value
res.append(a)

for axis, fallback in fallbacks_in_names:
Expand All @@ -228,7 +233,8 @@ def build_stat(ttFont, sibling_ttFonts=[]):
"values": [{"name": fallback.name, "value": fallback.value, "flags": 0x0}],
}
if axis in LINKED_VALUES and fallback.value in LINKED_VALUES[axis]:
a["values"][0]["linkedValue"] = LINKED_VALUES[axis][fallback.value]
linked_value = LINKED_VALUES[axis][fallback.value]
a["values"][0]["linkedValue"] = linked_value
res.append(a)

for axis, fallback in fallbacks_in_siblings:
Expand Down
Binary file added tests/data/Playfair[opsz,wdth,wght].ttf
Binary file not shown.
Binary file added tests/data/Wavefont[ROND,YALN,wght].ttf
Binary file not shown.
49 changes: 49 additions & 0 deletions tests/data/Wavefont[ROND,YALN,wght]_STAT.ttx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<Version value="0x00010001"/>
<DesignAxisRecordSize value="8"/>
<!-- DesignAxisCount=2 -->
<DesignAxisRecord>
<Axis index="0">
<AxisTag value="ROND"/>
<AxisNameID value="256"/> <!-- Roundness -->
<AxisOrdering value="0"/>
</Axis>
<Axis index="1">
<AxisTag value="wght"/>
<AxisNameID value="258"/> <!-- Weight -->
<AxisOrdering value="1"/>
</Axis>
</DesignAxisRecord>
<!-- AxisValueCount=5 -->
<AxisValueArray>
<AxisValue index="0" Format="1">
<AxisIndex value="0"/>
<Flags value="2"/> <!-- ElidableAxisValueName -->
<ValueNameID value="267"/> <!-- Default -->
<Value value="0.0"/>
</AxisValue>
<AxisValue index="1" Format="1">
<AxisIndex value="1"/>
<Flags value="0"/>
<ValueNameID value="259"/> <!-- Thin -->
<Value value="100.0"/>
</AxisValue>
<AxisValue index="2" Format="1">
<AxisIndex value="1"/>
<Flags value="0"/>
<ValueNameID value="260"/> <!-- ExtraLight -->
<Value value="200.0"/>
</AxisValue>
<AxisValue index="3" Format="1">
<AxisIndex value="1"/>
<Flags value="0"/>
<ValueNameID value="261"/> <!-- Light -->
<Value value="300.0"/>
</AxisValue>
<AxisValue index="4" Format="1">
<AxisIndex value="1"/>
<Flags value="2"/> <!-- ElidableAxisValueName -->
<ValueNameID value="2"/> <!-- Regular -->
<Value value="400.0"/>
</AxisValue>
</AxisValueArray>
<ElidedFallbackNameID value="2"/> <!-- Regular -->
22 changes: 22 additions & 0 deletions tests/test_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
opensans_cond_roman_fp = os.path.join(DATA_DIR, "OpenSansCondensed[wght].ttf")
opensans_cond_italic_fp = os.path.join(DATA_DIR, "OpenSansCondensed-Italic[wght].ttf")
wonky_fp = os.path.join(DATA_DIR, "Wonky[wdth,wght].ttf")
playfair_fp = os.path.join(DATA_DIR, "Playfair[opsz,wdth,wght].ttf")
wavefont_fp = os.path.join(DATA_DIR, "Wavefont[ROND,YALN,wght].ttf")


@pytest.fixture
Expand Down Expand Up @@ -293,6 +295,23 @@ def _test_names(ttFont, expected):
(17, 3, 1, 0x409): None,
},
),
# Test opsz particle is kept.
# Fixes https://github.com/googlefonts/axisregistry/issues/130
(
playfair_fp,
"Playfair",
None,
[],
{
(1, 3, 1, 0x409): "Playfair 5pt SemiExpanded Light",
(2, 3, 1, 0x409): "Regular",
(3, 3, 1, 0x409): "2.000;FTH;Playfair-5ptSemiExpandedLight",
(4, 3, 1, 0x409): "Playfair 5pt SemiExpanded Light",
(6, 3, 1, 0x409): "Playfair-5ptSemiExpandedLight",
(16, 3, 1, 0x409): "Playfair",
(17, 3, 1, 0x409): "5pt SemiExpanded Light",
},
),
],
)
def test_name_table(fp, family_name, style_name, siblings, expected):
Expand Down Expand Up @@ -440,6 +459,9 @@ def dump(table, ttFont=None):
[opensans_roman_fp, opensans_italic_fp, opensans_cond_roman_fp],
),
(wonky_fp, []),
# don't add a linkedValue for Regular to Bold since Bold doesn't exist
# Fixes https://github.com/googlefonts/axisregistry/issues/104
(wavefont_fp, []),
],
)
def test_stat(fp, sibling_fps):
Expand Down

0 comments on commit 98bdfcd

Please sign in to comment.