From 4515d08e19641be91e14c4532aa84d3868ef33ff Mon Sep 17 00:00:00 2001 From: "Andreas L. Delmelle" Date: Sun, 8 Jul 2007 19:47:53 +0000 Subject: [PATCH] Bugzilla 42785: Support alignment-adjust for images (submitted by Max Berger) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@554423 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/XMLObj.java | 9 +++++++++ .../org/apache/fop/fo/flow/AbstractGraphics.java | 15 +++++++++++++-- .../org/apache/fop/fo/flow/ExternalGraphic.java | 12 +++++++++++- .../apache/fop/fo/flow/InstreamForeignObject.java | 13 +++++++++++++ .../org/apache/fop/image/AbstractFopImage.java | 6 ++++++ src/java/org/apache/fop/image/FopImage.java | 10 ++++++++++ status.xml | 3 +++ 7 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/java/org/apache/fop/fo/XMLObj.java b/src/java/org/apache/fop/fo/XMLObj.java index e2b459192..f7d140732 100644 --- a/src/java/org/apache/fop/fo/XMLObj.java +++ b/src/java/org/apache/fop/fo/XMLObj.java @@ -27,6 +27,7 @@ import javax.xml.parsers.DocumentBuilderFactory; import org.apache.batik.dom.util.XMLSupport; import org.apache.fop.apps.FOPException; +import org.apache.fop.datatypes.Length; import org.apache.fop.util.ContentHandlerFactory.ObjectBuiltListener; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -94,6 +95,14 @@ public abstract class XMLObj extends FONode implements ObjectBuiltListener { public Point2D getDimension(Point2D view) { return null; } + + /** + * Retrieve the intrinsic alignment-adjust of the child element. + * @return the intrinsic alignment-adjust. + */ + public Length getIntrinsicAlignmentAdjust() { + return null; + } /** @see org.apache.fop.fo.FONode#getLocalName() */ public String getLocalName() { diff --git a/src/java/org/apache/fop/fo/flow/AbstractGraphics.java b/src/java/org/apache/fop/fo/flow/AbstractGraphics.java index 853e438fa..f48052009 100644 --- a/src/java/org/apache/fop/fo/flow/AbstractGraphics.java +++ b/src/java/org/apache/fop/fo/flow/AbstractGraphics.java @@ -236,6 +236,12 @@ public abstract class AbstractGraphics extends FObj { * @return the "alignment-adjust" property */ public Length getAlignmentAdjust() { + if (alignmentAdjust.getEnum() == EN_AUTO) { + final Length intrinsicAlignmentAdjust = this.getIntrinsicAlignmentAdjust(); + if (intrinsicAlignmentAdjust != null) { + return intrinsicAlignmentAdjust; + } + } return alignmentAdjust; } @@ -261,12 +267,17 @@ public abstract class AbstractGraphics extends FObj { } /** - * @return the graphics intrinsic width + * @return the graphics intrinsic width in millipoints */ public abstract int getIntrinsicWidth(); /** - * @return the graphics intrinsic height + * @return the graphics intrinsic height in millipoints */ public abstract int getIntrinsicHeight(); + + /** + * @return the graphics intrinsic alignment-adjust + */ + public abstract Length getIntrinsicAlignmentAdjust(); } diff --git a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java index 632812270..3ca8cf777 100644 --- a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java +++ b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java @@ -21,6 +21,7 @@ package org.apache.fop.fo.flow; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.datatypes.Length; import org.apache.fop.fo.FONode; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; @@ -44,6 +45,7 @@ public class ExternalGraphic extends AbstractGraphics { private String url; private int intrinsicWidth; private int intrinsicHeight; + private Length intrinsicAlignmentAdjust; /** * Create a new External graphic node. @@ -75,6 +77,7 @@ public class ExternalGraphic extends AbstractGraphics { } this.intrinsicWidth = fopimage.getIntrinsicWidth(); this.intrinsicHeight = fopimage.getIntrinsicHeight(); + this.intrinsicAlignmentAdjust = fopimage.getIntrinsicAlignmentAdjust(); } //TODO Report to caller so he can decide to throw an exception } @@ -135,5 +138,12 @@ public class ExternalGraphic extends AbstractGraphics { public int getIntrinsicHeight() { return this.intrinsicHeight; } - + + /** + * @see org.apache.fop.fo.flow.AbstractGraphics#getIntrinsicAlignmentAdjust() + */ + public Length getIntrinsicAlignmentAdjust() { + return this.intrinsicAlignmentAdjust; + } + } diff --git a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java index fc8dd4bc9..b201b95b1 100644 --- a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -21,6 +21,7 @@ package org.apache.fop.fo.flow; import java.awt.geom.Point2D; import org.apache.fop.apps.FOPException; +import org.apache.fop.datatypes.Length; import org.apache.fop.fo.FONode; import org.apache.fop.fo.ValidationException; import org.apache.fop.fo.XMLObj; @@ -40,6 +41,8 @@ public class InstreamForeignObject extends AbstractGraphics { //Additional value private Point2D intrinsicDimensions; + private Length intrinsicAlignmentAdjust; + /** * constructs an instream-foreign-object object (called by Maker). * @@ -98,6 +101,7 @@ public class InstreamForeignObject extends AbstractGraphics { log.error("Intrinsic dimensions of " + " instream-foreign-object could not be determined"); } + intrinsicAlignmentAdjust = child.getIntrinsicAlignmentAdjust(); } } @@ -124,6 +128,15 @@ public class InstreamForeignObject extends AbstractGraphics { return 0; } } + + /** + * @see org.apache.fop.fo.flow.AbstractGraphics#getIntrinsicAlignmentAdjust() + */ + public Length getIntrinsicAlignmentAdjust() + { + prepareIntrinsicSize(); + return intrinsicAlignmentAdjust; + } /** @see org.apache.fop.fo.FONode#addChildNode(org.apache.fop.fo.FONode) */ protected void addChildNode(FONode child) throws FOPException { diff --git a/src/java/org/apache/fop/image/AbstractFopImage.java b/src/java/org/apache/fop/image/AbstractFopImage.java index 4d49034a7..97f176712 100644 --- a/src/java/org/apache/fop/image/AbstractFopImage.java +++ b/src/java/org/apache/fop/image/AbstractFopImage.java @@ -29,6 +29,7 @@ import java.awt.Color; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.fop.datatypes.Length; /** * Base class to implement the FopImage interface. @@ -257,6 +258,11 @@ public abstract class AbstractFopImage implements FopImage { public int getIntrinsicHeight() { return (int)(getHeight() * 72000 / getVerticalResolution()); } + + /** @see org.apache.fop.image.FopImage#getIntrinsicAlignmentAdjust() */ + public Length getIntrinsicAlignmentAdjust() { + return this.imageInfo.alignmentAdjust; + } /** @see org.apache.fop.image.FopImage#getHorizontalResolution() */ public double getHorizontalResolution() { diff --git a/src/java/org/apache/fop/image/FopImage.java b/src/java/org/apache/fop/image/FopImage.java index 0db6a95a0..30f3c8258 100644 --- a/src/java/org/apache/fop/image/FopImage.java +++ b/src/java/org/apache/fop/image/FopImage.java @@ -24,6 +24,8 @@ import java.awt.color.ColorSpace; import java.awt.color.ICC_Profile; import java.awt.Color; +import org.apache.fop.datatypes.Length; + /** * Fop image interface for loading images. * @@ -89,6 +91,12 @@ public interface FopImage { */ int getIntrinsicHeight(); + /** + * @return the intrinsic alignment-adjust value or NULL if the image does + * not have one. + */ + Length getIntrinsicAlignmentAdjust(); + /** * @return the horizontal bitmap resolution (in dpi) */ @@ -193,6 +201,8 @@ public interface FopImage { public String mimeType; /** implementation-specific String (ex. the namespace for XML-based images) */ public String str; + /** intrinsic alignment-adjust or null if there is none */ + public Length alignmentAdjust; } } diff --git a/status.xml b/status.xml index 81d8e6751..d155da934 100644 --- a/status.xml +++ b/status.xml @@ -28,6 +28,9 @@ + + Support alignment-adjust for images. + Partial application of the patch in Bugzilla 41044: * addition of a generic PropertyCache to be used by all Property -- 2.39.5