Skip to content

Commit 1c73527

Browse files
committed
Add the default for fontconfig cachedir
1 parent 13fd37b commit 1c73527

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

fontique/src/backend/fontconfig/config.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub fn parse_config(path: &Path, sink: &mut impl ParserSink) {
3030
if root.tag_name().name() != "fontconfig" {
3131
return;
3232
}
33+
let mut cachedir_count = 0;
3334
let mut prefer = vec![];
3435
'outer: for child in root.children() {
3536
match child.tag_name().name() {
@@ -65,6 +66,7 @@ pub fn parse_config(path: &Path, sink: &mut impl ParserSink) {
6566
"cachedir" => {
6667
if let Some(path) = resolve_dir(child, path) {
6768
sink.cache_path(&path);
69+
cachedir_count += 1;
6870
}
6971
}
7072
"include" => {
@@ -121,6 +123,16 @@ pub fn parse_config(path: &Path, sink: &mut impl ParserSink) {
121123
_ => {}
122124
}
123125
}
126+
127+
if cachedir_count == 0 {
128+
if let Ok(home) = config_home() {
129+
let default_cache_dir = std::env::var("XDG_CACHE_HOME")
130+
.map(PathBuf::from)
131+
.unwrap_or(Path::new(&home).join(".cache"))
132+
.join("fontconfig");
133+
sink.cache_path(&default_cache_dir);
134+
}
135+
}
124136
}
125137

126138
/// Families we care about for aliases.

0 commit comments

Comments
 (0)