From 575f5910fa6fd33c51d02f11730e191f8c10a92a Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 2 Apr 2021 14:35:44 -0700 Subject: [PATCH] Use a real FontSystem in test platform --- gpui/src/platform/mac/fonts.rs | 2 + gpui/src/platform/test.rs | 80 +++------------------------------- 2 files changed, 8 insertions(+), 74 deletions(-) diff --git a/gpui/src/platform/mac/fonts.rs b/gpui/src/platform/mac/fonts.rs index 9fcc4852bf..609a5021da 100644 --- a/gpui/src/platform/mac/fonts.rs +++ b/gpui/src/platform/mac/fonts.rs @@ -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) } diff --git a/gpui/src/platform/test.rs b/gpui/src/platform/test.rs index 935ce27928..545ab10e34 100644 --- a/gpui/src/platform/test.rs +++ b/gpui/src/platform/test.rs @@ -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, + fonts: Arc, } 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, + _executor: Rc, ) -> anyhow::Result> { Ok(Box::new(Window::new(options.bounds.size()))) } fn fonts(&self) -> std::sync::Arc { - 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> { - Ok(vec![FontId(0)]) - } - - fn select_font( - &self, - font_ids: &[FontId], - properties: &font_kit::properties::Properties, - ) -> anyhow::Result { - 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 { - Ok(rect::RectF::new(vec2f(0., 0.), vec2f(0., 0.))) - } - - fn glyph_for_char(&self, font_id: FontId, ch: char) -> Option { - 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)> { - Some((rect::RectI::new(vec2i(0, 0), vec2i(0, 0)), vec![])) - } - - fn layout_str( - &self, - text: &str, - font_size: f32, - runs: &[(std::ops::Range, 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() }