From c8e6eff9b26e430aa406cf7c6e05e5b8d23b7e32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Fri, 6 Dec 2024 03:34:17 -0300 Subject: [PATCH] Ligature_carets (sync with fontspector) (issue #4865 / https://github.com/simoncozens/fontspector/commit/907d86521eb790c234ca8b471753549c400fdfad) --- Lib/fontbakery/checks/ligature_carets.py | 38 ++++++------------------ tests/test_checks_ligature_carets.py | 24 +++------------ 2 files changed, 13 insertions(+), 49 deletions(-) diff --git a/Lib/fontbakery/checks/ligature_carets.py b/Lib/fontbakery/checks/ligature_carets.py index ded26ece6c..ed39bc5d0c 100644 --- a/Lib/fontbakery/checks/ligature_carets.py +++ b/Lib/fontbakery/checks/ligature_carets.py @@ -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) @@ -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 @@ -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: @@ -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", ) diff --git a/tests/test_checks_ligature_carets.py b/tests/test_checks_ligature_carets.py index 6ed0578c22..591a6f3771 100644 --- a/tests/test_checks_ligature_carets.py +++ b/tests/test_checks_ligature_carets.py @@ -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") @@ -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")) @@ -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")