Skip to content

Commit

Permalink
Merge a few checks into opentype/fvar/regular_coords_correct
Browse files Browse the repository at this point in the history
Following FontSpector.

New check:
 - opentype/fvar/regular_coords_correct

Old checks:
 - opentype/varfont/regular_ital_coord
 - opentype/varfont/regular_opsz_coord
 - opentype/varfont/regular_slnt_coord
 - opentype/varfont/regular_wdth_coord
 - opentype/varfont/regular_wght_coord

On the OpenType profile.

(issue fonttools#4865)
  • Loading branch information
felipesanches committed Nov 15, 2024
1 parent e581c09 commit 34f9e59
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 329 deletions.
203 changes: 51 additions & 152 deletions Lib/fontbakery/checks/opentype_fvar_regular_coords_correct.py
Original file line number Diff line number Diff line change
@@ -1,161 +1,60 @@
from fontbakery.prelude import check, Message, FAIL, PASS, WARN
from fontbakery.prelude import check, Message, FAIL, WARN


@check(
id="opentype/varfont/regular_wght_coord",
id="opentype/fvar/regular_coords_correct",
rationale="""
According to the OpenType spec's
registered design-variation tag 'wght' available at
https://docs.microsoft.com/en-gb/typography/opentype/spec/dvaraxistag_wght
If a variable font has a 'wght' (Weight) axis, then the coordinate of
its 'Regular' instance is required to be 400.
""",
conditions=["is_variable_font", "has_wght_axis"],
proposal="https://github.com/fonttools/fontbakery/issues/1707",
)
def check_varfont_regular_wght_coord(ttFont, regular_wght_coord):
"""The variable font 'wght' (Weight) axis coordinate must be 400 on the
'Regular' instance."""

if regular_wght_coord is None:
yield FAIL, Message("no-regular-instance", '"Regular" instance not present.')
elif regular_wght_coord == 400:
yield PASS, "Regular:wght is 400."
else:
yield FAIL, Message(
"wght-not-400",
f'The "wght" axis coordinate of'
f' the "Regular" instance must be 400.'
f" Got {regular_wght_coord} instead.",
)


@check(
id="opentype/varfont/regular_wdth_coord",
rationale="""
According to the OpenType spec's
registered design-variation tag 'wdth' available at
https://docs.microsoft.com/en-gb/typography/opentype/spec/dvaraxistag_wdth
If a variable font has a 'wdth' (Width) axis, then the coordinate of
its 'Regular' instance is required to be 100.
""",
conditions=["is_variable_font", "has_wdth_axis"],
proposal="https://github.com/fonttools/fontbakery/issues/1707",
)
def check_varfont_regular_wdth_coord(ttFont, regular_wdth_coord):
"""
The variable font 'wdth' (Width) axis coordinate must be 100 on the 'Regular'
instance.
"""

if regular_wdth_coord is None:
yield FAIL, Message("no-regular-instance", '"Regular" instance not present.')
elif regular_wdth_coord == 100:
yield PASS, "Regular:wdth is 100."
else:
yield FAIL, Message(
"wdth-not-100",
f'The "wdth" axis coordinate of'
f' the "Regular" instance must be 100.'
f" Got {regular_wdth_coord} as a default value instead.",
)


@check(
id="opentype/varfont/regular_slnt_coord",
rationale="""
According to the OpenType spec's
registered design-variation tag 'slnt' available at
https://docs.microsoft.com/en-gb/typography/opentype/spec/dvaraxistag_slnt
If a variable font has a 'slnt' (Slant) axis, then the coordinate of
its 'Regular' instance is required to be zero.
According to the Open-Type spec's registered design-variation tags,instances in a variable font should have certain prescribed values.
If a variable font has a 'wght' (Weight) axis, the valid coordinate range is 1-1000.
If a variable font has a 'wdth' (Width) axis, the valid numeric range is strictly greater than zero.
If a variable font has a 'slnt' (Slant) axis, then the coordinate of its 'Regular' instance is required to be 0.
If a variable font has a 'ital' (Slant) axis, then the coordinate of its 'Regular' instance is required to be 0.
""",
conditions=["is_variable_font", "has_slnt_axis"],
proposal="https://github.com/fonttools/fontbakery/issues/1707",
conditions=["is_variable_font"],
proposal=[
"https://github.com/fonttools/fontbakery/issues/1707",
"https://github.com/fonttools/fontbakery/issues/2572",
],
)
def check_varfont_regular_slnt_coord(ttFont, regular_slnt_coord):
"""
The variable font 'slnt' (Slant) axis coordinate must be zero on the 'Regular'
instance.
"""

if regular_slnt_coord is None:
yield FAIL, Message("no-regular-instance", '"Regular" instance not present.')
elif regular_slnt_coord == 0:
yield PASS, "Regular:slnt is zero."
else:
yield FAIL, Message(
"slnt-not-0",
f'The "slnt" axis coordinate of'
f' the "Regular" instance must be zero.'
f" Got {regular_slnt_coord} as a default value instead.",
)


@check(
id="opentype/varfont/regular_ital_coord",
rationale="""
According to the OpenType spec's
registered design-variation tag 'ital' available at
https://docs.microsoft.com/en-gb/typography/opentype/spec/dvaraxistag_ital
If a variable font has a 'ital' (Italic) axis, then the coordinate of
its 'Regular' instance is required to be zero.
""",
conditions=["is_variable_font", "has_ital_axis"],
proposal="https://github.com/fonttools/fontbakery/issues/1707",
)
def check_varfont_regular_ital_coord(ttFont, regular_ital_coord):
"""
The variable font 'ital' (Italic) axis coordinate must be zero on the 'Regular'
instance.
"""

if regular_ital_coord is None:
yield FAIL, Message("no-regular-instance", '"Regular" instance not present.')
elif regular_ital_coord == 0:
yield PASS, "Regular:ital is zero."
else:
yield FAIL, Message(
"ital-not-0",
f'The "ital" axis coordinate of'
f' the "Regular" instance must be zero.'
f" Got {regular_ital_coord} as a default value instead.",
)


@check(
id="opentype/varfont/regular_opsz_coord",
rationale="""
According to the OpenType spec's
registered design-variation tag 'opsz' available at
https://docs.microsoft.com/en-gb/typography/opentype/spec/dvaraxistag_opsz
If a variable font has an 'opsz' (Optical Size) axis, then
the coordinate of its 'Regular' instance is recommended to be
a value in the range 10 to 16.
""",
conditions=["is_variable_font", "has_opsz_axis"],
proposal="https://github.com/fonttools/fontbakery/issues/1707",
)
def check_varfont_regular_opsz_coord(ttFont, regular_opsz_coord):
"""
The variable font 'opsz' (Optical Size) axis coordinate should be between 10 and 16
on the 'Regular' instance.
"""

if regular_opsz_coord is None:
def check_fvar_regular_coords_correct(
ttFont,
regular_wght_coord,
regular_wdth_coord,
regular_slnt_coord,
regular_ital_coord,
regular_opsz_coord,
):
"""Axes and named instances fall within correct ranges?"""

REGULAR_COORDINATE_EXPECTATIONS = [
("wght", 400, regular_wght_coord),
("wdth", 100, regular_wdth_coord),
("slnt", 0, regular_slnt_coord),
("ital", 0, regular_ital_coord),
]

if (
regular_wght_coord is None
and regular_wdth_coord is None
and regular_slnt_coord is None
and regular_ital_coord is None
and regular_opsz_coord is None
):
yield FAIL, Message("no-regular-instance", '"Regular" instance not present.')
elif regular_opsz_coord >= 10 and regular_opsz_coord <= 16:
yield PASS, f"Regular:opsz coordinate ({regular_opsz_coord}) looks good."
else:
return

for axis, expected, actual in REGULAR_COORDINATE_EXPECTATIONS:
if actual is not None and actual != expected:
yield FAIL, Message(
f"{axis}-not-{expected}",
f"Regular instance has {axis} coordinate of {actual},"
f" expected {expected}",
)

actual = regular_opsz_coord
if actual and not (10 <= actual <= 16):
yield WARN, Message(
"opsz-out-of-range",
f'The "opsz" (Optical Size) coordinate'
f' on the "Regular" instance is recommended'
f" to be a value in the range 10 to 16."
f" Got {regular_opsz_coord} instead.",
"opsz",
f"Regular instance has opsz coordinate of {actual},"
f" expected between 10 and 16",
)
30 changes: 1 addition & 29 deletions Lib/fontbakery/profiles/adobefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,35 +176,7 @@
"reason": "Adobe strongly recommends, but does not require having a Bold instance, and that instance should have coordinate 700 on the 'wght' axis.",
},
],
"opentype/varfont/regular_ital_coord": [
{
"code": "no-regular-instance",
"status": "WARN",
"reason": "Adobe strongly recommends, but does not require having a Regular instance.",
},
],
"opentype/varfont/regular_opsz_coord": [
{
"code": "no-regular-instance",
"status": "WARN",
"reason": "Adobe strongly recommends, but does not require having a Regular instance.",
},
],
"opentype/varfont/regular_slnt_coord": [
{
"code": "no-regular-instance",
"status": "WARN",
"reason": "Adobe strongly recommends, but does not require having a Regular instance.",
},
],
"opentype/varfont/regular_wdth_coord": [
{
"code": "no-regular-instance",
"status": "WARN",
"reason": "Adobe strongly recommends, but does not require having a Regular instance.",
},
],
"opentype/varfont/regular_wght_coord": [
"opentype/fvar/regular_coords_correct": [
{
"code": "no-regular-instance",
"status": "WARN",
Expand Down
6 changes: 1 addition & 5 deletions Lib/fontbakery/profiles/opentype.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"opentype/fsselection",
"opentype/fsselection_matches_macstyle",
"opentype/fvar/axis_ranges_correct",
"opentype/fvar/regular_coords_correct",
"opentype/gdef_mark_chars",
"opentype/gdef_non_mark_chars",
"opentype/gdef_spacing_marks",
Expand Down Expand Up @@ -49,11 +50,6 @@
"opentype/varfont/distinct_instance_records",
"opentype/varfont/family_axis_ranges",
"opentype/varfont/foundry_defined_tag_name",
"opentype/varfont/regular_ital_coord",
"opentype/varfont/regular_opsz_coord",
"opentype/varfont/regular_slnt_coord",
"opentype/varfont/regular_wdth_coord",
"opentype/varfont/regular_wght_coord",
"opentype/varfont/same_size_instance_records",
"opentype/varfont/stat_axis_record_for_each_axis",
"opentype/varfont/valid_default_instance_nameids",
Expand Down
34 changes: 1 addition & 33 deletions Lib/fontbakery/profiles/typenetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,39 +132,7 @@
"the 'wght' axis.",
},
],
"opentype/varfont/regular_ital_coord": [
{
"code": "no-regular-instance",
"status": "WARN",
"reason": "Adobe and Type Network recommend, but do not require"
" having a Regular instance.",
},
],
"opentype/varfont/regular_opsz_coord": [
{
"code": "no-regular-instance",
"status": "WARN",
"reason": "Adobe and Type Network recommend, but do not require"
" having a Regular instance.",
},
],
"opentype/varfont/regular_slnt_coord": [
{
"code": "no-regular-instance",
"status": "WARN",
"reason": "Adobe and Type Network recommend, but do not require"
" having a Regular instance.",
},
],
"opentype/varfont/regular_wdth_coord": [
{
"code": "no-regular-instance",
"status": "WARN",
"reason": "Adobe and Type Network recommend, but do not require"
" having a Regular instance.",
},
],
"opentype/varfont/regular_wght_coord": [
"opentype/fvar/regular_coords_correct": [
{
"code": "no-regular-instance",
"status": "WARN",
Expand Down
Loading

0 comments on commit 34f9e59

Please sign in to comment.