From 76e1ce592550a1e691ae54415341d1f52b5a7d91 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 13 Jul 2021 02:36:47 -0400 Subject: [PATCH] Backport PR #20597: Fix TTF headers for type 42 stix font --- extern/ttconv/pprdrv_tt.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/extern/ttconv/pprdrv_tt.cpp b/extern/ttconv/pprdrv_tt.cpp index 934215470808..a1b6d3799b64 100644 --- a/extern/ttconv/pprdrv_tt.cpp +++ b/extern/ttconv/pprdrv_tt.cpp @@ -841,17 +841,24 @@ void ttfont_sfnts(TTStreamWriter& stream, struct TTFONT *font) /* Now, generate those silly numTables numbers. */ sfnts_pputUSHORT(stream, count); /* number of tables */ - if ( count == 9 ) - { - sfnts_pputUSHORT(stream, 7); /* searchRange */ - sfnts_pputUSHORT(stream, 3); /* entrySelector */ - sfnts_pputUSHORT(stream, 81); /* rangeShift */ + + int search_range = 1; + int entry_sel = 0; + + while (search_range <= count) { + search_range <<= 1; + entry_sel++; } + entry_sel = entry_sel > 0 ? entry_sel - 1 : 0; + search_range = (search_range >> 1) * 16; + int range_shift = count * 16 - search_range; + + sfnts_pputUSHORT(stream, search_range); /* searchRange */ + sfnts_pputUSHORT(stream, entry_sel); /* entrySelector */ + sfnts_pputUSHORT(stream, range_shift); /* rangeShift */ + #ifdef DEBUG_TRUETYPE - else - { - debug("only %d tables selected",count); - } + debug("only %d tables selected",count); #endif /* Now, emmit the table directory. */