Author: jeremias
Date: Tue Jun 14 12:58:55 2011
New Revision: 1135540

URL: http://svn.apache.org/viewvc?rev=1135540&view=rev
Log:
Fixed regression introduced with rev 1095887:
Painting state was not properly handled when painting text runs which could 
lead to missing color setters and therefore wrong font colors.
Removed save/restoreGraphicsState from PDFTextUtil as that doesn't update the 
painting state. Instead the code is now using equivalent methods from 
PDFGraphics2D.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTextUtil.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFGraphics2D.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFTextPainter.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTextUtil.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTextUtil.java?rev=1135540&r1=1135539&r2=1135540&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTextUtil.java 
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTextUtil.java Tue Jun 
14 12:58:55 2011
@@ -84,7 +84,7 @@ public abstract class PDFTextUtil {
     private void writeChar(char ch, StringBuffer sb) {
         if (!useMultiByte) {
             if (ch < 32 || ch > 127) {
-                sb.append("\\").append(Integer.toOctalString((int)ch));
+                sb.append("\\").append(Integer.toOctalString(ch));
             } else {
                 switch (ch) {
                 case '(':
@@ -147,21 +147,6 @@ public abstract class PDFTextUtil {
     }
 
     /**
-     * Creates a "q" command, pushing a copy of the entire graphics state onto 
the stack.
-     */
-    public void saveGraphicsState() {
-        write("q\n");
-    }
-
-    /**
-     * Creates a "Q" command, restoring the entire graphics state to its 
former value by popping
-     * it from the stack.
-     */
-    public void restoreGraphicsState() {
-        write("Q\n");
-    }
-
-    /**
      * Creates a "cm" command.
      * @param at the transformation matrix
      */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFGraphics2D.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFGraphics2D.java?rev=1135540&r1=1135539&r2=1135540&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFGraphics2D.java 
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFGraphics2D.java Tue 
Jun 14 12:58:55 2011
@@ -624,8 +624,7 @@ public class PDFGraphics2D extends Abstr
                                && !trans.isIdentity();
 
         if (newClip || newTransform) {
-            currentStream.write("q\n");
-            paintingState.save();
+            saveGraphicsState();
             if (newTransform) {
                 concatMatrix(tranvals);
             }
@@ -650,8 +649,7 @@ public class PDFGraphics2D extends Abstr
                 applyUnknownPaint(paint, ss);
 
                 if (newClip || newTransform) {
-                    currentStream.write("Q\n");
-                    paintingState.restore();
+                    restoreGraphicsState();
                 }
                 return;
             }
@@ -662,8 +660,7 @@ public class PDFGraphics2D extends Abstr
         processPathIterator(iter);
         doDrawing(false, true, false);
         if (newClip || newTransform) {
-            currentStream.write("Q\n");
-            paintingState.restore();
+            restoreGraphicsState();
         }
     }
 
@@ -1613,8 +1610,7 @@ public class PDFGraphics2D extends Abstr
                                && !trans.isIdentity();
 
         if (newClip || newTransform) {
-            currentStream.write("q\n");
-            paintingState.save();
+            saveGraphicsState();
             if (newTransform) {
                 concatMatrix(tranvals);
             }
@@ -1637,8 +1633,7 @@ public class PDFGraphics2D extends Abstr
                 applyUnknownPaint(paint, s);
 
                 if (newClip || newTransform) {
-                    currentStream.write("Q\n");
-                    paintingState.restore();
+                    restoreGraphicsState();
                 }
                 return;
             }
@@ -1658,11 +1653,20 @@ public class PDFGraphics2D extends Abstr
                     iter.getWindingRule() == PathIterator.WIND_EVEN_ODD);
         }
         if (newClip || newTransform) {
-            currentStream.write("Q\n");
-            paintingState.restore();
+            restoreGraphicsState();
         }
     }
 
+    void saveGraphicsState() {
+        currentStream.write("q\n");
+        paintingState.save();
+    }
+
+    void restoreGraphicsState() {
+        currentStream.write("Q\n");
+        paintingState.restore();
+    }
+
     /** Checks whether the use of transparency is allowed. */
     protected void checkTransparencyAllowed() {
         pdfDoc.getProfile().verifyTransparencyAllowed("Java2D graphics");

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFTextPainter.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFTextPainter.java?rev=1135540&r1=1135539&r2=1135540&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFTextPainter.java 
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFTextPainter.java Tue 
Jun 14 12:58:55 2011
@@ -62,11 +62,13 @@ class PDFTextPainter extends NativeTextP
     }
 
     /** {@inheritDoc} */
+    @Override
     protected boolean isSupported(Graphics2D g2d) {
         return g2d instanceof PDFGraphics2D;
     }
 
     /** {@inheritDoc} */
+    @Override
     protected void paintTextRun(TextRun textRun, Graphics2D g2d) {
         AttributedCharacterIterator runaci = textRun.getACI();
         runaci.first();
@@ -86,7 +88,9 @@ class PDFTextPainter extends NativeTextP
         runaci.first(); //Reset ACI
 
         final PDFGraphics2D pdf = (PDFGraphics2D)g2d;
+
         PDFTextUtil textUtil = new PDFTextUtil(pdf.fontInfo) {
+            @Override
             protected void write(String code) {
                 pdf.currentStream.write(code);
             }
@@ -109,7 +113,7 @@ class PDFTextPainter extends NativeTextP
             return;
         }
 
-        textUtil.saveGraphicsState();
+        pdf.saveGraphicsState();
         textUtil.concatMatrix(g2d.getTransform());
         Shape imclip = g2d.getClip();
         pdf.writeClip(imclip);
@@ -197,7 +201,7 @@ class PDFTextPainter extends NativeTextP
         }
         textUtil.writeTJ();
         textUtil.endTextObject();
-        textUtil.restoreGraphicsState();
+        pdf.restoreGraphicsState();
         if (DEBUG) {
             g2d.setStroke(new BasicStroke(0));
             g2d.setColor(Color.LIGHT_GRAY);



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to