[−][src]Crate msdfgen
Safe bindings to msdfgen library
Crates
- msdfgen-sys Low-level unsafe bindings generated using bindgen.
- msdfgen-lib Bundled library which can be build and link with application.
- msdfgen High-level safe bindings which should be used by applications.
Features
- ttf-parse Enables ttf-parser crate integration which allows create shapes for glyphs of specific font.
- font Enables font crate integration which allows create shapes for glyphs of specific font.
- freetype-rs Enables freetype-rs crate integration which allows create shapes for glyphs of specific font.
- png Enables png crate integration which allows load and save bitmaps from/as PNG images.
- all Meta-feature which enables all supported features.
Usage
use msdfgen_lib; // forces linking with msdfgen library use std::fs::File; use notosans::REGULAR_TTF as FONT; use ttf_parser::Font; use msdfgen::{FontExt, Bitmap, Gray, Range, EDGE_THRESHOLD, OVERLAP_SUPPORT}; let font = Font::from_data(&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 bounds = shape.get_bounds(); let framing = bounds.autoframe(width, height, Range::Px(4.0), None).unwrap(); let mut bitmap = Bitmap::new(width, height); shape.edge_coloring_simple(3.0, 0); shape.generate_msdf(&mut bitmap, &framing, EDGE_THRESHOLD, OVERLAP_SUPPORT); // optionally shape.correct_sign(&mut bitmap, &framing, Default::default()); 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::<Gray<f32>>::new(width * 10, height * 10); bitmap.render(&mut preview, Default::default()); let mut output = File::create("A-letter-preview.png").unwrap(); preview.write_png(&mut output).unwrap();
Structs
Bitmap | Bitmap object |
Bounds | Bounds of shape or contour |
Contour | Contour object |
CubicSegment | Quadratic segment object |
EdgeHolder | Edge holder object |
Framing | Framing options |
Gray | Gray color |
LinearSegment | Linear segment object |
QuadraticSegment | Quadratic segment object |
RGB | RGB color |
Scanline | Scanline object |
Shape | Shape object |
Vector2 | Generic 2D vector |
Enums
EdgeColor | Edge color enumeration |
FillRule | Fill rule dictates how intersection total is interpreted during rasterization |
Range | Range specifier |
SegmentKind | Segment kind |
Constants
EDGE_THRESHOLD | Default edge threshold |
OVERLAP_SUPPORT | Default overlap support |
Traits
EdgeSegment | Generic edge segment |
ErrorEstimation | Error estimation helper trait |
FontExt | Extensions for font objects |
Pixel | Bitmap pixel |
RenderTarget | Rendering target helper trait |
SignCorrection | Sign correction helper trait |
Type Definitions
Point2 | Generic 2D point |