Skip to content

Commit

Permalink
SKIP instead of ERROR if opentype/slant_direction's reference codep…
Browse files Browse the repository at this point in the history
…oint is not covered

(PR #4969)
  • Loading branch information
Hoolean authored Jan 13, 2025
1 parent 5314a0a commit 7b75e1f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ A more detailed list of changes is available in the corresponding milestones for
## Upcoming release: 0.13.1 (2025-Jan-??)
- ...

### Changes to existing checks
### On the OpenType Profile
- **[opentype/slant_direction]:** SKIP instead of ERROR if a font does not contain 'H' (PR #4969)


## 0.13.0 (2025-Jan-10)
### Stable release notes
Expand Down
17 changes: 15 additions & 2 deletions Lib/fontbakery/checks/opentype/slant_direction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from fontbakery.prelude import check, condition, Message, FAIL, PASS
from fontbakery.prelude import Message, check, condition
from fontbakery.status import FAIL, PASS, SKIP
from fontbakery.testable import Font

# Reference codepoint to use to determine slant angle.
REFERENCE = "H"


@condition(Font)
def uharfbuzz_blob(font):
Expand Down Expand Up @@ -33,10 +37,19 @@ def check_slant_direction(ttFont, uharfbuzz_blob):
yield PASS, "Font has no slnt axis"
return

if ord(REFERENCE) not in ttFont.getBestCmap():
yield SKIP, Message(
"no-reference-glyph",
f"This check uses '{REFERENCE}' as a reference codepoint to "
"determine slant direction, but it is not present in this font, "
"and so the slant direction cannot be checked.",
)
return

hb_face = hb.Face(uharfbuzz_blob)
hb_font = hb.Font(hb_face)
buf = hb.Buffer()
buf.add_str("H")
buf.add_str(REFERENCE)
features = {"kern": True, "liga": True}
hb.shape(hb_font, buf, features)

Expand Down
19 changes: 18 additions & 1 deletion tests/test_checks_opentype_varfont_family_axis_ranges.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from fontTools.ttLib import TTFont

from conftest import check_id
from fontbakery.status import FAIL
from fontbakery.status import FAIL, SKIP
from fontbakery.checks.opentype.slant_direction import REFERENCE
from fontbakery.codetesting import (
assert_PASS,
assert_results_contain,
Expand Down Expand Up @@ -35,3 +36,19 @@ def test_check_slant_direction(check):

font = TEST_FILE("slant_direction/Cairo_wrong_slnt_axis.ttf")
assert_results_contain(check(font), FAIL, "positive-value-for-clockwise-lean")


@check_id("opentype/slant_direction")
def test_check_slant_direction_missing(check, tmp_path):
"""Check that the slant direction check handles the case where its reference
codepoint is not present."""

missing_codepoint = tmp_path / "MissingCodepoint.ttf"

# Remove the reference codepoint from a TTF that would otherwise PASS.
ttf = TTFont(TEST_FILE("slant_direction/Cairo_correct_slnt_axis.ttf"), lazy=False)
for subtable in ttf["cmap"].tables:
subtable.cmap.pop(ord(REFERENCE), None)
ttf.save(missing_codepoint)

assert_results_contain(check(str(missing_codepoint)), SKIP, "no-reference-glyph")

0 comments on commit 7b75e1f

Please sign in to comment.