diff --git a/Cargo.lock b/Cargo.lock index 89169c0efd64..562da86feec0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4040,9 +4040,9 @@ dependencies = [ [[package]] name = "rust-embed" -version = "5.9.0" +version = "6.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fe1fe6aac5d6bb9e1ffd81002340363272a7648234ec7bdfac5ee202cb65523" +checksum = "1be44a6694859b7cfc955699935944a6844aa9fe416aeda5d40829e3e38dfee6" dependencies = [ "rust-embed-impl", "rust-embed-utils", @@ -4051,9 +4051,9 @@ dependencies = [ [[package]] name = "rust-embed-impl" -version = "5.9.0" +version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed91c41c42ef7bf687384439c312e75e0da9c149b0390889b94de3c7d9d9e66" +checksum = "f567ca01565c50c67b29e535f5f67b8ea8aeadaeed16a88f10792ab57438b957" dependencies = [ "proc-macro2", "quote", @@ -4064,10 +4064,12 @@ dependencies = [ [[package]] name = "rust-embed-utils" -version = "5.1.0" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a512219132473ab0a77b52077059f1c47ce4af7fbdc94503e9862a34422876d" +checksum = "6116e7ab9ea963f60f2f20291d8fcf6c7273192cdd7273b3c80729a9605c97b2" dependencies = [ + "glob 0.3.0", + "sha2", "walkdir", ] diff --git a/gpui/src/app.rs b/gpui/src/app.rs index 3610957634b0..c1ce8fdba0d2 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -300,6 +300,10 @@ impl App { })) } + pub fn platform(&self) -> Arc { + self.0.borrow().platform() + } + pub fn font_cache(&self) -> Arc { self.0.borrow().cx.font_cache.clone() } diff --git a/gpui/src/platform.rs b/gpui/src/platform.rs index b58ad381a29f..2aad986a6671 100644 --- a/gpui/src/platform.rs +++ b/gpui/src/platform.rs @@ -127,6 +127,7 @@ pub enum CursorStyle { } pub trait FontSystem: Send + Sync { + fn add_fonts(&self, fonts: Vec>>) -> anyhow::Result<()>; fn load_family(&self, name: &str) -> anyhow::Result>; fn select_font( &self, diff --git a/gpui/src/platform/mac/fonts.rs b/gpui/src/platform/mac/fonts.rs index ba9e3ae3cf76..8f61bfab30bd 100644 --- a/gpui/src/platform/mac/fonts.rs +++ b/gpui/src/platform/mac/fonts.rs @@ -21,9 +21,12 @@ use core_graphics::{ base::CGGlyph, color_space::CGColorSpace, context::CGContext, geometry::CGAffineTransform, }; use core_text::{line::CTLine, string_attributes::kCTFontAttributeName}; -use font_kit::{canvas::RasterizationOptions, hinting::HintingOptions, source::SystemSource}; +use font_kit::{ + canvas::RasterizationOptions, handle::Handle, hinting::HintingOptions, source::SystemSource, + sources::mem::MemSource, +}; use parking_lot::RwLock; -use std::{cell::RefCell, char, cmp, convert::TryFrom, ffi::c_void}; +use std::{cell::RefCell, char, cmp, convert::TryFrom, ffi::c_void, sync::Arc}; #[allow(non_upper_case_globals)] const kCGImageAlphaOnly: u32 = 7; @@ -31,20 +34,26 @@ const kCGImageAlphaOnly: u32 = 7; pub struct FontSystem(RwLock); struct FontSystemState { - source: SystemSource, + memory_source: MemSource, + system_source: SystemSource, fonts: Vec, } impl FontSystem { pub fn new() -> Self { Self(RwLock::new(FontSystemState { - source: SystemSource::new(), + memory_source: MemSource::empty(), + system_source: SystemSource::new(), fonts: Vec::new(), })) } } impl platform::FontSystem for FontSystem { + fn add_fonts(&self, fonts: Vec>>) -> anyhow::Result<()> { + self.0.write().add_fonts(fonts) + } + fn load_family(&self, name: &str) -> anyhow::Result> { self.0.write().load_family(name) } @@ -93,9 +102,20 @@ impl platform::FontSystem for FontSystem { } impl FontSystemState { + fn add_fonts(&mut self, fonts: Vec>>) -> anyhow::Result<()> { + self.memory_source + .add_fonts(fonts.into_iter().map(|bytes| Handle::from_memory(bytes, 0)))?; + Ok(()) + } + fn load_family(&mut self, name: &str) -> anyhow::Result> { let mut font_ids = Vec::new(); - for font in self.source.select_family_by_name(name)?.fonts() { + + let family = self + .memory_source + .select_family_by_name(name) + .or_else(|_| self.system_source.select_family_by_name(name))?; + for font in family.fonts() { let font = font.load()?; font_ids.push(FontId(self.fonts.len())); self.fonts.push(font); diff --git a/server/Cargo.toml b/server/Cargo.toml index fec5bec74d30..b73c70102a31 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -29,7 +29,7 @@ oauth2-surf = "0.1.1" parking_lot = "0.11.1" postage = { version = "0.4.1", features = ["futures-traits"] } rand = "0.8" -rust-embed = "5.9.0" +rust-embed = { version = "6.2", features = ["include-exclude"] } scrypt = "0.7" serde = { version = "1.0", features = ["derive"] } sha-1 = "0.9" diff --git a/server/src/assets.rs b/server/src/assets.rs index a53be8ed95f2..4e79af8c600d 100644 --- a/server/src/assets.rs +++ b/server/src/assets.rs @@ -26,6 +26,6 @@ async fn get_static_asset(request: Request) -> tide::Result { Ok(tide::Response::builder(200) .content_type(content_type) - .body(content.as_ref()) + .body(content.data.as_ref()) .build()) } diff --git a/server/src/main.rs b/server/src/main.rs index 41f2638027c5..ba54f05f1c4d 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -83,7 +83,7 @@ impl AppState { let partial = Templates::get(path.as_ref()).unwrap(); self.handlebars .write() - .register_partial(partial_name, std::str::from_utf8(partial.as_ref()).unwrap()) + .register_partial(partial_name, std::str::from_utf8(&partial.data).unwrap()) .unwrap() } } @@ -98,7 +98,7 @@ impl AppState { self.register_partials(); self.handlebars.read().render_template( - std::str::from_utf8(Templates::get(path).unwrap().as_ref()).unwrap(), + std::str::from_utf8(&Templates::get(path).unwrap().data).unwrap(), data, ) } diff --git a/zed/Cargo.toml b/zed/Cargo.toml index 17314ebd6542..985901c50cf8 100644 --- a/zed/Cargo.toml +++ b/zed/Cargo.toml @@ -38,7 +38,7 @@ parking_lot = "0.11.1" postage = { version = "0.4.1", features = ["futures-traits"] } rand = "0.8.3" rsa = "0.4" -rust-embed = "5.9.0" +rust-embed = { version = "6.2", features = ["include-exclude"] } seahash = "4.1" serde = { version = "1", features = ["derive"] } serde_json = { version = "1.0.64", features = ["preserve_order"] } diff --git a/zed/assets/fonts/inconsolata/Inconsolata-Bold.ttf b/zed/assets/fonts/inconsolata/Inconsolata-Bold.ttf new file mode 100644 index 000000000000..e8aad4c3cd21 Binary files /dev/null and b/zed/assets/fonts/inconsolata/Inconsolata-Bold.ttf differ diff --git a/zed/assets/fonts/inconsolata/Inconsolata-Regular.ttf b/zed/assets/fonts/inconsolata/Inconsolata-Regular.ttf new file mode 100644 index 000000000000..00ffc946a5aa Binary files /dev/null and b/zed/assets/fonts/inconsolata/Inconsolata-Regular.ttf differ diff --git a/zed/assets/themes/dark.toml b/zed/assets/themes/dark.toml index 035684761374..74688fdb0d13 100644 --- a/zed/assets/themes/dark.toml +++ b/zed/assets/themes/dark.toml @@ -6,7 +6,7 @@ extends = "_base" 2 = "#131415" [text] -base = { family = "Helvetica", size = 14.0 } +base = { family = "Inconsolata", size = 14 } 0 = { extends = "$text.base", color = "#ffffff" } 1 = { extends = "$text.base", color = "#b3b3b3" } 2 = { extends = "$text.base", color = "#7b7d80" } diff --git a/zed/assets/themes/light.toml b/zed/assets/themes/light.toml index e70a088cc930..94274997a14e 100644 --- a/zed/assets/themes/light.toml +++ b/zed/assets/themes/light.toml @@ -7,7 +7,7 @@ extends = "_base" 3 = "#3a3b3c" [text] -base = { family = "Helvetica", size = 14.0 } +base = { family = "Inconsolata", size = 14 } 0 = { extends = "$text.base", color = "#acacac" } 1 = { extends = "$text.base", color = "#111111" } 2 = { extends = "$text.base", color = "#333333" } diff --git a/zed/src/assets.rs b/zed/src/assets.rs index e7c010342162..c0f3a1fbfc47 100644 --- a/zed/src/assets.rs +++ b/zed/src/assets.rs @@ -4,11 +4,14 @@ use rust_embed::RustEmbed; #[derive(RustEmbed)] #[folder = "assets"] +#[exclude = "*.DS_Store"] pub struct Assets; impl AssetSource for Assets { fn load(&self, path: &str) -> Result> { - Self::get(path).ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path)) + Self::get(path) + .map(|f| f.data) + .ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path)) } fn list(&self, path: &str) -> Vec> { diff --git a/zed/src/language.rs b/zed/src/language.rs index f6342bf254af..bcea6c25adf3 100644 --- a/zed/src/language.rs +++ b/zed/src/language.rs @@ -47,7 +47,8 @@ impl Language { impl LanguageRegistry { pub fn new() -> Self { let grammar = tree_sitter_rust::language(); - let rust_config = toml::from_slice(&LanguageDir::get("rust/config.toml").unwrap()).unwrap(); + let rust_config = + toml::from_slice(&LanguageDir::get("rust/config.toml").unwrap().data).unwrap(); let rust_language = Language { config: rust_config, grammar, @@ -84,7 +85,7 @@ impl LanguageRegistry { fn load_query(grammar: tree_sitter::Language, path: &str) -> Query { Query::new( grammar, - str::from_utf8(LanguageDir::get(path).unwrap().as_ref()).unwrap(), + str::from_utf8(&LanguageDir::get(path).unwrap().data).unwrap(), ) .unwrap() } diff --git a/zed/src/main.rs b/zed/src/main.rs index d1361870b808..3603e760eb07 100644 --- a/zed/src/main.rs +++ b/zed/src/main.rs @@ -2,12 +2,14 @@ #![allow(non_snake_case)] use fs::OpenOptions; +use gpui::AssetSource; use log::LevelFilter; use parking_lot::Mutex; use simplelog::SimpleLogger; use std::{fs, path::PathBuf, sync::Arc}; use zed::{ - self, assets, + self, + assets::Assets, channel::ChannelList, chat_panel, editor, file_finder, fs::RealFs, @@ -20,9 +22,15 @@ use zed::{ fn main() { init_logger(); - let app = gpui::App::new(assets::Assets).unwrap(); + let app = gpui::App::new(Assets).unwrap(); + let embedded_fonts = Assets + .list("fonts") + .into_iter() + .map(|f| Arc::new(Assets.load(&f).unwrap().to_vec())) + .collect(); + app.platform().fonts().add_fonts(embedded_fonts).unwrap(); - let themes = settings::ThemeRegistry::new(assets::Assets, app.font_cache()); + let themes = settings::ThemeRegistry::new(Assets, app.font_cache()); let (settings_tx, settings) = settings::channel(&app.font_cache(), &themes).unwrap(); let languages = Arc::new(language::LanguageRegistry::new()); languages.set_theme(&settings.borrow().theme.syntax); diff --git a/zed/src/settings.rs b/zed/src/settings.rs index 1cadfdaa9c1f..6b7defe1361d 100644 --- a/zed/src/settings.rs +++ b/zed/src/settings.rs @@ -37,8 +37,8 @@ impl Settings { pub fn new(font_cache: &FontCache, theme: Arc) -> Result { Ok(Self { - buffer_font_family: font_cache.load_family(&["Fira Code", "Monaco"])?, - buffer_font_size: 14.0, + buffer_font_family: font_cache.load_family(&["Inconsolata"])?, + buffer_font_size: 16., tab_size: 4, theme, })