Safe bindings to msdfgen library
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.
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.
use msdfgen_lib as _; // forces linking with msdfgen library
use std:: fs:: File ;
use notosans:: REGULAR_TTF as FONT ;
use ttf_parser:: Font ;
use msdfgen:: { FontExt , Bitmap , Range , EDGE_THRESHOLD , OVERLAP_SUPPORT } ;
fn main ( ) {
let font = Font :: from_data ( & FONT , 0 ) . unwrap ( ) ;
let glyph = font. glyph_index ( 'A' ) . unwrap ( ) ;
let mut shape = font. glyph_shape ( glyph) . unwrap ( ) ;
if !shape. validate ( ) {
panic ! ( "Invalid shape" ) ;
}
shape. normalize ( ) ;
let bounds = shape. get_bounds ( ) ;
let width = 32 ;
let height = 32 ;
let mut bitmap = Bitmap :: new ( width, height) ;
println ! ( "bounds: {:?}" , bounds) ;
shape. edge_coloring_simple ( 3.0 , 0 ) ;
let framing = bounds. autoframe ( width, height, Range :: Px ( 4.0 ) , None ) . unwrap ( ) ;
println ! ( "framing: {:?}" , framing) ;
shape. generate_msdf ( & mut bitmap, & framing, EDGE_THRESHOLD , OVERLAP_SUPPORT ) ;
let mut output = File :: create ( "A-msdf.png" ) . unwrap ( ) ;
bitmap. write_png ( & mut output) . unwrap ( ) ;
}