Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind hb_style_get_value APIs #222

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading