Skip to main content

Webfonts

AssetPack provides a couple of plugins generating woff2/sdf/msdf fonts from ttf, otf, woff, and svg files.

Webfont

This plugin generates woff2 fonts from ttf, otf, woff, and svg files.

Example

Original

Input Image
Input Image
import { webfont } from "@assetpack/core/webfont";

export default {
...
pipes: [
...
webfont(),
],
};

Tags

TagFolder/FileDescription
wfbothIf present the file(s) will be converted to a webfont (woff2).
familyfileThe font family name.

SDF + MSDF

These plugins generate signed distance field (SDF) and multi-channel signed distance field (MSDF) fonts from ttf files.

Example

Original

Input Image
Input Image
import { sdf, msdf } from "@assetpack/core/webfont";

export default {
...
pipes: [
...
sdf(),
msdf(),
],
};

API

OptionTypeDescription
fontobjectAn object containing options to customise the font generation. See below for available options.
font.outputType'xml' | 'json'Type of output font file. Can be xml for a BMFont standard .fnt file.
Defaults to 'xml' | 'json'
font.charsetstring | string[]The characters to include in the bitmap font.
font.fontSizenumberThe font size at which to generate the distance field.
Defaults to 42
font.textureSize[number, number]The dimensions of an output texture sheet, normally power-of-2 for GPU usage.
Defaults to [512, 512]
font.texturePaddingnumberPixels between each glyph in the texture.
Defaults to 2
font.bordernumberSpace between glyph textures and edge.
Defaults to 0
font.fieldType'msdf' | 'sdf' | 'psdf'What kind of distance field to generate. Can be msdf, sdf, or psdf.
Defaults to 'msdf'
font.distanceRangenumberThe width of the range around the shape between the minimum and maximum representable signed distance.
Defaults to 3
font.roundDecimalnumberRounded digits of the output font metrics. For xml output, roundDecimal: 0 recommended.
font.vectorbooleanOutput an SVG Vector file for debugging.
Defaults to false
font['smart-size']booleanShrink atlas to the smallest possible square.
Defaults to false
font.potbooleanOutput atlas size shall be power of 2.
Defaults to false
font.squarebooleanOutput atlas size shall be square.
Defaults to `false
font.rotbooleanAllow 90-degree rotation while packing.
Defaults to false
font.rtlbooleanUse RTL (Arabic/Persian) characters fix.
Defaults to false

Tags

TagFolder/FileDescription
sdfbothIf present the file(s) will be converted to a SDF font.
msdfbothIf present the file(s) will be converted to a MSDF font.
familyfileThe font family name.