Skip to content

Font build fail becasue of number in file name #640

@ir33k

Description

@ir33k

When generating font _get_font_height_from_name is used to get expected font height size from font file name

def _get_font_height_from_name(name):
"""
Search the name of the font for an integer which will be used as the
pixel height of the generated font
"""
match = re.search('([0-9]+)', name)
if match is None:
if name != 'FONT_FALLBACK' and name != 'FONT_FALLBACK_INTERNAL':
raise ValueError('Font {0}: no height found in name\n'.format(name))
return 14

Later freetype library validates font size based on size produced by this function.
I'm not on the latest SDK but I see that this function is still used on master branch.
I just want to point out potential user experience issue connected with that logic.

Custom font I tried to build had a number in file name which had nothing to do with font size, it was just part of the name.
Because of that build failed with "Invalid Pixel Size" error.
This was very difficult to debug as error comes from freefont library and not python code and I never suspected that filename can affect build in any way.
Removing numbers from file name, or changing first number to font height solves the problem.
I suspect that this logic was added to prevent some kind of mistakes like mismatch of file with actual file content or something like that.

Maybe we should have some kind of warning in https://developer.rebble.io/guides/app-resources/fonts/ that font filename should either contain font height or no numbers?
Or maybe error message can include hint mentioning file name?

It's a small thing, but took me hours to figure out.
Maybe small change in right place can save someone a lot of time in the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions