You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ga...@apache.org on 2012/04/22 22:09:49 UTC

svn commit: r1328964 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/

Author: gadams
Date: Sun Apr 22 20:09:49 2012
New Revision: 1328964

URL: http://svn.apache.org/viewvc?rev=1328964&view=rev
Log:
Make property function class names more consistent.

Added:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/CMYKColorFunction.java
      - copied, changed from r1328963, xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/CMYKcolorFunction.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/FromNearestSpecifiedValueFunction.java
      - copied, changed from r1328963, xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/ProportionalColumnWidthFunction.java
      - copied, changed from r1328963, xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PPColWidthFunction.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RGBICCColorFunction.java
      - copied, changed from r1328963, xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/ICCColorFunction.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RGBNamedColorFunction.java
      - copied, changed from r1328963, xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/NamedColorFunction.java
Removed:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/CMYKcolorFunction.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/ICCColorFunction.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/NamedColorFunction.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PPColWidthFunction.java
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/BodyStartFunction.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/FunctionBase.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/BodyStartFunction.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/BodyStartFunction.java?rev=1328964&r1=1328963&r2=1328964&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/BodyStartFunction.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/BodyStartFunction.java Sun Apr 22 20:09:49 2012
@@ -33,7 +33,7 @@ public class BodyStartFunction extends F
 
     /** {@inheritDoc} */
     public int getRequiredArgsCount() {
-        return 1;
+        return 0;
     }
 
     /** {@inheritDoc} */

Copied: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/CMYKColorFunction.java (from r1328963, xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/CMYKcolorFunction.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/CMYKColorFunction.java?p2=xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/CMYKColorFunction.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/CMYKcolorFunction.java&r1=1328963&r2=1328964&rev=1328964&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/CMYKcolorFunction.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/CMYKColorFunction.java Sun Apr 22 20:09:49 2012
@@ -25,7 +25,7 @@ import org.apache.fop.fo.properties.Prop
 /**
  * Implements the cmyk() function.
  */
-class CMYKcolorFunction extends FunctionBase {
+class CMYKColorFunction extends FunctionBase {
 
     /** {@inheritDoc} */
     public int getRequiredArgsCount() {

Copied: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/FromNearestSpecifiedValueFunction.java (from r1328963, xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/FromNearestSpecifiedValueFunction.java?p2=xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/FromNearestSpecifiedValueFunction.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java&r1=1328963&r2=1328964&rev=1328964&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/FromNearestSpecifiedValueFunction.java Sun Apr 22 20:09:49 2012
@@ -26,7 +26,7 @@ import org.apache.fop.fo.properties.Prop
  * Class modelling the from-nearest-specified-value function. See Sec. 5.10.4
  * of the XSL-FO standard.
  */
-public class NearestSpecPropFunction extends FunctionBase {
+public class FromNearestSpecifiedValueFunction extends FunctionBase {
 
     /** {@inheritDoc} */
     public int getRequiredArgsCount() {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/FunctionBase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/FunctionBase.java?rev=1328964&r1=1328963&r2=1328964&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/FunctionBase.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/FunctionBase.java Sun Apr 22 20:09:49 2012
@@ -20,6 +20,8 @@
 package org.apache.fop.fo.expr;
 
 import org.apache.fop.datatypes.PercentBase;
+import org.apache.fop.fo.properties.Property;
+import org.apache.fop.fo.properties.StringProperty;
 
 /**
  * Abstract Base class for XSL-FO functions
@@ -32,9 +34,9 @@ public abstract class FunctionBase imple
     }
 
     /** {@inheritDoc} */
-    public Property getOptionalArgDefault(int index, PropertyInfo pi) new PropertyException {
+    public Property getOptionalArgDefault(int index, PropertyInfo pi) throws PropertyException {
         if ( index >= getOptionalArgsCount() ) {
-            PropertyException e = new PropertyException ( new IndexOutOfBoundException ( "illegal optional argument index" ) );
+            PropertyException e = new PropertyException ( new IndexOutOfBoundsException ( "illegal optional argument index" ) );
             e.setPropertyInfo ( pi );
             throw e;
         } else {
@@ -43,7 +45,7 @@ public abstract class FunctionBase imple
     }
 
     /** {@inheritDoc} */
-    public int hasVariableArgs() {
+    public boolean hasVariableArgs() {
         return false;
     }
 
@@ -57,6 +59,6 @@ public abstract class FunctionBase imple
      * @return string property whose value is name of property being evaluated
      */
     protected final Property getPropertyName ( PropertyInfo pi ) {
-        return StringProperty.getInstance ( pi.getPropertMaker().getName() );
+        return StringProperty.getInstance ( pi.getPropertyMaker().getName() );
     }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java?rev=1328964&r1=1328963&r2=1328964&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java Sun Apr 22 20:09:49 2012
@@ -60,16 +60,15 @@ public final class PropertyParser extend
         FUNCTION_TABLE.put("system-color", new SystemColorFunction());
         FUNCTION_TABLE.put("from-table-column", new FromTableColumnFunction());
         FUNCTION_TABLE.put("inherited-property-value", new InheritedPropFunction());
-        FUNCTION_TABLE.put("from-nearest-specified-value", new NearestSpecPropFunction());
-        FUNCTION_TABLE.put("from-page-master-region", new FromPageMasterRegionFunction());
+        FUNCTION_TABLE.put("from-nearest-specified-value", new FromNearestSpecifiedValueFunction());
         FUNCTION_TABLE.put("from-parent", new FromParentFunction());
-        FUNCTION_TABLE.put("proportional-column-width", new PPColWidthFunction());
+        FUNCTION_TABLE.put("proportional-column-width", new ProportionalColumnWidthFunction());
         FUNCTION_TABLE.put("label-end", new LabelEndFunction());
         FUNCTION_TABLE.put("body-start", new BodyStartFunction());
-        FUNCTION_TABLE.put("rgb-icc", new ICCColorFunction());
-        FUNCTION_TABLE.put("rgb-named-color", new NamedColorFunction()); //since XSL-FO 2.0
+        FUNCTION_TABLE.put("rgb-icc", new RGBICCColorFunction());
+        FUNCTION_TABLE.put("rgb-named-color", new RGBNamedColorFunction()); //since XSL-FO 2.0
         FUNCTION_TABLE.put("cie-lab-color", new CIELabColorFunction()); //since XSL-FO 2.0
-        FUNCTION_TABLE.put("cmyk", new CMYKcolorFunction()); //non-standard!!!
+        FUNCTION_TABLE.put("cmyk", new CMYKColorFunction()); //non-standard!!!
 
         /**
          * * NOT YET IMPLEMENTED!!!
@@ -339,12 +338,7 @@ public final class PropertyParser extend
             next();
             // Push new function (for function context: getPercentBase())
             propInfo.pushFunction(function);
-            if (function.nbArgs() < 0) {
-                // Negative nbArgs --> function with variable number of arguments
-                prop = function.eval(parseVarArgs(function), propInfo);
-            } else {
-                prop = function.eval(parseArgs(function), propInfo);
-            }
+            prop = function.eval(parseArgs(function), propInfo);
             propInfo.popFunction();
             return prop;
 
@@ -360,26 +354,27 @@ public final class PropertyParser extend
      * 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 function The function object for which the arguments are
-     * collected.
-     * @return An array of Property objects representing the arguments
-     * found.
+     * @param function The function object for which the arguments are collected.
+     * @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.
+     * to the number expected or if another argument parsing error occurs.
      */
     Property[] parseArgs(Function function) throws PropertyException {
-        int nbArgs = function.nbArgs();
-        Property[] args = new Property[nbArgs];
-        Property prop;
-        int i = 0;
+        int numReq = function.getRequiredArgsCount();   // # required args
+        int numOpt = function.getOptionalArgsCount();   // # optional args
+        boolean hasVar = function.hasVariableArgs();    // has variable args
+        List<Property> args = new java.util.ArrayList<Property>(numReq + numOpt);
         if (currentToken == TOK_RPAR) {
             // No args: func()
             next();
         } else {
             while (true) {
-                prop = parseAdditiveExpr();
-                if (i < nbArgs) {
-                    args[i++] = prop;
+                Property p = parseAdditiveExpr();
+                int i = args.size();
+                if ( ( i < numReq ) || ( ( i - numReq ) < numOpt ) || hasVar ) {
+                    args.add ( p );
+                } else {
+                    throw new PropertyException ( "Unexpected function argument at index " + i );
                 }
                 // ignore extra args
                 if (currentToken != TOK_COMMA) {
@@ -389,66 +384,19 @@ public final class PropertyParser extend
             }
             expectRpar();
         }
-        if (i == nbArgs - 1 && function.padArgsWithPropertyName()) {
-            args[i++] = StringProperty.getInstance(
-                            propInfo.getPropertyMaker().getName());
-        }
-        if (nbArgs != i) {
-            throw new PropertyException("Expected " + nbArgs
-                                        + ", but got " + i + " args for function");
-        }
-        return args;
-    }
-
-    /**
-     *
-     * 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.
-     *
-     * The method differs from parseArgs in that it accepts a variable
-     * number of arguments.
-     *
-     * @param function The function object for which the arguments are
-     * collected.
-     * @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.
-     *
-     * TODO Merge this with parseArgs?
-     */
-    Property[] parseVarArgs(Function function) throws PropertyException {
-        // For variable argument functions the minimum number of arguments is returned as a
-        // negative integer from the nbArgs method
-        int nbArgs = -function.nbArgs();
-        List args = new LinkedList();
-        Property prop;
-        if (currentToken == TOK_RPAR) {
-            // No args: func()
-            next();
+        int numArgs = args.size();
+        if ( numArgs < numReq ) {
+            throw new PropertyException("Expected " + numReq + " required arguments, but only " + numArgs + " specified");
         } else {
-            while (true) {
-                prop = parseAdditiveExpr();
-                args.add(prop);
-                // ignore extra args
-                if (currentToken != TOK_COMMA) {
-                    break;
+            for ( int i = 0; i < numOpt; i++ ) {
+                if ( args.size() < ( numReq + i + 1 ) ) {
+                    args.add ( function.getOptionalArgDefault ( i, propInfo ) );
                 }
-                next();
             }
-            expectRpar();
         }
-        if (nbArgs > args.size()) {
-            throw new PropertyException("Expected at least " + nbArgs
-                                        + ", but got " + args.size() + " args for function");
-        }
-        Property[] propArray = new Property[args.size()];
-        args.toArray(propArray);
-        return propArray;
+        return (Property[]) args.toArray ( new Property [ args.size() ] );
     }
 
-
     /**
      * Evaluate an addition operation. If either of the arguments is null,
      * this means that it wasn't convertible to a Numeric value.

Copied: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/ProportionalColumnWidthFunction.java (from r1328963, xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PPColWidthFunction.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/ProportionalColumnWidthFunction.java?p2=xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/ProportionalColumnWidthFunction.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PPColWidthFunction.java&r1=1328963&r2=1328964&rev=1328964&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PPColWidthFunction.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/ProportionalColumnWidthFunction.java Sun Apr 22 20:09:49 2012
@@ -30,7 +30,7 @@ import org.apache.fop.fo.properties.Tabl
  * Class modelling the proportional-column-width function. See Sec. 5.10.4 of
  * the XSL-FO standard.
  */
-public class PPColWidthFunction extends FunctionBase {
+public class ProportionalColumnWidthFunction extends FunctionBase {
 
     /** {@inheritDoc} */
     public int getRequiredArgsCount() {
@@ -40,7 +40,7 @@ public class PPColWidthFunction extends 
     @Override
     /** {@inheritDoc} */
     public PercentBase getPercentBase() {
-        return new PPColWidthPercentBase();
+        return new ProportionalColumnWidthPercentBase();
     }
 
     /** {@inheritDoc} */
@@ -65,7 +65,7 @@ public class PPColWidthFunction extends 
         return new TableColLength(d.doubleValue(), pInfo.getFO());
     }
 
-    private static class PPColWidthPercentBase implements PercentBase {
+    private static class ProportionalColumnWidthPercentBase implements PercentBase {
 
         /** {@inheritDoc} */
         public int getBaseLength(PercentBaseContext context) throws PropertyException {

Copied: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RGBICCColorFunction.java (from r1328963, xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/ICCColorFunction.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RGBICCColorFunction.java?p2=xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RGBICCColorFunction.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/ICCColorFunction.java&r1=1328963&r2=1328964&rev=1328964&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/ICCColorFunction.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RGBICCColorFunction.java Sun Apr 22 20:09:49 2012
@@ -29,7 +29,7 @@ import org.apache.fop.util.ColorUtil;
 /**
  * Implements the rgb-icc() function.
  */
-class ICCColorFunction extends FunctionBase {
+class RGBICCColorFunction extends FunctionBase {
 
     /** {@inheritDoc} */
     public int getRequiredArgsCount() {
@@ -38,7 +38,7 @@ class ICCColorFunction extends FunctionB
 
     @Override
     /** {@inheritDoc} */
-    public int hasVariableArgs() {
+    public boolean hasVariableArgs() {
         return true;
     }
 

Copied: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RGBNamedColorFunction.java (from r1328963, xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/NamedColorFunction.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RGBNamedColorFunction.java?p2=xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RGBNamedColorFunction.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/NamedColorFunction.java&r1=1328963&r2=1328964&rev=1328964&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/NamedColorFunction.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RGBNamedColorFunction.java Sun Apr 22 20:09:49 2012
@@ -29,7 +29,7 @@ import org.apache.fop.fo.properties.Prop
  * Implements the rgb-named-color() function.
  * @since XSL-FO 2.0
  */
-class NamedColorFunction extends FunctionBase {
+class RGBNamedColorFunction extends FunctionBase {
 
     /** {@inheritDoc} */
     public int getRequiredArgsCount() {
@@ -39,7 +39,7 @@ class NamedColorFunction extends Functio
     /** {@inheritDoc} */
     @Override
     public PercentBase getPercentBase() {
-        return new NamedPercentBase();
+        return new RGBNamedPercentBase();
     }
 
     /** {@inheritDoc} */
@@ -92,7 +92,7 @@ class NamedColorFunction extends Functio
         return ColorProperty.getInstance(pInfo.getUserAgent(), sb.toString());
     }
 
-    private static final class NamedPercentBase implements PercentBase {
+    private static final class RGBNamedPercentBase implements PercentBase {
 
         /** {@inheritDoc} */
         public int getBaseLength(PercentBaseContext context) throws PropertyException {



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org