summaryrefslogtreecommitdiffstats
path: root/font/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'font/src/lib.rs')
-rw-r--r--font/src/lib.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/font/src/lib.rs b/font/src/lib.rs
index 5d35e47a..776127ea 100644
--- a/font/src/lib.rs
+++ b/font/src/lib.rs
@@ -65,6 +65,13 @@ 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 {
name: String,
@@ -209,6 +216,41 @@ impl Default for RasterizedGlyph {
}
}
+// Returns a custom underline cursor character
+pub fn get_underline_cursor_glyph(descent: i32, width: i32) -> Result<RasterizedGlyph, Error> {
+ // Create a new rectangle, the height is half the distance between
+ // bounding box bottom and the baseline
+ let height = i32::abs(descent / 2);
+ let buf = vec![255u8; (width * height * 3) as usize];
+
+ // Create a custom glyph with the rectangle data attached to it
+ return Ok(RasterizedGlyph {
+ c: UNDERLINE_CURSOR_CHAR,
+ top: descent + height,
+ left: 0,
+ height,
+ width,
+ buf: buf,
+ });
+}
+
+// Returns a custom beam cursor character
+pub fn get_beam_cursor_glyph(ascent: i32, height: i32, width: i32) -> Result<RasterizedGlyph, Error> {
+ // Create a new rectangle
+ let beam_width = (f64::from(width) / 5.) as i32;
+ let buf = vec![255u8; (beam_width * height * 3) as usize];
+
+ // Create a custom glyph with the rectangle data attached to it
+ return Ok(RasterizedGlyph {
+ c: BEAM_CURSOR_CHAR,
+ top: ascent,
+ left: 0,
+ height,
+ width: beam_width,
+ buf: buf,
+ });
+}
+
struct BufDebugger<'a>(&'a [u8]);
impl<'a> fmt::Debug for BufDebugger<'a> {