1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
extern crate conv;
extern crate image;
extern crate imageproc;
extern crate rusttype;
mod annotation;
mod canvas;
mod draw;
mod error;
pub use annotation::*;
pub use canvas::*;
pub use error::{Result, Error, ErrorKind};
const AA_FACTOR: u32 = 3;
const AA_FACTOR_FLOAT: f32 = 3.0;
pub type Typeface = rusttype::Font<'static>;
pub fn load_typeface<R: std::io::Read>(stream: &mut R) -> Result<Typeface> {
use rusttype::FontCollection;
let mut buf = Vec::new();
stream.read_to_end(&mut buf).map_err(|e| {
Error::io(e, "Unable to read font stream")
})?;
FontCollection::from_bytes(buf).into_font().ok_or_else(|| {
Error::font("Unable to find a font in font data")
})
}