diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2011-03-14 20:46:03 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2011-03-14 20:46:03 +0000 |
commit | 5d664ac15dd06286fa9e221dddc946cf27585deb (patch) | |
tree | 89c167d4e9b18540e959819c932b47862864a84b /src/java/org/apache | |
parent | 1aa0218dfaed1eee72e9c254f84579e301aadaef (diff) | |
download | xmlgraphics-fop-5d664ac15dd06286fa9e221dddc946cf27585deb.tar.gz xmlgraphics-fop-5d664ac15dd06286fa9e221dddc946cf27585deb.zip |
Bugzilla #49910: clipping rectangle is wrong on side-regions
Partial fix that works only when the reference-orientation property is set to 0 or 180 on side-regions
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1081554 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
10 files changed, 102 insertions, 63 deletions
diff --git a/src/java/org/apache/fop/area/BlockViewport.java b/src/java/org/apache/fop/area/BlockViewport.java index 032b39f95..770ff31fb 100644 --- a/src/java/org/apache/fop/area/BlockViewport.java +++ b/src/java/org/apache/fop/area/BlockViewport.java @@ -19,12 +19,14 @@ package org.apache.fop.area; +import java.awt.Rectangle; + /** * A BlockViewport. * This is used for block level Viewport/reference pairs. * The block-container creates this area. */ -public class BlockViewport extends Block { +public class BlockViewport extends Block implements Viewport { private static final long serialVersionUID = -7840580922580735157L; @@ -78,14 +80,16 @@ public class BlockViewport extends Block { clip = cl; } - /** - * Get the clipping for this viewport. - * - * @return the clipping for the viewport - * true if the contents should be clipped for this viewport - */ - public boolean getClip() { + public boolean hasClip() { return clip; } + + public Rectangle getClipRectangle() { + if (clip) { + return new Rectangle(getIPD(), getBPD()); + } else { + return null; + } + } } diff --git a/src/java/org/apache/fop/area/RegionViewport.java b/src/java/org/apache/fop/area/RegionViewport.java index 0654c5f6b..305dc5c10 100644 --- a/src/java/org/apache/fop/area/RegionViewport.java +++ b/src/java/org/apache/fop/area/RegionViewport.java @@ -19,6 +19,7 @@ package org.apache.fop.area; +import java.awt.Rectangle; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.util.HashMap; @@ -29,7 +30,7 @@ import java.util.HashMap; * region-reference-area as its child. These areas are described * in the fo:region-body description in the XSL Recommendation. */ -public class RegionViewport extends Area implements Cloneable { +public class RegionViewport extends Area implements Cloneable, Viewport { private static final long serialVersionUID = 505781815165102572L; @@ -75,11 +76,18 @@ public class RegionViewport extends Area implements Cloneable { clip = c; } - /** @return true if the viewport should be clipped. */ - public boolean isClip() { + public boolean hasClip() { return this.clip; } + public Rectangle getClipRectangle() { + if (clip) { + return new Rectangle(getIPD(), getBPD()); + } else { + return null; + } + } + /** * Get the view area of this viewport. * diff --git a/src/java/org/apache/fop/area/Viewport.java b/src/java/org/apache/fop/area/Viewport.java new file mode 100644 index 000000000..a92d826cc --- /dev/null +++ b/src/java/org/apache/fop/area/Viewport.java @@ -0,0 +1,44 @@ +/* + * 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.area; + +import java.awt.Rectangle; + +/** + * A viewport-area that may clip its content. + */ +public interface Viewport { + + /** + * Returns true if this area will clip overflowing content. + * + * @return {@code true} if the overflow trait has the value "hidden", "scroll" or + * "error-if-overflow" + */ + boolean hasClip(); + + /** + * Returns the clipping rectangle of this viewport area. + * + * @return the clipping rectangle expressed in the viewport's coordinate system, or + * null if clipping is disabled + */ + Rectangle getClipRectangle(); +} diff --git a/src/java/org/apache/fop/area/inline/Viewport.java b/src/java/org/apache/fop/area/inline/Viewport.java index 206a965e2..610697c36 100644 --- a/src/java/org/apache/fop/area/inline/Viewport.java +++ b/src/java/org/apache/fop/area/inline/Viewport.java @@ -19,19 +19,20 @@ package org.apache.fop.area.inline; -import org.apache.fop.area.Area; - -import java.io.IOException; +import java.awt.Rectangle; import java.awt.geom.Rectangle2D; +import java.io.IOException; import java.util.HashMap; +import org.apache.fop.area.Area; + /** * Inline viewport area. * This is an inline-level viewport area for inline container, * external graphic and instream foreign object. This viewport * holds the area and positions it. */ -public class Viewport extends InlineArea { +public class Viewport extends InlineArea implements org.apache.fop.area.Viewport { private static final long serialVersionUID = 813338534627918689L; @@ -60,15 +61,18 @@ public class Viewport extends InlineArea { this.clip = c; } - /** - * Get the clip of this viewport. - * - * @return true if this viewport should clip - */ - public boolean getClip() { + public boolean hasClip() { return this.clip; } + public Rectangle getClipRectangle() { + if (clip) { + return new Rectangle(getIPD(), getBPD()); + } else { + return null; + } + } + /** * Set the position and size of the content of this viewport. * diff --git a/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java b/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java index cfce3a875..50a95b09a 100644 --- a/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java +++ b/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java @@ -542,7 +542,7 @@ public abstract class AbstractPathOrientedRenderer extends PrintRenderer { } //Clipping - if (bv.getClip()) { + if (bv.hasClip()) { clipRect(0f, 0f, width, height); } @@ -593,8 +593,8 @@ public abstract class AbstractPathOrientedRenderer extends PrintRenderer { //Now adjust for border/padding currentBPPosition += borderPaddingBefore; - Rectangle2D clippingRect = null; - if (bv.getClip()) { + Rectangle clippingRect = null; + if (bv.hasClip()) { clippingRect = new Rectangle(currentIPPosition, currentBPPosition, bv.getIPD(), bv.getBPD()); } @@ -701,14 +701,14 @@ public abstract class AbstractPathOrientedRenderer extends PrintRenderer { drawBackAndBorders(viewport, x, y, width + bpwidth, height + bpheight); - if (viewport.getClip()) { + if (viewport.hasClip()) { saveGraphicsState(); clipRect(x + borderPaddingStart, y + borderPaddingBefore, width, height); } super.renderViewport(viewport); - if (viewport.getClip()) { + if (viewport.hasClip()) { restoreGraphicsState(); } } diff --git a/src/java/org/apache/fop/render/AbstractRenderer.java b/src/java/org/apache/fop/render/AbstractRenderer.java index 273f0bc16..4e0b13c56 100644 --- a/src/java/org/apache/fop/render/AbstractRenderer.java +++ b/src/java/org/apache/fop/render/AbstractRenderer.java @@ -278,7 +278,6 @@ public abstract class AbstractRenderer * @param port The region viewport to be rendered */ protected void renderRegionViewport(RegionViewport port) { - Rectangle2D view = port.getViewArea(); // The CTM will transform coordinates relative to // this region-reference area into page coords, so // set origin for the region to 0,0. @@ -289,7 +288,7 @@ public abstract class AbstractRenderer handleRegionTraits(port); // shouldn't the viewport have the CTM - startVParea(regionReference.getCTM(), port.isClip() ? view : null); + startVParea(regionReference.getCTM(), port.getClipRectangle()); // do after starting viewport area if (regionReference.getRegionClass() == FO_REGION_BODY) { renderBodyRegion((BodyRegion) regionReference); @@ -306,7 +305,7 @@ public abstract class AbstractRenderer * @param clippingRect the clipping rectangle if the viewport should be clipping, * null if no clipping is performed. */ - protected abstract void startVParea(CTM ctm, Rectangle2D clippingRect); + protected abstract void startVParea(CTM ctm, Rectangle clippingRect); /** * Signals exit from a viewport area. Subclasses can restore transformation matrices @@ -461,8 +460,8 @@ public abstract class AbstractRenderer int saveIP = currentIPPosition; int saveBP = currentBPPosition; - Rectangle2D clippingRect = null; - if (bv.getClip()) { + Rectangle clippingRect = null; + if (bv.hasClip()) { clippingRect = new Rectangle(saveIP, saveBP, bv.getIPD(), bv.getBPD()); } diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java index 046d1703b..dfa2477b6 100644 --- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java +++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java @@ -37,7 +37,6 @@ import java.util.Stack; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; - import org.xml.sax.SAXException; import org.apache.batik.parser.AWTTransformProducer; @@ -788,18 +787,11 @@ public class IFRenderer extends AbstractPathOrientedRenderer { contentRectTransform.translate(borderPaddingStart, borderPaddingBefore); concatenateTransformationMatrixMpt(contentRectTransform, false); - //Clipping - Rectangle clipRect = null; - if (bv.getClip()) { - clipRect = new Rectangle(0, 0, dim.width, dim.height); - //clipRect(0f, 0f, width, height); - } - //saveGraphicsState(); //Set up coordinate system for content rectangle AffineTransform contentTransform = ctm.toAffineTransform(); //concatenateTransformationMatrixMpt(contentTransform); - startViewport(contentTransform, clipRect); + startViewport(contentTransform, bv.getClipRectangle()); currentIPPosition = 0; currentBPPosition = 0; @@ -831,13 +823,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer { //Now adjust for border/padding currentBPPosition += borderPaddingBefore; - Rectangle2D clippingRect = null; - if (bv.getClip()) { - clippingRect = new Rectangle(currentIPPosition, currentBPPosition, - bv.getIPD(), bv.getBPD()); - } - - startVParea(ctm, clippingRect); + startVParea(ctm, bv.getClipRectangle()); currentIPPosition = 0; currentBPPosition = 0; renderBlocks(bv, children); @@ -863,19 +849,12 @@ public class IFRenderer extends AbstractPathOrientedRenderer { } /** {@inheritDoc} */ - protected void startVParea(CTM ctm, Rectangle2D clippingRect) { + protected void startVParea(CTM ctm, Rectangle clippingRect) { if (log.isTraceEnabled()) { log.trace("startVParea() ctm=" + ctm + ", clippingRect=" + clippingRect); } AffineTransform at = new AffineTransform(ctm.toArray()); - Rectangle clipRect = null; - if (clippingRect != null) { - clipRect = new Rectangle( - (int)clippingRect.getMinX() - currentIPPosition, - (int)clippingRect.getMinY() - currentBPPosition, - (int)clippingRect.getWidth(), (int)clippingRect.getHeight()); - } - startViewport(at, clipRect); + startViewport(at, clippingRect); if (log.isTraceEnabled()) { log.trace("startVPArea: " + at + " --> " + graphicContext.getTransform()); } diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java index 353aefa25..26f98ddd1 100644 --- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java +++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java @@ -445,7 +445,7 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem } /** {@inheritDoc} */ - protected void startVParea(CTM ctm, Rectangle2D clippingRect) { + protected void startVParea(CTM ctm, Rectangle clippingRect) { saveGraphicsState(); diff --git a/src/java/org/apache/fop/render/txt/TXTRenderer.java b/src/java/org/apache/fop/render/txt/TXTRenderer.java index aa36ea28f..386f95838 100644 --- a/src/java/org/apache/fop/render/txt/TXTRenderer.java +++ b/src/java/org/apache/fop/render/txt/TXTRenderer.java @@ -21,6 +21,7 @@ package org.apache.fop.render.txt; import java.awt.Color; import java.awt.Point; +import java.awt.Rectangle; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.io.IOException; @@ -560,7 +561,7 @@ public class TXTRenderer extends AbstractPathOrientedRenderer { /** * {@inheritDoc} */ - protected void startVParea(CTM ctm, Rectangle2D clippingRect) { + protected void startVParea(CTM ctm, Rectangle clippingRect) { currentState.push(ctm); } diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java index 85995e8b2..a7f085d7f 100644 --- a/src/java/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java @@ -21,6 +21,7 @@ package org.apache.fop.render.xml; // Java import java.awt.Color; +import java.awt.Rectangle; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.OutputStream; @@ -518,7 +519,7 @@ public class XMLRenderer extends AbstractXMLRenderer { addAreaAttributes(port); addTraitAttributes(port); addAttribute("rect", port.getViewArea()); - if (port.isClip()) { + if (port.hasClip()) { addAttribute("clipped", "true"); } startElement("regionViewport", atts); @@ -558,9 +559,8 @@ public class XMLRenderer extends AbstractXMLRenderer { } } - /** {@inheritDoc} */ @Override - protected void startVParea(CTM ctm, Rectangle2D clippingRect) { + protected void startVParea(CTM ctm, Rectangle clippingRect) { //only necessary for graphical output } @@ -679,7 +679,7 @@ public class XMLRenderer extends AbstractXMLRenderer { addAttribute("top-position", bvp.getYOffset()); } addAttribute("ctm", bvp.getCTM().toString()); - if (bvp.getClip()) { + if (bvp.hasClip()) { addAttribute("clipped", "true"); } } else { @@ -749,7 +749,7 @@ public class XMLRenderer extends AbstractXMLRenderer { addTraitAttributes(viewport); addAttribute("offset", viewport.getOffset()); addAttribute("pos", viewport.getContentPosition()); - if (viewport.getClip()) { + if (viewport.hasClip()) { addAttribute("clip", "true"); } startElement("viewport", atts); |