Safe bindings to msdfgen library

github crate docs MIT CI

Crates

Features

Usage

```norun use std::fs::File; use notosans::REGULARTTF as FONT; use ttfparser::Face; use msdfgen::{FontExt, Bitmap, Gray, Range, MsdfGeneratorConfig, FillRule, MIDVALUE};

let font = Face::from_slice(&FONT, 0).unwrap();

let glyph = font.glyph_index('A').unwrap();

let mut shape = font.glyph_shape(glyph).unwrap();

let width = 32; let height = 32;

let bound = shape.getbound(); let framing = bound.autoframe(width, height, Range::Px(4.0), None).unwrap(); let fillrule = FillRule::default();

let mut bitmap = Bitmap::new(width, height);

shape.edgecoloringsimple(3.0, 0);

let config = MsdfGeneratorConfig::default();

shape.generate_msdf(&mut bitmap, &framing, &config);

// optionally shape.correctsign(&mut bitmap, &framing, fillrule); shape.correctmsdferror(&mut bitmap, &framing, &config);

let error = shape.estimate_error(&mut bitmap, &framing, 5, Default::default());

println!("Estimated error: {}", error);

bitmap.flip_y();

let mut output = File::create("A-letter-msdf.png").unwrap(); bitmap.write_png(&mut output).unwrap();

let mut preview = Bitmap::>::new(width * 10, height * 10); bitmap.render(&mut preview, Default::default(), MID_VALUE);

let mut output = File::create("A-letter-preview.png").unwrap(); preview.write_png(&mut output).unwrap(); ```