Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emit WARNs when xAvgCharWidth value differs slightly from the expected value. #1627

Merged
merged 1 commit into from
Oct 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions Lib/fontbakery/specifications/googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,9 @@ def com_google_fonts_test_033(ttFont, monospace_stats):
)
def com_google_fonts_test_034(ttFont):
"""Check if OS/2 xAvgCharWidth is correct."""
current_value = ttFont['OS/2'].xAvgCharWidth
ACCEPTABLE_ERROR = 10 # This is how much we're willing to accept

if ttFont['OS/2'].version >= 3:
width_sum = 0
count = 0
Expand All @@ -1038,14 +1041,24 @@ def com_google_fonts_test_034(ttFont):
yield FAIL, "CRITICAL: Found no glyph width data!"
else:
expected_value = int(round(width_sum) / count)

if ttFont['OS/2'].xAvgCharWidth == expected_value:
if current_value == expected_value:
yield PASS, "OS/2 xAvgCharWidth is correct."
elif abs(current_value - expected_value) < ACCEPTABLE_ERROR:
yield WARN, ("OS/2 xAvgCharWidth is {} but should be"
" {} which corresponds to the"
" average of all glyph widths"
" in the font. These are similar values, which"
" may be a symptom of the slightly different"
" calculation of the xAvgCharWidth value in"
" font editors. There's further discussion on"
" this at https://github.com/googlefonts/fontbakery"
"/issues/1622").format(current_value,
expected_value)
else:
yield FAIL, ("OS/2 xAvgCharWidth is {} but should be "
"{} which corresponds to the "
"average of all glyph widths "
"in the font").format(ttFont['OS/2'].xAvgCharWidth,
"in the font").format(current_value,
expected_value)
else:
weightFactors = {'a': 64, 'b': 14, 'c': 27, 'd': 35,
Expand All @@ -1062,14 +1075,26 @@ def com_google_fonts_test_034(ttFont):
width_sum += (width*weightFactors[glyph_id])
expected_value = int(width_sum/1000.0 + 0.5) # round to closest int

if ttFont['OS/2'].xAvgCharWidth == expected_value:
if current_value == expected_value:
yield PASS, "OS/2 xAvgCharWidth value is correct."
elif abs(current_value - expected_value) < ACCEPTABLE_ERROR:
yield WARN, ("OS/2 xAvgCharWidth is {} but should be"
" {} which corresponds to the weighted"
" average of the widths of the latin"
" lowercase glyphs in the font."
" These are similar values, which"
" may be a symptom of the slightly different"
" calculation of the xAvgCharWidth value in"
" font editors. There's further discussion on"
" this at https://github.com/googlefonts/fontbakery"
"/issues/1622").format(current_value,
expected_value)
else:
yield FAIL, ("OS/2 xAvgCharWidth is {} but it should be "
"{} which corresponds to the weighted "
"average of the widths of the latin "
"lowercase glyphs in "
"the font").format(ttFont['OS/2'].xAvgCharWidth,
"the font").format(current_value,
expected_value)


Expand Down