#font #sdf #truetype #opentype #ttf

no-std bin+lib fontsdf

fontdue extension to generate sdf:s directly

12 releases (4 breaking)

0.5.0 Oct 4, 2022
0.4.7 Oct 4, 2022
0.4.6 Jul 10, 2022
0.4.5 Jun 3, 2022
0.1.0 May 8, 2022

#127 in Games

Download history 10/week @ 2022-11-28 21/week @ 2022-12-05 23/week @ 2022-12-12 33/week @ 2022-12-19 15/week @ 2022-12-26 6/week @ 2023-01-02 19/week @ 2023-01-09 11/week @ 2023-01-16 29/week @ 2023-01-23 41/week @ 2023-01-30 27/week @ 2023-02-06 41/week @ 2023-02-13 54/week @ 2023-02-20 8/week @ 2023-02-27 19/week @ 2023-03-06 13/week @ 2023-03-13

104 downloads per month
Used in 4 crates (via srs2dge-text)

MIT license

155KB
553 lines

fontsdf

dependency status build status crates.io docs.rs

This no_std library renders SDF:s directly and not by downscaling a higher resolution rasters.

Signed Distance Field (SDF) textures can be used to render text or other vector art more flexibly[1], with higher quality while using less video memory (for the texture).

[1] For example:

  • It is possible to use single a 64px glyph to render both 14px and 200px glyphs.
  • It is easy to add glow, outlines and such.

Comparisons:

NOTE: Use fontdue for simple glyphs instead. It is a lot faster.

Task SDF regular
High resolution glyphs
Medium resolution glyphs
Low resolution glyphs
Stretched or squished glyphs
Shadows borders and effects
GUI:s
3D game worlds
  • ✅ means it is good at

Example usage with image:

let font = fontsdf::Font::from_bytes(..).unwrap();

let (metrics, sdf) = font.rasterize('x', 64.0, true);
image::GrayImage::from_raw(metrics.width as _, metrics.height as _, sdf)
	.unwrap()
	.save("sdf_x.png")
	.unwrap();

Example output:

Normal

SDF

Example results:

Normal

  • 128x156
  • 80px font size

SDF

  • 128x128
  • 48px (+radius) font size (32px input size should be enough for any output size)
  • 'free' shadow

TODO:

Dependencies

~3.5MB
~86K SLoC