Font Subsetter API

Cut a TTF, OTF or WOFF font down to the characters you need (text, Unicode ranges, Latin or Vietnamese presets) and get WOFF2, WOFF and CSS.

POSThttps://apibox.io.vn/v1/font-subset

Upload a font as multipart file (TTF, OTF, WOFF or a TrueType collection with face_index) and say which characters to keep: sample text, unicodes ranges (U+0020-007E, U+1EA0-1EF9) and / or a preset: latin, latin-ext (Google Fonts ranges), vietnamese (Basic Latin + Latin-1 + every precomposed Vietnamese letter + combining tone marks + ₫), vietnamese-only or digits. The font is subset with HarfBuzz hb-subset, keeping the glyphs reachable through OpenType layout (ligatures, accents).

Choose format woff2 (default), woff, ttf or all. The response has the sizes before and after, missing_characters the font does not contain, vietnamese_support (full / partial / none), a CSS @font-face block with unicode-range, and the files as base64 (output=binary returns the font itself). Layout features: features=default (HarfBuzz default set), all, or a list such as kern,liga; drop_features removes some; hinting=false drops hinting for smaller files; pin_axes=true turns a variable font into its default instance.

WOFF2 input is not accepted (send the TTF / WOFF). Fonts up to 30 MB. Only subset fonts whose licence allows it (e.g. SIL OFL); responsibility for the font licence stays with you.

Parameters

NameInTypeRequiredDefault
filebodyfileyesTTF, OTF, WOFF or TTC font (multipart, raw body or file_base64), max 30 MB.
textbodystringnoSample text: every character in it is kept.
unicodesbodystringnoUnicode ranges, e.g. U+0020-007E, U+20AB (wildcards like U+1E?? allowed).
presetbodystringnolatin, latin-ext, vietnamese, vietnamese-only, digits (comma list allowed).
formatbodystringnowoff2woff2, woff, ttf or all (comma list allowed).
featuresbodystringnodefaultOpenType layout features to keep: default, all or a list like kern,liga,ss01.
drop_featuresbodystringnoFeature tags to remove, e.g. dlig,salt.
hintingbodybooleannotruefalse removes TrueType hinting (smaller files).
pin_axesbodybooleannofalseVariable fonts: keep only the default instance.
familybodystringnofont-family name in the CSS (default: the font’s family name).
outputbodystringnojsonjson (files as base64) or binary (the first chosen format as a file).

Example

curl -X POST "https://apibox.io.vn/v1/font-subset" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@./my-file"

Response

{
  "font": {
    "family": "Be Vietnam Pro",
    "style": "Regular",
    "full_name": "Be Vietnam Pro Regular",
    "postscript_name": "BeVietnamPro-Regular",
    "input_format": "ttf",
    "input_bytes": 132948,
    "characters_in_font": 459
  },
  "requested": 311,
  "kept": 309,
  "missing": 2,
  "missing_characters": "̩‛",
  "missing_ranges": "U+0329, U+201B",
  "vietnamese_support": "full",
  "features": "default",
  "hinting": true,
  "sizes": {
    "original": 132948,
    "woff2": 30884,
    "woff": 35096
  },
  "saved_percent": 76.8,
  "unicode_range": "U+0020-007E, U+00A0-00FF, U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0306, U+0309, U+0323, U+1EA0-1EF9, U+2013-2014, U+2018-201A, U+201C-201D, U+2026, U+20AB",
  "css": "@font-face {\n  font-family: 'Be Vietnam Pro';\n  font-style: normal;\n  font-weight: 400;\n  font-display: swap;\n  src: url('BeVietnamPro-Regular-subset.woff2') format('woff2'),\n       url('BeVietnamPro-Regular-subset.woff') format('woff');\n  unicode-range: U+0020-007E, U+00A0-00FF, …, U+1EA0-1EF9, …, U+20AB;\n}",
  "files": {
    "woff2": {
      "filename": "BeVietnamPro-Regular-subset.woff2",
      "content_base64": "d09GMgABAAAAAHikABEAAAABScwAAHhGAAEAAAAA…"
    },
    "woff": {
      "filename": "BeVietnamPro-Regular-subset.woff",
      "content_base64": "d09GRgABAAAAAIkYABEAAAABScwAAQAAAAAAAAAA…"
    }
  },
  "ms": 177
}

Use cases

  • Make Vietnamese web fonts load fast without losing diacritics
  • Create a tiny icon or logo font with only the letters of a title
  • Check whether a font supports all Vietnamese letters before using it
  • Convert TTF to WOFF2 / WOFF with a ready @font-face snippet

FAQ

Why do Vietnamese characters break with the Google "latin" subset?

Letters such as ă, ơ, ư, đ and the tones (ạ, ế, ữ…) live in Latin Extended ranges. Use preset=vietnamese to keep Basic Latin plus every precomposed Vietnamese letter and the combining marks in one file.

How is the WOFF2 made?

The subset font is compressed with Brotli in WOFF2 format with untransformed tables (the spec’s null transform for glyf / loca). Browsers load it like any WOFF2; files are a few percent larger than with the glyf transform.

Does it tell me which characters are missing?

Yes: missing_characters and missing_ranges list requested characters that are not in the font’s cmap, and vietnamese_support says full, partial or none.

Related APIs

Start with 1,000 free requests every month. Get free API key →