cairo/
recording_surface.rs
1use std::ops::Deref;
4
5#[cfg(feature = "use_glib")]
6use glib::translate::*;
7
8use crate::{ffi, Content, Error, Rectangle, Surface, SurfaceType};
9
10declare_surface!(RecordingSurface, SurfaceType::Recording);
11impl RecordingSurface {
12 #[doc(alias = "cairo_recording_surface_create")]
13 pub fn create(content: Content, extends: Option<Rectangle>) -> Result<RecordingSurface, Error> {
14 unsafe {
15 let extends_ptr = match extends {
16 Some(ref c) => c.to_raw_none(),
17 None => ::std::ptr::null(),
18 };
19
20 Self::from_raw_full(ffi::cairo_recording_surface_create(
21 content.into(),
22 extends_ptr,
23 ))
24 }
25 }
26
27 #[doc(alias = "cairo_recording_surface_get_extents")]
28 #[doc(alias = "get_extents")]
29 pub fn extents(&self) -> Option<Rectangle> {
30 unsafe {
31 let rectangle: Rectangle = ::std::mem::zeroed();
32 if ffi::cairo_recording_surface_get_extents(self.to_raw_none(), rectangle.to_raw_none())
33 .as_bool()
34 {
35 Some(rectangle)
36 } else {
37 None
38 }
39 }
40 }
41
42 #[doc(alias = "cairo_recording_surface_ink_extents")]
43 pub fn ink_extents(&self) -> (f64, f64, f64, f64) {
44 let mut x0 = 0.;
45 let mut y0 = 0.;
46 let mut width = 0.;
47 let mut height = 0.;
48
49 unsafe {
50 ffi::cairo_recording_surface_ink_extents(
51 self.to_raw_none(),
52 &mut x0,
53 &mut y0,
54 &mut width,
55 &mut height,
56 );
57 }
58 (x0, y0, width, height)
59 }
60}