git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1328963 13f79535-47bb-0310-9956-ffa450edef68tags/fop-1_1rc1old
*/ | */ | ||||
public class AbsFunction extends FunctionBase { | public class AbsFunction extends FunctionBase { | ||||
/** | |||||
* @return 1 (the number of arguments required for the abs function) | |||||
*/ | |||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 1; | return 1; | ||||
} | } | ||||
/** | |||||
* @param args array of arguments to be evaluated, the first of which | |||||
* should be a numeric value | |||||
* @param propInfo the PropertyInfo object to be evaluated | |||||
* @return the absolute value of the input | |||||
* @throws PropertyException for non-numeric input | |||||
*/ | |||||
public Property eval(Property[] args, | |||||
PropertyInfo propInfo) throws PropertyException { | |||||
/** {@inheritDoc} */ | |||||
public Property eval(Property[] args, PropertyInfo propInfo) throws PropertyException { | |||||
Numeric num = args[0].getNumeric(); | Numeric num = args[0].getNumeric(); | ||||
if (num == null) { | if (num == null) { | ||||
throw new PropertyException("Non numeric operand to abs function"); | throw new PropertyException("Non numeric operand to abs function"); |
*/ | */ | ||||
public class BodyStartFunction extends FunctionBase { | public class BodyStartFunction extends FunctionBase { | ||||
/** | |||||
* @return 0 (there are no arguments for body-start) | |||||
*/ | |||||
public int nbArgs() { | |||||
return 0; | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 1; | |||||
} | } | ||||
/** | |||||
* @param args array of arguments (none are used, but this is required by | |||||
* the Function interface) | |||||
* @param pInfo PropertyInfo object to be evaluated | |||||
* @return numeric object containing the calculated body-start value | |||||
* @throws PropertyException if called from outside of an fo:list-item | |||||
*/ | |||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
/** {@inheritDoc} */ | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
Numeric distance | Numeric distance | ||||
= pInfo.getPropertyList() | = pInfo.getPropertyList() | ||||
.get(Constants.PR_PROVISIONAL_DISTANCE_BETWEEN_STARTS).getNumeric(); | .get(Constants.PR_PROVISIONAL_DISTANCE_BETWEEN_STARTS).getNumeric(); |
*/ | */ | ||||
class CIELabColorFunction extends FunctionBase { | class CIELabColorFunction extends FunctionBase { | ||||
/** | |||||
* cie-lab-color() takes 2 times 3 arguments. | |||||
* {@inheritDoc} | |||||
*/ | |||||
public int nbArgs() { | |||||
return 2 * 3; | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 6; | |||||
} | } | ||||
@Override | |||||
/** {@inheritDoc} */ | |||||
public PercentBase getPercentBase() { | public PercentBase getPercentBase() { | ||||
return new CIELabPercentBase(); | return new CIELabPercentBase(); | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
float red = args[0].getNumber().floatValue(); | float red = args[0].getNumber().floatValue(); | ||||
float green = args[1].getNumber().floatValue(); | float green = args[1].getNumber().floatValue(); | ||||
float blue = args[2].getNumber().floatValue(); | float blue = args[2].getNumber().floatValue(); | ||||
/* Verify sRGB replacement arguments */ | /* Verify sRGB replacement arguments */ | ||||
if ((red < 0 || red > 255) | |||||
|| (green < 0 || green > 255) | |||||
|| (blue < 0 || blue > 255)) { | |||||
if ((red < 0 || red > 255) || (green < 0 || green > 255) || (blue < 0 || blue > 255)) { | |||||
throw new PropertyException("sRGB color values out of range. " | throw new PropertyException("sRGB color values out of range. " | ||||
+ "Arguments to cie-lab-color() must be [0..255] or [0%..100%]"); | + "Arguments to cie-lab-color() must be [0..255] or [0%..100%]"); | ||||
} | } |
*/ | */ | ||||
class CMYKcolorFunction extends FunctionBase { | class CMYKcolorFunction extends FunctionBase { | ||||
/** | |||||
* cmyk takes four arguments. | |||||
* {@inheritDoc} | |||||
*/ | |||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 4; | return 4; | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
sb.append("cmyk(" + args[0] + "," + args[1] + "," + args[2] + "," + args[3] + ")"); | sb.append("cmyk(" + args[0] + "," + args[1] + "," + args[2] + "," + args[3] + ")"); | ||||
FOUserAgent ua = (pInfo == null) | FOUserAgent ua = (pInfo == null) |
class CeilingFunction extends FunctionBase { | class CeilingFunction extends FunctionBase { | ||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 1; | return 1; | ||||
} | } | ||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
/** {@inheritDoc} */ | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
Number dbl = args[0].getNumber(); | Number dbl = args[0].getNumber(); | ||||
if (dbl == null) { | if (dbl == null) { | ||||
throw new PropertyException("Non number operand to ceiling function"); | throw new PropertyException("Non number operand to ceiling function"); |
class FloorFunction extends FunctionBase { | class FloorFunction extends FunctionBase { | ||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 1; | return 1; | ||||
} | } | ||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
/** {@inheritDoc} */ | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
Number dbl = args[0].getNumber(); | Number dbl = args[0].getNumber(); | ||||
if (dbl == null) { | if (dbl == null) { | ||||
throw new PropertyException("Non number operand to floor function"); | throw new PropertyException("Non number operand to floor function"); |
*/ | */ | ||||
public class FromParentFunction extends FunctionBase { | public class FromParentFunction extends FunctionBase { | ||||
/** | |||||
* @return 1 (maximum arguments for the from-parent function) | |||||
*/ | |||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 0; | |||||
} | |||||
@Override | |||||
/** {@inheritDoc} */ | |||||
public int getOptionalArgsCount() { | |||||
return 1; | return 1; | ||||
} | } | ||||
/** | |||||
* @return true (allow padding of arglist with property name) | |||||
*/ | |||||
public boolean padArgsWithPropertyName() { | |||||
return true; | |||||
@Override | |||||
/** {@inheritDoc} */ | |||||
public Property getOptionalArgDefault(int index, PropertyInfo pi) throws PropertyException { | |||||
if ( index == 0 ) { | |||||
return getPropertyName ( pi ); | |||||
} else { | |||||
return super.getOptionalArgDefault ( index, pi ); | |||||
} | |||||
} | } | ||||
/** | |||||
* @param args array of arguments, which should either be empty, or the | |||||
* first of which should contain an NCName corresponding to property name | |||||
* @param pInfo PropertyInfo object to be evaluated | |||||
* @return property containing the computed value | |||||
* @throws PropertyException if the arguments are incorrect | |||||
*/ | |||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
/** {@inheritDoc} */ | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
String propName = args[0].getString(); | String propName = args[0].getString(); | ||||
if (propName == null) { | if (propName == null) { | ||||
throw new PropertyException("Incorrect parameter to from-parent function"); | throw new PropertyException("Incorrect parameter to from-parent function"); |
*/ | */ | ||||
public class FromTableColumnFunction extends FunctionBase { | public class FromTableColumnFunction extends FunctionBase { | ||||
/** | |||||
* @return 1 (maximum arguments for the from-table-column function) | |||||
*/ | |||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 0; | |||||
} | |||||
@Override | |||||
/** {@inheritDoc} */ | |||||
public int getOptionalArgsCount() { | |||||
return 1; | return 1; | ||||
} | } | ||||
/** | |||||
* @return true (allow padding of arglist with property name) | |||||
*/ | |||||
public boolean padArgsWithPropertyName() { | |||||
return true; | |||||
@Override | |||||
/** {@inheritDoc} */ | |||||
public Property getOptionalArgDefault(int index, PropertyInfo pi) throws PropertyException { | |||||
if ( index == 0 ) { | |||||
return getPropertyName ( pi ); | |||||
} else { | |||||
return super.getOptionalArgDefault ( index, pi ); | |||||
} | |||||
} | } | ||||
/** | |||||
* | |||||
* @param args array of arguments, which should either be empty, or the | |||||
* first of which should contain an NCName corresponding to a property name | |||||
* @param pInfo PropertyInfo object to be evaluated | |||||
* @return the Property corresponding to the property name specified, or, if | |||||
* none, for the property for which the expression is being evaluated | |||||
* @throws PropertyException for incorrect arguments, and (for now) in all | |||||
* cases, because this function is not implemented | |||||
*/ | |||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
/** {@inheritDoc} */ | |||||
public Property eval(Property[] args,PropertyInfo pInfo) throws PropertyException { | |||||
FObj fo = pInfo.getPropertyList().getFObj(); | FObj fo = pInfo.getPropertyList().getFObj(); | ||||
public interface Function { | public interface Function { | ||||
/** | /** | ||||
* @return the number of arguments that must be passed to this function. For | |||||
* example, if the function should determine the minimum of two numbers, it | |||||
* must be passed two arguments, one for each of the two values. | |||||
* @return the number of required (non-optional) arguments that must be specified | |||||
* in the argument list | |||||
*/ | */ | ||||
int nbArgs(); | |||||
int getRequiredArgsCount(); | |||||
/** | |||||
* @return the number of non-required (optional) arguments that may be specified | |||||
* in the argument list, which, if specified, must follow the required arguments | |||||
*/ | |||||
int getOptionalArgsCount(); | |||||
/** | |||||
* @param index of optional argument | |||||
* @param pi property information instance that applies to property being evaluated | |||||
* @return the default property value for the optional argument at INDEX, where | |||||
* INDEX is with respect to optional arguments; i.e., the first optional argument | |||||
* position is index 0; if no default for a given index, then null is returned | |||||
* @throws PropertyException if index is greater than or equal to optional args count | |||||
*/ | |||||
public Property getOptionalArgDefault(int index, PropertyInfo pi) throws PropertyException; | |||||
/** | |||||
* Determine if function allows variable arguments. If it does, then they must appear | |||||
* after required and optional arguments, and all optional arguments must be specified. | |||||
* @return true if function permits additional variable number of arguments after | |||||
* required and (completely specified) optional arguments | |||||
*/ | |||||
boolean hasVariableArgs(); | |||||
/** | /** | ||||
* @return the basis for percentage calculations | * @return the basis for percentage calculations | ||||
/** | /** | ||||
* Evaluate the function | * Evaluate the function | ||||
* @param args an array of Properties that should be evaluated | * @param args an array of Properties that should be evaluated | ||||
* @param propInfo the PropertyInfo | |||||
* @param pi property information instance that applies to property being evaluated | |||||
* @return the Property satisfying the function | * @return the Property satisfying the function | ||||
* @throws PropertyException for problems when evaluating the function | * @throws PropertyException for problems when evaluating the function | ||||
*/ | */ | ||||
Property eval(Property[] args, | |||||
PropertyInfo propInfo) throws PropertyException; | |||||
Property eval(Property[] args, PropertyInfo pi) throws PropertyException; | |||||
/** | |||||
* @return if it is allowed to fill up the property list with | |||||
* the property name if only one arg is missing. | |||||
*/ | |||||
boolean padArgsWithPropertyName(); | |||||
} | } |
*/ | */ | ||||
public abstract class FunctionBase implements Function { | public abstract class FunctionBase implements Function { | ||||
/** | |||||
* @return null (by default, functions have no percent-based arguments) | |||||
*/ | |||||
/** {@inheritDoc} */ | |||||
public int getOptionalArgsCount() { | |||||
return 0; | |||||
} | |||||
/** {@inheritDoc} */ | |||||
public Property getOptionalArgDefault(int index, PropertyInfo pi) new PropertyException { | |||||
if ( index >= getOptionalArgsCount() ) { | |||||
PropertyException e = new PropertyException ( new IndexOutOfBoundException ( "illegal optional argument index" ) ); | |||||
e.setPropertyInfo ( pi ); | |||||
throw e; | |||||
} else { | |||||
return null; | |||||
} | |||||
} | |||||
/** {@inheritDoc} */ | |||||
public int hasVariableArgs() { | |||||
return false; | |||||
} | |||||
/** {@inheritDoc} */ | |||||
public PercentBase getPercentBase() { | public PercentBase getPercentBase() { | ||||
return null; | return null; | ||||
} | } | ||||
/** | /** | ||||
* @return false (by default don't pad arglist with property-name) | |||||
* @param pi property information instance that applies to property being evaluated | |||||
* @return string property whose value is name of property being evaluated | |||||
*/ | */ | ||||
public boolean padArgsWithPropertyName() { | |||||
return false; | |||||
protected final Property getPropertyName ( PropertyInfo pi ) { | |||||
return StringProperty.getInstance ( pi.getPropertMaker().getName() ); | |||||
} | } | ||||
} | } |
*/ | */ | ||||
class ICCColorFunction extends FunctionBase { | class ICCColorFunction extends FunctionBase { | ||||
/** | |||||
* rgb-icc takes a variable number of arguments. | |||||
* At least 4 should be passed - returns -4 | |||||
* {@inheritDoc} | |||||
*/ | |||||
public int nbArgs() { | |||||
return -4; | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 4; | |||||
} | } | ||||
@Override | |||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public int hasVariableArgs() { | |||||
return true; | |||||
} | |||||
@Override | @Override | ||||
/** {@inheritDoc} */ | |||||
public PercentBase getPercentBase() { | public PercentBase getPercentBase() { | ||||
return new ICCPercentBase(); | return new ICCPercentBase(); | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
// Map color profile NCNAME to src from declarations/color-profile element | // Map color profile NCNAME to src from declarations/color-profile element | ||||
String colorProfileName = args[3].getString(); | String colorProfileName = args[3].getString(); | ||||
Declarations decls = (pInfo.getFO() != null | Declarations decls = (pInfo.getFO() != null | ||||
green = args[1].getNumber().floatValue(); | green = args[1].getNumber().floatValue(); | ||||
blue = args[2].getNumber().floatValue(); | blue = args[2].getNumber().floatValue(); | ||||
/* Verify rgb replacement arguments */ | /* Verify rgb replacement arguments */ | ||||
if ((red < 0 || red > 255) | |||||
|| (green < 0 || green > 255) | |||||
|| (blue < 0 || blue > 255)) { | |||||
if ((red < 0 || red > 255) || (green < 0 || green > 255) || (blue < 0 || blue > 255)) { | |||||
throw new PropertyException("Color values out of range. " | throw new PropertyException("Color values out of range. " | ||||
+ "Arguments to rgb-icc() must be [0..255] or [0%..100%]"); | + "Arguments to rgb-icc() must be [0..255] or [0%..100%]"); | ||||
} | } |
*/ | */ | ||||
public class InheritedPropFunction extends FunctionBase { | public class InheritedPropFunction extends FunctionBase { | ||||
/** | |||||
* @return 1 (maximum number of arguments for the inherited-property-value | |||||
* function) | |||||
*/ | |||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 0; | |||||
} | |||||
@Override | |||||
/** {@inheritDoc} */ | |||||
public int getOptionalArgsCount() { | |||||
return 1; | return 1; | ||||
} | } | ||||
/** | |||||
* @return true (allow padding of arglist with property name) | |||||
*/ | |||||
public boolean padArgsWithPropertyName() { | |||||
return true; | |||||
@Override | |||||
/** {@inheritDoc} */ | |||||
public Property getOptionalArgDefault(int index, PropertyInfo pi) throws PropertyException { | |||||
if ( index == 0 ) { | |||||
return getPropertyName ( pi ); | |||||
} else { | |||||
return super.getOptionalArgDefault ( index, pi ); | |||||
} | |||||
} | } | ||||
/** | |||||
* | |||||
* @param args arguments to be evaluated | |||||
* @param pInfo PropertyInfo object to be evaluated | |||||
* @return Property satisfying the inherited-property-value | |||||
* @throws PropertyException for invalid parameter | |||||
*/ | |||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
/** {@inheritDoc} */ | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
String propName = args[0].getString(); | String propName = args[0].getString(); | ||||
if (propName == null) { | if (propName == null) { | ||||
throw new PropertyException("Incorrect parameter to inherited-property-value function"); | throw new PropertyException("Incorrect parameter to inherited-property-value function"); |
*/ | */ | ||||
public class LabelEndFunction extends FunctionBase { | public class LabelEndFunction extends FunctionBase { | ||||
/** | |||||
* @return 0 (the number of arguments required for the label-end function) | |||||
*/ | |||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 0; | return 0; | ||||
} | } | ||||
/** | |||||
* | |||||
* @param args array of arguments for the function (none are needed, but | |||||
* required for the Function interface) | |||||
* @param pInfo PropertyInfo object for the function | |||||
* @return the calculated label-end value for the list | |||||
* @throws PropertyException if called from outside of an fo:list-item | |||||
*/ | |||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
/** {@inheritDoc} */ | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
Length distance = pInfo.getPropertyList().get( | Length distance = pInfo.getPropertyList().get( | ||||
Constants.PR_PROVISIONAL_DISTANCE_BETWEEN_STARTS).getLength(); | Constants.PR_PROVISIONAL_DISTANCE_BETWEEN_STARTS).getLength(); |
*/ | */ | ||||
public class MaxFunction extends FunctionBase { | public class MaxFunction extends FunctionBase { | ||||
/** | |||||
* @return 2 (the number of arguments required for the max function) | |||||
*/ | |||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 2; | return 2; | ||||
} | } | ||||
/** | |||||
* Handle "numerics" if no proportional/percent parts | |||||
* @param args array of arguments to be processed | |||||
* @param pInfo PropertyInfo to be processed | |||||
* @return the maximum of the two args elements passed | |||||
* @throws PropertyException for invalid operands | |||||
*/ | |||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
/** {@inheritDoc} */ | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
Numeric n1 = args[0].getNumeric(); | Numeric n1 = args[0].getNumeric(); | ||||
Numeric n2 = args[1].getNumeric(); | Numeric n2 = args[1].getNumeric(); | ||||
if (n1 == null || n2 == null) { | if (n1 == null || n2 == null) { |
*/ | */ | ||||
public class MinFunction extends FunctionBase { | public class MinFunction extends FunctionBase { | ||||
/** | |||||
* @return 2 (the number of arguments required for the min function) | |||||
*/ | |||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 2; | return 2; | ||||
} | } | ||||
/** | |||||
* Handle "numerics" if no proportional/percent parts | |||||
* @param args array of arguments to be processed | |||||
* @param pInfo PropertyInfo to be processed | |||||
* @return the minimum of the two args elements passed | |||||
* @throws PropertyException for invalid operands | |||||
*/ | |||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
/** {@inheritDoc} */ | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
Numeric n1 = args[0].getNumeric(); | Numeric n1 = args[0].getNumeric(); | ||||
Numeric n2 = args[1].getNumeric(); | Numeric n2 = args[1].getNumeric(); | ||||
if (n1 == null || n2 == null) { | if (n1 == null || n2 == null) { |
*/ | */ | ||||
class NamedColorFunction extends FunctionBase { | class NamedColorFunction extends FunctionBase { | ||||
/** | |||||
* rgb-named-color() takes a 5 arguments. | |||||
* {@inheritDoc} | |||||
*/ | |||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 5; | return 5; | ||||
} | } | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
// Map color profile NCNAME to src from declarations/color-profile element | // Map color profile NCNAME to src from declarations/color-profile element | ||||
String colorProfileName = args[3].getString(); | String colorProfileName = args[3].getString(); | ||||
String colorName = args[4].getString(); | String colorName = args[4].getString(); |
*/ | */ | ||||
public class NearestSpecPropFunction extends FunctionBase { | public class NearestSpecPropFunction extends FunctionBase { | ||||
/** | |||||
* @return 1 (maximum number of arguments for from-nearest-specified-value | |||||
* function) | |||||
*/ | |||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 0; | |||||
} | |||||
@Override | |||||
/** {@inheritDoc} */ | |||||
public int getOptionalArgsCount() { | |||||
return 1; | return 1; | ||||
} | } | ||||
/** | |||||
* @return true (allow padding of arglist with property name) | |||||
*/ | |||||
public boolean padArgsWithPropertyName() { | |||||
return true; | |||||
@Override | |||||
/** {@inheritDoc} */ | |||||
public Property getOptionalArgDefault(int index, PropertyInfo pi) throws PropertyException { | |||||
if ( index == 0 ) { | |||||
return getPropertyName ( pi ); | |||||
} else { | |||||
return super.getOptionalArgDefault ( index, pi ); | |||||
} | |||||
} | } | ||||
/** | |||||
* | |||||
* @param args array of arguments for the function | |||||
* @param pInfo PropertyInfo for the function | |||||
* @return Property containing the nearest-specified-value | |||||
* @throws PropertyException for invalid arguments to the function | |||||
*/ | |||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
/** {@inheritDoc} */ | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
String propName = args[0].getString(); | String propName = args[0].getString(); | ||||
if (propName == null) { | if (propName == null) { | ||||
throw new PropertyException( | throw new PropertyException( |
*/ | */ | ||||
public class PPColWidthFunction extends FunctionBase { | public class PPColWidthFunction extends FunctionBase { | ||||
/** | |||||
* @return 1 (the number of arguments for the proportional-column-width | |||||
* function) | |||||
*/ | |||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 1; | return 1; | ||||
} | } | ||||
/** | |||||
* @return the {@link PercentBase} for the proportional-column-width() | |||||
* function | |||||
*/ | |||||
@Override | |||||
/** {@inheritDoc} */ | |||||
public PercentBase getPercentBase() { | public PercentBase getPercentBase() { | ||||
return new PPColWidthPercentBase(); | return new PPColWidthPercentBase(); | ||||
} | } | ||||
/** | |||||
* | |||||
* @param args array of arguments for this function | |||||
* @param pInfo PropertyInfo for this function | |||||
* @return numeric Property containing the units of proportional measure | |||||
* for this column | |||||
* @throws PropertyException for non-numeric operand, or if the parent | |||||
* element is not a table-column | |||||
*/ | |||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
/** {@inheritDoc} */ | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
Number d = args[0].getNumber(); | Number d = args[0].getNumber(); | ||||
if (d == null) { | if (d == null) { | ||||
throw new PropertyException("Non numeric operand to " | throw new PropertyException("Non numeric operand to " |
FUNCTION_TABLE.put("rgb", new RGBColorFunction()); | FUNCTION_TABLE.put("rgb", new RGBColorFunction()); | ||||
FUNCTION_TABLE.put("system-color", new SystemColorFunction()); | FUNCTION_TABLE.put("system-color", new SystemColorFunction()); | ||||
FUNCTION_TABLE.put("from-table-column", new FromTableColumnFunction()); | FUNCTION_TABLE.put("from-table-column", new FromTableColumnFunction()); | ||||
FUNCTION_TABLE.put("inherited-property-value", | |||||
new InheritedPropFunction()); | |||||
FUNCTION_TABLE.put("inherited-property-value", new InheritedPropFunction()); | |||||
FUNCTION_TABLE.put("from-nearest-specified-value", new NearestSpecPropFunction()); | |||||
FUNCTION_TABLE.put("from-page-master-region", new FromPageMasterRegionFunction()); | |||||
FUNCTION_TABLE.put("from-parent", new FromParentFunction()); | FUNCTION_TABLE.put("from-parent", new FromParentFunction()); | ||||
FUNCTION_TABLE.put("from-nearest-specified-value", | |||||
new NearestSpecPropFunction()); | |||||
FUNCTION_TABLE.put("proportional-column-width", | |||||
new PPColWidthFunction()); | |||||
FUNCTION_TABLE.put("proportional-column-width", new PPColWidthFunction()); | |||||
FUNCTION_TABLE.put("label-end", new LabelEndFunction()); | FUNCTION_TABLE.put("label-end", new LabelEndFunction()); | ||||
FUNCTION_TABLE.put("body-start", new BodyStartFunction()); | FUNCTION_TABLE.put("body-start", new BodyStartFunction()); | ||||
FUNCTION_TABLE.put("rgb-icc", new ICCColorFunction()); | FUNCTION_TABLE.put("rgb-icc", new ICCColorFunction()); | ||||
next(); | next(); | ||||
} else { | } else { | ||||
while (true) { | while (true) { | ||||
prop = parseAdditiveExpr(); | prop = parseAdditiveExpr(); | ||||
if (i < nbArgs) { | if (i < nbArgs) { | ||||
args[i++] = prop; | args[i++] = prop; |
} | } | ||||
/** | /** | ||||
* Return the next token in the expression string. | |||||
* Parse the next token in the expression string. | |||||
* This sets the following package visible variables: | * This sets the following package visible variables: | ||||
* currentToken An enumerated value identifying the recognized token | * currentToken An enumerated value identifying the recognized token | ||||
* currentTokenValue A String containing the token contents | * currentTokenValue A String containing the token contents |
class RGBColorFunction extends FunctionBase { | class RGBColorFunction extends FunctionBase { | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public int nbArgs() { | |||||
public int getRequiredArgsCount() { | |||||
return 3; | return 3; | ||||
} | } | ||||
/** | |||||
* @return an object which implements the PercentBase interface. | |||||
* Percents in arguments to this function are interpreted relative | |||||
* to 255. | |||||
*/ | |||||
@Override | |||||
/** {@inheritDoc} */ | |||||
public PercentBase getPercentBase() { | public PercentBase getPercentBase() { | ||||
return new RGBPercentBase(); | return new RGBPercentBase(); | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
return ColorProperty.getInstance(pInfo.getUserAgent(), | return ColorProperty.getInstance(pInfo.getUserAgent(), | ||||
"rgb(" + args[0] + "," | "rgb(" + args[0] + "," | ||||
+ args[1] + "," + args[2] + ")"); | + args[1] + "," + args[2] + ")"); |
import org.apache.fop.fo.properties.Property; | import org.apache.fop.fo.properties.Property; | ||||
class RoundFunction extends FunctionBase { | class RoundFunction extends FunctionBase { | ||||
public int nbArgs() { | |||||
/** {@inheritDoc} */ | |||||
public int getRequiredArgsCount() { | |||||
return 1; | return 1; | ||||
} | } | ||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
/** {@inheritDoc} */ | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
Number dbl = args[0].getNumber(); | Number dbl = args[0].getNumber(); | ||||
if (dbl == null) { | if (dbl == null) { | ||||
throw new PropertyException("Non number operand to round function"); | throw new PropertyException("Non number operand to round function"); |
class SystemColorFunction extends FunctionBase { | class SystemColorFunction extends FunctionBase { | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public int nbArgs() { | |||||
public int getRequiredArgsCount() { | |||||
return 1; | return 1; | ||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
public Property eval(Property[] args, | |||||
PropertyInfo pInfo) throws PropertyException { | |||||
public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { | |||||
FOUserAgent ua = (pInfo == null) | FOUserAgent ua = (pInfo == null) | ||||
? null | ? null | ||||
: (pInfo.getFO() == null ? null : pInfo.getFO().getUserAgent()); | : (pInfo.getFO() == null ? null : pInfo.getFO().getUserAgent()); |