+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-
-public class AbsFunction extends FunctionBase {
-
- public int nbArgs() {
- return 1;
- }
-
- public Property eval(Property[] args,
- PropertyInfo propInfo) throws PropertyException {
- Numeric num = args[0].getNumeric();
- if (num == null)
- throw new PropertyException("Non numeric operand to abs function");
- // What if has relative composants (percent, table-col units)?
- return new NumericProperty(num.abs());
- }
-
-}
-
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-import org.apache.fop.fo.FObj;
-import org.apache.fop.fo.flow.ListItem;
-
-public class BodyStartFunction extends FunctionBase {
-
- public int nbArgs() {
- return 0;
- }
-
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
- Numeric distance =
- pInfo.getPropertyList().get("provisional-distance-between-starts").getNumeric();
-
- FObj item = pInfo.getFO();
- while (item != null &&!(item instanceof ListItem)) {
- item = item.getParent();
- }
- if (item == null) {
- throw new PropertyException("body-start() called from outside an fo:list-item");
- }
-
- Numeric startIndent =
- item.properties.get("start-indent").getNumeric();
-
- return new NumericProperty(distance.add(startIndent));
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-import org.apache.fop.fo.NumberProperty;
-
-class CeilingFunction extends FunctionBase {
-
- public int nbArgs() {
- return 1;
- }
-
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
- Number dbl = args[0].getNumber();
- if (dbl == null)
- throw new PropertyException("Non number operand to ceiling function");
- return new NumberProperty(Math.ceil(dbl.doubleValue()));
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-import org.apache.fop.fo.NumberProperty;
-
-
-class FloorFunction extends FunctionBase {
-
- public int nbArgs() {
- return 1;
- }
-
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
- Number dbl = args[0].getNumber();
- if (dbl == null)
- throw new PropertyException("Non number operand to floor function");
- return new NumberProperty(Math.floor(dbl.doubleValue()));
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-
-
-/**
- * Return the specified or initial value of the property on this object.
- */
-public class FopPropValFunction extends FunctionBase {
-
- public int nbArgs() {
- return 1;
- }
-
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
- String propName = args[0].getString();
- if (propName == null) {
- throw new PropertyException("Incorrect parameter to _int-property-value function");
- }
- // System.err.println("Get property-value for " + propName);
- return pInfo.getPropertyList().get(propName);
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-
-
-public class FromParentFunction extends FunctionBase {
-
- public int nbArgs() {
- return 1;
- }
-
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
- String propName = args[0].getString();
- if (propName == null) {
- throw new PropertyException("Incorrect parameter to from-parent function");
- }
- // NOTE: special cases for shorthand property
- // Should return COMPUTED VALUE
- /*
- * For now, this is the same as inherited-property-value(propName)
- * (The only difference I can see is that this could work for
- * non-inherited properties too. Perhaps the result is different for
- * a property line line-height which "inherits specified"???
- */
- return pInfo.getPropertyList().getFromParent(propName);
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-
-
-public class FromTableColumnFunction extends FunctionBase {
-
- public int nbArgs() {
- return 1;
- }
-
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
- String propName = args[0].getString();
- if (propName == null) {
- throw new PropertyException("Incorrect parameter to from-table-column function");
- }
- throw new PropertyException("from-table-column unimplemented!");
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-import org.apache.fop.datatypes.PercentBase;
-
-public interface Function {
- int nbArgs();
- PercentBase getPercentBase();
- Property eval(Property[] args,
- PropertyInfo propInfo) throws PropertyException;
-}
-
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-import org.apache.fop.datatypes.PercentBase;
-
-public abstract class FunctionBase implements Function {
- // abstract int nbArgs() ;
-
- /**
- * By default, functions have no percent-based arguments.
- */
- public PercentBase getPercentBase() {
- return null;
- }
-
- /*
- * abstract Property eval(Property[] args, PropertyInfo propInfo)
- * throws PropertyException;
- */
-}
-
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-
-
-public class InheritedPropFunction extends FunctionBase {
-
- public int nbArgs() {
- return 1;
- }
-
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
- String propName = args[0].getString();
- if (propName == null) {
- throw new PropertyException("Incorrect parameter to inherited-property-value function");
- }
- return pInfo.getPropertyList().getInherited(propName);
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.datatypes.*;
-import org.apache.fop.fo.Property;
-import org.apache.fop.fo.LengthProperty;
-import org.apache.fop.fo.FObj;
-import org.apache.fop.fo.flow.ListItem;
-
-public class LabelEndFunction extends FunctionBase {
-
- public int nbArgs() {
- return 0;
- }
-
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
-
- Length distance =
- pInfo.getPropertyList().get("provisional-distance-between-starts").getLength();
- Length separation =
- pInfo.getPropertyList().getNearestSpecified("provisional-label-separation").getLength();
-
- FObj item = pInfo.getFO();
- while (item != null &&!(item instanceof ListItem)) {
- item = item.getParent();
- }
- if (item == null) {
- throw new PropertyException("label-end() called from outside an fo:list-item");
- }
- Length startIndent = item.properties.get("start-indent").getLength();
-
- LinearCombinationLength labelEnd = new LinearCombinationLength();
-
- // Should be CONTAINING_REFAREA but that doesn't work
- LengthBase base = new LengthBase(item, pInfo.getPropertyList(),
- LengthBase.CONTAINING_BOX);
- PercentLength refWidth = new PercentLength(1.0, base);
-
- labelEnd.addTerm(1.0, refWidth);
- labelEnd.addTerm(-1.0, distance);
- labelEnd.addTerm(-1.0, startIndent);
- labelEnd.addTerm(1.0, separation);
-
- return new LengthProperty(labelEnd);
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-
-
-public class MaxFunction extends FunctionBase {
- public int nbArgs() {
- return 2;
- }
-
- // Handle "numerics" if no proportional/percent parts!
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
- Numeric n1 = args[0].getNumeric();
- Numeric n2 = args[1].getNumeric();
- if (n1 == null || n2 == null)
- throw new PropertyException("Non numeric operands to max function");
- return new NumericProperty(n1.max(n2));
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-
-
-public class MinFunction extends FunctionBase {
- public int nbArgs() {
- return 2;
- }
-
- // Handle "numerics" if no proportional/percent parts!
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
- Numeric n1 = args[0].getNumeric();
- Numeric n2 = args[1].getNumeric();
- if (n1 == null || n2 == null)
- throw new PropertyException("Non numeric operands to min function");
- return new NumericProperty(n1.min(n2));
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-import org.apache.fop.datatypes.ColorType;
-
-public class NCnameProperty extends Property {
-
- private final String ncName;
-
- public NCnameProperty(String ncName) {
- this.ncName = ncName;
- }
-
- public ColorType getColor() throws PropertyException {
- // If a system color, return the corresponding value
- throw new PropertyException("Not a Color");
- }
-
- /**
- * Return the name as a String (should be specified with quotes!)
- */
- public String getString() {
- return this.ncName;
- }
-
- public String getNCname() {
- return this.ncName;
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-
-public class NearestSpecPropFunction extends FunctionBase {
-
- public int nbArgs() {
- return 1;
- }
-
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
- String propName = args[0].getString();
- if (propName == null) {
- throw new PropertyException("Incorrect parameter to from-nearest-specified-value function");
- }
- // NOTE: special cases for shorthand property
- // Should return COMPUTED VALUE
- return pInfo.getPropertyList().getNearestSpecified(propName);
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-
-import org.apache.fop.fo.Property;
-import org.apache.fop.datatypes.Length;
-import org.apache.fop.datatypes.PercentLength;
-import org.apache.fop.datatypes.LinearCombinationLength;
-import org.apache.fop.datatypes.MixedLength;
-import org.apache.fop.datatypes.TableColLength;
-import org.apache.fop.datatypes.PercentBase;
-
-/**
- * Represents a "numeric" value as defined by the XSL FO Specification.
- * This consists of one or more kinds of value specifications, from
- * absolute numbers (units power of 0) to lengths (unit power of 1),
- * relative lengths (ems), percentage lengths.
- * A Numeric can be constructed from other Property types representing
- * Numbers or Length-type values.
- * Numeric provides methods to return Number and Length values based on
- * its current value.
- * It supports basic arithmetic operations involving Numerics.
- */
-public class Numeric {
- // Bit fields
- public static final int ABS_LENGTH = 1; // abs units (or number)
- public static final int PC_LENGTH = 2; // Percentage
- public static final int TCOL_LENGTH = 4; // Table units
-
- private int valType;
- private double absValue;
- private double pcValue;
- private PercentBase pcBase = null; // base value for PC_LENGTH component
- private double tcolValue;
- private int dim;
-
-
- /**
- * Construct a Numeric object by specifying one or more components,
- * including absolute length, percent length, table units.
- * @param valType A combination of bits representing the value types.
- * @param absValue The value of a Number or resolved Length value if
- * the ABS_LENGTH flag is set.
- * @param pcValue The decimal percent value if the PC_LENGTH flag is set
- * @param tcolValue The decimal table unit value if the TCOL_LENGTH flag
- * is set.
- * @param dim The dimension of the value. 0 for a Number, 1 for a Length
- * (any type), >1, <0 if Lengths have been multiplied or divided.
- * @pcBase The PercentBase object used to calculate an actual value for
- * a PC_LENGTH.
- */
- protected Numeric(int valType, double absValue, double pcValue,
- double tcolValue, int dim, PercentBase pcBase) {
- this.valType = valType;
- this.absValue = absValue;
- this.pcValue = pcValue;
- this.tcolValue = tcolValue;
- this.dim = dim;
- this.pcBase = pcBase;
- }
-
- /**
- * Construct a Numeric object of dimension 0 from a double.
- * @param valType A combination of bits representing the value types.
- * @param absValue The value of a Number or resolved Length value.
- */
-
- /**
- * *
- * protected Numeric(int valType, double absValue) {
- * this.valType = valType;
- * this.absValue = absValue;
- * }
- */
-
- /**
- * Construct a Numeric object from a Number.
- * @param num The number.
- */
- public Numeric(Number num) {
- this(ABS_LENGTH, num.doubleValue(), 0.0, 0.0, 0, null);
- }
-
- /**
- * Construct a Numeric object from a Length.
- * @param l The Length.
- */
- public Numeric(Length l) {
- this(ABS_LENGTH, (double)l.mvalue(), 0.0, 0.0, 1, null);
- }
-
- /**
- * Construct a Numeric object from a PercentLength.
- * @param pclen The PercentLength.
- */
- public Numeric(PercentLength pclen) {
- this(PC_LENGTH, 0.0, pclen.value(), 0.0, 1, pclen.getBaseLength());
- }
-
- /**
- * Construct a Numeric object from a TableColLength.
- * @param tclen The TableColLength.
- */
- public Numeric(TableColLength tclen) {
- this(TCOL_LENGTH, 0.0, 0.0, tclen.getTableUnits(), 1, null);
- }
-
-
- /**
- * Return the current value as a Length if possible. This constructs
- * a new Length or Length subclass based on the current value type
- * of the Numeric.
- * If the stored value has a unit dimension other than 1, null
- * is returned.
- */
- public Length asLength() {
- if (dim == 1) {
- if (valType == ABS_LENGTH) {
- return new Length((int)absValue);
- }
- PercentLength pclen = null;
- if ((valType & PC_LENGTH) != 0) {
- pclen = new PercentLength(pcValue, pcBase);
- if (valType == PC_LENGTH)
- return pclen;
- }
- if ((valType & TCOL_LENGTH) != 0) {
- return new TableColLength((int)absValue, pclen, tcolValue);
- }
- return new MixedLength((int)absValue, pclen);
- } else {
- // or throw exception???
- // can't make Length if dimension != 1
- return null;
- }
- }
-
- /**
- * Return the current value as a Number if possible.
- * Calls asDouble().
- */
- public Number asNumber() {
- return asDouble();
- }
-
- public Double asDouble() {
- if (dim == 0 && valType == ABS_LENGTH) {
- return new Double(absValue);
- } else {
- // or throw exception???
- // can't make Number if dimension != 0
- return null;
- }
- }
-
- /**
- * Return the current value as a Integer if possible.
- * If the unit dimension is 0 and the value type is ABSOLUTE, an Integer
- * is returned. Otherwise null is returned. Note: the current value is
- * truncated if necessary to make an integer value.
- */
-
- /**
- * public Integer asInteger() {
- * if (dim == 0 && valType==ABS_LENGTH) {
- * return new Integer((int)absValue);
- * }
- * else {
- * // or throw exception???
- * // can't make Number if dimension != 0
- * return null;
- * }
- * }
- */
-
- /**
- * Return a boolean value indiciating whether the currently stored
- * value consists of different "types" of values (absolute, percent,
- * and/or table-unit.)
- */
- private boolean isMixedType() {
- int ntype = 0;
- for (int t = valType; t != 0; t = t >> 1) {
- if ((t & 1) != 0)
- ++ntype;
- }
- return ntype > 1;
- }
-
- /**
- * Subtract the operand from the current value and return a new Numeric
- * representing the result.
- * @param op The value to subtract.
- * @return A Numeric representing the result.
- * @throws PropertyException If the dimension of the operand is different
- * from the dimension of this Numeric.
- */
- public Numeric subtract(Numeric op) throws PropertyException {
- // Check of same dimension
- // Add together absolute and table units
- // What about percentages??? Treat as colUnits if they can't be
- // in same property!
- if (dim == op.dim) {
- PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase
- : op.pcBase;
- // Subtract each type of value
- return new Numeric(valType | op.valType, absValue - op.absValue,
- pcValue - op.pcValue,
- tcolValue - op.tcolValue, dim, npcBase);
- } else {
- throw new PropertyException("Can't add Numerics of different dimensions");
- }
- }
-
- /**
- * Add the operand from the current value and return a new Numeric
- * representing the result.
- * @param op The value to add.
- * @return A Numeric representing the result.
- * @throws PropertyException If the dimension of the operand is different
- * from the dimension of this Numeric.
- */
- public Numeric add(Numeric op) throws PropertyException {
- // Check of same dimension
- // Add together absolute and table units
- // What about percentages??? Treat as colUnits if they can't be
- // in same property!
- if (dim == op.dim) {
- PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase
- : op.pcBase;
- // Add each type of value
- return new Numeric(valType | op.valType, absValue + op.absValue,
- pcValue + op.pcValue,
- tcolValue + op.tcolValue, dim, npcBase);
- } else {
- throw new PropertyException("Can't add Numerics of different dimensions");
- }
- }
-
- /**
- * Multiply the the current value by the operand and return a new Numeric
- * representing the result.
- * @param op The multiplier.
- * @return A Numeric representing the result.
- * @throws PropertyException If both Numerics have "mixed" type.
- */
- public Numeric multiply(Numeric op) throws PropertyException {
- // Multiply together absolute units and add dimensions (exponents)
- // What about percentages??? Treat as colUnits if they can't be
- // in same property!
- if (dim == 0) {
- // This is a dimensionless quantity, ie. a "Number"
- return new Numeric(op.valType, absValue * op.absValue,
- absValue * op.pcValue,
- absValue * op.tcolValue, op.dim, op.pcBase);
- } else if (op.dim == 0) {
- double opval = op.absValue;
- return new Numeric(valType, opval * absValue, opval * pcValue,
- opval * tcolValue, dim, pcBase);
- } else if (valType == op.valType &&!isMixedType()) {
- // Check same relbase and pcbase ???
- PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase
- : op.pcBase;
- return new Numeric(valType, absValue * op.absValue,
- pcValue * op.pcValue,
- tcolValue * op.tcolValue, dim + op.dim,
- npcBase);
- } else {
- throw new PropertyException("Can't multiply mixed Numerics");
- }
- }
-
- /**
- * Divide the the current value by the operand and return a new Numeric
- * representing the result.
- * @param op The divisor.
- * @return A Numeric representing the result.
- * @throws PropertyException If both Numerics have "mixed" type.
- */
- public Numeric divide(Numeric op) throws PropertyException {
- // Multiply together absolute units and add dimensions (exponents)
- // What about percentages??? Treat as colUnits if they can't be
- // in same property!
- if (dim == 0) {
- // This is a dimensionless quantity, ie. a "Number"
- return new Numeric(op.valType, absValue / op.absValue,
- absValue / op.pcValue,
- absValue / op.tcolValue, -op.dim, op.pcBase);
- } else if (op.dim == 0) {
- double opval = op.absValue;
- return new Numeric(valType, absValue / opval, pcValue / opval,
- tcolValue / opval, dim, pcBase);
- } else if (valType == op.valType &&!isMixedType()) {
- PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase
- : op.pcBase;
- return new Numeric(valType,
- (valType == ABS_LENGTH ? absValue / op.absValue : 0.0),
- (valType == PC_LENGTH ? pcValue / op.pcValue : 0.0),
- (valType == TCOL_LENGTH ? tcolValue / op.tcolValue : 0.0),
- dim - op.dim, npcBase);
- } else {
- throw new PropertyException("Can't divide mixed Numerics.");
- }
- }
-
- /**
- * Return the absolute value of this Numeric.
- * @return A new Numeric object representing the absolute value.
- */
- public Numeric abs() {
- return new Numeric(valType, Math.abs(absValue), Math.abs(pcValue),
- Math.abs(tcolValue), dim, pcBase);
- }
-
- /**
- * Return a Numeric which is the maximum of the current value and the
- * operand.
- * @throws PropertyException If the dimensions or value types of the
- * object and the operand are different.
- */
- public Numeric max(Numeric op) throws PropertyException {
- double rslt = 0.0;
- // Only compare if have same dimension and value type!
- if (dim == op.dim && valType == op.valType &&!isMixedType()) {
- if (valType == ABS_LENGTH)
- rslt = absValue - op.absValue;
- else if (valType == PC_LENGTH)
- rslt = pcValue - op.pcValue;
- else if (valType == TCOL_LENGTH)
- rslt = tcolValue - op.tcolValue;
- if (rslt > 0.0)
- return this;
- else
- return op;
- }
- throw new PropertyException("Arguments to max() must have same dimension and value type.");
- }
-
- /**
- * Return a Numeric which is the minimum of the current value and the
- * operand.
- * @throws PropertyException If the dimensions or value types of the
- * object and the operand are different.
- */
- public Numeric min(Numeric op) throws PropertyException {
- double rslt = 0.0;
- // Only compare if have same dimension and value type!
- if (dim == op.dim && valType == op.valType &&!isMixedType()) {
- if (valType == ABS_LENGTH)
- rslt = absValue - op.absValue;
- else if (valType == PC_LENGTH)
- rslt = pcValue - op.pcValue;
- else if (valType == TCOL_LENGTH)
- rslt = tcolValue - op.tcolValue;
- if (rslt > 0.0)
- return op;
- else
- return this;
- }
- throw new PropertyException("Arguments to min() must have same dimension and value type.");
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-package org.apache.fop.fo.expr;
-
-import org.apache.fop.fo.Property;
-import org.apache.fop.datatypes.Length;
-import org.apache.fop.datatypes.ColorType;
-
-class NumericProperty extends Property {
- private Numeric numeric;
-
- NumericProperty(Numeric value) {
- this.numeric = value;
- }
-
- public Numeric getNumeric() {
- return this.numeric;
- }
-
- public Number getNumber() {
- return numeric.asNumber();
- }
-
- public Length getLength() {
- return numeric.asLength();
- }
-
- public ColorType getColorType() {
- // try converting to numeric number and then to color
- return null;
- }
-
- public Object getObject() {
- return this.numeric;
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-
-import org.apache.fop.fo.Property;
-import org.apache.fop.fo.LengthProperty;
-import org.apache.fop.datatypes.TableColLength;
-
-public class PPColWidthFunction extends FunctionBase {
-
- public int nbArgs() {
- return 1;
- }
-
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
- Number d = args[0].getNumber();
- if (d == null) {
- throw new PropertyException("Non number operand to proportional-column-width function");
- }
- if (!pInfo.getPropertyList().getElement().equals("table-column")) {
- throw new PropertyException("proportional-column-width function may only be used on table-column FO");
- }
- // Check if table-layout is "fixed"...
- return new LengthProperty(new TableColLength(d.doubleValue()));
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-import java.util.Stack;
-
-import org.apache.fop.fo.Property;
-import org.apache.fop.fo.PropertyList;
-import org.apache.fop.fo.FObj;
-import org.apache.fop.datatypes.PercentBase;
-
-
-/**
- * This class holds context information needed during property expression
- * evaluation.
- * It holds the Maker object for the property, the PropertyList being
- * built, and the FObj parent of the FObj for which the property is being set.
- */
-public class PropertyInfo {
- private Property.Maker maker;
- private PropertyList plist;
- private FObj fo;
- private Stack stkFunction; // Stack of functions being evaluated
-
- public PropertyInfo(Property.Maker maker, PropertyList plist, FObj fo) {
- this.maker = maker;
- this.plist = plist;
- this.fo = fo;
- }
-
- /**
- * Return whether this property inherits specified values.
- * Propagates to the Maker.
- * @return true if the property inherits specified values, false if it
- * inherits computed values.
- */
- public boolean inheritsSpecified() {
- return maker.inheritsSpecified();
- }
-
- /**
- * Return the PercentBase object used to calculate the absolute value from
- * a percent specification.
- * Propagates to the Maker.
- * @return The PercentBase object or null if percentLengthOK()=false.
- */
- public PercentBase getPercentBase() {
- PercentBase pcbase = getFunctionPercentBase();
- return (pcbase != null) ? pcbase : maker.getPercentBase(fo, plist);
- }
-
- /**
- * Return the current font-size value as base units (milli-points).
- */
- public int currentFontSize() {
- return plist.get("font-size").getLength().mvalue();
- }
-
- public FObj getFO() {
- return fo;
- }
-
- public PropertyList getPropertyList() {
- return plist;
- }
-
- public void pushFunction(Function func) {
- if (stkFunction == null) {
- stkFunction = new Stack();
- }
- stkFunction.push(func);
- }
-
- public void popFunction() {
- if (stkFunction != null)
- stkFunction.pop();
- }
-
- private PercentBase getFunctionPercentBase() {
- if (stkFunction != null) {
- Function f = (Function)stkFunction.peek();
- if (f != null) {
- return f.getPercentBase();
- }
- }
- return null;
- }
-
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-
-import org.apache.fop.fo.Property;
-import org.apache.fop.fo.ColorTypeProperty;
-import org.apache.fop.datatypes.ColorType;
-import org.apache.fop.datatypes.PercentBase;
-
-class RGBColorFunction extends FunctionBase {
- public int nbArgs() {
- return 3;
- }
-
- /**
- * Return an object which implements the PercentBase interface.
- * Percents in arguments to this function are interpreted relative
- * to 255.
- */
- public PercentBase getPercentBase() {
- return new RGBPercentBase();
- }
-
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
- // Using CSS rules, numbers are either supposed to be 0-255
- // or percentage values. If percentages value, they've already
- // been converted to reals.
- float[] cfvals = new float[3]; // RGB
- for (int i = 0; i < 3; i++) {
- Number cval = args[i].getNumber();
- if (cval == null) {
- throw new PropertyException("Argument to rgb() must be a Number");
- }
- float colorVal = cval.floatValue() / 255f;
- if (colorVal < 0.0 || colorVal > 255.0) {
- throw new PropertyException("Arguments to rgb() must normalize to the range 0 to 1");
- }
- cfvals[i] = colorVal;
- }
- return new ColorTypeProperty(new ColorType(cfvals[0], cfvals[1],
- cfvals[2]));
-
- }
-
- static class RGBPercentBase implements PercentBase {
- public int getDimension() {
- return 0;
- }
-
- public double getBaseValue() {
- return 255f;
- }
-
- public int getBaseLength() {
- return 0;
- }
-
- }
-}
+++ /dev/null
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- */
-
-package org.apache.fop.fo.expr;
-
-
-import org.apache.fop.fo.Property;
-import org.apache.fop.fo.NumberProperty;
-
-class RoundFunction extends FunctionBase {
- public int nbArgs() {
- return 1;
- }
-
- public Property eval(Property[] args,
- PropertyInfo pInfo) throws PropertyException {
- Number dbl = args[0].getNumber();
- if (dbl == null)
- throw new PropertyException("Non number operand to round function");
- double n = dbl.doubleValue();
- double r = Math.floor(n + 0.5);
- if (r == 0.0 && n < 0.0)
- r = -r; // round(-0.2) returns -0 not 0
- return new NumberProperty(r);
- }
-
-}