Skip to content

Commit

Permalink
Merge pull request #8 from m4rc1e/set_variations
Browse files Browse the repository at this point in the history
Add hb_font_set_variations func
  • Loading branch information
anthrotype authored Nov 13, 2018
2 parents 13fcb05 + 01bd00c commit 3e8a1e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/uharfbuzz/_harfbuzz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,26 @@ cdef class Font:
x, y = value
hb_font_set_scale(self._hb_font, x, y)

def set_variations(self, variations: Dict[str, float]) -> None:
cdef unsigned int size
cdef hb_variation_t* hb_variations
cdef bytes packed
cdef hb_variation_t variation
size = len(variations)
hb_variations = <hb_variation_t*>malloc(size * sizeof(hb_variation_t))
if not hb_variations:
raise MemoryError()

try:
for i, (name, value) in enumerate(variations.items()):
packed = name.encode()
variation.tag = hb_tag_from_string(packed, -1)
variation.value = value
hb_variations[i] = variation
hb_font_set_variations(self._hb_font, hb_variations, size)
finally:
free(hb_variations)


cdef hb_position_t _glyph_h_advance_func(hb_font_t* font, void* font_data,
hb_codepoint_t glyph,
Expand Down
7 changes: 7 additions & 0 deletions src/uharfbuzz/charfbuzz.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ cdef extern from "hb.h":
hb_codepoint_t glyph,
char *name, unsigned int size,
void *user_data)
ctypedef struct hb_variation_t:
hb_tag_t tag
float value

hb_font_funcs_t* hb_font_funcs_create()
void hb_font_funcs_set_glyph_h_advance_func(
Expand All @@ -164,6 +167,10 @@ cdef extern from "hb.h":
void* font_data, hb_destroy_func_t destroy)
void hb_font_get_scale(hb_font_t* font, int* x_scale, int* y_scale)
void hb_font_set_scale(hb_font_t* font, int x_scale, int y_scale)
void hb_font_set_variations(
hb_font_t* font,
const hb_variation_t* variations,
unsigned int variations_length)
void hb_font_destroy(hb_font_t* font)

# hb-shape.h
Expand Down

0 comments on commit 3e8a1e2

Please sign in to comment.