From: Rod Sheeter Date: Tue, 21 May 2019 18:14:31 +0000 (-0700) Subject: [subset] Write loca using more idiomatic harfbuzzese X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=95445d79be0a79e6e2d384d46819730146d397d8;p=platform%2Fupstream%2FlibHarfBuzzSharp.git [subset] Write loca using more idiomatic harfbuzzese --- diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 4d45a93..3addeb6 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -80,7 +80,8 @@ struct glyf return_trace (true); } - template + template static void _add_loca_and_head (hb_subset_plan_t * plan, Iterator padded_offsets) { @@ -92,9 +93,9 @@ struct glyf char *loca_prime_data = (char *) calloc(1, loca_prime_size); if (use_short_loca) - _write_loca (padded_offsets, 2, loca_prime_data); + _write_loca (padded_offsets, 1, loca_prime_data); else - _write_loca (padded_offsets, 1, loca_prime_data); + _write_loca (padded_offsets, 0, loca_prime_data); hb_blob_t * loca_blob = hb_blob_create (loca_prime_data, loca_prime_size, @@ -108,26 +109,27 @@ struct glyf hb_blob_destroy (loca_blob); } - template + template static void - _write_loca (Iterator it, unsigned size_denom, char * dest) + _write_loca (Iterator it, unsigned right_shift, char * dest) { - // write loca[0] through loca[numGlyphs-1] - EntryType * loca_start = (EntryType *) dest; - EntryType * loca_current = loca_start; + hb_array_t entries ((EntryType *) dest, it.len () + 1); unsigned int offset = 0; + it - | hb_apply ([&] (unsigned int padded_size) { - DEBUG_MSG(SUBSET, nullptr, "loca entry %ld offset %d", loca_current - loca_start, offset); - *loca_current = offset / size_denom; + | hb_map ([&] (unsigned int padded_size) { + unsigned int result = offset >> right_shift; + DEBUG_MSG(SUBSET, nullptr, "loca entry offset %d shifted %d", offset, result); offset += padded_size; - loca_current++; - }); + return result; + }) + | hb_sink ( hb_iter (entries)); // one bonus element so loca[numGlyphs] - loca[numGlyphs -1] is size of last glyph - DEBUG_MSG(SUBSET, nullptr, "loca entry %ld offset %d", loca_current - loca_start, offset); - *loca_current = offset / size_denom; + entries.arrayZ[entries.length - 1] = offset >> right_shift; + DEBUG_MSG(SUBSET, nullptr, "loca entry offset %d", (int16_t) entries.arrayZ[entries.length - 1]); } + // requires source of SubsetGlyph complains the identifier isn't declared template bool serialize(hb_serialize_context_t *c, Iterator it, @@ -169,7 +171,7 @@ struct glyf template void _populate_subset_glyphs (const hb_subset_plan_t * plan, - hb_vector_t * glyphs /* OUT */) const + hb_vector_t * glyphs /* OUT */) const { OT::glyf::accelerator_t glyf; glyf.init (plan->source); @@ -311,6 +313,7 @@ struct glyf return size; } + // TODO rewrite using new iterator framework if possible struct Iterator { const char *glyph_start;