aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2020-03-07 02:15:43 +0300
committerGitHub <noreply@github.com>2020-03-06 23:15:43 +0000
commitde5d770416eb6ea5567b2b46874b8e35b084b9e1 (patch)
tree5a2afbc20b8bdee35ca79844732b4ab5a62f8518
parent33cabfc3d2e9dca3267199c822d2a37ed6d72260 (diff)
downloadalacritty-de5d770416eb6ea5567b2b46874b8e35b084b9e1.tar.gz
alacritty-de5d770416eb6ea5567b2b46874b8e35b084b9e1.zip
Fix caching of variable font faces
-rw-r--r--font/src/ft/fc/mod.rs2
-rw-r--r--font/src/ft/fc/pattern.rs19
-rw-r--r--font/src/ft/mod.rs19
3 files changed, 29 insertions, 11 deletions
diff --git a/font/src/ft/fc/mod.rs b/font/src/ft/fc/mod.rs
index d2fd9d0a..cfcac4aa 100644
--- a/font/src/ft/fc/mod.rs
+++ b/font/src/ft/fc/mod.rs
@@ -41,7 +41,7 @@ pub mod char_set;
pub use char_set::{CharSet, CharSetRef};
pub mod pattern;
-pub use pattern::{Pattern, PatternHash, PatternRef};
+pub use pattern::{FTFaceLocation, Pattern, PatternHash, PatternRef};
/// Find the font closest matching the provided pattern.
///
diff --git a/font/src/ft/fc/pattern.rs b/font/src/ft/fc/pattern.rs
index d7e824ed..53641f67 100644
--- a/font/src/ft/fc/pattern.rs
+++ b/font/src/ft/fc/pattern.rs
@@ -356,6 +356,18 @@ macro_rules! string_accessor {
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct PatternHash(pub u32);
+#[derive(Hash, Eq, PartialEq, Debug)]
+pub struct FTFaceLocation {
+ pub path: PathBuf,
+ pub index: isize,
+}
+
+impl FTFaceLocation {
+ pub fn new(path: PathBuf, index: isize) -> Self {
+ Self { path, index }
+ }
+}
+
impl Pattern {
pub fn new() -> Self {
Self::default()
@@ -583,6 +595,13 @@ impl PatternRef {
unsafe { self.get_string(b"file\0").nth(index) }.map(From::from)
}
+ pub fn ft_face_location(&self, index: usize) -> Option<FTFaceLocation> {
+ match (self.file(index), self.index().next()) {
+ (Some(path), Some(index)) => Some(FTFaceLocation::new(path, index)),
+ _ => None,
+ }
+ }
+
pub fn config_substitute(&mut self, config: &ConfigRef, kind: MatchKind) {
unsafe {
FcConfigSubstitute(config.as_ptr(), self.as_ptr(), kind as u32);
diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs
index c4034a2a..9b84f55d 100644
--- a/font/src/ft/mod.rs
+++ b/font/src/ft/mod.rs
@@ -16,7 +16,6 @@
use std::cmp::{min, Ordering};
use std::collections::HashMap;
use std::fmt::{self, Display, Formatter};
-use std::path::PathBuf;
use std::rc::Rc;
use freetype::tt_os2::TrueTypeOS2Table;
@@ -27,7 +26,7 @@ use log::{debug, trace};
pub mod fc;
-use fc::{CharSet, Pattern, PatternHash, PatternRef};
+use fc::{CharSet, FTFaceLocation, Pattern, PatternHash, PatternRef};
use super::{
BitmapBuffer, FontDesc, FontKey, GlyphKey, Metrics, Rasterize, RasterizedGlyph, Size, Slant,
@@ -90,7 +89,7 @@ impl fmt::Debug for FaceLoadingProperties {
pub struct FreeTypeRasterizer {
library: Library,
faces: HashMap<FontKey, FaceLoadingProperties>,
- ft_faces: HashMap<PathBuf, Rc<FTFace>>,
+ ft_faces: HashMap<FTFaceLocation, Rc<FTFace>>,
fallback_lists: HashMap<FontKey, FallbackList>,
device_pixel_ratio: f32,
}
@@ -294,8 +293,8 @@ impl FreeTypeRasterizer {
Ok(FullMetrics { size_metrics, cell_width: width })
}
- fn load_ft_face(&mut self, path: PathBuf, index: isize) -> Result<Rc<FTFace>, Error> {
- let mut ft_face = self.library.new_face(&path, index)?;
+ fn load_ft_face(&mut self, ft_face_location: FTFaceLocation) -> Result<Rc<FTFace>, Error> {
+ let mut ft_face = self.library.new_face(&ft_face_location.path, ft_face_location.index)?;
if ft_face.has_color() {
unsafe {
// Select the colored bitmap size to use from the array of available sizes
@@ -304,7 +303,7 @@ impl FreeTypeRasterizer {
}
let ft_face = Rc::new(ft_face);
- self.ft_faces.insert(path, Rc::clone(&ft_face));
+ self.ft_faces.insert(ft_face_location, Rc::clone(&ft_face));
Ok(ft_face)
}
@@ -314,16 +313,16 @@ impl FreeTypeRasterizer {
pattern: &PatternRef,
font_key: FontKey,
) -> Result<Option<FontKey>, Error> {
- if let (Some(path), Some(index)) = (pattern.file(0), pattern.index().next()) {
+ if let Some(ft_face_location) = pattern.ft_face_location(0) {
if self.faces.get(&font_key).is_some() {
return Ok(Some(font_key));
}
- trace!("Got font path={:?}", path);
+ trace!("Got font path={:?}, index={:?}", ft_face_location.path, ft_face_location.index);
- let ft_face = match self.ft_faces.get(&path) {
+ let ft_face = match self.ft_faces.get(&ft_face_location) {
Some(ft_face) => Rc::clone(ft_face),
- None => self.load_ft_face(path, index)?,
+ None => self.load_ft_face(ft_face_location)?,
};
let non_scalable = if pattern.scalable().next().unwrap_or(true) {