Skip to content

Commit

Permalink
Merge pull request #187 from harfbuzz/hb-ot-layout
Browse files Browse the repository at this point in the history
Bind more hb-ot-layout APIs
  • Loading branch information
khaledhosny authored Feb 3, 2024
2 parents adbbf61 + 2c0b367 commit f3e9145
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
19 changes: 19 additions & 0 deletions src/uharfbuzz/_harfbuzz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/uharfbuzz/charfbuzz.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
28 changes: 23 additions & 5 deletions tests/test_uharfbuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"]
Expand All @@ -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):
Expand Down

0 comments on commit f3e9145

Please sign in to comment.