Skip to content

Commit 8a994a8

Browse files
emmamarichalfelipesanches
authored andcommitted
Reenabled and fixed implementation of centered caps check
"If possible, the uppercase glyphs should be vertically centered in the em box." 'caps_vertically_centered' On the Universal Profile. (issues fonttools#4139 and fonttools#4274)
1 parent 9c41991 commit 8a994a8

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
Below are the noteworthy changes from each release.
22
A more detailed list of changes is available in the corresponding milestones for each release in the Github issue tracker (https://github.com/googlefonts/fontbakery/milestones?state=closed).
33

4-
## Upcoming release: 0.13.0a2 (2024-Oct-??)
4+
## Upcoming release: 0.13.0a2 (2024-Oct-11)
55
### Migration of checks
66
#### Moved from OpenType to Universal profile
77
- **[name/no_copyright_on_description]**: Adding copyright information to the description name entry is bad practice but is not a breach of specification. (issue #4857)
88
- **[name/italic_names]**: This check uses the filename to determine whether the font should have various italic bits set. File naming is a matter for the OpenType specification. (issue #4858)
99

1010
### Changes to existing checks
11+
#### On the Universal Profile
12+
- **[caps_vertically_centered]:** Reenabled and corrected it. If possible, the uppercase glyphs should be vertically centered in the em box. (issues #4139 and #4274)
13+
1114
#### On the Google Fonts profile
1215
- **[googlefonts/article/images]:** Missing image files are now reported at **FATAL** level. (issue #4848)
1316

Lib/fontbakery/checks/some_other_checks.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from fontbakery.prelude import (
55
check,
6-
disable,
76
Message,
87
PASS,
98
FAIL,
@@ -92,7 +91,6 @@ def check_family_single_directory(fonts):
9291
)
9392

9493

95-
@disable
9694
@check(
9795
id="caps_vertically_centered",
9896
rationale="""
@@ -111,15 +109,11 @@ def check_family_single_directory(fonts):
111109
def check_caps_vertically_centered(ttFont):
112110
"""Check if uppercase glyphs are vertically centered."""
113111

114-
# This check modifies the font file with `.draw(pen)`
115-
# so here we'll work with a copy of the object so that we
116-
# do not affect other checks:
117112
from copy import deepcopy
113+
from fontTools.pens.boundsPen import BoundsPen
118114

119115
ttFont_copy = deepcopy(ttFont)
120116

121-
from fontTools.pens.boundsPen import BoundsPen
122-
123117
SOME_UPPERCASE_GLYPHS = ["A", "B", "C", "D", "E", "H", "I", "M", "O", "S", "T", "X"]
124118
glyphSet = ttFont_copy.getGlyphSet()
125119

@@ -128,26 +122,31 @@ def check_caps_vertically_centered(ttFont):
128122
yield SKIP, Message(
129123
"lacks-ascii",
130124
"The implementation of this check relies on a few samples"
131-
" of uppercase latin characteres that are not available in this font.",
125+
" of uppercase latin characters that are not available in this font.",
132126
)
133127
return
134128

135129
highest_point_list = []
130+
lowest_point_list = []
136131
for glyphName in SOME_UPPERCASE_GLYPHS:
137132
pen = BoundsPen(glyphSet)
138133
glyphSet[glyphName].draw(pen)
139-
highest_point = pen.bounds[3]
134+
_, lowest_point, _, highest_point = pen.bounds
140135
highest_point_list.append(highest_point)
136+
lowest_point_list.append(lowest_point)
141137

142138
upm = ttFont_copy["head"].unitsPerEm
143-
error_margin = upm * 0.05
139+
line_spacing_factor = 1.20
140+
error_margin = (line_spacing_factor * upm) * 0.18
144141
average_cap_height = sum(highest_point_list) / len(highest_point_list)
145-
descender = ttFont_copy["hhea"].descent
146-
top_margin = upm - average_cap_height
147-
difference = abs(top_margin - abs(descender))
148-
vertically_centered = difference <= error_margin
142+
average_descender = sum(lowest_point_list) / len(lowest_point_list)
143+
144+
top_margin = ttFont["hhea"].ascent - average_cap_height
145+
bottom_margin = abs(ttFont["hhea"].descent) + average_descender
146+
147+
difference = abs(top_margin - bottom_margin)
149148

150-
if not vertically_centered:
149+
if difference > error_margin:
151150
yield WARN, Message(
152151
"vertical-metrics-not-centered",
153152
"Uppercase glyphs are not vertically centered in the em box.",

Lib/fontbakery/profiles/typenetwork.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"googlefonts/negative_advance_width",
3434
"googlefonts/STAT/axis_order",
3535
#
36-
"caps_vertically_centered", # Disabled: issue #4274
36+
"caps_vertically_centered",
3737
"case_mapping",
3838
"cmap/format_12",
3939
"cjk_not_enough_glyphs",

Lib/fontbakery/profiles/universal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"alt_caron",
2525
"arabic_high_hamza",
2626
"arabic_spacing_symbols",
27-
# "caps_vertically_centered", # Disabled: issue #4274
27+
"caps_vertically_centered",
2828
"case_mapping",
2929
"cjk_chws_feature",
3030
"cjk_not_enough_glyphs",

tests/test_checks_universal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ def test_check_alt_caron():
12841284
assert_PASS(check(ttFont))
12851285

12861286

1287-
def DISABLED_test_check_caps_vertically_centered():
1287+
def test_check_caps_vertically_centered():
12881288
"""Check if uppercase glyphs are vertically centered."""
12891289

12901290
check = CheckTester("caps_vertically_centered")

0 commit comments

Comments
 (0)