diff --git a/Cargo.toml b/Cargo.toml index b9bbf28..5594bba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,20 +22,20 @@ strip = true [dependencies] winit = { version = "0.30.8", default-features = true } eframe = { version = "0.30.0", default-features = false, features = [ + "default_fonts", "accesskit", "persistence", "wgpu", "wayland", "x11", ] } -egui = { version = "0.30.0", default-features = false, features = [ - "persistence", -] } +egui = { version = "0.30.0" } egui_extras = "0.30.0" hex = "0.4.3" plist = "1.7.0" rfd = "0.15.2" serde = { version = "1.0.217", features = ["derive"] } +font-kit = "0.14.2" [target.'cfg(target_os = "macos")'.dependencies] objc2 = "0.5.2" @@ -46,3 +46,6 @@ objc2-app-kit = { version = "0.2.2", features = [ "NSMenuItem", ] } objc2-foundation = { version = "0.2.2", features = ["NSString", "NSThread"] } + +[patch.crates-io] +pathfinder_simd = { git = "https://github.com/theoparis/pathfinder", rev = "05f19143e21a96027de7cf2d60fa47ecd8899d21" } diff --git a/assets/fonts/Apple Symbols.ttf b/assets/fonts/Apple Symbols.ttf deleted file mode 100644 index d5f099f..0000000 Binary files a/assets/fonts/Apple Symbols.ttf and /dev/null differ diff --git a/assets/fonts/Helvetica.ttf b/assets/fonts/Helvetica.ttf deleted file mode 100644 index ee8f51c..0000000 Binary files a/assets/fonts/Helvetica.ttf and /dev/null differ diff --git a/assets/fonts/JetBrainsMonoNerdFont.ttf b/assets/fonts/JetBrainsMonoNerdFont.ttf deleted file mode 100644 index 521f56e..0000000 Binary files a/assets/fonts/JetBrainsMonoNerdFont.ttf and /dev/null differ diff --git a/assets/fonts/Symbol.ttf b/assets/fonts/Symbol.ttf deleted file mode 100644 index 2f4343a..0000000 Binary files a/assets/fonts/Symbol.ttf and /dev/null differ diff --git a/src/style.rs b/src/style.rs index b66463d..ea0c876 100644 --- a/src/style.rs +++ b/src/style.rs @@ -2,36 +2,56 @@ //! See LICENSE for details. use egui::{FontData, FontDefinitions, FontFamily}; +use font_kit::{ + family_name::FamilyName, handle::Handle, properties::Properties, source::SystemSource, +}; + +fn get_system_font(family: FamilyName) -> Option> { + match SystemSource::new() + .select_best_match(&[family], &Properties::new()) + .ok()? + { + Handle::Path { + path, + font_index: _, + } => std::fs::read(path).ok(), + Handle::Memory { + bytes, + font_index: _, + } => Some(bytes.to_vec()), + } +} pub fn get_fonts() -> FontDefinitions { let mut fonts = FontDefinitions::default(); - fonts.font_data.insert( - "Helvetica".into(), - FontData::from_static(include_bytes!("../assets/fonts/Helvetica.ttf")).into(), - ); - fonts.font_data.insert( - "JetBrainsMonoNerdFont".into(), - FontData::from_static(include_bytes!("../assets/fonts/JetBrainsMonoNerdFont.ttf")).into(), - ); - fonts.font_data.insert( - "Symbol".into(), - FontData::from_static(include_bytes!("../assets/fonts/Symbol.ttf")).into(), - ); - fonts.font_data.insert( - "Apple Symbols".into(), - FontData::from_static(include_bytes!("../assets/fonts/Apple Symbols.ttf")).into(), - ); - - let ent = fonts.families.entry(FontFamily::Proportional).or_default(); - ent.insert(0, "Helvetica".into()); - ent.insert(1, "Symbol".into()); - ent.insert(2, "Apple Symbols".into()); - let ent = fonts.families.entry(FontFamily::Monospace).or_default(); - ent.insert(0, "JetBrainsMonoNerdFont".into()); - ent.insert(1, "Symbol".into()); - ent.insert(2, "Apple Symbols".into()); - ent.push("Helvetica".into()); + if let Some(sans_serif) = get_system_font(FamilyName::SansSerif) { + fonts.font_data.insert( + "System Sans Serif".into(), + FontData::from_owned(sans_serif).into(), + ); + fonts + .families + .entry(FontFamily::Proportional) + .or_default() + .insert(0, "System Sans Serif".into()); + fonts + .families + .entry(FontFamily::Monospace) + .or_default() + .insert(0, "System Sans Serif".into()); + } + if let Some(monospace) = get_system_font(FamilyName::Monospace) { + fonts.font_data.insert( + "System Monospace".into(), + FontData::from_owned(monospace).into(), + ); + fonts + .families + .entry(FontFamily::Monospace) + .or_default() + .insert(0, "System Monospace".into()); + } fonts }