[cff-common] Write INDEX offset-size calc using hb_bit_storage()

This commit is contained in:
Behdad Esfahbod 2022-05-09 15:38:40 -06:00
parent 2ccfe84eff
commit 8bb1a3ce9a
1 changed files with 1 additions and 14 deletions

View File

@ -46,19 +46,6 @@ template<typename Type>
static inline const Type& StructAtOffsetOrNull (const void *P, unsigned int offset) static inline const Type& StructAtOffsetOrNull (const void *P, unsigned int offset)
{ return offset ? StructAtOffset<Type> (P, offset) : Null (Type); } { return offset ? StructAtOffset<Type> (P, offset) : Null (Type); }
inline unsigned int calcOffSize (unsigned int dataSize)
{
unsigned int size = 1;
unsigned int offset = dataSize + 1;
while (offset & ~0xFF)
{
size++;
offset >>= 8;
}
/* format does not support size > 4; caller should handle it as an error */
return size;
}
struct code_pair_t struct code_pair_t
{ {
hb_codepoint_t code; hb_codepoint_t code;
@ -197,7 +184,7 @@ struct CFFIndex
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
unsigned total = + it | hb_reduce (hb_add, 0); unsigned total = + it | hb_reduce (hb_add, 0);
unsigned off_size = calcOffSize (total); unsigned off_size = (hb_bit_storage (total + 1) + 7) / 8;
/* serialize CFFIndex header */ /* serialize CFFIndex header */
if (unlikely (!c->extend_min (this))) return_trace (false); if (unlikely (!c->extend_min (this))) return_trace (false);