diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-22 03:31:51 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-22 21:40:21 -0700 |
| commit | 33a0aea1fa5b12c817cc299b10f8a359d670c645 (patch) | |
| tree | 1f29b867d49a6158edc679c3cc1521a77f1175d7 /src/x/font.rs | |
| parent | efa17e7eb566d81ce821bde459e900d7398a9977 (diff) | |
there are now concepts of font lists and text lines
a "line" is a list of spans much of the layout logic is moved into TextLine, but not yet all of it Change-Id: I2edba34cd9be5a50ac6dc646cd6e2ab2369fca13 Force-Push: yes
Diffstat (limited to 'src/x/font.rs')
| -rw-r--r-- | src/x/font.rs | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/x/font.rs b/src/x/font.rs index 8d49e98..3bd641e 100644 --- a/src/x/font.rs +++ b/src/x/font.rs @@ -5,7 +5,9 @@ use std::cell::OnceCell; use std::ffi::CString; use std::sync::Arc; -use x11::xft::{ XftDrawStringUtf8, XftTextExtentsUtf8, XftFontOpenName }; +use x11::xft::{ + XftCharExists, XftDrawStringUtf8, XftTextExtentsUtf8, XftFontOpenName +}; use x11::xrender::XGlyphInfo; @@ -22,6 +24,13 @@ pub struct TextSpan { } +impl PartialEq for Font { + fn eq(&self, other: &Font) -> bool { + self.display == other.display + && self.font_state == other.font_state + } +} + impl Font { pub fn new(display: Arc<Display>, name: &str) -> xcb::Result<Arc<Font>> { let xlib_display = display.connection().get_xlib_display(); @@ -32,7 +41,10 @@ impl Font { XftFontOpenName(xlib_display, screen_index, name.as_ptr().cast()) }; - let font = Arc::new(Font { display, font_state, metrics: OnceCell::new() }); + let font = Arc::new(Font { + display, font_state, + metrics: OnceCell::new(), + }); let x_height = font.measure_character_heights("acemnorsuvwxz")?; let ascent = font.text_span("bdfhiklt")?.draw_size().height; @@ -70,6 +82,18 @@ impl Font { Ok(max_height) } + + pub fn check_char_exists(self: &Arc<Self>, codepoint: u32) -> xcb::Result<bool> { + let xlib_display = self.display.connection().get_xlib_display(); + + let result = unsafe { + XftCharExists(xlib_display, + self.font_state, + codepoint) + }; + + Ok(result != 0) + } } @@ -122,7 +146,7 @@ impl TextSpan { * deeply saddening, but there is nothing to be done but deal with it. */ pub fn draw(&self, context: &FontGraphicContext, color: &Color, - location: Point<i32>) + location: &Point<i32>) -> xcb::Result<()> { let xft_draw = context.get_xft_draw(); @@ -146,7 +170,7 @@ impl TextSpan { pub fn draw_offset(&self) -> Offset<i16> { Offset { x: self.extent.x, - y: self.extent.y + y: self.extent.y, } } @@ -184,6 +208,7 @@ impl TextSpan { * pixel, which causes it to often be smaller than draw_size(). See the note * on draw() for some highly relevant philosophy. */ + #[allow(unused)] pub fn logical_offset(&self) -> Offset<i16> { Offset { x: self.extent.xOff, |