From 3f8838ef97cc1fc9799be4d1be2ac3a86dae596d Mon Sep 17 00:00:00 2001 From: Peter Hancock Date: Mon, 22 Oct 2012 14:06:43 +0000 Subject: [PATCH] Support for relative border-*-*-radius fox properties Plus cleanup git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_RoundedCorners@1400883 13f79535-47bb-0310-9956-ffa450edef68 --- examples/fo/advanced/rounded-corners.fo | 28 +++---- src/java/org/apache/fop/fo/Constants.java | 26 +++--- .../org/apache/fop/fo/FOPropertyMapping.java | 79 +++++++++++++------ .../extensions/ExtensionElementMapping.java | 7 +- .../BoxCornerPropShorthandParser.java | 2 +- .../CommonBorderPaddingBackground.java | 23 +++--- .../org/apache/fop/layoutmgr/TraitSetter.java | 16 ++-- .../render/intermediate/BorderPainter.java | 15 ++-- .../fop/render/pdf/PDFPainterTestCase.java | 45 +++-------- .../fop/render/ps/PSPainterTestCase.java | 18 +---- 10 files changed, 134 insertions(+), 125 deletions(-) diff --git a/examples/fo/advanced/rounded-corners.fo b/examples/fo/advanced/rounded-corners.fo index d8df05922..7b275ae17 100644 --- a/examples/fo/advanced/rounded-corners.fo +++ b/examples/fo/advanced/rounded-corners.fo @@ -12,7 +12,7 @@ Examples using Rounded Corners - The "border-radius" property in the http://xmlgraphics.apache.org/fop/extensions namespace is a shorthand property for setting appropriate values for "border-*-radius-*" (see below), and is used to specify round corners on block areas. The property takes one or two values: + The "border-radius" property in the http://xmlgraphics.apache.org/fop/extensions namespace is a shorthand property for setting appropriate values for "border-*-radius" (see below), and is used to specify round corners on block areas. The property takes one or two values: Circular corners are specified when 'border-radius' is set to a single value. This value is the radius of the outer quadrant of the corner. @@ -21,20 +21,20 @@ - To specify the corner radii of two adjacent border segments, A and B, the properties border-A-radius-B and border-B-radius-A are set. The value border-A-radius-B is the radius of the A-B corner in the direction perpendicular to segment A. - + The radii for a specific corner can be specified for each CORNER (in 'before-start', 'before-end', 'after-start', 'after-end') with the property "border-CORNER-radius". These properties + have the same interpretation as the "border-radius" property. - + - + @@ -53,14 +53,14 @@ - + I - + II @@ -76,39 +76,39 @@ - The border segments join at a line that coincides with the one that interesects the inner and outer corners of the equivalent rectangular corner. This is clearly demonstrated below where rounded borders are overlayed on top of rectangular borders. + The border segments join at a line that coincides with the one that intersects the inner and outer corners of the equivalent rectangular corner. This is clearly demonstrated below where rounded borders are overlayed on top of rectangular borders. - + - + - + - + - + - + diff --git a/src/java/org/apache/fop/fo/Constants.java b/src/java/org/apache/fop/fo/Constants.java index 1a2425af5..7a83a12f8 100644 --- a/src/java/org/apache/fop/fo/Constants.java +++ b/src/java/org/apache/fop/fo/Constants.java @@ -781,37 +781,43 @@ public interface Constants { /** Property constant FOP proprietary*/ int PR_X_BORDER_BEFORE_RADIUS_START = 276; - /** Property constant FOP proprietary*/ int PR_X_BORDER_BEFORE_RADIUS_END = 277; - /** Property constant FOP proprietary*/ int PR_X_BORDER_AFTER_RADIUS_START = 278; /** Property constant FOP proprietary*/ int PR_X_BORDER_AFTER_RADIUS_END = 279; - /** Property constant FOP proprietary*/ - int PR_X_BORDER_START_RADIUS_START = 280; + int PR_X_BORDER_START_RADIUS_BEFORE = 280; /** Property constant FOP proprietary*/ - int PR_X_BORDER_START_RADIUS_END = 281; + int PR_X_BORDER_START_RADIUS_AFTER = 281; /** Property constant FOP proprietary*/ - int PR_X_BORDER_END_RADIUS_START = 282; + int PR_X_BORDER_END_RADIUS_BEFORE = 282; /** Property constant FOP proprietary*/ - int PR_X_BORDER_END_RADIUS_END = 283; + int PR_X_BORDER_END_RADIUS_AFTER = 283; /** Property constant FOP proprietary*/ int PR_X_BORDER_RADIUS = 284; + /** Property constant FOP proprietary*/ + int PR_X_BORDER_BEFORE_START_RADIUS = 285; + /** Property constant FOP proprietary*/ + int PR_X_BORDER_BEFORE_END_RADIUS = 286; + /** Property constant FOP proprietary*/ + int PR_X_BORDER_AFTER_START_RADIUS = 287; + /** Property constant FOP proprietary*/ + int PR_X_BORDER_AFTER_END_RADIUS = 288; + /** * Property constant - FOP proprietary extension (see NumberConverter) used * to perform additional control over number conversion when generating page * numbers. */ - int PR_X_NUMBER_CONVERSION_FEATURES = 285; + int PR_X_NUMBER_CONVERSION_FEATURES = 289; /** Scope for table header */ - int PR_X_HEADER_COLUMN = 286; + int PR_X_HEADER_COLUMN = 290; /** Number of property constants defined */ - int PROPERTY_COUNT = 286; + int PROPERTY_COUNT = 290; // compound property constants diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java index 08afbcd52..3ae81c62a 100644 --- a/src/java/org/apache/fop/fo/FOPropertyMapping.java +++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java @@ -206,12 +206,11 @@ public final class FOPropertyMapping implements Constants { genericBorderStyle.setDefault("none"); // GenericCondCornerRadius - genericCondCornerRadius = new CondLengthProperty.Maker(0); + genericCondCornerRadius = new CondLengthProperty.Maker(0); genericCondCornerRadius.useGeneric(genericCondLength); genericCondCornerRadius.setInherited(false); genericCondCornerRadius.getSubpropMaker(CP_LENGTH).setDefault("0pt"); genericCondCornerRadius.setPercentBase(LengthBase.CONTAINING_BLOCK_HEIGHT); - genericCondCornerRadius.addShorthand(generics[PR_X_BORDER_RADIUS]); // GenericBreak genericBreak = new EnumProperty.Maker(0); @@ -2617,53 +2616,59 @@ public final class FOPropertyMapping implements Constants { // fox:border-*-radius-* - - // border-before-radius-start - m = new CondLengthProperty.Maker(PR_X_BORDER_BEFORE_RADIUS_START); + m = new CondLengthProperty.Maker(PR_X_BORDER_BEFORE_RADIUS_START); m.useGeneric(genericCondCornerRadius); + m.addShorthand(generics[PR_X_BORDER_BEFORE_START_RADIUS]); + m.addShorthand(generics[PR_X_BORDER_RADIUS]); m.getSubpropMaker(CP_CONDITIONALITY).setDefault("discard"); - addPropertyMaker("fox:border-before-radius-start", m); - // border-before-radius-end - m = new CondLengthProperty.Maker(PR_X_BORDER_BEFORE_RADIUS_END); + m = new CondLengthProperty.Maker(PR_X_BORDER_BEFORE_RADIUS_END); m.useGeneric(genericCondCornerRadius); + m.addShorthand(generics[PR_X_BORDER_BEFORE_END_RADIUS]); + m.addShorthand(generics[PR_X_BORDER_RADIUS]); m.getSubpropMaker(CP_CONDITIONALITY).setDefault("discard"); addPropertyMaker("fox:border-before-radius-end", m); - // border-after-radius-start - m = new CondLengthProperty.Maker(PR_X_BORDER_AFTER_RADIUS_START); + m = new CondLengthProperty.Maker(PR_X_BORDER_AFTER_RADIUS_START); m.useGeneric(genericCondCornerRadius); + m.addShorthand(generics[PR_X_BORDER_AFTER_START_RADIUS]); + m.addShorthand(generics[PR_X_BORDER_RADIUS]); m.getSubpropMaker(CP_CONDITIONALITY).setDefault("discard"); addPropertyMaker("fox:border-after-radius-start", m); - // border-after-radius-end - m = new CondLengthProperty.Maker(PR_X_BORDER_AFTER_RADIUS_END); + m = new CondLengthProperty.Maker(PR_X_BORDER_AFTER_RADIUS_END); m.useGeneric(genericCondCornerRadius); + m.addShorthand(generics[PR_X_BORDER_AFTER_END_RADIUS]); + m.addShorthand(generics[PR_X_BORDER_RADIUS]); m.getSubpropMaker(CP_CONDITIONALITY).setDefault("discard"); addPropertyMaker("fox:border-after-radius-end", m); - // border-start-radius-before - m = new CondLengthProperty.Maker(PR_X_BORDER_START_RADIUS_START); + m = new CondLengthProperty.Maker(PR_X_BORDER_START_RADIUS_BEFORE); m.useGeneric(genericCondCornerRadius); + m.addShorthand(generics[PR_X_BORDER_BEFORE_START_RADIUS]); + m.addShorthand(generics[PR_X_BORDER_RADIUS]); m.getSubpropMaker(CP_CONDITIONALITY).setDefault("discard"); addPropertyMaker("fox:border-start-radius-before", m); - // border-start-radius-after - m = new CondLengthProperty.Maker(PR_X_BORDER_START_RADIUS_END); + m = new CondLengthProperty.Maker(PR_X_BORDER_START_RADIUS_AFTER); m.useGeneric(genericCondCornerRadius); + m.addShorthand(generics[PR_X_BORDER_AFTER_START_RADIUS]); + m.addShorthand(generics[PR_X_BORDER_RADIUS]); m.getSubpropMaker(CP_CONDITIONALITY).setDefault("discard"); addPropertyMaker("fox:border-start-radius-after", m); - // border-end-radius-before - m = new CondLengthProperty.Maker(PR_X_BORDER_END_RADIUS_START); + m = new CondLengthProperty.Maker(PR_X_BORDER_END_RADIUS_BEFORE); m.useGeneric(genericCondCornerRadius); + m.addShorthand(generics[PR_X_BORDER_BEFORE_END_RADIUS]); + m.addShorthand(generics[PR_X_BORDER_RADIUS]); m.getSubpropMaker(CP_CONDITIONALITY).setDefault("discard"); addPropertyMaker("fox:border-end-radius-before", m); - // border-end-radius-after - m = new CondLengthProperty.Maker(PR_X_BORDER_END_RADIUS_END); + m = new CondLengthProperty.Maker(PR_X_BORDER_END_RADIUS_AFTER); m.useGeneric(genericCondCornerRadius); + m.addShorthand(generics[PR_X_BORDER_AFTER_END_RADIUS]); + m.addShorthand(generics[PR_X_BORDER_RADIUS]); m.getSubpropMaker(CP_CONDITIONALITY).setDefault("discard"); addPropertyMaker("fox:border-end-radius-after", m); @@ -2793,14 +2798,14 @@ public final class FOPropertyMapping implements Constants { addPropertyMaker("border-right", m); // border-style - m = new ListProperty.Maker(PR_BORDER_STYLE); + m = new ListProperty.Maker(PR_BORDER_STYLE); m.setInherited(false); m.setDefault(""); m.setDatatypeParser(new BoxPropShorthandParser()); addPropertyMaker("border-style", m); // border-spacing - m = new ListProperty.Maker(PR_BORDER_SPACING); + m = new ListProperty.Maker(PR_BORDER_SPACING); m.setInherited(true); m.setDefault("0pt"); m.setDatatypeParser(new BorderSpacingShorthandParser()); @@ -2821,12 +2826,40 @@ public final class FOPropertyMapping implements Constants { addPropertyMaker("border-width", m); // fox:border-radius - m = new ListProperty.Maker(PR_X_BORDER_RADIUS); + m = new ListProperty.Maker(PR_X_BORDER_RADIUS); m.setInherited(false); m.setDatatypeParser(new BoxCornerPropShorthandParser()); m.setPercentBase(LengthBase.CONTAINING_BLOCK_WIDTH); addPropertyMaker("fox:border-radius", m); + // fox:border-before-start-radius + m = new ListProperty.Maker(PR_X_BORDER_BEFORE_START_RADIUS); + m.setInherited(false); + m.setDatatypeParser(new BoxCornerPropShorthandParser()); + m.setPercentBase(LengthBase.CONTAINING_BLOCK_WIDTH); + addPropertyMaker("fox:border-before-start-radius", m); + + // fox:border-before-end-radius + m = new ListProperty.Maker(PR_X_BORDER_BEFORE_END_RADIUS); + m.setInherited(false); + m.setDatatypeParser(new BoxCornerPropShorthandParser()); + m.setPercentBase(LengthBase.CONTAINING_BLOCK_WIDTH); + addPropertyMaker("fox:border-before-end-radius", m); + + // fox:border-after-start-radius + m = new ListProperty.Maker(PR_X_BORDER_AFTER_START_RADIUS); + m.setInherited(false); + m.setDatatypeParser(new BoxCornerPropShorthandParser()); + m.setPercentBase(LengthBase.CONTAINING_BLOCK_WIDTH); + addPropertyMaker("fox:border-after-start-radius", m); + + // fox:border-after-end-radius + m = new ListProperty.Maker(PR_X_BORDER_AFTER_END_RADIUS); + m.setInherited(false); + m.setDatatypeParser(new BoxCornerPropShorthandParser()); + m.setPercentBase(LengthBase.CONTAINING_BLOCK_WIDTH); + addPropertyMaker("fox:border-after-end-radius", m); + // cue m = new ToBeImplementedProperty.Maker(PR_CUE); m.setInherited(false); diff --git a/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java b/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java index 076691cb4..09b47f02a 100644 --- a/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java +++ b/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java @@ -40,8 +40,7 @@ public class ExtensionElementMapping extends ElementMapping { /** The standard XML prefix for elements and attributes in this namespace. */ public static final String STANDARD_PREFIX = "fox"; - private static final Set PROPERTY_ATTRIBUTES - = new java.util.HashSet(); + private static final Set PROPERTY_ATTRIBUTES = new java.util.HashSet(); static { //These are FOP's standard extension properties (fox:*) @@ -63,6 +62,10 @@ public class ExtensionElementMapping extends ElementMapping { PROPERTY_ATTRIBUTES.add("border-end-radius-before"); PROPERTY_ATTRIBUTES.add("border-end-radius-after"); PROPERTY_ATTRIBUTES.add("border-radius"); + PROPERTY_ATTRIBUTES.add("border-before-start-radius"); + PROPERTY_ATTRIBUTES.add("border-before-end-radius"); + PROPERTY_ATTRIBUTES.add("border-after-start-radius"); + PROPERTY_ATTRIBUTES.add("border-after-end-radius"); } /** diff --git a/src/java/org/apache/fop/fo/properties/BoxCornerPropShorthandParser.java b/src/java/org/apache/fop/fo/properties/BoxCornerPropShorthandParser.java index d3e37a7c9..06f198573 100644 --- a/src/java/org/apache/fop/fo/properties/BoxCornerPropShorthandParser.java +++ b/src/java/org/apache/fop/fo/properties/BoxCornerPropShorthandParser.java @@ -39,8 +39,8 @@ public class BoxCornerPropShorthandParser extends GenericShorthandParser { * If 2 value are present the first is the corner radius in the IP direction, * the second in the BP direction. * {@inheritDoc} - * int, Property, PropertyMaker, PropertyList) */ + @Override protected Property convertValueForProperty(int propId, Property property, PropertyMaker maker, diff --git a/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java b/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java index eaf678790..61c7b95cd 100644 --- a/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java +++ b/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java @@ -372,15 +372,15 @@ public class CommonBorderPaddingBackground { Constants.PR_BORDER_START_STYLE, Constants.PR_BORDER_START_WIDTH, Constants.PR_PADDING_START, - Constants.PR_X_BORDER_START_RADIUS_START, - Constants.PR_X_BORDER_START_RADIUS_END); + Constants.PR_X_BORDER_START_RADIUS_BEFORE, + Constants.PR_X_BORDER_START_RADIUS_AFTER); initBorderInfo(pList, END, Constants.PR_BORDER_END_COLOR, Constants.PR_BORDER_END_STYLE, Constants.PR_BORDER_END_WIDTH, Constants.PR_PADDING_END, - Constants.PR_X_BORDER_END_RADIUS_START, - Constants.PR_X_BORDER_END_RADIUS_END); + Constants.PR_X_BORDER_END_RADIUS_BEFORE, + Constants.PR_X_BORDER_END_RADIUS_AFTER); } @@ -452,15 +452,12 @@ public class CommonBorderPaddingBackground { padding[side] = pList.get(paddingProp).getCondLength(); // If style = none, force width to 0, don't get Color (spec 7.7.20) int style = pList.get(styleProp).getEnum(); - // if (style != Constants.EN_NONE) { - FOUserAgent ua = pList.getFObj().getUserAgent(); - setBorderInfo(BorderInfo.getInstance(style, - pList.get(widthProp).getCondLength(), - pList.get(colorProp).getColor(ua), - pList.get(radiusStartProp).getCondLength(), - pList.get(radiusEndProp).getCondLength()), side); - // } - + FOUserAgent ua = pList.getFObj().getUserAgent(); + setBorderInfo(BorderInfo.getInstance(style, + pList.get(widthProp).getCondLength(), + pList.get(colorProp).getColor(ua), + pList.get(radiusStartProp).getCondLength(), + pList.get(radiusEndProp).getCondLength()), side); } diff --git a/src/java/org/apache/fop/layoutmgr/TraitSetter.java b/src/java/org/apache/fop/layoutmgr/TraitSetter.java index b96283a4e..c4aac1d8c 100644 --- a/src/java/org/apache/fop/layoutmgr/TraitSetter.java +++ b/src/java/org/apache/fop/layoutmgr/TraitSetter.java @@ -104,14 +104,16 @@ public final class TraitSetter { */ private static void addBorderTrait(Area area, CommonBorderPaddingBackground bpProps, - boolean bDiscard, int iSide, BorderProps.Mode mode, + + boolean discard, int side, 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) { - area.addTrait(traitCode, new BorderProps(bpProps.getBorderStyle(iSide), iBP, radiusStart, radiusEnd, - bpProps.getBorderColor(iSide), mode)); + int width = bpProps.getBorderWidth(side, discard); + int radiusStart = bpProps.getBorderRadiusStart(side, discard, context); + int radiusEnd = bpProps.getBorderRadiusEnd(side, discard, context); + if (width > 0 || radiusStart > 0 || radiusEnd > 0) { + area.addTrait(traitCode, new BorderProps(bpProps.getBorderStyle(side), width, radiusStart, + radiusEnd, bpProps.getBorderColor(side), mode)); + } } diff --git a/src/java/org/apache/fop/render/intermediate/BorderPainter.java b/src/java/org/apache/fop/render/intermediate/BorderPainter.java index e286590ca..19e30b50f 100644 --- a/src/java/org/apache/fop/render/intermediate/BorderPainter.java +++ b/src/java/org/apache/fop/render/intermediate/BorderPainter.java @@ -30,9 +30,6 @@ import org.apache.fop.traits.BorderProps; */ public class BorderPainter { - /** TODO remove before integration*/ - public static final String ROUNDED_CORNERS = "fop.round-corners"; - // TODO Use a class to model border instead of an array /** Convention index of before top */ protected static final int TOP = 0; @@ -318,10 +315,10 @@ public class BorderPainter { final int ex2 = ex1 - end.getWidth() + end.getClippedWidth(); final int outery = -before.getClippedWidth(); final int innery = outery + before.getWidth(); - final int ellipseSBRadiusX = (int) (cornerCorrectionFactor * start.getRadiusEnd()); - final int ellipseSBRadiusY = (int) (cornerCorrectionFactor * before.getRadiusStart()); - final int ellipseBERadiusX = (int) (cornerCorrectionFactor * end.getRadiusStart()); - final int ellipseBERadiusY = (int) (cornerCorrectionFactor * before.getRadiusEnd()); + final int ellipseSBRadiusX = correctRadius(cornerCorrectionFactor, start.getRadiusEnd()); + final int ellipseSBRadiusY = correctRadius(cornerCorrectionFactor, before.getRadiusStart()); + final int ellipseBERadiusX = correctRadius(cornerCorrectionFactor, end.getRadiusStart()); + final int ellipseBERadiusY = correctRadius(cornerCorrectionFactor, before.getRadiusEnd()); saveGraphicsState(); translateCoordinates(x, y); if (orientation != 0) { @@ -406,6 +403,10 @@ public class BorderPainter { } } + private static int correctRadius(double cornerCorrectionFactor, int radius) { + return (int) (Math.round(cornerCorrectionFactor * radius)); + } + private static BorderSegment borderSegmentForBefore(BorderProps before) { return AbstractBorderSegment.asBorderSegment(before); } diff --git a/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java b/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java index 31f2f5c3b..f431b3ee9 100644 --- a/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java +++ b/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java @@ -24,64 +24,43 @@ import java.awt.Rectangle; import org.junit.Test; -import static org.junit.Assert.fail; +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.fo.Constants; +import org.apache.fop.render.intermediate.IFContext; +import org.apache.fop.traits.BorderProps; + import static org.mockito.Matchers.endsWith; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.fo.Constants; -import org.apache.fop.render.intermediate.IFContext; -import org.apache.fop.traits.BorderProps; - public class PDFPainterTestCase { @Test - public void testDrawBorderRect() { + public void testDrawBorderRect() throws Exception { // the goal of this test is to check that the drawing of rounded corners in PDF calls // PDFGraphicsPaiter.cubicBezierTo(); the check is done by verifying that a " c " command is written // to the PDFContentGenerator - // mock PDFContentGenerator pdfContentGenerator = mock(PDFContentGenerator.class); - // the next line is commented out because the format() method is static and not possible to mock - // when(PDFContentGenerator.format(anyFloat())).thenReturn("20.0"); - // mock FOUserAgent foUserAgent = mock(FOUserAgent.class); when(foUserAgent.isAccessibilityEnabled()).thenReturn(false); - // mock IFContext ifContext = mock(IFContext.class); when(ifContext.getUserAgent()).thenReturn(foUserAgent); - // mock PDFDocumentHandler pdfDocumentHandler = mock(PDFDocumentHandler.class); when(pdfDocumentHandler.getGenerator()).thenReturn(pdfContentGenerator); when(pdfDocumentHandler.getContext()).thenReturn(ifContext); - // mock PDFLogicalStructureHandler pdfLogicalStructureHandler = mock(PDFLogicalStructureHandler.class); - // real, not mock PDFPainter pdfPainter = new PDFPainter(pdfDocumentHandler, pdfLogicalStructureHandler); // build rectangle 200 x 50 (points, which are converted to milipoints) Rectangle rectangle = new Rectangle(0, 0, 200000, 50000); // build border properties: width 4pt, radius 30pt - int style = Constants.EN_SOLID; - BorderProps.Mode mode = BorderProps.Mode.SEPARATE; - Color color = Color.BLACK; - int borderWidth = 4000; - int radiusStart = 30000; - int radiusEnd = 30000; - BorderProps border1 = new BorderProps(style, borderWidth, radiusStart, radiusEnd, color, mode); - BorderProps border2 = new BorderProps(style, borderWidth, radiusStart, radiusEnd, color, mode); - BorderProps border3 = new BorderProps(style, borderWidth, radiusStart, radiusEnd, color, mode); - BorderProps border4 = new BorderProps(style, borderWidth, radiusStart, radiusEnd, color, mode); - try { - pdfPainter.drawBorderRect(rectangle, border1, border2, border3, border4, Color.WHITE); - // since we cannot mock the PDFContentGenerator.format() static method we have to restrict the - // verification to commands that end with " c ". - verify(pdfContentGenerator, times(16)).add(endsWith(" c ")); - } catch (Exception e) { - fail("something broke..."); - } + BorderProps border = new BorderProps(Constants.EN_SOLID, 4000, 30000, 30000, Color.BLACK, + BorderProps.Mode.SEPARATE); + pdfPainter.drawBorderRect(rectangle, border, border, border, border, Color.WHITE); + // since we cannot mock the PDFContentGenerator.format() static method we have to restrict the + // verification to commands that end with " c ". + verify(pdfContentGenerator, times(16)).add(endsWith(" c ")); } } diff --git a/test/java/org/apache/fop/render/ps/PSPainterTestCase.java b/test/java/org/apache/fop/render/ps/PSPainterTestCase.java index 7fac2b584..0a9f552ff 100644 --- a/test/java/org/apache/fop/render/ps/PSPainterTestCase.java +++ b/test/java/org/apache/fop/render/ps/PSPainterTestCase.java @@ -87,32 +87,20 @@ public class PSPainterTestCase { // the goal of this test is to check that the drawing of rounded corners in PS calls // PSGraphicsPaiter.cubicBezierTo(); the check is done by verifying that a curveto command is written // to the PSGenerator - // mock PSGenerator psGenerator = mock(PSGenerator.class); when(psGenerator.formatDouble(anyFloat())).thenReturn("20.0"); // simplify! - // mock PSRenderingUtil psRenderingUtil = mock(PSRenderingUtil.class); - // mock PSDocumentHandler psDocumentHandler = mock(PSDocumentHandler.class); when(psDocumentHandler.getGenerator()).thenReturn(psGenerator); when(psDocumentHandler.getPSUtil()).thenReturn(psRenderingUtil); - // real instance, no mock PSPainter psPainter = new PSPainter(psDocumentHandler); // build rectangle 200 x 50 (points, which are converted to milipoints) Rectangle rectangle = new Rectangle(0, 0, 200000, 50000); // build border properties: width 4pt, radius 30pt - int style = Constants.EN_SOLID; - BorderProps.Mode mode = BorderProps.Mode.SEPARATE; - Color color = Color.BLACK; - int borderWidth = 4000; - int radiusStart = 30000; - int radiusEnd = 30000; - BorderProps border1 = new BorderProps(style, borderWidth, radiusStart, radiusEnd, color, mode); - BorderProps border2 = new BorderProps(style, borderWidth, radiusStart, radiusEnd, color, mode); - BorderProps border3 = new BorderProps(style, borderWidth, radiusStart, radiusEnd, color, mode); - BorderProps border4 = new BorderProps(style, borderWidth, radiusStart, radiusEnd, color, mode); + BorderProps border = new BorderProps(Constants.EN_SOLID, 4000, 30000, 30000, Color.BLACK, + BorderProps.Mode.SEPARATE); try { - psPainter.drawBorderRect(rectangle, border1, border2, border3, border4, Color.WHITE); + psPainter.drawBorderRect(rectangle, border, border, border, border, Color.WHITE); verify(psGenerator, times(16)).writeln("20.0 20.0 20.0 20.0 20.0 20.0 curveto "); } catch (Exception e) { fail("something broke..."); -- 2.39.5