[subset] VORG table to use _subset2 method and new iterator frameworks
This commit is contained in:
parent
8062979990
commit
9bd8d66c2b
|
@ -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<VertOriginMetric> &subset_metrics,
|
||||
unsigned int dest_sz,
|
||||
void *dest) const
|
||||
template <typename Iterator,
|
||||
hb_requires (hb_is_iterator (Iterator))>
|
||||
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<VORG> ();
|
||||
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<VertOriginMetric> (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<VORG> (plan->source);
|
||||
const VORG *vorg_table = vorg_blob->as<VORG> ();
|
||||
TRACE_SUBSET (this);
|
||||
VORG *vorg_prime = c->serializer->start_embed<VORG> ();
|
||||
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<VertOriginMetric> 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
|
||||
|
|
|
@ -204,7 +204,7 @@ _subset_table (hb_subset_plan_t *plan,
|
|||
result = _subset<const OT::cff2> (plan);
|
||||
break;
|
||||
case HB_OT_TAG_VORG:
|
||||
result = _subset<const OT::VORG> (plan);
|
||||
result = _subset2<const OT::VORG> (plan);
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue