Author: phancock
Date: Mon Oct  8 09:24:03 2012
New Revision: 1395490

URL: http://svn.apache.org/viewvc?rev=1395490&view=rev
Log:
Increased unit test coverage for the Painters


Added:
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/intermediate/ArcToBezierCurveTransformer.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/intermediate/BezierCurvePainter.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/intermediate/GraphicsPainter.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/java2d/Java2DGraphicsPainter.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/pdf/PDFGraphicsPainter.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/ps/PSGraphicsPainter.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/test/java/org/apache/fop/render/intermediate/ArcToBezierCurveTransformerTestCase.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/test/java/org/apache/fop/render/intermediate/BorderPainterTestCase.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/test/java/org/apache/fop/render/pdf/PDFGraphicsPainterTestCase.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java
Removed:
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/java2d/Java2DBorderPainter.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/pdf/PDFBorderPainter.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/ps/PSBorderPainter.java
Modified:
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/layoutmgr/TraitSetter.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/afp/AFPPainter.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/intermediate/BorderPainter.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/java2d/Java2DPainter.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/pdf/PDFPainter.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/ps/PSPainter.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/traits/BorderProps.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/test/java/org/apache/fop/render/intermediate/AbstractIFPainterTestCase.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/test/java/org/apache/fop/render/ps/PSPainterTestCase.java
    
xmlgraphics/fop/branches/Temp_RoundedCorners/test/java/org/apache/fop/traits/BorderPropsTestCase.java

Modified: 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/layoutmgr/TraitSetter.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/layoutmgr/TraitSetter.java?rev=1395490&r1=1395489&r2=1395490&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/layoutmgr/TraitSetter.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/layoutmgr/TraitSetter.java
 Mon Oct  8 09:24:03 2012
@@ -80,19 +80,19 @@ public final class TraitSetter {
 
         addBorderTrait(area, bpProps, isNotFirst,
                 CommonBorderPaddingBackground.START,
-                BorderProps.SEPARATE, Trait.BORDER_START, context);
+                BorderProps.Mode.SEPARATE, Trait.BORDER_START, context);
 
         addBorderTrait(area, bpProps, isNotLast,
                 CommonBorderPaddingBackground.END,
-                BorderProps.SEPARATE, Trait.BORDER_END, context);
+                BorderProps.Mode.SEPARATE, Trait.BORDER_END, context);
 
         addBorderTrait(area, bpProps, false,
                 CommonBorderPaddingBackground.BEFORE,
-                BorderProps.SEPARATE, Trait.BORDER_BEFORE, context);
+                BorderProps.Mode.SEPARATE, Trait.BORDER_BEFORE, context);
 
         addBorderTrait(area, bpProps, false,
                 CommonBorderPaddingBackground.AFTER,
-                BorderProps.SEPARATE, Trait.BORDER_AFTER, context);
+                BorderProps.Mode.SEPARATE, Trait.BORDER_AFTER, context);
     }
 
     /*
@@ -104,18 +104,14 @@ public final class TraitSetter {
      */
     private static void addBorderTrait(Area area,
                                        CommonBorderPaddingBackground bpProps,
-                                       boolean bDiscard, int iSide, int mode,
-                                       Integer oTrait, PercentBaseContext 
context) {
+                                       boolean bDiscard, int iSide, 
BorderProps.Mode mode,
+                                       Integer traitCode, PercentBaseContext 
context) {
         int iBP = bpProps.getBorderWidth(iSide, bDiscard);
         int radiusStart = bpProps.getBorderRadiusStart(iSide, bDiscard, 
context);
         int radiusEnd = bpProps.getBorderRadiusEnd(iSide, bDiscard, context);
         if (iBP > 0 || radiusStart > 0 || radiusEnd > 0) {
-            BorderProps bps =  new BorderProps(bpProps.getBorderStyle(iSide),
-                    iBP, bpProps.getBorderColor(iSide),
-                    mode);
-            bps.setRadiusStart(radiusStart);
-            bps.setRadiusEnd(radiusEnd);
-            area.addTrait(oTrait, bps);
+            area.addTrait(traitCode, new 
BorderProps(bpProps.getBorderStyle(iSide), iBP, radiusStart, radiusEnd,
+                    bpProps.getBorderColor(iSide), mode));
         }
     }
 
@@ -273,14 +269,8 @@ public final class TraitSetter {
         int radiusStart = bordProps.getBorderRadiusStart(side, false, context);
         int radiusEnd = bordProps.getBorderRadiusEnd(side, false, context);
         if (width != 0 || radiusStart != 0 || radiusEnd != 0) {
-            BorderProps bps;
-            bps = new BorderProps(bordProps.getBorderStyle(side),
-                                  width,
-                                  bordProps.getBorderColor(side),
-                                  BorderProps.SEPARATE);
-            bps.setRadiusStart(radiusStart);
-            bps.setRadiusEnd(radiusEnd);
-            return bps;
+            return new BorderProps(bordProps.getBorderStyle(side), width, 
radiusStart, radiusEnd,
+                                  bordProps.getBorderColor(side), 
BorderProps.Mode.SEPARATE);
         } else {
             return null;
         }
@@ -290,8 +280,8 @@ public final class TraitSetter {
         assert borderInfo != null;
         int width = borderInfo.getRetainedWidth();
         if (width != 0) {
-            return new BorderProps(borderInfo.getStyle(), width, 
borderInfo.getColor(),
-                    (outer ? BorderProps.COLLAPSE_OUTER : 
BorderProps.COLLAPSE_INNER));
+            return  BorderProps.makeRectangular(borderInfo.getStyle(), width, 
borderInfo.getColor(),
+                    (outer ? BorderProps.Mode.COLLAPSE_OUTER : 
BorderProps.Mode.COLLAPSE_INNER));
         } else {
             return null;
         }

Modified: 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java?rev=1395490&r1=1395489&r2=1395490&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java
 Mon Oct  8 09:24:03 2012
@@ -597,9 +597,9 @@ public class TableCellLayoutManager exte
             blocks[i][j].addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
             blocks[i][j].setPositioning(Block.ABSOLUTE);
         }
-        blocks[i][j].addTrait(side, new BorderProps(border.getStyle(),
+        blocks[i][j].addTrait(side, 
BorderProps.makeRectangular(border.getStyle(),
                 border.getRetainedWidth(), border.getColor(),
-                outer ? BorderProps.COLLAPSE_OUTER : 
BorderProps.COLLAPSE_INNER));
+                outer ? BorderProps.Mode.COLLAPSE_OUTER : 
BorderProps.Mode.COLLAPSE_INNER));
     }
 
     private static void adjustXOffset(Block block, int amount) {

Modified: 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java?rev=1395490&r1=1395489&r2=1395490&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
 Mon Oct  8 09:24:03 2012
@@ -429,11 +429,12 @@ public abstract class AbstractPathOrient
             moveTo(sx1, clipy);
             float sx1a = sx1;
             float ex1a = ex1;
-            if (bpsTop.mode == BorderProps.COLLAPSE_OUTER) {
-                if (bpsLeft != null && bpsLeft.mode == 
BorderProps.COLLAPSE_OUTER) {
+
+            if (isCollapseOuter(bpsTop)) {
+                if (isCollapseOuter(bpsLeft)) {
                     sx1a -= clipw[LEFT];
                 }
-                if (bpsRight != null && bpsRight.mode == 
BorderProps.COLLAPSE_OUTER) {
+                if (isCollapseOuter(bpsRight)) {
                     ex1a += clipw[RIGHT];
                 }
                 lineTo(sx1a, outery);
@@ -463,11 +464,11 @@ public abstract class AbstractPathOrient
             moveTo(clipx, sy1);
             float sy1a = sy1;
             float ey1a = ey1;
-            if (bpsRight.mode == BorderProps.COLLAPSE_OUTER) {
-                if (bpsTop != null && bpsTop.mode == 
BorderProps.COLLAPSE_OUTER) {
+            if (isCollapseOuter(bpsRight)) {
+                if (isCollapseOuter(bpsTop)) {
                     sy1a -= clipw[TOP];
                 }
-                if (bpsBottom != null && bpsBottom.mode == 
BorderProps.COLLAPSE_OUTER) {
+                if (isCollapseOuter(bpsBottom)) {
                     ey1a += clipw[BOTTOM];
                 }
                 lineTo(outerx, sy1a);
@@ -497,11 +498,11 @@ public abstract class AbstractPathOrient
             moveTo(ex1, clipy);
             float sx1a = sx1;
             float ex1a = ex1;
-            if (bpsBottom.mode == BorderProps.COLLAPSE_OUTER) {
-                if (bpsLeft != null && bpsLeft.mode == 
BorderProps.COLLAPSE_OUTER) {
+            if (isCollapseOuter(bpsBottom)) {
+                if (isCollapseOuter(bpsLeft)) {
                     sx1a -= clipw[LEFT];
                 }
-                if (bpsRight != null && bpsRight.mode == 
BorderProps.COLLAPSE_OUTER) {
+                if (isCollapseOuter(bpsRight)) {
                     ex1a += clipw[RIGHT];
                 }
                 lineTo(ex1a, outery);
@@ -531,11 +532,11 @@ public abstract class AbstractPathOrient
             moveTo(clipx, ey1);
             float sy1a = sy1;
             float ey1a = ey1;
-            if (bpsLeft.mode == BorderProps.COLLAPSE_OUTER) {
-                if (bpsTop != null && bpsTop.mode == 
BorderProps.COLLAPSE_OUTER) {
+            if (isCollapseOuter(bpsLeft)) {
+                if (isCollapseOuter(bpsTop)) {
                     sy1a -= clipw[TOP];
                 }
-                if (bpsBottom != null && bpsBottom.mode == 
BorderProps.COLLAPSE_OUTER) {
+                if (isCollapseOuter(bpsBottom)) {
                     ey1a += clipw[BOTTOM];
                 }
                 lineTo(outerx, ey1a);
@@ -551,6 +552,10 @@ public abstract class AbstractPathOrient
         }
     }
 
+    private boolean isCollapseOuter(BorderProps bp) {
+        return bp != null && bp.isCollapseOuter();
+    }
+
     /**
      * Common method to render the background and borders for any inline area.
      * The all borders and padding are drawn outside the specified area.

Modified: 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/afp/AFPPainter.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/afp/AFPPainter.java?rev=1395490&r1=1395489&r2=1395490&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/afp/AFPPainter.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/afp/AFPPainter.java
 Mon Oct  8 09:24:03 2012
@@ -38,9 +38,6 @@ import java.util.Map;
 
 import org.w3c.dom.Document;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.image.loader.ImageException;
 import org.apache.xmlgraphics.image.loader.ImageInfo;
@@ -76,6 +73,7 @@ import org.apache.fop.render.ImageHandle
 import org.apache.fop.render.RenderingContext;
 import org.apache.fop.render.intermediate.AbstractIFPainter;
 import org.apache.fop.render.intermediate.BorderPainter;
+import org.apache.fop.render.intermediate.GraphicsPainter;
 import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.render.intermediate.IFState;
 import org.apache.fop.render.intermediate.IFUtil;
@@ -88,15 +86,12 @@ import org.apache.fop.util.CharUtilities
  */
 public class AFPPainter extends AbstractIFPainter<AFPDocumentHandler> {
 
-
-
-
-    //** logging instance */
-    private static Log log = LogFactory.getLog(AFPPainter.class);
-
     private static final int X = 0;
+
     private static final int Y = 1;
 
+    private final GraphicsPainter graphicsPainter;
+
     /** the border painter */
     private final AFPBorderPainterAdapter borderPainter;
     /** the rectangle painter */
@@ -114,9 +109,9 @@ public class AFPPainter extends Abstract
     public AFPPainter(AFPDocumentHandler documentHandler) {
         super(documentHandler);
         this.state = IFState.create();
-
-        this.borderPainter = new AFPBorderPainterAdapter(
-                new AFPBorderPainter(getPaintingState(), getDataStream()), 
this, documentHandler);
+        this.graphicsPainter = new AFPGraphicsPainter(
+                new AFPBorderPainter(getPaintingState(), getDataStream()));
+        this.borderPainter = new AFPBorderPainterAdapter(graphicsPainter, 
this, documentHandler);
         this.rectanglePainter = documentHandler.createRectanglePainter();
         this.unitConv = getPaintingState().getUnitConverter();
         this.eventProducer = 
AFPEventProducer.Provider.get(getUserAgent().getEventBroadcaster());
@@ -142,7 +137,7 @@ public class AFPPainter extends Abstract
 
     /** {@inheritDoc} */
     public void startViewport(AffineTransform transform, Dimension size, 
Rectangle clipRect)
-    throws IFException {
+            throws IFException {
         //AFP doesn't support clipping, so we treat viewport like a group
         //this is the same code as for startGroup()
         try {
@@ -248,10 +243,10 @@ public class AFPPainter extends Abstract
     /** {@inheritDoc} */
     protected void drawImage(Image image, Rectangle rect,
             RenderingContext context, boolean convert, Map additionalHints)
-    throws IOException, ImageException {
+                    throws IOException, ImageException {
 
 
-        AFPRenderingContext afpContext = (AFPRenderingContext)context;
+        AFPRenderingContext afpContext = (AFPRenderingContext) context;
 
         AFPResourceInfo resourceInfo = 
AFPImageHandler.createResourceInformation(
                 image.getInfo().getOriginalURI(),
@@ -292,7 +287,7 @@ public class AFPPainter extends Abstract
         }
         if (rect.width != 0 && rect.height != 0) {
             if (fill instanceof Color) {
-                getPaintingState().setColor((Color)fill);
+                getPaintingState().setColor((Color) fill);
             } else {
                 throw new UnsupportedOperationException("Non-Color paints 
NYI");
             }
@@ -315,13 +310,82 @@ public class AFPPainter extends Abstract
     }
 
 
+    private static final class AFPGraphicsPainter implements GraphicsPainter {
+
+        private final AFPBorderPainter graphicsPainter;
+
+        private AFPGraphicsPainter(AFPBorderPainter delegate) {
+            this.graphicsPainter = delegate;
+        }
+
+        public void drawBorderLine(int x1, int y1, int x2, int y2,
+                boolean horz, boolean startOrBefore, int style, Color color)
+                        throws IOException {
+            BorderPaintingInfo borderPaintInfo = new BorderPaintingInfo(
+                    toPoints(x1), toPoints(y1), toPoints(x2), toPoints(y2),
+                    horz, style, color);
+            graphicsPainter.paint(borderPaintInfo);
+        }
+
+        private float toPoints(int mpt) {
+            return mpt / 1000f;
+        }
+
+        public void drawLine(Point start, Point end, int width,
+                Color color, RuleStyle style) throws IOException {
+            if (start.y != end.y) {
+                //TODO Support arbitrary lines if necessary
+                throw new UnsupportedOperationException("Can only deal with 
horizontal lines right now");
+            }
+            //Simply delegates to drawBorderLine() as AFP line painting is not 
very sophisticated.
+            int halfWidth = width / 2;
+            drawBorderLine(start.x, start.y - halfWidth, end.x, start.y + 
halfWidth,
+                    true, true, style.getEnumValue(), color);
+        }
+
+        public void moveTo(int x, int y) throws IOException {
+        }
+
+        public void lineTo(int x, int y) throws IOException {
+        }
+
+        public void arcTo(double startAngle, double endAngle, int cx, int cy,
+                int width, int height) throws IOException {
+        }
+
+        public void rotateCoordinates(double angle) throws IOException {
+            throw new UnsupportedOperationException("Cannot handle coordinate 
rotation");
+        }
+
+        public void translateCoordinates(int xTranslate, int yTranslate) 
throws IOException {
+            throw new UnsupportedOperationException("Cannot handle coordinate 
translation");
+        }
+
+        public void scaleCoordinates(float xScale, float yScale) throws 
IOException {
+            throw new UnsupportedOperationException("Cannot handle coordinate 
scaling");
+        }
+
+        public void closePath() throws IOException {
+        }
+
+        public void clip() throws IOException {
+        }
+
+        public void saveGraphicsState() throws IOException {
+        }
+
+        public void restoreGraphicsState() throws IOException {
+        }
+
+
+    }
+
     //TODO Try to resolve the name-clash between the AFPBorderPainter in the 
afp package
     //and this one. Not done for now to avoid a lot of re-implementation and 
code duplication.
-
     private static class AFPBorderPainterAdapter extends BorderPainter {
 
         private final class BorderImagePainter implements 
Graphics2DImagePainter {
-            private final double esf;
+            private final double cornerCorrectionFactor;
             private final Rectangle borderRect;
             private final BorderProps bpsStart;
             private final BorderProps bpsEnd;
@@ -331,11 +395,11 @@ public class AFPPainter extends Abstract
             private final Color innerBackgroundColor;
 
             /* TODO represent border related parameters in a class */
-            private BorderImagePainter(double esf, Rectangle borderRect,
+            private BorderImagePainter(double cornerCorrectionFactor, 
Rectangle borderRect,
                     BorderProps bpsStart, BorderProps bpsEnd,
                     BorderProps bpsBefore, BorderProps bpsAfter,
                     boolean[] roundCorner, Color innerBackgroundColor) {
-                this.esf = esf;
+                this.cornerCorrectionFactor = cornerCorrectionFactor;
                 this.borderRect = borderRect;
                 this.bpsStart = bpsStart;
                 this.bpsBefore = bpsBefore;
@@ -350,13 +414,12 @@ public class AFPPainter extends Abstract
                 //background
                 Area background = new Area(area);
                 Area cornerRegion = new Area();
-                Area[] cornerBorder
-                        = new Area[]{new Area(), new Area(), new Area(), new 
Area()};
+                Area[] cornerBorder = new Area[]{new Area(), new Area(), new 
Area(), new Area()};
 
                 if (roundCorner[TOP_LEFT]) {
                     AffineTransform transform =  new AffineTransform();
-                    int beforeRadius = (int)(esf * bpsBefore.getRadiusStart());
-                    int startRadius = (int)(esf * bpsStart.getRadiusStart());
+                    int beforeRadius = (int)(cornerCorrectionFactor * 
bpsBefore.getRadiusStart());
+                    int startRadius = (int)(cornerCorrectionFactor * 
bpsStart.getRadiusStart());
 
                     int beforeWidth = bpsBefore.width;
                     int startWidth = bpsStart.width;
@@ -380,8 +443,8 @@ public class AFPPainter extends Abstract
                     AffineTransform transform
                             = new AffineTransform(-1, 0, 0, 1, 
borderRect.width, 0);
 
-                    int beforeRadius = (int)(esf * bpsBefore.getRadiusEnd());
-                    int startRadius = (int)(esf * bpsEnd.getRadiusStart());
+                    int beforeRadius = (int)(cornerCorrectionFactor * 
bpsBefore.getRadiusEnd());
+                    int startRadius = (int)(cornerCorrectionFactor * 
bpsEnd.getRadiusStart());
 
                     int beforeWidth = bpsBefore.width;
                     int startWidth = bpsEnd.width;
@@ -405,8 +468,8 @@ public class AFPPainter extends Abstract
                     AffineTransform transform = new AffineTransform(-1, 0, 0, 
-1,
                             borderRect.width, borderRect.height);
 
-                    int beforeRadius = (int)(esf * bpsAfter.getRadiusEnd());
-                    int startRadius = (int)(esf * bpsEnd.getRadiusEnd());
+                    int beforeRadius = (int)(cornerCorrectionFactor * 
bpsAfter.getRadiusEnd());
+                    int startRadius = (int)(cornerCorrectionFactor * 
bpsEnd.getRadiusEnd());
 
                     int beforeWidth = bpsAfter.width;
                     int startWidth = bpsEnd.width;
@@ -429,8 +492,8 @@ public class AFPPainter extends Abstract
                     AffineTransform transform
                             = new AffineTransform(1, 0, 0, -1, 0, 
borderRect.height);
 
-                    int beforeRadius = (int)(esf * bpsAfter.getRadiusStart());
-                    int startRadius = (int)(esf * bpsStart.getRadiusEnd());
+                    int beforeRadius = (int)(cornerCorrectionFactor * 
bpsAfter.getRadiusStart());
+                    int startRadius = (int)(cornerCorrectionFactor * 
bpsStart.getRadiusEnd());
 
                     int beforeWidth = bpsAfter.width;
                     int startWidth = bpsStart.width;
@@ -499,8 +562,7 @@ public class AFPPainter extends Abstract
                     borderPath.lineTo(
                             borderRect.width - (bpsEnd == null ? 0 : 
bpsEnd.width),
                             borderRect.height - bpsAfter.width);
-                    borderPath.lineTo(
-                            bpsStart == null ? 0 : bpsStart.width,
+                    borderPath.lineTo(bpsStart == null ? 0 : bpsStart.width,
                             borderRect.height - bpsAfter.width);
                     Area border = new Area(borderPath);
 
@@ -536,13 +598,12 @@ public class AFPPainter extends Abstract
             }
         }
 
-        private AFPBorderPainter delegate;
         private final AFPPainter painter;
         private final AFPDocumentHandler documentHandler;
 
-        public AFPBorderPainterAdapter(AFPBorderPainter borderPainter, 
AFPPainter painter,
+        public AFPBorderPainterAdapter(GraphicsPainter graphicsPainter, 
AFPPainter painter,
                 AFPDocumentHandler documentHandler) {
-            this.delegate = borderPainter;
+            super(graphicsPainter);
             this.painter = painter;
             this.documentHandler = documentHandler;
         }
@@ -559,55 +620,49 @@ public class AFPPainter extends Abstract
             return !hasRoundedCorners(bpsBefore,  bpsAfter, bpsStart,  bpsEnd);
         }
 
-        private boolean hasRoundedCorners( final BorderProps bpsBefore, final 
BorderProps bpsAfter,
+        private boolean hasRoundedCorners(final BorderProps bpsBefore, final 
BorderProps bpsAfter,
                 final BorderProps bpsStart, final BorderProps bpsEnd) {
             return ((bpsStart == null ? false : bpsStart.getRadiusStart() > 0)
-                        && (bpsBefore == null ? false : 
bpsBefore.getRadiusStart() > 0))
-                || ((bpsBefore == null ? false : bpsBefore.getRadiusEnd() > 0)
-                        && (bpsEnd == null ? false : bpsEnd.getRadiusStart() > 
0))
-                || ((bpsEnd == null ? false : bpsEnd.getRadiusEnd() > 0)
-                        && (bpsAfter == null ? false : bpsAfter.getRadiusEnd() 
> 0))
-                        || ((bpsAfter == null ? false : 
bpsAfter.getRadiusStart() > 0)
-                        && (bpsStart == null ? false : bpsStart.getRadiusEnd() 
> 0));
+                    && (bpsBefore == null ? false : bpsBefore.getRadiusStart() 
> 0))
+                    || ((bpsBefore == null ? false : bpsBefore.getRadiusEnd() 
> 0)
+                            && (bpsEnd == null ? false : 
bpsEnd.getRadiusStart() > 0))
+                            || ((bpsEnd == null ? false : 
bpsEnd.getRadiusEnd() > 0)
+                                    && (bpsAfter == null ? false : 
bpsAfter.getRadiusEnd() > 0))
+                                    || ((bpsAfter == null ? false : 
bpsAfter.getRadiusStart() > 0)
+                                            && (bpsStart == null ? false : 
bpsStart.getRadiusEnd() > 0));
         }
 
         private void drawRoundedCorners(final Rectangle borderRect,
                 final BorderProps bpsBefore, final BorderProps bpsAfter,
                 final BorderProps bpsStart, final BorderProps bpsEnd,
-                final Color innerBackgroundColor)
-        throws IFException {
-
-
-            final double esf = cornerScaleFactor(borderRect.width, 
borderRect.height,
-                    bpsBefore,  bpsAfter,
-                    bpsStart,  bpsEnd);
-
+                final Color innerBackgroundColor) throws IFException {
+            final double cornerCorrectionFactor = 
calculateCornerCorrectionFactor(borderRect.width,
+                    borderRect.height, bpsBefore,  bpsAfter, bpsStart,  
bpsEnd);
             final boolean[] roundCorner = new boolean[]{
                     bpsBefore != null  && bpsStart != null
-                        && bpsBefore.getRadiusStart() > 0
-                        && bpsStart.getRadiusStart() > 0
-                        && bpsBefore.mode != BorderProps.COLLAPSE_OUTER
-                        && bpsStart.mode != BorderProps.COLLAPSE_OUTER,
-                    bpsEnd != null && bpsBefore != null
-                        && bpsEnd.getRadiusStart() > 0
-                        && bpsBefore.getRadiusEnd() > 0
-                        && bpsEnd.mode != BorderProps.COLLAPSE_OUTER
-                        && bpsBefore.mode != BorderProps.COLLAPSE_OUTER,
-                    bpsEnd != null && bpsAfter != null
-                        && bpsEnd.getRadiusEnd() > 0
-                        && bpsAfter.getRadiusEnd() > 0
-                        && bpsEnd.mode != BorderProps.COLLAPSE_OUTER
-                        && bpsAfter.mode != BorderProps.COLLAPSE_OUTER,
-                    bpsStart != null && bpsAfter != null
-                        && bpsStart.getRadiusEnd() > 0
-                        && bpsAfter.getRadiusStart() > 0
-                        && bpsStart.mode != BorderProps.COLLAPSE_OUTER
-                        && bpsAfter.mode != BorderProps.COLLAPSE_OUTER
-                   };
-
+                            && bpsBefore.getRadiusStart() > 0
+                            && bpsStart.getRadiusStart() > 0
+                            && isNotCollapseOuter(bpsBefore)
+                            && isNotCollapseOuter(bpsStart),
+                            bpsEnd != null && bpsBefore != null
+                            && bpsEnd.getRadiusStart() > 0
+                            && bpsBefore.getRadiusEnd() > 0
+                            && isNotCollapseOuter(bpsEnd)
+                            && isNotCollapseOuter(bpsBefore),
+                            bpsEnd != null && bpsAfter != null
+                            && bpsEnd.getRadiusEnd() > 0
+                            && bpsAfter.getRadiusEnd() > 0
+                            && isNotCollapseOuter(bpsEnd)
+                            && isNotCollapseOuter(bpsAfter),
+                            bpsStart != null && bpsAfter != null
+                            && bpsStart.getRadiusEnd() > 0
+                            && bpsAfter.getRadiusStart() > 0
+                            && isNotCollapseOuter(bpsStart)
+                            && isNotCollapseOuter(bpsAfter)
+            };
 
             if (!roundCorner[TOP_LEFT] && !roundCorner[TOP_RIGHT]
-                        && !roundCorner[BOTTOM_RIGHT] && 
!roundCorner[BOTTOM_LEFT]) {
+                    && !roundCorner[BOTTOM_RIGHT] && 
!roundCorner[BOTTOM_LEFT]) {
                 try {
                     drawRectangularBorders(borderRect, bpsBefore, bpsAfter, 
bpsStart, bpsEnd);
                 } catch (IOException ioe) {
@@ -627,16 +682,19 @@ public class AFPPainter extends Abstract
 
                 name = documentHandler.cacheRoundedCorner(areaKey);
 
-                painter = new BorderImagePainter(esf, borderRect,
+                painter = new BorderImagePainter(cornerCorrectionFactor, 
borderRect,
                         bpsStart, bpsEnd, bpsBefore, bpsAfter,
                         roundCorner, innerBackgroundColor);
             }
             paintCornersAsBitmap(painter, borderRect, name);
         }
 
+        private boolean isNotCollapseOuter(BorderProps bp) {
+            return !bp.isCollapseOuter();
+        }
 
         private Area makeCornerClip(final int beforeRadius, final int 
startRadius,
-                 final AffineTransform transform) {
+                final AffineTransform transform) {
 
             Rectangle clipR = new Rectangle(0, 0, startRadius, beforeRadius);
 
@@ -678,7 +736,7 @@ public class AFPPainter extends Abstract
 
             GeneralPath cut = new GeneralPath();
             cut.moveTo(0, 0);
-            float borderWidthRatio = ((float)beforeWidth) / startWidth;
+            float borderWidthRatio = ((float) beforeWidth) / startWidth;
             if (beforeWidth * startRadius > startWidth * beforeRadius) {
                 cut.lineTo(startRadius, borderWidthRatio * startRadius);
                 cut.lineTo(startRadius, 0);
@@ -718,7 +776,7 @@ public class AFPPainter extends Abstract
 
             GeneralPath cut = new GeneralPath();
             cut.moveTo(0, 0);
-            float borderWidthRatio = ((float)beforeWidth) / startWidth;
+            float borderWidthRatio = ((float) beforeWidth) / startWidth;
             if (beforeWidth * startRadius > startWidth * beforeRadius) {
                 cut.lineTo(startRadius, borderWidthRatio * startRadius);
                 cut.lineTo(startRadius, 0);
@@ -735,7 +793,7 @@ public class AFPPainter extends Abstract
 
         private String makeKey(Rectangle area, BorderProps beforeProps,
                 BorderProps endProps, BorderProps afterProps, BorderProps 
startProps,
-                 Color innerBackgroundColor) {
+                Color innerBackgroundColor) {
 
             return hash(new StringBuffer()
                     .append(area.width)
@@ -770,9 +828,9 @@ public class AFPPainter extends Abstract
             char[] digits = {'0', '1', '2', '3', '4', '5', '6',
                     '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
             for (int idx = 0; idx < 6; ++idx) {
-              byte b = result[idx];
-              sb.append(digits[(b & 0xf0) >> 4]);
-              sb.append(digits[b & 0x0f]);
+                byte b = result[idx];
+                sb.append(digits[(b & 0xf0) >> 4]);
+                sb.append(digits[b & 0x0f]);
             }
             return sb.toString();
         }
@@ -816,107 +874,19 @@ public class AFPPainter extends Abstract
             }
         }
 
-        @Override
-        protected void clip() throws IOException {
-            //not supported by AFP
-        }
-
-        @Override
-        protected void closePath() throws IOException {
-            //used for clipping only, so not implemented
-        }
-
-        @Override
-        protected void moveTo(int x, int y) throws IOException {
-            //used for clipping only, so not implemented
-        }
-
-        @Override
-        protected void lineTo(int x, int y) throws IOException {
-            //used for clipping only, so not implemented
-        }
-
-        @Override
-        protected void saveGraphicsState() throws IOException {
-            //used for clipping only, so not implemented
-        }
-
-        @Override
-        protected void restoreGraphicsState() throws IOException {
-            //used for clipping only, so not implemented
-        }
-
-        private float toPoints(int mpt) {
-            return mpt / 1000f;
-        }
-
-        @Override
-        protected void drawBorderLine(                           // CSOK: 
ParameterNumber
-                int x1, int y1, int x2, int y2, boolean horz,
-                boolean startOrBefore, int style, Color color) throws 
IOException {
-            BorderPaintingInfo borderPaintInfo = new BorderPaintingInfo(
-                    toPoints(x1), toPoints(y1), toPoints(x2), toPoints(y2),
-                    horz, style, color);
-            delegate.paint(borderPaintInfo);
-        }
-
-        @Override
-        public void drawLine(Point start, Point end, int width, Color color, 
RuleStyle style)
-        throws IOException {
-            if (start.y != end.y) {
-                //TODO Support arbitrary lines if necessary
-                throw new UnsupportedOperationException(
-                "Can only deal with horizontal lines right now");
-            }
-
-            //Simply delegates to drawBorderLine() as AFP line painting is not 
very sophisticated.
-            int halfWidth = width / 2;
-            drawBorderLine(start.x, start.y - halfWidth, end.x, start.y + 
halfWidth,
-                    true, true, style.getEnumValue(), color);
-        }
-
-
         protected void arcTo(double startAngle, double endAngle, int cx, int 
cy, int width,
                 int height) throws IOException {
-            throw new UnsupportedOperationException(
-            "Can only deal with horizontal lines right now");
-
-        }
-
+            throw new UnsupportedOperationException("Can only deal with 
horizontal lines right now");
 
-        protected void changeCoords(double a, double b, double c, double d, 
double e, double f) {
-            throw new UnsupportedOperationException(
-            "Can only deal with horizontal lines right now");
-        }
-
-        protected void cubicBezierTo(int p1x, int p1y, int p2x, int p2y, int 
p3x, int p3y)
-        throws IOException {
-            throw new UnsupportedOperationException(
-            "Cannot handle cubic Bezier");
-        }
-
-        protected void rotateCoordinates(double angle) throws IOException {
-            throw new UnsupportedOperationException(
-            "Cannot handle coordinate rotation");
-        }
-
-        protected void scaleCoordinates(float xScale, float yScale) throws 
IOException {
-            throw new UnsupportedOperationException(
-            "Cannot handle coordinate scaling");
-        }
-
-        protected void translateCoordinates(int xTranslate, int yTranslate) 
throws IOException {
-            throw new UnsupportedOperationException(
-            "Cannot handle coordinate  translation");
         }
     }
 
     /** {@inheritDoc} */
     @Override
     public void drawLine(Point start, Point end, int width, Color color, 
RuleStyle style)
-    throws IFException {
+            throws IFException {
         try {
-            this.borderPainter.drawLine(start, end, width, color, style);
+            this.graphicsPainter.drawLine(start, end, width, color, style);
         } catch (IOException ioe) {
             throw new IFException("I/O error in drawLine()", ioe);
         }
@@ -936,14 +906,14 @@ public class AFPPainter extends Abstract
 
         // register font as necessary
         Map<String, Typeface> fontMetricMap = getFontInfo().getFonts();
-        final AFPFont afpFont = (AFPFont)fontMetricMap.get(fontKey);
+        final AFPFont afpFont = (AFPFont) fontMetricMap.get(fontKey);
         final Font font = getFontInfo().getFontInstance(triplet, fontSize);
         AFPPageFonts pageFonts = getPaintingState().getPageFonts();
         AFPFontAttributes fontAttributes = pageFonts.registerFont(fontKey, 
afpFont, fontSize);
 
         final int fontReference = fontAttributes.getFontReference();
 
-        final int[] coords = unitConv.mpts2units(new float[] {x, y} );
+        final int[] coords = unitConv.mpts2units(new float[] {x, y});
 
         final CharacterSet charSet = afpFont.getCharacterSet(fontSize);
 
@@ -967,7 +937,7 @@ public class AFPPainter extends Abstract
                     builder.absoluteMoveInline(p.x);
 
                     builder.setExtendedTextColor(state.getTextColor());
-                    builder.setCodedFont((byte)fontReference);
+                    builder.setCodedFont((byte) fontReference);
 
                     int l = text.length();
                     int[] dx = IFUtil.convertDPToDX ( dp );
@@ -1106,15 +1076,12 @@ public class AFPPainter extends Abstract
     /** {@inheritDoc} */
     public void clipBackground(Rectangle rect, BorderProps bpsBefore, 
BorderProps bpsAfter,
             BorderProps bpsStart, BorderProps bpsEnd) throws IFException {
-
-      //not supported by AFP
     }
 
     /** {@inheritDoc} */
     public boolean isBackgroundRequired(BorderProps bpsBefore, BorderProps 
bpsAfter,
             BorderProps bpsStart, BorderProps bpsEnd) {
-        return borderPainter.isBackgroundRequired( bpsBefore,  bpsAfter,
-                 bpsStart,  bpsEnd);
+        return borderPainter.isBackgroundRequired(bpsBefore,  bpsAfter, 
bpsStart,  bpsEnd);
     }
 
     /** {@inheritDoc} */

Added: 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/intermediate/ArcToBezierCurveTransformer.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/intermediate/ArcToBezierCurveTransformer.java?rev=1395490&view=auto
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/intermediate/ArcToBezierCurveTransformer.java
 (added)
+++ 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/intermediate/ArcToBezierCurveTransformer.java
 Mon Oct  8 09:24:03 2012
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.intermediate;
+
+import java.io.IOException;
+
+public class ArcToBezierCurveTransformer {
+
+    private final BezierCurvePainter bezierCurvePainter;
+
+    public ArcToBezierCurveTransformer(BezierCurvePainter bezierCurvePainter) {
+        this.bezierCurvePainter = bezierCurvePainter;
+    }
+
+    /**
+     * Draws an arc on the ellipse centered at (cx, cy) with width width and 
height height
+     * from start angle startAngle (with respect to the x-axis 
counter-clockwise)
+     * to the end angle endAngle.
+     * The ellipses major axis are assumed to coincide with the coordinate 
axis.
+     * The current position MUST coincide with the starting position on the 
ellipse.
+     * @param startAngle the start angle
+     * @param endAngle the end angle
+     * @param cx the x coordinate of the ellipse center
+     * @param cy the y coordinate of the ellipse center
+     * @param width the extent of the ellipse in the x direction
+     * @param height the extent of the ellipse in the y direction
+     * @throws IOException if an I/O error occurs
+     */
+    public void arcTo(final double startAngle, final double endAngle, final 
int cx, final int cy,
+            final int width, final int height) throws IOException {
+
+        //  Implementation follows 
http://www.spaceroots.org/documents/ellipse/ -
+        //      Drawing an elliptical arc using polylines, quadratic or cubic 
Bézier curves
+        //      L. Maisonobe, July 21, 2003
+
+        //  Scaling the coordinate system to represent the ellipse as a circle:
+        final double etaStart = Math.atan(Math.tan(startAngle) * width / 
height)
+                + quadrant(startAngle);
+        final double etaEnd = Math.atan(Math.tan(endAngle) * width / height)
+                + quadrant(endAngle);
+
+        final double sinStart = Math.sin(etaStart);
+        final double cosStart = Math.cos(etaStart);
+        final double sinEnd = Math.sin(etaEnd);
+        final double cosEnd = Math.cos(etaEnd);
+
+        final double p0x = cx + cosStart * width;
+        final double p0y = cy + sinStart * height;
+        final double p3x = cx + cosEnd * width;
+        final double p3y = cy + sinEnd * height;
+
+        double etaDiff = Math.abs(etaEnd - etaStart);
+        double tan = Math.tan((etaDiff) / 2d);
+        final double alpha = Math.sin(etaDiff) * (Math.sqrt(4d + 3d * tan * 
tan) - 1d) / 3d;
+
+        int order = etaEnd > etaStart ? 1 : -1;
+
+        // p1 = p0 + alpha*(-sin(startAngle), cos(startAngle))
+        final double p1x = p0x - alpha *  sinStart * width * order;
+        final double p1y = p0y + alpha *  cosStart * height * order;
+
+        // p1 = p3 + alpha*(sin(endAngle), -cos(endAngle))
+        final double p2x = p3x + alpha *  sinEnd * width * order;
+        final double p2y = p3y - alpha * cosEnd * height * order;
+
+        //Draw the curve in original coordinate system
+        bezierCurvePainter.cubicBezierTo((int) p1x, (int) p1y, (int) p2x, 
(int) p2y, (int) p3x, (int) p3y);
+    }
+
+    private double quadrant(double angle) {
+        if (angle <= Math.PI) {
+            if (angle <=  Math.PI / 2d) {
+                return 0;
+            } else {
+                return Math.PI;
+            }
+        } else {
+            if (angle > Math.PI * 3d / 2d) {
+                return 2d * Math.PI;
+            } else {
+                return Math.PI;
+            }
+        }
+    }
+}

Added: 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/intermediate/BezierCurvePainter.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/intermediate/BezierCurvePainter.java?rev=1395490&view=auto
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/intermediate/BezierCurvePainter.java
 (added)
+++ 
xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/render/intermediate/BezierCurvePainter.java
 Mon Oct  8 09:24:03 2012
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.intermediate;
+
+import java.io.IOException;
+
+public interface BezierCurvePainter {
+    /**
+     * Draw a cubic bezier from current position to (p3x, p3y) using the 
control points
+     * (p1x, p1y) and (p2x, p2y)
+     * @param p1x x coordinate of the first control point
+     * @param p1y y coordinate of the first control point
+     * @param p2x x coordinate of the second control point
+     * @param p2y y coordinate of the second control point
+     * @param p3x x coordinate of the end point
+     * @param p3y y coordinate of the end point
+     * @throws IOException if an I/O error occurs
+     */
+    void cubicBezierTo(int p1x, int p1y, int p2x, int p2y, int p3x, int p3y) 
throws IOException;
+}
\ No newline at end of file



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

Reply via email to