Skip to content

Commit

Permalink
Merge pull request #159 from harfbuzz/more-font
Browse files Browse the repository at this point in the history
Bind more font API
  • Loading branch information
khaledhosny authored Mar 12, 2023
2 parents ec68bb2 + d0414d3 commit 5316ba9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/uharfbuzz/_harfbuzz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,13 @@ cdef class Font:
else:
return None

def get_glyph_from_name(self, name: str):
cdef hb_codepoint_t gid
cdef bytes packed
packed = name.encode()
success = hb_font_get_glyph_from_name(self._hb_font, <char*>packed, len(packed), &gid)
return gid if success else None

def get_glyph_extents(self, gid: int):
cdef hb_glyph_extents_t extents
success = hb_font_get_glyph_extents(self._hb_font, gid, &extents)
Expand All @@ -691,6 +698,22 @@ cdef class Font:
else:
return None

def get_glyph_h_advance(self, gid: int):
return hb_font_get_glyph_h_advance(self._hb_font, gid)

def get_glyph_v_advance(self, gid: int):
return hb_font_get_glyph_v_advance(self._hb_font, gid)

def get_glyph_h_origin(self, gid: int):
cdef hb_position_t x, y
success = hb_font_get_glyph_h_origin(self._hb_font, gid, &x, &y)
return (x, y) if success else None

def get_glyph_v_origin(self, gid: int):
cdef hb_position_t x, y
success = hb_font_get_glyph_v_origin(self._hb_font, gid, &x, &y)
return (x, y) if success else None

def get_font_extents(self, direction: str):
cdef hb_font_extents_t extents
cdef hb_direction_t hb_direction
Expand All @@ -706,6 +729,11 @@ cdef class Font:
extents.line_gap
)

def get_variation_glyph(self, unicode: int, variation_selector: int):
cdef hb_codepoint_t gid
success = hb_font_get_variation_glyph(self._hb_font, unicode, variation_selector, &gid)
return gid if success else None

def get_nominal_glyph(self, unicode: int):
cdef hb_codepoint_t gid
success = hb_font_get_nominal_glyph(self._hb_font, unicode, &gid)
Expand Down Expand Up @@ -740,6 +768,13 @@ cdef class Font:
packed = name
return packed.decode()

def glyph_from_string(self, string: str):
cdef hb_codepoint_t gid
cdef bytes packed
packed = string.encode()
success = hb_font_glyph_from_string(self._hb_font, <char*>packed, len(packed), &gid)
return gid if success else None

def draw_glyph(self, gid: int, draw_funcs: DrawFuncs, draw_state: object = None):
cdef void *draw_state_p = <void *>draw_state
if PyCapsule_IsValid(draw_state, NULL):
Expand Down
31 changes: 31 additions & 0 deletions src/uharfbuzz/charfbuzz.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ cdef extern from "hb.h":
hb_codepoint_t glyph,
char* name,
unsigned int size)
hb_bool_t hb_font_get_glyph_from_name(
hb_font_t *font,
const char *name,
int len,
hb_codepoint_t *glyph)
hb_bool_t hb_font_get_glyph_extents(
hb_font_t* font,
hb_codepoint_t glyph,
Expand All @@ -354,10 +359,31 @@ cdef extern from "hb.h":
hb_direction_t direction, hb_font_extents_t *extents)
hb_bool_t hb_font_get_h_extents(hb_font_t *font, hb_font_extents_t *extents)
hb_bool_t hb_font_get_v_extents(hb_font_t *font, hb_font_extents_t *extents)
hb_position_t hb_font_get_glyph_h_advance(
hb_font_t *font,
hb_codepoint_t glyph)
hb_position_t hb_font_get_glyph_v_advance(
hb_font_t *font,
hb_codepoint_t glyph)
hb_bool_t hb_font_get_glyph_h_origin(
hb_font_t *font,
hb_codepoint_t glyph,
hb_position_t *x,
hb_position_t *y)
hb_bool_t hb_font_get_glyph_v_origin(
hb_font_t *font,
hb_codepoint_t glyph,
hb_position_t *x,
hb_position_t *y)
hb_bool_t hb_font_get_nominal_glyph(
hb_font_t *font,
hb_codepoint_t unicode,
hb_codepoint_t *glyph)
hb_bool_t hb_font_get_variation_glyph(
hb_font_t *font,
hb_codepoint_t unicode,
hb_codepoint_t variation_selector,
hb_codepoint_t *glyph)
const int * hb_font_get_var_coords_normalized(
hb_font_t *font,
unsigned int *length)
Expand All @@ -370,6 +396,11 @@ cdef extern from "hb.h":
hb_codepoint_t glyph,
char* name,
unsigned int size)
hb_bool_t hb_font_glyph_from_string(
hb_font_t *font,
const char *s,
int len,
hb_codepoint_t *glyph)
void hb_font_destroy(hb_font_t* font)

ctypedef struct hb_draw_state_t:
Expand Down

0 comments on commit 5316ba9

Please sign in to comment.