Expand description
Rust bindings for msdfgen. This crate attempts to bind msdfgen in a safe and idiomatic way.
§Examples
§Generate SDFs
use msdf::{GlyphLoader, Projection};
// Load a font from ttf data.
let face: Face;
let glyph_index = face.glyph_index('W').unwrap();
// Load a glyph into a shape using a ttf glyph index.
let shape = face.load_shape(glyph_index).unwrap();
// Not a required step for SDF and Psuedo-SDF generation. Other coloring options exist.
let colored_shape = shape.color_edges_simple(3.0);
// Project glyph down by a factor of 64x.
let projection = Projection {
scale: Vector2 { x: 1.0 / 64.0, y: 1.0 / 64.0 },
translation: Vector2 { x: 0.0, y: 0.0 },
};
// Using default configuration.
let sdf_config = Default::default();
let msdf_config = Default::default();
// Generate all types of SDF. Plain SDFs and Psuedo-SDFs do not require edge coloring.
let sdf = colored_shape.generate_sdf(32, 32, 10.0 * 64.0, &projection, &sdf_config);
let psdf = colored_shape.generate_psuedo_sdf(32, 32, 10.0 * 64.0, &projection, &sdf_config);
let msdf = colored_shape.generate_msdf(32, 32, 10.0 * 64.0, &projection, &msdf_config);
let mtsdf = colored_shape.generate_mtsdf(32, 32, 10.0 * 64.0, &projection, &msdf_config);
// Do something with these SDFs.
// let image: DynamicImage = DynamicImage::from(msdf.to_image());
// image.into_rgba8().save("mysdf.png").unwrap();
§Render SDFs to images
// Load MSDF from an image::Rgb32FImage.
let msdf = MSDF::from_image(image, 10.0, 0.5);
// Render to a 1024x1024 image.
let rendered = msdf.render(1024, 1024);
// Render to a 1024x1024 image with edge colors.
let rendered_colored = msdf.render_colored(1024, 1024);
// Do something with these images.
// let image: DynamicImage = DynamicImage::from(rendered);
// image.into_rgba8().save("myrenderedsdf.png").unwrap();
Structs§
- Colored
Shape - A shape that has been colored by one of the coloring functions. A shape must be colored first before it can be used to generate an MSDF or MTSDF.
- Error
Correction Config - The configuration for the MSDF error correction pass.
- MSDF
- A multi-channel signed distance field. Backed by a three-channel f32 image.
- MSDF
Config - Configuration for multi-channel SDF calculation.
- MTSDF
- A multi-channel signed distance field with true distance. Backed by a four-channel f32 image.
- Projection
- Specifies scale and translation for SDF generation.
- SDF
- A conventional single-channel signed distance field. Backed by a single-channel f32 image.
- SDFConfig
- Configuration for single-channel SDF calculation.
- Shape
- An msdfgen shape. Can be used to generate an SDF or Psuedo-SDF. Must be colored first using a coloring function to generate a MSDF or MTSDF.
Enums§
- Distance
Check Mode - Configuration of whether to use an algorithm that computes the exact shape distance at the positions of suspected artifacts.
- Error
Correction Mode - Error correction mode of operation.
- Msdf
Error - Type for errors emitted by the generator.
Traits§
- Glyph
Loader - SDFTrait
- Trait for various types of SDFs. Can be converted to an image, or rendered with SDFTrait::render / SDFTrait::render_colored.