foliojs / fontkit

An advanced font engine for Node and the browser
1.5k stars 223 forks source link

Bad glyphs code points produce by layout function with Arabic font #304

Open MaximeHPP opened 1 year ago

MaximeHPP commented 1 year ago

Here is the Tajawal-Medium font which you can download via Google Font: https://fonts.google.com/specimen/Tajawal After parsing the font and calling the layout function (without additional params) on an Arabic string, I get the right array of glyphs but with the wrong codePoints for each. Each codePoints is the one of the base glyph (without substitution). I checked via another lib like opentype.js and the glyphs have their own unicode. I need the true unicode because I don't use the path to display the text.

Steps to reproduce:

  1. Download the font
  2. Run
    const fontObject = fontkit.create(font);
    const glyphs = fontObject.layout('هناك حقي').glyphs; 
    const codePoint = glyphs[0].codePoints[0];
    console.log(glyphs[0],  fontObject.glyphForCodePoint(codePoint));

    You can see not the same glyphs but the same code point. Do you have any idea ? 🙏

MaximeHPP commented 1 year ago

If I understood correctly this codepoint table contains the unicodes of the characters replaced by the glyph. However, I noticed that even when ligatures are used to replace several characters, no glyph is considered as a ligature and the codepoint array is empty.