From 50b3f02fe752cc0fb18ece94ee1ee3fa89b68d1c Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 7 Oct 2011 21:34:16 +1030 Subject: [PATCH 3/3] ps: fix uncolored tiling patterns Uncolored patterns and type 3 chars must not use color setting operators. Add the flag pdfSetColor to the prolog for specifying when the color operators may be used. Modify all the color setting functions in the prolog to check this flag. Use this flag to disable color setting when outputing uncolored patterns or type 3 chars. Bug 41462 --- poppler/PSOutputDev.cc | 100 +++++++++++++++++++++++++++-------------------- 1 files changed, 57 insertions(+), 43 deletions(-) diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc index 09889f8..a592e4b 100644 --- a/poppler/PSOutputDev.cc +++ b/poppler/PSOutputDev.cc @@ -125,7 +125,7 @@ static char *prolog[] = { "} def", "~1sn", "/pdfOpNames [", - " /pdfFill /pdfStroke /pdfLastFill /pdfLastStroke", + " /pdfFill /pdfStroke /pdfLastFill /pdfLastStroke /pdfSetColor", " /pdfTextMat /pdfFontSize /pdfCharSpacing /pdfTextRender /pdfPatternCS", " /pdfTextRise /pdfWordSpacing /pdfHorizScaling /pdfTextClipPath", "] def", @@ -154,6 +154,7 @@ static char *prolog[] = { "~123sn", " /pdfLastFill false def", " /pdfLastStroke false def", + " /pdfSetColor true def", " /pdfTextMat [1 0 0 1 0 0] def", " /pdfFontSize 0 def", " /pdfCharSpacing 0 def", @@ -210,87 +211,87 @@ static char *prolog[] = { "~123sn", "% PDF color state", "~1n", - "/g { dup /pdfFill exch def setgray", - " /pdfLastFill true def /pdfLastStroke false def } def", - "/G { dup /pdfStroke exch def setgray", - " /pdfLastStroke true def /pdfLastFill false def } def", + "/g { pdfSetColor { dup /pdfFill exch def setgray", + " /pdfLastFill true def /pdfLastStroke false def } if } def", + "/G { pdfSetColor { dup /pdfStroke exch def setgray", + " /pdfLastStroke true def /pdfLastFill false def } if } def", "/fCol {", - " pdfLastFill not {", + " pdfSetColor { pdfLastFill not {", " pdfFill setgray", " /pdfLastFill true def /pdfLastStroke false def", - " } if", + " } if } if", "} def", "/sCol {", - " pdfLastStroke not {", + " pdfSetColor { pdfLastStroke not {", " pdfStroke setgray", " /pdfLastStroke true def /pdfLastFill false def", - " } if", + " } if } if", "} def", "~1s", - "/k { 4 copy 4 array astore /pdfFill exch def setcmykcolor", - " /pdfLastFill true def /pdfLastStroke false def } def", - "/K { 4 copy 4 array astore /pdfStroke exch def setcmykcolor", - " /pdfLastStroke true def /pdfLastFill false def } def", + "/k { pdfSetColor { 4 copy 4 array astore /pdfFill exch def setcmykcolor", + " /pdfLastFill true def /pdfLastStroke false def } if } def", + "/K { pdfSetColor { 4 copy 4 array astore /pdfStroke exch def setcmykcolor", + " /pdfLastStroke true def /pdfLastFill false def } if } def", "/fCol {", - " pdfLastFill not {", + " pdfSetColor { pdfLastFill not {", " pdfFill aload pop setcmykcolor", " /pdfLastFill true def /pdfLastStroke false def", - " } if", + " } if } if", "} def", "/sCol {", - " pdfLastStroke not {", + " pdfSetColor { pdfLastStroke not {", " pdfStroke aload pop setcmykcolor", " /pdfLastStroke true def /pdfLastFill false def", - " } if", + " } if } if", "} def", "~23n", - "/cs { /pdfFillXform exch def dup /pdfFillCS exch def", - " setcolorspace } def", - "/CS { /pdfStrokeXform exch def dup /pdfStrokeCS exch def", - " setcolorspace } def", - "/sc { pdfLastFill not { pdfFillCS setcolorspace } if", + "/cs { pdfSetColor { /pdfFillXform exch def dup /pdfFillCS exch def", + " setcolorspace } if } def", + "/CS { pdfSetColor { /pdfStrokeXform exch def dup /pdfStrokeCS exch def", + " setcolorspace } if } def", + "/sc { pdfSetColor { pdfLastFill not { pdfFillCS setcolorspace } if", " dup /pdfFill exch def aload pop pdfFillXform setcolor", - " /pdfLastFill true def /pdfLastStroke false def } def", - "/SC { pdfLastStroke not { pdfStrokeCS setcolorspace } if", + " /pdfLastFill true def /pdfLastStroke false def } if } def", + "/SC { pdfSetColor { pdfLastStroke not { pdfStrokeCS setcolorspace } if", " dup /pdfStroke exch def aload pop pdfStrokeXform setcolor", - " /pdfLastStroke true def /pdfLastFill false def } def", + " /pdfLastStroke true def /pdfLastFill false def } if } def", "/op { /pdfFillOP exch def", " pdfLastFill { pdfFillOP setoverprint } if } def", "/OP { /pdfStrokeOP exch def", " pdfLastStroke { pdfStrokeOP setoverprint } if } def", "/fCol {", - " pdfLastFill not {", + " pdfSetColor { pdfLastFill not {", " pdfFillCS setcolorspace", " pdfFill aload pop pdfFillXform setcolor", " pdfFillOP setoverprint", " /pdfLastFill true def /pdfLastStroke false def", - " } if", + " } if } if", "} def", "/sCol {", - " pdfLastStroke not {", + " pdfSetColor { pdfLastStroke not {", " pdfStrokeCS setcolorspace", " pdfStroke aload pop pdfStrokeXform setcolor", " pdfStrokeOP setoverprint", " /pdfLastStroke true def /pdfLastFill false def", - " } if", + " } if } if", "} def", "~23s", - "/k { 4 copy 4 array astore /pdfFill exch def setcmykcolor", - " /pdfLastFill true def /pdfLastStroke false def } def", - "/K { 4 copy 4 array astore /pdfStroke exch def setcmykcolor", - " /pdfLastStroke true def /pdfLastFill false def } def", - "/ck { 6 copy 6 array astore /pdfFill exch def", + "/k { pdfSetColor { 4 copy 4 array astore /pdfFill exch def setcmykcolor", + " /pdfLastFill true def /pdfLastStroke false def } if } def", + "/K { pdfSetColor { 4 copy 4 array astore /pdfStroke exch def setcmykcolor", + " /pdfLastStroke true def /pdfLastFill false def } if } def", + "/ck { pdfSetColor { 6 copy 6 array astore /pdfFill exch def", " findcmykcustomcolor exch setcustomcolor", - " /pdfLastFill true def /pdfLastStroke false def } def", - "/CK { 6 copy 6 array astore /pdfStroke exch def", + " /pdfLastFill true def /pdfLastStroke false def } if } def", + "/CK { pdfSetColor { 6 copy 6 array astore /pdfStroke exch def", " findcmykcustomcolor exch setcustomcolor", - " /pdfLastStroke true def /pdfLastFill false def } def", + " /pdfLastStroke true def /pdfLastFill false def } if } def", "/op { /pdfFillOP exch def", " pdfLastFill { pdfFillOP setoverprint } if } def", "/OP { /pdfStrokeOP exch def", " pdfLastStroke { pdfStrokeOP setoverprint } if } def", "/fCol {", - " pdfLastFill not {", + " pdfSetColor { pdfLastFill not {", " pdfFill aload length 4 eq {", " setcmykcolor", " }{", @@ -298,10 +299,10 @@ static char *prolog[] = { " } ifelse", " pdfFillOP setoverprint", " /pdfLastFill true def /pdfLastStroke false def", - " } if", + " } if } if", "} def", "/sCol {", - " pdfLastStroke not {", + " pdfSetColor { pdfLastStroke not {", " pdfStroke aload length 4 eq {", " setcmykcolor", " }{", @@ -309,7 +310,7 @@ static char *prolog[] = { " } ifelse", " pdfStrokeOP setoverprint", " /pdfLastStroke true def /pdfLastFill false def", - " } if", + " } if } if", "} def", "~123sn", "% build a font", @@ -4043,8 +4044,8 @@ GBool PSOutputDev::tilingPatternFillL1(GfxState *state, Catalog *cat, Object *st if (paintType == 2) { writePSFmt("{0:.6g} 0 {1:.6g} {2:.6g} {3:.6g} {4:.6g} setcachedevice\n", xStep, bbox[0], bbox[1], bbox[2], bbox[3]); - } else - { + writePS("/pdfSetColor false def\n"); + } else { if (x1 - 1 <= x0) { writePS("1 0 setcharwidth\n"); } else { @@ -4056,6 +4057,9 @@ GBool PSOutputDev::tilingPatternFillL1(GfxState *state, Catalog *cat, Object *st gfx->display(str); --numTilingPatterns; inType3Char = gFalse; + if (paintType == 2) { + writePS("/pdfSetColor true def\n"); + } writePS("} def\n"); delete gfx; writePS("end\n"); @@ -4081,6 +4085,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 +4102,13 @@ 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) { + writePS("/pdfSetColor false def\n"); + } gfx->display(str); + if (paintType == 2) { + writePS("/pdfSetColor true def\n"); + } inType3Char = gFalse; delete gfx; writePS(" }\n"); -- 1.7.4.1