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 cb...@apache.org on 2013/03/05 11:57:28 UTC

svn commit: r1452734 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/afp/ src/java/org/apache/fop/render/intermediate/ test/java/org/apache/fop/render/afp/ test/java/org/apache/fop/render/pdf/ test/java/org/apache/fop/render/ps/

Author: cbowditch
Date: Tue Mar  5 10:57:28 2013
New Revision: 1452734

URL: http://svn.apache.org/r1452734
Log:
FOP-2215; Thin dashed border look like dots
Submitted by Simon Steiner (ssteiner.at.thunderhead.com)

Added:
    xmlgraphics/fop/trunk/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPBorderPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/BorderPainter.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFBorderPainterTestCase.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSBorderPainterTestCase.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPBorderPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPBorderPainter.java?rev=1452734&r1=1452733&r2=1452734&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPBorderPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPBorderPainter.java Tue Mar  5 10:57:28 2013
@@ -128,23 +128,23 @@ public class AFPBorderPainter extends Ab
             break;
         case Constants.EN_DASHED:
             if (borderPaintInfo.isHorizontal()) {
-                int dashWidth = (int) (BorderPainter.dashWidthCalculator(x2 - x1, thickness));
+                int dashWidth = (int) unitConv.pt2units(BorderPainter.dashWidthCalculator(w, h));
                 lineDataInfo.setX2 ( lineDataInfo.getX1() + dashWidth );
                 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) {
                     dataStream.createLine(lineDataInfo);
                     lineDataInfo.setX1 ( lineDataInfo.getX2() + spaceWidth );
                     lineDataInfo.setX2 ( lineDataInfo.getX1() + dashWidth );
                 }
             } else {
-                int dashWidth = (int) BorderPainter.dashWidthCalculator(y2 - y1, thickness);
+                int dashWidth = (int) unitConv.pt2units(BorderPainter.dashWidthCalculator(h, w));
                 lineDataInfo.setX2 ( lineDataInfo.getX1() );
                 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) {
                     dataStream.createLine(lineDataInfo);
                     lineDataInfo.setY1 ( lineDataInfo.getY2() + spaceWidth );
                     lineDataInfo.setY2 ( lineDataInfo.getY1() + dashWidth );

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/BorderPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/BorderPainter.java?rev=1452734&r1=1452733&r2=1452734&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/BorderPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/BorderPainter.java Tue Mar  5 10:57:28 2013
@@ -289,6 +289,9 @@ public class BorderPainter {
      */
     public static float dashWidthCalculator(float borderLength, float borderWidth) {
         float dashWidth = DASHED_BORDER_LENGTH_FACTOR * borderWidth;
+        if (borderWidth < 3) {
+            dashWidth = (DASHED_BORDER_LENGTH_FACTOR * 3) * borderWidth;
+        }
         int period = (int) ((borderLength - dashWidth) / dashWidth / (1.0f + DASHED_BORDER_SPACE_RATIO));
         period = period < 0 ? 0 : period;
         return borderLength / (period * (1.0f + DASHED_BORDER_SPACE_RATIO) + 1.0f);

Added: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java?rev=1452734&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java (added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java Tue Mar  5 10:57:28 2013
@@ -0,0 +1,76 @@
+/*
+ * 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.afp;
+
+import static org.junit.Assert.assertTrue;
+
+import java.awt.Color;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+
+import org.apache.fop.afp.AFPBorderPainter;
+import org.apache.fop.afp.AFPLineDataInfo;
+import org.apache.fop.afp.AFPPaintingState;
+import org.apache.fop.afp.BorderPaintingInfo;
+import org.apache.fop.afp.DataStream;
+import org.apache.fop.afp.Factory;
+import org.apache.fop.fo.Constants;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AFPBorderPainterTestCase {
+    private ByteArrayOutputStream outStream;
+    private AFPBorderPainter borderPainter;
+    private DataStream ds;
+    private AFPLineDataInfo line;
+
+    @Before
+    public void setUp() throws Exception {
+        outStream = new ByteArrayOutputStream();
+        ds = new MyDataStream(new Factory(), null, outStream);
+        ds.startDocument();
+        ds.startPage(1000, 1000, 90, 72, 72);
+        borderPainter = new AFPBorderPainter(new AFPPaintingState(), ds);
+    }
+
+    /**
+     * This test will fail if either of the below statements isn't true:
+     * org.apache.fop.render.intermediate.BorderPainter.DASHED_BORDER_SPACE_RATIO = 0.5f:q
+     * org.apache.fop.render.intermediate.BorderPainter.DASHED_BORDER_LENGTH_FACTOR = 4.0f.
+     */
+    @Test
+    public void testDrawBorderLine() throws Exception {
+        BorderPaintingInfo paintInfo = new BorderPaintingInfo(0f, 0f, 1000f, 1000f, true,
+                Constants.EN_DASHED, Color.BLACK);
+        borderPainter.paint(paintInfo);
+        ds.endDocument();
+        assertTrue(line.getX1() == 4999 && line.getX2() == 8332);
+    }
+    
+    class MyDataStream extends DataStream {
+        public MyDataStream(Factory factory, AFPPaintingState paintingState, OutputStream outputStream) {
+            super(factory, paintingState, outputStream);
+        }
+        
+        public void createLine(AFPLineDataInfo lineDataInfo) {
+            line = lineDataInfo;
+        }
+    }
+}

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFBorderPainterTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFBorderPainterTestCase.java?rev=1452734&r1=1452733&r2=1452734&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFBorderPainterTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFBorderPainterTestCase.java Tue Mar  5 10:57:28 2013
@@ -56,7 +56,7 @@ public class PDFBorderPainterTestCase {
         generator.flushPDFDoc();
         OutputStream outStream = new ByteArrayOutputStream();
         outStream = generator.getStream().getBufferOutputStream();
-        assertTrue(((ByteArrayOutputStream) outStream).toString().contains("[2.105263 1.052632] 0 d 1 w"));
+        assertTrue(((ByteArrayOutputStream) outStream).toString().contains("[7.272727 3.636364] 0 d 1 w"));
     }
 
     public void tearDown() {

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSBorderPainterTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSBorderPainterTestCase.java?rev=1452734&r1=1452733&r2=1452734&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSBorderPainterTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSBorderPainterTestCase.java Tue Mar  5 10:57:28 2013
@@ -53,7 +53,7 @@ public class PSBorderPainterTestCase {
     public void testDrawBorderLine() throws Exception {
         borderPainter.drawBorderLine(0, 0, 40000, 1000, true, true,
                 Constants.EN_DASHED, Color.BLACK);
-        assertTrue(outStream.toString().contains("[2.1052632 1.0526316] 0 setdash"));
+        assertTrue(outStream.toString().contains("[7.2727275 3.6363637] 0 setdash"));
     }
 
     public void tearDown() {



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