[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;
|
return vertYOrigins[i].vertOriginY;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _subset (const hb_subset_plan_t *plan HB_UNUSED,
|
template <typename Iterator,
|
||||||
const VORG *vorg_table,
|
hb_requires (hb_is_iterator (Iterator))>
|
||||||
const hb_vector_t<VertOriginMetric> &subset_metrics,
|
void serialize (hb_serialize_context_t *c,
|
||||||
unsigned int dest_sz,
|
Iterator it,
|
||||||
void *dest) const
|
FWORD defaultVertOriginY)
|
||||||
{
|
{
|
||||||
hb_serialize_context_t c (dest, dest_sz);
|
|
||||||
|
|
||||||
VORG *subset_table = c.start_serialize<VORG> ();
|
if (unlikely (!c->extend_min ((*this)))) return;
|
||||||
if (unlikely (!c.extend_min (*subset_table)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
subset_table->version.major = 1;
|
this->version.major = 1;
|
||||||
subset_table->version.minor = 0;
|
this->version.minor = 0;
|
||||||
|
|
||||||
subset_table->defaultVertOriginY = vorg_table->defaultVertOriginY;
|
this->defaultVertOriginY = defaultVertOriginY;
|
||||||
subset_table->vertYOrigins.len = subset_metrics.length;
|
this->vertYOrigins.len = it.len ();
|
||||||
|
|
||||||
bool success = true;
|
+ it
|
||||||
if (subset_metrics.length > 0)
|
| hb_apply ([c] (const VertOriginMetric& _) { c->copy (_);})
|
||||||
{
|
;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
TRACE_SUBSET (this);
|
||||||
const VORG *vorg_table = vorg_blob->as<VORG> ();
|
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 */
|
auto it =
|
||||||
hb_vector_t<VertOriginMetric> subset_metrics;
|
+ vertYOrigins.as_array ()
|
||||||
subset_metrics.init ();
|
| 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);
|
||||||
|
|
||||||
|
VertOriginMetric metric;
|
||||||
hb_codepoint_t old_glyph = HB_SET_VALUE_INVALID;
|
metric.glyph = new_glyph;
|
||||||
unsigned int i = 0;
|
metric.vertOriginY = _.vertOriginY;
|
||||||
while (i < vertYOrigins.len
|
return metric;
|
||||||
&& 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* serialize the new table */
|
/* serialize the new table */
|
||||||
if (!_subset (plan, vorg_table, subset_metrics, dest_sz, dest))
|
vorg_prime->serialize (c->serializer, it, defaultVertOriginY);
|
||||||
{
|
return_trace (true);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sanitize (hb_sanitize_context_t *c) const
|
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);
|
result = _subset<const OT::cff2> (plan);
|
||||||
break;
|
break;
|
||||||
case HB_OT_TAG_VORG:
|
case HB_OT_TAG_VORG:
|
||||||
result = _subset<const OT::VORG> (plan);
|
result = _subset2<const OT::VORG> (plan);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue