Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a9139e

Browse files
authored
Merge pull request #20643 from jkseppan/auto-backport-of-pr-20597-on-v3.4.x
Backport PR #20597 on branch v3.4.x
2 parents c19a4d3 + 76e1ce5 commit 0a9139e

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
@@ -841,17 +841,24 @@ void ttfont_sfnts(TTStreamWriter& stream, struct TTFONT *font)
841841

842842
/* Now, generate those silly numTables numbers. */
843843
sfnts_pputUSHORT(stream, count); /* number of tables */
844-
if ( count == 9 )
845-
{
846-
sfnts_pputUSHORT(stream, 7); /* searchRange */
847-
sfnts_pputUSHORT(stream, 3); /* entrySelector */
848-
sfnts_pputUSHORT(stream, 81); /* rangeShift */
844+
845+
int search_range = 1;
846+
int entry_sel = 0;
847+
848+
while (search_range <= count) {
849+
search_range <<= 1;
850+
entry_sel++;
849851
}
852+
entry_sel = entry_sel > 0 ? entry_sel - 1 : 0;
853+
search_range = (search_range >> 1) * 16;
854+
int range_shift = count * 16 - search_range;
855+
856+
sfnts_pputUSHORT(stream, search_range); /* searchRange */
857+
sfnts_pputUSHORT(stream, entry_sel); /* entrySelector */
858+
sfnts_pputUSHORT(stream, range_shift); /* rangeShift */
859+
850860
#ifdef DEBUG_TRUETYPE
851-
else
852-
{
853-
debug("only %d tables selected",count);
854-
}
861+
debug("only %d tables selected",count);
855862
#endif
856863

857864
/* Now, emmit the table directory. */

0 commit comments

Comments
 (0)