foliojs / fontkit

An advanced font engine for Node and the browser
1.46k stars 219 forks source link

Fix saving loca index format/version when subsetting #191

Closed blikblum closed 5 years ago

blikblum commented 5 years ago

Fixes saving the loca index format when subsetting.

Fonts with version 1 (long format) were being saved with version 0. This was mangling the odd offsets (they were being saved divided by two and read multiplied by two creating a off by one error)

Probably fixes https://github.com/bpampuch/pdfmake/issues/1659 and https://github.com/foliojs/pdfkit/issues/914

ValeSauer commented 5 years ago

@blikblum Thanks for this PR: As far as I see, this does not change the API. However, after having updated fontkit I still get the same results as described here https://github.com/bpampuch/pdfmake/issues/1659. Not sure if I did everything the right way. Does this require further changes in the downstream modules?

blikblum commented 5 years ago

Did you rebuild font kit?

ValeSauer commented 5 years ago

Check, I built and it worked! Great!

mbutterick commented 5 years ago

would require to make all offsets even numbers, needing to add some sort of data padding complicating things at write and read time

FWIW I work on a Racket port of fontkit. I discovered this problem independently. AFAICT padding glyf data buffer to a 2-byte boundary is established practice (in ancient times, these buffers were even padded to 4-byte boundaries). It can be done in one line right about here. It works fine. I agree with @devongovett’s original logic about deriving the loca version rather than copying it, because the short version is intended as a kind of compression.

blikblum commented 5 years ago

I agree with @devongovett’s original logic about deriving the loca version rather than copying it, because the short version is intended as a kind of compression.

Nice, please create a PR so we can review.

mbutterick commented 5 years ago

I work on a Racket port of fontkit. Unfortunately I don’t know how to fix it in JS.