You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a TinySDF for drawing glyph SDFs based on font parameters:
consttinySdf=newTinySDF({fontSize: 24,// Font size in pixelsfontFamily: 'sans-serif',// CSS font-familyfontWeight: 'normal',// CSS font-weightfontStyle: 'normal',// CSS font-stylebuffer: 3,// Whitespace buffer around a glyph in pixelsradius: 8,// How many pixels around the glyph shape to use for encoding distancecutoff: 0.25// How much of the radius (relative) is used for the inside part of the glyph});constglyph=tinySdf.draw('泽');// draw a single character
Returns an object with the following properties:
data is a Uint8ClampedArray array of alpha values (0–255) for a width x height grid.
width: Width of the returned bitmap.
height: Height of the returned bitmap.
glyphTop: Maximum ascent of the glyph from alphabetic baseline.
glyphLeft: Currently hardwired to 0 (actual glyph differences are encoded in the rasterization).
glyphWidth: Width of the rasterized portion of the glyph.
glyphHeight Height of the rasterized portion of the glyph.
glyphAdvance: Layout advance.
TinySDF is provided as a ES module, so it's only supported on modern browsers, excluding IE.
In Node, you can't use require — only import in ESM-capable versions (v12.15+):
importTinySDFfrom'@mapbox/tiny-sdf';
Development
npm test# run tests
npm start # start server for the demo page
License
This implementation is licensed under the BSD 2-Clause license. It's based directly on the algorithm published in the Felzenszwalb/Huttenlocher paper, and is not a port of the existing C++ implementation provided by the paper's authors.