From 44e8bc4683b9034707ace7524de7a4a31a638d7e Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sun, 4 May 2025 22:39:42 -0500 Subject: [PATCH] making some font changes to better fonts for slides --- src/ui/song_editor.rs | 68 ++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/src/ui/song_editor.rs b/src/ui/song_editor.rs index 5782202..97de301 100644 --- a/src/ui/song_editor.rs +++ b/src/ui/song_editor.rs @@ -31,7 +31,9 @@ use super::presenter::slide_view; pub struct SongEditor { pub song: Option, title: String, - fonts: combo_box::State, + font_db: fontdb::Database, + fonts: Vec<(fontdb::ID, String)>, + fonts_combo: combo_box::State, font_sizes: combo_box::State, font: String, author: String, @@ -72,42 +74,21 @@ impl SongEditor { pub fn new() -> Self { let fonts = font_dir(); debug!(?fonts); - let mut fontdb = fontdb::Database::new(); - fontdb.load_system_fonts(); - let fonts: Vec = fontdb + let mut font_db = fontdb::Database::new(); + font_db.load_system_fonts(); + let mut fonts: Vec<(fontdb::ID, String)> = font_db .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() + let id = f.id; + let font_base_name: String = + f.families.iter().map(|f| f.0.clone()).collect(); + let font_weight = f.weight; + let font_style = f.style; + let font_stretch = f.stretch; + (id, font_base_name) }) .collect(); + fonts.dedup(); // let fonts = vec![ // String::from("Quicksand"), // String::from("Noto Sans"), @@ -134,9 +115,12 @@ impl SongEditor { "70".to_string(), "80".to_string(), ]; + let font_texts = fonts.iter().map(|f| f.1.clone()).collect(); Self { song: None, - fonts: combo_box::State::new(fonts), + font_db, + fonts, + fonts_combo: combo_box::State::new(font_texts), title: "Death was Arrested".to_owned(), font: "Quicksand".to_owned(), font_size: 16, @@ -189,11 +173,23 @@ impl SongEditor { self.background = song.background; } Message::ChangeFont(font) => { + let font_id = self + .fonts + .iter() + .filter(|f| f.1 == font) + .map(|f| f.0) + .next(); + if let Some(id) = font_id { + if let Some(face) = self.font_db.face(id) { + self.font = face.post_script_name.clone(); + // self.current_font = Font::from(face); + } + } self.font = font.clone(); let font_name = font.into_boxed_str(); let family = Family::Name(Box::leak(font_name)); - let weight = Weight::Normal; + let weight = Weight::Bold; let stretch = Stretch::Normal; let style = Style::Normal; let font = Font { @@ -383,7 +379,7 @@ order", .get(font_size_position.unwrap_or_default()) }; let font_selector = combo_box( - &self.fonts, + &self.fonts_combo, "Font", Some(selected_font), Message::ChangeFont,