[subset] Rename src_base args to base to match sanitize methods

So it will become easier to follow that serialize methods signatures should
match with their sanitize methods counterparts.
This commit is contained in:
Ebrahim Byagowi 2020-03-08 23:39:24 +03:30
parent 188a0a47c2
commit 07acd1a042
7 changed files with 108 additions and 148 deletions

View File

@ -313,10 +313,8 @@ struct OffsetTo : Offset<OffsetType, has_null>
}
template <typename ...Ts>
bool serialize_subset (hb_subset_context_t *c,
const OffsetTo& src,
const void *src_base,
Ts&&... ds)
bool serialize_subset (hb_subset_context_t *c, const OffsetTo& src,
const void *src_base, Ts&&... ds)
{
*this = 0;
if (src.is_null ())
@ -341,10 +339,8 @@ struct OffsetTo : Offset<OffsetType, has_null>
* Can't compile: whence = hb_serialize_context_t::Head followed by Ts&&...
*/
template <typename ...Ts>
bool serialize_copy (hb_serialize_context_t *c,
const OffsetTo& src,
const void *src_base,
unsigned dst_bias,
bool serialize_copy (hb_serialize_context_t *c, const OffsetTo& src,
const void *src_base, unsigned dst_bias,
hb_serialize_context_t::whence_t whence,
Ts&&... ds)
{
@ -361,10 +357,8 @@ struct OffsetTo : Offset<OffsetType, has_null>
return ret;
}
bool serialize_copy (hb_serialize_context_t *c,
const OffsetTo& src,
const void *src_base,
unsigned dst_bias = 0)
bool serialize_copy (hb_serialize_context_t *c, const OffsetTo& src,
const void *src_base, unsigned dst_bias = 0)
{ return serialize_copy (c, src, src_base, dst_bias, hb_serialize_context_t::Head); }
bool sanitize_shallow (hb_sanitize_context_t *c, const void *base) const

View File

@ -892,7 +892,7 @@ struct VariationSelectorRecord
const hb_set_t *unicodes,
const hb_set_t *glyphs,
const hb_map_t *glyph_map,
const void *src_base) const
const void *base) const
{
auto snap = c->snapshot ();
auto *out = c->embed<VariationSelectorRecord> (*this);
@ -905,7 +905,7 @@ struct VariationSelectorRecord
if (nonDefaultUVS != 0)
{
c->push ();
if (c->copy (src_base+nonDefaultUVS, unicodes, glyphs, glyph_map))
if (c->copy (base+nonDefaultUVS, unicodes, glyphs, glyph_map))
non_default_uvs_objidx = c->pop_pack ();
else c->pop_discard ();
}
@ -914,7 +914,7 @@ struct VariationSelectorRecord
if (defaultUVS != 0)
{
c->push ();
if (c->copy (src_base+defaultUVS, unicodes))
if (c->copy (base+defaultUVS, unicodes))
default_uvs_objidx = c->pop_pack ();
else c->pop_discard ();
}
@ -956,7 +956,7 @@ struct CmapSubtableFormat14
const hb_set_t *unicodes,
const hb_set_t *glyphs,
const hb_map_t *glyph_map,
const void *src_base)
const void *base)
{
auto snap = c->snapshot ();
unsigned table_initpos = c->length ();
@ -965,7 +965,7 @@ struct CmapSubtableFormat14
if (unlikely (!c->extend_min (*this))) return;
this->format = 14;
auto src_tbl = reinterpret_cast<const CmapSubtableFormat14*> (src_base);
auto src_tbl = reinterpret_cast<const CmapSubtableFormat14*> (base);
/*
* Some versions of OTS require that offsets are in order. Due to the use
@ -983,8 +983,7 @@ struct CmapSubtableFormat14
hb_vector_t<hb_pair_t<unsigned, unsigned>> obj_indices;
for (int i = src_tbl->record.len - 1; i >= 0; i--)
{
hb_pair_t<unsigned, unsigned> result =
src_tbl->record[i].copy (c, unicodes, glyphs, glyph_map, src_base);
hb_pair_t<unsigned, unsigned> result = src_tbl->record[i].copy (c, unicodes, glyphs, glyph_map, base);
if (result.first || result.second)
obj_indices.push (result);
}
@ -1102,12 +1101,12 @@ struct CmapSubtable
Iterator it,
unsigned format,
const hb_subset_plan_t *plan,
const void *src_base)
const void *base)
{
switch (format) {
case 4: u.format4.serialize (c, it); return;
case 12: u.format12.serialize (c, it); return;
case 14: u.format14.serialize (c, plan->unicodes, plan->_glyphset, plan->glyph_map, src_base); return;
case 4: return u.format4.serialize (c, it);
case 12: return u.format12.serialize (c, it);
case 14: return u.format14.serialize (c, plan->unicodes, plan->_glyphset, plan->glyph_map, base);
default: return;
}
}
@ -1168,7 +1167,7 @@ struct EncodingRecord
EncodingRecord* copy (hb_serialize_context_t *c,
Iterator it,
unsigned format,
const void *src_base,
const void *base,
const hb_subset_plan_t *plan,
/* INOUT */ unsigned *objidx) const
{
@ -1182,7 +1181,7 @@ struct EncodingRecord
{
CmapSubtable *cmapsubtable = c->push<CmapSubtable> ();
unsigned origin_length = c->length ();
cmapsubtable->serialize (c, it, format, plan, &(src_base+subtable));
cmapsubtable->serialize (c, it, format, plan, &(base+subtable));
if (c->length () - origin_length > 0) *objidx = c->pop_pack ();
else c->pop_discard ();
}
@ -1214,7 +1213,7 @@ struct cmap
void serialize (hb_serialize_context_t *c,
Iterator it,
EncodingRecIter encodingrec_iter,
const void *src_base,
const void *base,
const hb_subset_plan_t *plan)
{
if (unlikely (!c->extend_min ((*this)))) return;
@ -1225,13 +1224,13 @@ struct cmap
for (const EncodingRecord& _ : encodingrec_iter)
{
hb_set_t unicodes_set;
(src_base+_.subtable).collect_unicodes (&unicodes_set);
(base+_.subtable).collect_unicodes (&unicodes_set);
unsigned format = (src_base+_.subtable).u.format;
unsigned format = (base+_.subtable).u.format;
if (format == 4) c->copy (_, + it | hb_filter (unicodes_set, hb_first), 4u, src_base, plan, &format4objidx);
else if (format == 12) c->copy (_, + it | hb_filter (unicodes_set, hb_first), 12u, src_base, plan, &format12objidx);
else if (format == 14) c->copy (_, it, 14u, src_base, plan, &format14objidx);
if (format == 4) c->copy (_, + it | hb_filter (unicodes_set, hb_first), 4u, base, plan, &format4objidx);
else if (format == 12) c->copy (_, + it | hb_filter (unicodes_set, hb_first), 12u, base, plan, &format12objidx);
else if (format == 14) c->copy (_, it, 14u, base, plan, &format14objidx);
}
c->check_assign(this->encodingRecord.len, (c->length () - cmap::min_size)/EncodingRecord::static_size);

View File

@ -628,7 +628,7 @@ struct BitmapSizeTable
}
bool
subset (hb_subset_context_t *c, const void *src_base,
subset (hb_subset_context_t *c, const void *base,
const char *cbdt, unsigned int cbdt_length,
hb_vector_t<char> *cbdt_prime /* INOUT */) const
{
@ -647,7 +647,7 @@ struct BitmapSizeTable
if (!out_table->indexSubtableArrayOffset.serialize_subset (c,
indexSubtableArrayOffset,
src_base,
base,
&bitmap_size_context))
return_trace (false);
if (!bitmap_size_context.size ||

View File

@ -142,68 +142,62 @@ struct hb_subset_layout_context_t :
template<typename OutputArray>
struct subset_offset_array_t
{
subset_offset_array_t
(hb_subset_context_t *subset_context,
OutputArray& out,
const void *src_base)
: _subset_context(subset_context), _out (out), _src_base (src_base) {}
subset_offset_array_t (hb_subset_context_t *subset_context_,
OutputArray& out_,
const void *base_) : subset_context (subset_context_),
out (out_), base (base_) {}
template <typename T>
bool
operator ()
(T&& offset)
bool operator () (T&& offset)
{
auto *o = _out.serialize_append (_subset_context->serializer);
auto *o = out.serialize_append (subset_context->serializer);
if (unlikely (!o)) return false;
auto snap = _subset_context->serializer->snapshot ();
bool ret = o->serialize_subset (_subset_context, offset, _src_base);
auto snap = subset_context->serializer->snapshot ();
bool ret = o->serialize_subset (subset_context, offset, base);
if (!ret)
{
_out.pop ();
_subset_context->serializer->revert (snap);
out.pop ();
subset_context->serializer->revert (snap);
}
return ret;
}
private:
hb_subset_context_t *_subset_context;
OutputArray &_out;
const void *_src_base;
hb_subset_context_t *subset_context;
OutputArray &out;
const void *base;
};
template<typename OutputArray, typename Arg>
struct subset_offset_array_arg_t
{
subset_offset_array_arg_t
(hb_subset_context_t *subset_context,
OutputArray& out,
const void *src_base,
Arg &&arg)
: _subset_context(subset_context), _out (out), _src_base (src_base), _arg (arg) {}
subset_offset_array_arg_t (hb_subset_context_t *subset_context_,
OutputArray& out_,
const void *base_,
Arg &&arg_) : subset_context (subset_context_), out (out_),
base (base_), arg (arg_) {}
template <typename T>
bool
operator ()
(T&& offset)
bool operator () (T&& offset)
{
auto *o = _out.serialize_append (_subset_context->serializer);
auto *o = out.serialize_append (subset_context->serializer);
if (unlikely (!o)) return false;
auto snap = _subset_context->serializer->snapshot ();
bool ret = o->serialize_subset (_subset_context, offset, _src_base, _arg);
auto snap = subset_context->serializer->snapshot ();
bool ret = o->serialize_subset (subset_context, offset, base, arg);
if (!ret)
{
_out.pop ();
_subset_context->serializer->revert (snap);
out.pop ();
subset_context->serializer->revert (snap);
}
return ret;
}
private:
hb_subset_context_t *_subset_context;
OutputArray &_out;
const void *_src_base;
Arg &&_arg;
hb_subset_context_t *subset_context;
OutputArray &out;
const void *base;
Arg &&arg;
};
/*
@ -215,52 +209,40 @@ struct
{
template<typename OutputArray>
subset_offset_array_t<OutputArray>
operator ()
(hb_subset_context_t *subset_context,
OutputArray& out,
const void *src_base) const
{
return subset_offset_array_t<OutputArray> (subset_context, out, src_base);
}
operator () (hb_subset_context_t *subset_context, OutputArray& out,
const void *base) const
{ return subset_offset_array_t<OutputArray> (subset_context, out, base); }
/* Variant with one extra argument passed to serialize_subset */
template<typename OutputArray, typename Arg>
subset_offset_array_arg_t<OutputArray, Arg>
operator ()
(hb_subset_context_t *subset_context,
OutputArray& out,
const void *src_base,
Arg &&arg) const
{
return subset_offset_array_arg_t<OutputArray, Arg> (subset_context, out, src_base, arg);
}
operator () (hb_subset_context_t *subset_context, OutputArray& out,
const void *base, Arg &&arg) const
{ return subset_offset_array_arg_t<OutputArray, Arg> (subset_context, out, base, arg); }
}
HB_FUNCOBJ (subset_offset_array);
template<typename OutputArray>
struct subset_record_array_t
{
subset_record_array_t
(hb_subset_layout_context_t *c,
OutputArray* out,
const void *src_base)
: _subset_layout_context(c), _out (out), _src_base (src_base) {}
subset_record_array_t (hb_subset_layout_context_t *c_, OutputArray* out_,
const void *base_) : subset_layout_context (c_),
out (out_), base (base_) {}
template <typename T>
void
operator ()
(T&& record)
operator () (T&& record)
{
auto snap = _subset_layout_context->subset_context->serializer->snapshot ();
bool ret = record.subset (_subset_layout_context, _src_base);
if (!ret) _subset_layout_context->subset_context->serializer->revert (snap);
else _out->len++;
auto snap = subset_layout_context->subset_context->serializer->snapshot ();
bool ret = record.subset (subset_layout_context, base);
if (!ret) subset_layout_context->subset_context->serializer->revert (snap);
else out->len++;
}
private:
hb_subset_layout_context_t *_subset_layout_context;
OutputArray *_out;
const void *_src_base;
hb_subset_layout_context_t *subset_layout_context;
OutputArray *out;
const void *base;
};
/*
@ -271,13 +253,9 @@ struct
{
template<typename OutputArray>
subset_record_array_t<OutputArray>
operator ()
(hb_subset_layout_context_t *c,
OutputArray* out,
const void *src_base) const
{
return subset_record_array_t<OutputArray> (c, out, src_base);
}
operator () (hb_subset_layout_context_t *c, OutputArray* out,
const void *base) const
{ return subset_record_array_t<OutputArray> (c, out, base); }
}
HB_FUNCOBJ (subset_record_array);
@ -302,13 +280,12 @@ struct Record
{
int cmp (hb_tag_t a) const { return tag.cmp (a); }
bool subset (hb_subset_layout_context_t *c,
const void *src_base) const
bool subset (hb_subset_layout_context_t *c, const void *base) const
{
TRACE_SUBSET (this);
auto *out = c->subset_context->serializer->embed (this);
if (unlikely (!out)) return_trace (false);
bool ret = out->offset.serialize_subset (c->subset_context, offset, src_base, c, &tag);
bool ret = out->offset.serialize_subset (c->subset_context, offset, base, c, &tag);
return_trace (ret);
}
@ -2597,15 +2574,14 @@ struct FeatureTableSubstitutionRecord
feature_indexes->add (featureIndex);
}
bool subset (hb_subset_layout_context_t *c,
const void *src_base) const
bool subset (hb_subset_layout_context_t *c, const void *base) const
{
TRACE_SUBSET (this);
auto *out = c->subset_context->serializer->embed (this);
if (unlikely (!out)) return_trace (false);
out->featureIndex = c->feature_index_map->get (featureIndex);
bool ret = out->feature.serialize_subset (c->subset_context, feature, src_base, c);
bool ret = out->feature.serialize_subset (c->subset_context, feature, base, c);
return_trace (ret);
}
@ -2703,16 +2679,15 @@ struct FeatureVariationRecord
(base+substitutions).closure_features (lookup_indexes, feature_indexes);
}
bool subset (hb_subset_layout_context_t *c,
const void *src_base) const
bool subset (hb_subset_layout_context_t *c, const void *base) const
{
TRACE_SUBSET (this);
auto *out = c->subset_context->serializer->embed (this);
if (unlikely (!out)) return_trace (false);
out->conditions.serialize_subset (c->subset_context, conditions, src_base);
out->conditions.serialize_subset (c->subset_context, conditions, base);
bool ret = out->substitutions.serialize_subset (c->subset_context, substitutions, src_base, c);
bool ret = out->substitutions.serialize_subset (c->subset_context, substitutions, base, c);
return_trace (ret);
}

View File

@ -160,7 +160,7 @@ struct ValueFormat : HBUINT16
return ret;
}
void serialize_copy (hb_serialize_context_t *c, const void *src_base, const Value *values) const
void serialize_copy (hb_serialize_context_t *c, const void *base, const Value *values) const
{
unsigned int format = *this;
if (!format) return;
@ -170,10 +170,10 @@ struct ValueFormat : HBUINT16
if (format & xAdvance) c->copy (*values++);
if (format & yAdvance) c->copy (*values++);
if (format & xPlaDevice) copy_device (c, src_base, values++);
if (format & yPlaDevice) copy_device (c, src_base, values++);
if (format & xAdvDevice) copy_device (c, src_base, values++);
if (format & yAdvDevice) copy_device (c, src_base, values++);
if (format & xPlaDevice) copy_device (c, base, values++);
if (format & yPlaDevice) copy_device (c, base, values++);
if (format & xAdvDevice) copy_device (c, base, values++);
if (format & yAdvDevice) copy_device (c, base, values++);
}
private:
@ -194,7 +194,7 @@ struct ValueFormat : HBUINT16
return true;
}
bool copy_device (hb_serialize_context_t *c, const void *src_base, const Value *src_value) const
bool copy_device (hb_serialize_context_t *c, const void *base, const Value *src_value) const
{
Value *dst_value = c->copy (*src_value);
@ -203,7 +203,7 @@ struct ValueFormat : HBUINT16
*dst_value = 0;
c->push ();
if ((src_base + get_device (src_value)).copy (c))
if ((base + get_device (src_value)).copy (c))
{
c->add_link (*dst_value, c->pop_pack ());
return true;
@ -523,17 +523,15 @@ struct MarkRecord
return_trace (c->check_struct (this) && markAnchor.sanitize (c, base));
}
MarkRecord *copy (hb_serialize_context_t *c,
const void *src_base,
unsigned dst_bias,
const hb_map_t *klass_mapping) const
MarkRecord *copy (hb_serialize_context_t *c, const void *base,
unsigned dst_bias, const hb_map_t *klass_mapping) const
{
TRACE_SERIALIZE (this);
auto *out = c->embed (this);
if (unlikely (!out)) return_trace (nullptr);
out->klass = klass_mapping->get (klass);
out->markAnchor.serialize_copy (c, markAnchor, src_base, dst_bias);
out->markAnchor.serialize_copy (c, markAnchor, base, dst_bias);
return_trace (out);
}
@ -586,13 +584,13 @@ struct MarkArray : ArrayOf<MarkRecord> /* Array of MarkRecords--in Coverage orde
hb_requires (hb_is_source_of (Iterator, MarkRecord))>
bool serialize (hb_serialize_context_t *c,
const hb_map_t *klass_mapping,
const void *src_base,
const void *base,
Iterator it)
{
TRACE_SERIALIZE (this);
if (unlikely (!c->extend_min (*this))) return_trace (false);
if (unlikely (!c->check_assign (len, it.len ()))) return_trace (false);
c->copy_all (it, src_base, c->to_bias (this), klass_mapping);
c->copy_all (it, base, c->to_bias (this), klass_mapping);
return_trace (true);
}
@ -875,7 +873,7 @@ struct PairValueRecord
struct serialize_closure_t
{
const void *src_base;
const void *base;
const ValueFormat *valueFormats;
unsigned len1; /* valueFormats[0].get_len() */
const hb_map_t *glyph_map;
@ -890,8 +888,8 @@ struct PairValueRecord
out->secondGlyph = (*closure->glyph_map)[secondGlyph];
closure->valueFormats[0].serialize_copy (c, closure->src_base, &values[0]);
closure->valueFormats[1].serialize_copy (c, closure->src_base, &values[closure->len1]);
closure->valueFormats[0].serialize_copy (c, closure->base, &values[0]);
closure->valueFormats[1].serialize_copy (c, closure->base, &values[closure->len1]);
return_trace (true);
}
@ -1337,15 +1335,14 @@ struct EntryExitRecord
return_trace (entryAnchor.sanitize (c, base) && exitAnchor.sanitize (c, base));
}
EntryExitRecord* copy (hb_serialize_context_t *c,
const void *src_base) const
EntryExitRecord* copy (hb_serialize_context_t *c, const void *base) const
{
TRACE_SERIALIZE (this);
auto *out = c->embed (this);
if (unlikely (!out)) return_trace (nullptr);
out->entryAnchor.serialize_copy (c, entryAnchor, src_base);
out->exitAnchor.serialize_copy (c, exitAnchor, src_base);
out->entryAnchor.serialize_copy (c, entryAnchor, base);
out->exitAnchor.serialize_copy (c, exitAnchor, base);
return_trace (out);
}
@ -1480,9 +1477,7 @@ struct CursivePosFormat1
template <typename Iterator,
hb_requires (hb_is_iterator (Iterator))>
void serialize (hb_serialize_context_t *c,
Iterator it,
const void *src_base)
void serialize (hb_serialize_context_t *c, Iterator it, const void *base)
{
if (unlikely (!c->extend_min ((*this)))) return;
this->format = 1;
@ -1490,7 +1485,7 @@ struct CursivePosFormat1
for (const EntryExitRecord& entry_record : + it
| hb_map (hb_second))
c->copy (entry_record, src_base);
c->copy (entry_record, base);
auto glyphs =
+ it
@ -1656,7 +1651,7 @@ struct MarkBasePosFormat1
hb_map_t klass_mapping;
Markclass_closure_and_remap_indexes (this+markCoverage, this+markArray, glyphset, &klass_mapping);
if (!klass_mapping.get_population ()) return_trace (false);
out->classCount = klass_mapping.get_population ();
@ -1967,7 +1962,7 @@ struct MarkMarkPosFormat1
hb_map_t klass_mapping;
Markclass_closure_and_remap_indexes (this+mark1Coverage, this+mark1Array, glyphset, &klass_mapping);
if (!klass_mapping.get_population ()) return_trace (false);
out->classCount = klass_mapping.get_population ();

View File

@ -2783,9 +2783,7 @@ struct ChainContextFormat3
template<typename Iterator,
hb_requires (hb_is_iterator (Iterator))>
bool serialize_coverage_offsets (hb_subset_context_t *c,
Iterator it,
const void* src_base) const
bool serialize_coverage_offsets (hb_subset_context_t *c, Iterator it, const void* base) const
{
TRACE_SERIALIZE (this);
auto *out = c->serializer->start_embed<OffsetArrayOf<Coverage>> ();
@ -2793,7 +2791,7 @@ struct ChainContextFormat3
if (unlikely (!c->serializer->allocate_size<HBUINT16> (HBUINT16::static_size))) return_trace (false);
+ it
| hb_apply (subset_offset_array (c, *out, src_base))
| hb_apply (subset_offset_array (c, *out, base))
;
return_trace (out->len);

View File

@ -97,13 +97,12 @@ struct NameRecord
return UNSUPPORTED;
}
NameRecord* copy (hb_serialize_context_t *c,
const void *src_base) const
NameRecord* copy (hb_serialize_context_t *c, const void *base) const
{
TRACE_SERIALIZE (this);
auto *out = c->embed (this);
if (unlikely (!out)) return_trace (nullptr);
out->offset.serialize_copy (c, offset, src_base, 0, hb_serialize_context_t::Tail, length);
out->offset.serialize_copy (c, offset, base, 0, hb_serialize_context_t::Tail, length);
return_trace (out);
}