[subset] Write loca using more idiomatic harfbuzzese
This commit is contained in:
parent
d1b12a5465
commit
95445d79be
|
@ -80,7 +80,8 @@ struct glyf
|
||||||
return_trace (true);
|
return_trace (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Iterator>
|
template<typename Iterator,
|
||||||
|
hb_requires (hb_is_source_of (Iterator, unsigned int))>
|
||||||
static void
|
static void
|
||||||
_add_loca_and_head (hb_subset_plan_t * plan, Iterator padded_offsets)
|
_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);
|
char *loca_prime_data = (char *) calloc(1, loca_prime_size);
|
||||||
|
|
||||||
if (use_short_loca)
|
if (use_short_loca)
|
||||||
_write_loca <decltype (padded_offsets), HBUINT16> (padded_offsets, 2, loca_prime_data);
|
_write_loca <decltype (padded_offsets), HBUINT16> (padded_offsets, 1, loca_prime_data);
|
||||||
else
|
else
|
||||||
_write_loca <decltype (padded_offsets), HBUINT32> (padded_offsets, 1, loca_prime_data);
|
_write_loca <decltype (padded_offsets), HBUINT32> (padded_offsets, 0, loca_prime_data);
|
||||||
|
|
||||||
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,
|
||||||
|
@ -108,26 +109,27 @@ struct glyf
|
||||||
hb_blob_destroy (loca_blob);
|
hb_blob_destroy (loca_blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Iterator, typename EntryType>
|
template<typename Iterator, typename EntryType,
|
||||||
|
hb_requires (hb_is_source_of (Iterator, unsigned int))>
|
||||||
static void
|
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]
|
hb_array_t<EntryType> entries ((EntryType *) dest, it.len () + 1);
|
||||||
EntryType * loca_start = (EntryType *) dest;
|
|
||||||
EntryType * loca_current = loca_start;
|
|
||||||
unsigned int offset = 0;
|
unsigned int offset = 0;
|
||||||
+ it
|
+ it
|
||||||
| hb_apply ([&] (unsigned int padded_size) {
|
| hb_map ([&] (unsigned int padded_size) {
|
||||||
DEBUG_MSG(SUBSET, nullptr, "loca entry %ld offset %d", loca_current - loca_start, offset);
|
unsigned int result = offset >> right_shift;
|
||||||
*loca_current = offset / size_denom;
|
DEBUG_MSG(SUBSET, nullptr, "loca entry offset %d shifted %d", offset, result);
|
||||||
offset += padded_size;
|
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
|
// 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);
|
entries.arrayZ[entries.length - 1] = offset >> right_shift;
|
||||||
*loca_current = offset / size_denom;
|
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 <typename Iterator>
|
template <typename Iterator>
|
||||||
bool serialize(hb_serialize_context_t *c,
|
bool serialize(hb_serialize_context_t *c,
|
||||||
Iterator it,
|
Iterator it,
|
||||||
|
@ -311,6 +313,7 @@ struct glyf
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO rewrite using new iterator framework if possible
|
||||||
struct Iterator
|
struct Iterator
|
||||||
{
|
{
|
||||||
const char *glyph_start;
|
const char *glyph_start;
|
||||||
|
|
Loading…
Reference in New Issue