diff options
Diffstat (limited to 'src/java/org/apache/fop/fo/expr')
7 files changed, 94 insertions, 55 deletions
diff --git a/src/java/org/apache/fop/fo/expr/LabelEndFunction.java b/src/java/org/apache/fop/fo/expr/LabelEndFunction.java index d014662b3..4682272b5 100644 --- a/src/java/org/apache/fop/fo/expr/LabelEndFunction.java +++ b/src/java/org/apache/fop/fo/expr/LabelEndFunction.java @@ -66,7 +66,7 @@ public class LabelEndFunction extends FunctionBase { Length startIndent = pList.get(Constants.PR_START_INDENT).getLength(); LengthBase base = new LengthBase(pList.getFObj(), pInfo.getPropertyList(), - LengthBase.CONTAINING_REFAREA); + LengthBase.CONTAINING_REFAREA_WIDTH); PercentLength refWidth = new PercentLength(1.0, base); Numeric labelEnd = distance; diff --git a/src/java/org/apache/fop/fo/expr/NumericOp.java b/src/java/org/apache/fop/fo/expr/NumericOp.java index 34aa29d00..3edc41196 100755 --- a/src/java/org/apache/fop/fo/expr/NumericOp.java +++ b/src/java/org/apache/fop/fo/expr/NumericOp.java @@ -18,6 +18,7 @@ package org.apache.fop.fo.expr; +import org.apache.fop.datatypes.PercentBaseContext; import org.apache.fop.datatypes.Numeric; /** @@ -39,17 +40,17 @@ public class NumericOp { */ public static Numeric addition(Numeric op1, Numeric op2) throws PropertyException { if (op1.isAbsolute() && op2.isAbsolute()) { - return addition2(op1, op2); + return addition2(op1, op2, null); } else { return new RelativeNumericProperty(RelativeNumericProperty.ADDITION, op1, op2); } } - public static Numeric addition2(Numeric op1, Numeric op2) throws PropertyException { + public static Numeric addition2(Numeric op1, Numeric op2, PercentBaseContext context) throws PropertyException { if (op1.getDimension() != op2.getDimension()) { throw new PropertyException("Can't subtract Numerics of different dimensions"); } - return numeric(op1.getNumericValue() + op2.getNumericValue(), op1.getDimension()); + return numeric(op1.getNumericValue(context) + op2.getNumericValue(context), op1.getDimension()); } /** @@ -63,17 +64,17 @@ public class NumericOp { */ public static Numeric subtraction(Numeric op1, Numeric op2) throws PropertyException { if (op1.isAbsolute() && op2.isAbsolute()) { - return subtraction2(op1, op2); + return subtraction2(op1, op2, null); } else { return new RelativeNumericProperty(RelativeNumericProperty.SUBTRACTION, op1, op2); } } - public static Numeric subtraction2(Numeric op1, Numeric op2) throws PropertyException { + public static Numeric subtraction2(Numeric op1, Numeric op2, PercentBaseContext context) throws PropertyException { if (op1.getDimension() != op2.getDimension()) { throw new PropertyException("Can't subtract Numerics of different dimensions"); } - return numeric(op1.getNumericValue() - op2.getNumericValue(), op1.getDimension()); + return numeric(op1.getNumericValue(context) - op2.getNumericValue(context), op1.getDimension()); } /** @@ -87,14 +88,14 @@ public class NumericOp { */ public static Numeric multiply(Numeric op1, Numeric op2) throws PropertyException { if (op1.isAbsolute() && op2.isAbsolute()) { - return multiply2(op1, op2); + return multiply2(op1, op2, null); } else { return new RelativeNumericProperty(RelativeNumericProperty.MULTIPLY, op1, op2); } } - public static Numeric multiply2(Numeric op1, Numeric op2) throws PropertyException { - return numeric(op1.getNumericValue() * op2.getNumericValue(), + public static Numeric multiply2(Numeric op1, Numeric op2, PercentBaseContext context) throws PropertyException { + return numeric(op1.getNumericValue(context) * op2.getNumericValue(context), op1.getDimension() + op2.getDimension()); } @@ -110,14 +111,14 @@ public class NumericOp { */ public static Numeric divide(Numeric op1, Numeric op2) throws PropertyException { if (op1.isAbsolute() && op2.isAbsolute()) { - return divide2(op1, op2); + return divide2(op1, op2, null); } else { return new RelativeNumericProperty(RelativeNumericProperty.DIVIDE, op1, op2); } } - public static Numeric divide2(Numeric op1, Numeric op2) throws PropertyException { - return numeric(op1.getNumericValue() / op2.getNumericValue(), + public static Numeric divide2(Numeric op1, Numeric op2, PercentBaseContext context) throws PropertyException { + return numeric(op1.getNumericValue(context) / op2.getNumericValue(context), op1.getDimension() - op2.getDimension()); } @@ -129,14 +130,14 @@ public class NumericOp { */ public static Numeric modulo(Numeric op1, Numeric op2) throws PropertyException { if (op1.isAbsolute() && op2.isAbsolute()) { - return modulo2(op1, op2); + return modulo2(op1, op2, null); } else { return new RelativeNumericProperty(RelativeNumericProperty.MODULO, op1, op2); } } - public static Numeric modulo2(Numeric op1, Numeric op2) throws PropertyException { - return numeric(op1.getNumericValue() % op2.getNumericValue(), op1.getDimension()); + public static Numeric modulo2(Numeric op1, Numeric op2, PercentBaseContext context) throws PropertyException { + return numeric(op1.getNumericValue(context) % op2.getNumericValue(context), op1.getDimension()); } /** @@ -146,14 +147,14 @@ public class NumericOp { */ public static Numeric abs(Numeric op) throws PropertyException { if (op.isAbsolute()) { - return abs2(op); + return abs2(op, null); } else { return new RelativeNumericProperty(RelativeNumericProperty.ABS, op); } } - public static Numeric abs2(Numeric op) throws PropertyException { - return numeric(Math.abs(op.getNumericValue()), op.getDimension()); + public static Numeric abs2(Numeric op, PercentBaseContext context) throws PropertyException { + return numeric(Math.abs(op.getNumericValue(context)), op.getDimension()); } /** @@ -163,14 +164,14 @@ public class NumericOp { */ public static Numeric negate(Numeric op) throws PropertyException { if (op.isAbsolute()) { - return negate2(op); + return negate2(op, null); } else { return new RelativeNumericProperty(RelativeNumericProperty.NEGATE, op); } } - public static Numeric negate2(Numeric op) throws PropertyException { - return numeric(- op.getNumericValue(), op.getDimension()); + public static Numeric negate2(Numeric op, PercentBaseContext context) throws PropertyException { + return numeric(- op.getNumericValue(context), op.getDimension()); } /** @@ -182,17 +183,17 @@ public class NumericOp { */ public static Numeric max(Numeric op1, Numeric op2) throws PropertyException { if (op1.isAbsolute() && op2.isAbsolute()) { - return max2(op1, op2); + return max2(op1, op2, null); } else { return new RelativeNumericProperty(RelativeNumericProperty.MAX, op1, op2); } } - public static Numeric max2(Numeric op1, Numeric op2) throws PropertyException { + public static Numeric max2(Numeric op1, Numeric op2, PercentBaseContext context) throws PropertyException { if (op1.getDimension() != op2.getDimension()) { throw new PropertyException("Arguments to max() must have same dimensions"); } - return op1.getNumericValue() > op2.getNumericValue() ? op1 : op2; + return op1.getNumericValue(context) > op2.getNumericValue(context) ? op1 : op2; } /** @@ -204,17 +205,17 @@ public class NumericOp { */ public static Numeric min(Numeric op1, Numeric op2) throws PropertyException { if (op1.isAbsolute() && op2.isAbsolute()) { - return min2(op1, op2); + return min2(op1, op2, null); } else { return new RelativeNumericProperty(RelativeNumericProperty.MIN, op1, op2); } } - public static Numeric min2(Numeric op1, Numeric op2) throws PropertyException { + public static Numeric min2(Numeric op1, Numeric op2, PercentBaseContext context) throws PropertyException { if (op1.getDimension() != op2.getDimension()) { throw new PropertyException("Arguments to min() must have same dimensions"); } - return op1.getNumericValue() <= op2.getNumericValue() ? op1 : op2; + return op1.getNumericValue(context) <= op2.getNumericValue(context) ? op1 : op2; } /** diff --git a/src/java/org/apache/fop/fo/expr/NumericProperty.java b/src/java/org/apache/fop/fo/expr/NumericProperty.java index 72de27750..dd146ce7f 100644 --- a/src/java/org/apache/fop/fo/expr/NumericProperty.java +++ b/src/java/org/apache/fop/fo/expr/NumericProperty.java @@ -19,6 +19,7 @@ package org.apache.fop.fo.expr; import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.PercentBaseContext; import org.apache.fop.datatypes.Numeric; import org.apache.fop.fo.properties.ColorTypeProperty; import org.apache.fop.fo.properties.Property; @@ -60,6 +61,15 @@ public class NumericProperty extends Property implements Numeric, Length { } /** + * Return the value. + * @param Evaluation context + * @see Numeric#getNumericValue(Object) + */ + public double getNumericValue(PercentBaseContext context) { + return value; + } + + /** * Return true of the numeric is absolute. * @see Numeric#isAbsolute() */ @@ -89,6 +99,14 @@ public class NumericProperty extends Property implements Numeric, Length { } /** + * Return the value of this numeric as a length in millipoints. + * @param Evaluation context + */ + public int getValue(PercentBaseContext context) { + return (int) value; + } + + /** * Cast this as a length. That is only possible when the dimension is * one. */ diff --git a/src/java/org/apache/fop/fo/expr/PropertyInfo.java b/src/java/org/apache/fop/fo/expr/PropertyInfo.java index fb59332de..9cd5e714e 100644 --- a/src/java/org/apache/fop/fo/expr/PropertyInfo.java +++ b/src/java/org/apache/fop/fo/expr/PropertyInfo.java @@ -20,11 +20,12 @@ package org.apache.fop.fo.expr; import java.util.Stack; +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.Constants; -import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.FObj; +import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.properties.PropertyMaker; -import org.apache.fop.datatypes.PercentBase; /** @@ -57,7 +58,7 @@ public class PropertyInfo { * Propagates to the Maker. * @return The PercentBase object or null if percentLengthOK()=false. */ - public PercentBase getPercentBase() { + public PercentBase getPercentBase() throws PropertyException { PercentBase pcbase = getFunctionPercentBase(); return (pcbase != null) ? pcbase : maker.getPercentBase(fo, plist); } @@ -65,8 +66,8 @@ public class PropertyInfo { /** * @return the current font-size value as base units (milli-points). */ - public int currentFontSize() throws PropertyException { - return plist.get(Constants.PR_FONT_SIZE).getLength().getValue(); + public Length currentFontSize() throws PropertyException { + return plist.get(Constants.PR_FONT_SIZE).getLength(); } /** diff --git a/src/java/org/apache/fop/fo/expr/PropertyParser.java b/src/java/org/apache/fop/fo/expr/PropertyParser.java index 7d77d7f9b..4ab7e7249 100644 --- a/src/java/org/apache/fop/fo/expr/PropertyParser.java +++ b/src/java/org/apache/fop/fo/expr/PropertyParser.java @@ -285,18 +285,11 @@ public class PropertyParser extends PropertyTokenizer { String unitPart = currentTokenValue.substring(numLen); Double numPart = new Double(currentTokenValue.substring(0, numLen)); - LengthProperty length = null; if (unitPart.equals(RELUNIT)) { - length = new FixedLength(numPart.doubleValue(), + prop = (Property) NumericOp.multiply(new NumberProperty(numPart.doubleValue()), propInfo.currentFontSize()); } else { - length = new FixedLength(numPart.doubleValue(), unitPart); - } - if (length == null) { - throw new PropertyException("unrecognized unit name: " - + currentTokenValue); - } else { - prop = length; + prop = new FixedLength(numPart.doubleValue(), unitPart); } break; diff --git a/src/java/org/apache/fop/fo/expr/RGBColorFunction.java b/src/java/org/apache/fop/fo/expr/RGBColorFunction.java index ee1e28daa..4e050bd08 100644 --- a/src/java/org/apache/fop/fo/expr/RGBColorFunction.java +++ b/src/java/org/apache/fop/fo/expr/RGBColorFunction.java @@ -19,9 +19,10 @@ package org.apache.fop.fo.expr; +import org.apache.fop.datatypes.PercentBaseContext; +import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.properties.ColorTypeProperty; import org.apache.fop.fo.properties.Property; -import org.apache.fop.datatypes.PercentBase; class RGBColorFunction extends FunctionBase { public int nbArgs() { @@ -68,7 +69,7 @@ class RGBColorFunction extends FunctionBase { return 255f; } - public int getBaseLength() { + public int getBaseLength(PercentBaseContext context) { return 0; } diff --git a/src/java/org/apache/fop/fo/expr/RelativeNumericProperty.java b/src/java/org/apache/fop/fo/expr/RelativeNumericProperty.java index 97e940d0b..15017440d 100755 --- a/src/java/org/apache/fop/fo/expr/RelativeNumericProperty.java +++ b/src/java/org/apache/fop/fo/expr/RelativeNumericProperty.java @@ -18,6 +18,8 @@ package org.apache.fop.fo.expr; +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.PercentBaseContext; import org.apache.fop.datatypes.Numeric; import org.apache.fop.datatypes.Length; import org.apache.fop.fo.properties.Property; @@ -96,29 +98,30 @@ public class RelativeNumericProperty extends Property implements Numeric, Length /** * Return a resolved (calculated) Numeric with the value of the expression. + * @param context Evaluation context * @throws PropertyException when an exception occur during evaluation. */ - private Numeric getResolved() throws PropertyException { + private Numeric getResolved(PercentBaseContext context) throws PropertyException { Numeric n; switch (operation) { case ADDITION: - return NumericOp.addition2(op1, op2); + return NumericOp.addition2(op1, op2, context); case SUBTRACTION: - return NumericOp.subtraction2(op1, op2); + return NumericOp.subtraction2(op1, op2, context); case MULTIPLY: - return NumericOp.multiply2(op1, op2); + return NumericOp.multiply2(op1, op2, context); case DIVIDE: - return NumericOp.divide2(op1, op2); + return NumericOp.divide2(op1, op2, context); case MODULO: - return NumericOp.modulo2(op1, op2); + return NumericOp.modulo2(op1, op2, context); case NEGATE: - return NumericOp.negate2(op1); + return NumericOp.negate2(op1, context); case ABS: - return NumericOp.abs2(op1); + return NumericOp.abs2(op1, context); case MAX: - return NumericOp.max2(op1, op2); + return NumericOp.max2(op1, op2, context); case MIN: - return NumericOp.min2(op1, op2); + return NumericOp.min2(op1, op2, context); default: throw new PropertyException("Unknown expr operation " + operation); } @@ -129,7 +132,16 @@ public class RelativeNumericProperty extends Property implements Numeric, Length * @see Numeric#getNumericValue() */ public double getNumericValue() throws PropertyException { - return getResolved().getNumericValue(); + return getResolved(null).getNumericValue(null); + } + + /** + * Return the value. + * @param Evaluation context + * @see Numeric#getNumericValue(Object) + */ + public double getNumericValue(PercentBaseContext context) throws PropertyException { + return getResolved(context).getNumericValue(context); } /** @@ -175,6 +187,19 @@ public class RelativeNumericProperty extends Property implements Numeric, Length } /** + * Return the value of this numeric as a length in millipoints. + * @param Evaluation context + */ + public int getValue(PercentBaseContext context) { + try { + return (int) getNumericValue(context); + } catch (PropertyException exc) { + log.error(exc); + } + return 0; + } + + /** * Return a string represention of the expression. Only used for debugging. */ public String toString() { |