From 73641d03673638e361b0254ce400c02b1b65e6ed Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Sun, 23 Feb 2020 02:09:23 +0300 Subject: [PATCH] Fix Fontconfig's font size query Previously we were rounding pattern's `pixelsize` before `fc_sort`, however we were using not rounded one in `get_glyph`, so bitmap fonts could look a bit smaller when used in a mix with scalable fonts. --- CHANGELOG.md | 1 + font/src/ft/mod.rs | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bf47af..fabcf11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Parser reset between DCS escapes - Parser stopping at unknown DEC private modes/SGR character attributes - Block selection appending duplicate newlines when last column is selected +- Bitmap fonts being a bit smaller than they should be in some cases ### Removed diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs index 3e43a29..385c66d 100644 --- a/font/src/ft/mod.rs +++ b/font/src/ft/mod.rs @@ -100,7 +100,6 @@ pub struct FreeTypeRasterizer { keys: HashMap, fallback_lists: HashMap, device_pixel_ratio: f32, - pixel_size: f64, } #[inline] @@ -120,7 +119,6 @@ impl Rasterize for FreeTypeRasterizer { fallback_lists: HashMap::new(), library, device_pixel_ratio, - pixel_size: 0.0, }) } @@ -219,13 +217,12 @@ impl FreeTypeRasterizer { /// Load a font face according to `FontDesc` fn get_face(&mut self, desc: &FontDesc, size: Size) -> Result { // Adjust for DPI - let size = Size::new(size.as_f32_pts() * self.device_pixel_ratio * 96. / 72.); - self.pixel_size = f64::from(size.as_f32_pts()); + let size = f64::from(size.as_f32_pts() * self.device_pixel_ratio * 96. / 72.); let config = fc::Config::get_current(); let mut pattern = Pattern::new(); pattern.add_family(&desc.name); - pattern.add_pixelsize(self.pixel_size); + pattern.add_pixelsize(size); let hash = pattern.hash(); // Add style to a pattern @@ -473,7 +470,7 @@ impl FreeTypeRasterizer { } else { // Fallback if user has bitmap scaling disabled let metrics = face.ft_face.size_metrics().ok_or(Error::MissingSizeMetrics)?; - self.pixel_size as f64 / metrics.y_ppem as f64 + size as f64 / metrics.y_ppem as f64 }; Ok(downsample_bitmap(rasterized_glyph, fixup_factor)) } else {