papandreou / subset-font

Create a subset of a TrueType/OpenType/WOFF/WOFF2 font using the wasm build of harfbuzz/hb-subset
BSD 3-Clause "New" or "Revised" License
95 stars 6 forks source link

Add the ability to disable layout-closure #22

Closed HussainTaj-arbisoft closed 6 months ago

HussainTaj-arbisoft commented 11 months ago

Description

I'd like to be able to disable layout closure when subsetting fonts.

I attempted to subset Material icons font using subset-font. The output did provide a subset, however, the subset was larger in size than what I would have expected. I found out that this is because of layout closure.

The output of subset-font right now is equivalent to

hb-subset MaterialIcons-Regular.ttf <icons> -o out.ttf

What I would like to see instead can be produced with

hb-subset MaterialIcons-Regular.ttf <icons> -o out.ttf --no-layout-closure

Steps to Reproduce

  1. Download the MaterialIcon font.
  2. Set up a node project.
  3. Install subset-font.
  4. Create a test.js file with the following content:

    const subsetFont = require("subset-font");
    const fs = require('fs');
    
    const str = "_abcdefghijklmnopqrstuvwxyz0123456789" + String.fromCodePoint(0xe5c5, 0xe5c8);
    const fontBuffer = fs.readFileSync('MaterialIcons-Regular.ttf');
    
    subsetFont(fontBuffer, str).then((subsetBuffer) => {
        fs.writeFileSync('out.ttf', subsetBuffer);
    });
  5. Run with node test.js.
  6. Open out.ttf with a viewer like fontdrop.info.

Behavior

You see a lot more glyphs than what was defined in str variable.

Feature Request

Add an option "disableLayoutClosure". This should be equivalent to --no-layout-closure in hb-subset.

papandreou commented 11 months ago

That sounds reasonable! PR welcome 🤗