[poppler] poppler/CairoOutputDev.cc poppler/CairoOutputDev.h poppler/Gfx.cc poppler/PSOutputDev.cc poppler/PSOutputDev.h poppler/SplashOutputDev.cc poppler/SplashOutputDev.h

Albert Astals Cid aacid at kemper.freedesktop.org
Mon Sep 27 14:42:14 PDT 2010


 poppler/CairoOutputDev.cc  |   18 +++---------------
 poppler/CairoOutputDev.h   |    2 --
 poppler/Gfx.cc             |   21 +++++++++++++++++----
 poppler/PSOutputDev.cc     |   26 ++++++++++----------------
 poppler/PSOutputDev.h      |    3 +--
 poppler/SplashOutputDev.cc |   18 +++---------------
 poppler/SplashOutputDev.h  |    4 +---
 7 files changed, 35 insertions(+), 57 deletions(-)

New commits:
commit aa0fd32a8501473832bce1b8b804dd3f9a45735b
Author: Albert Astals Cid <aacid at kde.org>
Date:   Mon Sep 27 22:39:09 2010 +0100

    Consider render value when colorizing text
    
    Fixes bug 2807

diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc
index 65fac76..f832074 100644
--- a/poppler/CairoOutputDev.cc
+++ b/poppler/CairoOutputDev.cc
@@ -606,15 +606,6 @@ void CairoOutputDev::updateFont(GfxState *state) {
   cairo_set_font_matrix (cairo, &matrix);
 }
 
-void CairoOutputDev::updateRender(GfxState *state) {
-  int rm;
-  rm = state->getRender();
-  if (rm == 7 && haveCSPattern) {
-    haveCSPattern = gFalse;
-    restoreState(state);
-  }
-}
-
 void CairoOutputDev::doPath(cairo_t *cairo, GfxState *state, GfxPath *path) {
   GfxSubpath *subpath;
   int i, j;
@@ -909,7 +900,7 @@ void CairoOutputDev::endString(GfxState *state)
     return;
   }
   
-  if (!(render & 1)) {
+  if (!(render & 1) && !haveCSPattern) {
     LOG (printf ("fill string\n"));
     cairo_set_source (cairo, fill_pattern);
     cairo_show_glyphs (cairo, glyphs, glyphCount);
@@ -930,7 +921,7 @@ void CairoOutputDev::endString(GfxState *state)
   }
 
   // clip
-  if (render & 4) {
+  if (haveCSPattern || (render & 4)) {
     LOG (printf ("clip string\n"));
     // append the glyph path to textClipPath.
 
@@ -1014,17 +1005,14 @@ void CairoOutputDev::type3D1(GfxState *state, double wx, double wy,
 }
 
 void CairoOutputDev::beginTextObject(GfxState *state) {
-  if (state->getFillColorSpace()->getMode() == csPattern) {
+  if (!(state->getRender() & 4) && state->getFillColorSpace()->getMode() == csPattern) {
     haveCSPattern = gTrue;
     saveState(state);
-    savedRender = state->getRender();
-    state->setRender(7); // Set clip to text path
   }
 }
 
 void CairoOutputDev::endTextObject(GfxState *state) {
   if (haveCSPattern) {
-    state->setRender(savedRender);
     haveCSPattern = gFalse;
     if (state->getFillColorSpace()->getMode() != csPattern) {
       if (textClipPath) {
diff --git a/poppler/CairoOutputDev.h b/poppler/CairoOutputDev.h
index 02a4955..e003d83 100644
--- a/poppler/CairoOutputDev.h
+++ b/poppler/CairoOutputDev.h
@@ -150,7 +150,6 @@ public:
 
   //----- update text state
   virtual void updateFont(GfxState *state);
-  virtual void updateRender(GfxState *state);
 
   //----- path painting
   virtual void stroke(GfxState *state);
@@ -328,7 +327,6 @@ protected:
 
   GBool haveCSPattern;	// set if text has been drawn with a
                         //   clipping render mode because of pattern colorspace
-  int savedRender;	// use if pattern colorspace
 };
 
 //------------------------------------------------------------------------
diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 76dae02..7552fed 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -3342,7 +3342,7 @@ void Gfx::opBeginText(Object args[], int numArgs) {
   out->updateTextMat(state);
   out->updateTextPos(state);
   fontChanged = gTrue;
-  if (out->supportTextCSPattern(state)) {
+  if (!(state->getRender() & 4) && out->supportTextCSPattern(state)) {
     textHaveCSPattern = gTrue;
   }
 }
@@ -3397,10 +3397,23 @@ void Gfx::opSetTextLeading(Object args[], int numArgs) {
 }
 
 void Gfx::opSetTextRender(Object args[], int numArgs) {
+  int rm = state->getRender();
   state->setRender(args[0].getInt());
-  if (args[0].getInt() == 7) {
-    textHaveCSPattern = gFalse;
-  }
+  if ((args[0].getInt() & 4) && textHaveCSPattern && drawText) {
+    GBool needFill = out->deviceHasTextClip(state);
+    out->endTextObject(state);
+    if (needFill) {
+      doPatternFill(gTrue);
+    }
+    out->restoreState(state);
+    out->beginTextObject(state);
+    out->updateTextMat(state);
+    out->updateTextPos(state);
+    textHaveCSPattern = gFalse;
+  } else if ((rm & 4) && !(args[0].getInt() & 4) && out->supportTextCSPattern(state) && drawText) {
+	out->beginTextObject(state);
+    textHaveCSPattern = gTrue;
+  }
   out->updateRender(state);
 }
 
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 179a494..f7e4b8c 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -20,7 +20,7 @@
 // Copyright (C) 2007, 2008 Brad Hards <bradh at kde.org>
 // Copyright (C) 2008, 2009 Koji Otani <sho at bbr.jp>
 // Copyright (C) 2008 Hib Eris <hib at hiberis.nl>
-// Copyright (C) 2009 Thomas Freitag <Thomas.Freitag at alfa.de>
+// Copyright (C) 2009, 2010 Thomas Freitag <Thomas.Freitag at alfa.de>
 // Copyright (C) 2009 Till Kamppeter <till.kamppeter at gmail.com>
 // Copyright (C) 2009 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright (C) 2009 William Bader <williambader at hotmail.com>
@@ -125,7 +125,7 @@ static char *prolog[] = {
   "~1sn",
   "/pdfOpNames [",
   "  /pdfFill /pdfStroke /pdfLastFill /pdfLastStroke",
-  "  /pdfTextMat /pdfFontSize /pdfCharSpacing /pdfTextRender",
+  "  /pdfTextMat /pdfFontSize /pdfCharSpacing /pdfTextRender /pdfPatternCS",
   "  /pdfTextRise /pdfWordSpacing /pdfHorizScaling /pdfTextClipPath",
   "] def",
   "~123sn",
@@ -157,6 +157,7 @@ static char *prolog[] = {
   "  /pdfFontSize 0 def",
   "  /pdfCharSpacing 0 def",
   "  /pdfTextRender 0 def",
+  "  /pdfPatternCS false def", 
   "  /pdfTextRise 0 def",
   "  /pdfWordSpacing 0 def",
   "  /pdfHorizScaling 1 def",
@@ -398,6 +399,7 @@ static char *prolog[] = {
   "      pdfTextMat matrix concatmatrix dup 4 0 put dup 5 0 put",
   "      exch findfont exch makefont setfont } def",
   "/Tr { /pdfTextRender exch def } def",
+  "/Tp { /pdfPatternCS exch def } def", 
   "/Ts { /pdfTextRise exch def } def",
   "/Tw { /pdfWordSpacing exch def } def",
   "/Tz { /pdfHorizScaling exch def } def",
@@ -469,7 +471,7 @@ static char *prolog[] = {
   "/Tj1 {",
   "  0 pdfTextRise pdfTextMat dtransform rmoveto",
   "  currentpoint 8 2 roll",
-  "  pdfTextRender 1 and 0 eq {",
+  "  pdfTextRender 1 and 0 eq pdfPatternCS not and {",
   "    6 copy awidthshow",
   "  } if",
   "  pdfTextRender 3 and dup 1 eq exch 2 eq or {",
@@ -478,7 +480,7 @@ static char *prolog[] = {
   "    currentfont /FontType get 3 eq { fCol } { sCol } ifelse",
   "    false awcp currentpoint stroke moveto",
   "  } if",
-  "  pdfTextRender 4 and 0 ne {",
+  "  pdfTextRender 4 and 0 ne pdfPatternCS or {",
   "    8 6 roll moveto",
   "    false awcp",
   "    /pdfTextClipPath [ pdfTextClipPath aload pop",
@@ -3708,10 +3710,6 @@ void PSOutputDev::updateRender(GfxState *state) {
   int rm;
 
   rm = state->getRender();
-  if (rm == 7 && haveCSPattern) {
-    haveCSPattern = gFalse;
-    restoreState(state);
-  }
   writePSFmt("{0:d} Tr\n", rm);
   rm &= 3;
   if (rm != 0 && rm != 3) {
@@ -3807,7 +3805,8 @@ GBool PSOutputDev::tilingPatternFill(GfxState *state, Object *str,
   if (paintType == 2) {
     writePSFmt("{0:.4g} 0 {1:.4g} {2:.4g} {3:.4g} {4:.4g} setcachedevice\n",
 	       xStep, bbox[0], bbox[1], bbox[2], bbox[3]);
-  } else {
+  } else
+  {
     if (x1 - 1 <= x0) {
       writePS("1 0 setcharwidth\n");
     } else {
@@ -4359,7 +4358,7 @@ void PSOutputDev::drawString(GfxState *state, GooString *s) {
   }
   delete s2;
 
-  if (state->getRender() & 4) {
+  if (state->getRender() & 4 || haveCSPattern) {
     haveTextClip = gTrue;
   }
 }
@@ -4368,9 +4367,7 @@ void PSOutputDev::beginTextObject(GfxState *state) {
   if (state->getFillColorSpace()->getMode() == csPattern) {
     saveState(state);
     haveCSPattern = gTrue;
-    savedRender = state->getRender();
-    state->setRender(7);
-    writePSFmt("{0:d} Tr\n", 7);
+    writePS("true Tp\n");
   }
 }
 
@@ -4379,7 +4376,6 @@ void PSOutputDev::endTextObject(GfxState *state) {
     if (haveTextClip) {
       writePS("Tclip*\n");
       haveTextClip = gFalse;
-      state->setRender(savedRender);
       if (state->getFillColorSpace()->getMode() != csPattern) {
         double cxMin, cyMin, cxMax, cyMax;
         state->getClipBBox(&cxMin, &cyMin, &cxMax, &cyMax);
@@ -4390,8 +4386,6 @@ void PSOutputDev::endTextObject(GfxState *state) {
         restoreState(state);
         updateFillColor(state);
       }
-    } else {
-      state->setRender(savedRender);
     }
     haveCSPattern = gFalse;
   } else if (haveTextClip) {
diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h
index 38c838c..2ac7b13 100644
--- a/poppler/PSOutputDev.h
+++ b/poppler/PSOutputDev.h
@@ -17,7 +17,7 @@
 // Copyright (C) 2005 Kristian Høgsberg <krh at redhat.com>
 // Copyright (C) 2006-2008 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2007 Brad Hards <bradh 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) 2009 Till Kamppeter <till.kamppeter at gmail.com>
 // Copyright (C) 2009 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright (C) 2009 William Bader <williambader at hotmail.com>
@@ -427,7 +427,6 @@ private:
 				//   clipping render mode
   GBool haveCSPattern;		// set if text has been drawn with a
 				//   clipping render mode because of pattern colorspace
-  int savedRender;		// use if pattern colorspace
 
   GBool inType3Char;		// inside a Type 3 CharProc
   GooString *t3String;		// Type 3 content string
diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc
index 666ee18..0ae5bc5 100644
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -1225,15 +1225,6 @@ void SplashOutputDev::updateFont(GfxState * /*state*/) {
   needFontUpdate = gTrue;
 }
 
-void SplashOutputDev::updateRender(GfxState *state) {
-  int rm;
-  rm = state->getRender();
-  if (rm == 7 && haveCSPattern) {
-    haveCSPattern = gFalse;
-    restoreState(state);
-  }
-}
-
 void SplashOutputDev::doUpdateFont(GfxState *state) {
   GfxFont *gfxFont;
   GfxFontType fontType;
@@ -1621,7 +1612,7 @@ void SplashOutputDev::drawChar(GfxState *state, double x, double y,
 
   // fill
   if (!(render & 1)) {
-    if (!state->getFillColorSpace()->isNonMarking()) {
+    if (!haveCSPattern && !state->getFillColorSpace()->isNonMarking()) {
       splash->fillChar((SplashCoord)x, (SplashCoord)y, code, font);
     }
   }
@@ -1638,7 +1629,7 @@ void SplashOutputDev::drawChar(GfxState *state, double x, double y,
   }
 
   // clip
-  if (render & 4) {
+  if (haveCSPattern || (render & 4)) {
     if ((path = font->getGlyphPath(code))) {
       path->offset((SplashCoord)x, (SplashCoord)y);
       if (textClipPath) {
@@ -1927,17 +1918,14 @@ void SplashOutputDev::drawType3Glyph(T3FontCache *t3Font,
 }
 
 void SplashOutputDev::beginTextObject(GfxState *state) {
-  if (state->getFillColorSpace()->getMode() == csPattern) {
+  if (!(state->getRender() & 4) && state->getFillColorSpace()->getMode() == csPattern) {
     haveCSPattern = gTrue;
     saveState(state);
-    savedRender = state->getRender();
-    state->setRender(7);
   }
 }
 
 void SplashOutputDev::endTextObject(GfxState *state) {
   if (haveCSPattern) {
-    state->setRender(savedRender);
     haveCSPattern = gFalse;
     if (state->getFillColorSpace()->getMode() != csPattern) {
       if (textClipPath) {
diff --git a/poppler/SplashOutputDev.h b/poppler/SplashOutputDev.h
index 37b771a..adbd196 100644
--- a/poppler/SplashOutputDev.h
+++ b/poppler/SplashOutputDev.h
@@ -116,7 +116,6 @@ public:
 
   //----- update text state
   virtual void updateFont(GfxState *state);
-  virtual void updateRender(GfxState *state);
 
   //----- path painting
   virtual void stroke(GfxState *state);
@@ -246,8 +245,7 @@ private:
 			      Guchar *alphaLine);
 
   GBool haveCSPattern;		// set if text has been drawn with a
-				//   clipping render mode because of pattern colorspace
-  int savedRender;		// use if pattern colorspace
+							//   clipping render mode because of pattern colorspace
   GBool keepAlphaChannel;	// don't fill with paper color, keep alpha channel
 
   SplashColorMode colorMode;


More information about the poppler mailing list