Skip to content

Commit

Permalink
Bind hb_face_reference_table APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
mcratt authored and khaledhosny committed Dec 19, 2024
1 parent b93ba76 commit 017b259
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/uharfbuzz/_harfbuzz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,14 @@ cdef class Face:
raise MemoryError()
return Blob.from_ptr(blob)

def reference_table(self, tag: str) -> Blob:
cdef bytes packed = tag.encode()
cdef hb_tag_t hb_tag = hb_tag_from_string(<char*>packed, -1)
cdef hb_blob_t* blob = hb_face_reference_table(self._hb_face, hb_tag)
if blob is NULL:
raise MemoryError()
return Blob.from_ptr(blob)

@property
def table_tags(self) -> List[str]:
cdef unsigned int tag_count = STATIC_ARRAY_SIZE
Expand Down
1 change: 1 addition & 0 deletions src/uharfbuzz/charfbuzz.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ cdef extern from "hb.h":
hb_bool_t replace)
void hb_face_destroy(hb_face_t* face)
hb_blob_t* hb_face_reference_blob(hb_face_t *face)
hb_blob_t* hb_face_reference_table(hb_face_t *face,hb_tag_t tag)
hb_face_t* hb_face_reference(hb_face_t *face)
hb_face_t* hb_face_get_empty()
unsigned int hb_face_get_table_tags(
Expand Down
8 changes: 8 additions & 0 deletions tests/test_uharfbuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,14 @@ def test_list_names_with_user_names(self, mutatorsans):
"MutatorMathTest-Medium_Narrow_I",
]

def test_reference_table(self, blankfont):
face = blankfont.face
if "OS/2" in face.table_tags:
blob = face.reference_table("OS/2")
assert len(blob.data) == 96
if "head" in face.table_tags:
blob = face.reference_table("head")
assert len(blob.data) == 54

class TestFont:
def test_get_glyph_extents(self, opensans):
Expand Down

0 comments on commit 017b259

Please sign in to comment.