feat: configurable primary_font
This commit is contained in:
@@ -138,6 +138,10 @@ fn def_toast_topics() -> IdMap<ToastTopic, DisplayMethod> {
|
|||||||
IdMap::new()
|
IdMap::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn def_font() -> Arc<str> {
|
||||||
|
"LiberationSans:style=Bold".into()
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct GeneralConfig {
|
pub struct GeneralConfig {
|
||||||
#[serde(default = "def_watch_pos")]
|
#[serde(default = "def_watch_pos")]
|
||||||
@@ -223,6 +227,9 @@ pub struct GeneralConfig {
|
|||||||
|
|
||||||
#[serde(default = "def_false")]
|
#[serde(default = "def_false")]
|
||||||
pub focus_follows_mouse_mode: bool,
|
pub focus_follows_mouse_mode: bool,
|
||||||
|
|
||||||
|
#[serde(default = "def_font")]
|
||||||
|
pub primary_font: Arc<str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GeneralConfig {
|
impl GeneralConfig {
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ use vulkano::{command_buffer::CommandBufferUsage, format::Format, image::Image};
|
|||||||
|
|
||||||
use crate::graphics::WlxGraphics;
|
use crate::graphics::WlxGraphics;
|
||||||
|
|
||||||
const PRIMARY_FONT: &str = "LiberationSans";
|
|
||||||
|
|
||||||
pub struct FontCache {
|
pub struct FontCache {
|
||||||
|
primary_font: Arc<str>,
|
||||||
fc: FontConfig,
|
fc: FontConfig,
|
||||||
ft: Library,
|
ft: Library,
|
||||||
collections: IdMap<isize, FontCollection>,
|
collections: IdMap<isize, FontCollection>,
|
||||||
@@ -35,11 +34,12 @@ pub struct Glyph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FontCache {
|
impl FontCache {
|
||||||
pub fn new() -> anyhow::Result<Self> {
|
pub fn new(primary_font: Arc<str>) -> anyhow::Result<Self> {
|
||||||
let ft = Library::init()?;
|
let ft = Library::init()?;
|
||||||
let fc = FontConfig::default();
|
let fc = FontConfig::default();
|
||||||
|
|
||||||
Ok(FontCache {
|
Ok(FontCache {
|
||||||
|
primary_font,
|
||||||
fc,
|
fc,
|
||||||
ft,
|
ft,
|
||||||
collections: IdMap::new(),
|
collections: IdMap::new(),
|
||||||
@@ -105,7 +105,8 @@ impl FontCache {
|
|||||||
return *font;
|
return *font;
|
||||||
}
|
}
|
||||||
|
|
||||||
let pattern_str = format!("{PRIMARY_FONT}-{size}:style=bold:charset={cp:04x}");
|
let primary_font = self.primary_font.clone();
|
||||||
|
let pattern_str = format!("{primary_font}:size={size}:charset={cp:04x}");
|
||||||
let mut pattern = OwnedPattern::from_str(&pattern_str).unwrap(); // safe because PRIMARY_FONT is const
|
let mut pattern = OwnedPattern::from_str(&pattern_str).unwrap(); // safe because PRIMARY_FONT is const
|
||||||
self.fc
|
self.fc
|
||||||
.substitute(&mut pattern, fontconfig::MatchKind::Pattern);
|
.substitute(&mut pattern, fontconfig::MatchKind::Pattern);
|
||||||
|
|||||||
@@ -56,9 +56,11 @@ impl AppState {
|
|||||||
shaders.insert("frag_srgb", shader);
|
shaders.insert("frag_srgb", shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let session = AppSession::load();
|
||||||
|
|
||||||
Ok(AppState {
|
Ok(AppState {
|
||||||
fc: FontCache::new()?,
|
fc: FontCache::new(session.config.primary_font.clone())?,
|
||||||
session: AppSession::load(),
|
session,
|
||||||
tasks: TaskContainer::new(),
|
tasks: TaskContainer::new(),
|
||||||
graphics,
|
graphics,
|
||||||
input_state: InputState::new(),
|
input_state: InputState::new(),
|
||||||
|
|||||||
Reference in New Issue
Block a user