From 95ca678325076916fd1c0d20e4b3c0ee447a7587 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Mon, 24 Jul 2017 11:49:40 +0000 Subject: [PATCH] FOP-2730: Invalid output for empty block and border-left-style=dashed git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1802793 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/afp/AFPBorderPainter.java | 4 +- .../fop/render/pdf/PDFGraphicsPainter.java | 20 +++++---- .../fop/render/ps/PSGraphicsPainter.java | 12 ++++-- .../render/afp/AFPBorderPainterTestCase.java | 9 ++++ .../pdf/PDFGraphicsPainterTestCase.java | 9 ++++ .../render/ps/PSGraphicsPainterTestCase.java | 41 +++++++++++++++++++ 6 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 fop-core/src/test/java/org/apache/fop/render/ps/PSGraphicsPainterTestCase.java diff --git a/fop-core/src/main/java/org/apache/fop/afp/AFPBorderPainter.java b/fop-core/src/main/java/org/apache/fop/afp/AFPBorderPainter.java index a10c5ae9a..0408cb23f 100644 --- a/fop-core/src/main/java/org/apache/fop/afp/AFPBorderPainter.java +++ b/fop-core/src/main/java/org/apache/fop/afp/AFPBorderPainter.java @@ -138,7 +138,7 @@ public class AFPBorderPainter extends AbstractAFPPainter { 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 AbstractAFPPainter { 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); diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFGraphicsPainter.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFGraphicsPainter.java index 5e0792696..17d9108f0 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFGraphicsPainter.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFGraphicsPainter.java @@ -66,16 +66,20 @@ public class PDFGraphicsPainter implements GraphicsPainter, BezierCurvePainter { 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: diff --git a/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphicsPainter.java b/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphicsPainter.java index 9152d0937..e3343aef5 100644 --- a/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphicsPainter.java +++ b/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphicsPainter.java @@ -89,16 +89,20 @@ public class PSGraphicsPainter implements GraphicsPainter, BezierCurvePainter { 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); diff --git a/fop-core/src/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java b/fop-core/src/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java index dfe956d90..5354e985d 100644 --- a/fop-core/src/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java @@ -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); + } } diff --git a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFGraphicsPainterTestCase.java b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFGraphicsPainterTestCase.java index 3130a73e7..9b69660df 100644 --- a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFGraphicsPainterTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFGraphicsPainterTestCase.java @@ -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)); } diff --git a/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphicsPainterTestCase.java b/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphicsPainterTestCase.java new file mode 100644 index 000000000..58d309664 --- /dev/null +++ b/fop-core/src/test/java/org/apache/fop/render/ps/PSGraphicsPainterTestCase.java @@ -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"); + } +} -- 2.39.5