From 60e1d294b1e8b40cfc1a22dd3b7ffbc629d9397b Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 12 Mar 2025 16:15:02 -0500 Subject: [PATCH] trying to add fonts --- src/ui/song_editor.rs | 49 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/src/ui/song_editor.rs b/src/ui/song_editor.rs index f1e8fdd..06ac171 100644 --- a/src/ui/song_editor.rs +++ b/src/ui/song_editor.rs @@ -1,10 +1,12 @@ use std::path::PathBuf; use cosmic::{ + font, iced::{ font::{Family, Stretch, Style, Weight}, Font, Length, }, + iced_wgpu::graphics::text::cosmic_text::fontdb, iced_widget::row, theme, widget::{ @@ -14,6 +16,7 @@ use cosmic::{ }, Element, Task, }; +use dirs::font_dir; use iced_video_player::Video; use tracing::debug; @@ -60,10 +63,48 @@ pub enum Message { impl SongEditor { pub fn new() -> Self { - let fonts = vec![ - String::from("Quicksand"), - String::from("Noto Sans"), - ]; + let fonts = font_dir(); + debug!(?fonts); + let mut fontdb = fontdb::Database::new(); + fontdb.load_system_fonts(); + let fonts: Vec = fontdb + .faces() + .map(|f| { + let mut font = f.to_owned().post_script_name; + if let Some(at) = font.find("-") { + let _ = font.split_off(at); + } + let indices: Vec = font + .chars() + .enumerate() + .filter(|(index, c)| { + c.is_uppercase() && *index != 0 + }) + .map(|(index, c)| index) + .collect(); + + let mut font_parts = vec![]; + for index in indices.iter().rev() { + let (first, last) = font.split_at(*index); + font_parts.push(first); + if !last.is_empty() { + font_parts.push(last); + } + } + font_parts + .iter() + .map(|s| { + let mut s = s.to_string(); + s.push(' '); + s + }) + .collect() + }) + .collect(); + // let fonts = vec![ + // String::from("Quicksand"), + // String::from("Noto Sans"), + // ]; let font_sizes = vec![ "10".to_string(), "12".to_string(),