diff --git a/src/uharfbuzz/_harfbuzz.pyx b/src/uharfbuzz/_harfbuzz.pyx index 0f6aca7..1ffcd26 100644 --- a/src/uharfbuzz/_harfbuzz.pyx +++ b/src/uharfbuzz/_harfbuzz.pyx @@ -1335,6 +1335,25 @@ def ot_layout_get_baseline(font: Font, else: return None +def ot_layout_has_glyph_classes(face: Face) -> bool: + return hb_ot_layout_has_glyph_classes(face._hb_face) + +def ot_layout_has_positioning(face: Face) -> bool: + return hb_ot_layout_has_positioning(face._hb_face) + +def ot_layout_has_substitution(face: Face) -> bool: + return hb_ot_layout_has_substitution(face._hb_face) + +class OTLayoutGlyphClass(IntEnum): + UNCLASSIFIED = HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED + BASE_GLYPH = HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH + LIGATURE = HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE + MARK = HB_OT_LAYOUT_GLYPH_CLASS_MARK + COMPONENT = HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT + +def ot_layout_get_glyph_class(face: Face, glyph: int) -> OTLayoutGlyphClass: + return OTLayoutGlyphClass(hb_ot_layout_get_glyph_class(face._hb_face, glyph)) + def ot_color_has_palettes(face: Face) -> bool: return hb_ot_color_has_palettes(face._hb_face) diff --git a/src/uharfbuzz/charfbuzz.pxd b/src/uharfbuzz/charfbuzz.pxd index d7a7c1c..90e96d7 100644 --- a/src/uharfbuzz/charfbuzz.pxd +++ b/src/uharfbuzz/charfbuzz.pxd @@ -939,6 +939,18 @@ cdef extern from "hb-ot.h": hb_tag_t language_tag, hb_position_t* coord) # out + hb_bool_t hb_ot_layout_has_glyph_classes(hb_face_t *face) + hb_bool_t hb_ot_layout_has_positioning(hb_face_t *face) + hb_bool_t hb_ot_layout_has_substitution(hb_face_t *face) + + ctypedef enum hb_ot_layout_glyph_class_t: + HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED + HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH + HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE + HB_OT_LAYOUT_GLYPH_CLASS_MARK + HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT + hb_ot_layout_glyph_class_t hb_ot_layout_get_glyph_class(hb_face_t *face, hb_codepoint_t glyph) + # hb-ot-font.h void hb_ot_font_set_funcs(hb_font_t* font) diff --git a/tests/test_uharfbuzz.py b/tests/test_uharfbuzz.py index f023951..aedbf8a 100644 --- a/tests/test_uharfbuzz.py +++ b/tests/test_uharfbuzz.py @@ -957,7 +957,7 @@ def message(self, message): pass -class TestGetBaseline: +class TestOTLayout: # The test font contains a BASE table with some test values def test_ot_layout_get_baseline_invalid_tag(self, blankfont): with pytest.raises(ValueError): @@ -994,8 +994,6 @@ def test_ot_layout_get_baseline( ) assert value == expected_value - -class TestGetTags: def test_ot_layout_language_get_feature_tags(self, blankfont): tags = hb.ot_layout_language_get_feature_tags(blankfont.face, "GPOS") assert tags == ["kern"] @@ -1010,13 +1008,33 @@ def test_ot_layout_script_get_language_tags(self, blankfont): tags = hb.ot_layout_script_get_language_tags(blankfont.face, "GPOS", 0) assert tags == [] - -class TestGetAlternates: def test_ot_layout_lookup_get_glyph_alternates(self, blankfont): gid = blankfont.get_nominal_glyph(ord("c")) alternates = hb.ot_layout_lookup_get_glyph_alternates(blankfont.face, 1, gid) assert alternates == [1] + def test_ot_layout_has_glyph_classes(self, opensans): + assert hb.ot_layout_has_glyph_classes(opensans.face) + + def test_ot_layout_has_no_glyph_classes(self, blankfont): + assert hb.ot_layout_has_glyph_classes(blankfont.face) == False + + def test_ot_layout_get_glyph_class(self, opensans): + glyph_class = hb.ot_layout_get_glyph_class(opensans.face, 1) + assert glyph_class == hb.OTLayoutGlyphClass.BASE_GLYPH + + def test_ot_layout_has_positioning(self, opensans): + assert hb.ot_layout_has_positioning(opensans.face) + + def test_ot_layout_has_no_positioning(self, mathfont): + assert hb.ot_layout_has_positioning(mathfont.face) == False + + def test_ot_layout_has_substitution(self, opensans): + assert hb.ot_layout_has_substitution(opensans.face) + + def test_ot_layout_has_no_substitution(self, mathfont): + assert hb.ot_layout_has_substitution(mathfont.face) == False + class TestOTColor: def test_ot_color_has_palettes(self, colorv0font):