Skip to content

Commit

Permalink
Ligature_carets (sync with fontspector)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipesanches committed Dec 6, 2024
1 parent f615b40 commit f5c5be1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 49 deletions.
38 changes: 9 additions & 29 deletions Lib/fontbakery/checks/ligature_carets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fontbakery.testable import Font
from fontbakery.prelude import check, condition, FAIL, WARN, Message
from fontbakery.prelude import check, condition, SKIP, WARN, Message
from fontbakery.utils import bullet_list


@condition(Font)
Expand All @@ -22,12 +23,11 @@ def ligature_glyphs(font):
all_ligature_glyphs.append(lig.LigGlyph)
return all_ligature_glyphs
except (AttributeError, IndexError):
return -1 # Indicate fontTools-related crash...
return [] # fontTools bug perhaps? (issue #1596)


@check(
id="ligature_carets",
conditions=["ligature_glyphs"],
rationale="""
All ligatures in a font must have corresponding caret (text cursor) positions
defined in the GDEF table, otherwhise, users may experience issues with
Expand All @@ -39,29 +39,10 @@ def ligature_glyphs(font):
""",
proposal="https://github.com/fonttools/fontbakery/issues/1225",
)
def check_ligature_carets(ttFont, ligature_glyphs):
def check_ligature_carets(config, ttFont, ligature_glyphs):
"""Are there caret positions declared for every ligature?"""
if ligature_glyphs == -1:
yield FAIL, Message(
"malformed",
(
"Failed to lookup ligatures."
" This font file seems to be malformed."
" For more info, read:"
" https://github.com/fonttools/fontbakery/issues/1596"
),
)
elif "GDEF" not in ttFont:
yield WARN, Message(
"GDEF-missing",
(
"GDEF table is missing, but it is mandatory"
" to declare it on fonts that provide ligature"
" glyphs because the caret (text cursor)"
" positioning for each ligature must be"
" provided in this table."
),
)
if len(ligature_glyphs) == 0:
yield SKIP, Message("no-ligatures", "No ligature glyphs found.")
else:
lig_caret_list = ttFont["GDEF"].table.LigCaretList
if lig_caret_list is None:
Expand All @@ -76,10 +57,9 @@ def check_ligature_carets(ttFont, ligature_glyphs):
" for ligature glyphs on its GDEF table.",
)
elif missing:
missing = "\n\t- ".join(sorted(missing))
missing = bullet_list(config, sorted(missing))
yield WARN, Message(
"incomplete-caret-pos-data",
f"This font lacks caret positioning"
f" values for these ligature glyphs:"
f"\n\t- {missing}\n\n ",
f"This font lacks caret positioning values for these ligature glyphs:\n"
f"{missing}\n\n",
)
24 changes: 4 additions & 20 deletions tests/test_checks_ligature_carets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
# assert_PASS, FIXME: We must also have PASS test-cases!
assert_results_contain,
TEST_FILE,
MockFont,
)
from fontbakery.status import FAIL, WARN, SKIP
from fontbakery.status import WARN, SKIP


@check_id("ligature_carets")
Expand All @@ -17,16 +16,7 @@ def test_check_ligature_carets(check):
# Our reference Mada Medium doesn't have a GSUB 'liga' feature, so it is skipped
# because of an unfulfilled condition.
ttFont = TTFont(TEST_FILE("mada/Mada-Medium.ttf"))
msg = assert_results_contain(check(ttFont), SKIP, "unfulfilled-conditions")
assert "Unfulfilled Conditions: ligature_glyphs" in msg

# Simulate an error coming from the 'ligature_glyphs' condition;
# this is to exercise the 'malformed' code path.
font = TEST_FILE("mada/Mada-Medium.ttf")
msg = assert_results_contain(
check(MockFont(file=font, ligature_glyphs=-1)), FAIL, "malformed"
)
assert "Failed to lookup ligatures. This font file seems to be malformed." in msg
msg = assert_results_contain(check(ttFont), SKIP, "no-ligatures")

# SourceSansPro Bold has ligatures and GDEF table, but lacks caret position data.
ttFont = TTFont(TEST_FILE("source-sans-pro/OTF/SourceSansPro-Bold.otf"))
Expand All @@ -36,11 +26,5 @@ def test_check_ligature_carets(check):
" for ligature glyphs on its GDEF table."
)

# Remove the GDEF table to exercise the 'GDEF-missing' code path.
del ttFont["GDEF"]
msg = assert_results_contain(check(ttFont), WARN, "GDEF-missing")
assert "GDEF table is missing, but it is mandatory" in msg

# TODO: test the following code-paths:
# - WARN "incomplete-caret-pos-data"
# - PASS (We currently lack a reference family that PASSes this check!)
# TODO:
# assert_results_contain(check(ttFont), WARN, "incomplete-caret-pos-data")

0 comments on commit f5c5be1

Please sign in to comment.