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.rs49
1 files changed, 42 insertions, 7 deletions
diff --git a/src/x/font.rs b/src/x/font.rs
index 3bd641e..2dbfb75 100644
--- a/src/x/font.rs
+++ b/src/x/font.rs
@@ -1,5 +1,7 @@
+use crate::error::Result;
+use crate::layout::Parcel;
+use crate::geometry::{ Alignment, Point, Offset, Size };
 use crate::x::*;
-use crate::geometry::{ Point, Offset, Size };
 
 use std::cell::OnceCell;
 use std::ffi::CString;
@@ -32,7 +34,7 @@ impl PartialEq for Font {
 }
 
 impl Font {
-  pub fn new(display: Arc<Display>, name: &str) -> xcb::Result<Arc<Font>> {
+  pub fn new(display: Arc<Display>, name: &str) -> Result<Arc<Font>> {
     let xlib_display = display.connection().get_xlib_display();
     let screen_index = display.screen_index();
 
@@ -67,12 +69,12 @@ impl Font {
     *descent
   }
 
-  pub fn text_span(self: &Arc<Self>, text: &str) -> xcb::Result<TextSpan> {
+  pub fn text_span(self: &Arc<Self>, text: &str) -> Result<TextSpan> {
     TextSpan::new(Arc::clone(self), text)
   }
 
   fn measure_character_heights(self: &Arc<Self>, repertoire: &str)
-    -> xcb::Result<u16>
+    -> Result<u16>
   {
     let mut max_height = 0;
     for c in repertoire.chars() {
@@ -83,7 +85,7 @@ impl Font {
     Ok(max_height)
   }
 
-  pub fn check_char_exists(self: &Arc<Self>, codepoint: u32) -> xcb::Result<bool> {
+  pub fn check_char_exists(self: &Arc<Self>, codepoint: u32) -> Result<bool> {
     let xlib_display = self.display.connection().get_xlib_display();
 
     let result = unsafe {
@@ -98,7 +100,7 @@ impl Font {
 
 
 impl TextSpan {
-  pub fn new(font: Arc<Font>, text: &str) -> xcb::Result<Self> {
+  pub fn new(font: Arc<Font>, text: &str) -> Result<Self> {
     let xlib_display = font.display.connection().get_xlib_display();
 
     let text = CString::new(text).unwrap();
@@ -147,7 +149,7 @@ impl TextSpan {
    */
   pub fn draw(&self, context: &FontGraphicContext, color: &Color,
 	      location: &Point<i32>)
-    -> xcb::Result<()>
+    -> Result<()>
   {
     let xft_draw = context.get_xft_draw();
 
@@ -215,5 +217,38 @@ impl TextSpan {
       y: self.extent.yOff,
     }
   }
+
+  pub fn layout_and_draw(&self,
+                         open_parcel: &mut Parcel, location: &mut Point<i32>,
+                         alignment: Alignment, context: &FontGraphicContext,
+                         color: &Color)
+    -> Result<()>
+  {
+    match alignment {
+      Alignment::Left => {
+        location.x += self.draw_offset().x as i32;
+      }
+      Alignment::Right => {
+        location.x -= self.draw_size().width as i32;
+      }
+    }
+
+    self.draw(&context, color, &location)?;
+
+    match alignment {
+      Alignment::Left => {
+        location.x += self.draw_size().width as i32;
+
+        open_parcel.left += self.draw_size().width as u32;
+      }
+      Alignment::Right => {
+        location.x -= self.draw_offset().x as i32;
+
+        open_parcel.right -= self.draw_size().width as u32;
+      }
+    }
+
+    Ok(())
+  }
 }