diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp
index c2fedff50fc901d6f14b9830b1010e3632c29664..c3d35de7230c579bc29b6a5161764f58551f4ff6 100644 (file)
--- a/src/sp-pattern.cpp
+++ b/src/sp-pattern.cpp
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include <cstring>
+#include <string>
#include <libnr/nr-matrix-ops.h>
#include "libnr/nr-matrix-fns.h"
#include <libnr/nr-translate-matrix-ops.h>
Gets called when the referenced <pattern> is changed
*/
static void
-pattern_ref_modified (SPObject *ref, guint flags, SPPattern *pattern)
+pattern_ref_modified (SPObject */*ref*/, guint /*flags*/, SPPattern *pattern)
{
if (SP_IS_OBJECT (pattern))
SP_OBJECT (pattern)->requestModified(SP_OBJECT_MODIFIED_FLAG);
// Access functions that look up fields up the chain of referenced patterns and return the first one which is set
+// FIXME: all of them must use chase_hrefs the same as in SPGradient, to avoid lockup on circular refs
guint pattern_patternUnits (SPPattern *pat)
{
See (*) below for why the parent_transform may be necessary.
*/
static SPPainter *
-sp_pattern_painter_new (SPPaintServer *ps, NR::Matrix const &full_transform, NR::Matrix const &parent_transform, const NRRect *bbox)
+sp_pattern_painter_new (SPPaintServer *ps, NR::Matrix const &full_transform, NR::Matrix const &/*parent_transform*/, const NRRect *bbox)
{
SPPattern *pat = SP_PATTERN (ps);
SPPatPainter *pp = g_new (SPPatPainter, 1);
@@ -793,7 +798,7 @@ sp_pattern_painter_new (SPPaintServer *ps, NR::Matrix const &full_transform, NR:
}
static void
-sp_pattern_painter_free (SPPaintServer *ps, SPPainter *painter)
+sp_pattern_painter_free (SPPaintServer */*ps*/, SPPainter *painter)
{
SPPatPainter *pp = (SPPatPainter *) painter;
SPPattern *pat = pp->pat;
ba.y0 = pb->area.y0;
ba.x1 = pb->area.x1;
ba.y1 = pb->area.y1;
- nr_rect_d_matrix_transform (&psa, &ba, &pp->px2ps);
- psa.x0 = floor ((psa.x0 - pattern_x (pp->pat)) / pattern_width (pp->pat)) -1;
- psa.y0 = floor ((psa.y0 - pattern_y (pp->pat)) / pattern_height (pp->pat)) -1;
- psa.x1 = ceil ((psa.x1 - pattern_x (pp->pat)) / pattern_width (pp->pat)) +1;
- psa.y1 = ceil ((psa.y1 - pattern_y (pp->pat)) / pattern_height (pp->pat)) +1;
-
- for (y = psa.y0; y < psa.y1; y++) {
- for (x = psa.x0; x < psa.x1; x++) {
- NRPixBlock ppb;
- double psx, psy;
-
- psx = x * pattern_width (pp->pat);
- psy = y * pattern_height (pp->pat);
-
- area.x0 = (gint32)(pb->area.x0 - (pp->ps2px.c[0] * psx + pp->ps2px.c[2] * psy));
- area.y0 = (gint32)(pb->area.y0 - (pp->ps2px.c[1] * psx + pp->ps2px.c[3] * psy));
- area.x1 = area.x0 + pb->area.x1 - pb->area.x0;
- area.y1 = area.y0 + pb->area.y1 - pb->area.y0;
-
- // We do not update here anymore
-
- // Set up buffer
- // fixme: (Lauris)
- nr_pixblock_setup_extern (&ppb, pb->mode, area.x0, area.y0, area.x1, area.y1, NR_PIXBLOCK_PX (pb), pb->rs, FALSE, FALSE);
-
- nr_arena_item_invoke_render (NULL, pp->root, &area, &ppb, 0);
-
- nr_pixblock_release (&ppb);
- }
- }
+ // Trying to solve this bug: https://bugs.launchpad.net/inkscape/+bug/167416
+ // Bail out if the transformation matrix has extreme values. If we bail out
+ // however, then something (which was meaningless anyway) won't be rendered,
+ // which is better than getting stuck in a virtually infinite loop
+ if (fabs(pp->px2ps.c[0]) < 1e6 &&
+ fabs(pp->px2ps.c[3]) < 1e6 &&
+ fabs(pp->px2ps.c[4]) < 1e6 &&
+ fabs(pp->px2ps.c[5]) < 1e6)
+ {
+ nr_rect_d_matrix_transform (&psa, &ba, &pp->px2ps);
+
+ psa.x0 = floor ((psa.x0 - pattern_x (pp->pat)) / pattern_width (pp->pat)) -1;
+ psa.y0 = floor ((psa.y0 - pattern_y (pp->pat)) / pattern_height (pp->pat)) -1;
+ psa.x1 = ceil ((psa.x1 - pattern_x (pp->pat)) / pattern_width (pp->pat)) +1;
+ psa.y1 = ceil ((psa.y1 - pattern_y (pp->pat)) / pattern_height (pp->pat)) +1;
+
+ // If psa is too wide or tall, then something must be wrong! This is due to
+ // nr_rect_d_matrix_transform (&psa, &ba, &pp->px2ps) using a weird transformation matrix pp->px2ps.
+ g_assert(std::abs(psa.x1 - psa.x0) < 1e6);
+ g_assert(std::abs(psa.y1 - psa.y0) < 1e6);
+
+ for (y = psa.y0; y < psa.y1; y++) {
+ for (x = psa.x0; x < psa.x1; x++) {
+ NRPixBlock ppb;
+ double psx, psy;
+
+ psx = x * pattern_width (pp->pat);
+ psy = y * pattern_height (pp->pat);
+
+ area.x0 = (gint32)(pb->area.x0 - (pp->ps2px.c[0] * psx + pp->ps2px.c[2] * psy));
+ area.y0 = (gint32)(pb->area.y0 - (pp->ps2px.c[1] * psx + pp->ps2px.c[3] * psy));
+ area.x1 = area.x0 + pb->area.x1 - pb->area.x0;
+ area.y1 = area.y0 + pb->area.y1 - pb->area.y0;
+
+ // We do not update here anymore
+
+ // Set up buffer
+ // fixme: (Lauris)
+ nr_pixblock_setup_extern (&ppb, pb->mode, area.x0, area.y0, area.x1, area.y1, NR_PIXBLOCK_PX (pb), pb->rs, FALSE, FALSE);
+
+ nr_arena_item_invoke_render (NULL, pp->root, &area, &ppb, 0);
+
+ nr_pixblock_release (&ppb);
+ }
+ }
+ }
}
}