text: add metrics and dynamic height
This commit is contained in:
parent
2568b7b1f5
commit
8b93957f31
4 changed files with 84 additions and 28 deletions
27
src/pango.rs
27
src/pango.rs
|
|
@ -85,6 +85,7 @@ extern "C" {
|
|||
ink_rect: *mut PangoRectangle,
|
||||
logical_rect: *mut PangoRectangle,
|
||||
);
|
||||
fn pango_layout_get_baseline(layout: *mut PangoLayout_) -> c::c_int;
|
||||
|
||||
fn pango_extents_to_pixels(inclusive: *mut PangoRectangle, nearest: *mut PangoRectangle);
|
||||
}
|
||||
|
|
@ -104,6 +105,7 @@ pub enum PangoError {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Default)]
|
||||
struct PangoRectangle {
|
||||
x: c::c_int,
|
||||
y: c::c_int,
|
||||
|
|
@ -111,6 +113,8 @@ struct PangoRectangle {
|
|||
height: c::c_int,
|
||||
}
|
||||
|
||||
const PANGO_SCALE: i32 = 1024;
|
||||
|
||||
pub struct CairoImageSurface {
|
||||
s: *mut cairo_surface_t,
|
||||
}
|
||||
|
|
@ -325,18 +329,29 @@ impl PangoLayout {
|
|||
|
||||
pub fn inc_pixel_rect(&self) -> Rect {
|
||||
unsafe {
|
||||
let mut rect = PangoRectangle {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
};
|
||||
let mut rect = PangoRectangle::default();
|
||||
pango_layout_get_extents(self.l, &mut rect, ptr::null_mut());
|
||||
pango_extents_to_pixels(&mut rect, ptr::null_mut());
|
||||
Rect::new_sized(rect.x, rect.y, rect.width, rect.height).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn logical_pixel_rect(&self) -> Rect {
|
||||
unsafe {
|
||||
let mut rect = PangoRectangle::default();
|
||||
pango_layout_get_extents(self.l, ptr::null_mut(), &mut rect);
|
||||
pango_extents_to_pixels(&mut rect, ptr::null_mut());
|
||||
Rect::new_sized(rect.x, rect.y, rect.width, rect.height).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pixel_baseline(&self) -> i32 {
|
||||
unsafe {
|
||||
let res = pango_layout_get_baseline(self.l);
|
||||
(res as i32 + PANGO_SCALE - 1) / PANGO_SCALE
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show_layout(&self) {
|
||||
unsafe {
|
||||
pango_cairo_show_layout(self.c.c.c, self.l);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue