JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1985665
  • Score
    100M100P100Q210189F
  • License ISC

Browser-side SDF font generator

Package Exports

  • @mapbox/tiny-sdf

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@mapbox/tiny-sdf) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

TinySDF

TinySDF is a tiny and fast JavaScript library for generating SDF (signed distance field) from system fonts on the browser using Canvas 2D and Felzenszwalb/Huttenlocher distance transform. This is very useful for rendering text with WebGL.

Demo: http://mapbox.github.io/tiny-sdf/

Usage

Create a TinySDF for drawing SDFs based on font parameters:

var fontsize = 24; // Pixel font size
var buffer = 3;    // Pixel whitespace buffer around glyph
var radius = 8;    // Lower = "sharper", higher = "fuzzier"
var cutoff = 0.25  // Across the board alpha channel reduction
                   // Reduces low-alpha pixels to zero, "thins" SDF overall

var fontFamily = 'sans-serif'; // css font-family
var fontWeight = 'normal';     // css font-weight
var tinySDFGenerator = new TinySDF(fontsize,
                                   buffer,
                                   radius,
                                   cutoff,
                                   fontFamily,
                                   fontWeight);

var oneSDF = tinySDFGenerator.draw('泽');