foliojs / fontkit

An advanced font engine for Node and the browser
1.44k stars 210 forks source link

.getImageForSize(100) returns "null" using "Apple Color Emoji.ttc" #319

Closed axwt closed 10 months ago

axwt commented 10 months ago

Hi there, I'm trying to extract the image for emoji using the following code:

const fontkit = require('fontkit');
const font = fontkit.openSync('./Apple Color Emoji.ttc').fonts[0];

let run = font.layout("1");
let glyph = run.glyphs[0];
let imageData = glyph.getImageForSize(100); // returns null

From debugging, I can see that the glyph is still in the SBIX table.

Test tech specs: macOS — 13.5.1 Ventura .ttc file — 18.3d3e1 version

I saw this method worked previously. Any suggestion on why it doesn't work now?

axwt commented 10 months ago

After some debugging I can tell that it's either Apple changed their file format, or src/tables/sbix.js has an issue with the table parser.

getImageForSize() function here src/glyph/SBIXGlyph.js gets the proper table for the desired image size and then gets start and end offset to extract the image from the stream. The problem is imageOffsets table include the same numbers for all glyphs and that's why the function doesn't work.

G7CaQ7zr8IpDX9l5@2x
axwt commented 10 months ago

Ok, getImageForSize() works correctly. It is just the first 113 glyphs have the same numbers.