Browse Source

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
tags/fop-2_0
Peter Hancock 11 years ago
parent
commit
3f8838ef97

+ 14
- 14
examples/fo/advanced/rounded-corners.fo View File

@@ -12,7 +12,7 @@
Examples using Rounded Corners
</fo:block>
<fo:block margin="20pt 0 40pt 0">
<fo:block>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:
<fo:block>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:
</fo:block>
<fo:block-container margin="10 20pt 20pt 20pt">
<fo:block border-style="solid" border-width="10" border-color="#00f" fox:border-radius="20pt" padding="20pt" text-align="center" margin-bottom="10pt"> 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.</fo:block>
@@ -21,20 +21,20 @@
</fo:block-container>
</fo:block>
<fo:block margin="20pt 0 40pt 0">
<fo:block>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.
</fo:block>
<fo:block>The radii for a specific corner can be specified for each <fo:inline font-style="italic">CORNER</fo:inline> (in 'before-start', 'before-end', 'after-start', 'after-end') with the property "border-<fo:inline font-style="italic">CORNER</fo:inline>-radius". These properties
have the same interpretation as the "border-radius" property. </fo:block>
<fo:table border-collapse="separate" margin-top="10pt">
<fo:table-column column-width="200pt"/>
<fo:table-column column-width="200pt"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block margin-left="50pt" border-style="solid" border-width="50pt 0 0 50pt" border-color="#00f" fox:border-before-radius-start="100pt" fox:border-start-radius-before="100pt" height="100pt">
<fo:block margin-left="50pt" border-style="solid" border-width="50pt 0 0 50pt" border-color="#00f" fox:border-before-start-radius="100pt" height="100pt">
<fo:block padding="50pt"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block margin-left="50pt" border-style="solid" border-width="50pt 0 0 50pt" border-color="#00f" fox:border-before-radius-start="100pt" fox:border-start-radius-before="200pt" height="100pt">
<fo:block margin-left="50pt" border-style="solid" border-width="50pt 0 0 50pt" border-color="#00f" fox:border-before-start-radius="200pt 100pt" height="100pt">
<fo:block padding="50pt"/>
</fo:block>
</fo:table-cell>
@@ -53,14 +53,14 @@
<fo:table-body>
<fo:table-row>
<fo:table-cell height="100pt">
<fo:block margin-left="50pt" border-style="solid" border-width="70pt 0 0 70pt" border-color="#00f" fox:border-before-radius-start="100pt" fox:border-start-radius-before="100pt" height="100pt">
<fo:block margin-left="50pt" border-style="solid" border-width="70pt 0 0 70pt" border-color="#00f" fox:border-before-start-radius="100pt" height="100pt">
<fo:block padding="50pt" text-align="center">
<fo:inline font-style="italic">I</fo:inline>
</fo:block>
</fo:block>
</fo:table-cell>
<fo:table-cell height="100pt">
<fo:block margin-left="50pt" border-style="solid" border-width="70pt 0 0 70pt" border-color="#00f" fox:border-before-radius-start="50pt" fox:border-start-radius-before="50pt" height="100pt">
<fo:block margin-left="50pt" border-style="solid" border-width="70pt 0 0 70pt" border-color="#00f" fox:border-before-start-radius="50pt" height="100pt">
<fo:block padding="50pt" text-align="center">
<fo:inline font-style="italic">II</fo:inline>
</fo:block>
@@ -76,39 +76,39 @@
<fo:table-body>
<fo:table-row>
<fo:table-cell number-columns-spanned="3">
<fo:block margin-bottom="20pt">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.</fo:block>
<fo:block margin-bottom="20pt">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.</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell border-style="solid" border-width="0" border-before-color="#afa" border-start-color="#aaf" border-before-width="50pt" border-start-width="50pt" height="100pt">
<fo:block margin-top="-50pt" border-style="solid" border-width="0" border-before-color="#0f0" border-start-color="#00f" fox:border-before-radius-start="50pt" fox:border-start-radius-before="50pt" border-before-width="50pt" border-start-width="50pt" height="100pt">
<fo:block margin-top="-50pt" border-style="solid" border-width="0" border-before-color="#0f0" border-start-color="#00f" fox:border-before-start-radius="50pt" border-before-width="50pt" border-start-width="50pt" height="100pt">
<fo:block margin-bottom="100pt"/>
</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" border-width="0" border-before-color="#afa" border-start-color="#aaf" border-before-width="50pt" border-start-width="50pt" height="100pt">
<fo:block margin-top="-50pt" border-style="solid" border-width="0" border-before-color="#0f0" border-start-color="#00f" fox:border-before-radius-start="100pt" fox:border-start-radius-before="100pt" border-before-width="50pt" border-start-width="50pt" height="100pt">
<fo:block margin-top="-50pt" border-style="solid" border-width="0" border-before-color="#0f0" border-start-color="#00f" fox:border-before-start-radius="100pt" border-before-width="50pt" border-start-width="50pt" height="100pt">
<fo:block margin-bottom="100pt"/>
</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" border-width="0" border-before-color="#afa" border-start-color="#aaf" border-before-width="50pt" border-start-width="50pt" height="100pt">
<fo:block margin-top="-50pt" border-style="solid" border-width="0" border-before-color="#0f0" border-start-color="#00f" fox:border-before-radius-start="100pt" fox:border-start-radius-before="150pt" border-before-width="50pt" border-start-width="50pt" height="100pt">
<fo:block margin-top="-50pt" border-style="solid" border-width="0" border-before-color="#0f0" border-start-color="#00f" fox:border-before-start-radius="150pt 100pt" border-before-width="50pt" border-start-width="50pt" height="100pt">
<fo:block margin-bottom="100pt"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell border-style="solid" border-width="0" border-before-color="#afa" border-start-color="#aaf" border-before-width="50pt" border-start-width="100pt" height="100pt">
<fo:block margin-top="-50pt" border-style="solid" border-width="0" border-before-color="#0f0" border-start-color="#00f" fox:border-before-radius-start="50pt" fox:border-start-radius-before="50pt" border-before-width="50pt" border-start-width="100pt" height="100pt">
<fo:block margin-top="-50pt" border-style="solid" border-width="0" border-before-color="#0f0" border-start-color="#00f" fox:border-before-start-radius="50pt" border-before-width="50pt" border-start-width="100pt" height="100pt">
<fo:block margin-bottom="100pt"/>
</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" border-width="0" border-before-color="#afa" border-start-color="#aaf" border-before-width="50pt" border-start-width="100pt" height="100pt">
<fo:block margin-top="-50pt" border-style="solid" border-width="0" border-before-color="#0f0" border-start-color="#00f" fox:border-before-radius-start="100pt" fox:border-start-radius-before="100pt" border-before-width="50pt" border-start-width="100pt" height="100pt">
<fo:block margin-top="-50pt" border-style="solid" border-width="0" border-before-color="#0f0" border-start-color="#00f" fox:border-before-start-radius="100pt" border-before-width="50pt" border-start-width="100pt" height="100pt">
<fo:block margin-bottom="100pt"/>
</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" border-width="0" border-before-color="#afa" border-start-color="#aaf" border-before-width="50pt" border-start-width="100pt" height="100pt">
<fo:block margin-top="-50pt" border-style="solid" border-width="0" border-before-color="#0f0" border-start-color="#00f" fox:border-before-radius-start="100pt" fox:border-start-radius-before="150pt" border-before-width="50pt" border-start-width="100pt" height="100pt">
<fo:block margin-top="-50pt" border-style="solid" border-width="0" border-before-color="#0f0" border-start-color="#00f" fox:border-before-start-radius="150pt 100pt" border-before-width="50pt" border-start-width="100pt" height="100pt">
<fo:block margin-bottom="100pt"/>
</fo:block>
</fo:table-cell>

+ 16
- 10
src/java/org/apache/fop/fo/Constants.java View File

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


+ 56
- 23
src/java/org/apache/fop/fo/FOPropertyMapping.java View File

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

+ 5
- 2
src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java View File

@@ -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<String> PROPERTY_ATTRIBUTES
= new java.util.HashSet<String>();
private static final Set<String> PROPERTY_ATTRIBUTES = new java.util.HashSet<String>();

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

/**

+ 1
- 1
src/java/org/apache/fop/fo/properties/BoxCornerPropShorthandParser.java View File

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

+ 10
- 13
src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java View File

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



+ 9
- 7
src/java/org/apache/fop/layoutmgr/TraitSetter.java View File

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


+ 8
- 7
src/java/org/apache/fop/render/intermediate/BorderPainter.java View File

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

+ 12
- 33
test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java View File

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

}

+ 3
- 15
test/java/org/apache/fop/render/ps/PSPainterTestCase.java View File

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

Loading…
Cancel
Save