Skip to content

Commit

Permalink
Add support to set script and language with OT tags instead of ISO an…
Browse files Browse the repository at this point in the history
…d BCP 47 (#35)

* Add support to set script and language with OT tags instead of ISO and BCP 47
  • Loading branch information
justvanrossum authored Mar 22, 2020
1 parent 07600b7 commit 79775b9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/uharfbuzz/_harfbuzz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/uharfbuzz/charfbuzz.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/test_uharfbuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 79775b9

Please sign in to comment.