diff --git a/src/uharfbuzz/_harfbuzz.pyx b/src/uharfbuzz/_harfbuzz.pyx index cf4656f..14e539f 100644 --- a/src/uharfbuzz/_harfbuzz.pyx +++ b/src/uharfbuzz/_harfbuzz.pyx @@ -1,4 +1,5 @@ #cython: language_level=3 +cimport cython import os import warnings from enum import IntEnum, IntFlag @@ -648,6 +649,38 @@ cdef class Font: def synthetic_slant(self, value: float): hb_font_set_synthetic_slant(self._hb_font, value) + @property + def synthetic_bold(self) -> tuple[float, float, bool]: + cdef float x_embolden + cdef float y_embolden + cdef hb_bool_t in_place + hb_font_get_synthetic_bold(self._hb_font, &x_embolden, &y_embolden, &in_place) + return (x_embolden, y_embolden, bool(in_place)) + + @synthetic_bold.setter + def synthetic_bold(self, value: float|tuple[float]|tuple[float,float]|tuple[float,float,bool]): + cdef float x_embolden + cdef float y_embolden + cdef hb_bool_t in_place = False + if isinstance(value, tuple): + if len(value) == 1: + x_embolden = y_embolden = value[0] + elif len(value) == 2: + x_embolden, y_embolden = value + else: + x_embolden, y_embolden, in_place = value + else: + x_embolden = y_embolden = value + hb_font_set_synthetic_bold(self._hb_font, x_embolden, y_embolden, in_place) + + @property + def var_named_instance(self) -> int: + return hb_font_get_var_named_instance(self._hb_font) + + @var_named_instance.setter + def var_named_instance(self, value: int): + hb_font_set_var_named_instance(self._hb_font, value) + def set_variations(self, variations: Dict[str, float]) -> None: cdef unsigned int size cdef hb_variation_t* hb_variations @@ -668,6 +701,11 @@ cdef class Font: finally: free(hb_variations) + def set_variation(self, name: str, value: float) -> None: + packed = name.encode() + cdef hb_tag_t tag = hb_tag_from_string(packed, -1) + hb_font_set_variation(self._hb_font, tag, value) + def get_glyph_name(self, gid: int): cdef char name[64] cdef bytes packed @@ -761,6 +799,26 @@ cdef class Font: finally: free(coords_2dot14) + def get_var_coords_design(self): + cdef unsigned int length + cdef const float *coords + coords = hb_font_get_var_coords_design(self._hb_font, &length) + return [coords[i] for i in range(length)] + + def set_var_coords_design(self, coords): + cdef unsigned int length + cdef cython.float *c_coords + length = len(coords) + c_coords = malloc(length * sizeof(cython.float)) + if c_coords is NULL: + raise MemoryError() + try: + for i in range(length): + c_coords[i] = coords[i] + hb_font_set_var_coords_design(self._hb_font, c_coords, length) + finally: + free(c_coords) + def glyph_to_string(self, gid: int): cdef char name[64] cdef bytes packed diff --git a/src/uharfbuzz/charfbuzz.pxd b/src/uharfbuzz/charfbuzz.pxd index 235ed90..6af4627 100644 --- a/src/uharfbuzz/charfbuzz.pxd +++ b/src/uharfbuzz/charfbuzz.pxd @@ -335,12 +335,32 @@ cdef extern from "hb.h": void hb_font_set_ppem(hb_font_t* font, unsigned int x_ppem, unsigned int y_ppem) float hb_font_get_ptem(hb_font_t* font) void hb_font_set_ptem(hb_font_t* font, float ptem) + void hb_font_get_synthetic_bold (hb_font_t *font, + float *x_embolden, + float *y_embolden, + hb_bool_t *in_place) + void hb_font_set_synthetic_bold (hb_font_t *font, + float x_embolden, + float y_embolden, + hb_bool_t in_place) float hb_font_get_synthetic_slant (hb_font_t *font) void hb_font_set_synthetic_slant (hb_font_t *font, float slant) void hb_font_set_variations( hb_font_t* font, const hb_variation_t* variations, unsigned int variations_length) + void hb_font_set_variation( + hb_font_t *font, + hb_tag_t tag, + float value); + void hb_font_set_var_named_instance (hb_font_t *font, unsigned int instance_index) + unsigned int hb_font_get_var_named_instance (hb_font_t *font) + void hb_font_set_var_coords_design( + hb_font_t *font, + const float *coords, + unsigned int coords_length) + const float * hb_font_get_var_coords_design( + hb_font_t *font, unsigned int *length) hb_bool_t hb_font_get_glyph_name( hb_font_t* font, hb_codepoint_t glyph,