[librsvg: 5/30] drop get_ prefix from glib APIs getters




commit 222f4be5b8f68a3cf80242159bece0c9ec8d6e6f
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Tue May 4 13:02:05 2021 +0200

    drop get_ prefix from glib APIs getters
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/516>

 src/api.rs                          |  2 +-
 src/c_api/handle.rs                 |  6 +--
 src/document.rs                     |  2 +-
 src/drawing_ctx.rs                  | 21 +++++----
 src/filters/lighting.rs             |  2 +-
 src/surface_utils/shared_surface.rs | 87 ++++++++++++++++++-------------------
 src/text.rs                         | 18 ++++----
 7 files changed, 67 insertions(+), 71 deletions(-)
---
diff --git a/src/api.rs b/src/api.rs
index a8a09343..b35064f8 100644
--- a/src/api.rs
+++ b/src/api.rs
@@ -207,7 +207,7 @@ impl Loader {
 }
 
 fn url_from_file(file: &gio::File) -> Result<Url, LoadingError> {
-    Url::parse(&file.get_uri()).map_err(|_| LoadingError::BadUrl)
+    Url::parse(&file.uri()).map_err(|_| LoadingError::BadUrl)
 }
 
 /// Handle used to hold SVG data in memory.
diff --git a/src/c_api/handle.rs b/src/c_api/handle.rs
index 4bdf9773..271a8b06 100644
--- a/src/c_api/handle.rs
+++ b/src/c_api/handle.rs
@@ -651,7 +651,7 @@ impl CHandle {
     }
 
     fn set_base_gfile(&self, file: &gio::File) {
-        self.set_base_url(&file.get_uri());
+        self.set_base_url(&file.uri());
     }
 
     fn get_base_url(&self) -> Option<String> {
@@ -1088,12 +1088,12 @@ fn is_cancellable(obj: *mut gio::ffi::GCancellable) -> bool {
 
 fn get_rust_handle<'a>(handle: *const RsvgHandle) -> &'a CHandle {
     let handle = unsafe { &*handle };
-    handle.get_impl()
+    handle.impl_()
 }
 
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_handle_get_type() -> glib::ffi::GType {
-    CHandle::get_type().to_glib()
+    CHandle::type_().to_glib()
 }
 
 #[no_mangle]
diff --git a/src/document.rs b/src/document.rs
index 7a48304a..97dfbae7 100644
--- a/src/document.rs
+++ b/src/document.rs
@@ -268,7 +268,7 @@ fn load_image(
     loader.write(&bytes)?;
     loader.close()?;
 
-    let pixbuf = loader.get_pixbuf().ok_or_else(|| {
+    let pixbuf = loader.pixbuf().ok_or_else(|| {
         LoadingError::Other(format!("loading image: {}", human_readable_url(aurl)))
     })?;
 
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 5ff8049a..b0825835 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -206,7 +206,7 @@ pub fn draw_tree(
 
     // Preserve the user's transform and use it for the outermost bounding box.  All bounds/extents
     // will be converted to this transform in the end.
-    let user_transform = Transform::from(cr.get_matrix());
+    let user_transform = Transform::from(cr.matrix());
     let mut user_bbox = BoundingBox::new().with_transform(user_transform);
 
     // https://www.w3.org/TR/SVG2/coords.html#InitialCoordinateSystem
@@ -335,7 +335,7 @@ impl DrawingCtx {
     }
 
     fn get_transform(&self) -> Transform {
-        Transform::from(self.cr.get_matrix())
+        Transform::from(self.cr.matrix())
     }
 
     pub fn empty_bbox(&self) -> BoundingBox {
@@ -713,8 +713,7 @@ impl DrawingCtx {
 
                 let cr = match stacking_ctx.filter {
                     Filter::None => cairo::Context::new(
-                        &self
-                            .create_similar_surface_for_toplevel_viewport(&self.cr.get_target())?,
+                        &self.create_similar_surface_for_toplevel_viewport(&self.cr.target())?,
                     ),
                     Filter::List(_) => {
                         cairo::Context::new(&*self.create_surface_for_toplevel_viewport()?)
@@ -1022,7 +1021,7 @@ impl DrawingCtx {
         // Draw to another surface
         let surface = self
             .cr
-            .get_target()
+            .target()
             .create_similar(cairo::Content::ColorAlpha, pw, ph)?;
 
         let cr_pattern = cairo::Context::new(&surface);
@@ -1339,7 +1338,7 @@ impl DrawingCtx {
     ) -> Result<BoundingBox, RenderingError> {
         let transform = self.get_transform();
 
-        let gravity = span.layout.get_context().unwrap().get_gravity();
+        let gravity = span.layout.context().unwrap().gravity();
 
         let bbox = compute_text_box(&span.layout, span.x, span.y, transform, gravity);
         if bbox.is_none() {
@@ -1436,13 +1435,13 @@ impl DrawingCtx {
             // stacking contexts instead, or the result of rendering stacking contexts?
             for (depth, draw) in self.cr_stack.borrow().iter().enumerate() {
                 let affines = CompositingAffines::new(
-                    Transform::from(draw.get_matrix()),
+                    Transform::from(draw.matrix()),
                     self.initial_transform_with_offset(),
                     depth,
                 );
 
                 cr.set_matrix(affines.for_snapshot.into());
-                cr.set_source_surface(&draw.get_target(), 0.0, 0.0);
+                cr.set_source_surface(&draw.target(), 0.0, 0.0);
                 cr.paint();
             }
 
@@ -1746,14 +1745,14 @@ fn compute_stroke_and_fill_box(
     stroke: &Stroke,
     stroke_paint_source: &PaintSource,
 ) -> BoundingBox {
-    let affine = Transform::from(cr.get_matrix());
+    let affine = Transform::from(cr.matrix());
 
     let mut bbox = BoundingBox::new().with_transform(affine);
 
     // Dropping the precision of cairo's bezier subdivision, yielding 2x
     // _rendering_ time speedups, are these rather expensive operations
     // really needed here? */
-    let backup_tolerance = cr.get_tolerance();
+    let backup_tolerance = cr.tolerance();
     cr.set_tolerance(1.0);
 
     // Bounding box for fill
@@ -1813,7 +1812,7 @@ fn compute_text_box(
 ) -> Option<BoundingBox> {
     #![allow(clippy::many_single_char_names)]
 
-    let (ink, _) = layout.get_extents();
+    let (ink, _) = layout.extents();
     if ink.width == 0 || ink.height == 0 {
         return None;
     }
diff --git a/src/filters/lighting.rs b/src/filters/lighting.rs
index 9a9c188e..2fe9d453 100644
--- a/src/filters/lighting.rs
+++ b/src/filters/lighting.rs
@@ -493,7 +493,7 @@ macro_rules! impl_lighting_filter {
 
                 {
                     let output_stride = surface.stride() as usize;
-                    let mut output_data = surface.get_data();
+                    let mut output_data = surface.data();
                     let output_slice = &mut *output_data;
 
                     let compute_output_pixel =
diff --git a/src/surface_utils/shared_surface.rs b/src/surface_utils/shared_surface.rs
index d570fdad..c3e8f002 100644
--- a/src/surface_utils/shared_surface.rs
+++ b/src/surface_utils/shared_surface.rs
@@ -78,7 +78,7 @@ pub enum Operator {
 /// Wrapper for a Cairo image surface that enforces exclusive access when modifying it.
 ///
 /// Shared access to `cairo::ImageSurface` is tricky since a read-only borrowed reference
-/// can still be cloned and then modified. We can't simply use `cairo::ImageSurface::get_data()`
+/// can still be cloned and then modified. We can't simply use `cairo::ImageSurface::data()`
 /// because in the filter code we have surfaces referenced from multiple places and it would
 /// probably add more complexity to remove that and start passing around references.
 ///
@@ -202,13 +202,13 @@ impl ImageSurface<Shared> {
         surface_type: SurfaceType,
     ) -> Result<SharedImageSurface, cairo::Error> {
         // get_pixel() assumes ARgb32.
-        assert_eq!(surface.get_format(), cairo::Format::ARgb32);
+        assert_eq!(surface.format(), cairo::Format::ARgb32);
 
         let reference_count =
             unsafe { cairo::ffi::cairo_surface_get_reference_count(surface.to_raw_none()) };
         assert_eq!(reference_count, 1);
 
-        let (width, height) = (surface.get_width(), surface.get_height());
+        let (width, height) = (surface.width(), surface.height());
 
         // Cairo allows zero-sized surfaces, but it does malloc(0), whose result
         // is implementation-defined.  So, we can't assume NonNull below.  This is
@@ -222,7 +222,7 @@ impl ImageSurface<Shared> {
         })
         .unwrap();
 
-        let stride = surface.get_stride() as isize;
+        let stride = surface.stride() as isize;
 
         Ok(SharedImageSurface {
             state: Shared,
@@ -239,11 +239,8 @@ impl ImageSurface<Shared> {
     /// does not have a reference count of 1.
     #[inline]
     pub fn copy_from_surface(surface: &cairo::ImageSurface) -> Result<Self, cairo::Error> {
-        let copy = cairo::ImageSurface::create(
-            cairo::Format::ARgb32,
-            surface.get_width(),
-            surface.get_height(),
-        )?;
+        let copy =
+            cairo::ImageSurface::create(cairo::Format::ARgb32, surface.width(), surface.height())?;
 
         {
             let cr = cairo::Context::new(&copy);
@@ -281,19 +278,19 @@ impl ImageSurface<Shared> {
         content_type: Option<&str>,
         mime_data: Option<Vec<u8>>,
     ) -> Result<SharedImageSurface, cairo::Error> {
-        assert!(pixbuf.get_colorspace() == Colorspace::Rgb);
-        assert!(pixbuf.get_bits_per_sample() == 8);
+        assert!(pixbuf.colorspace() == Colorspace::Rgb);
+        assert!(pixbuf.bits_per_sample() == 8);
 
-        let n_channels = pixbuf.get_n_channels();
+        let n_channels = pixbuf.n_channels();
         assert!(n_channels == 3 || n_channels == 4);
         let has_alpha = n_channels == 4;
 
-        let width = pixbuf.get_width();
-        let height = pixbuf.get_height();
-        let stride = pixbuf.get_rowstride() as usize;
+        let width = pixbuf.width();
+        let height = pixbuf.height();
+        let stride = pixbuf.rowstride() as usize;
         assert!(width > 0 && height > 0 && stride > 0);
 
-        let pixbuf_data = unsafe { pixbuf.get_pixels() };
+        let pixbuf_data = unsafe { pixbuf.pixels() };
 
         let mut surf = ExclusiveImageSurface::new(width, height, SurfaceType::SRgb)?;
 
@@ -329,12 +326,12 @@ impl ImageSurface<Shared> {
 
         let pixbuf = Pixbuf::new(Colorspace::Rgb, true, 8, width, height)?;
 
-        assert!(pixbuf.get_colorspace() == Colorspace::Rgb);
-        assert!(pixbuf.get_bits_per_sample() == 8);
-        assert!(pixbuf.get_n_channels() == 4);
+        assert!(pixbuf.colorspace() == Colorspace::Rgb);
+        assert!(pixbuf.bits_per_sample() == 8);
+        assert!(pixbuf.n_channels() == 4);
 
-        let pixbuf_data = unsafe { pixbuf.get_pixels() };
-        let stride = pixbuf.get_rowstride() as usize;
+        let pixbuf_data = unsafe { pixbuf.pixels() };
+        let stride = pixbuf.rowstride() as usize;
 
         // We use chunks_mut(), not chunks_exact_mut(), because gdk-pixbuf tends
         // to make the last row *not* have the full stride (i.e. it is
@@ -466,9 +463,9 @@ impl ImageSurface<Shared> {
         let mut output_surface =
             cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
 
-        let output_stride = output_surface.get_stride() as usize;
+        let output_stride = output_surface.stride() as usize;
         {
-            let mut output_data = output_surface.get_data().unwrap();
+            let mut output_data = output_surface.data().unwrap();
 
             for (x, y, Pixel { a, .. }) in Pixels::within(self, bounds) {
                 let output_pixel = Pixel {
@@ -496,9 +493,9 @@ impl ImageSurface<Shared> {
         let mut output_surface =
             cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
 
-        let stride = output_surface.get_stride() as usize;
+        let stride = output_surface.stride() as usize;
         {
-            let mut data = output_surface.get_data().unwrap();
+            let mut data = output_surface.data().unwrap();
             let opacity = u8::from(opacity);
 
             for (x, y, pixel) in Pixels::within(self, bounds) {
@@ -522,9 +519,9 @@ impl ImageSurface<Shared> {
         let mut output_surface =
             cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
 
-        let stride = output_surface.get_stride() as usize;
+        let stride = output_surface.stride() as usize;
         {
-            let mut data = output_surface.get_data().unwrap();
+            let mut data = output_surface.data().unwrap();
 
             for (x, y, pixel) in Pixels::within(self, bounds) {
                 data.set_pixel(stride, pixel.unpremultiply(), x, y);
@@ -577,9 +574,9 @@ impl ImageSurface<Shared> {
         let mut output_surface =
             cairo::ImageSurface::create(cairo::Format::ARgb32, self.width, self.height)?;
 
-        let output_stride = output_surface.get_stride() as usize;
+        let output_stride = output_surface.stride() as usize;
         {
-            let mut output_data = output_surface.get_data().unwrap();
+            let mut output_data = output_surface.data().unwrap();
 
             if self.is_alpha_only() {
                 for (x, y, _pixel) in Pixels::within(self, bounds) {
@@ -713,13 +710,13 @@ impl ImageSurface<Shared> {
                 /// to Cairo.
                 #[inline]
                 unsafe fn new(surface: &mut cairo::ImageSurface) -> Self {
-                    assert_eq!(surface.get_format(), cairo::Format::ARgb32);
-                    let ptr = surface.get_data().unwrap().as_mut_ptr();
+                    assert_eq!(surface.format(), cairo::Format::ARgb32);
+                    let ptr = surface.data().unwrap().as_mut_ptr();
 
                     Self {
-                        width: surface.get_width() as u32,
-                        height: surface.get_height() as u32,
-                        stride: surface.get_stride() as isize,
+                        width: surface.width() as u32,
+                        height: surface.height() as u32,
+                        stride: surface.stride() as isize,
                         ptr: NonNull::new(ptr).unwrap(),
                         _marker: PhantomData,
                     }
@@ -1068,7 +1065,7 @@ impl ImageSurface<Shared> {
                 );
                 matrix.invert();
 
-                cr.get_source().set_matrix(matrix);
+                cr.source().set_matrix(matrix);
             }
 
             cr.paint();
@@ -1301,7 +1298,7 @@ impl ImageSurface<Exclusive> {
     ) -> Result<ExclusiveImageSurface, cairo::Error> {
         let surface = cairo::ImageSurface::create(cairo::Format::ARgb32, width, height)?;
 
-        let (width, height) = (surface.get_width(), surface.get_height());
+        let (width, height) = (surface.width(), surface.height());
 
         // Cairo allows zero-sized surfaces, but it does malloc(0), whose result
         // is implementation-defined.  So, we can't assume NonNull below.  This is
@@ -1313,7 +1310,7 @@ impl ImageSurface<Exclusive> {
         })
         .unwrap();
 
-        let stride = surface.get_stride() as isize;
+        let stride = surface.stride() as isize;
 
         Ok(ExclusiveImageSurface {
             state: Exclusive,
@@ -1333,15 +1330,15 @@ impl ImageSurface<Exclusive> {
 
     /// Raw access to the image data as a slice
     #[inline]
-    pub fn get_data(&mut self) -> cairo::ImageSurfaceData<'_> {
-        self.surface.get_data().unwrap()
+    pub fn data(&mut self) -> cairo::ImageSurfaceData<'_> {
+        self.surface.data().unwrap()
     }
 
     /// Modify the image data
     #[inline]
     pub fn modify(&mut self, draw_fn: &mut dyn FnMut(&mut cairo::ImageSurfaceData<'_>, usize)) {
         let stride = self.stride() as usize;
-        let mut data = self.get_data();
+        let mut data = self.data();
 
         draw_fn(&mut data, stride)
     }
@@ -1357,11 +1354,11 @@ impl ImageSurface<Exclusive> {
     }
 
     pub fn rows_mut(&mut self) -> RowsMut<'_> {
-        let width = self.surface.get_width();
-        let height = self.surface.get_height();
-        let stride = self.surface.get_stride();
+        let width = self.surface.width();
+        let height = self.surface.height();
+        let stride = self.surface.stride();
 
-        let data = self.surface.get_data().unwrap();
+        let data = self.surface.data().unwrap();
 
         RowsMut {
             width,
@@ -1420,7 +1417,7 @@ mod tests {
 
         // Fill the surface with some data.
         {
-            let mut data = surface.get_data();
+            let mut data = surface.data();
 
             let mut counter = 0u16;
             for x in data.iter_mut() {
diff --git a/src/text.rs b/src/text.rs
index 91515246..83b4daa1 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -193,7 +193,7 @@ impl MeasuredSpan {
 
         let properties = FontProperties::new(&values, &params);
         let layout = create_pango_layout(draw_ctx, &properties, &span.text);
-        let (w, h) = layout.get_size();
+        let (w, h) = layout.size();
 
         let w = f64::from(w) / f64::from(pango::SCALE);
         let h = f64::from(h) / f64::from(pango::SCALE);
@@ -228,7 +228,7 @@ impl PositionedSpan {
         let view_params = draw_ctx.get_view_params();
         let params = NormalizeParams::new(&values, &view_params);
 
-        let baseline = f64::from(layout.get_baseline()) / f64::from(pango::SCALE);
+        let baseline = f64::from(layout.baseline()) / f64::from(pango::SCALE);
         let baseline_shift = values.baseline_shift().0.to_user(&params);
         let offset = baseline + baseline_shift;
 
@@ -833,7 +833,7 @@ fn create_pango_layout(draw_ctx: &DrawingCtx, props: &FontProperties, text: &str
         }
     }
 
-    let mut font_desc = pango_context.get_font_description().unwrap();
+    let mut font_desc = pango_context.font_description().unwrap();
     font_desc.set_family(props.font_family.as_str());
     font_desc.set_style(pango::Style::from(props.font_style));
 
@@ -864,23 +864,23 @@ fn create_pango_layout(draw_ctx: &DrawingCtx, props: &FontProperties, text: &str
 
     let attr_list = pango::AttrList::new();
 
-    attr_list.insert(
-        pango::Attribute::new_letter_spacing(to_pango_units(props.letter_spacing)).unwrap(),
-    );
+    attr_list.insert(pango::Attribute::new_letter_spacing(to_pango_units(
+        props.letter_spacing,
+    )));
 
     if props.text_decoration.underline {
-        attr_list.insert(pango::Attribute::new_underline(pango::Underline::Single).unwrap());
+        attr_list.insert(pango::Attribute::new_underline(pango::Underline::Single));
     }
 
     if props.text_decoration.strike {
-        attr_list.insert(pango::Attribute::new_strikethrough(true).unwrap());
+        attr_list.insert(pango::Attribute::new_strikethrough(true));
     }
 
     // FIXME: Using the "smcp" OpenType feature only works for fonts that support it.  We
     // should query if the font supports small caps, and synthesize them if it doesn't.
     if props.font_variant == FontVariant::SmallCaps {
         // smcp - small capitals - https://docs.microsoft.com/en-ca/typography/opentype/spec/features_pt#smcp
-        attr_list.insert(pango::Attribute::new_font_features("'smcp' 1").unwrap());
+        attr_list.insert(pango::Attribute::new_font_features("'smcp' 1"));
     }
 
     layout.set_attributes(Some(&attr_list));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]