Use a real FontSystem in test platform

This commit is contained in:
Max Brunsfeld 2021-04-02 14:35:44 -07:00
parent dd31b870c3
commit 575f5910fa
2 changed files with 8 additions and 74 deletions

View File

@ -91,9 +91,11 @@ impl FontSystemState {
let mut font_ids = Vec::new();
for font in self.source.select_family_by_name(name)?.fonts() {
let font = font.load()?;
eprintln!("load font {:?}", font);
font_ids.push(FontId(self.fonts.len()));
self.fonts.push(font);
}
eprintln!("font ids: {:?}", font_ids);
Ok(font_ids)
}

View File

@ -1,17 +1,13 @@
use crate::fonts::FontId;
use pathfinder_geometry::{
rect,
vector::{vec2f, vec2i, Vector2F},
};
use pathfinder_geometry::vector::Vector2F;
use std::rc::Rc;
use std::sync::Arc;
struct App {
dispatcher: Arc<dyn super::Dispatcher>,
fonts: Arc<dyn super::FontSystem>,
}
struct Dispatcher;
struct FontSystem;
pub struct Window {
size: Vector2F,
@ -27,6 +23,7 @@ impl App {
fn new() -> Self {
Self {
dispatcher: Arc::new(Dispatcher),
fonts: Arc::new(super::current::FontSystem::new()),
}
}
}
@ -36,18 +33,18 @@ impl super::App for App {
self.dispatcher.clone()
}
fn activate(&self, ignoring_other_apps: bool) {}
fn activate(&self, _ignoring_other_apps: bool) {}
fn open_window(
&self,
options: super::WindowOptions,
executor: Rc<super::executor::Foreground>,
_executor: Rc<super::executor::Foreground>,
) -> anyhow::Result<Box<dyn super::Window>> {
Ok(Box::new(Window::new(options.bounds.size())))
}
fn fonts(&self) -> std::sync::Arc<dyn super::FontSystem> {
Arc::new(FontSystem)
self.fonts.clone()
}
}
@ -97,71 +94,6 @@ impl super::Window for Window {
}
}
impl super::FontSystem for FontSystem {
fn load_family(&self, name: &str) -> anyhow::Result<Vec<FontId>> {
Ok(vec![FontId(0)])
}
fn select_font(
&self,
font_ids: &[FontId],
properties: &font_kit::properties::Properties,
) -> anyhow::Result<FontId> {
Ok(font_ids[0])
}
fn font_metrics(&self, font_id: FontId) -> font_kit::metrics::Metrics {
font_kit::metrics::Metrics {
units_per_em: 1,
ascent: 0.,
descent: 0.,
line_gap: 0.,
underline_position: 1.,
underline_thickness: 1.,
cap_height: 12.,
x_height: 12.,
bounding_box: rect::RectF::new(vec2f(0., 0.), vec2f(10., 10.)),
}
}
fn typographic_bounds(
&self,
font_id: FontId,
glyph_id: crate::fonts::GlyphId,
) -> anyhow::Result<rect::RectF> {
Ok(rect::RectF::new(vec2f(0., 0.), vec2f(0., 0.)))
}
fn glyph_for_char(&self, font_id: FontId, ch: char) -> Option<crate::fonts::GlyphId> {
Some(0)
}
fn rasterize_glyph(
&self,
font_id: FontId,
font_size: f32,
glyph_id: crate::fonts::GlyphId,
subpixel_shift: Vector2F,
scale_factor: f32,
) -> Option<(rect::RectI, Vec<u8>)> {
Some((rect::RectI::new(vec2i(0, 0), vec2i(0, 0)), vec![]))
}
fn layout_str(
&self,
text: &str,
font_size: f32,
runs: &[(std::ops::Range<usize>, FontId)],
) -> crate::text_layout::Line {
crate::text_layout::Line {
width: 0.,
runs: vec![],
len: 0,
font_size: 12.,
}
}
}
pub fn app() -> impl super::App {
App::new()
}