-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check base characters have non-zero advance width. Added to the Universal profile Back-ported from FontSpector: simoncozens/fontspector@564e18c (issue #4906)
- Loading branch information
1 parent
56560fe
commit 8e073ab
Showing
10 changed files
with
70 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import unicodedata | ||
|
||
from fontbakery.prelude import check, Message, FAIL | ||
from fontbakery.utils import bullet_list, mark_glyphs | ||
|
||
|
||
def is_space(codepoint): | ||
return unicodedata.category(chr(codepoint)) in [ | ||
"Zs", # Space Separator | ||
"Zl", # Line Separator | ||
"Zp", # Paragraph Separator | ||
"Cf", # Format | ||
"Mn", # Nonspacing Mark | ||
"Cc", # Control | ||
] | ||
|
||
|
||
@check( | ||
id="base_has_width", | ||
rationale=""" | ||
Base characters should have non-zero advance width. | ||
""", | ||
proposal="https://github.com/fonttools/fontbakery/issues/4906", | ||
) | ||
def check_base_has_width(font, context): | ||
"""Check base characters have non-zero advance width.""" | ||
|
||
reversed_cmap = {v: k for k, v in font.ttFont.getBestCmap().items()} | ||
|
||
problems = [] | ||
for gid, metric in font.ttFont["hmtx"].metrics.items(): | ||
advance = metric[0] | ||
|
||
codepoint = reversed_cmap.get(gid) | ||
if codepoint == 0 or codepoint is None: | ||
continue | ||
|
||
if advance == 0 and not gid not in mark_glyphs(font.ttFont): | ||
if is_space(codepoint): | ||
continue | ||
|
||
problems.append(f"{gid} (U+{codepoint:04X})") | ||
|
||
if problems: | ||
problems = bullet_list(context, problems) | ||
yield FAIL, Message( | ||
"zero-width-bases", | ||
f"The following glyphs had zero advance width:\n{problems}", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
], | ||
"pending_review": [ | ||
"epar", | ||
"base_has_width", | ||
], | ||
"sections": { | ||
"Type Network": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters