Commit 0b728c8f authored by Paolo Borelli's avatar Paolo Borelli

drawing_ctx: do not pass in the handle

It is a bit more verbose, but reduces coupling.
rsvg_drawing_ctx_new now cannot fail.
parent 7ee0bb1f
......@@ -47,18 +47,21 @@ void rsvg_drawing_ctx_transformed_image_bounding_box (cairo_matrix_t *affine,
double *bbx, double *bby, double *bbw, double *bbh);
RsvgDrawingCtx *
rsvg_drawing_ctx_new (cairo_t *cr, RsvgHandle *handle)
rsvg_drawing_ctx_new (cairo_t *cr,
guint width,
guint height,
double vb_width,
double vb_height,
double dpi_x,
double dpi_y,
RsvgDefs *defs,
gboolean testing)
{
RsvgDimensionData data;
RsvgDrawingCtx *draw;
cairo_matrix_t affine;
cairo_matrix_t scale;
double bbx, bby, bbw, bbh;
rsvg_handle_get_dimensions (handle, &data);
if (data.width == 0 || data.height == 0)
return NULL;
draw = g_new0 (RsvgDrawingCtx, 1);
cairo_get_matrix (cr, &affine);
......@@ -66,8 +69,7 @@ rsvg_drawing_ctx_new (cairo_t *cr, RsvgHandle *handle)
/* find bounding box of image as transformed by the current cairo context
* The size of this bounding box determines the size of the intermediate
* surfaces allocated during drawing. */
rsvg_drawing_ctx_transformed_image_bounding_box (&affine,
data.width, data.height,
rsvg_drawing_ctx_transformed_image_bounding_box (&affine, width, height,
&bbx, &bby, &bbw, &bbh);
draw->initial_cr = cr;
......@@ -80,18 +82,18 @@ rsvg_drawing_ctx_new (cairo_t *cr, RsvgHandle *handle)
draw->rect.width = bbw;
draw->rect.height = bbh;
draw->defs = handle->priv->defs;
draw->dpi_x = handle->priv->dpi_x;
draw->dpi_y = handle->priv->dpi_y;
draw->vb.rect.width = data.em;
draw->vb.rect.height = data.ex;
draw->defs = defs;
draw->dpi_x = dpi_x;
draw->dpi_y = dpi_y;
draw->vb.rect.width = vb_width;
draw->vb.rect.height = vb_height;
draw->vb_stack = NULL;
draw->drawsub_stack = NULL;
draw->acquired_nodes = NULL;
draw->is_testing = handle->priv->is_testing;
draw->is_testing = testing;
/* scale according to size set by size_func callback */
cairo_matrix_init_scale (&scale, data.width / data.em, data.height / data.ex);
cairo_matrix_init_scale (&scale, width / vb_width, height / vb_height);
cairo_matrix_multiply (&affine, &affine, &scale);
/* adjust transform so that the corner of the bounding box above is
......
......@@ -52,7 +52,15 @@ struct RsvgDrawingCtx {
};
G_GNUC_INTERNAL
RsvgDrawingCtx *rsvg_drawing_ctx_new (cairo_t *cr, RsvgHandle *handle);
RsvgDrawingCtx *rsvg_drawing_ctx_new (cairo_t *cr,
guint width,
guint height,
double vb_width,
double vb_height,
double dpi_x,
double dpi_y,
RsvgDefs *defs,
gboolean testing);
G_GNUC_INTERNAL
void rsvg_drawing_ctx_free (RsvgDrawingCtx *draw_ctx);
......
......@@ -788,6 +788,7 @@ rsvg_handle_cascade (RsvgHandle *handle)
gboolean
rsvg_handle_render_cairo_sub (RsvgHandle * handle, cairo_t * cr, const char *id)
{
RsvgDimensionData dimensions;
RsvgDrawingCtx *draw;
RsvgNode *drawsub = NULL;
cairo_status_t status;
......@@ -815,10 +816,17 @@ rsvg_handle_render_cairo_sub (RsvgHandle * handle, cairo_t * cr, const char *id)
return FALSE;
}
draw = rsvg_drawing_ctx_new (cr, handle);
if (!draw)
rsvg_handle_get_dimensions (handle, &dimensions);
if (dimensions.width == 0 || dimensions.height == 0)
return FALSE;
draw = rsvg_drawing_ctx_new (cr,
dimensions.width, dimensions.height,
dimensions.em, dimensions.ex,
handle->priv->dpi_x, handle->priv->dpi_y,
handle->priv->defs,
handle->priv->is_testing);
rsvg_drawing_ctx_add_node_and_ancestors_to_stack (draw, drawsub);
cairo_save (cr);
......@@ -932,21 +940,24 @@ rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimensi
}
if (handle_subelement == TRUE) {
RsvgDimensionData dimensions;
RsvgBbox *bbox;
cairo_rectangle_t ink_rect;
rsvg_handle_get_dimensions (handle, &dimensions);
if (dimensions.width == 0 || dimensions.height == 0)
return FALSE;
target = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
1, 1);
cr = cairo_create (target);
draw = rsvg_drawing_ctx_new (cr, handle);
if (!draw) {
cairo_destroy (cr);
cairo_surface_destroy (target);
return FALSE;
}
draw = rsvg_drawing_ctx_new (cr,
dimensions.width, dimensions.height,
dimensions.em, dimensions.ex,
handle->priv->dpi_x, handle->priv->dpi_y,
handle->priv->defs,
handle->priv->is_testing);
g_assert (sself != NULL);
rsvg_drawing_ctx_add_node_and_ancestors_to_stack (draw, sself);
......@@ -996,12 +1007,12 @@ rsvg_handle_get_position_sub (RsvgHandle * handle, RsvgPositionData * position_d
{
RsvgDrawingCtx *draw;
RsvgNode *node;
RsvgDimensionData dimensions;
RsvgBbox *bbox;
cairo_rectangle_t ink_rect;
cairo_surface_t *target = NULL;
cairo_t *cr = NULL;
int width, height;
gboolean ret = FALSE;
g_return_val_if_fail (handle, FALSE);
g_return_val_if_fail (position_data, FALSE);
......@@ -1029,11 +1040,19 @@ rsvg_handle_get_position_sub (RsvgHandle * handle, RsvgPositionData * position_d
return TRUE;
}
rsvg_handle_get_dimensions (handle, &dimensions);
if (dimensions.width == 0 || dimensions.height == 0)
return FALSE;
target = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 1, 1);
cr = cairo_create (target);
draw = rsvg_drawing_ctx_new (cr, handle);
if (!draw)
goto bail;
draw = rsvg_drawing_ctx_new (cr,
dimensions.width, dimensions.height,
dimensions.em, dimensions.ex,
handle->priv->dpi_x, handle->priv->dpi_y,
handle->priv->defs,
handle->priv->is_testing);
g_assert (node != NULL);
rsvg_drawing_ctx_add_node_and_ancestors_to_stack (draw, node);
......@@ -1053,15 +1072,10 @@ rsvg_handle_get_position_sub (RsvgHandle * handle, RsvgPositionData * position_d
if (handle->priv->size_func)
(*handle->priv->size_func) (&width, &height, handle->priv->user_data);
ret = TRUE;
bail:
if (cr)
cairo_destroy (cr);
if (target)
cairo_surface_destroy (target);
cairo_destroy (cr);
cairo_surface_destroy (target);
return ret;
return TRUE;
}
/**
......
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