diff options
author | Aaron Williamson <guitarfanman@gmail.com> | 2017-01-28 19:30:47 -0700 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2017-05-01 08:52:22 -0700 |
commit | 7fc50f669056dc9a3a601b3f0248926384abb570 (patch) | |
tree | 8e00bef97c77714e55f4f25036f6760d2b1d1c8a /font/src/ft | |
parent | ac2a1ece9e30d8253c40bf2f1b44626292ea4f4d (diff) | |
download | alacritty-7fc50f669056dc9a3a601b3f0248926384abb570.tar.gz alacritty-7fc50f669056dc9a3a601b3f0248926384abb570.zip |
Improve freetype metric usage
The font metrics function was using freetype metrics in an ineffective
way, improve the use of those metrics and remove the now unnecessary
separate default values for font offset in linux.
Diffstat (limited to 'font/src/ft')
-rw-r--r-- | font/src/ft/mod.rs | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs index 82f06776..24ef5c77 100644 --- a/font/src/ft/mod.rs +++ b/font/src/ft/mod.rs @@ -59,18 +59,15 @@ impl ::Rasterize for FreeTypeRasterizer { .get(&key) .ok_or(Error::FontNotLoaded)?; - let scale_size = self.dpr as f64 * size.as_f32_pts() as f64; + let size_metrics = face.size_metrics() + .ok_or(Error::MissingSizeMetrics)?; - let em_size = face.em_size() as f64; - let w = face.max_advance_width() as f64; - let h = (face.ascender() - face.descender() + face.height()) as f64; - - let w_scale = w * scale_size / em_size; - let h_scale = h * scale_size / em_size; + let width = (size_metrics.max_advance / 64) as f64; + let height = (size_metrics.height / 64) as f64; Ok(Metrics { - average_advance: w_scale, - line_height: h_scale, + average_advance: width, + line_height: height, }) } @@ -278,6 +275,9 @@ pub enum Error { /// Couldn't find font matching description MissingFont(FontDesc), + /// Tried to get size metrics from a Face that didn't have a size + MissingSizeMetrics, + /// Requested an operation with a FontKey that isn't known to the rasterizer FontNotLoaded, } @@ -295,6 +295,7 @@ impl ::std::error::Error for Error { Error::FreeType(ref err) => err.description(), Error::MissingFont(ref _desc) => "couldn't find the requested font", Error::FontNotLoaded => "tried to operate on font that hasn't been loaded", + Error::MissingSizeMetrics => "tried to get size metrics from a face without a size", } } } @@ -311,6 +312,9 @@ impl ::std::fmt::Display for Error { }, Error::FontNotLoaded => { f.write_str("Tried to use a font that hasn't been loaded") + }, + Error::MissingSizeMetrics => { + f.write_str("Tried to get size metrics from a face without a size") } } } |