foliojs / fontkit

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

fontkit fails to create working subset for some fonts #188

Closed daliusd closed 5 years ago

daliusd commented 5 years ago

fontkit 1.7.8

Here is "Rasa" font with the problem: http://fonts.gstatic.com/s/rasa/v3/xn7vYHIn1mWmTqI.ttf . Actually there are more fonts that demonstrate this problem.

Download ttf, rename to rasa.ttf and run this script:

var fontkit = require('fontkit');
var fs = require('fs');

var font = fontkit.openSync('rasa.ttf');

var run = font.layout('argh');

var subset = font.createSubset();
run.glyphs.forEach(function(glyph) {
    subset.includeGlyph(glyph);
});

subset.encodeStream().pipe(fs.createWriteStream('subset.ttf'));

I have opened subset.ttf with FontForge and only "r" letter retains proper layout. Other letters are corrupted somehow. If I use other font that works properly (e.g. Roboto Condensed) then I don't have any problem.

Is there anything I could do to solve this problem? Maybe I can disable font subsetting in pdfkit?

moyogo commented 5 years ago

This is documented in the README under “Subsets”. The cmap, post and name tables are missing, if I recall correctly.

daliusd commented 5 years ago

@moyogo Yes, I know that. Problem is that pdfkit fails to render from this subset and this is primary use case for fontkit. FontForge seems to manage to read this subset file despite missing tables.

daliusd commented 5 years ago

I have tried to use .path.toSVG() and characters seems to be rendered correctly. So I assume only created subset file might be wrong.

devongovett commented 5 years ago

Do you have an example using pdfkit where this fails?

daliusd commented 5 years ago

It looks like this problem was fixed in fontkit 1.8.0. I can reproduce it with fontkit 1.7.8 but not with 1.8.0.

I have created demo project if you are still interested in it https://github.com/daliusd/pdfkitfail