Merge commit '2d08f1a1890851bc7860a6fd8e9b8b49597a384d' into axis-registry-pull-SHRP
This commit is contained in:
@@ -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
|
||||
@@ -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:
|
||||
@@ -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:
|
||||
@@ -250,13 +256,31 @@ def build_stat(ttFont, sibling_ttFonts=[]):
|
||||
|
||||
|
||||
def build_name_table(ttFont, family_name=None, style_name=None, siblings=[]):
|
||||
from fontTools.varLib.instancer import setRibbiBits
|
||||
|
||||
log.info("Building name table")
|
||||
name_table = ttFont["name"]
|
||||
family_name = family_name if family_name else name_table.getBestFamilyName()
|
||||
style_name = style_name if style_name else name_table.getBestSubFamilyName()
|
||||
if is_variable(ttFont):
|
||||
return build_vf_name_table(ttFont, family_name, siblings=siblings)
|
||||
return build_static_name_table_v1(ttFont, family_name, style_name)
|
||||
build_vf_name_table(ttFont, family_name, siblings=siblings)
|
||||
else:
|
||||
build_static_name_table_v1(ttFont, family_name, style_name)
|
||||
|
||||
# Set bits
|
||||
style_name = name_table.getBestSubFamilyName()
|
||||
# usWeightClass
|
||||
weight_seen = False
|
||||
for weight in sorted(GF_STATIC_STYLES, key=lambda k: len(k), reverse=True):
|
||||
if weight in style_name:
|
||||
weight_seen = True
|
||||
ttFont["OS/2"].usWeightClass = GF_STATIC_STYLES[weight]
|
||||
break
|
||||
if not weight_seen:
|
||||
log.warning(
|
||||
f"No known weight found for stylename {style_name}. Cannot set OS2.usWeightClass"
|
||||
)
|
||||
setRibbiBits(ttFont)
|
||||
|
||||
|
||||
def _fvar_instance_collisions(ttFont, siblings=[]):
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
# from Kablammo
|
||||
tag: "MUTA"
|
||||
display_name: "Mutation"
|
||||
min_value: 0
|
||||
default_value: 0
|
||||
max_value: 60
|
||||
precision: 0
|
||||
fallback {
|
||||
name: "Default"
|
||||
value: 0
|
||||
}
|
||||
fallback_only: false
|
||||
description:
|
||||
"As the mutation axis progresses, in seconds, "
|
||||
"letterforms morph — changing in ways that don't change "
|
||||
"their other attributes like width or weight."
|
||||
|
||||
15
axisregistry/Lib/axisregistry/data/sharpness.textproto
Normal file
15
axisregistry/Lib/axisregistry/data/sharpness.textproto
Normal file
@@ -0,0 +1,15 @@
|
||||
#SHRP based on https://github.com/monokromskriftforlag/geologisk/
|
||||
tag: "SHRP"
|
||||
display_name: "Sharpness"
|
||||
min_value: 0
|
||||
default_value: 0
|
||||
max_value: 100
|
||||
precision: 0
|
||||
fallback {
|
||||
name: "Default"
|
||||
value: 0
|
||||
}
|
||||
fallback_only: false
|
||||
description:
|
||||
"Adjust shapes from angular or blunt default shapes (0%)"
|
||||
" to become increasingly sharped forms (up to 100%)."
|
||||
BIN
axisregistry/tests/data/Playfair[opsz,wdth,wght].ttf
Normal file
BIN
axisregistry/tests/data/Playfair[opsz,wdth,wght].ttf
Normal file
Binary file not shown.
BIN
axisregistry/tests/data/Wavefont[ROND,YALN,wght].ttf
Normal file
BIN
axisregistry/tests/data/Wavefont[ROND,YALN,wght].ttf
Normal file
Binary file not shown.
49
axisregistry/tests/data/Wavefont[ROND,YALN,wght]_STAT.ttx
Normal file
49
axisregistry/tests/data/Wavefont[ROND,YALN,wght]_STAT.ttx
Normal file
@@ -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 -->
|
||||
@@ -25,6 +25,8 @@ opensans_italic_fp = os.path.join(DATA_DIR, "OpenSans-Italic[wdth,wght].ttf")
|
||||
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
|
||||
@@ -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):
|
||||
@@ -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):
|
||||
@@ -525,3 +547,23 @@ def test_build_variations_ps_name(fp, result):
|
||||
build_variations_ps_name(ttFont)
|
||||
variation_ps_name = ttFont["name"].getName(25, 3, 1, 0x409).toUnicode()
|
||||
assert variation_ps_name == result
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"fp, style_name, result",
|
||||
[
|
||||
(mavenpro_fp, "Regular", 400),
|
||||
(mavenpro_fp, "Italic", 400),
|
||||
(mavenpro_fp, "Black Italic", 900),
|
||||
(mavenpro_fp, "ExtraBold Italic", 800),
|
||||
(mavenpro_fp, "ExtraBold", 800),
|
||||
(mavenpro_fp, "Bold", 700),
|
||||
(mavenpro_fp, "Bold Italic", 700),
|
||||
(mavenpro_fp, "Thin Italic", 100),
|
||||
(mavenpro_fp, "Thin", 100),
|
||||
],
|
||||
)
|
||||
def test_us_weight_class(fp, style_name, result):
|
||||
ttFont = TTFont(fp)
|
||||
build_name_table(ttFont, style_name=style_name)
|
||||
assert ttFont["OS/2"].usWeightClass == result
|
||||
|
||||
Reference in New Issue
Block a user