diff options
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java b/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java index 31ede9aee..c7a4a6a34 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java +++ b/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java @@ -25,10 +25,14 @@ import java.awt.Rectangle; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.xmlgraphics.util.UnitConv; + import org.apache.fop.datatypes.Length; import org.apache.fop.datatypes.PercentBaseContext; import org.apache.fop.fo.Constants; import org.apache.fop.fo.GraphicsProperties; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.flow.AbstractGraphics; import org.apache.fop.fo.properties.LengthRangeProperty; /** @@ -98,9 +102,9 @@ public class ImageLayout implements Constants { boolean constrainIntrinsicSize = false; int cwidth = -1; int cheight = -1; - len = props.getContentWidth(); - if (len.getEnum() != EN_AUTO) { - switch (len.getEnum()) { + Length lenWidth = props.getContentWidth(); + if (lenWidth.getEnum() != EN_AUTO) { + switch (lenWidth.getEnum()) { case EN_SCALE_TO_FIT: if (ipd != -1) { cwidth = ipd; @@ -120,12 +124,12 @@ public class ImageLayout implements Constants { constrainIntrinsicSize = true; break; default: - cwidth = len.getValue(percentBaseContext); + cwidth = lenWidth.getValue(percentBaseContext); } } - len = props.getContentHeight(); - if (len.getEnum() != EN_AUTO) { - switch (len.getEnum()) { + Length lenHeight = props.getContentHeight(); + if (lenHeight.getEnum() != EN_AUTO) { + switch (lenHeight.getEnum()) { case EN_SCALE_TO_FIT: if (bpd != -1) { cheight = bpd; @@ -145,10 +149,21 @@ public class ImageLayout implements Constants { constrainIntrinsicSize = true; break; default: - cheight = len.getValue(percentBaseContext); + cheight = lenHeight.getValue(percentBaseContext); } } + //If no content-width or height is specified, adjust dimensions based upon the source resolution + int sourceResolution = 72; + if (props instanceof AbstractGraphics) { + sourceResolution = (int) ((AbstractGraphics)props).getUserAgent().getSourceResolution(); + } + boolean foundNonAuto = (lenWidth.getEnum() != EN_AUTO || lenHeight.getEnum() != EN_AUTO); + if (!foundNonAuto) { + cwidth = intrinsicSize.width / (sourceResolution / UnitConv.IN2PT); + cheight = intrinsicSize.height / (sourceResolution / UnitConv.IN2PT); + } + Dimension constrainedIntrinsicSize; if (constrainIntrinsicSize) { constrainedIntrinsicSize = constrain(intrinsicSize); @@ -164,11 +179,13 @@ public class ImageLayout implements Constants { //Adjust viewport if not explicit if (ipd == -1) { ipd = constrainExtent(cwidth, - props.getInlineProgressionDimension(), props.getContentWidth()); + props.getInlineProgressionDimension(), (foundNonAuto) + ? props.getContentWidth() : new DefaultLength()); } if (bpd == -1) { bpd = constrainExtent(cheight, - props.getBlockProgressionDimension(), props.getContentHeight()); + props.getBlockProgressionDimension(), (foundNonAuto) + ? props.getContentHeight() : new DefaultLength()); } this.clip = false; @@ -191,6 +208,36 @@ public class ImageLayout implements Constants { this.placement = new Rectangle(xoffset, yoffset, cwidth, cheight); } + private static class DefaultLength implements Length { + public double getNumericValue() throws PropertyException { + return 0; + } + + public double getNumericValue(PercentBaseContext context) throws PropertyException { + return 0; + } + + public int getDimension() { + return 0; + } + + public boolean isAbsolute() { + return false; + } + + public int getEnum() { + return 0; + } + + public int getValue() { + return 0; + } + + public int getValue(PercentBaseContext context) { + return 0; + } + } + private int constrainExtent(int extent, LengthRangeProperty range, Length contextExtent) { boolean mayScaleUp = (contextExtent.getEnum() != EN_SCALE_DOWN_TO_FIT); boolean mayScaleDown = (contextExtent.getEnum() != EN_SCALE_UP_TO_FIT); |