From: Rod Sheeter Date: Tue, 21 May 2019 19:38:53 +0000 (-0700) Subject: [subset] Iter in and out for loca X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=349d692b0ee45330220fd3ec9267979d73acd149;p=platform%2Fupstream%2FlibHarfBuzzSharp.git [subset] Iter in and out for loca --- diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 3addeb6..a5a81ad 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -81,21 +81,23 @@ struct glyf } template - static void + hb_requires (hb_is_source_of (Iterator, unsigned int))> + static bool _add_loca_and_head (hb_subset_plan_t * plan, Iterator padded_offsets) { unsigned int max_offset = + padded_offsets | hb_reduce (hb_max, 0); bool use_short_loca = max_offset <= 131070; - unsigned int loca_prime_size = (padded_offsets.len () + 1) * (use_short_loca ? 2 : 4); + unsigned int loca_prime_size = padded_offsets.len () * (use_short_loca ? 2 : 4); char *loca_prime_data = (char *) calloc(1, loca_prime_size); + if (unlikely (!loca_prime_data)) return false; + if (use_short_loca) - _write_loca (padded_offsets, 1, loca_prime_data); + _write_loca (padded_offsets, 1, hb_array_t ((HBUINT16*) loca_prime_data, padded_offsets.len ())); else - _write_loca (padded_offsets, 0, loca_prime_data); + _write_loca (padded_offsets, 0, hb_array_t ((HBUINT32*) loca_prime_data, padded_offsets.len ())); hb_blob_t * loca_blob = hb_blob_create (loca_prime_data, loca_prime_size, @@ -107,14 +109,15 @@ struct glyf _add_head_and_set_loca_version(plan, use_short_loca); hb_blob_destroy (loca_blob); + return true; } - template + template static void - _write_loca (Iterator it, unsigned right_shift, char * dest) + _write_loca (IteratorIn it, unsigned right_shift, IteratorOut dest) { - hb_array_t entries ((EntryType *) dest, it.len () + 1); unsigned int offset = 0; + it | hb_map ([&] (unsigned int padded_size) { @@ -123,10 +126,7 @@ struct glyf offset += padded_size; return result; }) - | hb_sink ( hb_iter (entries)); - // one bonus element so loca[numGlyphs] - loca[numGlyphs -1] is size of last glyph - entries.arrayZ[entries.length - 1] = offset >> right_shift; - DEBUG_MSG(SUBSET, nullptr, "loca entry offset %d", (int16_t) entries.arrayZ[entries.length - 1]); + | hb_sink (dest); } // requires source of SubsetGlyph complains the identifier isn't declared @@ -163,9 +163,10 @@ struct glyf | hb_map ([&] (const SubsetGlyph& _) { return _.padded_size(); }) | hb_sink (padded_offsets); - _add_loca_and_head (c->plan, hb_iter (padded_offsets)); + // loca ends with a final entry == last offset (+0) + padded_offsets << 0; - return_trace (true); + return_trace (c->serializer->check_success (_add_loca_and_head (c->plan, hb_iter (padded_offsets)))); } template diff --git a/test/api/hb-test.h b/test/api/hb-test.h index fc7dbbb..59e0a9b 100644 --- a/test/api/hb-test.h +++ b/test/api/hb-test.h @@ -179,11 +179,8 @@ static inline void hb_test_assert_blobs_equal (hb_blob_t *expected_blob, hb_blob { int expected = *(raw_expected + i); int actual = *(raw_actual + i); - if (expected != actual) - { - fprintf(stderr, "+%d %02x != %02x\n", i, expected, actual); - } - + if (expected != actual) fprintf(stderr, "+%d %02x != %02x\n", i, expected, actual); + else fprintf(stderr, "+%d %02x\n", i, expected); } } g_assert_cmpint(0, ==, memcmp(raw_expected, raw_actual, expected_length));