From 87d5fc2990db064b4c8c63cb0c51d9ef1ad64454 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Wed, 18 Oct 2023 18:11:44 +0300 Subject: [PATCH] WIP: make tracing more usable --- src/uharfbuzz/_harfbuzz.pyx | 12 +++++++++++- src/uharfbuzz/charfbuzz.pxd | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/uharfbuzz/_harfbuzz.pyx b/src/uharfbuzz/_harfbuzz.pyx index 14e539f..ae10d20 100644 --- a/src/uharfbuzz/_harfbuzz.pyx +++ b/src/uharfbuzz/_harfbuzz.pyx @@ -32,7 +32,7 @@ cdef extern from "Python.h": cdef int msgcallback(hb_buffer_t *buffer, hb_font_t *font, const char* message, void* userdata) noexcept: - ret = (userdata)(message.decode('utf-8')) + ret = (userdata)(message.decode('utf-8'), Buffer.from_ptr(buffer)) if ret is None: return 1 return ret @@ -150,6 +150,15 @@ cdef class Buffer: cdef Buffer inst = cls() return inst + @staticmethod + cdef Buffer from_ptr(hb_buffer_t* hb_buffer): + """Create Buffer from a pointer.""" + + cdef Buffer wrapper = Buffer.__new__(Buffer) + wrapper._hb_buffer = hb_buffer_reference(hb_buffer) + wrapper._message_callback = None + return wrapper + def __len__(self) -> int: return hb_buffer_get_length(self._hb_buffer) @@ -1663,6 +1672,7 @@ class SubsetFlags(IntFlag): NOTDEF_OUTLINE = HB_SUBSET_FLAGS_NOTDEF_OUTLINE GLYPH_NAMES = HB_SUBSET_FLAGS_GLYPH_NAMES NO_PRUNE_UNICODE_RANGES = HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES + NO_LAYOUT_CLOSURE = HB_SUBSET_FLAGS_NO_LAYOUT_CLOSURE cdef class SubsetInput: diff --git a/src/uharfbuzz/charfbuzz.pxd b/src/uharfbuzz/charfbuzz.pxd index 6af4627..6b9d37a 100644 --- a/src/uharfbuzz/charfbuzz.pxd +++ b/src/uharfbuzz/charfbuzz.pxd @@ -185,6 +185,7 @@ cdef extern from "hb.h": hb_buffer_cluster_level_t cluster_level) hb_buffer_cluster_level_t hb_buffer_get_cluster_level(hb_buffer_t *buffer) void hb_buffer_destroy(hb_buffer_t* buffer) + hb_buffer_t* hb_buffer_reference(hb_buffer_t* buffer) ctypedef hb_bool_t (*hb_buffer_message_func_t) ( hb_buffer_t *buffer, hb_font_t *font, @@ -681,8 +682,7 @@ cdef extern from "hb-subset.h": HB_SUBSET_FLAGS_NOTDEF_OUTLINE HB_SUBSET_FLAGS_GLYPH_NAMES HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES - # Not supported yet: HB_SUBSET_FLAGS_PATCH_MODE - # Not supported yet: HB_SUBSET_FLAGS_OMIT_GLYF + HB_SUBSET_FLAGS_NO_LAYOUT_CLOSURE ctypedef enum hb_subset_sets_t: HB_SUBSET_SETS_GLYPH_INDEX HB_SUBSET_SETS_UNICODE