You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ss...@apache.org on 2020/10/22 09:00:29 UTC

svn commit: r1882752 - in /xmlgraphics/fop/trunk/fop-core/src: main/java/org/apache/fop/afp/AFPGraphics2D.java test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java

Author: ssteiner
Date: Thu Oct 22 09:00:29 2020
New Revision: 1882752

URL: http://svn.apache.org/viewvc?rev=1882752&view=rev
Log:
FOP-2980: Reduce filesize for AFP Graphics2D

Modified:
    xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java
    xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java?rev=1882752&r1=1882751&r2=1882752&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java Thu Oct 22 09:00:29 2020
@@ -42,6 +42,8 @@ import java.awt.image.ImageObserver;
 import java.awt.image.RenderedImage;
 import java.awt.image.renderable.RenderableImage;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -432,9 +434,11 @@ public class AFPGraphics2D extends Abstr
     private void processPathIterator(PathIterator iter) {
         double[] dstPts = new double[6];
         double[] currentPosition = new double[2];
+        List<Integer> fillets = new ArrayList<Integer>();
         for (int[] openingCoords = new int[2]; !iter.isDone(); iter.next()) {
             switch (iter.currentSegment(dstPts)) {
             case PathIterator.SEG_LINETO:
+                flush(fillets);
                 graphicsObj.addLine(new int[] {
                         (int)Math.round(dstPts[X]),
                         (int)Math.round(dstPts[Y])
@@ -442,12 +446,13 @@ public class AFPGraphics2D extends Abstr
                 currentPosition = new double[]{dstPts[X], dstPts[Y]};
                 break;
             case PathIterator.SEG_QUADTO:
+                flush(fillets);
                 graphicsObj.addFillet(new int[] {
                         (int)Math.round(dstPts[X1]),
                         (int)Math.round(dstPts[Y1]),
                         (int)Math.round(dstPts[X2]),
                         (int)Math.round(dstPts[Y2])
-                     }, true);
+                }, true);
                 currentPosition = new double[]{dstPts[X2], dstPts[Y2]};
                 break;
             case PathIterator.SEG_CUBICTO:
@@ -458,18 +463,17 @@ public class AFPGraphics2D extends Abstr
                 if (quadParts.length >= 4) {
                     for (double[] quadPts : quadParts) {
                         if (quadPts != null && quadPts.length == 4) {
-                            graphicsObj.addFillet(new int[]{
-                                    (int) Math.round(quadPts[X1]),
-                                    (int) Math.round(quadPts[Y1]),
-                                    (int) Math.round(quadPts[X2]),
-                                    (int) Math.round(quadPts[Y2])
-                            }, true);
+                            fillets.add((int) Math.round(quadPts[X1]));
+                            fillets.add((int) Math.round(quadPts[Y1]));
+                            fillets.add((int) Math.round(quadPts[X2]));
+                            fillets.add((int) Math.round(quadPts[Y2]));
                             currentPosition = new double[]{quadPts[X2], quadPts[Y2]};
                         }
                     }
                 }
                 break;
             case PathIterator.SEG_MOVETO:
+                flush(fillets);
                 openingCoords = new int[] {
                         (int)Math.round(dstPts[X]),
                         (int)Math.round(dstPts[Y])
@@ -478,6 +482,7 @@ public class AFPGraphics2D extends Abstr
                 graphicsObj.setCurrentPosition(openingCoords);
                 break;
             case PathIterator.SEG_CLOSE:
+                flush(fillets);
                 graphicsObj.addLine(openingCoords, true);
                 currentPosition = new double[]{openingCoords[0], openingCoords[1]};
                 break;
@@ -486,6 +491,26 @@ public class AFPGraphics2D extends Abstr
                 break;
             }
         }
+        flush(fillets);
+    }
+
+    private void flush(List<Integer> fillets) {
+        List<int[]> intList = listToIntLists(fillets);
+        for (int[] ints : intList) {
+            graphicsObj.addFillet(ints, true);
+        }
+    }
+
+    private List<int[]> listToIntLists(List<Integer> input) {
+        List<int[]> out = new ArrayList<int[]>();
+        while (!input.isEmpty()) {
+            int[] data = new int[Math.min(100, input.size())];
+            for (int i = 0; i < data.length; i++) {
+                data[i] = input.remove(0);
+            }
+            out.add(data);
+        }
+        return out;
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java?rev=1882752&r1=1882751&r2=1882752&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java Thu Oct 22 09:00:29 2020
@@ -20,13 +20,22 @@
 package org.apache.fop.afp;
 
 import java.awt.BasicStroke;
+import java.awt.Rectangle;
+import java.awt.geom.Area;
+import java.awt.geom.Ellipse2D;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 
+import org.junit.Assert;
 import org.junit.Test;
 
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import org.apache.xmlgraphics.java2d.GraphicContext;
+
 import org.apache.fop.afp.modca.GraphicsObject;
 import org.apache.fop.fonts.FontInfo;
 
@@ -54,4 +63,21 @@ public class AFPGraphics2DTestCase {
         verify(gObject).setLineWidth(correctedLineWidth);
     }
 
+    @Test
+    public void testDrawGraphicsFillet() throws IOException {
+        GraphicContext gc = new GraphicContext();
+        gc.setClip(new Rectangle(0, 0, 2, 2));
+        graphics2D.setGraphicContext(gc);
+        GraphicsObject go = new GraphicsObject(new Factory(), "test");
+        graphics2D.setGraphicsObject(go);
+        graphics2D.draw(new Area(new Ellipse2D.Double(0, 0, 100, 100)));
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        go.writeToStream(bos);
+        ByteArrayInputStream is = new ByteArrayInputStream(bos.toByteArray());
+        is.skip(17 + 9 + 14 + 6);
+        int graphicsFilletMarker = 0x85;
+        Assert.assertEquals(is.read(), graphicsFilletMarker);
+        int sizeOfGraphicsFillet = 128;
+        Assert.assertEquals(is.read(), sizeOfGraphicsFillet);
+    }
 }



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