foliojs / fontkit

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

Newest version of restructure doesn't support all string encodings #331

Closed timmyL17 closed 3 months ago

timmyL17 commented 6 months ago

It appears that the newest version of restructure does not support all string encodings. When I tried to open a font file on my mac, the font name fields were all null because restructure does not support the x-mac-roman encoding. Perhaps fontkit should depend strictly on restructure v3.0.0 until restructure updates?

https://github.com/foliojs/restructure/issues/60#issue-2224034510

srl295 commented 6 months ago

Can you reproduce this here? Noting that this may be related to https://github.com/diegomura/react-pdf/issues/2675

srl295 commented 6 months ago

Repro!

var fontkit = require('fontkit');

// open a font synchronously
var font = fontkit.openSync('src/arial-bold.ttf');

// layout a string, using default shaping features.
// returns a GlyphRun, describing glyphs and positions.
var run = font.layout('hello world!');

// get an SVG path for a glyph
var svg = run.glyphs[0].path.toSVG();

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

console.log('name:'+font.getName());
console.log('fullname:'+font.fullName);

let buffer = subset.encode();
console.dir({buffer});

fullnae is Arial Bold under restructure@3.0.0, null for restructure@3.0.1

srl295 commented 6 months ago

also repro:

srl295 commented 6 months ago

Here https://github.com/foliojs/fontkit/blob/master/src/tables/name.js#L13

Is where random encodings are passed to restructure.

timmyL17 commented 6 months ago

Thanks, you beat me to it. That was essentially my repro. I should have posted it at the beginning.

devongovett commented 3 months ago

Fixed by https://github.com/foliojs/restructure/pull/62