diff options
author | Michiharu Ariza <ariza@adobe.com> | 2018-08-29 13:26:17 -0700 |
---|---|---|
committer | Michiharu Ariza <ariza@adobe.com> | 2018-08-29 13:26:17 -0700 |
commit | 8af9690ac7ce41fb1db878d556df5c4ee624eaa0 (patch) | |
tree | 9392f9fad1df5053414a1bd0f15c2f7001778b46 /src/hb-subset.cc | |
parent | 0ad081ec324e734cfca60d4d2c36a1be5bc8a067 (diff) | |
parent | fee0f41c6c1e50621d10b07802ca36a9b295b53d (diff) | |
download | harfbuzz-8af9690ac7ce41fb1db878d556df5c4ee624eaa0.tar.gz |
Merge branch 'master' into cff-subset
Renamed cff "private" source/headers without the suffix
Diffstat (limited to 'src/hb-subset.cc')
-rw-r--r-- | src/hb-subset.cc | 151 |
1 files changed, 4 insertions, 147 deletions
diff --git a/src/hb-subset.cc b/src/hb-subset.cc index bf9c3994..d106e0ae 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -24,14 +24,14 @@ * Google Author(s): Garret Rieger, Rod Sheeter, Behdad Esfahbod */ -#include "hb-private.hh" -#include "hb-open-type-private.hh" +#include "hb.hh" +#include "hb-open-type.hh" #include "hb-subset-glyf.hh" -#include "hb-subset-private.hh" +#include "hb-subset.hh" #include "hb-subset-plan.hh" -#include "hb-open-file-private.hh" +#include "hb-open-file.hh" #include "hb-ot-cmap-table.hh" #include "hb-ot-glyf-table.hh" #include "hb-ot-hdmx-table.hh" @@ -98,135 +98,6 @@ _subset (hb_subset_plan_t *plan) } -/* - * A face that has add_table(). - */ - -struct hb_subset_face_data_t -{ - struct table_entry_t - { - inline int cmp (const hb_tag_t *t) const - { - if (*t < tag) return -1; - if (*t > tag) return -1; - return 0; - } - - hb_tag_t tag; - hb_blob_t *blob; - }; - - hb_vector_t<table_entry_t, 32> tables; -}; - -static hb_subset_face_data_t * -_hb_subset_face_data_create (void) -{ - hb_subset_face_data_t *data = (hb_subset_face_data_t *) calloc (1, sizeof (hb_subset_face_data_t)); - if (unlikely (!data)) - return nullptr; - - data->tables.init (); - - return data; -} - -static void -_hb_subset_face_data_destroy (void *user_data) -{ - hb_subset_face_data_t *data = (hb_subset_face_data_t *) user_data; - - for (unsigned int i = 0; i < data->tables.len; i++) - hb_blob_destroy (data->tables[i].blob); - - data->tables.fini (); - - free (data); -} - -static hb_blob_t * -_hb_subset_face_data_reference_blob (hb_subset_face_data_t *data) -{ - - unsigned int table_count = data->tables.len; - unsigned int face_length = table_count * 16 + 12; - - for (unsigned int i = 0; i < table_count; i++) - face_length += hb_ceil_to_4 (hb_blob_get_length (data->tables.arrayZ[i].blob)); - - char *buf = (char *) malloc (face_length); - if (unlikely (!buf)) - return nullptr; - - hb_serialize_context_t c (buf, face_length); - OT::OpenTypeFontFile *f = c.start_serialize<OT::OpenTypeFontFile> (); - - bool is_cff = data->tables.lsearch (HB_TAG ('C','F','F',' ')) || data->tables.lsearch (HB_TAG ('C','F','F','2')); - hb_tag_t sfnt_tag = is_cff ? OT::OpenTypeFontFile::CFFTag : OT::OpenTypeFontFile::TrueTypeTag; - - Supplier<hb_tag_t> tags_supplier (&data->tables[0].tag, table_count, sizeof (data->tables[0])); - Supplier<hb_blob_t *> blobs_supplier (&data->tables[0].blob, table_count, sizeof (data->tables[0])); - bool ret = f->serialize_single (&c, - sfnt_tag, - tags_supplier, - blobs_supplier, - table_count); - - c.end_serialize (); - - if (unlikely (!ret)) - { - free (buf); - return nullptr; - } - - return hb_blob_create (buf, face_length, HB_MEMORY_MODE_WRITABLE, buf, free); -} - -static hb_blob_t * -_hb_subset_face_reference_table (hb_face_t *face, hb_tag_t tag, void *user_data) -{ - hb_subset_face_data_t *data = (hb_subset_face_data_t *) user_data; - - if (!tag) - return _hb_subset_face_data_reference_blob (data); - - hb_subset_face_data_t::table_entry_t *entry = data->tables.lsearch (tag); - if (entry) - return hb_blob_reference (entry->blob); - - return nullptr; -} - -/* TODO: Move this to hb-face.h and rename to hb_face_builder_create() - * with hb_face_builder_add_table(). */ -hb_face_t * -hb_subset_face_create (void) -{ - hb_subset_face_data_t *data = _hb_subset_face_data_create (); - if (unlikely (!data)) return hb_face_get_empty (); - - return hb_face_create_for_tables (_hb_subset_face_reference_table, - data, - _hb_subset_face_data_destroy); -} - -hb_bool_t -hb_subset_face_add_table (hb_face_t *face, hb_tag_t tag, hb_blob_t *blob) -{ - if (unlikely (face->destroy != (hb_destroy_func_t) _hb_subset_face_data_destroy)) - return false; - - hb_subset_face_data_t *data = (hb_subset_face_data_t *) face->user_data; - hb_subset_face_data_t::table_entry_t *entry = data->tables.push (); - - entry->tag = tag; - entry->blob = hb_blob_reference (blob); - - return true; -} - static bool _subset_table (hb_subset_plan_t *plan, hb_tag_t tag) @@ -372,17 +243,3 @@ hb_subset (hb_face_t *source, hb_subset_plan_destroy (plan); return result; } - -/** - * hb_subset_get_all_codepoints: - * @source: font face data to load. - * @out: set to add the all codepoints covered by font face, source. - */ -void -hb_subset_get_all_codepoints (hb_face_t *source, hb_set_t *out) -{ - OT::cmap::accelerator_t cmap; - cmap.init (source); - cmap.get_all_codepoints (out); - cmap.fini(); -} |