Author: ssteiner
Date: Mon Jul 24 11:49:40 2017
New Revision: 1802793

URL: http://svn.apache.org/viewvc?rev=1802793&view=rev
Log:
FOP-2730: Invalid output for empty block and border-left-style=dashed

Added:
    
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphicsPainterTestCase.java
   (with props)
Modified:
    
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPBorderPainter.java
    
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFGraphicsPainter.java
    
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphicsPainter.java
    
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java
    
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFGraphicsPainterTestCase.java

Modified: 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPBorderPainter.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPBorderPainter.java?rev=1802793&r1=1802792&r2=1802793&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPBorderPainter.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPBorderPainter.java
 Mon Jul 24 11:49:40 2017
@@ -138,7 +138,7 @@ public class AFPBorderPainter extends Ab
                 lineDataInfo.setY2(lineDataInfo.getY1());
                 int ex2 = Math.round(x2);
                 int spaceWidth = (int) 
(BorderPainter.DASHED_BORDER_SPACE_RATIO * dashWidth);
-                while (lineDataInfo.getX2() <= ex2) {
+                while (lineDataInfo.getX2() <= ex2 && dashWidth > 0) {
                     dataStream.createLine(lineDataInfo);
                     lineDataInfo.setX1(lineDataInfo.getX2() + spaceWidth);
                     lineDataInfo.setX2(lineDataInfo.getX1() + dashWidth);
@@ -149,7 +149,7 @@ public class AFPBorderPainter extends Ab
                 lineDataInfo.setY2(lineDataInfo.getY1() + dashWidth);
                 int ey2 = Math.round(y2);
                 int spaceWidth = (int) 
(BorderPainter.DASHED_BORDER_SPACE_RATIO * dashWidth);
-                while (lineDataInfo.getY2() <= ey2) {
+                while (lineDataInfo.getY2() <= ey2 && dashWidth > 0) {
                     dataStream.createLine(lineDataInfo);
                     lineDataInfo.setY1(lineDataInfo.getY2() + spaceWidth);
                     lineDataInfo.setY2(lineDataInfo.getY1() + dashWidth);

Modified: 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFGraphicsPainter.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFGraphicsPainter.java?rev=1802793&r1=1802792&r2=1802793&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFGraphicsPainter.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFGraphicsPainter.java
 Mon Jul 24 11:49:40 2017
@@ -66,16 +66,20 @@ public class PDFGraphicsPainter implemen
             generator.setColor(col);
             if (horz) {
                 float dashedWidth = BorderPainter.dashWidthCalculator(w, h);
-                float ym = y1 + (h / 2);
-                generator.setDashLine(dashedWidth, dashedWidth * 
BorderPainter.DASHED_BORDER_SPACE_RATIO)
-                        .setLineWidth(h)
-                        .strokeLine(x1, ym, x2, ym);
+                if (dashedWidth != 0) {
+                    float ym = y1 + (h / 2);
+                    generator.setDashLine(dashedWidth, dashedWidth * 
BorderPainter.DASHED_BORDER_SPACE_RATIO)
+                            .setLineWidth(h)
+                            .strokeLine(x1, ym, x2, ym);
+                }
             } else {
                 float dashedWidth = BorderPainter.dashWidthCalculator(h, w);
-                float xm = x1 + (w / 2);
-                generator.setDashLine(dashedWidth, dashedWidth * 
BorderPainter.DASHED_BORDER_SPACE_RATIO)
-                        .setLineWidth(w)
-                        .strokeLine(xm, y1, xm, y2);
+                if (dashedWidth != 0) {
+                    float xm = x1 + (w / 2);
+                    generator.setDashLine(dashedWidth, dashedWidth * 
BorderPainter.DASHED_BORDER_SPACE_RATIO)
+                            .setLineWidth(w)
+                            .strokeLine(xm, y1, xm, y2);
+                }
             }
             break;
         case Constants.EN_DOTTED:

Modified: 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphicsPainter.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphicsPainter.java?rev=1802793&r1=1802792&r2=1802793&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphicsPainter.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphicsPainter.java
 Mon Jul 24 11:49:40 2017
@@ -89,16 +89,20 @@ public class PSGraphicsPainter implement
             gen.useColor(col);
             if (horz) {
                 float dashWidth = BorderPainter.dashWidthCalculator(w, h);
-                gen.useDash("[" + dashWidth + " " + 
BorderPainter.DASHED_BORDER_SPACE_RATIO
-                        * dashWidth + "] 0");
+                if (dashWidth != 0) {
+                    gen.useDash("[" + dashWidth + " " + 
BorderPainter.DASHED_BORDER_SPACE_RATIO
+                            * dashWidth + "] 0");
+                }
                 gen.useLineCap(0);
                 gen.useLineWidth(h);
                 float ym = y1 + (h / 2);
                 drawLine(gen, x1, ym, x2, ym);
             } else {
                 float dashWidth = BorderPainter.dashWidthCalculator(h, w);
-                gen.useDash("[" + dashWidth + " " + 
BorderPainter.DASHED_BORDER_SPACE_RATIO
-                        * dashWidth + "] 0");
+                if (dashWidth != 0) {
+                    gen.useDash("[" + dashWidth + " " + 
BorderPainter.DASHED_BORDER_SPACE_RATIO
+                            * dashWidth + "] 0");
+                }
                 gen.useLineCap(0);
                 gen.useLineWidth(w);
                 float xm = x1 + (w / 2);

Modified: 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java?rev=1802793&r1=1802792&r2=1802793&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java
 Mon Jul 24 11:49:40 2017
@@ -26,6 +26,7 @@ import java.io.OutputStream;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import org.apache.fop.afp.AFPBorderPainter;
@@ -74,4 +75,12 @@ public class AFPBorderPainterTestCase {
             line = lineDataInfo;
         }
     }
+
+    @Test
+    public void testDrawBorderLineDashed2() throws Exception {
+        BorderPaintingInfo paintInfo = new BorderPaintingInfo(0, 0, 0, 0, 
false, Constants.EN_DASHED, Color.BLACK);
+        borderPainter.paint(paintInfo);
+        ds.endDocument();
+        assertNull(line);
+    }
 }

Modified: 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFGraphicsPainterTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFGraphicsPainterTestCase.java?rev=1802793&r1=1802792&r2=1802793&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFGraphicsPainterTestCase.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFGraphicsPainterTestCase.java
 Mon Jul 24 11:49:40 2017
@@ -24,10 +24,13 @@ import java.io.IOException;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.endsWith;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 
+import org.apache.fop.fo.Constants;
 import org.apache.fop.pdf.PDFNumber;
 
 public class PDFGraphicsPainterTestCase {
@@ -127,6 +130,12 @@ public class PDFGraphicsPainterTestCase
         verify(generator).add(op("c", args));
     }
 
+    @Test
+    public void testDrawBorderLineDashed() {
+        sut.drawBorderLine(0, 0, 0, 0, true, true, Constants.EN_DASHED, null);
+        verify(generator, never()).add(any(String.class));
+    }
+
     private void testTransformCoordinatesF(float... args) {
         verify(generator).add(opf("cm", args));
     }

Added: 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphicsPainterTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphicsPainterTestCase.java?rev=1802793&view=auto
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphicsPainterTestCase.java
 (added)
+++ 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphicsPainterTestCase.java
 Mon Jul 24 11:49:40 2017
@@ -0,0 +1,41 @@
+/*
+ * 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.ps;
+
+import java.awt.Color;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.xmlgraphics.ps.PSGenerator;
+
+import org.apache.fop.fo.Constants;
+
+public class PSGraphicsPainterTestCase {
+    @Test
+    public void testDrawBorderLineDashed() throws IOException {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        PSGenerator generator = new PSGenerator(bos);
+        PSGraphicsPainter sut = new PSGraphicsPainter(generator);
+        sut.drawBorderLine(0, 0, 0, 0, true, true, Constants.EN_DASHED, 
Color.BLACK);
+        Assert.assertEquals(bos.toString(), "0 LW\n0 0 M 0 0 L S N\n");
+    }
+}

Propchange: 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphicsPainterTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native



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

Reply via email to