aboutsummaryrefslogtreecommitdiff
path: root/font/src/ft/fc/char_set.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/char_set.rs
parent0f15dc05d9332bb9dc71bd9b70bc737da2dc33c5 (diff)
downloadalacritty-6b327b6f8f0f308ff8f46cdf551ce0d0f3eda60b.tar.gz
alacritty-6b327b6f8f0f308ff8f46cdf551ce0d0f3eda60b.zip
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/char_set.rs')
-rw-r--r--font/src/ft/fc/char_set.rs43
1 files changed, 41 insertions, 2 deletions
diff --git a/font/src/ft/fc/char_set.rs b/font/src/ft/fc/char_set.rs
index 89554458..4bba4818 100644
--- a/font/src/ft/fc/char_set.rs
+++ b/font/src/ft/fc/char_set.rs
@@ -13,15 +13,19 @@
// limitations under the License.
use std::ptr::NonNull;
-use foreign_types::{foreign_type, ForeignTypeRef};
+use foreign_types::{foreign_type, ForeignType, ForeignTypeRef};
use super::ffi::FcCharSetCreate;
-use super::ffi::{FcCharSet, FcCharSetAddChar, FcCharSetDestroy};
+use super::ffi::{
+ FcBool, FcCharSet, FcCharSetAddChar, FcCharSetCopy, FcCharSetCount, FcCharSetDestroy,
+ FcCharSetHasChar, FcCharSetMerge, FcCharSetSubtract, FcCharSetUnion,
+};
foreign_type! {
pub unsafe type CharSet {
type CType = FcCharSet;
fn drop = FcCharSetDestroy;
+ fn clone = FcCharSetCopy;
}
}
@@ -41,4 +45,39 @@ impl CharSetRef {
pub fn add(&mut self, glyph: char) -> bool {
unsafe { FcCharSetAddChar(self.as_ptr(), glyph as _) == 1 }
}
+
+ pub fn has_char(&self, glyph: char) -> bool {
+ unsafe { FcCharSetHasChar(self.as_ptr(), glyph as _) == 1 }
+ }
+
+ pub fn count(&self) -> u32 {
+ unsafe { FcCharSetCount(self.as_ptr()) as u32 }
+ }
+
+ pub fn union(&self, other: &CharSetRef) -> CharSet {
+ unsafe {
+ let ptr = FcCharSetUnion(self.as_ptr() as _, other.as_ptr() as _);
+ CharSet::from_ptr(ptr)
+ }
+ }
+
+ pub fn subtract(&self, other: &CharSetRef) -> CharSet {
+ unsafe {
+ let ptr = FcCharSetSubtract(self.as_ptr() as _, other.as_ptr() as _);
+ CharSet::from_ptr(ptr)
+ }
+ }
+
+ pub fn merge(&self, other: &CharSetRef) -> Result<bool, ()> {
+ unsafe {
+ // Value is just an indicator whether something was added or not
+ let mut value: FcBool = 0;
+ let res = FcCharSetMerge(self.as_ptr() as _, other.as_ptr() as _, &mut value);
+ if res == 0 {
+ Err(())
+ } else {
+ Ok(value != 0)
+ }
+ }
+ }
}