From 65d28bc5a70e4fbd5e5321f56914ed25749db4c9 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 5 Aug 2022 14:56:07 -0600 Subject: [PATCH] [MultipleSubst] Rewrite serialize() in terms of iterators Unused still, and hence untested --- src/OT/Layout/GSUB/MultipleSubst.hh | 12 ++++++------ src/OT/Layout/GSUB/MultipleSubstFormat1.hh | 18 ++++++++++-------- src/OT/Layout/GSUB/SubstLookup.hh | 17 +++++++++-------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/OT/Layout/GSUB/MultipleSubst.hh b/src/OT/Layout/GSUB/MultipleSubst.hh index 98f2f5fe7..15d726177 100644 --- a/src/OT/Layout/GSUB/MultipleSubst.hh +++ b/src/OT/Layout/GSUB/MultipleSubst.hh @@ -35,19 +35,19 @@ struct MultipleSubst } } - /* TODO This function is unused and not updated to 24bit GIDs. Should be done by using - * iterators. While at it perhaps using iterator of arrays of hb_codepoint_t instead. */ + template bool serialize (hb_serialize_context_t *c, - hb_sorted_array_t glyphs, - hb_array_t substitute_len_list, - hb_array_t substitute_glyphs_list) + GlyphIterator glyphs, + SequenceIterator sequences) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (u.format))) return_trace (false); unsigned int format = 1; u.format = format; switch (u.format) { - case 1: return_trace (u.format1.serialize (c, glyphs, substitute_len_list, substitute_glyphs_list)); + case 1: return_trace (u.format1.serialize (c, glyphs, sequences)); default:return_trace (false); } } diff --git a/src/OT/Layout/GSUB/MultipleSubstFormat1.hh b/src/OT/Layout/GSUB/MultipleSubstFormat1.hh index 89a04ec3b..dbcc6f6df 100644 --- a/src/OT/Layout/GSUB/MultipleSubstFormat1.hh +++ b/src/OT/Layout/GSUB/MultipleSubstFormat1.hh @@ -71,22 +71,24 @@ struct MultipleSubstFormat1_2 return_trace ((this+sequence[index]).apply (c)); } + template bool serialize (hb_serialize_context_t *c, - hb_sorted_array_t glyphs, - hb_array_t substitute_len_list, - hb_array_t substitute_glyphs_list) + GlyphIterator glyphs, + SequenceIterator sequences) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (this))) return_trace (false); if (unlikely (!sequence.serialize (c, glyphs.length))) return_trace (false); - for (unsigned int i = 0; i < glyphs.length; i++) + + for (auto& pair : hb_zip (sequences, sequence)) { - unsigned int substitute_len = substitute_len_list[i]; - if (unlikely (!sequence[i] - .serialize_serialize (c, substitute_glyphs_list.sub_array (0, substitute_len)))) + if (unlikely (!pair.second + .serialize_serialize (c, pair.first))) return_trace (false); - substitute_glyphs_list += substitute_len; } + return_trace (coverage.serialize_serialize (c, glyphs)); } diff --git a/src/OT/Layout/GSUB/SubstLookup.hh b/src/OT/Layout/GSUB/SubstLookup.hh index 320685b86..28db0e428 100644 --- a/src/OT/Layout/GSUB/SubstLookup.hh +++ b/src/OT/Layout/GSUB/SubstLookup.hh @@ -119,19 +119,20 @@ struct SubstLookup : Lookup return_trace (false); } - bool serialize_multiple (hb_serialize_context_t *c, - uint32_t lookup_props, - hb_sorted_array_t glyphs, - hb_array_t substitute_len_list, - hb_array_t substitute_glyphs_list) + template + bool serialize (hb_serialize_context_t *c, + uint32_t lookup_props, + GlyphIterator glyphs, + SequenceIterator sequences) { TRACE_SERIALIZE (this); if (unlikely (!Lookup::serialize (c, SubTable::Multiple, lookup_props, 1))) return_trace (false); if (c->push ()->u.multiple. serialize (c, - glyphs, - substitute_len_list, - substitute_glyphs_list)) + glyphs, + sequences)) { c->add_link (get_subtables ()[0], c->pop_pack ()); return_trace (true);