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

fix_weight_class variable font improvement #477

Closed
ollimeier opened this issue Feb 1, 2022 · 3 comments
Closed

fix_weight_class variable font improvement #477

ollimeier opened this issue Feb 1, 2022 · 3 comments

Comments

@ollimeier
Copy link

According to Microsoft's OT spec the usWeightClass should match the fvar default value.
In most of the cases this might be 400, but in some it's not.

fix_weight_class does not take care of that:

def fix_weight_class(ttFont):

The OT Spec says:
In a variable font that implements 'wght' variations, the value in the usWeightClass field of the OS/2 table must match the default 'wght' value specified in the 'fvar' table.
https://docs.microsoft.com/en-us/typography/opentype/spec/dvaraxistag_wght#additional-information

That do you think about something like that:

def fix_weight_class_var(font_obj):
    if 'fvar' not in font_obj:
        # not a variable font
        return

    fvar = font_obj['fvar']
    default_axis_values = {a.axisTag: a.defaultValue for a in fvar.axes}

    print('default_axis_values: ', default_axis_values)
    v = default_axis_values.get('wght', None)

    if isinstance(v, int) or isinstance(v, float):
        font_obj["OS/2"].usWeightClass = int(v)
        print('Changed usWeightClass tom match fvar default value.')
@simoncozens
Copy link
Contributor

This sounds like a good idea. We should also have a fontbakery check which does this.

By the way, the second if test could just be if v is not None.

@ollimeier
Copy link
Author

@simoncozens I just made a PR :) I will also add that to fontbakery.

@m4rc1e
Copy link
Collaborator

m4rc1e commented Feb 4, 2022

Fixed in #481

@m4rc1e m4rc1e closed this as completed Feb 4, 2022
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

No branches or pull requests

3 participants