Skip to content

Instantly share code, notes, and snippets.

@madig
Created June 11, 2019 12:57
Show Gist options
  • Save madig/248e3090de0f6c77001dee266181e59b to your computer and use it in GitHub Desktop.
Save madig/248e3090de0f6c77001dee266181e59b to your computer and use it in GitHub Desktop.
"""Find GDEF variation tables assigned to class * to class 0 kerning, which should
never exist."""
import argparse
import logging
from pathlib import Path
import fontTools.ttLib
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
parser = argparse.ArgumentParser()
parser.add_argument("fonts", nargs="+", type=Path)
args = parser.parse_args()
for p in args.fonts:
logging.info(p)
font = fontTools.ttLib.TTFont(p)
if not "GPOS" in font:
logging.info(f"No GPOS in {p}, skipping.")
continue
class_kerning_tables = [
t
for l in font["GPOS"].table.LookupList.Lookup
for t in l.SubTable
if t.Format == 2
]
if not class_kerning_tables:
logging.info(f"No class kerning in {p}, skipping.")
continue
for class_kerning_table in class_kerning_tables:
for class1_index, class1_record in enumerate(class_kerning_table.Class1Record):
class2_zero = class1_record.Class2Record[0]
# A XAdvDevice table in class1_record.Class2Record[0] points to a GDEF
# variation table that should not exist for a class 0.
if vars(class2_zero.Value1).get("XAdvDevice", None) is not None:
class_glyphs = ", ".join(
sorted(
k
for k, v in class_kerning_table.ClassDef1.classDefs.items()
if v == class1_index
)
)
logging.warning(
f"Ghost kerning against class 0: class {class1_index} ({class_glyphs})"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment