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
mod annotation;
mod canvas;
mod draw;
mod error;
pub use annotation::*;
pub use canvas::*;
pub use error::{Error, ErrorKind, Result};
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>(mut stream: 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)
.and_then(FontCollection::into_font)
.map_err(|e| Error::font(e, "Unable to read font from data"))
}