[librsvg: 12/13] use RsvgRectangle as out arguments for get_geometry_sub()



commit 1b15fc5f6200575333954f643ff6b79aedc257cf
Author: Julian Sparber <julian sparber net>
Date:   Sun Nov 25 21:43:47 2018 +0100

    use RsvgRectangle as out arguments for get_geometry_sub()

 librsvg/rsvg-handle.c             | 16 ++++++++--------
 librsvg/rsvg-private.h            |  2 +-
 librsvg/rsvg.h                    | 22 +++++++++++++++++++++-
 rsvg_internals/src/drawing_ctx.rs | 17 +++++++++++++----
 tests/api.c                       |  4 ++--
 tests/dimensions.c                |  4 ++--
 6 files changed, 47 insertions(+), 18 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index a1b245d2..13eb6b1a 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -1199,7 +1199,7 @@ rsvg_handle_get_dimensions (RsvgHandle * handle, RsvgDimensionData * dimension_d
 }
 
 static gboolean
-get_node_geometry(RsvgHandle *handle, RsvgNode *node, cairo_rectangle_t *ink_rect, cairo_rectangle_t 
*logical_rect)
+get_node_geometry(RsvgHandle *handle, RsvgNode *node, RsvgRectangle *ink_rect, RsvgRectangle *logical_rect)
 {
     RsvgDimensionData dimensions;
     cairo_surface_t *target;
@@ -1250,12 +1250,12 @@ get_node_geometry(RsvgHandle *handle, RsvgNode *node, cairo_rectangle_t *ink_rec
 gboolean
 rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimension_data, const char *id)
 {
-    cairo_rectangle_t ink_r;
+    RsvgRectangle ink_r;
 
     g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
     g_return_val_if_fail (dimension_data, FALSE);
 
-    memset (&ink_r, 0, sizeof (cairo_rectangle_t));
+    memset (&ink_r, 0, sizeof (RsvgRectangle));
     memset (dimension_data, 0, sizeof (RsvgDimensionData));
 
     if (!rsvg_handle_get_geometry_sub (handle, &ink_r, NULL, id)) {
@@ -1289,19 +1289,19 @@ rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimensi
  * Since: 2.46
  */
 gboolean
-rsvg_handle_get_geometry_sub (RsvgHandle * handle, cairo_rectangle_t * ink_rect, cairo_rectangle_t * 
logical_rect, const char *id)
+rsvg_handle_get_geometry_sub (RsvgHandle * handle, RsvgRectangle * ink_rect, RsvgRectangle * logical_rect, 
const char *id)
 {
     RsvgNode *root = NULL;
     RsvgNode *node;
     gboolean has_size;
     int root_width, root_height;
     gboolean res = FALSE;
-    cairo_rectangle_t ink_r, logical_r;
+    RsvgRectangle ink_r, logical_r;
 
     g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
 
-    memset (&ink_r, 0, sizeof (cairo_rectangle_t));
-    memset (&logical_r, 0, sizeof (cairo_rectangle_t));
+    memset (&ink_r, 0, sizeof (RsvgRectangle));
+    memset (&logical_r, 0, sizeof (RsvgRectangle));
 
     if (handle->priv->tree == NULL)
         return FALSE;
@@ -1376,7 +1376,7 @@ out:
 gboolean
 rsvg_handle_get_position_sub (RsvgHandle * handle, RsvgPositionData * position_data, const char *id)
 {
-    cairo_rectangle_t ink_r;
+    RsvgRectangle ink_r;
     int width, height;
 
     g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
diff --git a/librsvg/rsvg-private.h b/librsvg/rsvg-private.h
index 296b8c1a..58145e73 100644
--- a/librsvg/rsvg-private.h
+++ b/librsvg/rsvg-private.h
@@ -223,7 +223,7 @@ gboolean rsvg_drawing_ctx_draw_node_from_stack (RsvgDrawingCtx *ctx, RsvgTree *t
 
 /* Defined in rsvg_internals/src/drawing_ctx.rs */
 G_GNUC_INTERNAL
-void rsvg_drawing_ctx_get_geometry (RsvgDrawingCtx *ctx, cairo_rectangle_t *ink_rect, cairo_rectangle_t 
*logical_rect);
+void rsvg_drawing_ctx_get_geometry (RsvgDrawingCtx *ctx, RsvgRectangle *ink_rect, RsvgRectangle 
*logical_rect);
 
 /* Implemented in rust/src/node.rs */
 G_GNUC_INTERNAL
diff --git a/librsvg/rsvg.h b/librsvg/rsvg.h
index 880f9c9e..ddc8c2a7 100644
--- a/librsvg/rsvg.h
+++ b/librsvg/rsvg.h
@@ -71,6 +71,7 @@ typedef struct RsvgHandlePrivate RsvgHandlePrivate;
 typedef struct _RsvgHandleClass RsvgHandleClass;
 typedef struct _RsvgDimensionData RsvgDimensionData;
 typedef struct _RsvgPositionData RsvgPositionData;
+typedef struct _RsvgRectangle RsvgRectangle;
 
 /**
  * RsvgHandleClass:
@@ -131,6 +132,25 @@ struct _RsvgPositionData {
     int y;
 };
 
+/**
+ * RsvgRectangle:
+ * @x: X coordinate of the left side of the rectangle
+ * @y: Y coordinate of the the top side of the rectangle
+ * @width: width of the rectangle
+ * @height: height of the rectangle
+ *
+ * A data structure for holding a rectangle.
+ *
+ * Since: 2.46
+ */
+struct _RsvgRectangle {
+    double x;
+    double y;
+    double width;
+    double height;
+};
+
+
 void rsvg_cleanup (void);
 
 RSVG_DEPRECATED
@@ -156,7 +176,7 @@ void rsvg_handle_get_dimensions (RsvgHandle * handle, RsvgDimensionData * dimens
 
 gboolean rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimension_data, const char 
*id);
 gboolean rsvg_handle_get_position_sub (RsvgHandle * handle, RsvgPositionData * position_data, const char 
*id);
-gboolean rsvg_handle_get_geometry_sub (RsvgHandle * handle, cairo_rectangle_t * ink_rect, cairo_rectangle_t 
* logical_rect, const char *id);
+gboolean rsvg_handle_get_geometry_sub (RsvgHandle * handle, RsvgRectangle * ink_rect, RsvgRectangle * 
logical_rect, const char *id);
 
 gboolean rsvg_handle_has_sub (RsvgHandle * handle, const char *id);
 
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index a39696cb..f7e66ef5 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -1093,11 +1093,20 @@ pub extern "C" fn rsvg_drawing_ctx_add_node_and_ancestors_to_stack(
     draw_ctx.add_node_and_ancestors_to_stack(node);
 }
 
+#[derive(Clone, Copy, Debug, PartialEq)]
+#[repr(C)]
+pub struct RsvgRectangle {
+    pub x: f64,
+    pub y: f64,
+    pub width: f64,
+    pub height: f64,
+}
+
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_drawing_ctx_get_geometry(
     raw_draw_ctx: *const RsvgDrawingCtx,
-    ink_rect: *mut cairo_sys::cairo_rectangle_t,
-    logical_rect: *mut cairo_sys::cairo_rectangle_t,
+    ink_rect: *mut RsvgRectangle,
+    logical_rect: *mut RsvgRectangle,
 ) {
     assert!(!raw_draw_ctx.is_null());
     let draw_ctx = &mut *(raw_draw_ctx as *mut DrawingCtx<'_>);
@@ -1105,8 +1114,8 @@ pub unsafe extern "C" fn rsvg_drawing_ctx_get_geometry(
     assert!(!ink_rect.is_null());
     assert!(!logical_rect.is_null());
 
-    let ink_rect: &mut cairo::Rectangle = &mut *ink_rect;
-    let logical_rect: &mut cairo::Rectangle = &mut *logical_rect;
+    let ink_rect: &mut RsvgRectangle = &mut *ink_rect;
+    let logical_rect: &mut RsvgRectangle = &mut *logical_rect;
 
     match draw_ctx.get_bbox().ink_rect {
         Some(r) => {
diff --git a/tests/api.c b/tests/api.c
index 33504e3b..943d4450 100644
--- a/tests/api.c
+++ b/tests/api.c
@@ -501,8 +501,8 @@ dimensions_and_position (void)
     g_assert_cmpint (pos.y, ==, EXAMPLE_TWO_Y);
 
     /* TODO: test logical_rect */
-    cairo_rectangle_t ink_rect;
-    cairo_rectangle_t logical_rect;
+    RsvgRectangle ink_rect;
+    RsvgRectangle logical_rect;
     g_assert (rsvg_handle_get_geometry_sub (handle, &ink_rect, &logical_rect, EXAMPLE_TWO_ID));
     g_assert_cmpint (ink_rect.x, ==, EXAMPLE_TWO_X);
     g_assert_cmpint (ink_rect.y, ==, EXAMPLE_TWO_Y);
diff --git a/tests/dimensions.c b/tests/dimensions.c
index b109ea69..9edad448 100644
--- a/tests/dimensions.c
+++ b/tests/dimensions.c
@@ -28,8 +28,8 @@ test_dimensions (FixtureData *fixture)
     RsvgHandle *handle;
     RsvgPositionData position;
     RsvgDimensionData dimension;
-    cairo_rectangle_t ink_rect;
-    cairo_rectangle_t logical_rect;
+    RsvgRectangle ink_rect;
+    RsvgRectangle logical_rect;
     gchar *target_file;
     GError *error = NULL;
 


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