1

How to generate custom .otf font subset file?

Use case:

  1. There exists gauge .otf font file.
  2. There exists specific Unicode glyph set (ranges, points).
  3. Output is new .otf file sufficient for set from point 2.

How do this on .NET or JavaScript?

Yarl
  • 728
  • 1
  • 7
  • 26

2 Answers2

1

If you are ok with using a package, fontkit is powerful/flexible and supports TTF, OTF, WOFF, WOFF2, TTC, and DFONT. You should consider this if you are looking for more complicated edits. Below is an example sourced from their readme.

// npm install fontkit
var fontkit = require('fontkit');

// open a font synchronously
var font = fontkit.openSync('font.ttf');

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

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

let buffer = subset.encode();
Quinn Keaveney
  • 1,248
  • 1
  • 17
  • 39
0

Simply check this answer but instead of saving to .ttf save it to .otf.

Yarl
  • 728
  • 1
  • 7
  • 26