Skip to content

Commit 2cbe132

Browse files
committed
Fix TTF headers for type 42 stix font
1 parent 06141da commit 2cbe132

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

extern/ttconv/pprdrv_tt.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -800,16 +800,23 @@ void ttfont_sfnts(TTStreamWriter& stream, struct TTFONT *font)
800800

801801
/* Now, generate those silly numTables numbers. */
802802
sfnts_pputUSHORT(stream, count); /* number of tables */
803-
if ( count == 9 )
804-
{
805-
sfnts_pputUSHORT(stream, 7); /* searchRange */
806-
sfnts_pputUSHORT(stream, 3); /* entrySelector */
807-
sfnts_pputUSHORT(stream, 81); /* rangeShift */
808-
}
809-
else
810-
{
811-
debug("only %d tables selected",count);
803+
804+
int search_range = 1;
805+
int entry_sel = 0;
806+
807+
while (search_range <= count) {
808+
search_range <<= 1;
809+
entry_sel++;
812810
}
811+
entry_sel = entry_sel > 0 ? entry_sel - 1 : 0;
812+
search_range = (search_range >> 1) * 16;
813+
int range_shift = count * 16 - search_range;
814+
815+
sfnts_pputUSHORT(stream, search_range); /* searchRange */
816+
sfnts_pputUSHORT(stream, entry_sel); /* entrySelector */
817+
sfnts_pputUSHORT(stream, range_shift); /* rangeShift */
818+
819+
debug("only %d tables selected",count);
813820

814821
/* Now, emmit the table directory. */
815822
for (x=0; x < 9; x++)

0 commit comments

Comments
 (0)