From d0b6d539f6b5424b8f769f800c1126a5cf5374c9 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Thu, 28 Feb 2019 17:25:05 -0800 Subject: [PATCH] Make hb_subset_input_glyph_set () actually do something. --- src/hb-subset-plan.cc | 3 +++ test/api/hb-subset-test.h | 11 ++++++++++- test/api/test-subset-glyf.c | 24 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 5702d0173..49ab9e133 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -96,6 +96,7 @@ _remove_invalid_gids (hb_set_t *glyphs, static hb_set_t * _populate_gids_to_retain (hb_face_t *face, const hb_set_t *unicodes, + const hb_set_t *input_glyphs_to_retain, bool close_over_gsub, hb_set_t *unicodes_to_retain, hb_map_t *codepoint_to_glyph, @@ -110,6 +111,7 @@ _populate_gids_to_retain (hb_face_t *face, hb_set_t *initial_gids_to_retain = hb_set_create (); initial_gids_to_retain->add (0); // Not-def + hb_set_union (initial_gids_to_retain, input_glyphs_to_retain); hb_codepoint_t cp = HB_SET_VALUE_INVALID; while (unicodes->next (&cp)) @@ -213,6 +215,7 @@ hb_subset_plan_create (hb_face_t *face, plan->reverse_glyph_map = hb_map_create(); plan->_glyphset = _populate_gids_to_retain (face, input->unicodes, + input->glyphs, !plan->drop_layout, plan->unicodes, plan->codepoint_to_glyph, diff --git a/test/api/hb-subset-test.h b/test/api/hb-subset-test.h index cefa4e066..3e759a8a9 100644 --- a/test/api/hb-subset-test.h +++ b/test/api/hb-subset-test.h @@ -48,7 +48,7 @@ typedef short bool; HB_BEGIN_DECLS static inline hb_subset_input_t * -hb_subset_test_create_input(const hb_set_t *codepoints) +hb_subset_test_create_input (const hb_set_t *codepoints) { hb_subset_input_t *input = hb_subset_input_create_or_fail (); hb_set_t * input_codepoints = hb_subset_input_unicode_set (input); @@ -56,6 +56,15 @@ hb_subset_test_create_input(const hb_set_t *codepoints) return input; } +static inline hb_subset_input_t * +hb_subset_test_create_input_from_glyphs (const hb_set_t *glyphs) +{ + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + hb_set_t * input_glyphs = hb_subset_input_glyph_set (input); + hb_set_union (input_glyphs, glyphs); + return input; +} + static inline hb_face_t * hb_subset_test_create_subset (hb_face_t *source, hb_subset_input_t *input) diff --git a/test/api/test-subset-glyf.c b/test/api/test-subset-glyf.c index e8609ca83..4671156f9 100644 --- a/test/api/test-subset-glyf.c +++ b/test/api/test-subset-glyf.c @@ -79,6 +79,29 @@ test_subset_glyf (void) hb_face_destroy (face_ac); } +static void +test_subset_glyf_with_input_glyphs (void) +{ + hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf"); + hb_face_t *face_ac = hb_test_open_font_file ("fonts/Roboto-Regular.ac.ttf"); + + hb_set_t *glyphs = hb_set_create(); + hb_face_t *face_abc_subset; + hb_set_add (glyphs, 1); + hb_set_add (glyphs, 3); + face_abc_subset = + hb_subset_test_create_subset (face_abc, hb_subset_test_create_input_from_glyphs (glyphs)); + hb_set_destroy (glyphs); + + hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('g','l','y','f')); + hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('l','o','c', 'a')); + check_maxp_num_glyphs(face_abc_subset, 3, true); + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); + hb_face_destroy (face_ac); +} + static void test_subset_glyf_with_components (void) { @@ -291,6 +314,7 @@ main (int argc, char **argv) hb_test_add (test_subset_glyf_noop); hb_test_add (test_subset_glyf); + hb_test_add (test_subset_glyf_with_input_glyphs); hb_test_add (test_subset_glyf_strip_hints_simple); hb_test_add (test_subset_glyf_strip_hints_composite); hb_test_add (test_subset_glyf_strip_hints_invalid);