|
|
|
@ -65,11 +65,12 @@ struct CFFIndex |
|
|
|
|
template <typename Iterable, |
|
|
|
|
hb_requires (hb_is_iterable (Iterable))> |
|
|
|
|
bool serialize (hb_serialize_context_t *c, |
|
|
|
|
const Iterable &iterable) |
|
|
|
|
const Iterable &iterable, |
|
|
|
|
unsigned data_size = 0) |
|
|
|
|
{ |
|
|
|
|
TRACE_SERIALIZE (this); |
|
|
|
|
auto it = hb_iter (iterable); |
|
|
|
|
unsigned size = serialize_header(c, + it | hb_map (hb_iter) | hb_map (hb_len)); |
|
|
|
|
unsigned size = serialize_header(c, + it | hb_map (hb_iter) | hb_map (hb_len), data_size); |
|
|
|
|
unsigned char *ret = c->allocate_size<unsigned char> (size, false); |
|
|
|
|
if (unlikely (!ret)) return_trace (false); |
|
|
|
|
for (const auto &_ : +it) |
|
|
|
@ -91,11 +92,12 @@ struct CFFIndex |
|
|
|
|
template <typename Iterator, |
|
|
|
|
hb_requires (hb_is_iterator (Iterator))> |
|
|
|
|
unsigned serialize_header (hb_serialize_context_t *c, |
|
|
|
|
Iterator it) |
|
|
|
|
Iterator it, |
|
|
|
|
unsigned data_size = 0) |
|
|
|
|
{ |
|
|
|
|
TRACE_SERIALIZE (this); |
|
|
|
|
|
|
|
|
|
unsigned total = + it | hb_reduce (hb_add, 0); |
|
|
|
|
unsigned total = data_size ? data_size : + it | hb_reduce (hb_add, 0); |
|
|
|
|
unsigned off_size = (hb_bit_storage (total + 1) + 7) / 8; |
|
|
|
|
|
|
|
|
|
/* serialize CFFIndex header */ |
|
|
|
@ -174,16 +176,22 @@ struct CFFIndex |
|
|
|
|
|
|
|
|
|
template <typename Iterable, |
|
|
|
|
hb_requires (hb_is_iterable (Iterable))> |
|
|
|
|
static unsigned total_size (const Iterable &iterable) |
|
|
|
|
static unsigned total_size (const Iterable &iterable, unsigned *data_size = nullptr) |
|
|
|
|
{ |
|
|
|
|
auto it = + hb_iter (iterable) | hb_map (hb_iter) | hb_map (hb_len); |
|
|
|
|
// The following should return min_size IMO. But that crashes a few
|
|
|
|
|
// tests. I have not investigated why.
|
|
|
|
|
if (!it) return 0; //min_size;
|
|
|
|
|
if (!it) |
|
|
|
|
{ |
|
|
|
|
if (data_size) *data_size = 0; |
|
|
|
|
// The following should return min_size IMO. But that crashes a few
|
|
|
|
|
// tests. I have not investigated why.
|
|
|
|
|
return 0; //min_size;
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
unsigned total = + it | hb_reduce (hb_add, 0); |
|
|
|
|
unsigned off_size = (hb_bit_storage (total + 1) + 7) / 8; |
|
|
|
|
|
|
|
|
|
if (data_size) *data_size = total; |
|
|
|
|
|
|
|
|
|
return min_size + HBUINT8::static_size + (hb_len (it) + 1) * off_size + total; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|