// compute necessary bit width
int glyphBits = 0;
int advanceBits = 0;
for (int i=0; i < length; i++)
{
TextRecord tr = tag.records.get(i);
for (int j = 0; j < tr.entries.length; j++)
{
GlyphEntry entry = tr.entries[j];
while (entry.getIndex() > (1<<glyphBits))
glyphBits++;
while (Math.abs(entry.advance) > (1<<advanceBits))
advanceBits++;
}
}
// increment to get from bit index to bit count.
++glyphBits;
++advanceBits;
w.writeUI8(glyphBits);
w.writeUI8(++advanceBits); // add one extra bit because advances are signed
for (int i = 0; i < length; i++)
{
TextRecord record = tag.records.get(i);
encodeTextRecord(record, w, type, glyphBits, advanceBits);
}
w.writeUI8(0);
}