diff options
author | Jeremias Maerki <jeremias@apache.org> | 2005-09-05 08:09:42 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2005-09-05 08:09:42 +0000 |
commit | 299c6b1393cf9d5194929ac8c756171b2ff2ce4f (patch) | |
tree | a03a028f1ef7f339b938f6af08a2a51391e3216a /src/java/org | |
parent | 2daa1220f0331d560481ed48d5531ee1b6555793 (diff) | |
download | xmlgraphics-fop-299c6b1393cf9d5194929ac8c756171b2ff2ce4f.tar.gz xmlgraphics-fop-299c6b1393cf9d5194929ac8c756171b2ff2ce4f.zip |
Bugzilla #36487:
Background images were incorrectly positioned in some absolute positioned blocks.
Some additional attributes output by the XMLRenderer.
Refactored the layout for e-g and i-f-o. Introduced common base classes for the
corresponding flow objects as well as the e-g and i-f-o LMs.
Fixed incorrectly applied margins on region-body when writing mode is not lr.
Fixed application of correct percent base for margins and extents on regions
when the reference orientation is 90 degrees.
Fixed incorrectly positioned regions when writing mode is different between the
simple-page-master setting and the setting on the region.
Several updates to the layout engine test cases.
Submitted by: Manuel Mall <mm.at.arcus.com.au>
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@278690 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
15 files changed, 775 insertions, 781 deletions
diff --git a/src/java/org/apache/fop/area/Page.java b/src/java/org/apache/fop/area/Page.java index 0778fab47..3f03bfa8a 100644 --- a/src/java/org/apache/fop/area/Page.java +++ b/src/java/org/apache/fop/area/Page.java @@ -92,14 +92,21 @@ public class Page implements Serializable, Cloneable { * use the LengthBase.BLOCK_WIDTH. */ SimplePercentBaseContext pageWidthContext - = new SimplePercentBaseContext(null, LengthBase.CONTAINING_BLOCK_WIDTH, pageViewPortDims.ipd); + = new SimplePercentBaseContext(null, LengthBase.CONTAINING_BLOCK_WIDTH + , pageViewPortDims.ipd); SimplePercentBaseContext pageHeightContext - = new SimplePercentBaseContext(null, LengthBase.CONTAINING_BLOCK_WIDTH, pageViewPortDims.bpd); + = new SimplePercentBaseContext(null, LengthBase.CONTAINING_BLOCK_WIDTH + , pageViewPortDims.bpd); - Rectangle pageRefRect = - new Rectangle(mProps.marginLeft.getValue(pageWidthContext), mProps.marginTop.getValue(pageHeightContext), - pageViewPortDims.ipd - mProps.marginLeft.getValue(pageWidthContext) - mProps.marginRight.getValue(pageWidthContext), - pageViewPortDims.bpd - mProps.marginTop.getValue(pageHeightContext) - mProps.marginBottom.getValue(pageHeightContext)); + Rectangle pageRefRect + = new Rectangle(mProps.marginLeft.getValue(pageWidthContext) + , mProps.marginTop.getValue(pageHeightContext) + , pageViewPortDims.ipd + - mProps.marginLeft.getValue(pageWidthContext) + - mProps.marginRight.getValue(pageWidthContext) + , pageViewPortDims.bpd + - mProps.marginTop.getValue(pageHeightContext) + - mProps.marginBottom.getValue(pageHeightContext)); // Set up the CTM on the page reference area based on writing-mode // and reference-orientation @@ -112,7 +119,7 @@ public class Page implements Serializable, Cloneable { for (Iterator regenum = spm.getRegions().values().iterator(); regenum.hasNext();) { Region r = (Region)regenum.next(); - RegionViewport rvp = makeRegionViewport(r, reldims, pageCTM, pageViewPortDims); + RegionViewport rvp = makeRegionViewport(r, reldims, pageCTM, spm); if (r.getNameId() == Constants.FO_REGION_BODY) { rr = new BodyRegion((RegionBody) r, rvp); } else { @@ -133,13 +140,15 @@ public class Page implements Serializable, Cloneable { /** * Creates a RegionViewport Area object for this pagination Region. + * @param r the region the viewport is to be created for * @param reldims relative dimensions * @param pageCTM page coordinate transformation matrix + * @param spm the simple-page-master for this page * @return the new region viewport */ private RegionViewport makeRegionViewport(Region r, FODimension reldims, CTM pageCTM, - FODimension pageViewPortDims) { - Rectangle2D relRegionRect = r.getViewportRectangle(reldims, pageViewPortDims); + SimplePageMaster spm) { + Rectangle2D relRegionRect = r.getViewportRectangle(reldims, spm); Rectangle2D absRegionRect = pageCTM.transform(relRegionRect); // Get the region viewport rectangle in absolute coords by // transforming it using the page CTM diff --git a/src/java/org/apache/fop/fo/flow/AbstractGraphics.java b/src/java/org/apache/fop/fo/flow/AbstractGraphics.java new file mode 100644 index 000000000..b9f360c2c --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/AbstractGraphics.java @@ -0,0 +1,256 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.fo.flow; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.datatypes.Length; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.properties.CommonAccessibility; +import org.apache.fop.fo.properties.CommonAural; +import org.apache.fop.fo.properties.CommonBorderPaddingBackground; +import org.apache.fop.fo.properties.CommonMarginInline; +import org.apache.fop.fo.properties.CommonRelativePosition; +import org.apache.fop.fo.properties.KeepProperty; +import org.apache.fop.fo.properties.LengthRangeProperty; + +/** + * Common base class for instream-foreign-object and external-graphics + * flow formatting objects. + */ +public abstract class AbstractGraphics extends FObj { + + // The value of properties relevant for fo:instream-foreign-object + // and external-graphics. + private CommonAccessibility commonAccessibility; + private CommonAural commonAural; + private CommonBorderPaddingBackground commonBorderPaddingBackground; + private CommonMarginInline commonMarginInline; + private CommonRelativePosition commonRelativePosition; + private Length alignmentAdjust; + private int alignmentBaseline; + private Length baselineShift; + private LengthRangeProperty blockProgressionDimension; + // private ToBeImplementedProperty clip; + private Length contentHeight; + private String contentType; + private Length contentWidth; + private int displayAlign; + private int dominantBaseline; + private Length height; + private String id; + private LengthRangeProperty inlineProgressionDimension; + private KeepProperty keepWithNext; + private KeepProperty keepWithPrevious; + private Length lineHeight; + private int overflow; + private int scaling; + private int scalingMethod; + private int textAlign; + private int verticalAlign; // shorthand!!! + private Length width; + // End of property values + + /** + * constructs an instream-foreign-object object (called by Maker). + * + * @param parent the parent formatting object + */ + public AbstractGraphics(FONode parent) { + super(parent); + } + + /** + * @see org.apache.fop.fo.FObj#bind(PropertyList) + */ + public void bind(PropertyList pList) throws FOPException { + commonAccessibility = pList.getAccessibilityProps(); + commonAural = pList.getAuralProps(); + commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); + commonMarginInline = pList.getMarginInlineProps(); + commonRelativePosition = pList.getRelativePositionProps(); + alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength(); + alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum(); + baselineShift = pList.get(PR_BASELINE_SHIFT).getLength(); + blockProgressionDimension = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange(); + // clip = pList.get(PR_CLIP); + contentHeight = pList.get(PR_CONTENT_HEIGHT).getLength(); + contentType = pList.get(PR_CONTENT_TYPE).getString(); + contentWidth = pList.get(PR_CONTENT_WIDTH).getLength(); + displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum(); + dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum(); + height = pList.get(PR_HEIGHT).getLength(); + id = pList.get(PR_ID).getString(); + inlineProgressionDimension = pList.get(PR_INLINE_PROGRESSION_DIMENSION).getLengthRange(); + keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep(); + keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep(); + lineHeight = pList.get(PR_LINE_HEIGHT).getLength(); + overflow = pList.get(PR_OVERFLOW).getEnum(); + scaling = pList.get(PR_SCALING).getEnum(); + scalingMethod = pList.get(PR_SCALING_METHOD).getEnum(); + textAlign = pList.get(PR_TEXT_ALIGN).getEnum(); + verticalAlign = pList.get(PR_VERTICAL_ALIGN).getEnum(); + width = pList.get(PR_WIDTH).getLength(); + } + + /** + * Given the ipd and the content width calculates the + * required x offset based on the text-align property + * @param ipd the inline-progression-dimension of the object + * @param cwidth the calculated content width of the object + * @return the X offset + */ + public int computeXOffset (int ipd, int cwidth) { + int xoffset = 0; + switch (textAlign) { + case EN_CENTER: + xoffset = (ipd - cwidth) / 2; + break; + case EN_END: + xoffset = ipd - cwidth; + break; + case EN_START: + break; + case EN_JUSTIFY: + default: + break; + } + return xoffset; + } + + /** + * Given the bpd and the content height calculates the + * required y offset based on the display-align property + * @param bpd the block-progression-dimension of the object + * @param cheight the calculated content height of the object + * @return the Y offset + */ + public int computeYOffset(int bpd, int cheight) { + int yoffset = 0; + switch (displayAlign) { + case EN_BEFORE: + break; + case EN_AFTER: + yoffset = bpd - cheight; + break; + case EN_CENTER: + yoffset = (bpd - cheight) / 2; + break; + case EN_AUTO: + default: + break; + } + return yoffset; + } + + /** + * @return the "id" property. + */ + public String getId() { + return id; + } + + /** + * @return the Common Border, Padding, and Background Properties. + */ + public CommonBorderPaddingBackground getCommonBorderPaddingBackground() { + return commonBorderPaddingBackground; + } + + /** + * @return the "line-height" property. + */ + public Length getLineHeight() { + return lineHeight; + } + + /** + * @return the "inline-progression-dimension" property. + */ + public LengthRangeProperty getInlineProgressionDimension() { + return inlineProgressionDimension; + } + + /** + * @return the "block-progression-dimension" property. + */ + public LengthRangeProperty getBlockProgressionDimension() { + return blockProgressionDimension; + } + + /** + * @return the "height" property. + */ + public Length getHeight() { + return height; + } + + /** + * @return the "width" property. + */ + public Length getWidth() { + return width; + } + + /** + * @return the "content-height" property. + */ + public Length getContentHeight() { + return contentHeight; + } + + /** + * @return the "content-width" property. + */ + public Length getContentWidth() { + return contentWidth; + } + + /** + * @return the "scaling" property. + */ + public int getScaling() { + return scaling; + } + + /** + * @return the "vertical-align" property. + */ + public int getVerticalAlign() { + return verticalAlign; + } + + /** + * @return the "overflow" property. + */ + public int getOverflow() { + return overflow; + } + + /** + * @see org.apache.fop.fo.IntrinsicSizeAccess#getIntrinsicWidth() + */ + public abstract int getIntrinsicWidth(); + + /** + * @see org.apache.fop.fo.IntrinsicSizeAccess#getIntrinsicHeight() + */ + public abstract int getIntrinsicHeight(); +} diff --git a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java index 156d5bf21..5fa54cef4 100644 --- a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java +++ b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java @@ -18,60 +18,24 @@ package org.apache.fop.fo.flow; -import org.xml.sax.Locator; - import org.apache.fop.apps.FOPException; -import org.apache.fop.datatypes.Length; import org.apache.fop.fo.FONode; -import org.apache.fop.fo.FObj; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; -import org.apache.fop.fo.properties.CommonAccessibility; -import org.apache.fop.fo.properties.CommonAural; -import org.apache.fop.fo.properties.CommonBorderPaddingBackground; -import org.apache.fop.fo.properties.CommonMarginInline; -import org.apache.fop.fo.properties.CommonRelativePosition; -import org.apache.fop.fo.properties.KeepProperty; -import org.apache.fop.fo.properties.LengthRangeProperty; import org.apache.fop.image.FopImage; import org.apache.fop.image.ImageFactory; +import org.xml.sax.Locator; /** * External graphic formatting object. * This FO node handles the external graphic. It creates an image * inline area that can be added to the area tree. */ -public class ExternalGraphic extends FObj { +public class ExternalGraphic extends AbstractGraphics { // The value of properties relevant for fo:external-graphic. - private CommonAccessibility commonAccessibility; - private CommonAural commonAural; - private CommonBorderPaddingBackground commonBorderPaddingBackground; - private CommonMarginInline commonMarginInline; - private CommonRelativePosition commonRelativePosition; - private Length alignmentAdjust; - private int alignmentBaseline; - private Length baselineShift; - private LengthRangeProperty blockProgressionDimension; - // private ToBeImplementedProperty clip; - private Length contentHeight; - private String contentType; - private Length contentWidth; - private int displayAlign; - private int dominantBaseline; - private Length height; - private String id; - private LengthRangeProperty inlineProgressionDimension; - private KeepProperty keepWithNext; - private KeepProperty keepWithPrevious; - private Length lineHeight; - private int overflow; - private int scaling; - private int scalingMethod; + // All but one of the e-g properties are kept in AbstractGraphics private String src; - private int textAlign; - private int verticalAlign; //Extra - private Length width; // End of property values //Additional values @@ -91,34 +55,8 @@ public class ExternalGraphic extends FObj { * @see org.apache.fop.fo.FObj#bind(PropertyList) */ public void bind(PropertyList pList) throws FOPException { - commonAccessibility = pList.getAccessibilityProps(); - commonAural = pList.getAuralProps(); - commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); - commonMarginInline = pList.getMarginInlineProps(); - commonRelativePosition = pList.getRelativePositionProps(); - alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength(); - alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum(); - baselineShift = pList.get(PR_BASELINE_SHIFT).getLength(); - blockProgressionDimension = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange(); - // clip = pList.get(PR_CLIP); - contentHeight = pList.get(PR_CONTENT_HEIGHT).getLength(); - contentType = pList.get(PR_CONTENT_TYPE).getString(); - contentWidth = pList.get(PR_CONTENT_WIDTH).getLength(); - displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum(); - dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum(); - height = pList.get(PR_HEIGHT).getLength(); - id = pList.get(PR_ID).getString(); - inlineProgressionDimension = pList.get(PR_INLINE_PROGRESSION_DIMENSION).getLengthRange(); - keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep(); - keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep(); - lineHeight = pList.get(PR_LINE_HEIGHT).getLength(); - overflow = pList.get(PR_OVERFLOW).getEnum(); - scaling = pList.get(PR_SCALING).getEnum(); - scalingMethod = pList.get(PR_SCALING_METHOD).getEnum(); + super.bind(pList); src = pList.get(PR_SRC).getString(); - textAlign = pList.get(PR_TEXT_ALIGN).getEnum(); - verticalAlign = pList.get(PR_VERTICAL_ALIGN).getEnum(); - width = pList.get(PR_WIDTH).getLength(); //Additional processing: preload image url = ImageFactory.getURL(getSrc()); @@ -139,7 +77,7 @@ public class ExternalGraphic extends FObj { * @see org.apache.fop.fo.FONode#startOfNode */ protected void startOfNode() throws FOPException { - checkId(id); + checkId(getId()); getFOEventHandler().image(this); } @@ -153,83 +91,6 @@ public class ExternalGraphic extends FObj { } /** - * @return the Common Border, Padding, and Background Properties. - */ - public CommonBorderPaddingBackground getCommonBorderPaddingBackground() { - return commonBorderPaddingBackground; - } - - /** - * @return the Common Margin Properties-Inline. - */ - public CommonMarginInline getCommonMarginInline() { - return commonMarginInline; - } - - /** - * @return the "block-progression-dimension" property. - */ - public LengthRangeProperty getBlockProgressionDimension() { - return blockProgressionDimension; - } - - /** - * @return the "content-height" property. - */ - public Length getContentHeight() { - return contentHeight; - } - - /** - * @return the "content-width" property. - */ - public Length getContentWidth() { - return contentWidth; - } - - /** - * @return the "display-align" property. - */ - public int getDisplayAlign() { - return displayAlign; - } - - /** - * @return the "height" property. - */ - public Length getHeight() { - return height; - } - - /** - * @return the "id" property. - */ - public String getId() { - return id; - } - - /** - * @return the "inline-progression-dimension" property. - */ - public LengthRangeProperty getInlineProgressionDimension() { - return inlineProgressionDimension; - } - - /** - * @return the "overflow" property. - */ - public int getOverflow() { - return overflow; - } - - /** - * @return the "scaling" property. - */ - public int getScaling() { - return scaling; - } - - /** * @return the "src" property. */ public String getSrc() { @@ -244,27 +105,6 @@ public class ExternalGraphic extends FObj { } /** - * @return the "text-align" property. - */ - public int getTextAlign() { - return textAlign; - } - - /** - * @return the "width" property. - */ - public Length getWidth() { - return width; - } - - /** - * @return the "vertical-align" property. - */ - public int getVerticalAlign() { - return verticalAlign; - } - - /** * @see org.apache.fop.fo.FObj#getName() */ public String getName() { diff --git a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java index cfe90d07f..e59015947 100644 --- a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -19,59 +19,21 @@ package org.apache.fop.fo.flow; import java.awt.geom.Point2D; - -import org.xml.sax.Locator; - import org.apache.fop.apps.FOPException; -import org.apache.fop.datatypes.Length; import org.apache.fop.fo.FONode; -import org.apache.fop.fo.FObj; -import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; import org.apache.fop.fo.XMLObj; -import org.apache.fop.fo.properties.CommonAccessibility; -import org.apache.fop.fo.properties.CommonAural; -import org.apache.fop.fo.properties.CommonBorderPaddingBackground; -import org.apache.fop.fo.properties.CommonMarginInline; -import org.apache.fop.fo.properties.CommonRelativePosition; -import org.apache.fop.fo.properties.KeepProperty; -import org.apache.fop.fo.properties.LengthRangeProperty; +import org.xml.sax.Locator; /** * The instream-foreign-object flow formatting object. * This is an atomic inline object that contains * xml data. */ -public class InstreamForeignObject extends FObj { +public class InstreamForeignObject extends AbstractGraphics { // The value of properties relevant for fo:instream-foreign-object. - private CommonAccessibility commonAccessibility; - private CommonAural commonAural; - private CommonBorderPaddingBackground commonBorderPaddingBackground; - private CommonMarginInline commonMarginInline; - private CommonRelativePosition commonRelativePosition; - private Length alignmentAdjust; - private int alignmentBaseline; - private Length baselineShift; - private LengthRangeProperty blockProgressionDimension; - // private ToBeImplementedProperty clip; - private Length contentHeight; - private String contentType; - private Length contentWidth; - private int displayAlign; - private int dominantBaseline; - private Length height; - private String id; - private LengthRangeProperty inlineProgressionDimension; - private KeepProperty keepWithNext; - private KeepProperty keepWithPrevious; - private Length lineHeight; - private int overflow; - private int scaling; - private int scalingMethod; - private int textAlign; - private int verticalAlign; // shorthand!!! - private Length width; + // All property values contained in AbstractGraphics // End of property values //Additional value @@ -87,43 +49,10 @@ public class InstreamForeignObject extends FObj { } /** - * @see org.apache.fop.fo.FObj#bind(PropertyList) - */ - public void bind(PropertyList pList) throws FOPException { - commonAccessibility = pList.getAccessibilityProps(); - commonAural = pList.getAuralProps(); - commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); - commonMarginInline = pList.getMarginInlineProps(); - commonRelativePosition = pList.getRelativePositionProps(); - alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength(); - alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum(); - baselineShift = pList.get(PR_BASELINE_SHIFT).getLength(); - blockProgressionDimension = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange(); - // clip = pList.get(PR_CLIP); - contentHeight = pList.get(PR_CONTENT_HEIGHT).getLength(); - contentType = pList.get(PR_CONTENT_TYPE).getString(); - contentWidth = pList.get(PR_CONTENT_WIDTH).getLength(); - displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum(); - dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum(); - height = pList.get(PR_HEIGHT).getLength(); - id = pList.get(PR_ID).getString(); - inlineProgressionDimension = pList.get(PR_INLINE_PROGRESSION_DIMENSION).getLengthRange(); - keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep(); - keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep(); - lineHeight = pList.get(PR_LINE_HEIGHT).getLength(); - overflow = pList.get(PR_OVERFLOW).getEnum(); - scaling = pList.get(PR_SCALING).getEnum(); - scalingMethod = pList.get(PR_SCALING_METHOD).getEnum(); - textAlign = pList.get(PR_TEXT_ALIGN).getEnum(); - verticalAlign = pList.get(PR_VERTICAL_ALIGN).getEnum(); - width = pList.get(PR_WIDTH).getLength(); - } - - /** * @see org.apache.fop.fo.FONode#startOfNode */ protected void startOfNode() throws FOPException { - checkId(id); + checkId(getId()); } /** @@ -150,126 +79,6 @@ public class InstreamForeignObject extends FObj { } } - public int computeXOffset (int ipd, int cwidth) { - int xoffset = 0; - switch (textAlign) { - case EN_CENTER: - xoffset = (ipd - cwidth) / 2; - break; - case EN_END: - xoffset = ipd - cwidth; - break; - case EN_START: - break; - case EN_JUSTIFY: - default: - break; - } - return xoffset; - } - - public int computeYOffset(int bpd, int cheight) { - int yoffset = 0; - switch (displayAlign) { - case EN_BEFORE: - break; - case EN_AFTER: - yoffset = bpd - cheight; - break; - case EN_CENTER: - yoffset = (bpd - cheight) / 2; - break; - case EN_AUTO: - default: - break; - } - return yoffset; - } - - /** - * @return the "id" property. - */ - public String getId() { - return id; - } - - /** - * @return the Common Border, Padding, and Background Properties. - */ - public CommonBorderPaddingBackground getCommonBorderPaddingBackground() { - return commonBorderPaddingBackground; - } - - /** - * @return the "line-height" property. - */ - public Length getLineHeight() { - return lineHeight; - } - - /** - * @return the "inline-progression-dimension" property. - */ - public LengthRangeProperty getInlineProgressionDimension() { - return inlineProgressionDimension; - } - - /** - * @return the "block-progression-dimension" property. - */ - public LengthRangeProperty getBlockProgressionDimension() { - return blockProgressionDimension; - } - - /** - * @return the "height" property. - */ - public Length getHeight() { - return height; - } - - /** - * @return the "width" property. - */ - public Length getWidth() { - return width; - } - - /** - * @return the "content-height" property. - */ - public Length getContentHeight() { - return contentHeight; - } - - /** - * @return the "content-width" property. - */ - public Length getContentWidth() { - return contentWidth; - } - - /** - * @return the "scaling" property. - */ - public int getScaling() { - return scaling; - } - - /** - * @return the "vertical-align" property. - */ - public int getVerticalAlign() { - return verticalAlign; - } - - /** - * @return the "overflow" property. - */ - public int getOverflow() { - return overflow; - } - /** * @see org.apache.fop.fo.FObj#getName() */ diff --git a/src/java/org/apache/fop/fo/pagination/Region.java b/src/java/org/apache/fop/fo/pagination/Region.java index 4980d057e..756b2be03 100644 --- a/src/java/org/apache/fop/fo/pagination/Region.java +++ b/src/java/org/apache/fop/fo/pagination/Region.java @@ -99,11 +99,11 @@ public abstract class Region extends FObj { /** * @param pageRefRect reference dimension of the page area. - * @param pageViewRectRect page view port dimensions. + * @param spm the simple page master this region belongs to. * @return the rectangle for the viewport area */ public abstract Rectangle getViewportRectangle(FODimension pageRefRect - , FODimension pageViewPortRect); + , SimplePageMaster spm); /** * Returns the default region name (xsl-region-before, xsl-region-start, diff --git a/src/java/org/apache/fop/fo/pagination/RegionAfter.java b/src/java/org/apache/fop/fo/pagination/RegionAfter.java index 68d6d066d..776f9d764 100644 --- a/src/java/org/apache/fop/fo/pagination/RegionAfter.java +++ b/src/java/org/apache/fop/fo/pagination/RegionAfter.java @@ -40,31 +40,43 @@ public class RegionAfter extends RegionBA { } /** - * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension) + * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension, SimplePageMaster) */ - public Rectangle getViewportRectangle (FODimension reldims, FODimension pageViewPortRect) { - // Depends on extent, precedence ans writing mode - /* Special rules apply to resolving extent. - * In the property subsystem the extent property is configured to - * using BLOCK_WIDTH as its percent base. - * However, depending on the writing mode extent import resolved either - * against the page width or the page height. + public Rectangle getViewportRectangle (FODimension reldims, SimplePageMaster spm) { + /* Special rules apply to resolving extent as values are resolved relative + * to the page size and reference orientation. */ - Rectangle vpRect; - SimplePercentBaseContext pageWidthContext - = new SimplePercentBaseContext(null, LengthBase.CUSTOM_BASE, pageViewPortRect.ipd); - SimplePercentBaseContext pageHeightContext - = new SimplePercentBaseContext(null, LengthBase.CUSTOM_BASE, pageViewPortRect.bpd); + SimplePercentBaseContext pageWidthContext; + SimplePercentBaseContext pageHeightContext; + if (spm.getReferenceOrientation() % 180 == 0) { + pageWidthContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageWidth().getValue()); + pageHeightContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageHeight().getValue()); + } else { + // invert width and height since top left are rotated by 90 (cl or ccl) + pageWidthContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageHeight().getValue()); + pageHeightContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageWidth().getValue()); + } SimplePercentBaseContext neighbourContext; - if (getWritingMode() == EN_LR_TB || getWritingMode() == EN_RL_TB) { + Rectangle vpRect; + if (spm.getWritingMode() == EN_LR_TB || spm.getWritingMode() == EN_RL_TB) { neighbourContext = pageWidthContext; - vpRect = new Rectangle(0, reldims.bpd - getExtent().getValue(pageHeightContext), reldims.ipd, getExtent().getValue(pageHeightContext)); + vpRect = new Rectangle(0, reldims.bpd - getExtent().getValue(pageHeightContext) + , reldims.ipd, getExtent().getValue(pageHeightContext)); } else { neighbourContext = pageHeightContext; - vpRect = new Rectangle(0, reldims.bpd - getExtent().getValue(pageWidthContext), getExtent().getValue(pageWidthContext), reldims.ipd); + vpRect = new Rectangle(0, reldims.bpd - getExtent().getValue(pageWidthContext) + , getExtent().getValue(pageWidthContext), reldims.ipd); } if (getPrecedence() == EN_FALSE) { - adjustIPD(vpRect, getWritingMode(), neighbourContext); + adjustIPD(vpRect, spm.getWritingMode(), neighbourContext); } return vpRect; } diff --git a/src/java/org/apache/fop/fo/pagination/RegionBefore.java b/src/java/org/apache/fop/fo/pagination/RegionBefore.java index c1f683c05..53279e4da 100644 --- a/src/java/org/apache/fop/fo/pagination/RegionBefore.java +++ b/src/java/org/apache/fop/fo/pagination/RegionBefore.java @@ -46,28 +46,33 @@ public class RegionBefore extends RegionBA { } /** - * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension) + * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension, SimplePageMaster) */ - public Rectangle getViewportRectangle (FODimension reldims, FODimension pageViewPortRect) { - // Depends on extent, precedence and writing mode - // This should return rectangle in writing-mode coordinates relative - // to the page-reference area rectangle - // This means the origin is (start, before) and the dimensions are (ipd,bpd) - // Before is always 0, start depends on extent - // ipd depends on precedence, bpd=extent - /* Special rules apply to resolving extent. - * In the property subsystem the extent property is configured to - * using BLOCK_WIDTH as its percent base. - * However, depending on the writing mode extent import resolved either - * against the page width or the page height. + public Rectangle getViewportRectangle (FODimension reldims, SimplePageMaster spm) { + /* Special rules apply to resolving extent as values are resolved relative + * to the page size and reference orientation. */ - Rectangle vpRect; - SimplePercentBaseContext pageWidthContext - = new SimplePercentBaseContext(null, LengthBase.CUSTOM_BASE, pageViewPortRect.ipd); - SimplePercentBaseContext pageHeightContext - = new SimplePercentBaseContext(null, LengthBase.CUSTOM_BASE, pageViewPortRect.bpd); + SimplePercentBaseContext pageWidthContext; + SimplePercentBaseContext pageHeightContext; + if (spm.getReferenceOrientation() % 180 == 0) { + pageWidthContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageWidth().getValue()); + pageHeightContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageHeight().getValue()); + } else { + // invert width and height since top left are rotated by 90 (cl or ccl) + pageWidthContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageHeight().getValue()); + pageHeightContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageWidth().getValue()); + } SimplePercentBaseContext neighbourContext; - if (getWritingMode() == EN_LR_TB || getWritingMode() == EN_RL_TB) { + Rectangle vpRect; + if (spm.getWritingMode() == EN_LR_TB || spm.getWritingMode() == EN_RL_TB) { neighbourContext = pageWidthContext; vpRect = new Rectangle(0, 0, reldims.ipd, getExtent().getValue(pageHeightContext)); } else { @@ -75,7 +80,7 @@ public class RegionBefore extends RegionBA { vpRect = new Rectangle(0, 0, getExtent().getValue(pageWidthContext), reldims.ipd); } if (getPrecedence() == EN_FALSE) { - adjustIPD(vpRect, getWritingMode(), neighbourContext); + adjustIPD(vpRect, spm.getWritingMode(), neighbourContext); } return vpRect; } diff --git a/src/java/org/apache/fop/fo/pagination/RegionBody.java b/src/java/org/apache/fop/fo/pagination/RegionBody.java index 835802469..855b2747f 100644 --- a/src/java/org/apache/fop/fo/pagination/RegionBody.java +++ b/src/java/org/apache/fop/fo/pagination/RegionBody.java @@ -63,13 +63,14 @@ public class RegionBody extends Region { * these cases, but we will need to be able to change Numeric * values in order to do this. */ - attributeError("If overflow property is set to \"scroll\"," + - " a column-count other than \"1\" may not be specified."); + attributeError("If overflow property is set to \"scroll\"," + + " a column-count other than \"1\" may not be specified."); } } /** * Return the Common Margin Properties-Block. + * @return the Common Margin Properties-Block. */ public CommonMarginBlock getCommonMarginBlock() { return commonMarginBlock; @@ -77,6 +78,7 @@ public class RegionBody extends Region { /** * Return the "column-count" property. + * @return the "column-count" property. */ public int getColumnCount() { return columnCount.getValue(); @@ -84,35 +86,60 @@ public class RegionBody extends Region { /** * Return the "column-gap" property. + * @return the "column-gap" property. */ public int getColumnGap() { return columnGap.getValue(); } /** - * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension) + * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension, SimplePageMaster) */ - public Rectangle getViewportRectangle (FODimension reldims, FODimension pageViewPortRect) { + public Rectangle getViewportRectangle (FODimension reldims, SimplePageMaster spm) { /* Special rules apply to resolving margins in the page context. * Contrary to normal margins in this case top and bottom margin * are resolved relative to the height. In the property subsystem * all margin properties are configured to using BLOCK_WIDTH. * That's why we 'cheat' here and setup a context for the height but * use the LengthBase.BLOCK_WIDTH. - * Also the values are resolved relative to the page size. + * Also the values are resolved relative to the page size + * and reference orientation. */ - SimplePercentBaseContext pageWidthContext - = new SimplePercentBaseContext(null, LengthBase.CONTAINING_BLOCK_WIDTH, pageViewPortRect.ipd); - SimplePercentBaseContext pageHeightContext - = new SimplePercentBaseContext(null, LengthBase.CONTAINING_BLOCK_WIDTH, pageViewPortRect.bpd); + SimplePercentBaseContext pageWidthContext; + SimplePercentBaseContext pageHeightContext; + if (spm.getReferenceOrientation() % 180 == 0) { + pageWidthContext = new SimplePercentBaseContext(null, + LengthBase.CONTAINING_BLOCK_WIDTH, + spm.getPageWidth().getValue()); + pageHeightContext = new SimplePercentBaseContext(null, + LengthBase.CONTAINING_BLOCK_WIDTH, + spm.getPageHeight().getValue()); + } else { + // invert width and height since top left are rotated by 90 (cl or ccl) + pageWidthContext = new SimplePercentBaseContext(null, + LengthBase.CONTAINING_BLOCK_WIDTH, + spm.getPageHeight().getValue()); + pageHeightContext = new SimplePercentBaseContext(null, + LengthBase.CONTAINING_BLOCK_WIDTH, + spm.getPageWidth().getValue()); + } - int left = commonMarginBlock.marginLeft.getValue(pageWidthContext); - int right = commonMarginBlock.marginRight.getValue(pageWidthContext); - int top = commonMarginBlock.marginTop.getValue(pageHeightContext); - int bottom = commonMarginBlock.marginBottom.getValue(pageHeightContext); - return new Rectangle(left, top, - reldims.ipd - left - right, - reldims.bpd - top - bottom); + int start; + int end; + if (spm.getWritingMode() == EN_LR_TB) { // Left-to-right + start = commonMarginBlock.marginLeft.getValue(pageWidthContext); + end = commonMarginBlock.marginRight.getValue(pageWidthContext); + } else { // all other supported modes are right-to-left + start = commonMarginBlock.marginRight.getValue(pageWidthContext); + end = commonMarginBlock.marginLeft.getValue(pageWidthContext); + } + int before = commonMarginBlock.spaceBefore.getOptimum(pageHeightContext) + .getLength().getValue(pageHeightContext); + int after = commonMarginBlock.spaceAfter.getOptimum(pageHeightContext) + .getLength().getValue(pageHeightContext); + return new Rectangle(start, before, + reldims.ipd - start - end, + reldims.bpd - before - after); } /** diff --git a/src/java/org/apache/fop/fo/pagination/RegionEnd.java b/src/java/org/apache/fop/fo/pagination/RegionEnd.java index a097ec375..eadc08992 100644 --- a/src/java/org/apache/fop/fo/pagination/RegionEnd.java +++ b/src/java/org/apache/fop/fo/pagination/RegionEnd.java @@ -39,23 +39,33 @@ public class RegionEnd extends RegionSE { } /** - * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension) + * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension, SimplePageMaster) */ - public Rectangle getViewportRectangle (FODimension reldims, FODimension pageViewPortRect) { - // Depends on extent, precedence and writing mode - /* Special rules apply to resolving extent. - * In the property subsystem the extent property is configured to - * using BLOCK_WIDTH as its percent base. - * However, depending on the writing mode extent import resolved either - * against the page width or the page height. + public Rectangle getViewportRectangle (FODimension reldims, SimplePageMaster spm) { + /* Special rules apply to resolving extent as values are resolved relative + * to the page size and reference orientation. */ - Rectangle vpRect; - SimplePercentBaseContext pageWidthContext - = new SimplePercentBaseContext(null, LengthBase.CUSTOM_BASE, pageViewPortRect.ipd); - SimplePercentBaseContext pageHeightContext - = new SimplePercentBaseContext(null, LengthBase.CUSTOM_BASE, pageViewPortRect.bpd); + SimplePercentBaseContext pageWidthContext; + SimplePercentBaseContext pageHeightContext; + if (spm.getReferenceOrientation() % 180 == 0) { + pageWidthContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageWidth().getValue()); + pageHeightContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageHeight().getValue()); + } else { + // invert width and height since top left are rotated by 90 (cl or ccl) + pageWidthContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageHeight().getValue()); + pageHeightContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageWidth().getValue()); + } SimplePercentBaseContext neighbourContext; - if (getWritingMode() == EN_LR_TB || getWritingMode() == EN_RL_TB) { + Rectangle vpRect; + if (spm.getWritingMode() == EN_LR_TB || spm.getWritingMode() == EN_RL_TB) { neighbourContext = pageHeightContext; vpRect = new Rectangle(reldims.ipd - getExtent().getValue(pageWidthContext), 0, getExtent().getValue(pageWidthContext), reldims.bpd); @@ -65,7 +75,7 @@ public class RegionEnd extends RegionSE { vpRect = new Rectangle(reldims.ipd - getExtent().getValue(pageHeightContext), 0, reldims.bpd, getExtent().getValue(pageHeightContext)); } - adjustIPD(vpRect, getWritingMode(), neighbourContext); + adjustIPD(vpRect, spm.getWritingMode(), neighbourContext); return vpRect; } diff --git a/src/java/org/apache/fop/fo/pagination/RegionStart.java b/src/java/org/apache/fop/fo/pagination/RegionStart.java index 2de7cc68f..2d74069bc 100644 --- a/src/java/org/apache/fop/fo/pagination/RegionStart.java +++ b/src/java/org/apache/fop/fo/pagination/RegionStart.java @@ -39,32 +39,40 @@ public class RegionStart extends RegionSE { } /** - * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension) + * @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension, SimplePageMaster) */ - public Rectangle getViewportRectangle (FODimension reldims, FODimension pageViewPortRect) { - // Depends on extent, precedence and writing mode - // This is the rectangle relative to the page-reference area in - // writing-mode relative coordinates - /* Special rules apply to resolving extent. - * In the property subsystem the extent property is configured to - * using BLOCK_WIDTH as its percent base. - * However, depending on the writing mode extent import resolved either - * against the page width or the page height. + public Rectangle getViewportRectangle (FODimension reldims, SimplePageMaster spm) { + /* Special rules apply to resolving extent as values are resolved relative + * to the page size and reference orientation. */ - Rectangle vpRect; - SimplePercentBaseContext pageWidthContext - = new SimplePercentBaseContext(null, LengthBase.CUSTOM_BASE, pageViewPortRect.ipd); - SimplePercentBaseContext pageHeightContext - = new SimplePercentBaseContext(null, LengthBase.CUSTOM_BASE, pageViewPortRect.bpd); + SimplePercentBaseContext pageWidthContext; + SimplePercentBaseContext pageHeightContext; + if (spm.getReferenceOrientation() % 180 == 0) { + pageWidthContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageWidth().getValue()); + pageHeightContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageHeight().getValue()); + } else { + // invert width and height since top left are rotated by 90 (cl or ccl) + pageWidthContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageHeight().getValue()); + pageHeightContext = new SimplePercentBaseContext(null, + LengthBase.CUSTOM_BASE, + spm.getPageWidth().getValue()); + } SimplePercentBaseContext neighbourContext; - if (getWritingMode() == EN_LR_TB || getWritingMode() == EN_RL_TB) { + Rectangle vpRect; + if (spm.getWritingMode() == EN_LR_TB || spm.getWritingMode() == EN_RL_TB) { neighbourContext = pageHeightContext; vpRect = new Rectangle(0, 0, getExtent().getValue(pageWidthContext), reldims.bpd); } else { neighbourContext = pageWidthContext; vpRect = new Rectangle(0, 0, reldims.bpd, getExtent().getValue(pageHeightContext)); } - adjustIPD(vpRect, getWritingMode(), neighbourContext); + adjustIPD(vpRect, spm.getWritingMode(), neighbourContext); return vpRect; } diff --git a/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java new file mode 100644 index 000000000..ec36508f2 --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java @@ -0,0 +1,308 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.layoutmgr.inline; + +import java.awt.geom.Rectangle2D; +import java.util.LinkedList; + +import org.apache.fop.area.Area; +import org.apache.fop.area.inline.InlineArea; +import org.apache.fop.area.inline.Viewport; +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.LengthBase; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.flow.AbstractGraphics; +import org.apache.fop.fo.properties.CommonBorderPaddingBackground; +import org.apache.fop.layoutmgr.LayoutContext; +import org.apache.fop.layoutmgr.TraitSetter; + + +/** + * LayoutManager handling the common tasks for the fo:instream-foreign-object + * and fo:external-graphics formatting objects + */ +public abstract class AbstractGraphicsLayoutManager extends LeafNodeLayoutManager { + + protected AbstractGraphics fobj; + + /** + * Constructor + * @param node the formatting object that creates this area + * @param parent the parent layout manager + */ + public AbstractGraphicsLayoutManager(AbstractGraphics node) { + super(node); + fobj = node; + } + + /** + * Get the inline area created by this element. + * + * @return the viewport inline area + */ + private Viewport getInlineArea() { + + // viewport size is determined by block-progression-dimension + // and inline-progression-dimension + + // if replaced then use height then ignore block-progression-dimension + //int h = this.propertyList.get("height").getLength().mvalue(); + + // use specified line-height then ignore dimension in height direction + boolean hasLH = false; //propertyList.get("line-height").getSpecifiedValue() != null; + + Length len; + + int bpd = -1; + int ipd = -1; + boolean bpdauto = false; + if (hasLH) { + bpd = fobj.getLineHeight().getValue(this); + } else { + // this property does not apply when the line-height applies + // isn't the block-progression-dimension always in the same + // direction as the line height? + len = fobj.getBlockProgressionDimension().getOptimum(this).getLength(); + if (len.getEnum() != EN_AUTO) { + bpd = len.getValue(this); + } else { + len = fobj.getHeight(); + if (len.getEnum() != EN_AUTO) { + bpd = len.getValue(this); + } + } + } + + len = fobj.getInlineProgressionDimension().getOptimum(this).getLength(); + if (len.getEnum() != EN_AUTO) { + ipd = len.getValue(this); + } else { + len = fobj.getWidth(); + if (len.getEnum() != EN_AUTO) { + ipd = len.getValue(this); + } + } + + // if auto then use the intrinsic size of the content scaled + // to the content-height and content-width + int cwidth = -1; + int cheight = -1; + len = fobj.getContentWidth(); + if (len.getEnum() != EN_AUTO) { + if (len.getEnum() == EN_SCALE_TO_FIT) { + if (ipd != -1) { + cwidth = ipd; + } + } else { + cwidth = len.getValue(this); + } + } + len = fobj.getContentHeight(); + if (len.getEnum() != EN_AUTO) { + if (len.getEnum() == EN_SCALE_TO_FIT) { + if (bpd != -1) { + cwidth = bpd; + } + } else { + cheight = len.getValue(this); + } + } + + int scaling = fobj.getScaling(); + if ((scaling == EN_UNIFORM) || (cwidth == -1) || cheight == -1) { + if (cwidth == -1 && cheight == -1) { + cwidth = fobj.getIntrinsicWidth(); + cheight = fobj.getIntrinsicHeight(); + } else if (cwidth == -1) { + cwidth = (int)(fobj.getIntrinsicWidth() * (double)cheight + / fobj.getIntrinsicHeight()); + } else if (cheight == -1) { + cheight = (int)(fobj.getIntrinsicHeight() * (double)cwidth + / fobj.getIntrinsicWidth()); + } else { + // adjust the larger + double rat1 = cwidth / fobj.getIntrinsicWidth(); + double rat2 = cheight / fobj.getIntrinsicHeight(); + if (rat1 < rat2) { + // reduce cheight + cheight = (int)(rat1 * fobj.getIntrinsicHeight()); + } else if (rat1 > rat2) { + cwidth = (int)(rat2 * fobj.getIntrinsicWidth()); + } + } + } + + if (ipd == -1) { + ipd = cwidth; + } + if (bpd == -1) { + bpd = cheight; + } + + boolean clip = false; + if (cwidth > ipd || cheight > bpd) { + int overflow = fobj.getOverflow(); + if (overflow == EN_HIDDEN) { + clip = true; + } else if (overflow == EN_ERROR_IF_OVERFLOW) { + fobj.getLogger().error("Object overflows the viewport: clipping"); + clip = true; + } + } + + int xoffset = fobj.computeXOffset(ipd, cwidth); + int yoffset = fobj.computeYOffset(bpd, cheight); + + CommonBorderPaddingBackground borderProps = fobj.getCommonBorderPaddingBackground(); + + //Determine extra BPD from borders etc. + int beforeBPD = borderProps.getPadding(CommonBorderPaddingBackground.BEFORE, false, this); + beforeBPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.BEFORE, + false); + int afterBPD = borderProps.getPadding(CommonBorderPaddingBackground.AFTER, false, this); + afterBPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.AFTER, false); + + yoffset += beforeBPD; + //bpd += beforeBPD; + //bpd += afterBPD; + + //Determine extra IPD from borders etc. + int startIPD = borderProps.getPadding(CommonBorderPaddingBackground.START, + false/*bNotFirst*/, this); + startIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.START, + false/*bNotFirst*/); + int endIPD = borderProps.getPadding(CommonBorderPaddingBackground.END, false/*bNotLast*/, this); + endIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.END, false/*bNotLast*/); + + xoffset += startIPD; + //ipd += startIPD; + //ipd += endIPD; + + Rectangle2D placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight); + + Area viewportArea = getChildArea(); + TraitSetter.setProducerID(viewportArea, fobj.getId()); + + Viewport vp = new Viewport(viewportArea); + TraitSetter.setProducerID(vp, fobj.getId()); + vp.setIPD(ipd); + vp.setBPD(bpd); + vp.setContentPosition(placement); + vp.setClip(clip); + vp.setOffset(0); + + // Common Border, Padding, and Background Properties + TraitSetter.addBorders(vp, fobj.getCommonBorderPaddingBackground(), this); + TraitSetter.addBackground(vp, fobj.getCommonBorderPaddingBackground(), this); + + return vp; + } + + /** + * @see org.apache.fop.layoutmgr.LayoutManager#getNextKnuthElements(LayoutContext, int) + */ + public LinkedList getNextKnuthElements(LayoutContext context, + int alignment) { + Viewport areaCurrent = getInlineArea(); + setCurrentArea(areaCurrent); + setAlignment(fobj.getVerticalAlign()); + setLead(areaCurrent.getAllocBPD()); + return super.getNextKnuthElements(context, alignment); + } + + /** + * @see org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager#addId() + */ + protected void addId() { + getPSLM().addIDToPage(fobj.getId()); + } + + /** + * Offset this area. + * Offset the inline area in the bpd direction when adding the + * inline area. + * This is used for vertical alignment. + * External graphic uses the large allocation rectangle so we have + * to take the border/padding into account as well. + * @param area the inline area to be updated + * @param context the layout context used for adding the area + * @see LeafNodeLayoutManager#offsetArea(InlineArae, LayoutContext) + */ + protected void offsetArea(InlineArea area, LayoutContext context) { + int bpd = area.getBPD() + + area.getBorderAndPaddingWidthBefore() + + area.getBorderAndPaddingWidthAfter(); + switch (verticalAlignment) { + case EN_MIDDLE: + area.setOffset(context.getMiddleBaseline() - bpd / 2); + break; + case EN_TOP: + area.setOffset(context.getTopBaseline()); + break; + case EN_BOTTOM: + area.setOffset(context.getBottomBaseline() - bpd); + break; + case EN_BASELINE: + default: + area.setOffset(context.getBaseline() - bpd); + break; + } + } + + /** + * Returns the image of foreign object area to be put into + * the viewport. + * @return the appropriate area + */ + abstract Area getChildArea(); + + // --------- Property Resolution related functions --------- // + + /** + * @see org.apache.fop.datatypes.PercentBaseContext#getBaseLength(int, FObj) + */ + public int getBaseLength(int lengthBase, FObj fobj) { + switch (lengthBase) { + case LengthBase.IMAGE_INTRINSIC_WIDTH: + return getIntrinsicWidth(); + case LengthBase.IMAGE_INTRINSIC_HEIGHT: + return getIntrinsicHeight(); + default: // Delegate to super class + return super.getBaseLength(lengthBase, fobj); + } + } + + /** + * Returns the intrinsic width of the e-g. + * @return the width of the element + */ + protected int getIntrinsicWidth() { + return fobj.getIntrinsicWidth(); + } + + /** + * Returns the intrinsic height of the e-g. + * @return the height of the element + */ + protected int getIntrinsicHeight() { + return fobj.getIntrinsicHeight(); + } + +} + diff --git a/src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java index b31b5ea04..e6ddcffbd 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/ExternalGraphicLayoutManager.java @@ -18,41 +18,19 @@ package org.apache.fop.layoutmgr.inline; -// Java import java.awt.geom.Rectangle2D; -import java.util.LinkedList; - -// FOP +import org.apache.fop.area.Area; import org.apache.fop.area.inline.Image; -import org.apache.fop.area.inline.InlineArea; -import org.apache.fop.area.inline.Viewport; -import org.apache.fop.datatypes.Length; -import org.apache.fop.datatypes.LengthBase; -import org.apache.fop.fo.FObj; import org.apache.fop.fo.flow.ExternalGraphic; -import org.apache.fop.fo.properties.CommonBorderPaddingBackground; -import org.apache.fop.layoutmgr.LayoutContext; -import org.apache.fop.layoutmgr.TraitSetter; + /** * LayoutManager for the fo:external-graphic formatting object */ -public class ExternalGraphicLayoutManager extends LeafNodeLayoutManager { +public class ExternalGraphicLayoutManager extends AbstractGraphicsLayoutManager { private ExternalGraphic fobj; - private int breakAfter; - private int breakBefore; - private int align; - private int startIndent; - private int endIndent; - private int spaceBefore; - private int spaceAfter; - private int viewWidth = -1; - private int viewHeight = -1; - private boolean clip = false; - private Rectangle2D placement = null; - /** * Constructor * @@ -68,6 +46,7 @@ public class ExternalGraphicLayoutManager extends LeafNodeLayoutManager { * This gets the sizes for the image and the dimensions and clipping. * @todo see if can simplify property handling logic */ + /* private void setup() { // assume lr-tb for now and just use the .optimum value of the range Length ipd = fobj.getInlineProgressionDimension().getOptimum(this).getLength(); @@ -195,97 +174,35 @@ public class ExternalGraphicLayoutManager extends LeafNodeLayoutManager { afterBPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.AFTER, false); yoffset += beforeBPD; + viewBPD = viewHeight; viewHeight += beforeBPD; viewHeight += afterBPD; //Determine extra IPD from borders etc. int startIPD = borderProps.getPadding(CommonBorderPaddingBackground.START, - false/*bNotFirst*/, this); + false, this); startIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.START, - false/*bNotFirst*/); - int endIPD = borderProps.getPadding(CommonBorderPaddingBackground.END, false/*bNotLast*/, this); - endIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.END, false/*bNotLast*/); + false); + int endIPD = borderProps.getPadding(CommonBorderPaddingBackground.END, false, this); + endIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.END, false); xoffset += startIPD; + viewIPD = viewWidth; viewWidth += startIPD; viewWidth += endIPD; placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight); } - - /** - * @see org.apache.fop.layoutmgr.LayoutManager#getNextKnuthElements(LayoutContext, int) - */ - public LinkedList getNextKnuthElements(LayoutContext context, - int alignment) { - setup(); - InlineArea area = getExternalGraphicInlineArea(); - setCurrentArea(area); - setAlignment(fobj.getVerticalAlign()); - setLead(viewHeight); - return super.getNextKnuthElements(context, alignment); - } - - /** - * Get the inline area for this external grpahic. - * This creates the image area and puts it inside a viewport. - * - * @return the viewport containing the image area - */ - public InlineArea getExternalGraphicInlineArea() { - Image imArea = new Image(fobj.getSrc()); - TraitSetter.setProducerID(imArea, fobj.getId()); - Viewport vp = new Viewport(imArea); - TraitSetter.setProducerID(vp, fobj.getId()); - vp.setIPD(viewWidth); - vp.setBPD(viewHeight); - vp.setClip(clip); - vp.setContentPosition(placement); - vp.setOffset(0); - - // Common Border, Padding, and Background Properties - TraitSetter.addBorders(vp, fobj.getCommonBorderPaddingBackground(), this); - TraitSetter.addBackground(vp, fobj.getCommonBorderPaddingBackground(), this); - - return vp; - } - - /** @see org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager#addId() */ - protected void addId() { - getPSLM().addIDToPage(fobj.getId()); - } - - // --------- Property Resolution related functions --------- // + */ /** - * @see org.apache.fop.datatypes.PercentBaseContext#getBaseLength(int, FObj) - */ - public int getBaseLength(int lengthBase, FObj fobj) { - switch (lengthBase) { - case LengthBase.IMAGE_INTRINSIC_WIDTH: - return getIntrinsicWidth(); - case LengthBase.IMAGE_INTRINSIC_HEIGHT: - return getIntrinsicHeight(); - default: // Delegate to super class - return super.getBaseLength(lengthBase, fobj); - } - } - - /** - * Returns the intrinsic width of the e-g. - * @return the width of the element - */ - protected int getIntrinsicWidth() { - return fobj.getIntrinsicWidth(); - } - - /** - * Returns the intrinsic height of the e-g. - * @return the height of the element + * Get the inline area created by this element. + * + * @return the inline area */ - protected int getIntrinsicHeight() { - return fobj.getIntrinsicHeight(); + protected Area getChildArea() { + return new Image(fobj.getSrc()); } - + } diff --git a/src/java/org/apache/fop/layoutmgr/inline/InstreamForeignObjectLM.java b/src/java/org/apache/fop/layoutmgr/inline/InstreamForeignObjectLM.java index 995bfc6c2..4a6865543 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/InstreamForeignObjectLM.java +++ b/src/java/org/apache/fop/layoutmgr/inline/InstreamForeignObjectLM.java @@ -18,33 +18,21 @@ package org.apache.fop.layoutmgr.inline; -// Java -import java.awt.geom.Rectangle2D; -import java.util.LinkedList; - -// FOP -import org.apache.fop.datatypes.Length; -import org.apache.fop.datatypes.LengthBase; +import org.apache.fop.area.Area; +import org.apache.fop.area.inline.ForeignObject; import org.apache.fop.fo.XMLObj; import org.apache.fop.fo.flow.InstreamForeignObject; -import org.apache.fop.fo.properties.CommonBorderPaddingBackground; -import org.apache.fop.layoutmgr.TraitSetter; -import org.apache.fop.area.inline.ForeignObject; -import org.apache.fop.area.inline.Viewport; -import org.apache.fop.fo.FObj; -import org.apache.fop.layoutmgr.LayoutContext; /** * LayoutManager for the fo:instream-foreign-object formatting object */ -public class InstreamForeignObjectLM extends LeafNodeLayoutManager { +public class InstreamForeignObjectLM extends AbstractGraphicsLayoutManager { private InstreamForeignObject fobj; /** * Constructor * @param node the formatting object that creates this area - * @param parent the parent layout manager */ public InstreamForeignObjectLM(InstreamForeignObject node) { super(node); @@ -54,221 +42,16 @@ public class InstreamForeignObjectLM extends LeafNodeLayoutManager { /** * Get the inline area created by this element. * - * @return the viewport inline area + * @return the inline area */ - private Viewport getInlineArea() { + protected Area getChildArea() { XMLObj child = (XMLObj) fobj.getChildXMLObj(); - // viewport size is determined by block-progression-dimension - // and inline-progression-dimension - - // if replaced then use height then ignore block-progression-dimension - //int h = this.propertyList.get("height").getLength().mvalue(); - - // use specified line-height then ignore dimension in height direction - boolean hasLH = false; //propertyList.get("line-height").getSpecifiedValue() != null; - - Length len; - - int bpd = -1; - int ipd = -1; - boolean bpdauto = false; - if (hasLH) { - bpd = fobj.getLineHeight().getValue(this); - } else { - // this property does not apply when the line-height applies - // isn't the block-progression-dimension always in the same - // direction as the line height? - len = fobj.getBlockProgressionDimension().getOptimum(this).getLength(); - if (len.getEnum() != EN_AUTO) { - bpd = len.getValue(this); - } else { - len = fobj.getHeight(); - if (len.getEnum() != EN_AUTO) { - bpd = len.getValue(this); - } - } - } - - len = fobj.getInlineProgressionDimension().getOptimum(this).getLength(); - if (len.getEnum() != EN_AUTO) { - ipd = len.getValue(this); - } else { - len = fobj.getWidth(); - if (len.getEnum() != EN_AUTO) { - ipd = len.getValue(this); - } - } - - // if auto then use the intrinsic size of the content scaled - // to the content-height and content-width - int cwidth = -1; - int cheight = -1; - len = fobj.getContentWidth(); - if (len.getEnum() != EN_AUTO) { - if (len.getEnum() == EN_SCALE_TO_FIT) { - if (ipd != -1) { - cwidth = ipd; - } - } else { - cwidth = len.getValue(this); - } - } - len = fobj.getContentHeight(); - if (len.getEnum() != EN_AUTO) { - if (len.getEnum() == EN_SCALE_TO_FIT) { - if (bpd != -1) { - cwidth = bpd; - } - } else { - cheight = len.getValue(this); - } - } - - int scaling = fobj.getScaling(); - if ((scaling == EN_UNIFORM) || (cwidth == -1) || cheight == -1) { - if (cwidth == -1 && cheight == -1) { - cwidth = fobj.getIntrinsicWidth(); - cheight = fobj.getIntrinsicHeight(); - } else if (cwidth == -1) { - cwidth = (int)(fobj.getIntrinsicWidth() * (double)cheight - / fobj.getIntrinsicHeight()); - } else if (cheight == -1) { - cheight = (int)(fobj.getIntrinsicHeight() * (double)cwidth - / fobj.getIntrinsicWidth()); - } else { - // adjust the larger - double rat1 = cwidth / fobj.getIntrinsicWidth(); - double rat2 = cheight / fobj.getIntrinsicHeight(); - if (rat1 < rat2) { - // reduce cheight - cheight = (int)(rat1 * fobj.getIntrinsicHeight()); - } else if (rat1 > rat2) { - cwidth = (int)(rat2 * fobj.getIntrinsicWidth()); - } - } - } - - if (ipd == -1) { - ipd = cwidth; - } - if (bpd == -1) { - bpd = cheight; - } - - boolean clip = false; - if (cwidth > ipd || cheight > bpd) { - int overflow = fobj.getOverflow(); - if (overflow == EN_HIDDEN) { - clip = true; - } else if (overflow == EN_ERROR_IF_OVERFLOW) { - fobj.getLogger().error("Instream foreign object overflows the viewport: clipping"); - clip = true; - } - } - - int xoffset = fobj.computeXOffset(ipd, cwidth); - int yoffset = fobj.computeYOffset(bpd, cheight); - - CommonBorderPaddingBackground borderProps = fobj.getCommonBorderPaddingBackground(); - - //Determine extra BPD from borders etc. - int beforeBPD = borderProps.getPadding(CommonBorderPaddingBackground.BEFORE, false, this); - beforeBPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.BEFORE, - false); - int afterBPD = borderProps.getPadding(CommonBorderPaddingBackground.AFTER, false, this); - afterBPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.AFTER, false); - - yoffset += beforeBPD; - bpd += beforeBPD; - bpd += afterBPD; - - //Determine extra IPD from borders etc. - int startIPD = borderProps.getPadding(CommonBorderPaddingBackground.START, - false/*bNotFirst*/, this); - startIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.START, - false/*bNotFirst*/); - int endIPD = borderProps.getPadding(CommonBorderPaddingBackground.END, false/*bNotLast*/, this); - endIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.END, false/*bNotLast*/); - - xoffset += startIPD; - ipd += startIPD; - ipd += endIPD; - - Rectangle2D placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight); - org.w3c.dom.Document doc = child.getDOMDocument(); String ns = child.getDocumentNamespace(); - //fobj.childNodes = null; This is bad for i-f-o in static-content!!!!! - ForeignObject foreign = new ForeignObject(doc, ns); - TraitSetter.setProducerID(foreign, fobj.getId()); - - Viewport vp = new Viewport(foreign); - TraitSetter.setProducerID(vp, fobj.getId()); - vp.setIPD(ipd); - vp.setBPD(bpd); - vp.setContentPosition(placement); - vp.setClip(clip); - vp.setOffset(0); - - // Common Border, Padding, and Background Properties - TraitSetter.addBorders(vp, fobj.getCommonBorderPaddingBackground(), this); - TraitSetter.addBackground(vp, fobj.getCommonBorderPaddingBackground(), this); - - return vp; - } - - /** - * @see org.apache.fop.layoutmgr.LayoutManager#getNextKnuthElements(LayoutContext, int) - */ - public LinkedList getNextKnuthElements(LayoutContext context, - int alignment) { - Viewport areaCurrent = getInlineArea(); - setCurrentArea(areaCurrent); - setAlignment(fobj.getVerticalAlign()); - setLead(areaCurrent.getBPD()); - return super.getNextKnuthElements(context, alignment); - } - - /** - * @see org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager#addId() - */ - protected void addId() { - getPSLM().addIDToPage(fobj.getId()); + return new ForeignObject(doc, ns); } - - // --------- Property Resolution related functions --------- // - /** - * @see org.apache.fop.datatypes.PercentBaseContext#getBaseLength(int, FObj) - */ - public int getBaseLength(int lengthBase, FObj fobj) { - switch (lengthBase) { - case LengthBase.IMAGE_INTRINSIC_WIDTH: - return getIntrinsicWidth(); - case LengthBase.IMAGE_INTRINSIC_HEIGHT: - return getIntrinsicHeight(); - default: // Delegate to super class - return super.getBaseLength(lengthBase, fobj); - } - } - - /** - * Returns the intrinsic width of the e-g. - * @return the width of the element - */ - protected int getIntrinsicWidth() { - return fobj.getIntrinsicWidth(); - } - - /** - * Returns the intrinsic height of the e-g. - * @return the height of the element - */ - protected int getIntrinsicHeight() { - return fobj.getIntrinsicHeight(); - } - } diff --git a/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java b/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java index 398ba939f..a89ee7383 100644 --- a/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java +++ b/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java @@ -187,8 +187,11 @@ public abstract class AbstractPathOrientedRenderer extends PrintRenderer { for (int y = 0; y < vertCount; y++) { // place once Rectangle2D pos; - pos = new Rectangle2D.Float(sx + (x * fopimage.getIntrinsicWidth()), - sy + (y * fopimage.getIntrinsicHeight()), + // Image positions are relative to the currentIP/BP + pos = new Rectangle2D.Float(sx - currentIPPosition + + (x * fopimage.getIntrinsicWidth()), + sy - currentBPPosition + + (y * fopimage.getIntrinsicHeight()), fopimage.getIntrinsicWidth(), fopimage.getIntrinsicHeight()); drawImage(back.getURL(), pos); diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java index 9622ecc87..ba395c984 100644 --- a/src/java/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java @@ -375,6 +375,7 @@ public class XMLRenderer extends PrintRenderer { atts.clear(); addAreaAttributes(region); addTraitAttributes(region); + addAttribute("ctm", region.getCTM().toString()); if (region.getRegionClass() == FO_REGION_BEFORE) { startElement("regionBefore", atts); renderRegion(region); @@ -524,6 +525,7 @@ public class XMLRenderer extends PrintRenderer { atts.clear(); addAreaAttributes(viewport); addTraitAttributes(viewport); + addAttribute("offset", viewport.getOffset()); startElement("viewport", atts); super.renderViewport(viewport); endElement("viewport"); @@ -554,6 +556,8 @@ public class XMLRenderer extends PrintRenderer { /** * Renders an fo:foreing-object. * @param fo the foreign object + * @param pos the position of the foreign object + * @see org.apache.fop.render.AbstractRenderer#renderForeignObject(ForeignObject, Rectangle2D) */ public void renderForeignObject(ForeignObject fo, Rectangle2D pos) { atts.clear(); @@ -622,6 +626,9 @@ public class XMLRenderer extends PrintRenderer { endElement("inlineparent"); } + /** + * @see org.apache.fop.render.AbstractRenderer#renderInlineBlockParent(InlineBlockParent) + */ protected void renderInlineBlockParent(InlineBlockParent ibp) { atts.clear(); addAreaAttributes(ibp); |