papandreou/subset-font

Subsetting emojis from an emoji font results in a non-working font

Calinou opened this issue Β· 2 comments

Using Node.js 23.1.0 on Windows 11 23H2, I've tried to subset a small number of emoji from Noto Color Emoji which I've downloaded from Google Fonts. For context, I'm looking to address godotengine/godot-demo-projects#1119 without committing a 24 MB file to that repository.

Using the following script:

#!/usr/bin/env node
const fs = require('fs');
const subsetFont = require('subset-font');

const inputFile = 'NotoColorEmoji-Regular.ttf';
const outputFile = 'NotoColorEmoji-Regular-subset.woff2';
const subsetText = 'πŸ₯³πŸ§πŸ°πŸŽπŸŽ‚πŸŽˆπŸŽΊπŸŽ‰πŸŽŠπŸ“§γ€½οΈπŸ§ΏπŸŒΆοΈπŸ”‹πŸ˜‚β€οΈπŸ˜πŸ€£πŸ˜ŠπŸ₯ΊπŸ™πŸ’•πŸ˜­πŸ˜˜πŸ‘πŸ˜…πŸ‘';

const mySfntFontBuffer = Buffer.from(fs.readFileSync(inputFile));
(async () => {
  const subsetBuffer = await subsetFont(mySfntFontBuffer, subsetText, {
    targetFormat: 'woff2',
  });

  fs.writeFile(outputFile, subsetBuffer, 'binary', (err) => {
    if (!err) {
      console.log(`Subset written to: ${outputFile}`);
    } else {
      console.error(err);
    }
  });
})();

package.json:

{
  "type": "commonjs",
  "dependencies": {
    "subset-font": "^2.4.0"
  }
}

The font generation process works, but the resulting font doesn't have working emoji, even though they are included in the font. You don't see emoji when trying to enter them using an emoji keyboard (or copy-pasting from a website listing emoji).

I've tried both WOFF2 and SFNT (.ttf) output to no avail.

Wakamai Fondue has this to say about the generated subset:

image

image

The original TTF in comparison:

image

Loading the original font in Godot 4.3:

image

Loading either of the subset fonts:

image

Can you confirm that the same subsetting works with hb-subset?

Can you confirm that the same subsetting works with hb-subset?

I've tried and it didn't work in Godot either.

NotoColorEmoji-subset.zip

Command line:

hb-subset NotoColorEmoji-Regular.ttf \
  --text="πŸ₯³πŸ§πŸ°πŸŽπŸŽ‚πŸŽˆπŸŽΊπŸŽ‰πŸŽŠπŸ“§γ€½οΈπŸ§ΏπŸŒΆοΈπŸ”‹πŸ˜‚β€οΈπŸ˜πŸ€£πŸ˜ŠπŸ₯ΊπŸ™πŸ’•πŸ˜­πŸ˜˜πŸ‘πŸ˜…πŸ‘" \
  --output-file="NotoColorEmoji-Regular-subset.ttf"

However, this is actually most likely a Godot bug, so I'll close this for now.