ruffle/core/src/font.rs

23 lines
592 B
Rust
Raw Normal View History

2019-07-19 08:32:41 +00:00
use crate::backend::render::{RenderBackend, ShapeHandle};
2019-05-04 18:45:11 +00:00
type Error = Box<dyn std::error::Error>;
2019-05-04 18:45:11 +00:00
pub struct Font {
glyphs: Vec<ShapeHandle>,
}
impl Font {
pub fn from_swf_tag(renderer: &mut dyn RenderBackend, tag: &swf::Font) -> Result<Font, Error> {
2019-05-04 18:45:11 +00:00
let mut glyphs = vec![];
for glyph in &tag.glyphs {
2019-07-19 08:32:41 +00:00
let shape_handle = renderer.register_glyph_shape(glyph);
2019-05-04 18:45:11 +00:00
glyphs.push(shape_handle);
}
2019-05-24 17:25:03 +00:00
Ok(Font { glyphs })
2019-05-04 18:45:11 +00:00
}
pub fn get_glyph(&self, i: usize) -> Option<ShapeHandle> {
2019-05-09 21:14:21 +00:00
self.glyphs.get(i).cloned()
2019-05-04 18:45:11 +00:00
}
}