extern crate rusttype;
extern crate image;
use rusttype::{FontCollection, Scale, point};
use image::{Rgba, DynamicImage};
fn main() {
let font_data = include_bytes!("../fonts/wqy-microhei/WenQuanYiMicroHei.ttf");
let collection = FontCollection::from_bytes(font_data as &[u8]);
let font = collection.into_font().unwrap();
let mut image = DynamicImage::new_rgba8(500, 100).to_rgba();
let size = 32.0;
let scale = Scale {x: size, y: size};
let text = "This is RustType rendered into a png!";
let colour = (150, 0, 0);
let start = point(20.0, 50.0);
for glyph in font.layout(text, scale, start) {
if let Some(bounding_box) = glyph.pixel_bounding_box() {
glyph.draw(|x, y, v| image.put_pixel(
x + bounding_box.min.x as u32,
y + bounding_box.min.y as u32,
Rgba {data: [colour.0, colour.1, colour.2, (v * 255.0) as u8]}
));
}
}
image.save("image_example.png").unwrap();
}