port check 065 and refactor 063: split out common condition
(issue
@@ -2194,25 +2194,26 @@ def check_GASP_table_is_correctly_set(ttFont):
" Try exporting the font with autohinting enabled.")
+@register_condition
+@condition
+def has_kerning_info(ttFont):
+ if not "GPOS" in ttFont:
+ return False
+ for lookup in ttFont["GPOS"].table.LookupList.Lookup:
+ if lookup.LookupType == 2: # type 2 = Pair Adjustment
+ return True
+ elif lookup.LookupType == 9:
+ if lookup.SubTable[0].ExtensionLookupType == 2:
+ return True
+
+
@register_test
@test(
id='com.google.fonts/test/063'
)
def check_GPOS_table_has_kerning_info(ttFont):
"""Does GPOS table have kerning information?"""
- if "GPOS" not in ttFont:
- yield FAIL, "Font is missing a \"GPOS\" table."
- else:
- has_kerning_info = False
- for lookup in ttFont["GPOS"].table.LookupList.Lookup:
- if lookup.LookupType == 2: # type 2 = Pair Adjustment
- has_kerning_info = True
- break # avoid reading all kerning info
- elif lookup.LookupType == 9:
- if lookup.SubTable[0].ExtensionLookupType == 2:
- has_kerning_info = True
- break
- if not has_kerning_info:
+ if not has_kerning_info(ttFont):
yield WARN, "GPOS table lacks kerning information."
else:
yield PASS, "GPOS table has got kerning information."
@@ -2272,6 +2273,50 @@ def check_all_ligatures_have_corresponding_caret_positions(ttFont, ligatures):
yield PASS, "Looks good!"
+@register_test
+@test(
+ id='com.google.fonts/test/065'
+ , conditions=['ligatures', 'has_kerning_info']
+)
+
+def check_nonligated_sequences_kerning_info(ttFont, ligatures, has_kerning_info):
+ """Is there kerning info for non-ligated sequences?
+
+ Fonts with ligatures should have kerning on the corresponding
+ non-ligated sequences for text where ligatures are not used.
+ """
+ remaining = ligatures
+ def look_for_nonligated_kern_info(table):
+ for pairpos in table.SubTable:
+ for i, glyph in enumerate(pairpos.Coverage.glyphs):
+ if glyph in ligatures.keys():
+ for pairvalue in pairpos.PairSet[i].PairValueRecord:
+ if pairvalue.SecondGlyph in ligatures[glyph]:
+ del remaining[glyph]
+
+ for lookup in ttFont["GPOS"].table.LookupList.Lookup:
+ if lookup.LookupType == 2: # type 2 = Pair Adjustment
+ look_for_nonligated_kern_info(lookup)
+ # elif lookup.LookupType == 9:
+ # if lookup.SubTable[0].ExtensionLookupType == 2:
+ # look_for_nonligated_kern_info(lookup.SubTable[0])
+
+ def ligatures_str(ligs):
+ result = []
+ for first in ligs:
+ result.extend(["{}_{}".format(first, second)
+ for second in ligs[first]])
+ return result
+
+ if remaining != {}:
+ yield FAIL, ("GPOS table lacks kerning info for the following"
+ " non-ligated sequences: "
+ "{}").format(ligatures_str(remaining))
+ else:
+ yield PASS, ("GPOS table provides kerning info for "
+ "all non-ligated sequences.")
+
+
@register_condition
@condition
def seems_monospaced(monospace_stats):
