prawnpdf / ttfunk

Font Metrics Parser for Prawn
http://prawnpdf.org
Other
125 stars 75 forks source link

Fix calculation of search_range for font subsets. #49

Closed mtyaka closed 6 years ago

mtyaka commented 6 years ago

When encoding a font subset, the search_range field should be calculated as (maximum power of 2 <= numTables)*16.

Currently TTFunk is correctly calculating the maximum power of two (2^x), but then instead of setting search_range to the actual value of 2^x * 16, it sets it to x * 16, which is not correct.

The incorrect entry for search_range causes the font to fail OpenType Sanitizer (OTS) validation. Because OTS is used in both Chrome and Firefox, the validation error means that the subset font generated with TTFunk currently cannot be used in the browser.

Testing

To reproduce the issue generate a new subset and save it to disk. Then run the OTS validator on it.

require 'ttfunk'
require 'ttfunk/subset'
font = TTFunk::File.open('myfont.ttf')
subset = TTFunk::Subset.for(font, :unicode)
subset.use(97)
File.write('mysubset.ttf', subset.encode, mode: 'wb')

Install OTS and run ots-sanitize:

$ ots-sanitize mysubset.ttf
> ERROR at src/ots.cc:201 (ProcessTTF)
> WARNING: bad search range
> ERROR at src/ots.cc:207 (ProcessTTF)
> ERROR: incorrect entrySelector for table directory
> Failed to sanitize file!

NOTE

With this patch in place, ots-sanitize fails due to a different error, which will be fixed in a separate PR.

mtyaka commented 6 years ago

Rebased from 9f75f6ff3d6d87468b08dc72a7989ec077b6ffcf.

pointlessone commented 6 years ago

@mtyaka I believe you have commit bit. Your PRs seem to have dpes on each other. Merge when ready. I suggest using Rebase and Merge mode.

mtyaka commented 6 years ago

Thanks for all the reviews @pointlessone. I don't have merge permissions on this repo.

mtyaka commented 6 years ago

@pointlessone Thanks for inviting me to the contributors team. For some reason though, the merge button is still greyed out for me.

screen shot 2018-02-07 at 12 38 02

pointlessone commented 6 years ago

@mtyaka How about now?

mtyaka commented 6 years ago

@pointlessone Still no.

screen shot 2018-02-07 at 13 13 15

pointlessone commented 6 years ago

@mtyaka Try now?

mtyaka commented 6 years ago

@pointlessone It works now, thank you!