diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index 0a0a07382916cdc462adb4a466ebe66c7b15d23c..dbae48a5aaeb50212f3397e9eeb29293304905af 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -88,7 +88,6 @@ cocoa = "0.25" core-foundation = { version = "0.9.3", features = ["with-uuid"] } core-graphics = "0.22.3" core-text = "19.2" -font-kit = { git = "https://github.com/zed-industries/font-kit", rev = "d97147f" } foreign-types = "0.3" log.workspace = true media = { path = "../media" } diff --git a/crates/gpui/src/platform/linux.rs b/crates/gpui/src/platform/linux.rs index 7a361c70343aca35d47a212cf337a080a629f4a6..c762c3135e9c665d15a3ea3eecc924b043b04611 100644 --- a/crates/gpui/src/platform/linux.rs +++ b/crates/gpui/src/platform/linux.rs @@ -1,5 +1,7 @@ mod dispatcher; mod platform; +mod text_system; pub(crate) use dispatcher::*; pub(crate) use platform::*; +pub(crate) use text_system::*; diff --git a/crates/gpui/src/platform/linux/platform.rs b/crates/gpui/src/platform/linux/platform.rs index a2b87b7ea139db8db397ee677ccf63ab67cff8f4..327ec59d16eb644e96b80ec98df300f828a3f18a 100644 --- a/crates/gpui/src/platform/linux/platform.rs +++ b/crates/gpui/src/platform/linux/platform.rs @@ -2,9 +2,9 @@ use crate::{ Action, AnyWindowHandle, BackgroundExecutor, ClipboardItem, CursorStyle, DisplayId, - ForegroundExecutor, Keymap, LinuxDispatcher, Menu, PathPromptOptions, Platform, - PlatformDisplay, PlatformInput, PlatformTextSystem, PlatformWindow, Result, SemanticVersion, - Task, WindowOptions, + ForegroundExecutor, Keymap, LinuxDispatcher, LinuxTextSystem, Menu, PathPromptOptions, + Platform, PlatformDisplay, PlatformInput, PlatformTextSystem, PlatformWindow, Result, + SemanticVersion, Task, WindowOptions, }; use futures::channel::oneshot; @@ -23,6 +23,7 @@ pub(crate) struct LinuxPlatform(Mutex); pub(crate) struct LinuxPlatformState { background_executor: BackgroundExecutor, foreground_executor: ForegroundExecutor, + text_system: Arc, } impl Default for LinuxPlatform { @@ -37,6 +38,7 @@ impl LinuxPlatform { Self(Mutex::new(LinuxPlatformState { background_executor: BackgroundExecutor::new(dispatcher.clone()), foreground_executor: ForegroundExecutor::new(dispatcher), + text_system: Arc::new(LinuxTextSystem::new()), })) } } @@ -51,7 +53,7 @@ impl Platform for LinuxPlatform { } fn text_system(&self) -> Arc { - unimplemented!() + self.0.lock().text_system.clone() } fn run(&self, on_finish_launching: Box) { diff --git a/crates/gpui/src/platform/linux/text_system.rs b/crates/gpui/src/platform/linux/text_system.rs new file mode 100644 index 0000000000000000000000000000000000000000..30f65c0ece7ca094bb0ce000f35c5123000ab73a --- /dev/null +++ b/crates/gpui/src/platform/linux/text_system.rs @@ -0,0 +1,103 @@ +use crate::{ + Bounds, DevicePixels, Font, FontId, FontMetrics, FontRun, GlyphId, LineLayout, Pixels, + PlatformTextSystem, RenderGlyphParams, SharedString, Size, +}; +use anyhow::Result; +use collections::HashMap; +use font_kit::{ + font::Font as FontKitFont, + handle::Handle, + hinting::HintingOptions, + metrics::Metrics, + properties::{Style as FontkitStyle, Weight as FontkitWeight}, + source::SystemSource, + sources::mem::MemSource, +}; +use parking_lot::RwLock; +use smallvec::SmallVec; +use std::sync::Arc; + +pub(crate) struct LinuxTextSystem(RwLock); + +struct LinuxTextSystemState { + memory_source: MemSource, + system_source: SystemSource, + fonts: Vec, + font_selections: HashMap, + font_ids_by_postscript_name: HashMap, + font_ids_by_family_name: HashMap>, + postscript_names_by_font_id: HashMap, +} + +unsafe impl Send for LinuxTextSystemState {} +unsafe impl Sync for LinuxTextSystemState {} + +impl LinuxTextSystem { + pub(crate) fn new() -> Self { + Self(RwLock::new(LinuxTextSystemState { + memory_source: MemSource::empty(), + system_source: SystemSource::new(), + fonts: Vec::new(), + font_selections: HashMap::default(), + font_ids_by_postscript_name: HashMap::default(), + font_ids_by_family_name: HashMap::default(), + postscript_names_by_font_id: HashMap::default(), + })) + } +} + +impl Default for LinuxTextSystem { + fn default() -> Self { + Self::new() + } +} + +#[allow(unused)] +impl PlatformTextSystem for LinuxTextSystem { + fn add_fonts(&self, fonts: &[Arc>]) -> Result<()> { + unimplemented!() + } + fn all_font_names(&self) -> Vec { + unimplemented!() + } + fn all_font_families(&self) -> Vec { + unimplemented!() + } + fn font_id(&self, descriptor: &Font) -> Result { + unimplemented!() + } + fn font_metrics(&self, font_id: FontId) -> FontMetrics { + unimplemented!() + } + fn typographic_bounds(&self, font_id: FontId, glyph_id: GlyphId) -> Result> { + unimplemented!() + } + fn advance(&self, font_id: FontId, glyph_id: GlyphId) -> Result> { + unimplemented!() + } + fn glyph_for_char(&self, font_id: FontId, ch: char) -> Option { + unimplemented!() + } + fn glyph_raster_bounds(&self, params: &RenderGlyphParams) -> Result> { + unimplemented!() + } + fn rasterize_glyph( + &self, + params: &RenderGlyphParams, + raster_bounds: Bounds, + ) -> Result<(Size, Vec)> { + unimplemented!() + } + fn layout_line(&self, text: &str, font_size: Pixels, runs: &[FontRun]) -> LineLayout { + unimplemented!() + } + fn wrap_line( + &self, + text: &str, + font_id: FontId, + font_size: Pixels, + width: Pixels, + ) -> Vec { + unimplemented!() + } +}