From 408c1daeb4ff86d2204ed1bdd059513357ada392 Mon Sep 17 00:00:00 2001 From: Qunxin Liu Date: Fri, 29 Mar 2019 10:34:32 -0700 Subject: [PATCH] [subset] subset name table step 1, write out table unmodified, use accelerator to access string --- src/hb-ot-name-table.hh | 53 +++++++++++++++++++++++++++++++++++++++++ src/hb-subset.cc | 4 ++++ 2 files changed, 57 insertions(+) diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index fca509149..bacd5a8e6 100644 --- a/src/hb-ot-name-table.hh +++ b/src/hb-ot-name-table.hh @@ -158,6 +158,59 @@ struct name unsigned int get_size () const { return min_size + count * nameRecordZ.item_size; } + size_t get_subsetted_size(const name *source_name, hb_subset_plan_t *plan, hb_set_t *name_record_ids_to_retain) const + { + size_t result = min_size; + result += count * NameRecord::static_size; + + hb_face_t *face = plan->source; + accelerator_t acc; + acc.init (face); + + for(unsigned int i = 0; iadd(i); + } + } + + acc.fini(); + + return result; + } + + void serialize(void *dest, const void *source, size_t dest_size) const + { + memcpy(dest, source, dest_size); + } + + bool subset(hb_subset_plan_t *plan) const + { + hb_set_t *name_record_ids_to_retain = hb_set_create(); + size_t dest_size = get_subsetted_size(this, plan, name_record_ids_to_retain); + name *dest = (name *) malloc (dest_size); + if(unlikely (!dest)) + { + DEBUG_MSG(SUBSET, nullptr, "Unable to alloc %lu for name subset output.", + (unsigned long) dest_size); + return false; + } + + serialize(dest, this, dest_size); + hb_set_destroy(name_record_ids_to_retain); + + hb_blob_t *name_prime_blob = hb_blob_create((const char *) dest, + dest_size, + HB_MEMORY_MODE_READONLY, + dest, + free); + bool result = plan->add_table (HB_OT_TAG_name, name_prime_blob); + hb_blob_destroy (name_prime_blob); + + return result; + } bool sanitize_records (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); diff --git a/src/hb-subset.cc b/src/hb-subset.cc index bccb98d62..333e7d484 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -43,6 +43,7 @@ #include "hb-ot-cff1-table.hh" #include "hb-ot-cff2-table.hh" #include "hb-ot-vorg-table.hh" +#include "hb-ot-name-table.hh" #include "hb-ot-layout-gsub-table.hh" #include "hb-ot-layout-gpos-table.hh" @@ -158,6 +159,9 @@ _subset_table (hb_subset_plan_t *plan, case HB_OT_TAG_hdmx: result = _subset (plan); break; + case HB_OT_TAG_name: + result = _subset (plan); + break; case HB_OT_TAG_head: // TODO that won't work well if there is no glyf DEBUG_MSG(SUBSET, nullptr, "skip head, handled by glyf");