[subset] Add source_blob as a hb_subset_context_t field (#2203)
So no more double sanitizing source table.
This commit is contained in:
parent
e90213868b
commit
e642aab116
|
@ -339,20 +339,16 @@ struct sbix
|
|||
strikes.sanitize (c, this)));
|
||||
}
|
||||
|
||||
bool add_strike (hb_subset_context_t *c,
|
||||
const void *dst_base,
|
||||
unsigned int i,
|
||||
unsigned int sbix_len) const {
|
||||
if (strikes[i].is_null () ||
|
||||
sbix_len < (unsigned int) strikes[i])
|
||||
bool
|
||||
add_strike (hb_subset_context_t *c, const void *dst_base, unsigned i) const
|
||||
{
|
||||
if (strikes[i].is_null () || c->source_blob->length < (unsigned) strikes[i])
|
||||
return false;
|
||||
|
||||
return (this+strikes[i]).subset (c, sbix_len - (unsigned int) strikes[i]);
|
||||
return (this+strikes[i]).subset (c, c->source_blob->length - (unsigned) strikes[i]);
|
||||
}
|
||||
|
||||
bool serialize_strike_offsets (hb_subset_context_t *c,
|
||||
const void *dst_base,
|
||||
unsigned int sbix_len) const
|
||||
bool serialize_strike_offsets (hb_subset_context_t *c, const void *dst_base) const
|
||||
{
|
||||
TRACE_SERIALIZE (this);
|
||||
|
||||
|
@ -369,7 +365,7 @@ struct sbix
|
|||
*o = 0;
|
||||
auto snap = c->serializer->snapshot ();
|
||||
c->serializer->push ();
|
||||
bool ret = add_strike (c, dst_base, i, sbix_len);
|
||||
bool ret = add_strike (c, dst_base, i);
|
||||
if (!ret)
|
||||
{
|
||||
c->serializer->pop_discard ();
|
||||
|
@ -396,11 +392,8 @@ struct sbix
|
|||
if (unlikely (!sbix_prime)) return_trace (false);
|
||||
if (unlikely (!c->serializer->embed (this->version))) return_trace (false);
|
||||
if (unlikely (!c->serializer->embed (this->flags))) return_trace (false);
|
||||
hb_blob_ptr_t<sbix> table = hb_sanitize_context_t ().reference_table<sbix> (c->plan->source);
|
||||
const unsigned int sbix_len = table.get_blob ()->length;
|
||||
table.destroy ();
|
||||
|
||||
return_trace (serialize_strike_offsets (c, sbix_prime, sbix_len));
|
||||
return_trace (serialize_strike_offsets (c, sbix_prime));
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
@ -409,25 +409,19 @@ struct gvar
|
|||
unsigned int num_glyphs = c->plan->num_output_glyphs ();
|
||||
out->glyphCount = num_glyphs;
|
||||
|
||||
hb_blob_ptr_t<gvar> table = hb_sanitize_context_t ().reference_table<gvar> (c->plan->source);
|
||||
|
||||
unsigned int subset_data_size = 0;
|
||||
for (hb_codepoint_t gid = 0; gid < num_glyphs; gid++)
|
||||
{
|
||||
hb_codepoint_t old_gid;
|
||||
if (!c->plan->old_gid_for_new_gid (gid, &old_gid)) continue;
|
||||
subset_data_size += get_glyph_var_data_bytes (table.get_blob (), old_gid).length;
|
||||
subset_data_size += get_glyph_var_data_bytes (c->source_blob, old_gid).length;
|
||||
}
|
||||
|
||||
bool long_offset = subset_data_size & ~0xFFFFu;
|
||||
out->flags = long_offset ? 1 : 0;
|
||||
|
||||
HBUINT8 *subset_offsets = c->serializer->allocate_size<HBUINT8> ((long_offset ? 4 : 2) * (num_glyphs + 1));
|
||||
if (!subset_offsets)
|
||||
{
|
||||
table.destroy ();
|
||||
return_trace (false);
|
||||
}
|
||||
if (!subset_offsets) return_trace (false);
|
||||
|
||||
/* shared tuples */
|
||||
if (!sharedTupleCount || !sharedTuples)
|
||||
|
@ -436,29 +430,21 @@ struct gvar
|
|||
{
|
||||
unsigned int shared_tuple_size = F2DOT14::static_size * axisCount * sharedTupleCount;
|
||||
F2DOT14 *tuples = c->serializer->allocate_size<F2DOT14> (shared_tuple_size);
|
||||
if (!tuples)
|
||||
{
|
||||
table.destroy ();
|
||||
return_trace (false);
|
||||
}
|
||||
if (!tuples) return_trace (false);
|
||||
out->sharedTuples = (char *) tuples - (char *) out;
|
||||
memcpy (tuples, &(this+sharedTuples), shared_tuple_size);
|
||||
}
|
||||
|
||||
char *subset_data = c->serializer->allocate_size<char> (subset_data_size);
|
||||
if (!subset_data)
|
||||
{
|
||||
table.destroy ();
|
||||
return_trace (false);
|
||||
}
|
||||
out->dataZ = subset_data - (char *)out;
|
||||
if (!subset_data) return_trace (false);
|
||||
out->dataZ = subset_data - (char *) out;
|
||||
|
||||
unsigned int glyph_offset = 0;
|
||||
for (hb_codepoint_t gid = 0; gid < num_glyphs; gid++)
|
||||
{
|
||||
hb_codepoint_t old_gid;
|
||||
hb_bytes_t var_data_bytes = c->plan->old_gid_for_new_gid (gid, &old_gid)
|
||||
? get_glyph_var_data_bytes (table.get_blob (), old_gid)
|
||||
? get_glyph_var_data_bytes (c->source_blob, old_gid)
|
||||
: hb_bytes_t ();
|
||||
|
||||
if (long_offset)
|
||||
|
@ -476,7 +462,6 @@ struct gvar
|
|||
else
|
||||
((HBUINT16 *) subset_offsets)[num_glyphs] = glyph_offset / 2;
|
||||
|
||||
table.destroy ();
|
||||
return_trace (true);
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ _subset (hb_subset_plan_t *plan)
|
|||
retry:
|
||||
hb_serialize_context_t serializer ((void *) buf, buf_size);
|
||||
serializer.start_serialize<TableType> ();
|
||||
hb_subset_context_t c (plan, &serializer);
|
||||
hb_subset_context_t c (source_blob, plan, &serializer);
|
||||
bool needed = table->subset (&c);
|
||||
if (serializer.ran_out_of_room)
|
||||
{
|
||||
|
|
|
@ -54,12 +54,15 @@ struct hb_subset_context_t :
|
|||
dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN
|
||||
( _dispatch (obj, hb_prioritize, hb_forward<Ts> (ds)...) )
|
||||
|
||||
hb_blob_t *source_blob;
|
||||
hb_subset_plan_t *plan;
|
||||
hb_serialize_context_t *serializer;
|
||||
unsigned int debug_depth;
|
||||
|
||||
hb_subset_context_t (hb_subset_plan_t *plan_,
|
||||
hb_subset_context_t (hb_blob_t *source_blob_,
|
||||
hb_subset_plan_t *plan_,
|
||||
hb_serialize_context_t *serializer_) :
|
||||
source_blob (source_blob_),
|
||||
plan (plan_),
|
||||
serializer (serializer_),
|
||||
debug_depth (0) {}
|
||||
|
|
Loading…
Reference in New Issue