# 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/)

This library renders SDF:s directly and not by downscaling a higher resolution rasters. This is probably faster, but my implementation is definitely not fast.

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:

Comparisons:

NOTE: Use fontdue for simple glyphs instead. It is ~75 times faster.

| Task | SDF | regular | |---------------------------:|:------------------:|:-------------------:| | High resolution glyphs | :whitecheckmark: | :whitecheckmark: | | Medium resolution glyphs | :whitecheckmark: | :whitecheckmark: | | Low resolution glyphs | | :whitecheckmark: | | Flexible resolution glyphs | :whitecheckmark: | | | Distorted text | :whitecheckmark: | | | Shadows borders and effects| :whitecheckmark: | | | GUI:s | | :whitecheckmark: | | 3D game worlds | :whitecheckmark: | |

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: