Skip to content

Commit

Permalink
Merge pull request #131 from m4rc1e/bits
Browse files Browse the repository at this point in the history
build_name_table: set bits as well
  • Loading branch information
m4rc1e authored Apr 13, 2023
2 parents 12b2364 + 37b137e commit db5a94a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Lib/axisregistry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,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=[]):
Expand Down
20 changes: 20 additions & 0 deletions tests/test_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,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

0 comments on commit db5a94a

Please sign in to comment.