[poppler] 2 commits - poppler/Gfx.cc poppler/Gfx.h poppler/SplashOutputDev.cc poppler/SplashOutputDev.h poppler/TextOutputDev.cc poppler/TextOutputDev.h

Albert Astals Cid aacid at kemper.freedesktop.org
Wed Apr 21 11:22:26 PDT 2010


 poppler/Gfx.cc             |  137 +++++++++++++++++++++------------------------
 poppler/Gfx.h              |    4 -
 poppler/SplashOutputDev.cc |   41 ++++++++++++-
 poppler/SplashOutputDev.h  |    3 
 poppler/TextOutputDev.cc   |    1 
 poppler/TextOutputDev.h    |    1 
 6 files changed, 108 insertions(+), 79 deletions(-)

New commits:
commit ccf238b32e236f69c0507a5421ac2649dfa8d865
Author: Thomas Freitag <Thomas.Freitag at alfa.de>
Date:   Wed Apr 21 19:21:37 2010 +0100

    Improve colorizing text and masks in pattern colorspace
    
    Bug #27482

diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 85d657b..8a7dfee 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -1304,24 +1304,19 @@ void Gfx::opSetFillGray(Object args[], int numArgs) {
       doPatternFill(gTrue);
     }
     out->restoreState(state);
-    state->setFillPattern(NULL);
-    state->setFillColorSpace(new GfxDeviceGrayColorSpace());
-    out->updateFillColorSpace(state);
-    color.c[0] = dblToCol(args[0].getNum());
-    state->setFillColor(&color);
-    out->updateFillColor(state);
+  }
+  state->setFillPattern(NULL);
+  state->setFillColorSpace(new GfxDeviceGrayColorSpace());
+  out->updateFillColorSpace(state);
+  color.c[0] = dblToCol(args[0].getNum());
+  state->setFillColor(&color);
+  out->updateFillColor(state);
+  if (textHaveCSPattern) {
     out->beginTextObject(state);
     out->updateRender(state);
     out->updateTextMat(state);
     out->updateTextPos(state);
     textHaveCSPattern = gFalse;
-  } else {
-    state->setFillPattern(NULL);
-    state->setFillColorSpace(new GfxDeviceGrayColorSpace());
-    out->updateFillColorSpace(state);
-    color.c[0] = dblToCol(args[0].getNum());
-    state->setFillColor(&color);
-    out->updateFillColor(state);
   }
 }
 
@@ -1341,19 +1336,27 @@ void Gfx::opSetFillCMYKColor(Object args[], int numArgs) {
   int i;
 
   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());
+    GBool needFill = out->deviceHasTextClip(state);
+    out->endTextObject(state);
+    if (needFill) {
+      doPatternFill(gTrue);
     }
-    state->setFillColor(&color);
-    out->updateFillColor(state);
+    out->restoreState(state);
+  }
+  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);
+  if (textHaveCSPattern) {
+    out->beginTextObject(state);
+    out->updateRender(state);
+    out->updateTextMat(state);
+    out->updateTextPos(state);
+    textHaveCSPattern = gFalse;
   }
 }
 
@@ -1376,19 +1379,27 @@ void Gfx::opSetFillRGBColor(Object args[], int numArgs) {
   int i;
 
   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());
+    GBool needFill = out->deviceHasTextClip(state);
+    out->endTextObject(state);
+    if (needFill) {
+      doPatternFill(gTrue);
     }
-    state->setFillColor(&color);
-    out->updateFillColor(state);
+    out->restoreState(state);
+  }
+  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);
+  if (textHaveCSPattern) {
+    out->beginTextObject(state);
+    out->updateRender(state);
+    out->updateTextMat(state);
+    out->updateTextPos(state);
+    textHaveCSPattern = gFalse;
   }
 }
 
@@ -1411,7 +1422,6 @@ void Gfx::opSetFillColorSpace(Object args[], int numArgs) {
   GfxColorSpace *colorSpace;
   GfxColor color;
 
-  state->setFillPattern(NULL);
   res->lookupColorSpace(args[0].getName(), &obj);
   if (obj.isNull()) {
     colorSpace = GfxColorSpace::parse(&args[0], this);
@@ -1420,35 +1430,29 @@ void Gfx::opSetFillColorSpace(Object args[], int numArgs) {
   }
   obj.free();
   if (colorSpace) {
+    if (textHaveCSPattern) {
+      GBool needFill = out->deviceHasTextClip(state);
+      out->endTextObject(state);
+      if (needFill) {
+        doPatternFill(gTrue);
+      }
+      out->restoreState(state);
+    }
+    state->setFillPattern(NULL);
     state->setFillColorSpace(colorSpace);
     out->updateFillColorSpace(state);
     colorSpace->getDefaultColor(&color);
     state->setFillColor(&color);
     out->updateFillColor(state);
-    if (drawText) {
-      if (colorSpace->getMode() == csPattern) {
-        if (out->supportTextCSPattern(state) && textHaveCSPattern) {
-          GBool needFill = out->deviceHasTextClip(state);
-          out->endTextObject(state);
-          if (needFill)
-            doPatternFill(gTrue);
-          out->restoreState(state);
-        }
-        colorSpaceText = NULL;
-        textHaveCSPattern = gTrue;
-        out->beginTextObject(state);
-      } else if (textHaveCSPattern) {
-        GBool needFill = out->deviceHasTextClip(state);
-        out->endTextObject(state);
-        if (needFill) {
-          doPatternFill(gTrue);
-        }
-        out->beginTextObject(state);
-        out->updateRender(state);
-        out->updateTextMat(state);
-        out->updateTextPos(state);
-        textHaveCSPattern = gFalse;
-      }
+    if (textHaveCSPattern) {
+      out->beginTextObject(state);
+      out->updateRender(state);
+      out->updateTextMat(state);
+      out->updateTextPos(state);
+      textHaveCSPattern = colorSpace->getMode() == csPattern;
+    } else if (drawText && out->supportTextCSPattern(state)) {
+      out->beginTextObject(state);
+      textHaveCSPattern = gTrue;
     }
   } else {
     error(getPos(), "Bad color space (fill)");
@@ -3329,7 +3333,6 @@ void Gfx::opBeginText(Object args[], int numArgs) {
   out->updateTextPos(state);
   fontChanged = gTrue;
   if (out->supportTextCSPattern(state)) {
-    colorSpaceText = NULL;
     textHaveCSPattern = gTrue;
   }
 }
@@ -3343,14 +3346,6 @@ void Gfx::opEndText(Object args[], int numArgs) {
       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;
 }
diff --git a/poppler/Gfx.h b/poppler/Gfx.h
index 3e12509..f1a8964 100644
--- a/poppler/Gfx.h
+++ b/poppler/Gfx.h
@@ -18,7 +18,7 @@
 // Copyright (C) 2008 Brad Hards <bradh at kde.org>
 // Copyright (C) 2008, 2010 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright (C) 2009 Albert Astals Cid <aacid at kde.org>
-// Copyright (C) 2009 Thomas Freitag <Thomas.Freitag at alfa.de>
+// Copyright (C) 2009, 2010 Thomas Freitag <Thomas.Freitag at alfa.de>
 // Copyright (C) 2010 David Benjamin <davidben at mit.edu>
 //
 // To see a description of the changes please see the Changelog file that
@@ -196,8 +196,6 @@ private:
   GBool drawText;		// in text drawing
   GBool maskHaveCSPattern;	// in mask drawing and mask has pattern colorspace
   GBool commandAborted;         // did the previous command abort the drawing?
-  GfxColorSpace *colorSpaceText;// colorspace after text has filled with pattern
-  GfxColor colorText;		// fill color after after text has filled with pattern
   GfxResources *res;		// resource stack
   int updateLevel;
 
diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc
index bb5cb7f..00aae92 100644
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -1974,7 +1974,20 @@ GBool SplashOutputDev::imageMaskSrc(void *data, SplashColorPtr line) {
 }
 
 void SplashOutputDev::endMaskClip(GfxState * state) {
-	splash->setSoftMask(NULL);
+  double bbox[4] = {0,0,1,1}; // dummy
+  /* transfer mask to alpha channel! */
+  // memcpy(maskBitmap->getAlphaPtr(), maskBitmap->getDataPtr(), bitmap->getRowSize() * bitmap->getHeight());
+  // memset(maskBitmap->getDataPtr(), 0, bitmap->getRowSize() * bitmap->getHeight());
+  int c;
+  Guchar *dest = bitmap->getAlphaPtr();
+  Guchar *src = maskBitmap->getDataPtr();
+  for (c= 0; c < maskBitmap->getRowSize() * maskBitmap->getHeight(); c++) {
+    dest[c] = src[c];
+  }
+  delete maskBitmap;
+  maskBitmap = NULL;
+  endTransparencyGroup(state);
+  paintTransparencyGroup(state, bbox);
 }
 
 void SplashOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
@@ -2007,10 +2020,31 @@ void SplashOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
   imgMaskData.y = 0;
 
   if (state->getFillColorSpace()->getMode() == csPattern) {
-    SplashBitmap *maskBitmap;
     Splash *maskSplash;
     SplashColor maskColor;
-    
+
+    /* from beginTransparencyGroup: */
+    // push a new stack entry
+    SplashTransparencyGroup *transpGroup = new SplashTransparencyGroup();
+    transpGroup->tx = 0;
+    transpGroup->ty = 0;
+    transpGroup->blendingColorSpace = NULL;
+    transpGroup->isolated = gFalse;
+    transpGroup->next = transpGroupStack;
+    transpGroupStack = transpGroup;
+    // save state
+    transpGroup->origBitmap = bitmap;
+    transpGroup->origSplash = splash;
+    //~ this ignores the blendingColorSpace arg
+    // create the temporary bitmap
+    bitmap = new SplashBitmap(bitmap->getWidth(), bitmap->getHeight(), bitmapRowPad, colorMode, gTrue,
+                              bitmapTopDown); 
+    splash = new Splash(bitmap, vectorAntialias,
+                        transpGroup->origSplash->getScreen());
+    splash->blitTransparent(transpGroup->origBitmap, 0, 0, 0, 0, bitmap->getWidth(), bitmap->getHeight());
+    splash->setInNonIsolatedGroup(transpGroup->origBitmap, 0, 0);
+    transpGroup->tBitmap = bitmap;
+
     maskBitmap = new SplashBitmap(bitmap->getWidth(), bitmap->getHeight(), 1, splashModeMono8, gFalse);
     maskSplash = new Splash(maskBitmap, vectorAntialias);
     maskColor[0] = 0;
@@ -2019,7 +2053,6 @@ void SplashOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
     maskSplash->setFillPattern(new SplashSolidColor(maskColor));
     maskSplash->fillImageMask(&imageMaskSrc, &imgMaskData,  width, height, mat, t3GlyphStack != NULL);
     delete maskSplash;
-    splash->setSoftMask(maskBitmap);
   } else {
     splash->fillImageMask(&imageMaskSrc, &imgMaskData, width, height, mat, t3GlyphStack != NULL);
     if (inlineImg) {
diff --git a/poppler/SplashOutputDev.h b/poppler/SplashOutputDev.h
index df33850..37b771a 100644
--- a/poppler/SplashOutputDev.h
+++ b/poppler/SplashOutputDev.h
@@ -14,7 +14,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2005 Takashi Iwai <tiwai at suse.de>
-// Copyright (C) 2009 Thomas Freitag <Thomas.Freitag at alfa.de>
+// Copyright (C) 2009, 2010 Thomas Freitag <Thomas.Freitag at alfa.de>
 // Copyright (C) 2009 Carlos Garcia Campos <carlosgc at gnome.org>
 //
 // To see a description of the changes please see the Changelog file that
@@ -277,6 +277,7 @@ private:
 
   SplashTransparencyGroup *	// transparency group stack
     transpGroupStack;
+  SplashBitmap *maskBitmap; // for image masks in pattern colorspace
 };
 
 #endif
commit 8e86dfb328d94939ecf390d34af533b831b2837b
Author: Albert Astals Cid <aacid at kde.org>
Date:   Wed Apr 21 19:19:53 2010 +0100

    Add copyright

diff --git a/poppler/TextOutputDev.cc b/poppler/TextOutputDev.cc
index e03cc8d..afca5f2 100644
--- a/poppler/TextOutputDev.cc
+++ b/poppler/TextOutputDev.cc
@@ -22,6 +22,7 @@
 // Copyright (C) 2008, 2010 Hib Eris <hib at hiberis.nl>
 // Copyright (C) 2009 Ross Moore <ross at maths.mq.edu.au>
 // Copyright (C) 2009 Kovid Goyal <kovid at kovidgoyal.net>
+// Copyright (C) 2010 Brian Ewins <brian.ewins at gmail.com>
 //
 // 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
diff --git a/poppler/TextOutputDev.h b/poppler/TextOutputDev.h
index 62e2d4c..cceec20 100644
--- a/poppler/TextOutputDev.h
+++ b/poppler/TextOutputDev.h
@@ -15,6 +15,7 @@
 // Copyright (C) 2007-2008 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright (C) 2007 Adrian Johnson <ajohnson at redneon.com>
 // Copyright (C) 2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2010 Brian Ewins <brian.ewins at gmail.com>
 //
 // 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


More information about the poppler mailing list