import org.apache.fop.fo.properties.FixedLength;
/**
- * Class modelling the fo:external-graphic object.
+ * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_external-graphic">
+ * <code>fo:external-graphic</code></a> object.
* This FO node handles the external graphic. It creates an image
* inline area that can be added to the area tree.
*/
super(parent);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void bind(PropertyList pList) throws FOPException {
super.bind(pList);
src = pList.get(PR_SRC).getString();
this.intrinsicHeight = info.getSize().getHeightMpt();
int baseline = info.getSize().getBaselinePositionFromBottom();
if (baseline != 0) {
- this.intrinsicAlignmentAdjust = new FixedLength(-baseline);
+ this.intrinsicAlignmentAdjust
+ = FixedLength.getInstance(-baseline);
}
}
//TODO Report to caller so he can decide to throw an exception
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected void startOfNode() throws FOPException {
super.startOfNode();
getFOEventHandler().image(this);
/**
* {@inheritDoc}
- * XSL Content Model: empty
+ * <br>XSL Content Model: empty
*/
protected void validateChildNode(Locator loc, String nsURI, String localName)
throws ValidationException {
invalidChildError(loc, nsURI, localName);
}
- /**
- * @return the "src" property.
- */
+ /** @return the "src" property */
public String getSrc() {
return src;
}
- /**
- * @return Get the resulting URL based on the src property.
- */
+ /** @return Get the resulting URL based on the src property */
public String getURL() {
return url;
}
return "external-graphic";
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public int getNameId() {
return FO_EXTERNAL_GRAPHIC;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public int getIntrinsicWidth() {
return this.intrinsicWidth;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public int getIntrinsicHeight() {
return this.intrinsicHeight;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public Length getIntrinsicAlignmentAdjust() {
return this.intrinsicAlignmentAdjust;
}
private int millipoints;
/**
- * Set the length given a number of units and a unit name.
+ * Set the length given a number of units, a unit name and
+ * an assumed resolution (used in case the units are pixels)
*
- * @param numUnits quantity of input units
- * @param units input unit specifier (in, cm, etc.)
+ * @param numUnits quantity of input units
+ * @param units input unit specifier
+ * @param res input/source resolution
*/
- private FixedLength(double numUnits, String units) {
- convert(numUnits, units);
+ private FixedLength(double numUnits, String units, float res) {
+ this.millipoints = convert(numUnits, units, res);
}
/**
- * Return the cached FixedLength instance corresponding
+ * Return the cached {@link FixedLength} instance corresponding
+ * to the computed value in base-units (millipoints).
+ *
+ * @param numUnits quantity of input units
+ * @param units input unit specifier
+ * @param sourceResolution input/source resolution (= ratio of pixels per pt)
+ * @return the canonical FixedLength instance corresponding
+ * to the given number of units and unit specifier
+ * in the given resolution
+ */
+ public static FixedLength getInstance(double numUnits,
+ String units,
+ float sourceResolution) {
+ return (FixedLength)cache.fetch(
+ new FixedLength(numUnits, units, sourceResolution));
+
+ }
+
+ /**
+ * Return the cached {@link FixedLength} instance corresponding
* to the computed value
+ * This method assumes a source-resolution of 1 (1px = 1pt)
*
* @param numUnits input units
* @param units unit specifier
*/
public static FixedLength getInstance(double numUnits,
String units) {
- return (FixedLength) cache.fetch(new FixedLength(numUnits, units));
+ return getInstance(numUnits, units, 1.0f);
}
/**
- * @param baseUnits the length as a number of base units (millipoints)
+ * Return the cached {@link FixedLength} instance corresponding
+ * to the computed value.
+ * This method assumes 'millipoints' (non-standard) as units,
+ * and an implied source-resolution of 1 (1px = 1pt).
+ *
+ * @param numUnits input units
+ * @return the canonical FixedLength instance corresponding
+ * to the given number of units and unit specifier
*/
- public FixedLength(int baseUnits) {
- millipoints = baseUnits;
+ public static FixedLength getInstance(double numUnits) {
+ return getInstance(numUnits, "mpt", 1.0f);
+
}
-
+
/**
* Convert the given length to a dimensionless integer representing
* a whole number of base units (milli-points).
+ *
* @param dvalue quantity of input units
* @param unit input unit specifier (in, cm, etc.)
+ * @param res the input/source resolution (in case the unit spec is "px")
*/
- private void convert(double dvalue, String unit) {
- // TODO: the whole routine smells fishy.
+ private static int convert(double dvalue, String unit, float res) {
+ // TODO: Maybe this method has a better place in org.apache.fop.util.UnitConv?.
- int assumedResolution = 1; // points/pixel = 72dpi
-
- if (unit.equals("in")) {
- dvalue = dvalue * 72;
- } else if (unit.equals("cm")) {
- dvalue = dvalue * 28.3464567;
- } else if (unit.equals("mm")) {
- dvalue = dvalue * 2.83464567;
- } else if (unit.equals("pt")) {
- // Do nothing.
- // dvalue = dvalue;
- } else if (unit.equals("mpt")) { //mpt is non-standard!!! mpt=millipoints
- // TODO: this seems to be wrong.
- // Do nothing.
- // dvalue = dvalue;
- } else if (unit.equals("pc")) {
- dvalue = dvalue * 12;
- /*
- * } else if (unit.equals("em")) {
- * dvalue = dvalue * fontsize;
- */
- } else if (unit.equals("px")) {
- // TODO: get resolution from user agent?
- dvalue = dvalue * assumedResolution;
- } else {
- dvalue = 0;
- log.error("Unknown length unit '" + unit + "'");
- }
- if (unit.equals("mpt")) {
- millipoints = (int)dvalue;
+ if ("px".equals(unit)) {
+ //device-dependent units, take the resolution into account
+ dvalue *= (res * 1000);
} else {
- millipoints = (int)(dvalue * 1000);
+ if ("in".equals(unit)) {
+ dvalue *= 72000;
+ } else if ("cm".equals(unit)) {
+ dvalue *= 28346.4567;
+ } else if ("mm".equals(unit)) {
+ dvalue *= 2834.64567;
+ } else if ("pt".equals(unit)) {
+ dvalue *= 1000;
+ } else if ("pc".equals(unit)) {
+ dvalue *= 12000;
+ } else if (!"mpt".equals(unit)) {
+ dvalue = 0;
+ log.error("Unknown length unit '" + unit + "'");
+ }
}
+ return (int)dvalue;
}
/** {@inheritDoc} */
}
/**
- * Return true since FixedLength are always absolute.
+ * Return true since a FixedLength is always absolute.
* {@inheritDoc}
*/
public boolean isAbsolute() {
/** {@inheritDoc} */
public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
if (obj instanceof FixedLength) {
return (((FixedLength)obj).millipoints == this.millipoints);
- } else {
- return false;
}
+ return false;
}
/** {@inheritDoc} */