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.
This commit is contained in:
parent
62d9174509
commit
793b5cc3a9
|
@ -273,6 +273,54 @@ impl FreeTypeRasterizer {
|
||||||
|
|
||||||
fn get_rendered_glyph(&mut self, glyph_key: &GlyphKey)
|
fn get_rendered_glyph(&mut self, glyph_key: &GlyphKey)
|
||||||
-> Result<RasterizedGlyph, Error> {
|
-> Result<RasterizedGlyph, Error> {
|
||||||
|
// 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).unwrap();
|
||||||
|
let size_metrics = face.ft_face
|
||||||
|
.size_metrics()
|
||||||
|
.ok_or(Error::MissingSizeMetrics)?;
|
||||||
|
|
||||||
|
// Get the bottom of the bounding box
|
||||||
|
let descent = (size_metrics.descender / 64) as i32;
|
||||||
|
|
||||||
|
// Get the width of the cell
|
||||||
|
let width = (size_metrics.max_advance / 64) as i32;
|
||||||
|
|
||||||
|
// Return the new custom glyph
|
||||||
|
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).unwrap();
|
||||||
|
let size_metrics = face.ft_face
|
||||||
|
.size_metrics()
|
||||||
|
.ok_or(Error::MissingSizeMetrics)?;
|
||||||
|
|
||||||
|
// Get the height of the cell
|
||||||
|
let height = (size_metrics.height / 64) as i32;
|
||||||
|
|
||||||
|
// Get the top of the bounding box
|
||||||
|
let descent = (size_metrics.descender / 64) as i32;
|
||||||
|
let ascent = height + descent;
|
||||||
|
|
||||||
|
// Get the width of the cell
|
||||||
|
let width = (size_metrics.max_advance / 64) as i32;
|
||||||
|
|
||||||
|
// Return the new custom glyph
|
||||||
|
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)
|
||||||
|
};
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render a normal character if it's not a cursor
|
||||||
let font_key = self.face_for_glyph(glyph_key, false)?;
|
let font_key = self.face_for_glyph(glyph_key, false)?;
|
||||||
let face = self.faces.get(&font_key).unwrap();
|
let face = self.faces.get(&font_key).unwrap();
|
||||||
let index = face.ft_face.get_char_index(glyph_key.c as usize);
|
let index = face.ft_face.get_char_index(glyph_key.c as usize);
|
||||||
|
@ -294,62 +342,14 @@ impl FreeTypeRasterizer {
|
||||||
|
|
||||||
let (pixel_width, buf) = Self::normalize_buffer(&glyph.bitmap())?;
|
let (pixel_width, buf) = Self::normalize_buffer(&glyph.bitmap())?;
|
||||||
|
|
||||||
// Render a custom symbol for the underline and beam cursor
|
Ok(RasterizedGlyph {
|
||||||
match glyph_key.c {
|
c: glyph_key.c,
|
||||||
super::UNDERLINE_CURSOR_CHAR => {
|
top: glyph.bitmap_top(),
|
||||||
// Get the primary face metrics
|
left: glyph.bitmap_left(),
|
||||||
// This always loads the default face
|
width: pixel_width,
|
||||||
let face = self.faces.get(glyph_key.font_key)?;
|
height: glyph.bitmap().rows(),
|
||||||
let size_metrics = face.ft_face
|
buf: buf,
|
||||||
.size_metrics()
|
})
|
||||||
.ok_or(Error::MissingSizeMetrics)?;
|
|
||||||
|
|
||||||
// Get the bottom of the bounding box
|
|
||||||
let descent = (size_metrics.descender / 64) as i32;
|
|
||||||
|
|
||||||
// Get the width of the cell
|
|
||||||
let width = (size_metrics.max_advance / 64) as i32;
|
|
||||||
|
|
||||||
// Return the new custom glyph
|
|
||||||
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 size_metrics = face.ft_face
|
|
||||||
.size_metrics()
|
|
||||||
.ok_or(Error::MissingSizeMetrics)?;
|
|
||||||
|
|
||||||
// Get the height of the cell
|
|
||||||
let height = (size_metrics.height / 64) as i32;
|
|
||||||
|
|
||||||
// Get the top of the bounding box
|
|
||||||
let descent = (size_metrics.descender / 64) as i32;
|
|
||||||
let ascent = height + descent;
|
|
||||||
|
|
||||||
// Get the width of the cell
|
|
||||||
let width = (size_metrics.max_advance / 64) as i32;
|
|
||||||
|
|
||||||
// Return the new custom glyph
|
|
||||||
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,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ft_load_flags(pat: &fc::Pattern) -> freetype::face::LoadFlag {
|
fn ft_load_flags(pat: &fc::Pattern) -> freetype::face::LoadFlag {
|
||||||
|
|
Loading…
Reference in New Issue