Skip to content

Commit

Permalink
font-patcher: Use WIN metrics in all conflicting cases
Browse files Browse the repository at this point in the history
[why]
When HHEA and (depending on USE-TYPO-METRIC) TYPO or WIN are not
consistent it is unclear which metric we should trust.

In #1056 the complete font bounding box (i.e. yMin and yMax) has been
compared to the baseline to baseline distances, and in all these cases
the WIN values seem to be best (preserve the glyph bounding box).

    font-line report fontname.ttf | grep metrics:
    ttfdump -t head fontname.ttf | grep "yM(in|ax)"

[note]
Roboto will still be clipped?! There seem to be ridiculously high glyphs
in there. Did not check which.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
  • Loading branch information
Finii committed Jan 22, 2023
1 parent 04c682f commit 6210087
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions font-patcher
Original file line number Diff line number Diff line change
Expand Up @@ -946,21 +946,11 @@ class font_patcher:
our_btb = typo_btb if use_typo else win_btb
if our_btb == hhea_btb:
metrics = 1 if use_typo else 2 # conforming font
elif abs(our_btb - hhea_btb) / our_btb < 0.03:
print("{}: Font vertical metrics slightly off ({:.1f}%)".format(projectName, (our_btb - hhea_btb) / our_btb * 100.0))
metrics = 1 if use_typo else 2
else:
# Try the other metric
our_btb = typo_btb if not use_typo else win_btb
if our_btb == hhea_btb:
print("{}: Font vertical metrics probably wrong USE TYPO METRICS, assume opposite (i.e. {})".format(projectName, not use_typo))
use_typo = not use_typo
self.sourceFont.os2_use_typo_metrics = 1 if use_typo else 0
metrics = 1 if use_typo else 2
else:
print("{}: WARNING Font vertical metrics inconsistent ({:.1f}%), using HHEA".format(projectName, (our_btb - hhea_btb) / our_btb * 100.0))
our_btb = hhea_btb
metrics = 0
# We trust the WIN metric more, see experiments in #1056
print("{}: WARNING Font vertical metrics inconsistent (HHEA {} / TYPO {} / WIN {}), using WIN".format(projectName, hhea_btb, typo_btb, win_btb))
our_btb = win_btb
metrics = 1

# print("FINI hhea {} typo {} win {} use {} {} {}".format(hhea_btb, typo_btb, win_btb, use_typo, our_btb != hhea_btb, self.sourceFont.fontname))

Expand Down

0 comments on commit 6210087

Please sign in to comment.