aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/fo/flow/ExternalGraphic.java
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2004-12-28 18:03:12 +0000
committerJeremias Maerki <jeremias@apache.org>2004-12-28 18:03:12 +0000
commit73a83df9636693496269245c4f0b5fcd56aae0b1 (patch)
tree15d30059f8b317d5945d26c83d137e59b7f06490 /src/java/org/apache/fop/fo/flow/ExternalGraphic.java
parentbf98519aaaaeeb247aa87403b021d46896f469c5 (diff)
downloadxmlgraphics-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/flow/ExternalGraphic.java')
-rw-r--r--src/java/org/apache/fop/fo/flow/ExternalGraphic.java64
1 files changed, 63 insertions, 1 deletions
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;
+ }
+ }
+
}