From 541174dc49fb3af50af085d57b773b31ddf57e40 Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Fri, 27 Mar 2020 18:16:13 +0100 Subject: [PATCH] Implement issue 36 (#38) * added post table format 2.0, so we have glyph names * implement a issue #36: adding font.get_glyph_name(gid) method * also expose hb_font_glyph_to_string() via font.glyph_to_string() --- src/uharfbuzz/_harfbuzz.pyx | 17 +++++++++++++++++ src/uharfbuzz/charfbuzz.pxd | 10 ++++++++++ tests/data/AdobeBlank.subset.ttf | Bin 1856 -> 1892 bytes tests/test_uharfbuzz.py | 26 ++++++++++++++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/src/uharfbuzz/_harfbuzz.pyx b/src/uharfbuzz/_harfbuzz.pyx index de2b0f9..33d796d 100644 --- a/src/uharfbuzz/_harfbuzz.pyx +++ b/src/uharfbuzz/_harfbuzz.pyx @@ -374,6 +374,23 @@ cdef class Font: finally: free(hb_variations) + def get_glyph_name(self, gid: int): + cdef char name[64] + cdef bytes packed + success = hb_font_get_glyph_name(self._hb_font, gid, name, 64) + if success: + packed = name + return packed.decode() + else: + return None + + def glyph_to_string(self, gid: int): + cdef char name[64] + cdef bytes packed + hb_font_glyph_to_string(self._hb_font, gid, name, 64) + packed = name + return packed.decode() + cdef hb_position_t _glyph_h_advance_func(hb_font_t* font, void* font_data, hb_codepoint_t glyph, diff --git a/src/uharfbuzz/charfbuzz.pxd b/src/uharfbuzz/charfbuzz.pxd index 75c59ea..9a814cb 100644 --- a/src/uharfbuzz/charfbuzz.pxd +++ b/src/uharfbuzz/charfbuzz.pxd @@ -212,6 +212,16 @@ cdef extern from "hb.h": hb_font_t* font, const hb_variation_t* variations, unsigned int variations_length) + hb_bool_t hb_font_get_glyph_name( + hb_font_t* font, + hb_codepoint_t glyph, + char* name, + unsigned int size) + void hb_font_glyph_to_string( + hb_font_t* font, + hb_codepoint_t glyph, + char* name, + unsigned int size) void hb_font_destroy(hb_font_t* font) # hb-shape.h diff --git a/tests/data/AdobeBlank.subset.ttf b/tests/data/AdobeBlank.subset.ttf index 75da7a236223e8303b3c1da33914dfff399010cf..0c89e20cd2ccb9d4613fe92e38e18c5d5f974e1a 100644 GIT binary patch delta 183 zcmX@W_k?ePxZ)KC28Mm^0sg@o81|PlFtAMl@&nw1L!DM!-{}YBKbdIZFM9$g$djH^ zna04`0c0|p0Evc-)Wj5S*5ug}m&EWC-{uowU|?+liaSr{VU&=0CBNi+JipCX24?0L zKtYC!KCYiZ^sPk~oi{r$y0UOHfw&9||K~6mO`gaqs>BK8xG=afxG}ghcrfHMGBGl< Ym*!;}m>3(fl^VL4I9hIA%sQ7502VMW2LJ#7 delta 148 zcmaFDcYtq#xZ(x|28Mm^0sg@o81|PlFt8N>`2p_1p-wBV@AL!m4@|W1mt6uB