Browse Source

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
tags/fop-2_3
Simon Steiner 6 years ago
parent
commit
95ca678325

+ 2
- 2
fop-core/src/main/java/org/apache/fop/afp/AFPBorderPainter.java View File

@@ -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);

+ 12
- 8
fop-core/src/main/java/org/apache/fop/render/pdf/PDFGraphicsPainter.java View File

@@ -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:

+ 8
- 4
fop-core/src/main/java/org/apache/fop/render/ps/PSGraphicsPainter.java View File

@@ -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);

+ 9
- 0
fop-core/src/test/java/org/apache/fop/render/afp/AFPBorderPainterTestCase.java View File

@@ -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);
}
}

+ 9
- 0
fop-core/src/test/java/org/apache/fop/render/pdf/PDFGraphicsPainterTestCase.java View File

@@ -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));
}

+ 41
- 0
fop-core/src/test/java/org/apache/fop/render/ps/PSGraphicsPainterTestCase.java View File

@@ -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");
}
}

Loading…
Cancel
Save