about summary refs log tree commit diff
path: root/src/x/font.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/x/font.rs')
-rw-r--r--src/x/font.rs33
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,