Commit b4ab2aaa authored by Paolo Borelli's avatar Paolo Borelli

Do not assert if we ask dimensions of a file with no ink box

Avoid to assert on files that do not have ink box at all.
Also add a testcase and improve the test.
Hopefully fixes GNOME/librsvg#324:
at least it fixes the mininal test case, but the crash of vmware
viewer needs to be tested.

Fixes GNOME/librsvg#324
parent 9f8ed056
Pipeline #27024 passed with stages
in 7 minutes and 57 seconds
......@@ -1124,13 +1124,13 @@ get_node_ink_rect(RsvgHandle *handle, RsvgNode *node, cairo_rectangle_t *ink_rec
cairo_surface_t *target;
cairo_t *cr;
RsvgDrawingCtx *draw;
gboolean res;
gboolean res = FALSE;
g_assert (node != NULL);
rsvg_handle_get_dimensions (handle, &dimensions);
if (dimensions.width == 0 || dimensions.height == 0)
return FALSE;
return res;
target = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 1, 1);
cr = cairo_create (target);
......@@ -1140,7 +1140,9 @@ get_node_ink_rect(RsvgHandle *handle, RsvgNode *node, cairo_rectangle_t *ink_rec
rsvg_tree_cascade (handle->priv->tree);
res = rsvg_drawing_ctx_draw_node_from_stack (draw, handle->priv->tree);
rsvg_drawing_ctx_get_ink_rect (draw, ink_rect);
if (res) {
res = rsvg_drawing_ctx_get_ink_rect (draw, ink_rect);
}
rsvg_drawing_ctx_free (draw);
cairo_destroy (cr);
......
......@@ -262,7 +262,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_ink_rect (RsvgDrawingCtx *ctx, cairo_rectangle_t *ink_rect);
gboolean rsvg_drawing_ctx_get_ink_rect (RsvgDrawingCtx *ctx, cairo_rectangle_t *ink_rect);
/* Implemented in rust/src/node.rs */
G_GNUC_INTERNAL
......
......@@ -1006,19 +1006,24 @@ pub extern "C" fn rsvg_drawing_ctx_add_node_and_ancestors_to_stack(
pub extern "C" fn rsvg_drawing_ctx_get_ink_rect(
raw_draw_ctx: *const RsvgDrawingCtx,
ink_rect: *mut cairo_sys::cairo_rectangle_t,
) {
) -> glib_sys::gboolean {
assert!(!raw_draw_ctx.is_null());
let draw_ctx = unsafe { &mut *(raw_draw_ctx as *mut DrawingCtx) };
assert!(!ink_rect.is_null());
let r = draw_ctx.get_bbox().ink_rect.unwrap();
unsafe {
(*ink_rect).x = r.x;
(*ink_rect).y = r.y;
(*ink_rect).width = r.width;
(*ink_rect).height = r.height;
}
let res = match draw_ctx.get_bbox().ink_rect {
Some(r) => unsafe {
(*ink_rect).x = r.x;
(*ink_rect).y = r.y;
(*ink_rect).width = r.width;
(*ink_rect).height = r.height;
true
},
_ => false,
};
res.to_glib()
}
pub struct AcquiredNode(*const RefCell<Vec<RsvgNode>>, RsvgNode);
......
<svg xmlns="http://www.w3.org/2000/svg">
</svg>
......@@ -18,16 +18,27 @@ test_render_crash (gconstpointer data)
g_assert_no_error (error);
g_assert (handle != NULL);
rsvg_handle_get_dimensions (handle, &dimensions);
g_assert (dimensions.width > 0);
g_assert (dimensions.height > 0);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
dimensions.width, dimensions.height);
cr = cairo_create (surface);
g_assert (rsvg_handle_render_cairo (handle, cr));
cairo_surface_destroy (surface);
cairo_destroy (cr);
/* rsvg_handle_get_dimensions_sub has a return value we can check */
if (rsvg_handle_get_dimensions_sub (handle, &dimensions, NULL)) {
RsvgDimensionData dimensions2;
g_assert_cmpint (dimensions.width, >, 0);
g_assert_cmpint (dimensions.height, >, 0);
rsvg_handle_get_dimensions (handle, &dimensions2);
g_assert_cmpint (dimensions2.width, ==, dimensions.width);
g_assert_cmpint (dimensions2.height, ==, dimensions.height);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, dimensions.width, dimensions.height);
cr = cairo_create (surface);
g_assert (rsvg_handle_render_cairo (handle, cr));
cairo_surface_destroy (surface);
cairo_destroy (cr);
} else {
g_assert_cmpint (dimensions.width, ==, 0);
g_assert_cmpint (dimensions.height, ==, 0);
}
g_object_unref (handle);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment