3587f3
From 718d428984e3a84fda521c0f5e6d975c7390af2b Mon Sep 17 00:00:00 2001
3587f3
From: Marek Kasik <mkasik@redhat.com>
3587f3
Date: Fri, 6 Apr 2018 15:06:46 +0200
3587f3
Subject: [PATCH] cairo: Fix tiling patterns when pattern cell is too far
3587f3
3587f3
Rendering of tiling pattern which has pattern matrix moving pattern cell
3587f3
far away can fail on allocation of memory. This commit solves the issue by
3587f3
modifying of cairo pattern matrix so that its offset is closer to the path
3587f3
filled by the pattern.
3587f3
3587f3
https://bugs.freedesktop.org/show_bug.cgi?id=105905
3587f3
---
3587f3
 poppler/CairoOutputDev.cc | 11 +++++++++++
3587f3
 1 file changed, 11 insertions(+)
3587f3
3587f3
diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc
3587f3
index 631ab27b..b2e730bf 100644
3587f3
--- a/poppler/CairoOutputDev.cc
3587f3
+++ b/poppler/CairoOutputDev.cc
3587f3
@@ -915,6 +915,8 @@ GBool CairoOutputDev::tilingPatternFill(GfxState *state, Gfx *gfxA, Catalog *cat
3587f3
   StrokePathClip *strokePathTmp;
3587f3
   GBool adjusted_stroke_width_tmp;
3587f3
   cairo_pattern_t *maskTmp;
3587f3
+  double xoffset, yoffset;
3587f3
+  double det;
3587f3
 
3587f3
   width = bbox[2] - bbox[0];
3587f3
   height = bbox[3] - bbox[1];
3587f3
@@ -976,6 +978,15 @@ GBool CairoOutputDev::tilingPatternFill(GfxState *state, Gfx *gfxA, Catalog *cat
3587f3
   if (cairo_pattern_status (pattern))
3587f3
     return gFalse;
3587f3
 
3587f3
+  det = pmat[0] * pmat[3] - pmat[1] * pmat[2];
3587f3
+  if (fabs(det) < 0.000001)
3587f3
+    return gFalse;
3587f3
+
3587f3
+  xoffset = round ((pmat[3] * pmat[4] - pmat[2] * pmat[5]) / (xStep * det));
3587f3
+  yoffset = - round ((pmat[1] * pmat[4] - pmat[0] * pmat[5]) / (yStep * det));
3587f3
+  pattern_matrix.x0 -= xoffset * pattern_matrix.xx * xStep + yoffset * pattern_matrix.xy * yStep;
3587f3
+  pattern_matrix.y0 -= xoffset * pattern_matrix.yx * xStep + yoffset * pattern_matrix.yy * yStep;
3587f3
+
3587f3
   state->getUserClipBBox(&xMin, &yMin, &xMax, &yMax);
3587f3
   cairo_rectangle (cairo, xMin, yMin, xMax - xMin, yMax - yMin);
3587f3
 
3587f3
-- 
3587f3
2.14.3
3587f3