Skip to content

Commit

Permalink
Bind hb_style_get_value APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
mcratt authored and khaledhosny committed Dec 3, 2024
1 parent 01bebae commit b93ba76
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/uharfbuzz/_harfbuzz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,13 @@ class OTMetricsTag(IntEnum):
UNDERLINE_SIZE = HB_OT_METRICS_TAG_UNDERLINE_SIZE
UNDERLINE_OFFSET = HB_OT_METRICS_TAG_UNDERLINE_OFFSET

class StyleTag(IntEnum):
ITALIC = HB_STYLE_TAG_ITALIC
OPTICAL_SIZE = HB_STYLE_TAG_OPTICAL_SIZE
SLANT_ANGLE = HB_STYLE_TAG_SLANT_ANGLE
SLANT_RATIO = HB_STYLE_TAG_SLANT_RATIO
WIDTH = HB_STYLE_TAG_WIDTH
WEIGHT = HB_STYLE_TAG_WEIGHT

cdef class Font:
cdef hb_font_t* _hb_font
Expand Down Expand Up @@ -1574,6 +1581,9 @@ cdef class Font:
else:
return None

# style
def get_style_value(self, tag: StyleTag) -> float:
return hb_style_get_value(self._hb_font, tag)

cdef struct _pen_methods:
void *moveTo
Expand Down
9 changes: 9 additions & 0 deletions src/uharfbuzz/charfbuzz.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,15 @@ cdef extern from "hb.h":
hb_bool_t hb_set_previous_range(const hb_set_t* set, hb_codepoint_t* first, hb_codepoint_t* last)
unsigned int hb_set_next_many(const hb_set_t* set, hb_codepoint_t codepoint, hb_codepoint_t* out, unsigned int size)

# hb-style.h
ctypedef enum hb_style_tag_t:
HB_STYLE_TAG_ITALIC
HB_STYLE_TAG_OPTICAL_SIZE
HB_STYLE_TAG_SLANT_ANGLE
HB_STYLE_TAG_SLANT_RATIO
HB_STYLE_TAG_WIDTH
HB_STYLE_TAG_WEIGHT
float hb_style_get_value(hb_font_t *font, hb_style_tag_t style_tag)

cdef extern from "hb-ot.h":
# hb-ot-layout.h
Expand Down
9 changes: 9 additions & 0 deletions tests/test_uharfbuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,15 @@ def test_get_layout_baseline(
value = blankfont.get_layout_baseline(baseline_tag, direction, script_tag, "")
assert value == expected_value

def test_get_style_value(
self, blankfont
):
assert blankfont.get_style_value(hb.StyleTag.ITALIC) == 0.0
assert blankfont.get_style_value(hb.StyleTag.OPTICAL_SIZE) == 12.0
assert blankfont.get_style_value(hb.StyleTag.SLANT_ANGLE) == 0.0
assert blankfont.get_style_value(hb.StyleTag.SLANT_RATIO) == -0.0
assert blankfont.get_style_value(hb.StyleTag.WIDTH) == 100.0
assert blankfont.get_style_value(hb.StyleTag.WEIGHT) == 400.0

class TestShape:
@pytest.mark.parametrize(
Expand Down

0 comments on commit b93ba76

Please sign in to comment.