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

fix base_has_width and add test #5008

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 15 additions & 9 deletions Lib/fontbakery/checks/base_has_width.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@


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
]
return (
unicodedata.category(chr(codepoint))
in [
"Zs", # Space Separator
"Zl", # Line Separator
"Zp", # Paragraph Separator
"Cf", # Format
"Mn", # Nonspacing Mark
"Cc", # Control
]
or 0xE000 <= codepoint <= 0xF8FF
or 0xF0000 <= codepoint <= 0xFFFFD
or 0x100000 <= codepoint <= 0x10FFFD
)


@check(
Expand All @@ -36,7 +42,7 @@ def check_base_has_width(font, config):
if codepoint == 0 or codepoint is None:
continue

if advance == 0 and not gid not in mark_glyphs(font.ttFont):
if advance == 0 and gid not in mark_glyphs(font.ttFont):
if is_space(codepoint):
continue

Expand Down
48 changes: 48 additions & 0 deletions tests/test_checks_base_has_width.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from io import BytesIO
from fontTools.ttLib import TTFont

from conftest import check_id
from fontbakery.status import FAIL
from fontbakery.codetesting import (
assert_PASS,
assert_results_contain,
TEST_FILE,
)


def get_test_font():
import defcon
import ufo2ft

test_ufo = defcon.Font(TEST_FILE("test.ufo"))
# Add a PUA character that has no width
glyph = test_ufo.newGlyph("uniF176")
glyph.unicode = 0xF176
test_ttf = ufo2ft.compileTTF(test_ufo)

# Make the CheckTester class happy... :-P
stream = BytesIO()
test_ttf.save(stream)
stream.seek(0)
test_ttf = TTFont(stream)
test_ttf.reader.file.name = "in-memory-data.ttf"
return test_ttf


@check_id("base_has_width")
def test_check_base_has_width(check):
"""Do some base characters have zero width?"""

ttfont = get_test_font()

assert_PASS(check(ttfont), "if acute has width...")

ttfont["hmtx"].metrics["A"] = (0, 0)

message = assert_results_contain(
check(ttfont),
FAIL,
"zero-width-bases",
"following glyphs had zero advance width",
)
assert "U+0041" in message