Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that particle names on STAT table match the fallback names... #3056

Merged
merged 3 commits into from
Oct 15, 2020

Conversation

felipesanches
Copy link
Collaborator

...in each axis registry at the Google Fonts Axis Registry
(issue #3022)

This pull request is marked as a DRAFT because it still lacks code-tests. I want to get feedback from @m4rc1e regarding whether this implementation correctly encodes the checking procedures he had in mind for the STAT table when he requested it at #3022. If Marc agrees that this is indeed what we should be checking for, then I'll put the effort to write a few test-case examples in a code-test for this check.

Copy link
Collaborator

@m4rc1e m4rc1e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this! I really appreciate it.

I find the nested loops and conditions difficult to read. It may be best to munge the axis registry and stat table into flatter data structures e.g

font_axis_values = {
    "wght": {"value": 100, "name": Thin},
    "wdth": {"value": 75, "name": Condensed},
    ...
}

axis_registry_fallbacks = {
    wght: [
        {"value": 100, "name": "Thin"},
         ...
    ],
    ...
}

It should then be much easier to make the comparison.

for axis_tag, axis_value in font_axis_values.items():
    if axis_tag not in axis_registry_fallbacks:
        # Warn/fail that axis isn't in the axis registry
    else:
        if axis_value not in axis_registry[axis_tag]:
            # Fail that axis isn't in the axis registry

Besides from the readability improvements, we also need to do the following:

for axis_value in ttFont['STAT'].table.AxisValueArray.AxisValue:
axis = ttFont['STAT'].table.DesignAxisRecord.Axis[axis_value.AxisIndex]
if axis.AxisTag in GFAxisRegistry.keys():
expected = GFAxisRegistry[axis.AxisTag]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format 4 AxisValue tables don't have an AxisIndex attrib.

https://docs.microsoft.com/en-us/typography/opentype/spec/stat#axis-value-table-format-4

if axis.AxisTag in GFAxisRegistry.keys():
expected = GFAxisRegistry[axis.AxisTag]
expected_names = [fb.name for fb in expected.fallback]
for name_entry in ttFont['name'].names:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be wise to only check nameRecords which are US English only (langid=0x409) against our axis registry. We may have fonts in the future which contain non-english nameRecords for STAT particles.

@felipesanches
Copy link
Collaborator Author

thanks for all the feedback!

felipesanches added a commit to felipesanches/fontbakery that referenced this pull request Oct 12, 2020
felipesanches added a commit to felipesanches/fontbakery that referenced this pull request Oct 12, 2020
@felipesanches felipesanches marked this pull request as ready for review October 14, 2020 23:49
@felipesanches felipesanches merged commit 963bcbf into fonttools:master Oct 15, 2020
felipesanches added a commit that referenced this pull request Oct 15, 2020
@felipesanches
Copy link
Collaborator Author

@m4rc1e, I'm merging this now because it is already useful. If possible, please open a new issue attaching a format-4 table so that we can expand the implementation to support that as well.

def com_google_fonts_check_STAT_gf_axisregistry_names(ttFont, GFAxisRegistry):
""" Validate STAT particle names and values match the fallback names in GFAxisRegistry. """

def normalize_name(name):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function already exists in googlefonts_conditions

@m4rc1e
Copy link
Collaborator

m4rc1e commented Oct 15, 2020

This looks pretty good! I agree it's now worth merging. Thank you so much for adding this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants