From 19afd25004487cfaa7b487b1768b4dae1ab37296 Mon Sep 17 00:00:00 2001 From: Qunxin Liu Date: Wed, 24 Apr 2019 14:02:29 -0700 Subject: [PATCH] [subset] Update to use _subset2() for name table --- src/hb-ot-name-table.hh | 47 ++++++++++------------------------------------- src/hb-subset.cc | 4 ++-- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index fde808c..056a77a 100644 --- a/src/hb-ot-name-table.hh +++ b/src/hb-ot-name-table.hh @@ -158,32 +158,19 @@ struct name unsigned int get_size () const { return min_size + count * nameRecordZ.item_size; } - size_t get_subsetted_size (const name *source_name, + void get_subsetted_ids (const name *source_name, const hb_subset_plan_t *plan, hb_vector_t& name_record_idx_to_retain) const { - size_t result = min_size; - - hb_face_t *face = plan->source; - accelerator_t acc; - acc.init (face); - for(unsigned int i = 0; i < count; i++) { - if (format == 0 && (unsigned int) nameRecordZ[i].nameID > 25) + if (format == 0 && (unsigned int) source_name->nameRecordZ[i].nameID > 25) continue; if (!hb_set_is_empty (plan->name_ids) && !hb_set_has (plan->name_ids, source_name->nameRecordZ[i].nameID)) continue; - result += acc.get_name (i).get_size (); name_record_idx_to_retain.push (i); } - - acc.fini (); - - result += name_record_idx_to_retain.length * NameRecord::static_size; - - return result; } bool serialize_name_record (hb_serialize_context_t *c, @@ -294,36 +281,22 @@ struct name return_trace (true); } - bool subset (hb_subset_plan_t *plan) const + bool subset (hb_subset_context_t *c) const { + hb_subset_plan_t *plan = c->plan; hb_vector_t name_record_idx_to_retain; - size_t dest_size = get_subsetted_size (this, plan, name_record_idx_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; - } + get_subsetted_ids (this, plan, name_record_idx_to_retain); - hb_serialize_context_t c (dest, dest_size); - name *name_prime = c.start_serialize (); - if (!name_prime || !name_prime->serialize (&c, this, plan, name_record_idx_to_retain)) + hb_serialize_context_t *serializer = c->serializer; + name *name_prime = serializer->start_embed (); + if (!name_prime || !name_prime->serialize (serializer, this, plan, name_record_idx_to_retain)) { - free (dest); DEBUG_MSG (SUBSET, nullptr, "Failed to serialize write new name."); - c.end_serialize (); return false; } - - c.end_serialize (); - - hb_blob_t *name_prime_blob = c.copy_blob (); - bool result = plan->add_table (HB_OT_TAG_name, name_prime_blob); - hb_blob_destroy (name_prime_blob); - - return result; + + return true; } bool sanitize_records (hb_sanitize_context_t *c) const diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 333e7d4..2165b8a 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -88,7 +88,6 @@ _subset2 (hb_subset_plan_t *plan) serializer.start_serialize (); hb_subset_context_t c (plan, &serializer); result = table->subset (&c); - serializer.end_serialize (); if (serializer.ran_out_of_room) { buf_size += (buf_size >> 1) + 32; @@ -105,6 +104,7 @@ _subset2 (hb_subset_plan_t *plan) abort (); } + serializer.end_serialize (); if (result) { hb_blob_t *dest_blob = serializer.copy_blob (); @@ -160,7 +160,7 @@ _subset_table (hb_subset_plan_t *plan, result = _subset (plan); break; case HB_OT_TAG_name: - result = _subset (plan); + result = _subset2 (plan); break; case HB_OT_TAG_head: // TODO that won't work well if there is no glyf -- 2.7.4