Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFSerializer.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFSerializer.java?rev=1401607&r1=1401606&r2=1401607&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFSerializer.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFSerializer.java Wed Oct 24 10:20:17 2012 @@ -519,6 +519,37 @@ implements IFConstants, IFPainter, IFDoc } /** {@inheritDoc} */ + public void clipBackground(Rectangle rect, BorderProps bpsBefore, BorderProps bpsAfter, + BorderProps bpsStart, BorderProps bpsEnd) throws IFException { + try { + AttributesImpl atts = new AttributesImpl(); + addAttribute(atts, "x", Integer.toString(rect.x)); + addAttribute(atts, "y", Integer.toString(rect.y)); + addAttribute(atts, "width", Integer.toString(rect.width)); + addAttribute(atts, "height", Integer.toString(rect.height)); + if (hasRoundedCorners(bpsBefore, bpsAfter, bpsStart, bpsEnd)) { + + if (bpsBefore != null) { + addAttribute(atts, "top", bpsBefore.toString()); + } + if (bpsAfter != null) { + addAttribute(atts, "bottom", bpsAfter.toString()); + } + if (bpsStart != null) { + addAttribute(atts, "left", bpsStart.toString()); + } + if (bpsEnd != null) { + addAttribute(atts, "right", bpsEnd.toString()); + } + } + handler.element(EL_CLIP_RECT, atts); + } catch (SAXException e) { + throw new IFException("SAX error in clipRect()", e); + } + } + + + /** {@inheritDoc} */ public void fillRect(Rectangle rect, Paint fill) throws IFException { if (fill == null) { return; @@ -536,9 +567,38 @@ implements IFConstants, IFPainter, IFDoc } } + //TODO create a class representing all borders should exist + //with query methods like this + private boolean hasRoundedCorners(BorderProps bpsBefore, BorderProps bpsAfter, + BorderProps bpsStart, BorderProps bpsEnd) { + boolean rtn = false; + + if (bpsBefore != null && bpsBefore.getRadiusStart() > 0 + && bpsStart != null && bpsStart.getRadiusStart() > 0) { + rtn = true; + } + + if (bpsBefore != null && bpsBefore.getRadiusEnd() > 0 + && bpsEnd != null && bpsEnd.getRadiusStart() > 0) { + rtn = true; + } + + if (bpsEnd != null && bpsEnd.getRadiusEnd() > 0 + && bpsAfter != null && bpsAfter.getRadiusEnd() > 0) { + rtn = true; + } + + if (bpsAfter != null && bpsAfter.getRadiusStart() > 0 + && bpsStart != null && bpsStart.getRadiusEnd() > 0) { + rtn = true; + } + + return rtn; + } + /** {@inheritDoc} */ public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom, - BorderProps left, BorderProps right) throws IFException { + BorderProps left, BorderProps right, Color innerBackgroundColor) throws IFException { if (top == null && bottom == null && left == null && right == null) { return; } @@ -560,6 +620,12 @@ implements IFConstants, IFPainter, IFDoc if (right != null) { addAttribute(atts, "right", right.toString()); } + + if (innerBackgroundColor != null) { + addAttribute(atts, "inner-background-color", + ColorUtil.colorToString(innerBackgroundColor)); + } + handler.element(EL_BORDER_RECT, atts); } catch (SAXException e) { throw new IFException("SAX error in drawBorderRect()", e); @@ -856,4 +922,10 @@ implements IFConstants, IFPainter, IFDoc throw new IFException("SAX error serializing object", e); } } + + /** {@inheritDoc} */ + public boolean isBackgroundRequired(BorderProps bpsTop, BorderProps bpsBottom, + BorderProps bpsLeft, BorderProps bpsRight) { + return true; + } }
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java?rev=1401607&r1=1401606&r2=1401607&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java Wed Oct 24 10:20:17 2012 @@ -38,6 +38,8 @@ import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontTriplet; import org.apache.fop.render.RenderingContext; import org.apache.fop.render.intermediate.AbstractIFPainter; +import org.apache.fop.render.intermediate.BorderPainter; +import org.apache.fop.render.intermediate.GraphicsPainter; import org.apache.fop.render.intermediate.IFContext; import org.apache.fop.render.intermediate.IFException; import org.apache.fop.render.intermediate.IFState; @@ -58,7 +60,9 @@ public class Java2DPainter extends Abstr /** The font information */ protected FontInfo fontInfo; - private Java2DBorderPainter borderPainter; + private final GraphicsPainter graphicsPainter; + + private final BorderPainter borderPainter; /** The current state, holds a Graphics2D and its context */ protected Java2DGraphicsState g2dState; @@ -92,7 +96,8 @@ public class Java2DPainter extends Abstr } this.fontInfo = fontInfo; this.g2dState = new Java2DGraphicsState(g2d, fontInfo, g2d.getTransform()); - this.borderPainter = new Java2DBorderPainter(this); + graphicsPainter = new Java2DGraphicsPainter(this); + this.borderPainter = new BorderPainter(graphicsPainter); } /** {@inheritDoc} */ @@ -174,6 +179,13 @@ public class Java2DPainter extends Abstr } /** {@inheritDoc} */ + public void clipBackground(Rectangle rect, BorderProps bpsBefore, BorderProps bpsAfter, + BorderProps bpsStart, BorderProps bpsEnd) throws IFException { + // TODO Auto-generated method stub + + } + + /** {@inheritDoc} */ public void fillRect(Rectangle rect, Paint fill) throws IFException { if (fill == null) { return; @@ -188,19 +200,18 @@ public class Java2DPainter extends Abstr public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom, BorderProps left, BorderProps right) throws IFException { if (top != null || bottom != null || left != null || right != null) { - try { - this.borderPainter.drawBorders(rect, top, bottom, left, right); - } catch (IOException e) { - //Won't happen with Java2D - throw new IllegalStateException("Unexpected I/O error"); - } + this.borderPainter.drawBorders(rect, top, bottom, left, right, null); } } /** {@inheritDoc} */ public void drawLine(Point start, Point end, int width, Color color, RuleStyle style) throws IFException { - this.borderPainter.drawLine(start, end, width, color, style); + try { + this.graphicsPainter.drawLine(start, end, width, color, style); + } catch (IOException ioe) { + throw new IFException("Unexpected error drawing line", ioe); + } } /** {@inheritDoc} */ @@ -263,4 +274,6 @@ public class Java2DPainter extends Abstr g2dState.transform(transform); } + + } Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLPainter.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLPainter.java?rev=1401607&r1=1401606&r2=1401607&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLPainter.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLPainter.java Wed Oct 24 10:20:17 2012 @@ -174,6 +174,14 @@ public class PCLPainter extends Abstract } /** {@inheritDoc} */ + public void clipBackground(Rectangle rect, BorderProps bpsBefore, BorderProps bpsAfter, + BorderProps bpsStart, BorderProps bpsEnd) throws IFException { + //PCL cannot clip (only HP GL/2 can) + //If you need clipping support, switch to RenderingMode.BITMAP. + + } + + /** {@inheritDoc} */ public void fillRect(Rectangle rect, Paint fill) throws IFException { if (fill == null) { return; @@ -201,7 +209,7 @@ public class PCLPainter extends Abstract final BorderProps top, final BorderProps bottom, final BorderProps left, final BorderProps right) throws IFException { if (isSpeedOptimized()) { - super.drawBorderRect(rect, top, bottom, left, right); + super.drawBorderRect(rect, top, bottom, left, right, null); return; } if (top != null || bottom != null || left != null || right != null) { @@ -525,4 +533,6 @@ public class PCLPainter extends Abstract gen.setCursorPos(transPoint.getX(), transPoint.getY()); } + + } Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java?rev=1401607&r1=1401606&r2=1401607&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java Wed Oct 24 10:20:17 2012 @@ -43,6 +43,8 @@ import org.apache.fop.pdf.PDFTextUtil; import org.apache.fop.pdf.PDFXObject; import org.apache.fop.render.RenderingContext; import org.apache.fop.render.intermediate.AbstractIFPainter; +import org.apache.fop.render.intermediate.BorderPainter; +import org.apache.fop.render.intermediate.GraphicsPainter; import org.apache.fop.render.intermediate.IFContext; import org.apache.fop.render.intermediate.IFException; import org.apache.fop.render.intermediate.IFState; @@ -61,7 +63,9 @@ public class PDFPainter extends Abstract /** The current content generator */ protected PDFContentGenerator generator; - private final PDFBorderPainter borderPainter; + private final GraphicsPainter graphicsPainter; + + private final BorderPainter borderPainter; private boolean accessEnabled; @@ -114,7 +118,8 @@ public class PDFPainter extends Abstract super(documentHandler); this.logicalStructureHandler = logicalStructureHandler; this.generator = documentHandler.getGenerator(); - this.borderPainter = new PDFBorderPainter(this.generator); + this.graphicsPainter = new PDFGraphicsPainter(this.generator); + this.borderPainter = new BorderPainter(this.graphicsPainter); this.state = IFState.create(); accessEnabled = this.getUserAgent().isAccessibilityEnabled(); languageAvailabilityChecker = accessEnabled @@ -250,6 +255,20 @@ public class PDFPainter extends Abstract } /** {@inheritDoc} */ + public void clipBackground(Rectangle rect, + BorderProps bpsBefore, BorderProps bpsAfter, + BorderProps bpsStart, BorderProps bpsEnd) throws IFException { + + try { + borderPainter.clipBackground(rect, + bpsBefore, bpsAfter, bpsStart, bpsEnd); + } catch (IOException ioe) { + throw new IFException("I/O error while clipping background", ioe); + } + + } + + /** {@inheritDoc} */ public void fillRect(Rectangle rect, Paint fill) throws IFException { if (fill == null) { return; @@ -283,23 +302,26 @@ public class PDFPainter extends Abstract /** {@inheritDoc} */ @Override public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom, - BorderProps left, BorderProps right) throws IFException { + BorderProps left, BorderProps right, Color innerBackgroundColor) throws IFException { if (top != null || bottom != null || left != null || right != null) { generator.endTextObject(); - try { - this.borderPainter.drawBorders(rect, top, bottom, left, right); - } catch (IOException ioe) { - throw new IFException("I/O error while drawing borders", ioe); - } + this.borderPainter.drawBorders(rect, top, bottom, left, right, innerBackgroundColor); } } + + + /** {@inheritDoc} */ @Override public void drawLine(Point start, Point end, int width, Color color, RuleStyle style) throws IFException { generator.endTextObject(); - this.borderPainter.drawLine(start, end, width, color, style); + try { + this.graphicsPainter.drawLine(start, end, width, color, style); + } catch (IOException ioe) { + throw new IFException("Cannot draw line", ioe); + } } private Typeface getTypeface(String fontName) { Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java?rev=1401607&r1=1401606&r2=1401607&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java Wed Oct 24 10:20:17 2012 @@ -48,6 +48,8 @@ import org.apache.fop.fonts.SingleByteFo import org.apache.fop.fonts.Typeface; import org.apache.fop.render.RenderingContext; import org.apache.fop.render.intermediate.AbstractIFPainter; +import org.apache.fop.render.intermediate.BorderPainter; +import org.apache.fop.render.intermediate.GraphicsPainter; import org.apache.fop.render.intermediate.IFException; import org.apache.fop.render.intermediate.IFState; import org.apache.fop.render.intermediate.IFUtil; @@ -64,7 +66,9 @@ public class PSPainter extends AbstractI /** logging instance */ private static Log log = LogFactory.getLog(PSPainter.class); - private PSBorderPainter borderPainter; + private final GraphicsPainter graphicsPainter; + + private BorderPainter borderPainter; private boolean inTextMode = false; @@ -78,7 +82,8 @@ public class PSPainter extends AbstractI protected PSPainter(PSDocumentHandler documentHandler, IFState state) { super(documentHandler); - this.borderPainter = new PSBorderPainter(getGenerator()); + this.graphicsPainter = new PSGraphicsPainter(getGenerator()); + this.borderPainter = new BorderPainter(graphicsPainter); this.state = state; } @@ -199,6 +204,20 @@ public class PSPainter extends AbstractI } /** {@inheritDoc} */ + public void clipBackground(Rectangle rect, + BorderProps bpsBefore, BorderProps bpsAfter, + BorderProps bpsStart, BorderProps bpsEnd) throws IFException { + + try { + borderPainter.clipBackground(rect, + bpsBefore, bpsAfter, bpsStart, bpsEnd); + } catch (IOException ioe) { + throw new IFException("I/O error while clipping background", ioe); + } + + } + + /** {@inheritDoc} */ public void fillRect(Rectangle rect, Paint fill) throws IFException { if (fill == null) { return; @@ -225,15 +244,15 @@ public class PSPainter extends AbstractI /** {@inheritDoc} */ public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom, - BorderProps left, BorderProps right) throws IFException { + BorderProps left, BorderProps right, Color innerBackgroundColor) throws IFException { if (top != null || bottom != null || left != null || right != null) { try { endTextObject(); if (getDocumentHandler().getPSUtil().getRenderingMode() == PSRenderingMode.SIZE && hasOnlySolidBorders(top, bottom, left, right)) { - super.drawBorderRect(rect, top, bottom, left, right); + super.drawBorderRect(rect, top, bottom, left, right, innerBackgroundColor); } else { - this.borderPainter.drawBorders(rect, top, bottom, left, right); + this.borderPainter.drawBorders(rect, top, bottom, left, right, innerBackgroundColor); } } catch (IOException ioe) { throw new IFException("I/O error in drawBorderRect()", ioe); @@ -246,7 +265,7 @@ public class PSPainter extends AbstractI throws IFException { try { endTextObject(); - this.borderPainter.drawLine(start, end, width, color, style); + this.graphicsPainter.drawLine(start, end, width, color, style); } catch (IOException ioe) { throw new IFException("I/O error in drawLine()", ioe); } Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/traits/BorderProps.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/traits/BorderProps.java?rev=1401607&r1=1401606&r2=1401607&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/traits/BorderProps.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/traits/BorderProps.java Wed Oct 24 10:20:17 2012 @@ -34,47 +34,90 @@ import org.apache.fop.util.ColorUtil; */ public class BorderProps implements Serializable { - private static final long serialVersionUID = -886871454032189183L; + private static final long serialVersionUID = 8022237892391068187L; - /** Separate border model */ - public static final int SEPARATE = 0; - /** Collapsing border model, for borders inside a table */ - public static final int COLLAPSE_INNER = 1; - /** Collapsing border model, for borders at the table's outer border */ - public static final int COLLAPSE_OUTER = 2; + public enum Mode { + SEPARATE("separate") { + @Override + int getClippedWidth(BorderProps bp) { + return 0; + } + }, + COLLAPSE_INNER("collapse-inner"), // for borders inside a table + COLLAPSE_OUTER("collapse-outer"); // for borders at the table's outer border + + private final String value; + + Mode(String value) { + this.value = value; + } + + int getClippedWidth(BorderProps bp) { + return bp.width / 2; + }; + } /** Border style (one of EN_*) */ - public int style; // Enum for border style // CSOK: VisibilityModifier + public final int style; // Enum for border style // CSOK: VisibilityModifier /** Border color */ - public Color color; // CSOK: VisibilityModifier + public final Color color; // CSOK: VisibilityModifier + /** Border width */ - public int width; // CSOK: VisibilityModifier - /** Border mode (one of SEPARATE, COLLAPSE_INNER and COLLAPSE_OUTER) */ - public int mode; // CSOK: VisibilityModifier + public final int width; // CSOK: VisibilityModifier + + private final int radiusStart; + + private final int radiusEnd; + + /** Border mode */ + private final Mode mode; // CSOK: VisibilityModifier /** * Constructs a new BorderProps instance. * @param style border style (one of EN_*) * @param width border width + * @param radiusStart radius of start corner in the direction perpendicular to border segment + * @param radiusEnd radius of end corner in the direction perpendicular to border segment * @param color border color * @param mode border mode ((one of SEPARATE, COLLAPSE_INNER and COLLAPSE_OUTER) */ - public BorderProps(int style, int width, Color color, int mode) { + public BorderProps(int style, int width, int radiusStart, int radiusEnd, Color color, Mode mode) { this.style = style; this.width = width; + this.radiusStart = radiusStart; + this.radiusEnd = radiusEnd; this.color = color; this.mode = mode; } /** - * Constructs a new BorderProps instance. - * @param style border style (one of the XSL enum values for border style) + * Factory method for a new BorderProps instance with rectangular corners. + * @param style border style (one of EN_*) * @param width border width * @param color border color * @param mode border mode ((one of SEPARATE, COLLAPSE_INNER and COLLAPSE_OUTER) */ - public BorderProps(String style, int width, Color color, int mode) { - this(getConstantForStyle(style), width, color, mode); + public static BorderProps makeRectangular(int style, int width, Color color, Mode mode) { + return new BorderProps(style, width, 0, 0, color, mode); + } + + private BorderProps(String style, int width, int radiusStart, int radiusEnd, Color color, Mode mode) { + this(getConstantForStyle(style), width, radiusStart, radiusEnd, color, mode); + } + + /** + * + * @return the radius of the corner adjacent to the before or start border + */ + public int getRadiusStart() { + return radiusStart; + } + + /** + * @return the radius of the corner adjacent to the after or end border + */ + public int getRadiusEnd() { + return radiusEnd; } /** @@ -82,11 +125,7 @@ public class BorderProps implements Seri * @return the effective width of the clipped part of the border */ public static int getClippedWidth(BorderProps bp) { - if ((bp != null) && (bp.mode != SEPARATE)) { - return bp.width / 2; - } else { - return 0; - } + return bp == null ? 0 : bp.mode.getClippedWidth(bp); } private String getStyleString() { @@ -97,6 +136,10 @@ public class BorderProps implements Seri return BorderStyle.valueOf(style).getEnumValue(); } + public boolean isCollapseOuter() { + return mode == Mode.COLLAPSE_OUTER; + } + /** {@inheritDoc} */ @Override public int hashCode() { @@ -112,12 +155,14 @@ public class BorderProps implements Seri return true; } else { if (obj instanceof BorderProps) { - BorderProps other = (BorderProps)obj; + BorderProps other = (BorderProps) obj; return (style == other.style) && org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor( color, other.color) && width == other.width - && mode == other.mode; + && mode == other.mode + && radiusStart == other.radiusStart + && radiusEnd == other.radiusEnd; } } return false; @@ -131,60 +176,79 @@ public class BorderProps implements Seri * @return a BorderProps instance */ public static BorderProps valueOf(FOUserAgent foUserAgent, String s) { - if (s.startsWith("(") && s.endsWith(")")) { - s = s.substring(1, s.length() - 1); - Pattern pattern = Pattern.compile("([^,\\(]+(?:\\(.*\\))?)"); - Matcher m = pattern.matcher(s); - boolean found; - found = m.find(); - String style = m.group(); - found = m.find(); - String color = m.group(); - found = m.find(); - int width = Integer.parseInt(m.group()); - int mode = SEPARATE; - found = m.find(); - if (found) { - String ms = m.group(); - if ("collapse-inner".equalsIgnoreCase(ms)) { - mode = COLLAPSE_INNER; - } else if ("collapse-outer".equalsIgnoreCase(ms)) { - mode = COLLAPSE_OUTER; - } - } - Color c; - try { - c = ColorUtil.parseColorString(foUserAgent, color); - } catch (PropertyException e) { - throw new IllegalArgumentException(e.getMessage()); - } - - return new BorderProps(style, width, c, mode); - } else { - throw new IllegalArgumentException("BorderProps must be surrounded by parentheses"); - } + return BorderPropsDeserializer.INSTANCE.valueOf(foUserAgent, s); } - /** {@inheritDoc} */ @Override public String toString() { StringBuffer sbuf = new StringBuffer(); - sbuf.append('('); - sbuf.append(getStyleString()); - sbuf.append(','); - sbuf.append(ColorUtil.colorToString(color)); - sbuf.append(','); - sbuf.append(width); - if (mode != SEPARATE) { - sbuf.append(','); - if (mode == COLLAPSE_INNER) { - sbuf.append("collapse-inner"); - } else { - sbuf.append("collapse-outer"); + sbuf.append('(') + .append(getStyleString()).append(',') + .append(ColorUtil.colorToString(color)).append(',') + .append(width); + if (!mode.equals(Mode.SEPARATE)) { + sbuf.append(",").append(mode.value); + } + + if (radiusStart != 0 || radiusEnd != 0) { + if (mode.equals(Mode.SEPARATE)) { + // Because of the corner radii properties the mode must be set + // so that the parameter index is consistent + sbuf.append(",").append(Mode.SEPARATE.value); } + sbuf.append(',').append(radiusStart) + .append(',').append(radiusEnd); } sbuf.append(')'); return sbuf.toString(); } + private static final class BorderPropsDeserializer { + + private static final BorderPropsDeserializer INSTANCE = new BorderPropsDeserializer(); + + private static final Pattern PATTERN = Pattern.compile("([^,\\(]+(?:\\(.*\\))?)"); + + private BorderPropsDeserializer() { + } + + public BorderProps valueOf(FOUserAgent foUserAgent, String s) { + if (s.startsWith("(") && s.endsWith(")")) { + s = s.substring(1, s.length() - 1); + Matcher m = PATTERN.matcher(s); + m.find(); + String style = m.group(); + m.find(); + String color = m.group(); + m.find(); + int width = Integer.parseInt(m.group()); + Mode mode = Mode.SEPARATE; + if (m.find()) { + String ms = m.group(); + if (Mode.COLLAPSE_INNER.value.equalsIgnoreCase(ms)) { + mode = Mode.COLLAPSE_INNER; + } else if (Mode.COLLAPSE_OUTER.value.equalsIgnoreCase(ms)) { + mode = Mode.COLLAPSE_OUTER; + } + } + Color c; + try { + c = ColorUtil.parseColorString(foUserAgent, color); + } catch (PropertyException e) { + throw new IllegalArgumentException(e.getMessage()); + } + int startRadius = 0; + int endRadius = 0; + if (m.find()) { + startRadius = Integer.parseInt(m.group()); + m.find(); + endRadius = Integer.parseInt(m.group()); + } + return new BorderProps(style, width, startRadius, endRadius, c, mode); + } else { + throw new IllegalArgumentException("BorderProps must be surrounded by parentheses"); + } + } + } + } Modified: xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGPainter.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGPainter.java?rev=1401607&r1=1401606&r2=1401607&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGPainter.java (original) +++ xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGPainter.java Wed Oct 24 10:20:17 2012 @@ -260,6 +260,13 @@ public class SVGPainter extends Abstract } /** {@inheritDoc} */ + public void clipBackground(Rectangle rect, BorderProps bpsBefore, BorderProps bpsAfter, + BorderProps bpsStart, BorderProps bpsEnd) throws IFException { + //TODO Implement me!!! + + } + + /** {@inheritDoc} */ public void fillRect(Rectangle rect, Paint fill) throws IFException { if (fill == null) { return; @@ -399,4 +406,13 @@ public class SVGPainter extends Abstract } } + /** {@inheritDoc} */ + public void fillBackground(Rectangle rect, Paint fill, BorderProps bpsBefore, + BorderProps bpsAfter, BorderProps bpsStart, BorderProps bpsEnd) throws IFException { + // Not supported in SVG + + } + + + } Modified: xmlgraphics/fop/trunk/status.xml URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=1401607&r1=1401606&r2=1401607&view=diff ============================================================================== --- xmlgraphics/fop/trunk/status.xml (original) +++ xmlgraphics/fop/trunk/status.xml Wed Oct 24 10:20:17 2012 @@ -59,6 +59,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> <release version="FOP Trunk" date="TBD"> + <action context="Code" dev="PH" type="add" fixes-bug="54041"> + Added support for Rounded Corners on block areas. + </action> <action context="Renderers" dev="VH" type="add" fixes-bug="54038"> Added PDF/A-2 output option. </action> Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/table/TableCellLayoutManagerTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/table/TableCellLayoutManagerTestCase.java?rev=1401607&r1=1401606&r2=1401607&view=diff ============================================================================== --- xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/table/TableCellLayoutManagerTestCase.java (original) +++ xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/table/TableCellLayoutManagerTestCase.java Wed Oct 24 10:20:17 2012 @@ -23,10 +23,6 @@ import java.awt.Color; import org.junit.Test; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import org.apache.fop.fo.flow.table.PrimaryGridUnit; import org.apache.fop.fo.flow.table.Table; import org.apache.fop.fo.flow.table.TableCell; @@ -41,6 +37,10 @@ import org.apache.fop.layoutmgr.PageSequ import org.apache.fop.layoutmgr.PositionIterator; import org.apache.fop.layoutmgr.RetrieveTableMarkerLayoutManager; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + public class TableCellLayoutManagerTestCase { // this test aims to check that the first call to addAreas() calls @@ -57,7 +57,7 @@ public class TableCellLayoutManagerTestC CondLengthProperty clp = mock(CondLengthProperty.class); when(clp.getLengthValue()).thenReturn(0); // real border info - BorderInfo bi = BorderInfo.getInstance(0, clp, Color.BLACK); + BorderInfo bi = BorderInfo.getInstance(0, clp, Color.BLACK, clp, clp); // mock column TableColumn tcol = mock(TableColumn.class); when(tcol.getCommonBorderPaddingBackground()).thenReturn(cbpb); Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/intermediate/AbstractIFPainterTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/intermediate/AbstractIFPainterTestCase.java?rev=1401607&r1=1401606&r2=1401607&view=diff ============================================================================== --- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/intermediate/AbstractIFPainterTestCase.java (original) +++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/intermediate/AbstractIFPainterTestCase.java Wed Oct 24 10:20:17 2012 @@ -29,6 +29,7 @@ import org.w3c.dom.Document; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontTriplet; import org.apache.fop.render.RenderingContext; +import org.apache.fop.traits.BorderProps; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; @@ -59,6 +60,10 @@ public class AbstractIFPainterTestCase { public void clipRect(Rectangle rect) throws IFException { } + public void clipBackground(Rectangle rect, BorderProps bpsBefore, BorderProps bpsAfter, + BorderProps bpsStart, BorderProps bpsEnd) throws IFException { + } + public void fillRect(Rectangle rect, Paint fill) throws IFException { } @@ -76,6 +81,7 @@ public class AbstractIFPainterTestCase { public void drawText(int x, int y, int letterSpacing, int wordSpacing, int[][] dp, String text) throws IFException { } + }; FontInfo fontInfo = mock(FontInfo.class); when(handler.getFontInfo()).thenReturn(fontInfo); Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java?rev=1401607&r1=1401606&r2=1401607&view=diff ============================================================================== --- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java (original) +++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java Wed Oct 24 10:20:17 2012 @@ -16,6 +16,8 @@ */ package org.apache.fop.render.ps; +import java.awt.Color; +import java.awt.Rectangle; import java.io.IOException; import java.util.Collections; @@ -26,9 +28,13 @@ import org.mockito.verification.Verifica import org.apache.xmlgraphics.ps.PSGenerator; import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.fo.Constants; import org.apache.fop.render.intermediate.IFContext; import org.apache.fop.render.intermediate.IFState; +import org.apache.fop.traits.BorderProps; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.anyFloat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -75,4 +81,30 @@ public class PSPainterTestCase { } verify(gen, test).useColor(state.getTextColor()); } + + @Test + public void testDrawBorderRect() { + // 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 + PSGenerator psGenerator = mock(PSGenerator.class); + when(psGenerator.formatDouble(anyFloat())).thenReturn("20.0"); // simplify! + PSRenderingUtil psRenderingUtil = mock(PSRenderingUtil.class); + PSDocumentHandler psDocumentHandler = mock(PSDocumentHandler.class); + when(psDocumentHandler.getGenerator()).thenReturn(psGenerator); + when(psDocumentHandler.getPSUtil()).thenReturn(psRenderingUtil); + 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 + BorderProps border = new BorderProps(Constants.EN_SOLID, 4000, 30000, 30000, Color.BLACK, + BorderProps.Mode.SEPARATE); + try { + 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..."); + } + } + } Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/traits/BorderPropsTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/traits/BorderPropsTestCase.java?rev=1401607&r1=1401606&r2=1401607&view=diff ============================================================================== --- xmlgraphics/fop/trunk/test/java/org/apache/fop/traits/BorderPropsTestCase.java (original) +++ xmlgraphics/fop/trunk/test/java/org/apache/fop/traits/BorderPropsTestCase.java Wed Oct 24 10:20:17 2012 @@ -19,16 +19,17 @@ package org.apache.fop.traits; -import static org.junit.Assert.assertEquals; - import java.awt.Color; +import org.junit.Test; + import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives; import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace; import org.apache.fop.fo.Constants; import org.apache.fop.util.ColorUtil; -import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * Tests the BorderProps class. @@ -44,23 +45,38 @@ public class BorderPropsTestCase { Color col = new Color(1.0f, 1.0f, 0.5f, 1.0f); //Normalize: Avoid false alarms due to color conversion (rounding) col = ColorUtil.parseColorString(null, ColorUtil.colorToString(col)); - - BorderProps b1 = new BorderProps(Constants.EN_DOUBLE, 1250, - col, BorderProps.COLLAPSE_OUTER); - String ser = b1.toString(); - BorderProps b2 = BorderProps.valueOf(null, ser); - assertEquals(b1, b2); + BorderProps sut = BorderProps.makeRectangular(Constants.EN_DOUBLE, 1250, col, + BorderProps.Mode.COLLAPSE_OUTER); + testSerialization(sut); float[] cmyk = new float[] {1.0f, 1.0f, 0.5f, 1.0f}; col = DeviceCMYKColorSpace.createCMYKColor(cmyk); //Convert to sRGB with CMYK alternative as constructed by the cmyk() function float[] rgb = col.getRGBColorComponents(null); col = new ColorWithAlternatives(rgb[0], rgb[1], rgb[2], new Color[] {col}); - b1 = new BorderProps(Constants.EN_INSET, 9999, - col, BorderProps.SEPARATE); - ser = b1.toString(); - b2 = BorderProps.valueOf(null, ser); - assertEquals(b1, b2); + sut = BorderProps.makeRectangular(Constants.EN_INSET, 9999, col, BorderProps.Mode.SEPARATE); + testSerialization(sut); + } + + /** + * Test serialization and deserialization to/from String. + * @throws Exception if an error occurs + */ + @Test + public void testSerializationWithCornerRadii() throws Exception { + Color col = new Color(1.0f, 1.0f, 0.5f, 1.0f); + //Normalize: Avoid false alarms due to color conversion (rounding) + col = ColorUtil.parseColorString(null, ColorUtil.colorToString(col)); + for(BorderProps.Mode mode : BorderProps.Mode.values()) { + BorderProps sut = BorderProps.makeRectangular(Constants.EN_SOLID, 10, col, mode); + testSerialization(sut); + sut = new BorderProps(Constants.EN_SOLID, 10, 4, 3, col, mode); + testSerialization(sut); + } + } + + private void testSerialization(BorderProps borderProp) { + assertEquals(borderProp, BorderProps.valueOf(null, borderProp.toString())); } } Modified: xmlgraphics/fop/trunk/test/pdf/accessibility/pdf/complete.pdf URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/pdf/accessibility/pdf/complete.pdf?rev=1401607&r1=1401606&r2=1401607&view=diff ============================================================================== Binary files - no diff available. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
