[lasem] svg_view: avoid cairo errors when gradient matrix is not invertible.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [lasem] svg_view: avoid cairo errors when gradient matrix is not invertible.
- Date: Tue, 12 Jun 2012 18:04:14 +0000 (UTC)
commit 2af1dcb18d3bc06867ad2a6bfdfcd6378711e214
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Tue Jun 12 20:03:28 2012 +0200
svg_view: avoid cairo errors when gradient matrix is not invertible.
src/lsmsvggradientelement.c | 16 ++++++++--------
src/lsmsvgview.c | 20 ++++++++++++++++----
src/lsmsvgview.h | 6 ++++--
3 files changed, 28 insertions(+), 14 deletions(-)
---
diff --git a/src/lsmsvggradientelement.c b/src/lsmsvggradientelement.c
index 4820567..3671e05 100644
--- a/src/lsmsvggradientelement.c
+++ b/src/lsmsvggradientelement.c
@@ -72,14 +72,14 @@ lsm_svg_gradient_element_render (LsmSvgElement *self, LsmSvgView *view)
gradient->transform.matrix.e,
gradient->transform.matrix.f);
- lsm_svg_view_set_gradient_properties (view,
- gradient->spread_method.value,
- gradient->units.value,
- &gradient->transform.matrix);
-
- for (node = LSM_DOM_NODE (referenced_gradient)->first_child; node != NULL; node = node->next_sibling)
- if (LSM_IS_SVG_ELEMENT (node))
- lsm_svg_element_render (LSM_SVG_ELEMENT (node), view);
+ if (lsm_svg_view_set_gradient_properties (view,
+ gradient->spread_method.value,
+ gradient->units.value,
+ &gradient->transform.matrix)) {
+ for (node = LSM_DOM_NODE (referenced_gradient)->first_child; node != NULL; node = node->next_sibling)
+ if (LSM_IS_SVG_ELEMENT (node))
+ lsm_svg_element_render (LSM_SVG_ELEMENT (node), view);
+ }
}
static void
diff --git a/src/lsmsvgview.c b/src/lsmsvgview.c
index 2029f55..1ed54fd 100644
--- a/src/lsmsvgview.c
+++ b/src/lsmsvgview.c
@@ -194,17 +194,19 @@ lsm_svg_view_add_gradient_color_stop (LsmSvgView *view, double offset)
style->stop_opacity->value * view->pattern_data->opacity);
}
-void
+gboolean
lsm_svg_view_set_gradient_properties (LsmSvgView *view,
LsmSvgSpreadMethod method,
LsmSvgPatternUnits units,
const LsmSvgMatrix *gradient_matrix)
{
cairo_matrix_t matrix;
+ cairo_matrix_t inv_matrix;
+ cairo_status_t status;
- g_return_if_fail (LSM_IS_SVG_VIEW (view));
- g_return_if_fail (view->pattern_data != NULL);
- g_return_if_fail (view->pattern_data->pattern != NULL);
+ g_return_val_if_fail (LSM_IS_SVG_VIEW (view), FALSE);
+ g_return_val_if_fail (view->pattern_data != NULL, FALSE);
+ g_return_val_if_fail (view->pattern_data->pattern != NULL, FALSE);
switch (method) {
case LSM_SVG_SPREAD_METHOD_REFLECT:
@@ -238,7 +240,17 @@ lsm_svg_view_set_gradient_properties (LsmSvgView *view,
}
+ inv_matrix = matrix;
+ status = cairo_matrix_invert (&inv_matrix);
+
+ if (status != CAIRO_STATUS_SUCCESS) {
+ lsm_debug_render ("SvgView::set_gradient_properties] Not invertible matrix");
+ return FALSE;
+ }
+
cairo_pattern_set_matrix (view->pattern_data->pattern, &matrix);
+
+ return TRUE;
}
gboolean
diff --git a/src/lsmsvgview.h b/src/lsmsvgview.h
index 0bb7140..58187b0 100644
--- a/src/lsmsvgview.h
+++ b/src/lsmsvgview.h
@@ -99,12 +99,14 @@ void lsm_svg_view_create_radial_gradient (LsmSvgView *view, double cx, double
void lsm_svg_view_create_linear_gradient (LsmSvgView *view, double x1, double y1,
double x2, double y2);
void lsm_svg_view_add_gradient_color_stop (LsmSvgView *view, double offset);
-void lsm_svg_view_set_gradient_properties (LsmSvgView *view,
+G_GNUC_WARN_UNUSED_RESULT gboolean
+ lsm_svg_view_set_gradient_properties (LsmSvgView *view,
LsmSvgSpreadMethod method,
LsmSvgPatternUnits units,
const LsmSvgMatrix *matrix);
-gboolean lsm_svg_view_create_surface_pattern (LsmSvgView *view, const LsmBox *viewport,
+G_GNUC_WARN_UNUSED_RESULT gboolean
+ lsm_svg_view_create_surface_pattern (LsmSvgView *view, const LsmBox *viewport,
const LsmSvgMatrix *matrix,
LsmSvgViewSurfaceType surface_type) G_GNUC_WARN_UNUSED_RESULT;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]