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

SKIP instead of ERROR if opentype/slant_direction's reference codepoint is not covered #4969

Merged
merged 3 commits into from
Jan 13, 2025
Merged
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
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")
Loading