diff --git a/src/uharfbuzz/_harfbuzz.pyx b/src/uharfbuzz/_harfbuzz.pyx index 6a9e494..de2b0f9 100644 --- a/src/uharfbuzz/_harfbuzz.pyx +++ b/src/uharfbuzz/_harfbuzz.pyx @@ -166,6 +166,18 @@ cdef class Buffer: hb_buffer_set_script( self._hb_buffer, hb_script_from_string(cstr, -1)) + def set_language_from_ot_tag(self, value: str): + cdef bytes packed = value.encode() + cdef char* cstr = packed + hb_buffer_set_language( + self._hb_buffer, hb_ot_tag_to_language(hb_tag_from_string(cstr, -1))) + + def set_script_from_ot_tag(self, value: str): + cdef bytes packed = value.encode() + cdef char* cstr = packed + hb_buffer_set_script( + self._hb_buffer, hb_ot_tag_to_script(hb_tag_from_string(cstr, -1))) + def add_codepoints(self, codepoints: List[int], item_offset: int = 0, item_length: int = -1) -> None: cdef unsigned int size = len(codepoints) diff --git a/src/uharfbuzz/charfbuzz.pxd b/src/uharfbuzz/charfbuzz.pxd index d59929a..75c59ea 100644 --- a/src/uharfbuzz/charfbuzz.pxd +++ b/src/uharfbuzz/charfbuzz.pxd @@ -39,6 +39,8 @@ cdef extern from "hb.h": hb_script_t hb_script_from_string(const char* str, int len) hb_tag_t hb_tag_from_string(const char* str, int len) void hb_tag_to_string(hb_tag_t tag, char* buf) + hb_language_t hb_ot_tag_to_language(hb_tag_t tag) + hb_script_t hb_ot_tag_to_script(hb_tag_t tag) ctypedef struct hb_user_data_key_t: pass diff --git a/tests/test_uharfbuzz.py b/tests/test_uharfbuzz.py index 97b6959..3943511 100644 --- a/tests/test_uharfbuzz.py +++ b/tests/test_uharfbuzz.py @@ -86,6 +86,12 @@ def test_guess_set_segment_properties(self): buf.language = "he-il" assert buf.language == "he-il" + buf.set_script_from_ot_tag("mym2") + assert buf.script == "Mymr" + + buf.set_language_from_ot_tag("BGR") + assert buf.language == "bg" + class TestShape: @pytest.mark.parametrize(