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