[subset] start_embed never returns nullptr

Remove checks.
pull/4264/head
Behdad Esfahbod 1 year ago
parent c2eaedd2cd
commit 82741304d3
  1. 8
      src/OT/Color/CBDT/CBDT.hh
  2. 3
      src/OT/Color/COLR/COLR.hh
  3. 5
      src/OT/Color/sbix/sbix.hh
  4. 3
      src/OT/Layout/GDEF/GDEF.hh
  5. 1
      src/OT/Layout/GPOS/AnchorFormat3.hh
  6. 1
      src/OT/Layout/GPOS/CursivePosFormat1.hh
  7. 1
      src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh
  8. 5
      src/OT/glyf/glyf.hh
  9. 3
      src/OT/name/name.hh
  10. 2
      src/hb-ot-cff-common.hh
  11. 8
      src/hb-ot-cmap-table.hh
  12. 3
      src/hb-ot-hdmx-table.hh
  13. 3
      src/hb-ot-hmtx-table.hh
  14. 14
      src/hb-ot-layout-common.hh
  15. 6
      src/hb-ot-layout-gsubgpos.hh
  16. 4
      src/hb-ot-math-table.hh
  17. 3
      src/hb-ot-post-table.hh
  18. 2
      src/hb-ot-stat-table.hh
  19. 1
      src/hb-ot-var-common.hh
  20. 2
      src/hb-ot-vorg-table.hh
  21. 31
      src/hb-subset-cff1.cc
  22. 20
      src/hb-subset-cff2.cc

@ -397,7 +397,6 @@ struct IndexSubtableRecord
TRACE_SERIALIZE (this);
auto *subtable = c->serializer->start_embed<IndexSubtable> ();
if (unlikely (!subtable)) return_trace (false);
if (unlikely (!c->serializer->extend_min (subtable))) return_trace (false);
auto *old_subtable = get_subtable (base);
@ -577,9 +576,6 @@ struct IndexSubtableArray
{
TRACE_SUBSET (this);
auto *dst = c->serializer->start_embed<IndexSubtableArray> ();
if (unlikely (!dst)) return_trace (false);
hb_vector_t<hb_pair_t<hb_codepoint_t, const IndexSubtableRecord*>> lookup;
build_lookup (c, bitmap_size_context, &lookup);
if (unlikely (!c->serializer->propagate_error (lookup)))
@ -994,12 +990,10 @@ CBLC::subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);
auto *cblc_prime = c->serializer->start_embed<CBLC> ();
// Use a vector as a secondary buffer as the tables need to be built in parallel.
hb_vector_t<char> cbdt_prime;
if (unlikely (!cblc_prime)) return_trace (false);
auto *cblc_prime = c->serializer->start_embed<CBLC> ();
if (unlikely (!c->serializer->extend_min (cblc_prime))) return_trace (false);
cblc_prime->version = version;

@ -409,7 +409,6 @@ struct ColorLine
{
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (this);
if (unlikely (!out)) return_trace (false);
if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
if (!c->serializer->check_assign (out->extend, extend, HB_SERIALIZE_ERROR_INT_OVERFLOW)) return_trace (false);
@ -2167,7 +2166,7 @@ struct COLR
if (version == 0 && (!base_it || !layer_it))
return_trace (false);
COLR *colr_prime = c->serializer->start_embed<COLR> ();
auto *colr_prime = c->serializer->start_embed<COLR> ();
if (unlikely (!c->serializer->extend_min (colr_prime))) return_trace (false);
if (version == 0)

@ -48,7 +48,6 @@ struct SBIXGlyph
{
TRACE_SERIALIZE (this);
SBIXGlyph* new_glyph = c->start_embed<SBIXGlyph> ();
if (unlikely (!new_glyph)) return_trace (nullptr);
if (unlikely (!c->extend_min (new_glyph))) return_trace (nullptr);
new_glyph->xOffset = xOffset;
@ -143,7 +142,6 @@ struct SBIXStrike
unsigned int num_output_glyphs = c->plan->num_output_glyphs ();
auto* out = c->serializer->start_embed<SBIXStrike> ();
if (unlikely (!out)) return_trace (false);
auto snap = c->serializer->snapshot ();
if (unlikely (!c->serializer->extend (out, num_output_glyphs + 1))) return_trace (false);
out->ppem = ppem;
@ -388,7 +386,6 @@ struct sbix
TRACE_SERIALIZE (this);
auto *out = c->serializer->start_embed<Array32OfOffset32To<SBIXStrike>> ();
if (unlikely (!out)) return_trace (false);
if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
hb_vector_t<Offset32To<SBIXStrike>*> new_strikes;
@ -423,8 +420,6 @@ struct sbix
{
TRACE_SUBSET (this);
sbix *sbix_prime = c->serializer->start_embed<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);

@ -49,8 +49,6 @@ struct AttachPoint : Array16Of<HBUINT16>
{
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (*this);
if (unlikely (!out)) return_trace (false);
return_trace (out->serialize (c->serializer, + iter ()));
}
};
@ -202,7 +200,6 @@ struct CaretValueFormat3
{
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (*this);
if (unlikely (!out)) return_trace (false);
if (!c->serializer->embed (caretValueFormat)) return_trace (false);
if (!c->serializer->embed (coordinate)) return_trace (false);

@ -45,7 +45,6 @@ struct AnchorFormat3
{
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (*this);
if (unlikely (!out)) return_trace (false);
if (unlikely (!c->serializer->embed (format))) return_trace (false);
if (unlikely (!c->serializer->embed (xCoordinate))) return_trace (false);
if (unlikely (!c->serializer->embed (yCoordinate))) return_trace (false);

@ -278,7 +278,6 @@ struct CursivePosFormat1
const hb_map_t &glyph_map = *c->plan->glyph_map;
auto *out = c->serializer->start_embed (*this);
if (unlikely (!out)) return_trace (false);
auto it =
+ hb_zip (this+coverage, entryExitRecord)

@ -191,7 +191,6 @@ struct ReverseChainSingleSubstFormat1
TRACE_SERIALIZE (this);
auto *out = c->serializer->start_embed (this);
if (unlikely (!c->serializer->check_success (out))) return_trace (false);
if (unlikely (!c->serializer->embed (this->format))) return_trace (false);
if (unlikely (!c->serializer->embed (this->coverage))) return_trace (false);

@ -126,9 +126,8 @@ struct glyf
padded_offsets.push (g.length ());
}
glyf *glyf_prime = c->serializer->start_embed <glyf> ();
bool result = glyf_prime &&
glyf_prime->serialize (c->serializer, hb_iter (glyphs), use_short_loca, c->plan);
auto *glyf_prime = c->serializer->start_embed <glyf> ();
bool result = glyf_prime->serialize (c->serializer, hb_iter (glyphs), use_short_loca, c->plan);
if (c->plan->normalized_coords && !c->plan->pinned_at_default)
_free_compiled_subset_glyphs (glyphs);

@ -386,8 +386,7 @@ struct name
{
TRACE_SUBSET (this);
name *name_prime = c->serializer->start_embed<name> ();
if (unlikely (!name_prime)) return_trace (false);
auto *name_prime = c->serializer->start_embed<name> ();
#ifdef HB_EXPERIMENTAL_API
const hb_hashmap_t<hb_ot_name_record_ids_t, hb_bytes_t> *name_table_overrides =

@ -245,7 +245,7 @@ struct CFFIndexOf : CFFIndex<COUNT>
for (unsigned int i = 0; i < dataArrayLen; i++)
{
TYPE *dest = c->start_embed<TYPE> ();
if (unlikely (!dest || !dest->serialize (c, dataArray[i], param1, param2)))
if (unlikely (!dest->serialize (c, dataArray[i], param1, param2)))
return_trace (false);
}
return_trace (true);

@ -924,8 +924,7 @@ struct DefaultUVS : SortedArray32Of<UnicodeValueRange>
DefaultUVS* copy (hb_serialize_context_t *c,
const hb_set_t *unicodes) const
{
DefaultUVS *out = c->start_embed<DefaultUVS> ();
if (unlikely (!out)) return nullptr;
auto *out = c->start_embed<DefaultUVS> ();
auto snap = c->snapshot ();
HBUINT32 len;
@ -1074,9 +1073,7 @@ struct NonDefaultUVS : SortedArray32Of<UVSMapping>
const hb_set_t *glyphs_requested,
const hb_map_t *glyph_map) const
{
NonDefaultUVS *out = c->start_embed<NonDefaultUVS> ();
if (unlikely (!out)) return nullptr;
auto *out = c->start_embed<NonDefaultUVS> ();
auto it =
+ as_array ()
| hb_filter ([&] (const UVSMapping& _)
@ -1774,7 +1771,6 @@ struct cmap
TRACE_SUBSET (this);
cmap *cmap_prime = c->serializer->start_embed<cmap> ();
if (unlikely (!c->serializer->check_success (cmap_prime))) return_trace (false);
auto encodingrec_iter =
+ hb_iter (encodingRecord)

@ -116,8 +116,7 @@ struct hdmx
{
TRACE_SUBSET (this);
hdmx *hdmx_prime = c->serializer->start_embed <hdmx> ();
if (unlikely (!hdmx_prime)) return_trace (false);
auto *hdmx_prime = c->serializer->start_embed <hdmx> ();
unsigned num_input_glyphs = get_num_glyphs ();
auto it =

@ -190,8 +190,7 @@ struct hmtxvmtx
{
TRACE_SUBSET (this);
T *table_prime = c->serializer->start_embed <T> ();
if (unlikely (!table_prime)) return_trace (false);
auto *table_prime = c->serializer->start_embed <T> ();
accelerator_t _mtx (c->plan->source);
unsigned num_long_metrics;

@ -810,7 +810,7 @@ struct Feature
{
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (*this);
if (unlikely (!out || !c->serializer->extend_min (out))) return_trace (false);
if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
out->featureParams.serialize_subset (c, featureParams, this, tag);
@ -984,7 +984,7 @@ struct RecordListOfFeature : RecordListOf<Feature>
{
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (*this);
if (unlikely (!out || !c->serializer->extend_min (out))) return_trace (false);
if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
+ hb_enumerate (*this)
| hb_filter (l->feature_index_map, hb_first)
@ -1081,7 +1081,7 @@ struct LangSys
{
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (*this);
if (unlikely (!out || !c->serializer->extend_min (out))) return_trace (false);
if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
const uint32_t *v;
out->reqFeatureIndex = l->feature_index_map->has (reqFeatureIndex, &v) ? *v : 0xFFFFu;
@ -1191,7 +1191,7 @@ struct Script
return false;
auto *out = c->serializer->start_embed (*this);
if (unlikely (!out || !c->serializer->extend_min (out))) return_trace (false);
if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
bool defaultLang = false;
if (has_default_lang_sys ())
@ -1250,7 +1250,7 @@ struct RecordListOfScript : RecordListOf<Script>
{
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (*this);
if (unlikely (!out || !c->serializer->extend_min (out))) return_trace (false);
if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
for (auto _ : + hb_enumerate (*this))
{
@ -1370,7 +1370,7 @@ struct Lookup
{
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (*this);
if (unlikely (!out || !c->serializer->extend_min (out))) return_trace (false);
if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
out->lookupType = lookupType;
out->lookupFlag = lookupFlag;
@ -1459,7 +1459,7 @@ struct LookupOffsetList : List16OfOffsetTo<TLookup, OffsetType>
{
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (this);
if (unlikely (!out || !c->serializer->extend_min (out))) return_trace (false);
if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
+ hb_enumerate (*this)
| hb_filter (l->lookup_index_map, hb_first)

@ -3014,8 +3014,6 @@ struct ChainRule
const hb_map_t *lookahead_map = nullptr) const
{
TRACE_SERIALIZE (this);
auto *out = c->start_embed (this);
if (unlikely (!out)) return_trace (false);
const hb_map_t *mapping = backtrack_map;
serialize_array (c, backtrack.len, + backtrack.iter ()
@ -3849,8 +3847,6 @@ struct ChainContextFormat3
{
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (this);
if (unlikely (!out)) return_trace (false);
if (unlikely (!c->serializer->embed (this->format))) return_trace (false);
if (!serialize_coverage_offsets (c, backtrack.iter (), this))
@ -3974,7 +3970,7 @@ struct ExtensionFormat1
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (this);
if (unlikely (!out || !c->serializer->extend_min (out))) return_trace (false);
if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
out->format = format;
out->extensionLookupType = extensionLookupType;

@ -73,7 +73,6 @@ struct MathConstants
{
TRACE_SERIALIZE (this);
auto *out = c->start_embed (this);
if (unlikely (!out)) return_trace (nullptr);
HBINT16 *p = c->allocate_size<HBINT16> (HBINT16::static_size * 2);
if (unlikely (!p)) return_trace (nullptr);
@ -310,7 +309,6 @@ struct MathKern
{
TRACE_SERIALIZE (this);
auto *out = c->start_embed (this);
if (unlikely (!out)) return_trace (nullptr);
if (unlikely (!c->embed (heightCount))) return_trace (nullptr);
@ -757,8 +755,6 @@ struct MathGlyphAssembly
bool subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (*this);
if (unlikely (!out)) return_trace (false);
if (!c->serializer->copy (italicsCorrection, this)) return_trace (false);
if (!c->serializer->copy<HBUINT16> (partRecords.len)) return_trace (false);

@ -96,8 +96,7 @@ struct post
bool subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);
post *post_prime = c->serializer->start_embed<post> ();
if (unlikely (!post_prime)) return_trace (false);
auto *post_prime = c->serializer->start_embed<post> ();
bool glyph_names = c->plan->flags & HB_SUBSET_FLAGS_GLYPH_NAMES;
if (!serialize (c->serializer, glyph_names))

@ -448,8 +448,6 @@ struct AxisValueOffsetArray: UnsizedArrayOf<Offset16To<AxisValue>>
const hb_array_t<const StatAxisRecord> axis_records) const
{
TRACE_SUBSET (this);
auto *out = c->serializer->start_embed (this);
if (unlikely (!out)) return_trace (false);
auto axisValueOffsets = as_array (axisValueCount);
count = 0;

@ -41,7 +41,6 @@ struct DeltaSetIndexMapFormat01
{
TRACE_SERIALIZE (this);
auto *out = c->start_embed (this);
if (unlikely (!out)) return_trace (nullptr);
unsigned total_size = min_size + mapCount * get_width ();
HBUINT8 *p = c->allocate_size<HBUINT8> (total_size);

@ -90,7 +90,7 @@ struct VORG
bool subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);
VORG *vorg_prime = c->serializer->start_embed<VORG> ();
auto *vorg_prime = c->serializer->start_embed<VORG> ();
if (unlikely (!c->serializer->check_success (vorg_prime))) return_trace (false);
auto it =

@ -745,8 +745,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c,
objidx_t subrs_link = 0;
if (plan.subset_localsubrs[i].length > 0)
{
CFF1Subrs *dest = c->start_embed <CFF1Subrs> ();
if (unlikely (!dest)) return false;
auto *dest = c->start_embed <CFF1Subrs> ();
c->push ();
if (likely (dest && dest->serialize (c, plan.subset_localsubrs[i])))
subrs_link = c->pop_pack ();
@ -757,8 +756,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c,
}
}
PrivateDict *pd = c->start_embed<PrivateDict> ();
if (unlikely (!pd)) return false;
auto *pd = c->start_embed<PrivateDict> ();
c->push ();
cff1_private_dict_op_serializer_t privSzr (plan.desubroutinize, plan.drop_hints);
/* N.B. local subrs immediately follows its corresponding private dict. i.e., subr offset == private dict size */
@ -787,9 +785,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c,
if (unlikely (!c->start_zerocopy (total_size)))
return false;
CFF1CharStrings *cs = c->start_embed<CFF1CharStrings> ();
if (unlikely (!cs)) return false;
auto *cs = c->start_embed<CFF1CharStrings> ();
if (likely (cs->serialize (c, plan.subset_charstrings)))
plan.info.char_strings_link = c->pop_pack (false);
else
@ -802,8 +798,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c,
/* FDArray (FD Index) */
if (acc.fdArray != &Null (CFF1FDArray))
{
CFF1FDArray *fda = c->start_embed<CFF1FDArray> ();
if (unlikely (!fda)) return false;
auto *fda = c->start_embed<CFF1FDArray> ();
c->push ();
cff1_font_dict_op_serializer_t fontSzr;
auto it = + hb_zip (+ hb_iter (plan.fontdicts_mod), + hb_iter (plan.fontdicts_mod));
@ -834,8 +829,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c,
/* Charset */
if (plan.subset_charset)
{
Charset *dest = c->start_embed<Charset> ();
if (unlikely (!dest)) return false;
auto *dest = c->start_embed<Charset> ();
c->push ();
if (likely (dest->serialize (c,
plan.subset_charset_format,
@ -852,8 +846,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c,
/* Encoding */
if (plan.subset_encoding)
{
Encoding *dest = c->start_embed<Encoding> ();
if (unlikely (!dest)) return false;
auto *dest = c->start_embed<Encoding> ();
c->push ();
if (likely (dest->serialize (c,
plan.subset_enc_format,
@ -871,8 +864,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c,
/* global subrs */
{
c->push ();
CFF1Subrs *dest = c->start_embed <CFF1Subrs> ();
if (unlikely (!dest)) return false;
auto *dest = c->start_embed <CFF1Subrs> ();
if (likely (dest->serialize (c, plan.subset_globalsubrs)))
c->pop_pack (false);
else
@ -884,8 +876,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c,
/* String INDEX */
{
CFF1StringIndex *dest = c->start_embed<CFF1StringIndex> ();
if (unlikely (!dest)) return false;
auto *dest = c->start_embed<CFF1StringIndex> ();
c->push ();
if (likely (dest->serialize (c, *acc.stringIndex, plan.sidmap)))
c->pop_pack ();
@ -912,8 +903,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c,
/* top dict INDEX */
{
/* serialize singleton TopDict */
TopDict *top = c->start_embed<TopDict> ();
if (!top) return false;
auto *top = c->start_embed<TopDict> ();
c->push ();
cff1_top_dict_op_serializer_t topSzr;
unsigned top_size = 0;
@ -929,8 +919,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c,
return false;
}
/* serialize INDEX header for above */
CFF1Index *dest = c->start_embed<CFF1Index> ();
if (!dest) return false;
auto *dest = c->start_embed<CFF1Index> ();
return dest->serialize_header (c, hb_iter (hb_array_t<unsigned> (&top_size, 1)));
}
}

@ -524,8 +524,7 @@ static bool _serialize_cff2 (hb_serialize_context_t *c,
if (plan.subset_localsubrs[i].length > 0)
{
CFF2Subrs *dest = c->start_embed <CFF2Subrs> ();
if (unlikely (!dest)) return false;
auto *dest = c->start_embed <CFF2Subrs> ();
c->push ();
if (likely (dest->serialize (c, plan.subset_localsubrs[i])))
subrs_link = c->pop_pack (false);
@ -535,8 +534,7 @@ static bool _serialize_cff2 (hb_serialize_context_t *c,
return false;
}
}
PrivateDict *pd = c->start_embed<PrivateDict> ();
if (unlikely (!pd)) return false;
auto *pd = c->start_embed<PrivateDict> ();
c->push ();
cff2_private_dict_op_serializer_t privSzr (plan.desubroutinize, plan.drop_hints, plan.pinned,
acc.varStore, normalized_coords);
@ -562,9 +560,7 @@ static bool _serialize_cff2 (hb_serialize_context_t *c,
if (unlikely (!c->start_zerocopy (total_size)))
return false;
CFF2CharStrings *cs = c->start_embed<CFF2CharStrings> ();
if (unlikely (!cs)) return false;
auto *cs = c->start_embed<CFF2CharStrings> ();
if (likely (cs->serialize (c, plan.subset_charstrings)))
plan.info.char_strings_link = c->pop_pack (false);
else
@ -593,8 +589,7 @@ static bool _serialize_cff2 (hb_serialize_context_t *c,
/* FDArray (FD Index) */
{
c->push ();
CFF2FDArray *fda = c->start_embed<CFF2FDArray> ();
if (unlikely (!fda)) return false;
auto *fda = c->start_embed<CFF2FDArray> ();
cff_font_dict_op_serializer_t fontSzr;
auto it =
+ hb_zip (+ hb_iter (acc.fontDicts)
@ -611,8 +606,8 @@ static bool _serialize_cff2 (hb_serialize_context_t *c,
!plan.pinned)
{
c->push ();
CFF2VariationStore *dest = c->start_embed<CFF2VariationStore> ();
if (unlikely (!dest || !dest->serialize (c, acc.varStore))) return false;
auto *dest = c->start_embed<CFF2VariationStore> ();
if (unlikely (!dest->serialize (c, acc.varStore))) return false;
plan.info.var_store_link = c->pop_pack (false);
}
@ -634,8 +629,7 @@ static bool _serialize_cff2 (hb_serialize_context_t *c,
/* global subrs */
{
CFF2Subrs *dest = c->start_embed <CFF2Subrs> ();
if (unlikely (!dest)) return false;
auto *dest = c->start_embed <CFF2Subrs> ();
return dest->serialize (c, plan.subset_globalsubrs);
}
}

Loading…
Cancel
Save