• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..21-May-2021-

README.mdH A D21-May-20211.2 KiB2922

package.jsonH A D21-May-2021728 3534

README.md

1# TinySDF
2
3TinySDF is a tiny and fast JavaScript library for generating SDF (signed distance field)
4from system fonts on the browser using Canvas 2D and
5[Felzenszwalb/Huttenlocher distance transform](https://cs.brown.edu/~pff/dt/).
6This is very useful for [rendering text with WebGL](https://www.mapbox.com/blog/text-signed-distance-fields/).
7
8Demo: http://mapbox.github.io/tiny-sdf/
9
10## Usage
11Create a TinySDF for drawing SDFs based on font parameters:
12
13    var fontsize = 24; // Pixel font size
14    var buffer = 3;    // Pixel whitespace buffer around glyph
15    var radius = 8;    // Lower = "sharper", higher = "fuzzier"
16    var cutoff = 0.25  // Across the board alpha channel reduction
17                       // Reduces low-alpha pixels to zero, "thins" SDF overall
18
19    var fontFamily = 'sans-serif'; // css font-family
20    var fontWeight = 'normal';     // css font-weight
21    var tinySDFGenerator = new TinySDF(fontsize,
22                                       buffer,
23                                       radius,
24                                       cutoff,
25                                       fontFamily,
26                                       fontWeight);
27
28    var oneSDF = tinySDFGenerator.draw('泽');
29