diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc index db06453..7bcef60 100644 --- a/poppler/Gfx.cc +++ b/poppler/Gfx.cc @@ -27,6 +27,7 @@ // Copyright (C) 2008 Pino Toscano // Copyright (C) 2008 Michael Vrable // Copyright (C) 2008 Hib Eris +// Copyright (C) 2009 Thomas Freitag // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -497,6 +498,9 @@ Gfx::Gfx(XRef *xrefA, OutputDev *outA, int pageNum, Dict *resDict, Catalog *cata subPage = gFalse; printCommands = globalParams->getPrintCommands(); profileCommands = globalParams->getProfileCommands(); + textHaveCSPattern = gFalse; + drawText = gFalse; + maskHaveCSPattern = gFalse; mcStack = NULL; // start the resource stack @@ -541,6 +545,9 @@ Gfx::Gfx(XRef *xrefA, OutputDev *outA, Dict *resDict, Catalog *catalogA, catalog = catalogA; subPage = gTrue; printCommands = globalParams->getPrintCommands(); + textHaveCSPattern = gFalse; + drawText = gFalse; + maskHaveCSPattern = gFalse; mcStack = NULL; // start the resource stack @@ -657,7 +664,7 @@ void Gfx::go(GBool topLevel) { data_p = new ProfileData(); hash->add (cmd_g, data_p); } - + data_p->addElement(timer.getElapsed ()); } } @@ -1252,14 +1259,21 @@ void Gfx::opSetFillCMYKColor(Object args[], int numArgs) { GfxColor color; int i; - state->setFillPattern(NULL); - state->setFillColorSpace(new GfxDeviceCMYKColorSpace()); - out->updateFillColorSpace(state); - for (i = 0; i < 4; ++i) { - color.c[i] = dblToCol(args[i].getNum()); + if (textHaveCSPattern) { + colorSpaceText = new GfxDeviceCMYKColorSpace(); + for (i = 0; i < 4; ++i) { + colorText.c[i] = dblToCol(args[i].getNum()); + } + } else { + state->setFillPattern(NULL); + state->setFillColorSpace(new GfxDeviceCMYKColorSpace()); + out->updateFillColorSpace(state); + for (i = 0; i < 4; ++i) { + color.c[i] = dblToCol(args[i].getNum()); + } + state->setFillColor(&color); + out->updateFillColor(state); } - state->setFillColor(&color); - out->updateFillColor(state); } void Gfx::opSetStrokeCMYKColor(Object args[], int numArgs) { @@ -1280,14 +1294,21 @@ void Gfx::opSetFillRGBColor(Object args[], int numArgs) { GfxColor color; int i; - state->setFillPattern(NULL); - state->setFillColorSpace(new GfxDeviceRGBColorSpace()); - out->updateFillColorSpace(state); - for (i = 0; i < 3; ++i) { - color.c[i] = dblToCol(args[i].getNum()); + if (textHaveCSPattern) { + colorSpaceText = new GfxDeviceRGBColorSpace(); + for (i = 0; i < 3; ++i) { + colorText.c[i] = dblToCol(args[i].getNum()); + } + } else { + state->setFillPattern(NULL); + state->setFillColorSpace(new GfxDeviceRGBColorSpace()); + out->updateFillColorSpace(state); + for (i = 0; i < 3; ++i) { + color.c[i] = dblToCol(args[i].getNum()); + } + state->setFillColor(&color); + out->updateFillColor(state); } - state->setFillColor(&color); - out->updateFillColor(state); } void Gfx::opSetStrokeRGBColor(Object args[], int numArgs) { @@ -1323,6 +1344,19 @@ void Gfx::opSetFillColorSpace(Object args[], int numArgs) { colorSpace->getDefaultColor(&color); state->setFillColor(&color); out->updateFillColor(state); + if (drawText) { + if (colorSpace->getMode() == csPattern) { + colorSpaceText = NULL; + textHaveCSPattern = gTrue; + out->beginTextObject(state); + } else if (textHaveCSPattern) { + out->endTextObject(state); + doPatternFill(gTrue); + out->restoreState(state); + textHaveCSPattern = gFalse; + out->beginTextObject(state); + } + } } else { error(getPos(), "Bad color space (fill)"); } @@ -1846,7 +1880,7 @@ void Gfx::doTilingPatternFill(GfxTilingPattern *tPat, if (stroke) { state->clipToStrokePath(); out->clipToStrokePath(state); - } else { + } else if (!textHaveCSPattern && !maskHaveCSPattern) { state->clip(); if (eoFill) { out->eoClip(state); @@ -1974,7 +2008,7 @@ void Gfx::doShadingPatternFill(GfxShadingPattern *sPat, if (stroke) { state->clipToStrokePath(); out->clipToStrokePath(state); - } else { + } else if (!textHaveCSPattern && !maskHaveCSPattern) { state->clip(); if (eoFill) { out->eoClip(state); @@ -2239,14 +2273,14 @@ void Gfx::doFunctionShFill1(GfxFunctionShading *shading, colors2[2] = colorM0; colors2[3] = colorMM; doFunctionShFill1(shading, x0, y0, xM, yM, colors2, depth + 1); - + // lower-left sub-rectangle colors2[0] = color0M; colors2[1] = colors[1]; colors2[2] = colorMM; colors2[3] = colorM1; doFunctionShFill1(shading, x0, yM, xM, y1, colors2, depth + 1); - + // upper-right sub-rectangle colors2[0] = colorM0; colors2[1] = colorMM; @@ -3090,15 +3124,35 @@ void Gfx::opEOClip(Object args[], int numArgs) { //------------------------------------------------------------------------ void Gfx::opBeginText(Object args[], int numArgs) { + out->beginTextObject(state); + drawText = gTrue; state->setTextMat(1, 0, 0, 1, 0, 0); state->textMoveTo(0, 0); out->updateTextMat(state); out->updateTextPos(state); fontChanged = gTrue; + if (out->supportTextCSPattern(state)) { + colorSpaceText = NULL; + textHaveCSPattern = gTrue; + } } void Gfx::opEndText(Object args[], int numArgs) { out->endTextObject(state); + drawText = gFalse; + if (out->supportTextCSPattern(state) && textHaveCSPattern) { + doPatternFill(gTrue); + out->restoreState(state); + if (colorSpaceText != NULL) { + state->setFillPattern(NULL); + state->setFillColorSpace(colorSpaceText); + out->updateFillColorSpace(state); + state->setFillColor(&colorText); + out->updateFillColor(state); + colorSpaceText = NULL; + } + } + textHaveCSPattern = gFalse; } //------------------------------------------------------------------------ @@ -3664,6 +3718,12 @@ void Gfx::doImage(Object *ref, Stream *str, GBool inlineImg) { // draw it if (!contentIsHidden()) out->drawImageMask(state, ref, str, width, height, invert, inlineImg); + if (out->fillMaskCSPattern(state)) { + maskHaveCSPattern = gTrue; + doPatternFill(gTrue); + out->endMaskClip(state); + maskHaveCSPattern = gFalse; + } } else { @@ -4084,7 +4144,7 @@ void Gfx::opBeginImage(Object args[], int numArgs) { // display the image if (str) { doImage(NULL, str, gTrue); - + // skip 'EI' tag c1 = str->getUndecodedStream()->getChar(); c2 = str->getUndecodedStream()->getChar(); @@ -4200,7 +4260,7 @@ GBool Gfx::contentIsHidden() { void Gfx::opBeginMarkedContent(Object args[], int numArgs) { // push a new stack entry pushMarkedContent(); - + OCGs *contentConfig = catalog->getOptContentConfig(); char* name0 = args[0].getName(); if ( strncmp( name0, "OC", 2) == 0 && contentConfig) {