Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Load embedded fonts
Marshall Bowers785901c75e4d
diff --git a/crates/gpui3/src/text_system.rs b/crates/gpui3/src/text_system.rsindex 3b16bb506c1..7c96b1a180c 100644--- a/crates/gpui3/src/text_system.rs+++ b/crates/gpui3/src/text_system.rs@@ -55,6 +55,10 @@ impl TextSystem {}}+ pub fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> Result<()> {+ self.platform_text_system.add_fonts(fonts)+ }+pub fn font_id(&self, font: &Font) -> Result<FontId> {let font_id = self.font_ids_by_font.read().get(font).copied();if let Some(font_id) = font_id {diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rsindex 4beca32ca18..f8b8b747e99 100644--- a/crates/storybook2/src/storybook2.rs+++ b/crates/storybook2/src/storybook2.rs@@ -10,8 +10,8 @@ use std::sync::Arc;use clap::Parser;use gpui3::{- div, px, size, view, AnyView, BorrowAppContext, Bounds, Context, Element, ViewContext,- WindowBounds, WindowOptions,+ div, px, size, view, AnyView, AppContext, AssetSource, BorrowAppContext, Bounds, Context,+ Element, ViewContext, WindowBounds, WindowOptions,};use log::LevelFilter;use simplelog::SimpleLogger;@@ -54,6 +54,8 @@ fn main() {let asset_source = Arc::new(Assets);gpui3::App::production(asset_source).run(move |cx| {+ load_embedded_fonts(cx);+let selector =story_selector.unwrap_or(StorySelector::Component(ComponentStory::Workspace));@@ -112,15 +114,16 @@ impl StoryWrapper {}}-// fn load_embedded_fonts(platform: &dyn gpui2::Platform) {-// let font_paths = Assets.list("fonts");-// let mut embedded_fonts = Vec::new();-// for font_path in &font_paths {-// if font_path.ends_with(".ttf") {-// let font_path = &*font_path;-// let font_bytes = Assets.load(font_path).unwrap().to_vec();-// embedded_fonts.push(Arc::from(font_bytes));-// }-// }-// platform.fonts().add_fonts(&embedded_fonts).unwrap();-// }+fn load_embedded_fonts(cx: &AppContext) {+ let font_paths = Assets.list(&"fonts".into()).unwrap();+ let mut embedded_fonts = Vec::new();+ for font_path in &font_paths {+ if font_path.ends_with(".ttf") {+ let font_path = &*font_path;+ let font_bytes = Assets.load(font_path).unwrap().to_vec();+ embedded_fonts.push(Arc::from(font_bytes));+ }+ }++ cx.text_system().add_fonts(&embedded_fonts).unwrap();+}diff --git a/crates/ui2/src/story.rs b/crates/ui2/src/story.rsindex 2a753df4f1c..e51ff0f8568 100644--- a/crates/ui2/src/story.rs+++ b/crates/ui2/src/story.rs@@ -14,7 +14,7 @@ impl Story {.flex_col().pt_2().px_4()- .font("Zed Mono Extended")+ .font("Zed Mono").bg(color.background)}