trying to add fonts
This commit is contained in:
parent
0b317c0f1e
commit
60e1d294b1
|
@ -1,10 +1,12 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
|
font,
|
||||||
iced::{
|
iced::{
|
||||||
font::{Family, Stretch, Style, Weight},
|
font::{Family, Stretch, Style, Weight},
|
||||||
Font, Length,
|
Font, Length,
|
||||||
},
|
},
|
||||||
|
iced_wgpu::graphics::text::cosmic_text::fontdb,
|
||||||
iced_widget::row,
|
iced_widget::row,
|
||||||
theme,
|
theme,
|
||||||
widget::{
|
widget::{
|
||||||
|
@ -14,6 +16,7 @@ use cosmic::{
|
||||||
},
|
},
|
||||||
Element, Task,
|
Element, Task,
|
||||||
};
|
};
|
||||||
|
use dirs::font_dir;
|
||||||
use iced_video_player::Video;
|
use iced_video_player::Video;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
@ -60,10 +63,48 @@ pub enum Message {
|
||||||
|
|
||||||
impl SongEditor {
|
impl SongEditor {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let fonts = vec![
|
let fonts = font_dir();
|
||||||
String::from("Quicksand"),
|
debug!(?fonts);
|
||||||
String::from("Noto Sans"),
|
let mut fontdb = fontdb::Database::new();
|
||||||
];
|
fontdb.load_system_fonts();
|
||||||
|
let fonts: Vec<String> = 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<usize> = 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![
|
let font_sizes = vec![
|
||||||
"10".to_string(),
|
"10".to_string(),
|
||||||
"12".to_string(),
|
"12".to_string(),
|
||||||
|
|
Loading…
Reference in a new issue