diff options
author | Roozbeh Pournader <roozbeh@google.com> | 2014-08-01 12:44:04 -0700 |
---|---|---|
committer | James Godfrey-Kittle <jamesgk@google.com> | 2015-04-16 12:16:21 -0700 |
commit | 7237600eb825bafbd37b7b751540ad8ac3110a4a (patch) | |
tree | bbb58216d7f700c75e395765d5c85260961235c9 /scripts/touchup_for_android.py | |
parent | 308edc3450450342faf1d196d9e29c694e7b3e67 (diff) |
Fix ccmp rules that used spacing marks instead of non-spacing ones.
Fixes https://b.corp.google.com/issue?id=16727859.
Diffstat (limited to 'scripts/touchup_for_android.py')
-rwxr-xr-x | scripts/touchup_for_android.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/touchup_for_android.py b/scripts/touchup_for_android.py index ffed31a..1dac756 100755 --- a/scripts/touchup_for_android.py +++ b/scripts/touchup_for_android.py @@ -8,6 +8,7 @@ import sys from fontTools import ttLib from nototools import font_data +from nototools import unicode_data def drop_lookup(table, lookup_number): @@ -44,6 +45,56 @@ def fix_digit_widths(font): hmtx_table[digit][0] = most_common_width +_MAP_SPACING_TO_COMBINING = { + 'acute': 'acutecomb', + 'breve': 'brevenosp', + 'caron': 'uni030C', + 'cedilla': 'cedillanosp', + 'circumflex': 'circumflexnosp', + 'dieresis': 'dieresisnosp', + 'dotaccent': 'dotnosp', + 'grave': 'gravecomb', + 'hungarumlaut': 'acutedblnosp', + 'macron': 'macroncomb', + 'ogonek': 'ogoneknosp', + 'tilde': 'tildecomb', + 'ring': 'ringnosp', + 'tonos': 'acutecomb', + 'uni02F3': 'ringsubnosp', +} + +def fix_ccmp_lookup(font): + """Fixes the broken ccmp lookup.""" + cmap = font_data.get_cmap(font) + reverse_cmap = {name: code for (code, name) in cmap.items()} + + # Where we know the bad 'ccmp' is + ccmp_lookup = font['GSUB'].table.LookupList.Lookup[2] + assert ccmp_lookup.LookupType == 4 + assert ccmp_lookup.SubTableCount == 1 + ligatures = ccmp_lookup.SubTable[0].ligatures + for first_char, ligtable in ligatures.iteritems(): + ligatures_to_delete = [] + for index, ligature in enumerate(ligtable): + assert len(ligature.Component) == 1 + component = ligature.Component[0] + if (component.endswith('comb') + or component in ['commaaccent', + 'commaaccentrotate', + 'ringacute']): + continue + if first_char == 'a' and component == 'uni02BE': + ligatures_to_delete.append(index) + continue + char = reverse_cmap[component] + general_category = unicode_data.category(char) + if general_category != 'Mn': # not a combining mark + ligature.Component[0] = _MAP_SPACING_TO_COMBINING[component] + ligatures[first_char] = [ + ligature for (index, ligature) in enumerate(ligtable) + if index not in ligatures_to_delete] + + def apply_temporary_fixes(font): """Apply some temporary fixes.""" @@ -63,6 +114,9 @@ def apply_temporary_fixes(font): # Drop the lookup forming the ff ligature drop_lookup(font['GSUB'], 5) + # Correct the ccmp lookup to use combining marks instead of spacing ones + fix_ccmp_lookup(font) + # Fix the digit widths fix_digit_widths(font) |