Skip to content

Commit

Permalink
Eliminated some false positives
Browse files Browse the repository at this point in the history
in Ubuntu Sans related to digraphs.

com.google.fonts/check/tabular_kerning
On the Universal profile

(PR #4579)
  • Loading branch information
yanone authored and felipesanches committed Apr 15, 2024
1 parent 3df339e commit 2c151b8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ A more detailed list of changes is available in the corresponding milestones for
- ...


## Upcoming release: 0.12.1 (2024-Apr-15)
## 0.12.1 (2024-Apr-15)
- Temporarily pin glyphsets dependency to version v0.6.17 until a failing assert is addressed (issue #4639)
- **com.google.fonts/check/tabular_kerning** (Universal profile) will remain experimental for a bit longer (issue #4640)

### Changes to existing checks
#### On the Universal profile
- **[com.google.fonts/check/tabular_kerning]:** Eliminated some false positives in Ubuntu Sans related to digraphs. (PR #4579)


## 0.12.0 (2024-Apr-12)
- Restablish ordering of results on github markdown reports, showing the more severe results (such as FAILs) at the top. (issue #4600)
Expand Down
51 changes: 35 additions & 16 deletions Lib/fontbakery/checks/universal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2483,19 +2483,33 @@ def buffer_for_GIDs(GIDs, features):
hb.shape(vhb.hbfont, buf, features)
return buf

def kerning(ttFont, glyph_list):
def get_kerning(ttFont, glyph_list):
GID_list = [GID_for_glyph(ttFont, glyph) for glyph in glyph_list]
return buf_to_width(
width1 = buf_to_width(
buffer_for_GIDs(
GID_list,
{"kern": True},
)
) - buf_to_width(
)
width2 = buf_to_width(
buffer_for_GIDs(
GID_list,
{"kern": False},
)
)
return width1 - width2

def get_str_buffer(ttFont, glyph_list):
GID_list = [GID_for_glyph(ttFont, glyph) for glyph in glyph_list]
buffer = buffer_for_GIDs(GID_list, {})
string = vhb.serialize_buf(buffer)
return string

def digraph_kerning(ttFont, glyph_list, expected_kerning):
return (
len(get_str_buffer(ttFont, glyph_list).split("|")) > 1
and get_kerning(ttFont, glyph_list) == expected_kerning
)

all_glyphs = list(ttFont.getGlyphOrder())
tabular_glyphs = []
Expand Down Expand Up @@ -2545,19 +2559,24 @@ def kerning(ttFont, glyph_list):
(tabular_numerals, tabular_glyphs),
):
combinations = unique_combinations(sets[0], sets[1])
for a, b in combinations:
if kerning(ttFont, [a, b]) != 0:
yield FAIL, Message(
"has-tabular-kerning",
f"Kerning between {a} and {b} is not zero",
)
passed = False
if kerning(ttFont, [b, a]) != 0:
yield FAIL, Message(
"has-tabular-kerning",
f"Kerning between {b} and {a} is not zero",
)
passed = False
for x, y in combinations:
for a, b in ((x, y), (y, x)):
kerning = get_kerning(ttFont, [a, b])
if kerning != 0:
# Check if either a or b are digraphs that themselves
# have kerning when decomposed in ccmp
# that would throw off the reading, skip if it's identical
# to the kerning of the whole sequence
if digraph_kerning(ttFont, [a], kerning) or digraph_kerning(
ttFont, [b], kerning
):
pass
else:
yield FAIL, Message(
"has-tabular-kerning",
f"Kerning between {a} and {b} is {kerning}, should be 0",
)
passed = False

if passed:
yield PASS, "No kerning found for tabular glyphs"
Expand Down
Binary file not shown.
Binary file added data/test/ubuntusans/UbuntuSans[wdth,wght].ttf
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/checks/universal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,16 @@ def test_check_math_tabular_kerning():
font = TEST_FILE("hinting/Roboto-VF.ttf")
assert_results_contain(check(font), FAIL, "has-tabular-kerning")

# Ubuntu Sans has digraphs (like DZ) that get decomposed in ccmp
# and then have kerning between the individual D and Z, which
# used to throw off the check
font = TEST_FILE("ubuntusans/UbuntuSans[wdth,wght].ttf")
assert_PASS(check(font))
# This currently shows false positives:
# TODO: Fix this and turn this into an assert_PASS
font = TEST_FILE("ubuntusans/UbuntuSans-Italic[wdth,wght].ttf")
assert_results_contain(check(font), FAIL, "has-tabular-kerning")


def test_check_linegaps():
"""Checking Vertical Metric Linegaps."""
Expand Down

0 comments on commit 2c151b8

Please sign in to comment.