ruffle/core/src/font.rs

38 lines
1013 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>,
/// The scaling applied to the font height to render at the proper size.
/// This depends on the DefineFont tag version.
scale: f32,
2019-05-04 18:45:11 +00:00
}
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);
}
Ok(Font {
glyphs,
/// DefineFont3 stores coordinates at 20x the scale of DefineFont1/2.
/// (SWF19 p.164)
scale: if tag.version >= 3 { 20480.0 } else { 1024.0 },
})
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
}
#[inline]
pub fn scale(&self) -> f32 {
self.scale
}
2019-05-04 18:45:11 +00:00
}