[subset] Update to use _subset2() for name table

This commit is contained in:
Qunxin Liu 2019-04-24 14:02:29 -07:00 committed by Garret Rieger
parent 1ca4b5c770
commit 19afd25004
2 changed files with 12 additions and 39 deletions

View File

@ -158,32 +158,19 @@ struct name
unsigned int get_size () const unsigned int get_size () const
{ return min_size + count * nameRecordZ.item_size; } { 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, const hb_subset_plan_t *plan,
hb_vector_t<unsigned int>& name_record_idx_to_retain) const hb_vector_t<unsigned int>& 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++) 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; continue;
if (!hb_set_is_empty (plan->name_ids) && if (!hb_set_is_empty (plan->name_ids) &&
!hb_set_has (plan->name_ids, source_name->nameRecordZ[i].nameID)) !hb_set_has (plan->name_ids, source_name->nameRecordZ[i].nameID))
continue; continue;
result += acc.get_name (i).get_size ();
name_record_idx_to_retain.push (i); 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, bool serialize_name_record (hb_serialize_context_t *c,
@ -294,36 +281,22 @@ struct name
return_trace (true); 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<unsigned int> name_record_idx_to_retain; hb_vector_t<unsigned int> name_record_idx_to_retain;
size_t dest_size = get_subsetted_size (this, plan, name_record_idx_to_retain); get_subsetted_ids (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;
}
hb_serialize_context_t c (dest, dest_size); hb_serialize_context_t *serializer = c->serializer;
name *name_prime = c.start_serialize<name> (); name *name_prime = serializer->start_embed<name> ();
if (!name_prime || !name_prime->serialize (&c, this, plan, name_record_idx_to_retain)) 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."); DEBUG_MSG (SUBSET, nullptr, "Failed to serialize write new name.");
c.end_serialize ();
return false; return false;
} }
c.end_serialize (); return true;
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;
} }
bool sanitize_records (hb_sanitize_context_t *c) const bool sanitize_records (hb_sanitize_context_t *c) const

View File

@ -88,7 +88,6 @@ _subset2 (hb_subset_plan_t *plan)
serializer.start_serialize<TableType> (); serializer.start_serialize<TableType> ();
hb_subset_context_t c (plan, &serializer); hb_subset_context_t c (plan, &serializer);
result = table->subset (&c); result = table->subset (&c);
serializer.end_serialize ();
if (serializer.ran_out_of_room) if (serializer.ran_out_of_room)
{ {
buf_size += (buf_size >> 1) + 32; buf_size += (buf_size >> 1) + 32;
@ -105,6 +104,7 @@ _subset2 (hb_subset_plan_t *plan)
abort (); abort ();
} }
serializer.end_serialize ();
if (result) if (result)
{ {
hb_blob_t *dest_blob = serializer.copy_blob (); hb_blob_t *dest_blob = serializer.copy_blob ();
@ -160,7 +160,7 @@ _subset_table (hb_subset_plan_t *plan,
result = _subset<const OT::hdmx> (plan); result = _subset<const OT::hdmx> (plan);
break; break;
case HB_OT_TAG_name: case HB_OT_TAG_name:
result = _subset<const OT::name> (plan); result = _subset2<const OT::name> (plan);
break; break;
case HB_OT_TAG_head: case HB_OT_TAG_head:
// TODO that won't work well if there is no glyf // TODO that won't work well if there is no glyf