From 48d184f22597d6b9a4cdb07b3f74dca93e798850 Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Wed, 7 Oct 2026 21:53:14 +0000 Subject: [PATCH] fix(compare): match fonts whose family has the technology suffix IDML adds " (OTF)", " (TT)" or " (T1)" to some family names depending on the exporting computer. compare.py removed it from family names but not from Font Self keys and Font Name, so each such font counted as missing and the converter's font as extra. The suffix is now removed from the family part of both. Trustworthy pairs: extra Font values 17,889 -> 5,146 (-12,743); the same fonts now count as reproduced. --- docs/measurement.md | 6 ++++++ tools/compare.py | 23 ++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/measurement.md b/docs/measurement.md index a26c588..d57f38a 100644 --- a/docs/measurement.md +++ b/docs/measurement.md @@ -190,6 +190,12 @@ exporting computer: and not in others, and the strings occur in no INDD file). Family names (`FontFamily` `Name`, `Font` `FontFamily`, `AppliedFont`, `BulletsFont`) are compared with that suffix removed from both values. + A `Font` element is matched by its `Self`, which contains the family + name (`…FontnMinion Pro (OTF) Regular`), and its `Name` starts with + it: the suffix is removed from the family name in both before the + fonts are matched and compared. Otherwise each such font counted as + missing and its counterpart in the output as extra (12,743 extra + values in the trustworthy pairs before this rule). A value enters this list only with a reason of this kind. Values that are hard to decode, or that the converter does not write yet, stay in the diff --git a/tools/compare.py b/tools/compare.py index 93476b8..bcd23bb 100644 --- a/tools/compare.py +++ b/tools/compare.py @@ -246,6 +246,8 @@ def load(path): for el in root.iter(): s = el.get("Self") if s is not None: + if el.tag == "Font": + s = font_self(el, s) elements.setdefault((el.tag, s), el) # Children without Self (TextFramePreference, ...) are # compared as "/" of the parent. @@ -348,15 +350,29 @@ RELINKED = re.compile(r"LinkResource.*|LinkImport.*") FONT_SUFFIX = re.compile(r" \((OTF|TT|T1)\)$") -def font_name(tag, key, v): +def font_name(tag, key, v, family=None): """A value with the font technology suffix removed if it names a font - family: FontFamily Name, Font FontFamily, AppliedFont and BulletsFont.""" + family: FontFamily Name, Font FontFamily, AppliedFont and BulletsFont. + A Font's Name starts with its family (passed as family).""" if (tag, key) in (("FontFamily", "Name"), ("Font", "FontFamily")) or \ key.endswith(("P.AppliedFont", "P.BulletsFont")): return FONT_SUFFIX.sub("", v) + if (tag, key) == ("Font", "Name") and family and v.startswith(family): + return FONT_SUFFIX.sub("", family) + v[len(family):] return v +def font_self(el, s): + """A Font's Self with the technology suffix removed from the family + name it contains, so that fonts match whether or not the exporting + computer added the suffix.""" + family = el.get("FontFamily") or "" + base = FONT_SUFFIX.sub("", family) + if base != family: + return s.replace("Fontn" + family, "Fontn" + base, 1) + return s + + @functools.cache def excluded(tag, key): return any(k == key and fnmatch.fnmatchcase(tag, t) for t, k, _ in EXCLUDED) @@ -550,7 +566,8 @@ def value_coverage(p, ref, ours): o = mine.get(k) if o is None: missing[key] += 1 - elif norm(font_name(tag, k, o)) != norm(font_name(tag, k, v)): + elif norm(font_name(tag, k, o, mine.get("FontFamily"))) != \ + norm(font_name(tag, k, v, theirs.get("FontFamily"))): wrong[key] += 1 for k in mine.keys() - theirs.keys(): extra[(tag, k)] += 1