Skip to content
Closed
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
17 changes: 16 additions & 1 deletion src/uharfbuzz/_harfbuzz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ from cpython.pycapsule cimport PyCapsule_GetPointer, PyCapsule_IsValid
from cpython.unicode cimport (
PyUnicode_1BYTE_DATA, PyUnicode_2BYTE_DATA, PyUnicode_4BYTE_DATA,
PyUnicode_1BYTE_KIND, PyUnicode_2BYTE_KIND, PyUnicode_4BYTE_KIND,
PyUnicode_KIND, PyUnicode_GET_LENGTH, PyUnicode_FromKindAndData
PyUnicode_KIND, PyUnicode_GET_LENGTH, PyUnicode_FromKindAndData,
PyUnicode_AsUTF8AndSize
)
from typing import Callable, Dict, List, Sequence, Tuple, Union, NamedTuple
from pathlib import Path
Expand Down Expand Up @@ -2955,6 +2956,20 @@ cdef class SubsetInput:
self._hb_input, face._hb_face, hb_tag, value
)

def override_name_table(self, name_id: OTNameIdPredefined | int, platform_id: int, encoding_id: int, language_id: int, name_str: str | None) -> bool:
cdef const char* c_name
cdef Py_ssize_t str_len
if name_str is None:
c_name = NULL
str_len = -1
else:
c_name = PyUnicode_AsUTF8AndSize(name_str, &str_len)
if c_name == NULL:
raise MemoryError()
return hb_subset_input_override_name_table(
self._hb_input, name_id, platform_id, encoding_id, language_id, c_name, str_len
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux distributions builds want to link to system HarfBuzz which is typically built without experimental APIs, so this call should be wrapped in HB_EXPERIMENTAL_API and raise a NotImplementedError otherwise.


@property
def unicode_set(self) -> Set:
return Set.from_ptr(hb_set_reference (hb_subset_input_unicode_set(self._hb_input)))
Expand Down
1 change: 1 addition & 0 deletions src/uharfbuzz/charfbuzz.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -1369,3 +1369,4 @@ cdef extern from "hb-subset.h":
hb_subset_plan_t* hb_subset_plan_reference(hb_subset_plan_t* plan)
hb_bool_t hb_subset_plan_set_user_data(hb_subset_plan_t* plan, hb_user_data_key_t* key, void* data, hb_destroy_func_t destroy, hb_bool_t replace)
void* hb_subset_plan_get_user_data(const hb_subset_plan_t* plan, hb_user_data_key_t* key)
hb_bool_t hb_subset_input_override_name_table(hb_subset_input_t* input, hb_ot_name_id_t name_id, unsigned platform_id, unsigned encoding_id, unsigned language_id, const char* name_str, int str_len)
23 changes: 23 additions & 0 deletions tests/test_uharfbuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,3 +1798,26 @@ def test_subset(blankfont):
def test_deprecated():
with pytest.deprecated_call():
hb.ot_color_glyph_get_layers(hb.Face(), 0)

def test_override_name_table(blankfont):
str1 = "Roboto Test"
str1_3 = "Roboto Test unicode platform"
str2 = "Bold"
str6 = "Roboto-Bold"
str12 = "Non ascii test Ü"
str16 = "Roboto-test-inserting"

inp = hb.SubsetInput()
assert inp.override_name_table(1, 1, 0, 0, str1)
assert inp.override_name_table(1, 3, 1, 0x409, str1_3)
assert inp.override_name_table(hb.OTNameIdPredefined.FULL_NAME, 3, 1, 0x409, str1_3)
assert inp.override_name_table(2, 1, 0, 0, str2[:4])
assert inp.override_name_table(6, 1, 0, 0, str6)
assert inp.override_name_table(12, 1, 0, 0, str12) == 0
assert inp.override_name_table(14, 1, 0, 0, None)
assert inp.override_name_table(16, 1, 0, 0, str16)

face = hb.subset(blankfont.face, inp)

assert face.get_name(1) == str1_3
assert face.get_name(hb.OTNameIdPredefined.FULL_NAME) == str1_3
Loading