making some font changes to better fonts for slides

This commit is contained in:
Chris Cochrun 2025-05-04 22:39:42 -05:00
parent 625988820c
commit 44e8bc4683

View file

@ -31,7 +31,9 @@ use super::presenter::slide_view;
pub struct SongEditor { pub struct SongEditor {
pub song: Option<Song>, pub song: Option<Song>,
title: String, title: String,
fonts: combo_box::State<String>, font_db: fontdb::Database,
fonts: Vec<(fontdb::ID, String)>,
fonts_combo: combo_box::State<String>,
font_sizes: combo_box::State<String>, font_sizes: combo_box::State<String>,
font: String, font: String,
author: String, author: String,
@ -72,42 +74,21 @@ impl SongEditor {
pub fn new() -> Self { pub fn new() -> Self {
let fonts = font_dir(); let fonts = font_dir();
debug!(?fonts); debug!(?fonts);
let mut fontdb = fontdb::Database::new(); let mut font_db = fontdb::Database::new();
fontdb.load_system_fonts(); font_db.load_system_fonts();
let fonts: Vec<String> = fontdb let mut fonts: Vec<(fontdb::ID, String)> = font_db
.faces() .faces()
.map(|f| { .map(|f| {
let mut font = f.to_owned().post_script_name; let id = f.id;
if let Some(at) = font.find("-") { let font_base_name: String =
let _ = font.split_off(at); f.families.iter().map(|f| f.0.clone()).collect();
} let font_weight = f.weight;
let indices: Vec<usize> = font let font_style = f.style;
.chars() let font_stretch = f.stretch;
.enumerate() (id, font_base_name)
.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(); .collect();
fonts.dedup();
// let fonts = vec![ // let fonts = vec![
// String::from("Quicksand"), // String::from("Quicksand"),
// String::from("Noto Sans"), // String::from("Noto Sans"),
@ -134,9 +115,12 @@ impl SongEditor {
"70".to_string(), "70".to_string(),
"80".to_string(), "80".to_string(),
]; ];
let font_texts = fonts.iter().map(|f| f.1.clone()).collect();
Self { Self {
song: None, 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(), title: "Death was Arrested".to_owned(),
font: "Quicksand".to_owned(), font: "Quicksand".to_owned(),
font_size: 16, font_size: 16,
@ -189,11 +173,23 @@ impl SongEditor {
self.background = song.background; self.background = song.background;
} }
Message::ChangeFont(font) => { 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(); self.font = font.clone();
let font_name = font.into_boxed_str(); let font_name = font.into_boxed_str();
let family = Family::Name(Box::leak(font_name)); let family = Family::Name(Box::leak(font_name));
let weight = Weight::Normal; let weight = Weight::Bold;
let stretch = Stretch::Normal; let stretch = Stretch::Normal;
let style = Style::Normal; let style = Style::Normal;
let font = Font { let font = Font {
@ -383,7 +379,7 @@ order",
.get(font_size_position.unwrap_or_default()) .get(font_size_position.unwrap_or_default())
}; };
let font_selector = combo_box( let font_selector = combo_box(
&self.fonts, &self.fonts_combo,
"Font", "Font",
Some(selected_font), Some(selected_font),
Message::ChangeFont, Message::ChangeFont,