diff --git a/src/Makefile.sources b/src/Makefile.sources index f2821e3de2819d6aefd0e3dfaa53b2d16102cc16..f412a65d23b07c38657cd995dba4153e0f6f537f 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -185,6 +185,7 @@ HB_ICU_headers = hb-icu.h HB_SUBSET_sources = \ hb-subset.cc \ hb-subset-glyf.cc \ + hb-subset-input.cc \ hb-subset-plan.cc \ $(NULL) diff --git a/src/hb-face.h b/src/hb-face.h index 9842d52b650034b7010d3a77b0274e40257dce39..0ce8d0462d5cb3fc39bc271ea3e0ea7cd140545a 100644 --- a/src/hb-face.h +++ b/src/hb-face.h @@ -71,7 +71,6 @@ hb_face_set_user_data (hb_face_t *face, hb_destroy_func_t destroy, hb_bool_t replace); - HB_EXTERN void * hb_face_get_user_data (hb_face_t *face, hb_user_data_key_t *key); diff --git a/src/hb-set.cc b/src/hb-set.cc index 0b4f871e852fda9bb9ff18bcf69c8725db9045b7..f3b864c12840dadbdd9bc50b1c092b99d9eff455 100644 --- a/src/hb-set.cc +++ b/src/hb-set.cc @@ -50,6 +50,13 @@ hb_set_create (void) return set; } +static const hb_set_t _hb_set_nil = { + HB_OBJECT_HEADER_STATIC, + true, /* in_error */ + + {0} /* elts */ +}; + /** * hb_set_get_empty: * @@ -60,13 +67,6 @@ hb_set_create (void) hb_set_t * hb_set_get_empty (void) { - static const hb_set_t _hb_set_nil = { - HB_OBJECT_HEADER_STATIC, - true, /* in_error */ - - {0} /* elts */ - }; - return const_cast (&_hb_set_nil); } diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc new file mode 100644 index 0000000000000000000000000000000000000000..75c016843a80b549c97bac48599f5735a6ebdc95 --- /dev/null +++ b/src/hb-subset-input.cc @@ -0,0 +1,109 @@ +/* + * Copyright © 2018 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Garret Rieger, Rod Sheeter, Behdad Esfahbod + */ + +#include "hb-object-private.hh" +#include "hb-subset-private.hh" +#include "hb-set-private.hh" + +/** + * hb_subset_input_create: + * + * Return value: New subset input. + * + * Since: 1.8.0 + **/ +hb_subset_input_t * +hb_subset_input_create (void) +{ + hb_subset_input_t *input = hb_object_create(); + + /* Unlike libharfbuzz, in this lib we return nullptr + * in case of allocation failure. */ + if (unlikely (!input)) + return nullptr; + + input->unicodes = hb_set_create (); + input->glyphs = hb_set_create (); + + return input; +} + +/** + * hb_subset_input_reference: (skip) + * @subset_input: a subset_input. + * + * + * + * Return value: + * + * Since: 1.8.0 + **/ +hb_subset_input_t * +hb_subset_input_reference (hb_subset_input_t *subset_input) +{ + return hb_object_reference (subset_input); +} + +/** + * hb_subset_input_destroy: + * @subset_input: a subset_input. + * + * Since: 1.8.0 + **/ +void +hb_subset_input_destroy(hb_subset_input_t *subset_input) +{ + if (!hb_object_destroy (subset_input)) return; + + hb_set_destroy (subset_input->unicodes); + hb_set_destroy (subset_input->glyphs); + + free (subset_input); +} + +/** + * hb_subset_input_unicode_set: + * @subset_input: a subset_input. + * + * Since: 1.8.0 + **/ +HB_EXTERN hb_set_t * +hb_subset_input_unicode_set (hb_subset_input_t *subset_input) +{ + return subset_input->unicodes; +} + +/** + * hb_subset_input_glyph_set: + * @subset_input: a subset_input. + * + * Since: 1.8.0 + **/ +HB_EXTERN hb_set_t * +hb_subset_input_glyph_set (hb_subset_input_t *subset_input) +{ + return subset_input->glyphs; +} diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index a06d38ae56fb293b8d4ae7cb67e378b66cb23829..c9d39c5b063349a4cc8fc14eb78f49ec0d45b654 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -140,7 +140,7 @@ hb_subset_plan_create (hb_face_t *face, plan->gids_to_retain.init(); plan->gids_to_retain_sorted.init(); - _populate_codepoints (input->codepoints, plan->codepoints); + _populate_codepoints (input->unicodes, plan->codepoints); _populate_gids_to_retain (face, plan->codepoints, plan->gids_to_retain, diff --git a/src/hb-subset-private.hh b/src/hb-subset-private.hh index 9689da808c5449a740a46dae32db528343f63f7b..4ef1b9540575ca69fc6f0e40e36b595192ecd258 100644 --- a/src/hb-subset-private.hh +++ b/src/hb-subset-private.hh @@ -38,7 +38,16 @@ struct hb_subset_input_t { hb_object_header_t header; ASSERT_POD (); - hb_set_t *codepoints; + hb_set_t *unicodes; + hb_set_t *glyphs; + + /* TODO + * + * features + * lookups + * nameIDs + * ... + */ }; #endif /* HB_SUBSET_PRIVATE_HH */ diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 3b022dd44d0a469abd11d1dd333780b758157ee1..09ae19fbfc656254f6716fbebd61e43a6a3dc36d 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -21,14 +21,12 @@ * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * - * Google Author(s): Garret Rieger, Rod Sheeter + * Google Author(s): Garret Rieger, Rod Sheeter, Behdad Esfahbod */ #include "hb-object-private.hh" #include "hb-open-type-private.hh" -#include "hb-private.hh" - #include "hb-subset-glyf.hh" #include "hb-subset-private.hh" #include "hb-subset-plan.hh" @@ -53,7 +51,7 @@ struct hb_subset_profile_t { * * Return value: New profile with default settings. * - * Since: 1.7.5 + * Since: 1.8.0 **/ hb_subset_profile_t * hb_subset_profile_create () @@ -64,7 +62,7 @@ hb_subset_profile_create () /** * hb_subset_profile_destroy: * - * Since: 1.7.5 + * Since: 1.8.0 **/ void hb_subset_profile_destroy (hb_subset_profile_t *profile) @@ -74,38 +72,6 @@ hb_subset_profile_destroy (hb_subset_profile_t *profile) free (profile); } -/** - * hb_subset_input_create: - * - * Return value: New subset input. - * - * Since: 1.7.5 - **/ -hb_subset_input_t * -hb_subset_input_create (hb_set_t *codepoints) -{ - if (unlikely (!codepoints)) - codepoints = hb_set_get_empty(); - - hb_subset_input_t *input = hb_object_create(); - input->codepoints = hb_set_reference(codepoints); - return input; -} - -/** - * hb_subset_input_destroy: - * - * Since: 1.7.5 - **/ -void -hb_subset_input_destroy(hb_subset_input_t *subset_input) -{ - if (!hb_object_destroy (subset_input)) return; - - hb_set_destroy (subset_input->codepoints); - free (subset_input); -} - template static hb_blob_t * _subset (hb_subset_plan_t *plan, hb_face_t *source) diff --git a/src/hb-subset.h b/src/hb-subset.h index 3eb41de848b2a23a6a25923e7556b5b36e73ea77..81e11fe65c7e065f81f7ec739bc10947498bf301 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -47,17 +47,27 @@ hb_subset_profile_destroy (hb_subset_profile_t *profile); /* * hb_subset_input_t + * * Things that change based on the input. Characters to keep, etc. */ typedef struct hb_subset_input_t hb_subset_input_t; HB_EXTERN hb_subset_input_t * -hb_subset_input_create (hb_set_t *codepoints); +hb_subset_input_create (void); + +HB_EXTERN hb_subset_input_t * +hb_subset_input_reference (hb_subset_input_t *subset_input); HB_EXTERN void hb_subset_input_destroy (hb_subset_input_t *subset_input); +HB_EXTERN hb_set_t * +hb_subset_input_unicode_set (hb_subset_input_t *subset_input); + +HB_EXTERN hb_set_t * +hb_subset_input_glyph_set (hb_subset_input_t *subset_input); + /* hb_subset() */ diff --git a/test/api/test-subset-glyf.c b/test/api/test-subset-glyf.c index fa41800b0c29e25b54d328190c6391deaa2d1c86..014f24338e9e4384bccfc7f31a2ba0417dc2ba99 100644 --- a/test/api/test-subset-glyf.c +++ b/test/api/test-subset-glyf.c @@ -94,9 +94,9 @@ test_subset_glyf (void) hb_face_t *face_abc_subset; hb_blob_t *glyf_expected_blob; hb_blob_t *glyf_actual_blob; - hb_set_t *codepoints = hb_set_create(); hb_subset_profile_t *profile = hb_subset_profile_create(); - hb_subset_input_t *input = hb_subset_input_create (codepoints); + hb_subset_input_t *input = hb_subset_input_create (); + hb_set_t *codepoints = hb_set_reference (hb_subset_input_unicode_set (input)); g_assert (face_abc); g_assert (face_ac); diff --git a/test/api/test-subset.c b/test/api/test-subset.c index 4184a563f91d18ff152518163aadb1e652d89dcc..44eba1581d9fedf64e5870011a6b83bda909bb08 100644 --- a/test/api/test-subset.c +++ b/test/api/test-subset.c @@ -43,7 +43,7 @@ test_subset (void) hb_face_t *face = hb_face_create(font_blob, 0); hb_subset_profile_t *profile = hb_subset_profile_create(); - hb_subset_input_t *input = hb_subset_input_create (hb_set_get_empty ()); + hb_subset_input_t *input = hb_subset_input_create (); hb_face_t *out_face = hb_subset(face, profile, input); g_assert(out_face); diff --git a/util/hb-subset.cc b/util/hb-subset.cc index a3505a8143d3f00f9511b50263031ff7a0d13870..16abd14d56f66263d5f8c5612e198d304bc677d5 100644 --- a/util/hb-subset.cc +++ b/util/hb-subset.cc @@ -37,13 +37,13 @@ struct subset_consumer_t { subset_consumer_t (option_parser_t *parser) - : failed (false), options (parser), font (nullptr), codepoints (nullptr) {} + : failed (false), options (parser), font (nullptr), input (nullptr) {} void init (hb_buffer_t *buffer_, const font_options_t *font_opts) { font = hb_font_reference (font_opts->get_font ()); - codepoints = hb_set_create(); + input = hb_subset_input_create (); } void consume_line (const char *text, @@ -51,14 +51,13 @@ struct subset_consumer_t const char *text_before, const char *text_after) { - // text appears to be a g_string when set by --unicodes - // TODO(Q1) are gunichar and hbcodepoint_t interchangeable? // TODO(Q1) does this only get called with at least 1 codepoint? + hb_set_t *codepoints = hb_subset_input_unicode_set (input); gchar *c = (gchar *)text; do { gunichar cp = g_utf8_get_char(c); - hb_codepoint_t hb_cp = cp; // TODO(Q1) is this safe? - hb_set_add(codepoints, hb_cp); + hb_codepoint_t hb_cp = cp; + hb_set_add (codepoints, hb_cp); } while ((c = g_utf8_find_next_char(c, text + text_len)) != nullptr); } @@ -90,12 +89,10 @@ struct subset_consumer_t void finish (const font_options_t *font_opts) { - // TODO(Q1) check for errors from creates and such hb_subset_profile_t *subset_profile = hb_subset_profile_create(); - hb_subset_input_t *subset_input = hb_subset_input_create (codepoints); hb_face_t *face = hb_font_get_face (font); - hb_face_t *new_face = hb_subset(face, subset_profile, subset_input); + hb_face_t *new_face = hb_subset(face, subset_profile, input); hb_blob_t *result = hb_face_reference_blob (new_face); failed = !hb_blob_get_length (result); @@ -103,8 +100,7 @@ struct subset_consumer_t write_file (options.output_file, result); hb_subset_profile_destroy (subset_profile); - hb_subset_input_destroy (subset_input); - hb_set_destroy (codepoints); + hb_subset_input_destroy (input); hb_blob_destroy (result); hb_face_destroy (new_face); hb_font_destroy (font); @@ -116,7 +112,7 @@ struct subset_consumer_t private: output_options_t options; hb_font_t *font; - hb_set_t *codepoints; + hb_subset_input_t *input; }; int