diff --git a/src/hb-ot-vorg-table.hh b/src/hb-ot-vorg-table.hh index b2059e86e..19e08ebb5 100644 --- a/src/hb-ot-vorg-table.hh +++ b/src/hb-ot-vorg-table.hh @@ -69,102 +69,50 @@ struct VORG return vertYOrigins[i].vertOriginY; } - bool _subset (const hb_subset_plan_t *plan HB_UNUSED, - const VORG *vorg_table, - const hb_vector_t &subset_metrics, - unsigned int dest_sz, - void *dest) const + template + void serialize (hb_serialize_context_t *c, + Iterator it, + FWORD defaultVertOriginY) { - hb_serialize_context_t c (dest, dest_sz); - VORG *subset_table = c.start_serialize (); - if (unlikely (!c.extend_min (*subset_table))) - return false; + if (unlikely (!c->extend_min ((*this)))) return; - subset_table->version.major = 1; - subset_table->version.minor = 0; + this->version.major = 1; + this->version.minor = 0; - subset_table->defaultVertOriginY = vorg_table->defaultVertOriginY; - subset_table->vertYOrigins.len = subset_metrics.length; + this->defaultVertOriginY = defaultVertOriginY; + this->vertYOrigins.len = it.len (); - bool success = true; - if (subset_metrics.length > 0) - { - unsigned int size = VertOriginMetric::static_size * subset_metrics.length; - VertOriginMetric *metrics = c.allocate_size (size); - if (likely (metrics != nullptr)) - memcpy (metrics, &subset_metrics[0], size); - else - success = false; - } - c.end_serialize (); - - return success; + + it + | hb_apply ([c] (const VertOriginMetric& _) { c->copy (_);}) + ; } - bool subset (hb_subset_plan_t *plan) const + bool subset (hb_subset_context_t *c) const { - hb_blob_t *vorg_blob = hb_sanitize_context_t().reference_table (plan->source); - const VORG *vorg_table = vorg_blob->as (); + TRACE_SUBSET (this); + VORG *vorg_prime = c->serializer->start_embed (); + if (unlikely (!c->serializer->check_success (vorg_prime))) return_trace (false); - /* count the number of glyphs to be included in the subset table */ - hb_vector_t subset_metrics; - subset_metrics.init (); + auto it = + + vertYOrigins.as_array () + | hb_filter (c->plan->glyphset (), &VertOriginMetric::glyph) + | hb_map ([&] (const VertOriginMetric& _) + { + hb_codepoint_t new_glyph = HB_SET_VALUE_INVALID; + c->plan->new_gid_for_old_gid (_.glyph, &new_glyph); - - hb_codepoint_t old_glyph = HB_SET_VALUE_INVALID; - unsigned int i = 0; - while (i < vertYOrigins.len - && plan->glyphset ()->next (&old_glyph)) - { - while (old_glyph > vertYOrigins[i].glyph) - { - i++; - if (i >= vertYOrigins.len) - break; - } - - if (old_glyph == vertYOrigins[i].glyph) - { - hb_codepoint_t new_glyph; - if (plan->new_gid_for_old_gid (old_glyph, &new_glyph)) - { - VertOriginMetric *metrics = subset_metrics.push (); - metrics->glyph = new_glyph; - metrics->vertOriginY = vertYOrigins[i].vertOriginY; - } - } - } - - /* alloc the new table */ - unsigned int dest_sz = VORG::min_size + VertOriginMetric::static_size * subset_metrics.length; - void *dest = (void *) malloc (dest_sz); - if (unlikely (!dest)) - { - subset_metrics.fini (); - hb_blob_destroy (vorg_blob); - return false; - } + VertOriginMetric metric; + metric.glyph = new_glyph; + metric.vertOriginY = _.vertOriginY; + return metric; + }) + ; /* serialize the new table */ - if (!_subset (plan, vorg_table, subset_metrics, dest_sz, dest)) - { - subset_metrics.fini (); - free (dest); - hb_blob_destroy (vorg_blob); - return false; - } - - hb_blob_t *result = hb_blob_create ((const char *)dest, - dest_sz, - HB_MEMORY_MODE_READONLY, - dest, - free); - bool success = plan->add_table (HB_OT_TAG_VORG, result); - hb_blob_destroy (result); - subset_metrics.fini (); - hb_blob_destroy (vorg_blob); - return success; + vorg_prime->serialize (c->serializer, it, defaultVertOriginY); + return_trace (true); } bool sanitize (hb_sanitize_context_t *c) const diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 3f4c2e40b..b117870c8 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -204,7 +204,7 @@ _subset_table (hb_subset_plan_t *plan, result = _subset (plan); break; case HB_OT_TAG_VORG: - result = _subset (plan); + result = _subset2 (plan); break; #endif