mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-19 08:40:46 +01:00
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.
This commit is contained in:
1 parent
14b36ee317
commit
48d184f225
2 files changed
+26
-3
No files matched your search
@@ -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
|
||||
|
||||
+20
-3
@@ -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 "<parent tag>/<child tag>" 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
|
||||
|
||||
Reference in new issue
Block a user