Skip to content

Commit 484a83e

Browse files
committed
report: add baseline to baseline distance calcs across typo, hhea, win metrics & OS/2.fsSelection bit 7 flag setting
also adds report formatting updates
1 parent 47572fb commit 484a83e

File tree

1 file changed

+51
-30
lines changed

1 file changed

+51
-30
lines changed

lib/fontline/commands.py

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,25 @@ def get_font_report(fontpath):
3434
ymin = tt["head"].yMin
3535
units_per_em = tt["head"].unitsPerEm
3636

37+
# Bit flag checks
38+
fsselection_bit6_mask = 1 << 6
39+
fsselection_bit6_set = (tt['OS/2'].fsSelection & fsselection_bit6_mask ) != 0
40+
3741
# Calculated values
3842
os2_typo_total_height = os2_typo_ascender + -(os2_typo_descender)
3943
os2_win_total_height = os2_win_ascent + os2_win_descent
4044
hhea_total_height = hhea_ascent + -(hhea_descent)
41-
typo_to_upm = 1.0 * (os2_typo_linegap + os2_typo_total_height) / units_per_em
42-
winascdesc_to_upm = 1.0 * os2_win_total_height / units_per_em
43-
hheaascdesc_to_upm = 1.0 * hhea_total_height / units_per_em
45+
46+
hhea_btb_distance = hhea_total_height + hhea_linegap
47+
typo_btb_distance = os2_typo_total_height + os2_typo_linegap
48+
win_external_leading = hhea_linegap - ((os2_win_ascent + os2_win_descent) - (hhea_ascent - hhea_descent))
49+
if win_external_leading < 0:
50+
win_external_leading = 0
51+
win_btb_distance = os2_win_ascent + os2_win_descent + win_external_leading
52+
53+
typo_to_upm = 1.0 * typo_btb_distance / units_per_em
54+
winascdesc_to_upm = 1.0 * win_btb_distance / units_per_em
55+
hheaascdesc_to_upm = 1.0 * hhea_btb_distance / units_per_em
4456

4557
# The file path header
4658
report = [" "]
@@ -56,48 +68,57 @@ def get_font_report(fontpath):
5668
report.append("")
5769
# The vertical metrics strings
5870
report.append("--- Metrics ---")
59-
report.append("[head] Units per Em: \t{}".format(units_per_em))
60-
report.append("[head] yMax: \t\t{}".format(ymax))
61-
report.append("[head] yMin: \t\t{}".format(ymin))
62-
report.append("[OS/2] CapHeight: \t{}".format(os2_cap_height))
63-
report.append("[OS/2] xHeight: \t{}".format(os2_x_height))
64-
report.append("[OS/2] TypoAscender: \t{}".format(os2_typo_ascender))
65-
report.append("[OS/2] TypoDescender: \t{}".format(os2_typo_descender))
66-
report.append("[OS/2] WinAscent: \t{}".format(os2_win_ascent))
67-
report.append("[OS/2] WinDescent: \t{}".format(os2_win_descent))
68-
report.append("[hhea] Ascent: \t\t{}".format(hhea_ascent))
69-
report.append("[hhea] Descent: \t{}".format(hhea_descent))
71+
report.append("[head] Units per Em: {}".format(units_per_em))
72+
report.append("[head] yMax: {}".format(ymax))
73+
report.append("[head] yMin: {}".format(ymin))
74+
report.append("[OS/2] CapHeight: {}".format(os2_cap_height))
75+
report.append("[OS/2] xHeight: {}".format(os2_x_height))
76+
report.append("[OS/2] TypoAscender: {}".format(os2_typo_ascender))
77+
report.append("[OS/2] TypoDescender: {}".format(os2_typo_descender))
78+
report.append("[OS/2] WinAscent: {}".format(os2_win_ascent))
79+
report.append("[OS/2] WinDescent: {}".format(os2_win_descent))
80+
report.append("[hhea] Ascent: {}".format(hhea_ascent))
81+
report.append("[hhea] Descent: {}".format(hhea_descent))
7082
report.append("")
71-
report.append("[hhea] LineGap: \t{}".format(hhea_linegap))
72-
report.append("[OS/2] TypoLineGap: \t{}".format(os2_typo_linegap))
83+
report.append("[hhea] LineGap: {}".format(hhea_linegap))
84+
report.append("[OS/2] TypoLineGap: {}".format(os2_typo_linegap))
7385
report.append("")
74-
report.append("--- Height Calculations by Table Values ---")
75-
report.append(
76-
"[OS/2] TypoAscender to TypoDescender: \t{}".format(os2_typo_total_height)
86+
87+
report.append("--- Ascent to Descent Calculations ---")
88+
report.append("[hhea] Ascent to Descent: {}".format(hhea_total_height))
89+
report.append("[OS/2] TypoAscender to TypoDescender: {}".format(os2_typo_total_height)
7790
)
78-
report.append("[OS/2] WinAscent to WinDescent: \t{}".format(os2_win_total_height))
79-
report.append("[hhea] Ascent to Descent: \t\t{}".format(hhea_total_height))
91+
report.append("[OS/2] WinAscent to WinDescent: {}".format(os2_win_total_height))
8092
report.append("")
93+
8194
report.append("--- Delta Values ---")
8295
report.append(
83-
"WinAscent to TypoAscender: \t{}".format(os2_win_ascent - os2_typo_ascender)
96+
"[hhea] Ascent to [OS/2] TypoAscender: {}".format(hhea_ascent - os2_typo_ascender)
8497
)
8598
report.append(
86-
"Ascent to TypoAscender: \t{}".format(hhea_ascent - os2_typo_ascender)
99+
"[hhea] Descent : [OS/2] TypoDescender: {}".format(os2_typo_descender - hhea_descent)
87100
)
88101
report.append(
89-
"WinDescent to TypoDescender: \t{}".format(
90-
os2_win_descent - -(os2_typo_descender)
91-
)
102+
"[OS/2] WinAscent to [OS/2] TypoAscender: {}".format(os2_win_ascent - os2_typo_ascender)
92103
)
93104
report.append(
94-
"Descent to TypoDescender: \t{}".format(os2_typo_descender - hhea_descent)
105+
"[OS/2] WinDescent to [OS/2] TypoDescender: {}".format(
106+
os2_win_descent - -(os2_typo_descender)
107+
)
95108
)
96109
report.append("")
110+
report.append("--- Baseline to Baseline Distances ---")
111+
report.append("hhea metrics: {}".format(hhea_btb_distance))
112+
report.append("typo metrics: {}".format(typo_btb_distance))
113+
report.append("win metrics: {}".format(win_btb_distance))
114+
report.append("")
115+
report.append("[OS/2] fsSelection USE_TYPO_METRICS bit set: {}".format(fsselection_bit6_set))
116+
report.append("")
97117
report.append("--- Ratios ---")
98-
report.append("(Typo Asc + Desc + Linegap) / UPM: \t{0:.3g}".format(typo_to_upm))
99-
report.append("(winAsc + winDesc) / UPM: \t\t{0:.3g}".format(winascdesc_to_upm))
100-
report.append("(hhea Asc + Desc) / UPM: \t\t{0:.3g}".format(hheaascdesc_to_upm))
118+
report.append("hhea metrics / UPM: {0:.3g}".format(hheaascdesc_to_upm))
119+
report.append("typo metrics / UPM: {0:.3g}".format(typo_to_upm))
120+
report.append("win metrics / UPM: {0:.3g}".format(winascdesc_to_upm))
121+
101122

102123
return "\n".join(report)
103124

0 commit comments

Comments
 (0)