diff options
Diffstat (limited to 'tools/layoutlib/rename_font/build_font.py')
-rwxr-xr-x | tools/layoutlib/rename_font/build_font.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/tools/layoutlib/rename_font/build_font.py b/tools/layoutlib/rename_font/build_font.py index c747d92..9713a4c 100755 --- a/tools/layoutlib/rename_font/build_font.py +++ b/tools/layoutlib/rename_font/build_font.py @@ -209,15 +209,18 @@ def ends_in_regular(string): def get_version(string): - # The string must begin with 'Version n.nn ' - # to extract n.nn, we return the second entry in the split strings. string = string.strip() - if not string.startswith('Version '): - raise InvalidFontException('mal-formed font version') - return sanitize(string.split()[1]) + # The spec says that the version string should start with "Version ". But not + # all fonts do. So, we return the complete string if it doesn't start with + # the prefix, else we return the rest of the string after sanitizing it. + prefix = 'Version ' + if string.startswith(prefix): + string = string[len(prefix):] + return sanitize(string) def sanitize(string): + """ Remove non-standard chars. """ return re.sub(r'[^\w-]+', '', string) if __name__ == '__main__': |