提交 349d692b 编写于 作者: R Rod Sheeter

[subset] Iter in and out for loca

上级 95445d79
...@@ -82,20 +82,22 @@ struct glyf ...@@ -82,20 +82,22 @@ struct glyf
template<typename Iterator, template<typename Iterator,
hb_requires (hb_is_source_of (Iterator, unsigned int))> hb_requires (hb_is_source_of (Iterator, unsigned int))>
static void static bool
_add_loca_and_head (hb_subset_plan_t * plan, Iterator padded_offsets) _add_loca_and_head (hb_subset_plan_t * plan, Iterator padded_offsets)
{ {
unsigned int max_offset = unsigned int max_offset =
+ padded_offsets + padded_offsets
| hb_reduce (hb_max, 0); | hb_reduce (hb_max, 0);
bool use_short_loca = max_offset <= 131070; 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); char *loca_prime_data = (char *) calloc(1, loca_prime_size);
if (unlikely (!loca_prime_data)) return false;
if (use_short_loca) if (use_short_loca)
_write_loca <decltype (padded_offsets), HBUINT16> (padded_offsets, 1, loca_prime_data); _write_loca <decltype (padded_offsets), HBUINT16> (padded_offsets, 1, hb_array_t<HBUINT16> ((HBUINT16*) loca_prime_data, padded_offsets.len ()));
else else
_write_loca <decltype (padded_offsets), HBUINT32> (padded_offsets, 0, loca_prime_data); _write_loca <decltype (padded_offsets), HBUINT32> (padded_offsets, 0, hb_array_t<HBUINT32> ((HBUINT32*) loca_prime_data, padded_offsets.len ()));
hb_blob_t * loca_blob = hb_blob_create (loca_prime_data, hb_blob_t * loca_blob = hb_blob_create (loca_prime_data,
loca_prime_size, loca_prime_size,
...@@ -107,14 +109,15 @@ struct glyf ...@@ -107,14 +109,15 @@ struct glyf
_add_head_and_set_loca_version(plan, use_short_loca); _add_head_and_set_loca_version(plan, use_short_loca);
hb_blob_destroy (loca_blob); hb_blob_destroy (loca_blob);
return true;
} }
template<typename Iterator, typename EntryType, template<typename IteratorIn, typename EntryType, typename IteratorOut,
hb_requires (hb_is_source_of (Iterator, unsigned int))> hb_requires (hb_is_source_of (IteratorIn, unsigned int)),
hb_requires (hb_is_source_of (IteratorOut, EntryType))>
static void static void
_write_loca (Iterator it, unsigned right_shift, char * dest) _write_loca (IteratorIn it, unsigned right_shift, IteratorOut dest)
{ {
hb_array_t<EntryType> entries ((EntryType *) dest, it.len () + 1);
unsigned int offset = 0; unsigned int offset = 0;
+ it + it
| hb_map ([&] (unsigned int padded_size) { | hb_map ([&] (unsigned int padded_size) {
...@@ -123,10 +126,7 @@ struct glyf ...@@ -123,10 +126,7 @@ struct glyf
offset += padded_size; offset += padded_size;
return result; return result;
}) })
| hb_sink ( hb_iter (entries)); | hb_sink (dest);
// 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]);
} }
// requires source of SubsetGlyph complains the identifier isn't declared // requires source of SubsetGlyph complains the identifier isn't declared
...@@ -163,9 +163,10 @@ struct glyf ...@@ -163,9 +163,10 @@ struct glyf
| hb_map ([&] (const SubsetGlyph& _) { return _.padded_size(); }) | hb_map ([&] (const SubsetGlyph& _) { return _.padded_size(); })
| hb_sink (padded_offsets); | 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 <typename SubsetGlyph> template <typename SubsetGlyph>
......
...@@ -179,11 +179,8 @@ static inline void hb_test_assert_blobs_equal (hb_blob_t *expected_blob, hb_blob ...@@ -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 expected = *(raw_expected + i);
int actual = *(raw_actual + i); int actual = *(raw_actual + i);
if (expected != actual) if (expected != actual) fprintf(stderr, "+%d %02x != %02x\n", i, expected, actual);
{ else fprintf(stderr, "+%d %02x\n", i, expected);
fprintf(stderr, "+%d %02x != %02x\n", i, expected, actual);
}
} }
} }
g_assert_cmpint(0, ==, memcmp(raw_expected, raw_actual, expected_length)); g_assert_cmpint(0, ==, memcmp(raw_expected, raw_actual, expected_length));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册