diff options
author | Jeremias Maerki <jeremias@apache.org> | 2004-12-28 18:03:12 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2004-12-28 18:03:12 +0000 |
commit | 73a83df9636693496269245c4f0b5fcd56aae0b1 (patch) | |
tree | 15d30059f8b317d5945d26c83d137e59b7f06490 /src/java/org/apache/fop/fo | |
parent | bf98519aaaaeeb247aa87403b021d46896f469c5 (diff) | |
download | xmlgraphics-fop-73a83df9636693496269245c4f0b5fcd56aae0b1.tar.gz xmlgraphics-fop-73a83df9636693496269245c4f0b5fcd56aae0b1.zip |
Support for percentages on external-graphic and instream-foreign-object for the content-height and content-width attributes.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198215 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/fo')
4 files changed, 150 insertions, 5 deletions
diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java index 14878037f..127e2668d 100644 --- a/src/java/org/apache/fop/fo/FOPropertyMapping.java +++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java @@ -1418,6 +1418,7 @@ public class FOPropertyMapping implements Constants { l.addEnum("auto", makeEnumProperty(EN_AUTO, "AUTO")); l.addEnum("scale-to-fit", makeEnumProperty(EN_SCALE_TO_FIT, "SCALE_TO_FIT")); l.setDefault("auto"); + l.setPercentBase(LengthBase.IMAGE_INTRINSIC_HEIGHT); addPropertyMaker("content-height", l); // content-width @@ -1426,6 +1427,7 @@ public class FOPropertyMapping implements Constants { l.addEnum("auto", makeEnumProperty(EN_AUTO, "AUTO")); l.addEnum("scale-to-fit", makeEnumProperty(EN_SCALE_TO_FIT, "SCALE_TO_FIT")); l.setDefault("auto"); + l.setPercentBase(LengthBase.IMAGE_INTRINSIC_WIDTH); addPropertyMaker("content-width", l); // height diff --git a/src/java/org/apache/fop/fo/IntrinsicSizeAccess.java b/src/java/org/apache/fop/fo/IntrinsicSizeAccess.java new file mode 100644 index 000000000..07e2e2afa --- /dev/null +++ b/src/java/org/apache/fop/fo/IntrinsicSizeAccess.java @@ -0,0 +1,37 @@ +/* + * Copyright 2004 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; + +/** + * This interface defines the interface for LengthBase to access the intrinsic + * size of an image (for external-graphic and instream-foreign-object). + */ +public interface IntrinsicSizeAccess { + + /** + * @return the intrinsic width of an image (in millipoints). + */ + int getIntrinsicWidth(); + + /** + * @return the intrinsic height of an image (in millipoints). + */ + 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 55c5a567d..7d609028e 100644 --- a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java +++ b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java @@ -27,6 +27,7 @@ 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.IntrinsicSizeAccess; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; import org.apache.fop.fo.properties.CommonAccessibility; @@ -36,6 +37,8 @@ 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.apache.fop.layoutmgr.ExternalGraphicLayoutManager; /** @@ -43,7 +46,8 @@ import org.apache.fop.layoutmgr.ExternalGraphicLayoutManager; * 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 FObj implements IntrinsicSizeAccess { + // The value of properties relevant for fo:external-graphic. private CommonAccessibility commonAccessibility; private CommonAural commonAural; @@ -75,6 +79,10 @@ public class ExternalGraphic extends FObj { private Length width; // End of property values + //Additional values + private String url; + private FopImage fopimage; + /** * Create a new External graphic node. * @@ -116,6 +124,9 @@ public class ExternalGraphic extends FObj { textAlign = pList.get(PR_TEXT_ALIGN).getEnum(); verticalAlign = pList.get(PR_VERTICAL_ALIGN).getEnum(); width = pList.get(PR_WIDTH).getLength(); + + //Additional processing + url = ImageFactory.getURL(getSrc()); } /** @@ -220,6 +231,13 @@ public class ExternalGraphic extends FObj { } /** + * @return Get the resulting URL based on the src property. + */ + public String getURL() { + return url; + } + + /** * Return the "text-align" property. */ public int getTextAlign() { @@ -253,4 +271,48 @@ public class ExternalGraphic extends FObj { public int getNameId() { return FO_EXTERNAL_GRAPHIC; } + + /** + * Preloads the image so the intrinsic size is available. + */ + private void prepareIntrinsicSize() { + if (fopimage == null) { + ImageFactory fact = ImageFactory.getInstance(); + fopimage = fact.getImage(getURL(), getUserAgent()); + if (fopimage == null) { + getLogger().error("Image not available: " + getURL()); + } else { + // load dimensions + if (!fopimage.load(FopImage.DIMENSIONS)) { + getLogger().error("Cannot read image dimensions: " + getURL()); + } + } + //TODO Report to caller so he can decide to throw an exception + } + } + + /** + * @see org.apache.fop.fo.IntrinsicSizeAccess#getIntrinsicWidth() + */ + public int getIntrinsicWidth() { + prepareIntrinsicSize(); + if (fopimage != null) { + return fopimage.getWidth() * 1000; + } else { + return 0; + } + } + + /** + * @see org.apache.fop.fo.IntrinsicSizeAccess#getIntrinsicHeight() + */ + public int getIntrinsicHeight() { + prepareIntrinsicSize(); + if (fopimage != null) { + return fopimage.getHeight() * 1000; + } else { + return 0; + } + } + } diff --git a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java index 60c36f271..f8ffccbd0 100644 --- a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -18,8 +18,7 @@ package org.apache.fop.fo.flow; -// Java -import java.util.List; +import java.awt.geom.Point2D; import org.xml.sax.Locator; @@ -27,8 +26,10 @@ 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.IntrinsicSizeAccess; 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; @@ -36,14 +37,14 @@ 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.layoutmgr.InstreamForeignObjectLM; /** * 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 FObj implements IntrinsicSizeAccess { + // The value of properties relevant for fo:instream-foreign-object. private CommonAccessibility commonAccessibility; private CommonAural commonAural; @@ -74,6 +75,9 @@ public class InstreamForeignObject extends FObj { private Length width; // End of property values + //Additional value + private Point2D intrinsicDimensions; + /** * constructs an instream-foreign-object object (called by Maker). * @@ -280,4 +284,44 @@ public class InstreamForeignObject extends FObj { public int getNameId() { return FO_INSTREAM_FOREIGN_OBJECT; } + + /** + * Preloads the image so the intrinsic size is available. + */ + private void prepareIntrinsicSize() { + if (intrinsicDimensions == null) { + XMLObj child = (XMLObj)childNodes.get(0); + Point2D csize = new Point2D.Float(-1, -1); + intrinsicDimensions = child.getDimension(csize); + if (intrinsicDimensions == null) { + getLogger().error("Intrinsic dimensions of " + + " instream-foreign-object could not be determined"); + } + } + } + + /** + * @see org.apache.fop.fo.IntrinsicSizeAccess#getIntrinsicWidth() + */ + public int getIntrinsicWidth() { + prepareIntrinsicSize(); + if (intrinsicDimensions != null) { + return (int)(intrinsicDimensions.getX() * 1000); + } else { + return 0; + } + } + + /** + * @see org.apache.fop.fo.IntrinsicSizeAccess#getIntrinsicHeight() + */ + public int getIntrinsicHeight() { + prepareIntrinsicSize(); + if (intrinsicDimensions != null) { + return (int)(intrinsicDimensions.getY() * 1000); + } else { + return 0; + } + } + } |