summaryrefslogtreecommitdiffstats
path: root/font/src/ft/fc/mod.rs
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2020-01-27 03:54:33 +0300
committerGitHub <noreply@github.com>2020-01-27 03:54:33 +0300
commit6b327b6f8f0f308ff8f46cdf551ce0d0f3eda60b (patch)
treeb42a7002902be622cd853b87f48508f8bdd89e9b /font/src/ft/fc/mod.rs
parent0f15dc05d9332bb9dc71bd9b70bc737da2dc33c5 (diff)
Rework Fontconfig fallback to use cached list from font_sort
Previous implementation was querying Fontconfig using `charset` in a pattern, which was leading to unpredictable fallbacks in some cases, since Fontconfig was picking the font with the most coverage for a given charset, regardless of user configuration. Moreover all fallback was based on font_match which is extremely slow for such performance sensitive task as a fallback, so alacritty had a hard times on vtebench's unicode-random-write. The new approach is to use some internal fallback list from font_sort and iterate over it to get a proper fallback font, since it matches the following example query from `fc-match`: `fc-match -s "monospace:pixelsize=X:style=Y" That being said it's more intuitive for users to setup their system Fontconfig fallback, and also most applications are doing similar things. Moreover the new implementation uses internal caches over Fontconfig API when possible and performs font matches only once during load of requested font with font_sort, which leads to dramatically improved performance on already mentioned vtebench's unicode-random-write. Fixes #3176. Fixes #3134. Fixes #2657. Fixes #1560. Fixes #965. Fixes #511.
Diffstat (limited to 'font/src/ft/fc/mod.rs')
-rw-r--r--font/src/ft/fc/mod.rs7
1 files changed, 3 insertions, 4 deletions
diff --git a/font/src/ft/fc/mod.rs b/font/src/ft/fc/mod.rs
index 612f7c5a..7389614f 100644
--- a/font/src/ft/fc/mod.rs
+++ b/font/src/ft/fc/mod.rs
@@ -75,11 +75,10 @@ pub fn font_sort(config: &ConfigRef, pattern: &mut PatternRef) -> Option<FontSet
let mut result = FcResultNoMatch;
let mut charsets: *mut _ = ptr::null_mut();
-
let ptr = FcFontSort(
config.as_ptr(),
pattern.as_ptr(),
- 0, // false
+ 1, // Trim font list
&mut charsets,
&mut result,
);
@@ -323,7 +322,7 @@ mod tests {
let fonts = super::font_sort(config, &mut pattern).expect("sort font monospace");
for font in fonts.into_iter().take(10) {
- let font = font.render_prepare(&config, &pattern);
+ let font = pattern.render_prepare(&config, &font);
print!("index={:?}; ", font.index());
print!("family={:?}; ", font.family());
print!("style={:?}; ", font.style());
@@ -345,7 +344,7 @@ mod tests {
let fonts = super::font_sort(config, &mut pattern).expect("font_sort");
for font in fonts.into_iter().take(10) {
- let font = font.render_prepare(&config, &pattern);
+ let font = pattern.render_prepare(&config, &font);
print!("index={:?}; ", font.index());
print!("family={:?}; ", font.family());
print!("style={:?}; ", font.style());