From 5dadbb0fa096574b6bccd75cced203baf615fedf Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Tue, 17 Apr 2018 07:00:23 -0600 Subject: [PATCH] [subset] Add implementation of cmap format 12 codepoint listing. (#988) --- src/hb-ot-cmap-table.hh | 21 +++++++++++- test/api/fonts/Roboto-Regular.abc.format12.ttf | Bin 0 -> 2412 bytes test/api/test-subset-codepoints.c | 44 +++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 test/api/fonts/Roboto-Regular.abc.format12.ttf diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index c7c5d0a..5e71eab 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -204,6 +204,8 @@ struct CmapSubtableLongGroup { friend struct CmapSubtableFormat12; friend struct CmapSubtableFormat13; + template + friend struct CmapSubtableLongSegmented; friend struct cmap; int cmp (hb_codepoint_t codepoint) const @@ -276,6 +278,15 @@ struct CmapSubtableLongSegmented return true; } + inline void get_all_codepoints (hb_set_t *out) const + { + for (unsigned int i = 0; i < this->groups.len; i++) { + hb_set_add_range (out, + this->groups[i].startCharCode, + this->groups[i].endCharCode); + } + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -690,7 +701,7 @@ struct cmap break; case 12: this->get_glyph_func = get_glyph_from; - this->get_all_codepoints_func = null_get_all_codepoints_func; + this->get_all_codepoints_func = get_all_codepoints_from; break; case 4: { @@ -758,6 +769,14 @@ struct cmap } template + static inline void get_all_codepoints_from (const void *obj, + hb_set_t *out) + { + const Type *typed_obj = (const Type *) obj; + typed_obj->get_all_codepoints (out); + } + + template static inline bool get_glyph_from_symbol (const void *obj, hb_codepoint_t codepoint, hb_codepoint_t *glyph) diff --git a/test/api/fonts/Roboto-Regular.abc.format12.ttf b/test/api/fonts/Roboto-Regular.abc.format12.ttf new file mode 100644 index 0000000000000000000000000000000000000000..5aa63341cd5824456e79ead1306982305e693a64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}}Et^|wv<>D`tu+{I zX)bd+T<+59=HL%DYig;hOsrF^Prmuu1;+mQR_dYHp+8K&z3=RYQcccw@6WVjxi?a3 z-=W_<_v^Deqto&39WU!=f0--(sjeIu-1hfB-+MpRe0b${ErxY4l688#M9-;k5o?wk zjY{oUoPD)y5rMc`wi$t$$~MU&m2I`t!0k%LxmFGrm5h50Hr>ixg0`WyNOQC}f~wO| zO9d7=%37L(lKR=wg{0;5Vv?o*vH0Ro=EFPRdgi#`xSado*nTry{nK-~k8)Q{f4q1) z=RbWBZ)JQN#7lT$>!ByBR8->Pg_BZ{n6gS)Mj#{03|^+I2f<}3kt+&!k-U*0?Qcsl zk_5-*m2KB*j8niZ7q-TZ%V$jc-roCZ?!T$!R|X-U$Nv&Y$M?-><)}0K;VOom-Wci(C3Pz_!B&t$UH1%tC-%tH1b9ZL zh93maL^QP*Jb3S6!>oq?gTqsMag{ literal 0 HcmV?d00001 diff --git a/test/api/test-subset-codepoints.c b/test/api/test-subset-codepoints.c index c4f9c0e..3bd1fe0 100644 --- a/test/api/test-subset-codepoints.c +++ b/test/api/test-subset-codepoints.c @@ -48,12 +48,56 @@ test_get_all_codepoints_format4 (void) hb_face_destroy (face); } +static void +test_get_all_codepoints_format12 (void) +{ + hb_face_t *face = hb_subset_test_open_font("fonts/Roboto-Regular.abc.format12.ttf"); + hb_set_t *codepoints = hb_set_create(); + + hb_subset_get_all_codepoints (face, codepoints); + + hb_codepoint_t cp = HB_SET_VALUE_INVALID; + g_assert (hb_set_next (codepoints, &cp)); + g_assert_cmpuint (0x61, ==, cp); + g_assert (hb_set_next (codepoints, &cp)); + g_assert_cmpuint (0x62, ==, cp); + g_assert (hb_set_next (codepoints, &cp)); + g_assert_cmpuint (0x63, ==, cp); + g_assert (!hb_set_next (codepoints, &cp)); + + hb_set_destroy (codepoints); + hb_face_destroy (face); +} + +static void +test_get_all_codepoints (void) +{ + hb_face_t *face = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf"); + hb_set_t *codepoints = hb_set_create(); + + hb_subset_get_all_codepoints (face, codepoints); + + hb_codepoint_t cp = HB_SET_VALUE_INVALID; + g_assert (hb_set_next (codepoints, &cp)); + g_assert_cmpuint (0x61, ==, cp); + g_assert (hb_set_next (codepoints, &cp)); + g_assert_cmpuint (0x62, ==, cp); + g_assert (hb_set_next (codepoints, &cp)); + g_assert_cmpuint (0x63, ==, cp); + g_assert (!hb_set_next (codepoints, &cp)); + + hb_set_destroy (codepoints); + hb_face_destroy (face); +} + int main (int argc, char **argv) { hb_test_init (&argc, &argv); + hb_test_add (test_get_all_codepoints); hb_test_add (test_get_all_codepoints_format4); + hb_test_add (test_get_all_codepoints_format12); return hb_test_run(); } -- 2.7.4