diff options
author | Karen Lease <klease@apache.org> | 2000-11-10 21:58:36 +0000 |
---|---|---|
committer | Karen Lease <klease@apache.org> | 2000-11-10 21:58:36 +0000 |
commit | 3bcf62990651a49de8b9c73d017b79ea23f92396 (patch) | |
tree | 5f1deaa801b2a73b496499835abfb74ffff9dbd6 /src/org/apache/fop/fo | |
parent | 57511f306ea10159a47e0dfae160d92f90cddb56 (diff) | |
download | xmlgraphics-fop-3bcf62990651a49de8b9c73d017b79ea23f92396.tar.gz xmlgraphics-fop-3bcf62990651a49de8b9c73d017b79ea23f92396.zip |
property expression parsing classes: initial version
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193765 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/fo')
21 files changed, 2606 insertions, 0 deletions
diff --git a/src/org/apache/fop/fo/expr/AbsFunction.java b/src/org/apache/fop/fo/expr/AbsFunction.java new file mode 100644 index 000000000..578aaffca --- /dev/null +++ b/src/org/apache/fop/fo/expr/AbsFunction.java @@ -0,0 +1,69 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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()); + } +} + diff --git a/src/org/apache/fop/fo/expr/CeilingFunction.java b/src/org/apache/fop/fo/expr/CeilingFunction.java new file mode 100644 index 000000000..5812b53a0 --- /dev/null +++ b/src/org/apache/fop/fo/expr/CeilingFunction.java @@ -0,0 +1,68 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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())); + } +} diff --git a/src/org/apache/fop/fo/expr/FloorFunction.java b/src/org/apache/fop/fo/expr/FloorFunction.java new file mode 100644 index 000000000..f9055db72 --- /dev/null +++ b/src/org/apache/fop/fo/expr/FloorFunction.java @@ -0,0 +1,69 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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())); + } +} diff --git a/src/org/apache/fop/fo/expr/FromParentFunction.java b/src/org/apache/fop/fo/expr/FromParentFunction.java new file mode 100644 index 000000000..4c66b4ffa --- /dev/null +++ b/src/org/apache/fop/fo/expr/FromParentFunction.java @@ -0,0 +1,77 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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); + } + +} diff --git a/src/org/apache/fop/fo/expr/FromTableColumnFunction.java b/src/org/apache/fop/fo/expr/FromTableColumnFunction.java new file mode 100644 index 000000000..cd37b6a52 --- /dev/null +++ b/src/org/apache/fop/fo/expr/FromTableColumnFunction.java @@ -0,0 +1,70 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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!"); + } + +} diff --git a/src/org/apache/fop/fo/expr/Function.java b/src/org/apache/fop/fo/expr/Function.java new file mode 100644 index 000000000..d0aba74f9 --- /dev/null +++ b/src/org/apache/fop/fo/expr/Function.java @@ -0,0 +1,62 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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; +} + diff --git a/src/org/apache/fop/fo/expr/FunctionBase.java b/src/org/apache/fop/fo/expr/FunctionBase.java new file mode 100644 index 000000000..e14bf3eea --- /dev/null +++ b/src/org/apache/fop/fo/expr/FunctionBase.java @@ -0,0 +1,69 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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; + */ +} + diff --git a/src/org/apache/fop/fo/expr/InheritedPropFunction.java b/src/org/apache/fop/fo/expr/InheritedPropFunction.java new file mode 100644 index 000000000..8b708e5fb --- /dev/null +++ b/src/org/apache/fop/fo/expr/InheritedPropFunction.java @@ -0,0 +1,70 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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); + } + +} diff --git a/src/org/apache/fop/fo/expr/MaxFunction.java b/src/org/apache/fop/fo/expr/MaxFunction.java new file mode 100644 index 000000000..2a986aee7 --- /dev/null +++ b/src/org/apache/fop/fo/expr/MaxFunction.java @@ -0,0 +1,70 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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)); + } + +} diff --git a/src/org/apache/fop/fo/expr/MinFunction.java b/src/org/apache/fop/fo/expr/MinFunction.java new file mode 100644 index 000000000..05643b225 --- /dev/null +++ b/src/org/apache/fop/fo/expr/MinFunction.java @@ -0,0 +1,69 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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)); + } + +} diff --git a/src/org/apache/fop/fo/expr/NCnameProperty.java b/src/org/apache/fop/fo/expr/NCnameProperty.java new file mode 100644 index 000000000..abfcbcf85 --- /dev/null +++ b/src/org/apache/fop/fo/expr/NCnameProperty.java @@ -0,0 +1,80 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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; + } + +} diff --git a/src/org/apache/fop/fo/expr/NearestSpecPropFunction.java b/src/org/apache/fop/fo/expr/NearestSpecPropFunction.java new file mode 100644 index 000000000..0c62b346f --- /dev/null +++ b/src/org/apache/fop/fo/expr/NearestSpecPropFunction.java @@ -0,0 +1,71 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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); + } + +} diff --git a/src/org/apache/fop/fo/expr/Numeric.java b/src/org/apache/fop/fo/expr/Numeric.java new file mode 100644 index 000000000..12bcdbf49 --- /dev/null +++ b/src/org/apache/fop/fo/expr/Numeric.java @@ -0,0 +1,405 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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.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."); + } + +} diff --git a/src/org/apache/fop/fo/expr/NumericProperty.java b/src/org/apache/fop/fo/expr/NumericProperty.java new file mode 100644 index 000000000..49d08920d --- /dev/null +++ b/src/org/apache/fop/fo/expr/NumericProperty.java @@ -0,0 +1,84 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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; + } +} diff --git a/src/org/apache/fop/fo/expr/PPColWidthFunction.java b/src/org/apache/fop/fo/expr/PPColWidthFunction.java new file mode 100644 index 000000000..1e2501d42 --- /dev/null +++ b/src/org/apache/fop/fo/expr/PPColWidthFunction.java @@ -0,0 +1,76 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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())); + } + +} diff --git a/src/org/apache/fop/fo/expr/PropertyException.java b/src/org/apache/fop/fo/expr/PropertyException.java new file mode 100644 index 000000000..814d20822 --- /dev/null +++ b/src/org/apache/fop/fo/expr/PropertyException.java @@ -0,0 +1,57 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +package org.apache.fop.fo.expr; + +public class PropertyException extends Exception { + PropertyException(String detail) { + super(detail); + } +} diff --git a/src/org/apache/fop/fo/expr/PropertyInfo.java b/src/org/apache/fop/fo/expr/PropertyInfo.java new file mode 100644 index 000000000..5416ebfbe --- /dev/null +++ b/src/org/apache/fop/fo/expr/PropertyInfo.java @@ -0,0 +1,132 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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; + } +} diff --git a/src/org/apache/fop/fo/expr/PropertyParser.java b/src/org/apache/fop/fo/expr/PropertyParser.java new file mode 100644 index 000000000..209193194 --- /dev/null +++ b/src/org/apache/fop/fo/expr/PropertyParser.java @@ -0,0 +1,460 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.Property; +import org.apache.fop.fo.LengthProperty; +import org.apache.fop.fo.NumberProperty; +import org.apache.fop.fo.StringProperty; +import org.apache.fop.fo.ColorTypeProperty; +import org.apache.fop.datatypes.*; + +import java.util.Hashtable; + +/** + * Class to parse XSL FO property expression. + * This class is heavily based on the epxression parser in James Clark's + * XT, an XSLT processor. + */ +public class PropertyParser extends PropertyTokenizer { + private PropertyInfo propInfo; // Maker and propertyList related info + + static private final String RELUNIT = "em"; + static private final Numeric negOne = new Numeric(new Double(-1.0)); + static final private Hashtable functionTable = new Hashtable(); + + static { + // Initialize the Hashtable of XSL-defined functions + functionTable.put("ceiling", new CeilingFunction()); + functionTable.put("floor", new FloorFunction()); + functionTable.put("round", new RoundFunction()); + functionTable.put("min", new MinFunction()); + functionTable.put("max", new MaxFunction()); + functionTable.put("abs", new AbsFunction()); + functionTable.put("rgb", new RGBColorFunction()); + functionTable.put("from-table-column", new FromTableColumnFunction()); + functionTable.put("inherited-property-value", new InheritedPropFunction()); + functionTable.put("from-parent", new FromParentFunction()); + functionTable.put("from-nearest-specified-value", new NearestSpecPropFunction()); + functionTable.put("proportional-column-width", new PPColWidthFunction()); + + /*** NOT YET IMPLEMENTED!!! + functionTable.put("icc-color", new ICCcolorFunction()); + functionTable.put("system-color", new SystemColorFunction()); + + functionTable.put("system-font", new SystemFontFunction()); + + functionTable.put("label-end", new LabelEndFunction()); + functionTable.put("body-start", new BodyStartFunction()); + functionTable.put("merge-property-values", new MergePropsFunction()); + ***/ + } + + + /** + * Public entrypoint to the Property expression parser. + * @param expr The specified value (attribute on the xml element). + * @param propInfo A PropertyInfo object representing the context in + * which the property expression is to be evaluated. + * @return A Property object holding the parsed result. + * @throws PropertyException If the "expr" cannot be parsed as a Property. + */ + public static Property parse(String expr, PropertyInfo propInfo) + throws PropertyException { + return new PropertyParser(expr, propInfo).parseProperty(); + } + + + /** + * Private constructor. Called by the static parse() method. + * @param propExpr The specified value (attribute on the xml element). + * @param propInfo A PropertyInfo object representing the context in + * which the property expression is to be evaluated. + */ + private PropertyParser(String propExpr, PropertyInfo pInfo) { + super(propExpr); + this.propInfo = pInfo; + } + + /** + * Parse the property expression described in the instance variables. + * Note: If the property expression String is empty, a StringProperty + * object holding an empty String is returned. + * @return A Property object holding the parsed result. + * @throws PropertyException If the "expr" cannot be parsed as a Property. + */ + private Property parseProperty() throws PropertyException { + next(); + if (currentToken == TOK_EOF) { + // if prop value is empty string, force to StringProperty + return new StringProperty(""); + } + Property prop = parseAdditiveExpr(); + if (currentToken != TOK_EOF) + throw new PropertyException("unexpected token"); + return prop; + } + + /** + * Try to parse an addition or subtraction expression and return the + * resulting Property. + */ + private Property parseAdditiveExpr() throws PropertyException { + // Evaluate and put result on the operand stack + Property prop = parseMultiplicativeExpr(); + loop: + for (;;) { + switch (currentToken) { + case TOK_PLUS: + next(); + prop = evalAddition(prop.getNumeric(), + parseMultiplicativeExpr().getNumeric() ); + break; + case TOK_MINUS: + next(); + prop = evalSubtraction(prop.getNumeric(), + parseMultiplicativeExpr().getNumeric() ); + break; + default: + break loop; + } + } + return prop; + } + + /** + * Try to parse a multiply, divide or modulo expression and return + * the resulting Property. + */ + private Property parseMultiplicativeExpr() throws PropertyException { + Property prop = parseUnaryExpr(); + loop: + for (;;) { + switch (currentToken) { + case TOK_DIV: + next(); + prop = evalDivide(prop.getNumeric(), parseUnaryExpr().getNumeric() ); + break; + case TOK_MOD: + next(); + prop = evalModulo(prop.getNumber(), parseUnaryExpr().getNumber() ); + break; + case TOK_MULTIPLY: + next(); + prop = evalMultiply(prop.getNumeric(), parseUnaryExpr().getNumeric()); + break; + default: + break loop; + } + } + return prop; + } + + /** + * Try to parse a unary minus expression and return the + * resulting Property. + */ + private Property parseUnaryExpr() throws PropertyException { + if (currentToken == TOK_MINUS) { + next(); + return evalNegate(parseUnaryExpr().getNumeric()); + } + return parsePrimaryExpr(); + } + + + /** + * Checks that the current token is a right parenthesis + * and throws an exception if this isn't the case. + */ + private final void expectRpar() throws PropertyException { + if (currentToken != TOK_RPAR) + throw new PropertyException("expected )"); + next(); + } + + /** + * Try to parse a primary expression and return the + * resulting Property. + * A primary expression is either a parenthesized expression or an + * expression representing a primitive Property datatype, such as a + * string literal, an NCname, a number or a unit expression, or a + * function call expression. + */ + private Property parsePrimaryExpr() throws PropertyException { + Property prop; + switch (currentToken) { + case TOK_LPAR: + next(); + prop = parseAdditiveExpr(); + expectRpar(); + return prop; + + case TOK_LITERAL: + prop = new StringProperty(currentTokenValue); + break; + + case TOK_NCNAME: + // Interpret this in context of the property or do it later? + prop = new NCnameProperty(currentTokenValue); + break; + + case TOK_FLOAT: + prop = new NumberProperty(new Double(currentTokenValue)); + break; + + case TOK_INTEGER: + prop = new NumberProperty(new Integer(currentTokenValue)); + break; + + case TOK_PERCENT: + /* Get the length base value object from the Maker. If null, then + * this property can't have % values. Treat it as a real number. + */ + double pcval = new Double(currentTokenValue.substring(0, + currentTokenValue.length()-1)). + doubleValue()/100.0; + // LengthBase lbase = this.propInfo.getPercentLengthBase(); + PercentBase pcBase = this.propInfo.getPercentBase(); + if (pcBase != null) { + if (pcBase.getDimension() == 0) { + prop = new NumberProperty(pcval * pcBase.getBaseValue()); + } + else if (pcBase.getDimension() == 1) { + prop = new LengthProperty(new PercentLength(pcval, pcBase)); + } + else { + throw new PropertyException("Illegal percent dimension value"); + } + } + else { + // WARNING? Interpret as a decimal fraction, eg. 50% = .5 + prop = new NumberProperty(pcval); + } + break; + + case TOK_NUMERIC: + // A number plus a valid unit name. + int numLen = currentTokenValue.length()-currentUnitLength; + String unitPart = currentTokenValue.substring(numLen); + Double numPart = new Double(currentTokenValue.substring(0,numLen)); + Length length= null; + if (unitPart.equals(RELUNIT)) { + length = new Length(numPart.doubleValue(), + propInfo.currentFontSize()); + } + else + length = new Length(numPart.doubleValue(), unitPart); + if (length == null) { + throw new PropertyException("unrecognized unit name: "+ currentTokenValue); + } + else prop = new LengthProperty(length); + break; + + case TOK_COLORSPEC: + prop = new ColorTypeProperty(new ColorType(currentTokenValue)); + break; + + case TOK_FUNCTION_LPAR: + { + Function function = (Function)functionTable.get(currentTokenValue); + if (function == null) { + throw new PropertyException("no such function: " + currentTokenValue); + } + next(); + // Push new function (for function context: getPercentBase()) + propInfo.pushFunction(function); + prop = function.eval(parseArgs(function.nbArgs()), propInfo); + propInfo.popFunction(); + return prop; + } + default: + throw new PropertyException("syntax error"); + } + next(); + return prop; + } + + /** + * Parse a comma separated list of function arguments. Each argument + * may itself be an expression. This method consumes the closing right + * parenthesis of the argument list. + * @param nbArgs The number of arguments expected by the function. + * @return An array of Property objects representing the arguments + * found. + * @throws PropertyException If the number of arguments found isn't equal + * to the number expected. + */ + Property[] parseArgs(int nbArgs) throws PropertyException { + Property[] args = new Property[nbArgs]; + Property prop; + int i=0; + if (currentToken == TOK_RPAR) { + // No args: func() + next(); + } + else { + while(true) { + + prop = parseAdditiveExpr(); + if (i < nbArgs) { + args[i++] = prop; + } + // ignore extra args + if (currentToken != TOK_COMMA) + break; + next(); + } + expectRpar(); + } + if (nbArgs != i) { + throw new PropertyException("Wrong number of args for function"); + } + return args; + } + + + /** + * Evaluate an addition operation. If either of the arguments is null, + * this means that it wasn't convertible to a Numeric value. + * @param op1 A Numeric object (Number or Length-type object) + * @param op2 A Numeric object (Number or Length-type object) + * @return A new NumericProperty object holding an object which represents + * the sum of the two operands. + * @throws PropertyException If either operand is null. + */ + private Property evalAddition(Numeric op1, Numeric op2) + throws PropertyException { + if (op1 == null || op2 == null) + throw new PropertyException("Non numeric operand in addition"); + return new NumericProperty(op1.add(op2)); + } + + /** + * Evaluate a subtraction operation. If either of the arguments is null, + * this means that it wasn't convertible to a Numeric value. + * @param op1 A Numeric object (Number or Length-type object) + * @param op2 A Numeric object (Number or Length-type object) + * @return A new NumericProperty object holding an object which represents + * the difference of the two operands. + * @throws PropertyException If either operand is null. + */ + private Property evalSubtraction(Numeric op1, Numeric op2) + throws PropertyException { + if (op1 == null || op2 == null) + throw new PropertyException("Non numeric operand in subtraction"); + return new NumericProperty(op1.subtract(op2)); + } + + /** + * Evaluate a unary minus operation. If the argument is null, + * this means that it wasn't convertible to a Numeric value. + * @param op A Numeric object (Number or Length-type object) + * @return A new NumericProperty object holding an object which represents + * the negative of the operand (multiplication by *1). + * @throws PropertyException If the operand is null. + */ + private Property evalNegate(Numeric op) throws PropertyException { + if (op == null) + throw new PropertyException("Non numeric operand to unary minus"); + return new NumericProperty(op.multiply(negOne)); + } + + /** + * Evaluate a multiplication operation. If either of the arguments is null, + * this means that it wasn't convertible to a Numeric value. + * @param op1 A Numeric object (Number or Length-type object) + * @param op2 A Numeric object (Number or Length-type object) + * @return A new NumericProperty object holding an object which represents + * the product of the two operands. + * @throws PropertyException If either operand is null. + */ + private Property evalMultiply(Numeric op1, Numeric op2) + throws PropertyException { + if (op1 == null || op2 == null) + throw new PropertyException("Non numeric operand in multiplication"); + return new NumericProperty(op1.multiply(op2)); + } + + + /** + * Evaluate a division operation. If either of the arguments is null, + * this means that it wasn't convertible to a Numeric value. + * @param op1 A Numeric object (Number or Length-type object) + * @param op2 A Numeric object (Number or Length-type object) + * @return A new NumericProperty object holding an object which represents + * op1 divided by op2. + * @throws PropertyException If either operand is null. + */ + private Property evalDivide(Numeric op1, Numeric op2) + throws PropertyException { + if (op1 == null || op2 == null) + throw new PropertyException("Non numeric operand in division"); + return new NumericProperty(op1.divide(op2)); + } + + /** + * Evaluate a modulo operation. If either of the arguments is null, + * this means that it wasn't convertible to a Number value. + * @param op1 A Number object + * @param op2 A Number object + * @return A new NumberProperty object holding an object which represents + * op1 mod op2. + * @throws PropertyException If either operand is null. + */ + private Property evalModulo(Number op1, Number op2) + throws PropertyException { + if (op1 == null || op2 == null) + throw new PropertyException("Non number operand to modulo"); + return new NumberProperty(op1.doubleValue()%op2.doubleValue()); + } + +} diff --git a/src/org/apache/fop/fo/expr/PropertyTokenizer.java b/src/org/apache/fop/fo/expr/PropertyTokenizer.java new file mode 100644 index 000000000..47169fe59 --- /dev/null +++ b/src/org/apache/fop/fo/expr/PropertyTokenizer.java @@ -0,0 +1,378 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +package org.apache.fop.fo.expr; + + + +/** + * Class to tokenize XSL FO property expression. + * This class is heavily based on the epxression tokenizer in James Clark's + * XT, an XSLT processor. + */ +class PropertyTokenizer { + + static final int TOK_EOF = 0; + static final int TOK_NCNAME = TOK_EOF + 1; + static final int TOK_MULTIPLY = TOK_NCNAME + 1; + static final int TOK_LPAR = TOK_MULTIPLY + 1; + static final int TOK_RPAR = TOK_LPAR + 1; + static final int TOK_LITERAL = TOK_RPAR + 1; + static final int TOK_NUMBER = TOK_LITERAL + 1; + static final int TOK_FUNCTION_LPAR = TOK_NUMBER + 1; + static final int TOK_PLUS = TOK_FUNCTION_LPAR + 1; + static final int TOK_MINUS = TOK_PLUS + 1; + static final int TOK_MOD = TOK_MINUS + 1; + static final int TOK_DIV = TOK_MOD + 1; + static final int TOK_NUMERIC = TOK_DIV + 1; + static final int TOK_COMMA = TOK_NUMERIC + 1; + static final int TOK_PERCENT = TOK_COMMA + 1; + static final int TOK_COLORSPEC = TOK_PERCENT + 1; + static final int TOK_FLOAT = TOK_COLORSPEC + 1; + static final int TOK_INTEGER = TOK_FLOAT + 1; + + int currentToken = TOK_EOF; + String currentTokenValue = null; + protected int currentUnitLength = 0; + + private int currentTokenStartIndex = 0; + private final String expr; + private int exprIndex = 0; + private int exprLength; + private boolean recognizeOperator = false; + + + /** + * Construct a new PropertyTokenizer object to tokenize the passed + * String. + * @param s The Property expressio to tokenize. + */ + PropertyTokenizer(String s) { + this.expr = s; + this.exprLength = s.length(); + } + + /** + * Return the next token in the expression string. + * This sets the following package visible variables: + * currentToken An enumerated value identifying the recognized token + * currentTokenValue A String containing the token contents + * currentUnitLength If currentToken = TOK_NUMERIC, the number of + * characters in the unit name. + * @throws PropertyException If un unrecognized token is encountered. + */ + void next() throws PropertyException { + currentTokenValue = null; + currentTokenStartIndex = exprIndex; + boolean currentMaybeOperator = recognizeOperator; + boolean bSawDecimal ; + recognizeOperator = true; + for (;;) { + if (exprIndex >= exprLength) { + currentToken = TOK_EOF; + return; + } + char c = expr.charAt(exprIndex++); + switch (c) { + case ' ': + case '\t': + case '\r': + case '\n': + currentTokenStartIndex = exprIndex; + break; + case ',': + recognizeOperator = false; + currentToken = TOK_COMMA; + return; + case '+': + recognizeOperator = false; + currentToken = TOK_PLUS; + return; + case '-': + recognizeOperator = false; + currentToken = TOK_MINUS; + return; + case '(': + currentToken = TOK_LPAR; + recognizeOperator = false; + return; + case ')': + currentToken = TOK_RPAR; + return; + case '"': + case '\'': + exprIndex = expr.indexOf(c, exprIndex); + if (exprIndex < 0) { + exprIndex = currentTokenStartIndex + 1; + throw new PropertyException("missing quote"); + } + currentTokenValue = expr.substring(currentTokenStartIndex + 1, + exprIndex++); + currentToken = TOK_LITERAL; + return; + case '*': + if (currentMaybeOperator) { + recognizeOperator = false; + currentToken = TOK_MULTIPLY; + } + else + throw new PropertyException("illegal operator *"); + return; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + scanDigits(); + if (exprIndex < exprLength + && expr.charAt(exprIndex) == '.') { + exprIndex++; + bSawDecimal=true; + if (exprIndex < exprLength + && isDigit(expr.charAt(exprIndex))) { + exprIndex++; + scanDigits(); + } + } + else bSawDecimal=false; + if (exprIndex < exprLength && expr.charAt(exprIndex) == '%') { + exprIndex++; + currentToken = TOK_PERCENT ; + } + else { + // Check for possible unit name following number + currentUnitLength = exprIndex; + scanName(); + currentUnitLength = exprIndex-currentUnitLength; + currentToken = (currentUnitLength>0)? TOK_NUMERIC : + (bSawDecimal? TOK_FLOAT : TOK_INTEGER) ; + } + currentTokenValue = expr.substring(currentTokenStartIndex, + exprIndex); + return; + + case '.': + if (exprIndex < exprLength && isDigit(expr.charAt(exprIndex))) { + ++exprIndex; + scanDigits(); + if (exprIndex < exprLength && expr.charAt(exprIndex) == '%') { + exprIndex++; + currentToken = TOK_PERCENT ; + } + else { + // Check for possible unit name following number + currentUnitLength = exprIndex; + scanName(); + currentUnitLength = exprIndex-currentUnitLength; + currentToken = (currentUnitLength>0)? TOK_NUMERIC : TOK_FLOAT; + } + currentTokenValue = expr.substring(currentTokenStartIndex, + exprIndex); + return; + } + throw new PropertyException("illegal character '.'"); + + case '#': // Start of color value + if (exprIndex < exprLength && isHexDigit(expr.charAt(exprIndex))) { + ++exprIndex; + scanHexDigits(); + currentToken = TOK_COLORSPEC; + currentTokenValue = expr.substring(currentTokenStartIndex, + exprIndex); + // Probably should have some multiple of 3 for length! + return; + } + else throw new PropertyException("illegal character '#'"); + + default: + --exprIndex; + scanName(); + if (exprIndex == currentTokenStartIndex) + throw new PropertyException("illegal character"); + currentTokenValue = expr.substring(currentTokenStartIndex, + exprIndex); + if (currentMaybeOperator) { + if (currentTokenValue.equals("mod")) + currentToken = TOK_MOD; + else if (currentTokenValue.equals("div")) + currentToken = TOK_DIV; + else + throw new PropertyException("unrecognized operator name"); + recognizeOperator = false; + return; + } + if (followingParen()) { + currentToken = TOK_FUNCTION_LPAR; + recognizeOperator = false; + } + else + currentToken = TOK_NCNAME; + return; + } + } + } + + /** + * Attempt to recognize a valid NAME token in the input expression. + */ + private void scanName() { + if (exprIndex < exprLength + && isNameStartChar(expr.charAt(exprIndex))) + while (++exprIndex < exprLength + && isNameChar(expr.charAt(exprIndex))) + ; + } + + /** + * Attempt to recognize a valid sequence of decimal digits in the + * input expression. + */ + private void scanDigits() { + while (exprIndex < exprLength && isDigit(expr.charAt(exprIndex))) + exprIndex++; + } + + /** + * Attempt to recognize a valid sequence of hexadecimal digits in the + * input expression. + */ + private void scanHexDigits() { + while (exprIndex < exprLength && isHexDigit(expr.charAt(exprIndex))) + exprIndex++; + } + + /** + * Return a boolean value indicating whether the following non-whitespace + * character is an opening parenthesis. + */ + private boolean followingParen() { + for (int i = exprIndex; i < exprLength; i++) { + switch (expr.charAt(i)) { + case '(': + exprIndex = i + 1; + return true; + case ' ': + case '\r': + case '\n': + case '\t': + break; + default: + return false; + } + } + return false; + } + + + static private final String nameStartChars = + "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + static private final String nameChars = ".-0123456789"; + static private final String digits = "0123456789"; + static private final String hexchars = digits + "abcdefABCDEF"; + + /** + * Return a boolean value indicating whether the argument is a + * decimal digit (0-9). + * @param c The character to check + */ + private static final boolean isDigit(char c) { + return digits.indexOf(c) >= 0; + } + + /** + * Return a boolean value indicating whether the argument is a + * hexadecimal digit (0-9, A-F, a-f). + * @param c The character to check + */ + private static final boolean isHexDigit(char c) { + return hexchars.indexOf(c) >=0; + } + + /** + * Return a boolean value indicating whether the argument is whitespace + * as defined by XSL (space, newline, CR, tab). + * @param c The character to check + */ + private static final boolean isSpace(char c) { + switch(c) { + case ' ': + case '\r': + case '\n': + case '\t': + return true; + } + return false; + } + + /** + * Return a boolean value indicating whether the argument is a valid name + * start character, ie. can start a NAME as defined by XSL. + * @param c The character to check + */ + private static final boolean isNameStartChar(char c) { + return nameStartChars.indexOf(c) >= 0 || c >= 0x80; + } + + /** + * Return a boolean value indicating whether the argument is a valid name + * character, ie. can occur in a NAME as defined by XSL. + * @param c The character to check + */ + private static final boolean isNameChar(char c) { + return nameStartChars.indexOf(c) >= 0 || + nameChars.indexOf(c) >= 0 || c >= 0x80; + } + +} diff --git a/src/org/apache/fop/fo/expr/RGBColorFunction.java b/src/org/apache/fop/fo/expr/RGBColorFunction.java new file mode 100644 index 000000000..16f619494 --- /dev/null +++ b/src/org/apache/fop/fo/expr/RGBColorFunction.java @@ -0,0 +1,98 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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; } + } +} diff --git a/src/org/apache/fop/fo/expr/RoundFunction.java b/src/org/apache/fop/fo/expr/RoundFunction.java new file mode 100644 index 000000000..43cf2e3b1 --- /dev/null +++ b/src/org/apache/fop/fo/expr/RoundFunction.java @@ -0,0 +1,72 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ +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); + } +} |