diff options
author | Christian Dürr <contact@christianduerr.com> | 2017-12-24 17:17:07 +0100 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2017-12-24 09:46:54 -0800 |
commit | 793b5cc3a9e16d25a3a623f0a00517da3b04c0ea (patch) | |
tree | c92b93b847f348bf3a8c7a366e161fab22f5d7a4 | |
parent | 62d9174509059460262ce458b622d87d1562d406 (diff) | |
download | alacritty-793b5cc3a9e16d25a3a623f0a00517da3b04c0ea.tar.gz alacritty-793b5cc3a9e16d25a3a623f0a00517da3b04c0ea.zip |
Move custom cursor block on ft
Moved the custom cursor block on ft to the top, so no unnecessary
operations are executed when trying to draw a custom cursor glyph.
-rw-r--r-- | font/src/ft/mod.rs | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs index b46b0086..7ed3b426 100644 --- a/font/src/ft/mod.rs +++ b/font/src/ft/mod.rs @@ -273,33 +273,12 @@ impl FreeTypeRasterizer { fn get_rendered_glyph(&mut self, glyph_key: &GlyphKey) -> Result<RasterizedGlyph, Error> { - let font_key = self.face_for_glyph(glyph_key, false)?; - let face = self.faces.get(&font_key).unwrap(); - let index = face.ft_face.get_char_index(glyph_key.c as usize); - - let size = face.non_scalable.as_ref() - .map(|v| v.pixelsize as f32) - .unwrap_or_else(|| glyph_key.size.as_f32_pts() * self.device_pixel_ratio * 96. / 72.); - - face.ft_face.set_char_size(to_freetype_26_6(size), 0, 0, 0)?; - - unsafe { - let ft_lib = self.library.raw(); - freetype::ffi::FT_Library_SetLcdFilter(ft_lib, face.lcd_filter); - } - - face.ft_face.load_glyph(index as u32, face.load_flags)?; - let glyph = face.ft_face.glyph(); - glyph.render_glyph(face.render_mode)?; - - let (pixel_width, buf) = Self::normalize_buffer(&glyph.bitmap())?; - // Render a custom symbol for the underline and beam cursor match glyph_key.c { super::UNDERLINE_CURSOR_CHAR => { // Get the primary face metrics // This always loads the default face - let face = self.faces.get(glyph_key.font_key)?; + let face = self.faces.get(&glyph_key.font_key).unwrap(); let size_metrics = face.ft_face .size_metrics() .ok_or(Error::MissingSizeMetrics)?; @@ -311,12 +290,12 @@ impl FreeTypeRasterizer { let width = (size_metrics.max_advance / 64) as i32; // Return the new custom glyph - super::get_underline_cursor_glyph(descent, width) - } + return super::get_underline_cursor_glyph(descent, width); + }, super::BEAM_CURSOR_CHAR | super::BOX_CURSOR_CHAR => { // Get the primary face metrics // This always loads the default face - let face = self.faces.get(glyph_key.font_key)?; + let face = self.faces.get(&glyph_key.font_key).unwrap(); let size_metrics = face.ft_face .size_metrics() .ok_or(Error::MissingSizeMetrics)?; @@ -332,24 +311,45 @@ impl FreeTypeRasterizer { let width = (size_metrics.max_advance / 64) as i32; // Return the new custom glyph - if glyph_key.c == super::BEAM_CURSOR_CHAR { + return if glyph_key.c == super::BEAM_CURSOR_CHAR { super::get_beam_cursor_glyph(ascent, height, width) } else { super::get_box_cursor_glyph(ascent, height, width) - } - } - _ => { - // If it's not a special char, return the normal glyph - Ok(RasterizedGlyph { - c: glyph_key.c, - top: glyph.bitmap_top(), - left: glyph.bitmap_left(), - width: pixel_width, - height: glyph.bitmap().rows(), - buf: buf, - }) - } + }; + }, + _ => (), + } + + // Render a normal character if it's not a cursor + let font_key = self.face_for_glyph(glyph_key, false)?; + let face = self.faces.get(&font_key).unwrap(); + let index = face.ft_face.get_char_index(glyph_key.c as usize); + + let size = face.non_scalable.as_ref() + .map(|v| v.pixelsize as f32) + .unwrap_or_else(|| glyph_key.size.as_f32_pts() * self.device_pixel_ratio * 96. / 72.); + + face.ft_face.set_char_size(to_freetype_26_6(size), 0, 0, 0)?; + + unsafe { + let ft_lib = self.library.raw(); + freetype::ffi::FT_Library_SetLcdFilter(ft_lib, face.lcd_filter); } + + face.ft_face.load_glyph(index as u32, face.load_flags)?; + let glyph = face.ft_face.glyph(); + glyph.render_glyph(face.render_mode)?; + + let (pixel_width, buf) = Self::normalize_buffer(&glyph.bitmap())?; + + Ok(RasterizedGlyph { + c: glyph_key.c, + top: glyph.bitmap_top(), + left: glyph.bitmap_left(), + width: pixel_width, + height: glyph.bitmap().rows(), + buf: buf, + }) } fn ft_load_flags(pat: &fc::Pattern) -> freetype::face::LoadFlag { |