# fontsdf
[](https://deps.rs/repo/github/Overpeek/fontsdf)
[](https://github.com/Overpeek/fontsdf/actions)
[](https://crates.io/crates/fontsdf)
[](https://docs.rs/fontsdf/)
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 | ✓ | |
- :whitecheckmark: means it is good at
Example usage with image
:
```rust
let font = fontsdf::Font::from_bytes(..).unwrap();
let (metrics, sdf) = font.rasterize('x', 64.0, true);
image::GrayImage::fromraw(metrics.width as _, metrics.height as _, sdf)
.unwrap()
.save("sdfx.png")
.unwrap();
```
Example output:
Normal
SDF
Example results:
Normal
SDF
- 128x128
- 48px (+radius) font size (32px input size should be enough for any output size)
- 'free' shadow
TODO:
- dual distance field (https://steamcdn-a.akamaihd.net/apps/valve/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf)