From 5fb973966338d9afd34bee109c0c827c370a5a97 Mon Sep 17 00:00:00 2001 From: Jason Crain Date: Thu, 15 May 2014 02:22:44 -0500 Subject: [PATCH] cairo: Use matrix to determine pattern size bug #33364 --- poppler/CairoOutputDev.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc index f31b46b..6323040 100644 --- a/poppler/CairoOutputDev.cc +++ b/poppler/CairoOutputDev.cc @@ -837,6 +837,7 @@ GBool CairoOutputDev::tilingPatternFill(GfxState *state, Gfx *gfxA, Catalog *cat cairo_pattern_t *pattern; cairo_surface_t *surface; cairo_matrix_t matrix; + cairo_matrix_t pattern_matrix; cairo_t *old_cairo; double xMin, yMin, xMax, yMax; double width, height; @@ -850,8 +851,18 @@ GBool CairoOutputDev::tilingPatternFill(GfxState *state, Gfx *gfxA, Catalog *cat return gFalse; /* TODO: implement the other cases here too */ - surface_width = (int) ceil (width); - surface_height = (int) ceil (height); + // Find the width and height of the transformed pattern + cairo_get_matrix (cairo, &matrix); + cairo_matrix_init (&pattern_matrix, mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]); + cairo_matrix_multiply (&matrix, &matrix, &pattern_matrix); + + double widthX = width, widthY = 0; + cairo_matrix_transform_distance (&matrix, &widthX, &widthY); + surface_width = ceil (sqrt (widthX * widthX + widthY * widthY)); + + double heightX = 0, heightY = height; + cairo_matrix_transform_distance (&matrix, &heightX, &heightY); + surface_height = ceil (sqrt (heightX * heightX + heightY * heightY)); surface = cairo_surface_create_similar (cairo_get_target (cairo), CAIRO_CONTENT_COLOR_ALPHA, @@ -862,6 +873,7 @@ GBool CairoOutputDev::tilingPatternFill(GfxState *state, Gfx *gfxA, Catalog *cat old_cairo = cairo; cairo = cairo_create (surface); cairo_surface_destroy (surface); + cairo_scale (cairo, surface_width / width, surface_height / height); box.x1 = bbox[0]; box.y1 = bbox[1]; box.x2 = bbox[2]; box.y2 = bbox[3]; @@ -888,8 +900,7 @@ GBool CairoOutputDev::tilingPatternFill(GfxState *state, Gfx *gfxA, Catalog *cat cairo_matrix_init_scale (&matrix, surface_width / width, surface_height / height); cairo_pattern_set_matrix (pattern, &matrix); - cairo_matrix_init (&matrix, mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]); - cairo_transform (cairo, &matrix); + cairo_transform (cairo, &pattern_matrix); cairo_set_source (cairo, pattern); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); if (strokePathClip) { -- 2.0.0.rc2