From eb05394d2163b48af24fe4579dff2f4d5cad7845 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sat, 8 Oct 2011 15:03:24 +1030 Subject: [PATCH 3/3] ps: fix uncolored tiling patterns Uncolored patterns and type 3 chars must not use color setting operators. When emitting an uncolored pattern: - disable the update color space functions - disable the update color functions - set pdfLastFill and pdfLastStroke to true to ensure the the sCol and fCol procedures that is used by some of the PS procedures that emulate PDF operators do not update the color. Bug 41462 --- poppler/PSOutputDev.cc | 41 +++++++++++++++++++++++++++++++++++++++++ poppler/PSOutputDev.h | 1 + 2 files changed, 42 insertions(+), 0 deletions(-) diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc index 09889f8..71e3cb1 100644 --- a/poppler/PSOutputDev.cc +++ b/poppler/PSOutputDev.cc @@ -1149,6 +1149,7 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA, } processColors = 0; inType3Char = gFalse; + inUncoloredPattern = gFalse; #if OPI_SUPPORT // initialize OPI nesting levels @@ -3688,6 +3689,9 @@ void PSOutputDev::updateLineWidth(GfxState *state) { } void PSOutputDev::updateFillColorSpace(GfxState *state) { + if (inUncoloredPattern) { + return; + } switch (level) { case psLevel1: case psLevel1Sep: @@ -3706,6 +3710,9 @@ void PSOutputDev::updateFillColorSpace(GfxState *state) { } void PSOutputDev::updateStrokeColorSpace(GfxState *state) { + if (inUncoloredPattern) { + return; + } switch (level) { case psLevel1: case psLevel1Sep: @@ -3732,6 +3739,9 @@ void PSOutputDev::updateFillColor(GfxState *state) { double c, m, y, k; int i; + if (inUncoloredPattern) { + return; + } switch (level) { case psLevel1: state->getFillGray(&gray); @@ -3795,6 +3805,9 @@ void PSOutputDev::updateStrokeColor(GfxState *state) { double c, m, y, k; int i; + if (inUncoloredPattern) { + return; + } switch (level) { case psLevel1: state->getStrokeGray(&gray); @@ -4052,9 +4065,21 @@ GBool PSOutputDev::tilingPatternFillL1(GfxState *state, Catalog *cat, Object *st } } inType3Char = gTrue; + if (paintType == 2) { + inUncoloredPattern = gTrue; + // ensure any PS procedures that contain sCol or fCol do not change the color + writePS("/pdfLastFill true def\n"); + writePS("/pdfLastStroke true def\n"); + } ++numTilingPatterns; gfx->display(str); --numTilingPatterns; + if (paintType == 2) { + inUncoloredPattern = gFalse; + // ensure the next PS procedures that uses sCol or fCol will update the color + writePS("/pdfLastFill false def\n"); + writePS("/pdfLastStroke false def\n"); + } inType3Char = gFalse; writePS("} def\n"); delete gfx; @@ -4081,6 +4106,10 @@ GBool PSOutputDev::tilingPatternFillL2(GfxState *state, Catalog *cat, Object *st PDFRectangle box; Gfx *gfx; + if (paintType == 2) { + // setpattern with PaintType 2 needs the paint color + writePS("currentcolor\n"); + } writePS("<<\n /PatternType 1\n"); writePSFmt(" /PaintType {0:d}\n", paintType); writePSFmt(" /TilingType {0:d}\n", tilingType); @@ -4094,7 +4123,19 @@ GBool PSOutputDev::tilingPatternFillL2(GfxState *state, Catalog *cat, Object *st box.y2 = bbox[3]; gfx = new Gfx(xref, this, resDict, m_catalog, &box, NULL); inType3Char = gTrue; + if (paintType == 2) { + inUncoloredPattern = gTrue; + // ensure any PS procedures that contain sCol or fCol do not change the color + writePS("/pdfLastFill true def\n"); + writePS("/pdfLastStroke true def\n"); + } gfx->display(str); + if (paintType == 2) { + inUncoloredPattern = gFalse; + // ensure the next PS procedures that uses sCol or fCol will update the color + writePS("/pdfLastFill false def\n"); + writePS("/pdfLastStroke false def\n"); + } inType3Char = gFalse; delete gfx; writePS(" }\n"); diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h index a1e0a29..8112bc4 100644 --- a/poppler/PSOutputDev.h +++ b/poppler/PSOutputDev.h @@ -450,6 +450,7 @@ private: // clipping render mode because of pattern colorspace GBool inType3Char; // inside a Type 3 CharProc + GBool inUncoloredPattern; // inside a uncolored pattern (PaintType = 2) GooString *t3String; // Type 3 content string double t3WX, t3WY, // Type 3 character parameters t3LLX, t3LLY, t3URX, t3URY; -- 1.7.4.1