diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs index 97f0255..877564f 100644 --- a/font/src/darwin/mod.rs +++ b/font/src/darwin/mod.rs @@ -461,6 +461,19 @@ impl Font { } pub fn get_glyph(&self, character: char, _size: f64, use_thin_strokes: bool) -> Result { + // Render custom symbols for underline and beam cursor + if character == super::UNDERLINE_CURSOR_CHAR { + let descent = -(self.ct_font.descent() as i32); + let width = self.glyph_advance('0') as i32; + return super::get_underline_cursor_glyph(descent, width); + } else if character == super::BEAM_CURSOR_CHAR { + let metrics = self.metrics(); + let height = metrics.line_height; + let ascent = height - self.ct_font.descent() + 1.; + let width = self.glyph_advance('0') as i32; + return super::get_beam_cursor_glyph(ascent as i32, height as i32, width); + }; + let glyph_index = self.glyph_index(character) .ok_or(Error::MissingGlyph(character))?; diff --git a/font/src/lib.rs b/font/src/lib.rs index 776127e..a2580fc 100644 --- a/font/src/lib.rs +++ b/font/src/lib.rs @@ -59,18 +59,12 @@ mod darwin; pub use darwin::*; /// Character used for the underline cursor -#[cfg(not(target_os = "macos"))] // This is part of the private use area and should not conflict with any font pub const UNDERLINE_CURSOR_CHAR: char = '\u{10a3e2}'; -#[cfg(target_os = "macos")] -pub const UNDERLINE_CURSOR_CHAR: char = '▁'; /// Character used for the beam cursor -#[cfg(not(target_os = "macos"))] // This is part of the private use area and should not conflict with any font pub const BEAM_CURSOR_CHAR: char = '\u{10a3e3}'; -#[cfg(target_os = "macos")] -pub const BEAM_CURSOR_CHAR: char = '▎'; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FontDesc { @@ -217,6 +211,7 @@ impl Default for RasterizedGlyph { } // Returns a custom underline cursor character +// TODO: Make sure this works with positive/0 descent -> small fonts pub fn get_underline_cursor_glyph(descent: i32, width: i32) -> Result { // Create a new rectangle, the height is half the distance between // bounding box bottom and the baseline @@ -235,6 +230,7 @@ pub fn get_underline_cursor_glyph(descent: i32, width: i32) -> Result small fonts pub fn get_beam_cursor_glyph(ascent: i32, height: i32, width: i32) -> Result { // Create a new rectangle let beam_width = (f64::from(width) / 5.) as i32;