1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
use crate::x::*;
use std::ffi::CString;
use std::sync::Arc;
use x11::xft::{
XftColor,
XftDraw,
XftDrawStringUtf8,
XftFontOpenName,
};
pub struct Font {
display: Arc<Display>,
font_state: *mut x11::xft::XftFont,
}
impl Font {
pub fn new(display: Arc<Display>, name: &str) -> xcb::Result<Font> {
let xlib_display = display.connection().get_xlib_display();
let screen_index = display.screen_index();
let name = CString::new(name).unwrap();
let font_state = unsafe {
XftFontOpenName(xlib_display, screen_index, name.as_ptr().cast())
};
Ok(Font { display, font_state })
}
pub fn draw(&self, xft_context: *mut XftDraw, xft_color: &XftColor,
x: i32, y: i32, text: &str)
-> xcb::Result<()>
{
let text = CString::new(text).unwrap();
unsafe {
XftDrawStringUtf8(xft_context, xft_color, self.font_state, x, y,
text.as_ptr().cast(), text.count_bytes() as i32)
};
Ok(())
}
}
|