Skip to content

Commit fa27906

Browse files
committed
Fix default font selection
1 parent 03765ea commit fa27906

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎src/config.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ impl Config {
6565
self.input_text.password = true;
6666
}
6767

68+
pub fn override_font(&mut self, font: String) {
69+
self.font = Some(font);
70+
}
71+
6872
pub fn is_height_adaptive(&self) -> bool {
6973
self.adaptive_height
7074
}

‎src/font/fdue.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,20 @@ fn index_to_u32(idx: i32) -> Option<u32> {
108108

109109
impl FontBackend for Font {
110110
fn default() -> Self {
111+
for name in ["DejaVu Sans Mono", "monospace"] {
112+
if let Ok(font) = Font::font_by_name(name) {
113+
return font;
114+
}
115+
}
116+
117+
log::info!("no preferred default font found, falling back to any available font");
111118
let pat = Pattern::new(&FONTCONFIG_CACHE);
112119
fontconfig::list_fonts(&pat, None)
113120
.iter()
121+
.filter(|pat| {
122+
pat.lang_set()
123+
.map_or(false, |mut langs| langs.any(|l| l == "en"))
124+
})
114125
.find_map(|pat| {
115126
let path = std::path::Path::new(pat.filename()?);
116127
if !path.exists() {
@@ -263,3 +274,19 @@ impl FontBackend for Font {
263274
}
264275
}
265276
}
277+
278+
#[cfg(test)]
279+
mod tests {
280+
use super::*;
281+
282+
#[test]
283+
fn fontconfig_has_en_font() {
284+
let pat = Pattern::new(&FONTCONFIG_CACHE);
285+
let fonts = fontconfig::list_fonts(&pat, None);
286+
let has_en = fonts.iter().any(|pat| {
287+
pat.lang_set()
288+
.map_or(false, |mut langs| langs.any(|l| l == "en"))
289+
});
290+
assert!(has_en, "no font with English language support found");
291+
}
292+
}

0 commit comments

Comments
 (0)