# fontsdf [![dependency status](https://deps.rs/repo/github/Overpeek/fontsdf/status.svg)](https://deps.rs/repo/github/Overpeek/fontsdf) [![build status](https://github.com/Overpeek/fontsdf/actions/workflows/rust.yml/badge.svg)](https://github.com/Overpeek/fontsdf/actions) [![crates.io](https://img.shields.io/crates/v/fontsdf.svg?label=fontsdf)](https://crates.io/crates/fontsdf) [![docs.rs](https://docs.rs/fontsdf/badge.svg)](https://docs.rs/fontsdf/)

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).

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

[1] For example:

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 | ✓ | |

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

TODO: