xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r1095887 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFGraphics2D.java
Date Fri, 22 Apr 2011 08:25:30 GMT
Author: jeremias
Date: Fri Apr 22 08:25:30 2011
New Revision: 1095887

URL: http://svn.apache.org/viewvc?rev=1095887&view=rev
Log:
Update graphics state when applying color.
Optimize painting of rectangles where possible to reduce file sizes.
Some generics and FindBugs fixes.

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

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=1095887&r1=1095886&r2=1095887&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 Fri Apr 22 08:25:30
2011
@@ -243,6 +243,7 @@ public class PDFGraphics2D extends Abstr
      * @return     a new graphics context that is a copy of
      * this graphics context.
      */
+    @Override
     public Graphics create() {
         return new PDFGraphics2D(this);
     }
@@ -486,6 +487,7 @@ public class PDFGraphics2D extends Abstr
      * @see      java.awt.image.ImageObserver
      * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int,
int, int)
      */
+    @Override
     public boolean drawImage(Image img, int x, int y,
                              ImageObserver observer) {
         preparePainting();
@@ -506,6 +508,7 @@ public class PDFGraphics2D extends Abstr
     }
 
     /** {@inheritDoc} */
+    @Override
     public boolean drawImage(Image img, int x, int y, int width, int height,
                                ImageObserver observer) {
         preparePainting();
@@ -576,6 +579,7 @@ public class PDFGraphics2D extends Abstr
      * @see         java.awt.Component#getGraphics
      * @see         java.awt.Graphics#create
      */
+    @Override
     public void dispose() {
         pdfDoc = null;
         fontInfo = null;
@@ -599,6 +603,7 @@ public class PDFGraphics2D extends Abstr
      * @see #setClip
      * @see #setComposite
      */
+    @Override
     public void draw(Shape s) {
         preparePainting();
 
@@ -748,9 +753,17 @@ public class PDFGraphics2D extends Abstr
              }
         }
 
-        StringBuffer sb = new StringBuffer();
-        colorHandler.establishColor(sb, col, fill);
-        currentStream.write(sb.toString());
+        boolean doWrite = false;
+        if (fill && paintingState.setBackColor(col)) {
+            doWrite = true;
+        } else if (paintingState.setColor(col)) {
+            doWrite = true;
+        }
+        if (doWrite) {
+            StringBuffer sb = new StringBuffer();
+            colorHandler.establishColor(sb, col, fill);
+            currentStream.write(sb.toString());
+        }
     }
 
     /**
@@ -805,7 +818,7 @@ public class PDFGraphics2D extends Abstr
             transform.concatenate(getTransform());
             transform.concatenate(gp.getTransform());
 
-            List theMatrix = new java.util.ArrayList();
+            List<Double> theMatrix = new java.util.ArrayList<Double>();
             double [] mat = new double[6];
             transform.getMatrix(mat);
             for (int idx = 0; idx < mat.length; idx++) {
@@ -814,29 +827,29 @@ public class PDFGraphics2D extends Abstr
 
             Point2D p1 = gp.getStartPoint();
             Point2D p2 = gp.getEndPoint();
-            List theCoords = new java.util.ArrayList();
+            List<Double> theCoords = new java.util.ArrayList<Double>();
             theCoords.add(new Double(p1.getX()));
             theCoords.add(new Double(p1.getY()));
             theCoords.add(new Double(p2.getX()));
             theCoords.add(new Double(p2.getY()));
 
-            List theExtend = new java.util.ArrayList();
-            theExtend.add(new Boolean(true));
-            theExtend.add(new Boolean(true));
+            List<Boolean> theExtend = new java.util.ArrayList<Boolean>();
+            theExtend.add(Boolean.TRUE);
+            theExtend.add(Boolean.TRUE);
 
-            List theDomain = new java.util.ArrayList();
+            List<Double> theDomain = new java.util.ArrayList<Double>();
             theDomain.add(new Double(0));
             theDomain.add(new Double(1));
 
-            List theEncode = new java.util.ArrayList();
+            List<Double> theEncode = new java.util.ArrayList<Double>();
             theEncode.add(new Double(0));
             theEncode.add(new Double(1));
             theEncode.add(new Double(0));
             theEncode.add(new Double(1));
 
-            List theBounds = new java.util.ArrayList();
+            List<Double> theBounds = new java.util.ArrayList<Double>();
 
-            List someColors = new java.util.ArrayList();
+            List<Color> someColors = new java.util.ArrayList<Color>();
 
             for (int count = 0; count < cols.length; count++) {
                 Color c1 = cols[count];
@@ -882,7 +895,7 @@ public class PDFGraphics2D extends Abstr
             transform.concatenate(getTransform());
             transform.concatenate(rgp.getTransform());
 
-            List theMatrix = new java.util.ArrayList();
+            List<Double> theMatrix = new java.util.ArrayList<Double>();
             double [] mat = new double[6];
             transform.getMatrix(mat);
             for (int idx = 0; idx < mat.length; idx++) {
@@ -893,7 +906,7 @@ public class PDFGraphics2D extends Abstr
             Point2D ac = rgp.getCenterPoint();
             Point2D af = rgp.getFocusPoint();
 
-            List theCoords = new java.util.ArrayList();
+            List<Double> theCoords = new java.util.ArrayList<Double>();
             double dx = af.getX() - ac.getX();
             double dy = af.getY() - ac.getY();
             double d = Math.sqrt(dx * dx + dy * dy);
@@ -913,7 +926,7 @@ public class PDFGraphics2D extends Abstr
             theCoords.add(new Double(ar));
 
             Color[] cols = rgp.getColors();
-            List someColors = new java.util.ArrayList();
+            List<Color> someColors = new java.util.ArrayList<Color>();
             for (int count = 0; count < cols.length; count++) {
                 Color cc = cols[count];
                 if (cc.getAlpha() != 255) {
@@ -924,7 +937,7 @@ public class PDFGraphics2D extends Abstr
             }
 
             float[] fractions = rgp.getFractions();
-            List theBounds = new java.util.ArrayList();
+            List<Double> theBounds = new java.util.ArrayList<Double>();
             for (int count = 1; count < fractions.length - 1; count++) {
                 float offset = fractions[count];
                 theBounds.add(new Double(offset));
@@ -964,7 +977,7 @@ public class PDFGraphics2D extends Abstr
         pattGraphic.setOutputStream(outputStream);
 
         GraphicsNode gn = pp.getGraphicsNode();
-        Rectangle2D gnBBox = gn.getBounds();
+        //Rectangle2D gnBBox = gn.getBounds();
         Rectangle2D rect = pp.getPatternRect();
 
         // if (!pp.getOverflow()) {
@@ -1000,7 +1013,7 @@ public class PDFGraphics2D extends Abstr
         //     }
         // }
 
-        List bbox = new java.util.ArrayList();
+        List<Double> bbox = new java.util.ArrayList<Double>();
         bbox.add(new Double(rect.getX()));
         bbox.add(new Double(rect.getHeight() + rect.getY()));
         bbox.add(new Double(rect.getWidth() + rect.getX()));
@@ -1011,7 +1024,7 @@ public class PDFGraphics2D extends Abstr
         transform.concatenate(getTransform());
         transform.concatenate(pp.getPatternTransform());
 
-        List theMatrix = new java.util.ArrayList();
+        List<Double> theMatrix = new java.util.ArrayList<Double>();
         double [] mat = new double[6];
         transform.getMatrix(mat);
         for (int idx = 0; idx < mat.length; idx++) {
@@ -1219,6 +1232,7 @@ public class PDFGraphics2D extends Abstr
     }
 
     /** {@inheritDoc} */
+    @Override
     public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
         String key = "TempImage:" + img.toString();
         drawInnerRenderedImage(key, img, xform);
@@ -1268,6 +1282,7 @@ public class PDFGraphics2D extends Abstr
     }
 
     /** {@inheritDoc} */
+    @Override
     public void drawRenderableImage(RenderableImage img,
                                     AffineTransform xform) {
         //TODO Check if this is good enough
@@ -1298,6 +1313,7 @@ public class PDFGraphics2D extends Abstr
      * @see #setComposite
      * @see #setClip
      */
+    @Override
     public void drawString(String s, float x, float y) {
         preparePainting();
 
@@ -1321,7 +1337,7 @@ public class PDFGraphics2D extends Abstr
         applyPaint(getPaint(), true);
         applyAlpha(c.getAlpha(), OPAQUE);
 
-        Map kerning = fontState.getKerning();
+        Map<Integer, Map<Integer, Integer>> kerning = fontState.getKerning();
         boolean kerningAvailable = (kerning != null && !kerning.isEmpty());
 
         boolean useMultiByte = isMultiByteFont(currentFontName);
@@ -1379,8 +1395,8 @@ public class PDFGraphics2D extends Abstr
             }
 
             if (kerningAvailable && (i + 1) < l) {
-                addKerning(currentStream, (new Integer(ch)),
-                           (new Integer(fontState.mapChar(s.charAt(i + 1)))),
+                addKerning(currentStream, (Integer.valueOf(ch)),
+                           (Integer.valueOf(fontState.mapChar(s.charAt(i + 1)))),
                            kerning, startText, endText);
             }
 
@@ -1400,7 +1416,7 @@ public class PDFGraphics2D extends Abstr
     protected void applyAlpha(int fillAlpha, int strokeAlpha) {
         if (fillAlpha != OPAQUE || strokeAlpha != OPAQUE) {
             checkTransparencyAllowed();
-            Map vals = new java.util.HashMap();
+            Map<String, Float> vals = new java.util.HashMap<String, Float>();
             if (fillAlpha != OPAQUE) {
                 vals.put(PDFGState.GSTATE_ALPHA_NONSTROKE, new Float(fillAlpha / 255f));
             }
@@ -1437,6 +1453,7 @@ public class PDFGraphics2D extends Abstr
      * @return the internal Font
      * @deprecated use FontInfo.getFontInstanceForAWTFont(java.awt.Font awtFont) instead
      */
+    @Deprecated
     protected Font getInternalFontForAWTFont(java.awt.Font awtFont) {
         return fontInfo.getFontInstanceForAWTFont(awtFont);
     }
@@ -1449,18 +1466,18 @@ public class PDFGraphics2D extends Abstr
     protected boolean isMultiByteFont(String name) {
         // This assumes that *all* CIDFonts use a /ToUnicode mapping
         org.apache.fop.fonts.Typeface f
-            = (org.apache.fop.fonts.Typeface)fontInfo.getFonts().get(name);
+            = fontInfo.getFonts().get(name);
         return f.isMultiByte();
     }
 
     private void addKerning(StringWriter buf, Integer ch1, Integer ch2,
-                            Map kerning, String startText,
+                            Map<Integer, Map<Integer, Integer>> kerning, String
startText,
                             String endText) {
         preparePainting();
-        Map kernPair = (Map)kerning.get(ch1);
+        Map<Integer, Integer> kernPair = kerning.get(ch1);
 
         if (kernPair != null) {
-            Integer width = (Integer)kernPair.get(ch2);
+            Integer width = kernPair.get(ch2);
             if (width != null) {
                 currentStream.write(endText + (-width.intValue()) + " " + startText);
             }
@@ -1572,6 +1589,7 @@ public class PDFGraphics2D extends Abstr
      * @see #clip
      * @see #setClip
      */
+    @Override
     public void fill(Shape s) {
         preparePainting();
 
@@ -1626,11 +1644,19 @@ public class PDFGraphics2D extends Abstr
             }
         }
 
-        //PathIterator iter = s.getPathIterator(getTransform());
-        PathIterator iter = s.getPathIterator(IDENTITY_TRANSFORM);
-        processPathIterator(iter);
-        doDrawing(true, false,
-                  iter.getWindingRule() == PathIterator.WIND_EVEN_ODD);
+        if (s instanceof Rectangle2D) {
+            Rectangle2D rect = (Rectangle2D)s;
+            currentStream.write(PDFNumber.doubleOut(rect.getMinX(), DEC) + " "
+                    + PDFNumber.doubleOut(rect.getMinY(), DEC) + " ");
+            currentStream.write(PDFNumber.doubleOut(rect.getWidth(), DEC) + " "
+                    + PDFNumber.doubleOut(rect.getHeight(), DEC) + " re ");
+            doDrawing(true, false, false);
+        } else {
+            PathIterator iter = s.getPathIterator(IDENTITY_TRANSFORM);
+            processPathIterator(iter);
+            doDrawing(true, false,
+                    iter.getWindingRule() == PathIterator.WIND_EVEN_ODD);
+        }
         if (newClip || newTransform) {
             currentStream.write("Q\n");
             paintingState.restore();
@@ -1720,6 +1746,7 @@ public class PDFGraphics2D extends Abstr
      *
      * @return the PDF graphics configuration
      */
+    @Override
     public GraphicsConfiguration getDeviceConfiguration() {
         return new PDFGraphicsConfiguration();
     }
@@ -1744,6 +1771,7 @@ public class PDFGraphics2D extends Abstr
      * @see       java.awt.FontMetrics
      * @see       java.awt.Graphics#getFontMetrics()
      */
+    @Override
     public java.awt.FontMetrics getFontMetrics(java.awt.Font f) {
         return fmg.getFontMetrics(f);
     }
@@ -1763,6 +1791,7 @@ public class PDFGraphics2D extends Abstr
      * drawn twice, then all pixels are restored to their original values.
      * @param     c1 the XOR alternation color
      */
+    @Override
     public void setXORMode(Color c1) {
         //NYI
     }
@@ -1787,6 +1816,7 @@ public class PDFGraphics2D extends Abstr
      * @param       dx the horizontal distance to copy the pixels.
      * @param       dy the vertical distance to copy the pixels.
      */
+    @Override
     public void copyArea(int x, int y, int width, int height, int dx,
                          int dy) {
         //NYI



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message