Struct Font

Source
pub struct Font<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Font<'a>

Source

pub fn render_glyph(&self, glyph_id: u16, size: u32) -> Option<GlyphBitmap>

Examples found in repository?
examples/render.rs (line 47)
30fn main() {
31    let mut args = std::env::args();
32    let _ = args.next();
33    let filename = args.next().unwrap();
34    let glyph_id: u16 = args.next().unwrap().parse().unwrap();
35    let out_filename = args.next().unwrap();
36    let mut f = File::open(&filename).unwrap();
37    let mut data = Vec::new();
38    match f.read_to_end(&mut data) {
39        Err(e) => println!("failed to read {}, {}", filename, e),
40        Ok(_) => match parse(&data) {
41            Ok(font) => {
42                if out_filename == "__bench__" {
43                    for size in 1..201 {
44                        let start = SystemTime::now();
45                        let n_iter = 1000;
46                        for _ in 0..n_iter {
47                            match font.render_glyph(glyph_id, size) {
48                                Some(_glyph) => (),
49                                None => (),
50                            }
51                        }
52                        let elapsed = start.elapsed().unwrap();
53                        let elapsed =
54                            elapsed.as_secs() as f64 + 1e-9 * (elapsed.subsec_nanos() as f64);
55                        println!("{} {}", size, elapsed * (1e6 / n_iter as f64));
56                    }
57                } else {
58                    match font.render_glyph(glyph_id, 400) {
59                        Some(glyph) => dump_pgm(&glyph, &out_filename),
60                        None => println!("failed to render {} {}", filename, glyph_id),
61                    }
62                }
63            }
64            Err(_) => println!("failed to parse {}", filename),
65        },
66    }
67}
Source

pub fn lookup_glyph_id(&self, code_point: u32) -> Option<u16>

Auto Trait Implementations§

§

impl<'a> Freeze for Font<'a>

§

impl<'a> RefUnwindSafe for Font<'a>

§

impl<'a> Send for Font<'a>

§

impl<'a> Sync for Font<'a>

§

impl<'a> Unpin for Font<'a>

§

impl<'a> UnwindSafe for Font<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.