@@ -34,13 +34,25 @@ def get_font_report(fontpath):
34
34
ymin = tt ["head" ].yMin
35
35
units_per_em = tt ["head" ].unitsPerEm
36
36
37
+ # Bit flag checks
38
+ fsselection_bit6_mask = 1 << 6
39
+ fsselection_bit6_set = (tt ['OS/2' ].fsSelection & fsselection_bit6_mask ) != 0
40
+
37
41
# Calculated values
38
42
os2_typo_total_height = os2_typo_ascender + - (os2_typo_descender )
39
43
os2_win_total_height = os2_win_ascent + os2_win_descent
40
44
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
44
56
45
57
# The file path header
46
58
report = [" " ]
@@ -56,48 +68,57 @@ def get_font_report(fontpath):
56
68
report .append ("" )
57
69
# The vertical metrics strings
58
70
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 ))
70
82
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 ))
73
85
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 )
77
90
)
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 ))
80
92
report .append ("" )
93
+
81
94
report .append ("--- Delta Values ---" )
82
95
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 )
84
97
)
85
98
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 )
87
100
)
88
101
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 )
92
103
)
93
104
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
+ )
95
108
)
96
109
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 ("" )
97
117
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
+
101
122
102
123
return "\n " .join (report )
103
124
0 commit comments