From d473d34d4328c542b1a1572f6695056ec1770d18 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 14 Nov 2012 22:44:20 +1030 Subject: [PATCH] cairo: Fix crash in CairoImageOutputDev with setSoftMaskFromImageMask BUg 57067 --- poppler/CairoOutputDev.cc | 46 +++++++++++++++++++++++++++++++++++++++++++++ poppler/CairoOutputDev.h | 5 +++++ 2 files changed, 51 insertions(+) diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc index 2cd67c9..f4c4ada 100644 --- a/poppler/CairoOutputDev.cc +++ b/poppler/CairoOutputDev.cc @@ -2993,6 +2993,52 @@ void CairoImageOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *st } } +void CairoImageOutputDev::setSoftMaskFromImageMask(GfxState *state, Object *ref, Stream *str, + int width, int height, GBool invert, + GBool inlineImg, double *baseMatrix) +{ + cairo_t *cr; + cairo_surface_t *surface; + double x1, y1, x2, y2; + double *ctm; + double mat[6]; + CairoImage *image; + + ctm = state->getCTM(); + + mat[0] = ctm[0]; + mat[1] = ctm[1]; + mat[2] = -ctm[2]; + mat[3] = -ctm[3]; + mat[4] = ctm[2] + ctm[4]; + mat[5] = ctm[3] + ctm[5]; + x1 = mat[4]; + y1 = mat[5]; + x2 = x1 + width; + y2 = y1 + height; + + image = new CairoImage (x1, y1, x2, y2); + saveImage (image); + + if (imgDrawCbk && imgDrawCbk (numImages - 1, imgDrawCbkData)) { + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); + cr = cairo_create (surface); + setCairo (cr); + cairo_translate (cr, 0, height); + cairo_scale (cr, width, -height); + + CairoOutputDev::drawImageMask(state, ref, str, width, height, invert, inlineImg, gFalse); + if (state->getFillColorSpace()->getMode() == csPattern) { + cairo_mask (cairo, mask); + } + image->setImage (surface); + + setCairo (NULL); + cairo_surface_destroy (surface); + cairo_destroy (cr); + } +} + void CairoImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, GBool interpolate, int *maskColors, GBool inlineImg) diff --git a/poppler/CairoOutputDev.h b/poppler/CairoOutputDev.h index df76975..a699a7b 100644 --- a/poppler/CairoOutputDev.h +++ b/poppler/CairoOutputDev.h @@ -465,6 +465,11 @@ public: Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GBool maskInterpolate); + virtual void setSoftMaskFromImageMask(GfxState *state, Object *ref, Stream *str, + int width, int height, GBool invert, + GBool inlineImg, double *baseMatrix); + virtual void unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix) {} + //----- transparency groups and soft masks virtual void beginTransparencyGroup(GfxState * /*state*/, double * /*bbox*/, -- 1.7.10.4