From: Peter Bernard West Date: Tue, 7 May 2002 16:06:36 +0000 (+0000) Subject: New files for experimental code. X-Git-Tag: FOP_Alt-Design_Migration~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=894e8299fd64babbc838e540edcf510cd8560e73;p=xmlgraphics-fop.git New files for experimental code. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@194795 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/datatypes/Angle.java b/src/org/apache/fop/datatypes/Angle.java new file mode 100644 index 000000000..ce3323e5a --- /dev/null +++ b/src/org/apache/fop/datatypes/Angle.java @@ -0,0 +1,108 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; + +/* + * Angle.java + * $Id$ + * Created: Wed Nov 21 15:39:30 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ +/** + * Constructor class for Angle datatype. Constructs a Numeric. + * @author Peter B. West + * @version $Revision$ $Name$ + */ + +public class Angle { + /* + * Constants for UnitNames + */ + public static final int NOUNIT = 0; + public static final int DEG = 1; + public static final int GRAD = 2; + public static final int RAD = 3; + + /** + * Array of constant conversion factors from unit to milliseconds, + * indexed by integer unit constant. Keep this array in sync with + * the integer constants or bear the consequences. + */ + public static final double[] degPerUnit = { + 0.0 + ,1.0 + ,57.29578 // Degrees per grade + ,63.661977 // Degrees per radian + }; + + /** + * Private constructor - don't instantiate a Time object. + */ + private Angle() {} + + /** + * Construct a Numeric with a given unit and quantity. + * The unit power is + * assumed as 1. The base unit is degrees. + * @param property int index of the property. + * @param value the number of units. + * @param unit an integer value representing the unit of definition. + */ + public static Numeric makeAngle(int property, double value, int unit) + throws PropertyException + { + return new Numeric(property, value * degPerUnit[unit], + Numeric.DEGREES, 1, unit); + } + + /** + * Construct a Numeric with a given unit and quantity. + * The unit power is + * assumed as 1. The base unit is degrees. + * @param propertyName the name of the property with which this value + * is associated. + * @param value the number of units. + * @param unit an integer value representing the unit of definition. + */ + public static Numeric makeAngle + (String propertyName, double value, int unit) + throws PropertyException + { + return new Numeric(propertyName, value * degPerUnit[unit], + Numeric.DEGREES, 1, unit); + } + + /** + * @param unit an int encoding an Angle. + * @return the String name of the unit in which this + * Numeric was defined. + */ + public static String getUnitName(int unit) { + switch (unit) { + case DEG: + return "deg"; + case GRAD: + return "grad"; + case RAD: + return "rad"; + default: + return ""; + } + } + + /** + * Normalize the angle value in the range 0 <= angle <= 360 + * @param numeric a Numeric representing the value to be + * normalized. + * @return a double containing the normalized value. + */ + public static double normalize(Numeric numeric) { + if (numeric.power == 1) + return numeric.value % 360; // Negative angles still negative + return numeric.value; + } + +} diff --git a/src/org/apache/fop/datatypes/Auto.java b/src/org/apache/fop/datatypes/Auto.java new file mode 100644 index 000000000..e05119533 --- /dev/null +++ b/src/org/apache/fop/datatypes/Auto.java @@ -0,0 +1,53 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.Properties; + +/* + * Auto.java + * $Id$ + * + * Created: Tue Nov 20 22:18:11 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Class for "auto" objects. + */ + +public class Auto extends AbstractPropertyValue { + + /** + * @param property the int index of the property on which + * this value is being defined. + * @exception PropertyException + */ + public Auto(int property) + throws PropertyException + { + super(property); + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. + * @exception PropertyException + */ + public Auto(String propertyName) + throws PropertyException + { + super(propertyName); + } + + /** + * validate the Auto against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.AUTO); + } + +} diff --git a/src/org/apache/fop/datatypes/Bool.java b/src/org/apache/fop/datatypes/Bool.java new file mode 100644 index 000000000..9cff9ecfe --- /dev/null +++ b/src/org/apache/fop/datatypes/Bool.java @@ -0,0 +1,108 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.Properties; + +/* + * Bool.java + * $Id$ + * + * Created: Fri Nov 23 15:21:37 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ +/** + * Boolean property value. May take values of "true" or "false". + * @author Peter B. West + * @version $Revision$ $Name$ + */ + +public class Bool extends AbstractPropertyValue { + + /** + * The boolean value of the property + */ + private boolean bool = false; + + /** + * @param property the int index of the property on which + * this value is being defined. + * @param bool the boolean value. + * @exception PropertyException + */ + public Bool (int property, boolean bool) + throws PropertyException + { + super(property); + this.bool = bool; + } + + /** + * @param property the int index of the property on which + * this value is being defined. + * @param boolStr a String containing the boolean value. It + * must be either "true" or "false". + * @exception PropertyException + */ + public Bool (int property, String boolStr) + throws PropertyException + { + super(property); + if (boolStr.equals("true")) bool = true; + else if (boolStr.equals("false")) bool = false; + else throw new PropertyException + ("Attempt to set Bool to " + boolStr); + } + + /** + * @param propertyName the StringString containing the boolean value. It + * must be either "true" or "false". + * @exception PropertyException + */ + public Bool (String propertyName, String boolStr) + throws PropertyException + { + super(propertyName); + if (boolStr.equals("true")) bool = true; + else if (boolStr.equals("false")) bool = false; + else throw new PropertyException + ("Attempt to set Bool to " + boolStr); + } + + /** + * @param propertyName the Stringboolean value. + * @exception PropertyException + */ + public Bool (String propertyName, boolean bool) + throws PropertyException + { + super(propertyName); + this.bool = bool; + } + + /** + * @return the String. + */ + public boolean getBoolean() { + return bool; + } + + /** + * validate the Bool against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.BOOL); + } + + public String toString() { + return bool ? "true" : "false" + "\n" + super.toString(); + } + +} diff --git a/src/org/apache/fop/datatypes/Compound.java b/src/org/apache/fop/datatypes/Compound.java new file mode 100644 index 000000000..d5fa460e9 --- /dev/null +++ b/src/org/apache/fop/datatypes/Compound.java @@ -0,0 +1,14 @@ +package org.apache.fop.datatypes; + +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ +/** + * Marker interface for compound property lists + */ + +public interface Compound { +} diff --git a/src/org/apache/fop/datatypes/Country.java b/src/org/apache/fop/datatypes/Country.java new file mode 100644 index 000000000..bf1cc2ab4 --- /dev/null +++ b/src/org/apache/fop/datatypes/Country.java @@ -0,0 +1,52 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.PropertyConsts; +import org.apache.fop.fo.Properties; +import org.apache.fop.configuration.Configuration; + +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * A class for country specifiers. + */ + +public class Country extends NCName { + + public Country(int property, String countryCode) throws PropertyException + { + super(property, countryCode); + // Validate the code + if (Configuration.getHashMapEntry("countriesMap", countryCode) + == null) throw new PropertyException + ("Invalid country code: " + countryCode); + } + + public Country(String propertyName, String countryCode) + throws PropertyException + { + this(PropertyConsts.getPropertyIndex(propertyName), countryCode); + } + + /** + * @return the String country code. + */ + public String getCountry() { + return string; + } + + /** + * Validate the Country against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.COUNTRY_T); + } + +} diff --git a/src/org/apache/fop/datatypes/Ems.java b/src/org/apache/fop/datatypes/Ems.java new file mode 100644 index 000000000..90dfce315 --- /dev/null +++ b/src/org/apache/fop/datatypes/Ems.java @@ -0,0 +1,57 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.PropertyConsts; + +/* + * Ems.java + * $Id$ + * Created: Wed Nov 21 15:39:30 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ +/** + * Constructor class for relative lengths measured in ems. Constructs + * a Numeric. + * @author Peter B. West + * @version $Revision$ $Name$ + */ + +public class Ems { + + /** + * Private constructor - don't instantiate a Ems object. + */ + private Ems() {} + + /** + * Construct a Numeric with a given unit and quantity. + * The unit power is assumed as 1. The base unit is millipoints. + * @param property the index of the property with which this value + * is associated. + * @param value the number of units. + * @return a Numeric representing this Ems. + */ + public static Numeric makeEms(int property, double value) + throws PropertyException + { + return new Numeric(property, value, Numeric.EMS, 0, 0); + } + + /** + * Construct a Numeric with a given unit and quantity. + * The unit power is assumed as 1. The base unit is millipoints. + * @param propertyName the name of the property with which this value + * is associated. + * @param value the number of units. + * @return a Numeric representing this Ems. + */ + public static Numeric makeEms (String propertyName, double value) + throws PropertyException + { + return makeEms(PropertyConsts.getPropertyIndex(propertyName), value); + } + +} diff --git a/src/org/apache/fop/datatypes/EnumType.java b/src/org/apache/fop/datatypes/EnumType.java new file mode 100644 index 000000000..062ab2fc9 --- /dev/null +++ b/src/org/apache/fop/datatypes/EnumType.java @@ -0,0 +1,119 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.PropertyConsts; +import org.apache.fop.fo.Properties; +import org.apache.fop.messaging.MessageHandler; + +/* + * EnumType.java + * $Id$ + * + * Created: Tue Nov 20 22:18:11 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ +/** + * Base class for representing enumerated values. The value is maintained as + * an int constant value. + * @author Peter B. West + * @version $Revision$ $Name$ + */ + +public class EnumType extends AbstractPropertyValue { + + /** + * An integer enumeration value. + */ + protected int enumValue; + + /** + * @param property the int index of the property on which + * this value is being defined. + * @param enumText the String containing the enumeration text. + * An NCName. + * @exception PropertyException + */ + public EnumType(int property, String enumText) + throws PropertyException + { + super(property); + // Get the enum integer or mapped enum integer + enumValue = PropertyConsts.getEnumIndex(property, enumText); + } + + /** + * @param property the int index of the property on which + * this value is being defined. + * @param enum the int enumeration constant. + * @exception PropertyException + */ + public EnumType(int property, int enum) + throws PropertyException + { + super(property); + enumValue = enum; + // Validate the text; getEnumText will throw a PropertyException + // if the enum integer is invalid + String enumText = PropertyConsts.getEnumText(property, enum); + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. + * @param enumText the String containing the enumeration text. + * An NCName. + * @exception PropertyException + */ + public EnumType(String propertyName, String enumText) + throws PropertyException + { + this(PropertyConsts.getPropertyIndex(propertyName), enumText); + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. + * @param enum the int enumeration constant. + * @exception PropertyException + */ + public EnumType(String propertyName, int enum) + throws PropertyException + { + this(PropertyConsts.getPropertyIndex(propertyName), enum); + } + + /** + * @return the int ENUM value. + */ + public int getEnumValue() { + return enumValue; + } + + /** + * @return the String enumeration token. + */ + public String getEnumToken() throws PropertyException { + return PropertyConsts.getEnumText(property, enumValue); + } + + /** + * validate the EnumType against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.ENUM); + } + + public String toString() { + String enumText; + try { + enumText = PropertyConsts.getEnumText(property, enumValue); + } catch (PropertyException e) { + throw new RuntimeException(e.getMessage()); + } + return enumText + " " + enumValue + "\n" + super.toString(); + } + +} diff --git a/src/org/apache/fop/datatypes/FontFamilySet.java b/src/org/apache/fop/datatypes/FontFamilySet.java new file mode 100644 index 000000000..04189d4d2 --- /dev/null +++ b/src/org/apache/fop/datatypes/FontFamilySet.java @@ -0,0 +1,96 @@ + +package org.apache.fop.datatypes; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.PropertyConsts; +import org.apache.fop.fo.Properties; +import org.apache.fop.fo.expr.AbstractPropertyValue; + +/* + * FontFamilySet.java + * $Id$ + * + * Created: Mon Nov 26 22:46:05 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * A base class for representing a set of font family names. + */ + +public class FontFamilySet extends AbstractPropertyValue { + + /** + * An array of Strings containing a prioritized list of + * font family or generic font family names. + */ + private String[] fontFamilyNames; + + /** + * @param property int index of the property. + * @param fontNames an array of Strings containing a + * prioritized list of font names, as literals or NCNames, + * being either the full name of a font, or an enumeration token + * representing a font family. + * @exception PropertyException. + */ + public FontFamilySet(int property, String[] fontFamilyNames) + throws PropertyException + { + super(property); + this.fontFamilyNames = fontFamilyNames; + } + + /** + * @param propertyName String name of the property. + * @param fontNames an array of Strings containing a + * prioritized list of font names, as literals or NCNames, + * being either the full name of a font, or an enumeration token + * representing a font family. + * @exception PropertyException. + */ + public FontFamilySet(String propertyName, String[] fontFamilyNames) + throws PropertyException + { + this(PropertyConsts.getPropertyIndex(propertyName), fontFamilyNames); + } + + /** + * Validate the FontFamilySet against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.FONTSET); + } + + /** + * An Iterator implementing member class of FontFamilySet. + */ + class Traverser implements Iterator { + + /** + * The index for the iteration across the fontFamilyNames array. + */ + private int index = 0; + + public Traverser() {} + + public boolean hasNext() { + return index < fontFamilyNames.length; + } + + public Object next() { + if (hasNext()) return (Object)fontFamilyNames[index++]; + throw new NoSuchElementException(); + } + + public void remove() { + throw new UnsupportedOperationException(); + } + } +} diff --git a/src/org/apache/fop/datatypes/Frequency.java b/src/org/apache/fop/datatypes/Frequency.java new file mode 100644 index 000000000..fc541caf0 --- /dev/null +++ b/src/org/apache/fop/datatypes/Frequency.java @@ -0,0 +1,94 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; + +/* + * Frequency.java + * + * Created: Wed Nov 21 15:39:30 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ +/** + * Constructor class for Frequency datatype. Constructs a Numeric. + * @author Peter B. West + * @version $Revision$ $Name$ + */ + +public class Frequency { + + /* + * Constants for UnitNames + */ + public static final int NOUNIT = 0; + public static final int HZ = 1; + public static final int KHZ = 2; + + /** + * Array of constant conversion factors from unit to Hertz, + * indexed by integer unit constant. Keep this array in sync with + * the integer constants or bear the consequences. + */ + public static final double[] hzPerUnit = { + 0.0 + ,1.0 + ,1000.0 + }; + + /** + * Private constructor - don't instantiate a Frequency object. + */ + private Frequency() {} + + /** + * Construct a Numeric with a given unit and quantity. + * The unit power is assumed as 1. The base unit is Hertz. + * @param property the index of the property with which this value + * is associated. + * @param value the number of units. + * @param unit an integer constant representing the unit + * @return a Numeric representing this Frequency. + */ + public static Numeric makeFrequency(int property, double value, int unit) + throws PropertyException + { + return new Numeric(property, value * hzPerUnit[unit], + Numeric.HERTZ, 1, unit); + } + + /** + * Construct a Numeric with a given unit and quantity. + * The unit power is assumed as 1. The base unit is Hertz. + * @param propertyName the name of the property with which this value + * is associated. + * @param value the number of units. + * @param unit an integer constant representing the unit + * @return a Numeric representing this Frequency. + */ + public static Numeric makeFrequency + (String propertyName, double value, int unit) + throws PropertyException + { + return new Numeric(propertyName, value * hzPerUnit[unit], + Numeric.HERTZ, 1, unit); + } + + /** + * @param unit an int encoding a Frequency unit. + * @return the String name of the unit in which this + * Numeric was defined. + */ + public static String getUnitName(int unit) { + switch (unit) { + case HZ: + return "Hz"; + case KHZ: + return "kHz"; + default: + return ""; + } + } + +} diff --git a/src/org/apache/fop/datatypes/FromNearestSpecified.java b/src/org/apache/fop/datatypes/FromNearestSpecified.java new file mode 100644 index 000000000..c4688d1db --- /dev/null +++ b/src/org/apache/fop/datatypes/FromNearestSpecified.java @@ -0,0 +1,84 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.Properties; + +/* + * FromNearestSpecified.java + *
+ * $Id$ + *
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ +/** + *

+ * A pseudo-class to represent a call to the core property value function + * from-nearest-specified-value(), only in the cases where the property + * assigned to is identical to the NCName argument, and this is a + * shorthand. + *

+ * Further, the function call must be the only component of the expression + * in which it occurs. (See Rec. Section 5.10.4 Property Value Functions.) + * In these circumstances, the function call resolves to a + * from-nearest-specified-value() function call on each of the properties to + * which the shorthand resolves. + *

+ * The use of the pseudo-property should ensure that the function call is not + * involved in any arithmetic components of a more complex expression. I.e, + * the function evaluator in the parser must check to see whether the + * property for which the from-nearest-specified-value() function is being + * evaluated is a shorthand. If not, the function is normally evaluated. + * If so, the parser must further check that the property assigned to (i.e. + * the property against which this function is being evaluated) is the same + * as the NCName argument. If not, it is an error. If so, the + * property evaluates to an instance of this class. The value must itself + * be later resolved before the property value can be utilised in the fo + * node, but, in the meantime, any attempt to involve the function call in + * any more complex expression will throw an exception. + *

+ * This mechanism ensures, without greatly complicating the parser, + * that the constraint on the from-nearest-specified-value() function, with + * respect to shorthands, is met. + *

+ * See also FromParent pseudo-class. + * + * @author Peter B. West + * @version $Revision$ $Name$ + */ + +public class FromNearestSpecified extends AbstractPropertyValue { + + /** + * @param property the int index of the property on which + * this value is being defined. In this case, a shorthand property. + * @exception PropertyException + */ + public FromNearestSpecified(int property) + throws PropertyException + { + super(property); + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. In this case, a shorthand property. + * @exception PropertyException + */ + public FromNearestSpecified(String propertyName) + throws PropertyException + { + super(propertyName); + } + + /** + * validate the FromNearestSpecified against the associated + * property. + */ + public void validate() throws PropertyException { + super.validate(Properties.SHORTHAND); + } + +} diff --git a/src/org/apache/fop/datatypes/FromParent.java b/src/org/apache/fop/datatypes/FromParent.java new file mode 100644 index 000000000..6c0530797 --- /dev/null +++ b/src/org/apache/fop/datatypes/FromParent.java @@ -0,0 +1,82 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.Properties; + +/* + * FromParent.java + *
+ * $Id$ + *
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ +/** + *

+ * A pseudo-class to represent a call to the core property value function + * from-parent(), only in the cases where the property assigned to + * is identical to the NCName argument, and this is a shorthand. + *

+ * Further, the function call must be the only component of the expression + * in which it occurs. (See Rec. Section 5.10.4 Property Value Functions.) + * In these circumstances, the function call resolves to a + * from-parent() function call on each of the properties to + * which the shorthand resolves. + *

+ * The use of the pseudo-property should ensure that the function call is not + * involved in any arithmetic components of a more complex expression. I.e, + * the function evaluator in the parser must check to see whether the + * property for which the from-parent() function is being + * evaluated is a shorthand. If not, the function is normally evaluated. + * If so, the parser must further check that the property assigned to (i.e. + * the property against which this function is being evaluated) is the same + * as the NCName argument. If not, it is an error. If so, the + * property evaluates to an instance of this class. The value must itself + * be later resolved before the property value can be utilised in the fo + * node, but, in the meantime, any attempt to involve the function call in + * any more complex expression will throw an exception. + *

+ * This mechanism ensures, without greatly complicating the parser, + * that the constraint on the from-parent() function, with + * respect to shorthands, is met. + *

+ * See also FromNearestSpecified pseudo-class. + *

+ * @author Peter B. West + * @version $Revision$ $Name$ + */ + +public class FromParent extends AbstractPropertyValue { + + /** + * @param property the int index of the property on which + * this value is being defined. In this case, a shorthand property. + * @exception PropertyException + */ + public FromParent(int property) + throws PropertyException + { + super(property); + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. In this case, a shorthand property. + * @exception PropertyException + */ + public FromParent(String propertyName) + throws PropertyException + { + super(propertyName); + } + + /** + * validate the FromParent against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.SHORTHAND); + } + +} diff --git a/src/org/apache/fop/datatypes/Inherit.java b/src/org/apache/fop/datatypes/Inherit.java new file mode 100644 index 000000000..7dd38b609 --- /dev/null +++ b/src/org/apache/fop/datatypes/Inherit.java @@ -0,0 +1,96 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.Properties; +import org.apache.fop.fo.PropertyConsts; + +/* + * Inherit.java + * $Id$ + * + * Created: Tue Nov 20 22:18:11 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * A class representing the inherit keyword. + */ + +public class Inherit extends AbstractPropertyValue { + + /** + * The property from which the inherited value is to be derived. This + * may be different from the target property. + */ + private int sourceProperty; + + /** + * @param property the int index of the property on which + * this value is being defined. + * @param sourceProperty the int index of the property from + * which the inherited value is derived. + * @exception PropertyException + */ + public Inherit(int property, int sourceProperty) + throws PropertyException + { + super(property); + this.sourceProperty = sourceProperty; + } + + /** + * @param property the int index of the property on which + * this value is being defined. + * @exception PropertyException + */ + public Inherit(int property) + throws PropertyException + { + this(property, property); + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. + * @param sourcePropertyName the String name of the property + * from which the inherited value is derived. + * @exception PropertyException + */ + public Inherit(String propertyName, String sourcePropertyName) + throws PropertyException + { + super(propertyName); + property = PropertyConsts.getPropertyIndex(propertyName); + sourceProperty = PropertyConsts.getPropertyIndex(sourcePropertyName); + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. + * @exception PropertyException + */ + public Inherit(String propertyName) + throws PropertyException + { + this(propertyName, propertyName); + } + + /** + * @return int containing the source property index. + */ + public int getSourceProperty() { + return sourceProperty; + } + + /** + * validate the Inherit against the associated property. + */ + public void validate() throws PropertyException { + super.validate(sourceProperty, Properties.INHERIT); + } + +} diff --git a/src/org/apache/fop/datatypes/InheritCompound.java b/src/org/apache/fop/datatypes/InheritCompound.java new file mode 100644 index 000000000..99c2319cb --- /dev/null +++ b/src/org/apache/fop/datatypes/InheritCompound.java @@ -0,0 +1,86 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.Properties; +import org.apache.fop.fo.PropertyConsts; +import org.apache.fop.datatypes.Inherit; + +/* + * Inherit.java + * $Id$ + * + * Created: Tue Nov 20 22:18:11 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * A class used to indicate that a value in a compound sub-property + * should be inherited as a result of the 'inherit' keyword being specified + * on the compound shorthand. + */ + +public class InheritCompound extends Inherit { + + /** + * @param property the int index of the property on which + * this value is being defined. + * @param sourceProperty the int index of the property from + * which the inherited value is derived. + * @exception PropertyException + */ + public InheritCompound(int property, int sourceProperty) + throws PropertyException + { + super(property); + this.sourceProperty = sourceProperty; + } + + /** + * @param property the int index of the property on which + * this value is being defined. + * @exception PropertyException + */ + public InheritCompound(int property) + throws PropertyException + { + this(property, property); + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. + * @param sourcePropertyName the String name of the property + * from which the inherited value is derived. + * @exception PropertyException + */ + public InheritCompound(String propertyName, String sourcePropertyName) + throws PropertyException + { + super(propertyName); + property = PropertyConsts.getPropertyIndex(propertyName); + sourceProperty = PropertyConsts.getPropertyIndex(sourcePropertyName); + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. + * @exception PropertyException + */ + public InheritCompound(String propertyName) + throws PropertyException + { + this(propertyName, propertyName); + } + + /** + * validate the Inherit against the associated property. + */ + public void validate() throws PropertyException { + super.validate(sourceProperty, Properties.INHERIT_COMPOUND); + } + +} diff --git a/src/org/apache/fop/datatypes/IntegerType.java b/src/org/apache/fop/datatypes/IntegerType.java new file mode 100644 index 000000000..8e928989d --- /dev/null +++ b/src/org/apache/fop/datatypes/IntegerType.java @@ -0,0 +1,50 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; + +/* + * IntegerType.java + * + * Created: Wed Nov 21 15:39:30 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Constructor for Integer datatype. Constructs a Numeric. + */ + +public class IntegerType { + + /** + * Construct a Numeric with a given quantity. + * The unit power is assumed as 0. The base unit is NUMERIC. + * @param property the index of the property with which this value + * is associated. + * @param value the integer value. + * @return a Numeric representing this IntegerType. + */ + public static Numeric makeInteger(int property, long value) + throws PropertyException + { + return new Numeric(property, (double)value, Numeric.NUMBER, 0, 0); + } + + /** + * Construct a numeric with a given unit and quantity. + * The unit power is assumed as 0. The base unit is NUMERIC. + * @param propertyName the name of the property with which this value + * is associated. + * @param value the integer value. + * @return a Numeric representing this IntegerType. + */ + public static Numeric makeInteger(String propertyName, long value) + throws PropertyException + { + return new Numeric(propertyName, (double)value, Numeric.NUMBER, 0, 0); + } + +} diff --git a/src/org/apache/fop/datatypes/Ints.java b/src/org/apache/fop/datatypes/Ints.java new file mode 100644 index 000000000..4b1c744b6 --- /dev/null +++ b/src/org/apache/fop/datatypes/Ints.java @@ -0,0 +1,63 @@ +/* + * Ints.java + * $Id$ + * + * Created: Sun Nov 4 13:24:25 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.PropNames; +import org.apache.fop.fo.FObjectNames; +import org.apache.fop.datastructs.ROIntegerArray; + +/** + * Data class of pre-initialised Integer objects. + */ + +public class Ints { + /** + * An ROIntegerArray of Integer object constants corresponding + * to the set of property index values. + * @see org.apache.fop.fo.PropNames + */ + public static final ROIntegerArray consts; + /** + * An ROIntegerArray of Integer object constants corresponding + * to the set of flow object index values. + * @see org.apache.fop.fo.FObjectNames + */ + public static final ROIntegerArray foconsts; + private static final Integer[] constsAr; + private static final Integer[] foconstsAr; + static { + int range = PropNames.LAST_PROPERTY_INDEX >= FObjectNames.LAST_FO ? + PropNames.LAST_PROPERTY_INDEX : FObjectNames.LAST_FO; + constsAr = new Integer[PropNames.LAST_PROPERTY_INDEX + 1]; + for (int i = 0; i <= PropNames.LAST_PROPERTY_INDEX; i++) { + constsAr[i] = new Integer(i); + } + consts = new ROIntegerArray(constsAr); + foconstsAr = new Integer[FObjectNames.LAST_FO + 1]; + if (PropNames.LAST_PROPERTY_INDEX >= FObjectNames.LAST_FO) { + System.arraycopy(constsAr, 0, foconstsAr, 0, + FObjectNames.LAST_FO + 1); + } + else { + System.arraycopy(constsAr, 0, foconstsAr, 0, + PropNames.LAST_PROPERTY_INDEX + 1); + for (int i = PropNames.LAST_PROPERTY_INDEX + 1; + i <= FObjectNames.LAST_FO; i++) { + foconstsAr[i] = new Integer(i); + } + } + foconsts = new ROIntegerArray(foconstsAr); + } + + private Ints (){} +} diff --git a/src/org/apache/fop/datatypes/Language.java b/src/org/apache/fop/datatypes/Language.java new file mode 100644 index 000000000..c4d46f65f --- /dev/null +++ b/src/org/apache/fop/datatypes/Language.java @@ -0,0 +1,55 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.PropertyConsts; +import org.apache.fop.fo.Properties; +import org.apache.fop.configuration.Configuration; + +/* + * Language.java + * $Id$ + * + * Created: Mon Nov 26 22:46:05 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * A class for language specifiers. + */ + +public class Language extends NCName { + + public Language(int property, String languageCode) throws PropertyException + { + super(property, languageCode); + // Validate the code + if (Configuration.getHashMapEntry("languagesMap", languageCode) + == null) throw new PropertyException + ("Invalid language code: " + languageCode); + } + + public Language(String propertyName, String languageCode) + throws PropertyException + { + this(PropertyConsts.getPropertyIndex(propertyName), languageCode); + } + + /** + * Validate the Language against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.LANGUAGE_T); + } + + /** + * @return the String language code. + */ + public String getLanguage() { + return string; + } + +} diff --git a/src/org/apache/fop/datatypes/Literal.java b/src/org/apache/fop/datatypes/Literal.java new file mode 100644 index 000000000..de4fa44d6 --- /dev/null +++ b/src/org/apache/fop/datatypes/Literal.java @@ -0,0 +1,66 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.Properties; +import org.apache.fop.fo.PropertyConsts; + +/* + * Literal.java + * $Id$ + * Created: Wed Nov 21 15:39:30 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Class to represent Literal values. Subclass of StringType. + */ + +public class Literal extends StringType { + + /** + * Construct a Literal with a given String. + * @param property the index of the property with which this value + * is associated. + * @param string the String value. + */ + public Literal(int property, String string) + throws PropertyException + { + super(property, string); + } + + /** + * Construct a Literal with a given String. + * @param propertyName the name of the property with which this value + * is associated. + * @param string the String value. + */ + public Literal(String propertyName, String string) + throws PropertyException + { + this(PropertyConsts.getPropertyIndex(propertyName), string); + } + + /** + * Validate this Literal. Check that it is allowed on the + * associated property. A Literal may also encode a single + * character; i.e. a <character> type. If the + * validation against LITERAL fails, try CHARACTER_T. + */ + public void validate() throws PropertyException { + try { + super.validate(Properties.LITERAL); + } catch (PropertyException e) { + if (string.length() == 1) { + super.validate(Properties.CHARACTER_T); + } else { + throw new PropertyException(e.getMessage()); + } + } + } + +} diff --git a/src/org/apache/fop/datatypes/MappedEnumType.java b/src/org/apache/fop/datatypes/MappedEnumType.java new file mode 100644 index 000000000..b6460fdee --- /dev/null +++ b/src/org/apache/fop/datatypes/MappedEnumType.java @@ -0,0 +1,83 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.datatypes.EnumType; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.PropertyConsts; +import org.apache.fop.fo.Properties; + +/* + * MappedEnumType.java + * $Id$ + * + * Created: Tue Nov 20 22:18:11 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Class to represent an enumerated type whose values map onto another + * String. + */ + +public class MappedEnumType extends EnumType { + + /** + * The String value to which the associated ENUM token maps. + * It expresses some underlying type other than an ENUM. + */ + private String mappedEnum; + + /** + * @param property the int index of the property on which + * this value is being defined. + * @param enumText the String containing the enumeration text. + * An NCName. + * @exception PropertyException + */ + public MappedEnumType(int property, String enumText) + throws PropertyException + { + // Set property index in AbstractPropertyValue + // and enumValue enum constant in EnumType + super(property, enumText); + mappedEnum = PropertyConsts.getMappedEnumValue(property, enumValue); + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. + * @param enumText the String containing the enumeration text. + * An NCName. + * @exception PropertyException + */ + public MappedEnumType(String propertyName, String enumText) + throws PropertyException + { + // Set property index in AbstractPropertyValue + // and enumValue enum constant in EnumType + super(propertyName, enumText); + mappedEnum = PropertyConsts.getMappedEnumValue(property, enumValue); + } + + /** + * @return a String containing the text of the value to which + * this ENUM token is mapped. + */ + public String getMappedEnumValue() { + return mappedEnum; + } + + /** + * validate the MappedEnumType against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.MAPPED_ENUM); + } + + public String toString() { + return mappedEnum + " " + super.toString(); + } + +} diff --git a/src/org/apache/fop/datatypes/MimeType.java b/src/org/apache/fop/datatypes/MimeType.java new file mode 100644 index 000000000..56ba5954e --- /dev/null +++ b/src/org/apache/fop/datatypes/MimeType.java @@ -0,0 +1,72 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.Properties; + +/* + * MimeType.java + * $Id$ + * + * Created: Tue Nov 20 22:18:11 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Class for mime-type subset of content-type. + */ + +public class MimeType extends AbstractPropertyValue { + + /** + * A mimetype; one of the possible types of value for + * content-type. + */ + private String mimetype; + + /** + * @param property the int index of the property on which + * this value is being defined. + * @param mimetype the String containing the mimetype + * extracted from url(...). + * @exception PropertyException + */ + public MimeType(int property, String mimetype) + throws PropertyException + { + super(property); + this.mimetype = mimetype; + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. + * @param mimetype the String containing the mimetype + * extracted from url(...). + * @exception PropertyException + */ + public MimeType(String propertyName, String mimetype) + throws PropertyException + { + super(propertyName); + this.mimetype = mimetype; + } + + /** + * @return a String containing the MIMETYPE. + */ + public String getMimetype() { + return mimetype; + } + + /** + * validate the MimeType against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.MIMETYPE); + } + +} diff --git a/src/org/apache/fop/datatypes/NCName.java b/src/org/apache/fop/datatypes/NCName.java new file mode 100644 index 000000000..3bb283a52 --- /dev/null +++ b/src/org/apache/fop/datatypes/NCName.java @@ -0,0 +1,63 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.Properties; +import org.apache.fop.datatypes.StringType; + +/* + * NCName.java + * $Id$ + * + * Created: Fri Nov 23 15:21:37 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * An NCName. + */ + +public class NCName extends StringType { + + /** + * @param property the int index of the property on which + * this value is being defined. + * @param string the String. + * @exception PropertyException + */ + public NCName (int property, String string) + throws PropertyException + { + super(property, string); + } + + /** + * @param propertyName the StringString. + * @exception PropertyException + */ + public NCName (String propertyName, String string) + throws PropertyException + { + super(propertyName, string); + } + + /** + * @return the String. + */ + public String getNCName() { + return string; + } + + /** + * validate the NCName against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.NCNAME); + } + +} diff --git a/src/org/apache/fop/datatypes/None.java b/src/org/apache/fop/datatypes/None.java new file mode 100644 index 000000000..4ba4a24d0 --- /dev/null +++ b/src/org/apache/fop/datatypes/None.java @@ -0,0 +1,53 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.Properties; + +/* + * None.java + * $Id$ + * + * Created: Tue Nov 20 22:18:11 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Class for property values of "none". + */ + +public class None extends AbstractPropertyValue { + + /** + * @param property the int index of the property on which + * this value is being defined. + * @exception PropertyException + */ + public None(int property) + throws PropertyException + { + super(property); + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. + * @exception PropertyException + */ + public None(String propertyName) + throws PropertyException + { + super(propertyName); + } + + /** + * validate the None against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.NONE); + } + +} diff --git a/src/org/apache/fop/datatypes/Numeric.java b/src/org/apache/fop/datatypes/Numeric.java new file mode 100644 index 000000000..e1dfdc52f --- /dev/null +++ b/src/org/apache/fop/datatypes/Numeric.java @@ -0,0 +1,931 @@ +/* + * $Id$ + * + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ + +package org.apache.fop.datatypes; + +import java.lang.Number; + +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.PropertyConsts; +import org.apache.fop.fo.Properties; + + +/** + * An abstraction of "numeric" values as defined by the XSL FO Specification. + * Numerics include absolute numbers, absolute lengths, relative lengths + * (percentages and ems), angle, time and frequency. + * + * Relative lengths are converted immediately to a pure numeric factor, i.e. + * an absolute number (a number with unit power zero.) They retain a + * baseunit of PERCENTAGE or EMS respectively. + * + * Relative lengths resolve to absolute lengths as soon as they are involved + * in a multop with any Numeric with a baseunit of MILLIPOINTS. It is illegal + * for them to be involved in multops with Numerics of other baseunits. + * + * Therefore, only a number, its power and its baseunit need be provided for + * in this class. + * + * All numeric values are represented as a value and a unit raised to a + * power. For absolute numbers, including relative lengths, the unit power is + * zero. + * + * Whenever the power associated with a number is non-zero, it is a length, + * angle, time or frequency. + * + * It is an error for the end result of an expression to be a numeric with + * a power other than 0 or 1. (Rec. 5.9.6) + * + * Operations defined on combinations of the types are (where + * unit = ( MILLIPOINTS | HERTZ | MILLISECS | DEGREES ) + * length = MILLIPOINTS + * number = NUMBER + * relunit = ( PERCENTAGE | EMS ) + * notnumber = ( unit | relunit ) + * absunit = ( number | unit ) + * notlength = ( HERTZ | MILLISECS | DEGREES ) + * numeric = ( number | notnumber ) + * ) + * numeric^n addop numeric^m = Illegal + * numeric1 addop numeric2 = Illegal + * numeric1^n addop numeric1^n = numeric1^n includes number + number + * + * number multop anyunit = anyunit universal multiplier + * includes number * relunit + * unit1 multop unit2 = Illegal + * relunit multop notlength = Illegal + * relunit multop relunit = Illegal + * + * unit1^n multop unit1^m = unit1^(n+m) includes number * number + * excludes relunit* relunit + * relunit multop length = length + * + * Numerics are changeable, as the above table shows. A numeric + * created as a Time in seconds to power 1, e.g., if divided by another + * Time in seconds to power 1 becomes a number. if it is then + * multiplied by a Length in points to power 1, it becomes a + * Length in points. + * + * In fact, all lengths are maintained internally + * in millipoints. Each of the non-number Numeric types is maintained + * internally in a single baseunit. These are:
+ * MILLIPOINTS
+ * HERTZ
+ * MILLISECS
+ * DEGREES
+ */ +public class Numeric extends AbstractPropertyValue implements Cloneable { + + /** + * Integer constant encoding a valid Numeric subclass + * base unit + */ + public static final int + NUMBER = 1 + ,PERCENTAGE = 2 + ,EMS = 4 + ,MILLIPOINTS = 8 + ,HERTZ = 16 + ,MILLISECS = 32 + ,DEGREES = 64 + + ,LAST_BASEUNIT = DEGREES + ; + + /** + * Integer constants for the subunits of numbers. + */ + public static final int NUMERIC = NUMBER | PERCENTAGE | EMS; + + /** + * Integer constants for the subunits of relative lengths. + */ + public static final int REL_LENGTH = PERCENTAGE | EMS; + + /** + * Integer constants for the named units. + */ + public static final int UNIT = MILLIPOINTS | HERTZ | MILLISECS | DEGREES; + + /** + * Integer constants for the named units not a length. + */ + public static final int NOT_LENGTH = HERTZ | MILLISECS | DEGREES; + + /** + * Integer constants for the absolute-valued units. + */ + public static final int ABS_UNIT = NUMBER | UNIT; + + /** + * Integer constants for non-numbers. + */ + public static final int NOT_NUMBER = UNIT | REL_LENGTH; + + /** + * The numerical contents of this instance. + */ + protected double value; + + /** + * The power to which the UNIT (not the number) is raised + */ + protected int power; + + /** + * The current baseunit of this instance. + * One of the constants defined here. Defaults to millipoints. + */ + private int baseunit = MILLIPOINTS; + + /** + * The baseunit in which this Numeric was originally defined. + */ + private int originalBaseUnit = MILLIPOINTS; + + /** + * The actual unit in which this Numeric was originally defined. + * This is a constant defined in each of the original unit types. + */ + private int originalUnit = Length.PT; + + /** + * Construct a fully specified Numeric object. + * @param property int index of the property. + * @param value the actual value. + * @param baseunit the baseunit for this Numeric. + * @param power The dimension of the value. 0 for a Number, 1 for a Length + * (any type), >1, <0 if Lengths have been multiplied or divided. + * @param unit int enumeration of the subtype of the + * baseunit in which this Numeric is being defined. + */ + protected Numeric + (int property, double value, int baseunit, int power, int unit) + throws PropertyException + { + super(property); + // baseunit must be a power of 2 <= the LAST_BASEUNIT + if ((baseunit & (baseunit - 1)) != 0 + || baseunit > LAST_BASEUNIT) + throw new PropertyException + ("Invalid baseunit: " + baseunit); + if ((baseunit & NUMERIC) != 0 && power != 0) + throw new PropertyException + ("Invalid power for NUMERIC: " + power); + + this.value = value; + this.power = power; + this.baseunit = baseunit; + originalBaseUnit = baseunit; + originalUnit = unit; + if (baseunit == DEGREES) this.value = Angle.normalize(this); + } + + /** + * Construct a fully specified Numeric object. + * @param propertyName String name of the property. + * @param value the actual value. + * @param baseunit the baseunit for this Numeric. Because a + * power is being specified, NUMBER baseunits are invalid. + * @param power The dimension of the value. 0 for a Number, 1 for a Length + * (any type), >1, <0 if Lengths have been multiplied or divided. + * @param unit int enumeration of the subtype of the + * baseunit in which this Numeric is being defined. + */ + protected Numeric (String propertyName, double value, int baseunit, + int power, int unit) + throws PropertyException + { + this(PropertyConsts.getPropertyIndex(propertyName), + value, baseunit, power, unit); + } + + /** + * Construct a Numeric object of dimension 0 from a + * double. + * @param propertyName String property name. + * @param value the number as a double. + */ + public Numeric(String propertyName, double value) + throws PropertyException + { + this(PropertyConsts.getPropertyIndex(propertyName), value); + } + + /** + * Construct a Numeric object of dimension 0 from a + * double. + * @param property int property index. + * @param value the number as a double. + */ + public Numeric(int property, double value) throws PropertyException { + this(property, value, NUMBER, 0, 0); + } + + /** + * Construct a Numeric object of dimension 0 from a + * long. + * @param propertyName String property name. + * @param value the number as a long. + */ + public Numeric(String propertyName, long value) + throws PropertyException + { + this(propertyName, (double)value); + } + + /** + * Construct a Numeric object of dimension 0 from a + * long. + * @param property int property index. + * @param value the number as a long. + */ + public Numeric(int property, long value)throws PropertyException { + this(property, (double)value); + } + + /** + * Construct a Numeric object from a Number. + * @param propertyName String property name. + * @param num an absolute number. + */ + public Numeric(String propertyName, Number num) + throws PropertyException + { + this(propertyName, num.doubleValue()); + } + + /** + * Construct a Numeric object from a Number. + * @param property int property index. + * @param num an absolute number. + */ + public Numeric(int property, Number num) throws PropertyException { + this(property, num.doubleValue()); + } + + /** + * @return double value of the Numeric. + */ + public double getValue() { + return value; + } + + /** + * @return int unit power of this Numeric. + */ + public int getPower() { + return power; + } + + /** + * @return int current baseunit of this Numeric. + */ + public int getBaseunit() { + return baseunit; + } + + /** + * @return int original base unit of this Numeric. + */ + public int getOriginalBaseUnit() { + return originalBaseUnit; + } + + /** + * @return int original unit in which this Numeric was + * defined. Value is defined in terms of the originalBaseUnit type. + */ + public int getOriginalUnit() { + return originalUnit; + } + + /** + * Validate this Numeric. + * @exception PropertyException if this numeric is invalid for + * the associated property. + */ + public void validate() throws PropertyException { + switch (baseunit) { + case NUMBER: + if (power != 0) + throw new PropertyException + ("Attempt to validate Numeric with unit power of " + + power); + super.validate(Properties.NUMBER); + break; + case PERCENTAGE: + if (power != 0) + throw new PropertyException + ("Attempt to validate Percentage with unit power of " + + power); + super.validate(Properties.PERCENTAGE); + break; + case MILLIPOINTS: + super.validate(Properties.LENGTH); + if (power != 1) + throw new PropertyException + ("Length with unit power " + power); + break; + case HERTZ: + super.validate(Properties.FREQUENCY); + if (power != 1) + throw new PropertyException + ("Frequency with unit power " + power); + break; + case MILLISECS: + super.validate(Properties.TIME); + if (power != 1) + throw new PropertyException + ("Time with unit power " + power); + break; + case DEGREES: + super.validate(Properties.ANGLE); + if (power != 1) + throw new PropertyException + ("Angle with unit power " + power); + break; + default: + throw new PropertyException + ("Unrecognized baseunit type: " + baseunit); + } + } + + /** + * This object has a NUMERIC type if it is a NUMBER, EMS or PERCENTAGE + * type. + */ + public boolean isNumeric() { + return (baseunit & NUMERIC) != 0; + } + + /** + * This object is a number if the baseunit is NUMBER. Power is + * guaranteed to be zero for NUMBER baseunit. + */ + public boolean isNumber() { + return (baseunit == NUMBER); + } + + /** + * This object is an EMS factor is the baseunit is EMS. Power is + * guaranteed to be zero for EMS baseunit. + */ + public boolean isEms() { + return (baseunit == EMS); + } + + /** + * This object is a percentage factor if the baseunit is PERCENTAGE. + * Power is guaranteed to be zero for PERCENTAGE baseunit. + */ + public boolean isPercentage() { + return (baseunit == PERCENTAGE); + } + + /** + * This object is a length in millipoints. + */ + public boolean isLength() { + return (baseunit == MILLIPOINTS && power == 1); + } + + /** + * This object is a time in milliseconds. + */ + public boolean isTime() { + return (baseunit == MILLISECS && power == 1); + } + + /** + * This object is a frequency in hertz. + */ + public boolean isFrequency() { + return (baseunit == HERTZ && power == 1); + } + + /** + * This object is an angle in degrees. + */ + public boolean isAngle() { + return (baseunit == DEGREES && power == 1); + } + + /** + * Return this Numeric converted (if necessary) to a + * double. The + * value field, a double, is returned unchanged. To check + * whether this is a good thing to do, call isNumber(). + * @return a double primitive type. + */ + public double asDouble() { + return value; + } + + /** + * Return the current value as a long. + * The double value is converted to an long and + * returned. No other checking or conversion occurs. + */ + public long asLong() { + return (long)value; + } + + /** + * Return the current value as an int. + * The double value is converted to an int and + * returned. No other checking or conversion occurs. + */ + public int asInt() { + return (int)value; + } + + /** + * Subtract the operand from the current value. + * @param op The value to subtract. + * @return Numeric; this object. + * @throws PropertyException If the unit power of the operands is different + */ + public Numeric subtract(Numeric op) throws PropertyException { + // Check of same dimension + if (power != op.power) + throw new PropertyException + ("Can't subtract Numerics of different unit powers."); + if (baseunit != op.baseunit) { + throw new PropertyException + ("Can't subtract Numerics of different baseunits: " + + getBaseunitString() + " " + op.getBaseunitString()); + } + + // Subtract each type of value + value -= op.value; + if (baseunit == DEGREES) this.value = Angle.normalize(this); + return this; + } + + /** + * Add the operand to the current value. + * @param op The value to add. + * @return Numeric; this object. + * @throws PropertyException + * if the unit power of the operands is different. + */ + public Numeric add(Numeric op) throws PropertyException { + // Check of same powerension + if (power != op.power) + throw new PropertyException + ("Can't add Numerics of different unit powers."); + if (baseunit != op.baseunit) { + throw new PropertyException + ("Can't add Numerics of different baseunits: " + + getBaseunitString() + " " + op.getBaseunitString()); + } + + // Add each type of value + value += op.value; + if (baseunit == DEGREES) this.value = Angle.normalize(this); + return this; + } + + /** + * Derive the remainder from a truncating division (mod). As with + * additive operators, the values must be absolute Numerics + * of the same unit value. (5.9.6) + * @param op a Numeric representing the divisor + * @return Numeric; this object. + * @throws PropertyException If the unit power of the operands is + * different or if the operands have different baseunits. + */ + public Numeric mod(Numeric op) throws PropertyException { + if (power != op.power) + throw new PropertyException + ("Can't mod Numerics of different unit powers."); + if (baseunit != op.baseunit) { + throw new PropertyException + ("Can't mod Numerics of different baseunits: " + + getBaseunitString() + " " + op.getBaseunitString()); + } + if ((baseunit & REL_LENGTH) != 0) { + throw new PropertyException + ("Can't mod relative lengths." + + getBaseunitString() + " " + op.getBaseunitString()); + } + + value %= op.value; + if (baseunit == DEGREES) this.value = Angle.normalize(this); + return this; + } + + /** + * Derive the remainder from a truncating division (mod). As with + * additive operators, the values must be absolute Numerics + * of the same unit value. (5.9.6) + * In this case, the argument is a double, i.e., an absolute + * Numeric with a unit value of zero. + *

Originally the restriction for this method was lifted as noted + * here. There is no indication of why. The restriction is now in place. + *

In this case only, the restriction + * on the same unit power is lifted. + * @param op a double containing the divisor + * @return Numeric; this object. + */ + public Numeric mod(double op) throws PropertyException { + if (power != 0) + throw new PropertyException + ("Can't mod Numerics of different unit powers."); + if (baseunit != NUMBER) { + throw new PropertyException + ("Can't mod Numerics of different baseunits: " + + getBaseunitString() + " literal double"); + } + if ((baseunit & REL_LENGTH) != 0) { + throw new PropertyException + ("Can't mod relative lengths." + + getBaseunitString()); + } + + value %= op; + if (baseunit == DEGREES) this.value = Angle.normalize(this); + return this; + } + + /** + * Multiply the the current value by the operand. + * @param op The multiplier. + * @return Numeric; this object. + * @throws PropertyException for invalid combinations. + */ + public Numeric multiply(Numeric op) throws PropertyException { + if (baseunit == NUMBER) { + // NUMBER is the universal multiplier + // Multiply and convert to the basetype and power of the arg + value *= op.value; + power = op.power; + baseunit = op.baseunit; + } else { // this is not a NUMBER - must be unit or relative length + if (op.baseunit == NUMBER) { + // NUMBER is the universal multiplier + value *= op.value; + } else { // op not a NUMBER - must be UNIT or REL_LENGTH + if ((baseunit & UNIT ) != 0) { // this is a unit + if ((op.baseunit & UNIT) != 0) { // op is a unit + if (baseunit != op.baseunit) { // not same unit + throw new PropertyException + ("Can't multiply Numerics of different " + + "baseunits: " + getBaseunitString() + + " " + op.getBaseunitString()); + } else { // same unit- multiply OK + value *= op.value; + power += op.power; + } + } else { // op is a REL_LENGTH; this is a UNIT + if (baseunit == MILLIPOINTS) { // this is a LENGTH + // Result is a length * numeric relative factor + value *= op.value; + } else { // this is a UNIT not a LENGTH + throw new PropertyException + ("Can't multiply a unit other than a " + + "length by a relative length: " + + getBaseunitString() + + " " + op.getBaseunitString()); + } + } + } else { // this is a REL_LENGTH op is UNIT or REL_LENGTH + // only valid if op is a LENGTH + if (op.baseunit == MILLIPOINTS) { + value *= op.value; + power = op.power; + baseunit = op.baseunit; + } else { // Can't be done + throw new PropertyException + ("Can't multiply a unit other than a " + + "length by a relative length: " + + getBaseunitString() + + " " + op.getBaseunitString()); + } + } + } + } // end of this == unit or relative length + // Perfom some validity checks + if (isNumeric() && power != 0) + throw new PropertyException + ("Number, Ems or Percentage with non-zero power"); + // if the operation has resulted in a non-NUMERIC reducing to + // a unit power of 0, change the type to NUMBER + if (power == 0 && ! this.isNumeric()) baseunit = NUMBER; + // Always normalize if we are dealing with degrees. + if (baseunit == DEGREES) this.value = Angle.normalize(this); + return this; + } + + /** + * Multiply the the current value by the double operand. + * @param op The multiplier. + * @return Numeric; this object. + */ + public Numeric multiply(double op) { + value *= op; + if (baseunit == DEGREES) this.value = Angle.normalize(this); + return this; + } + + /** + * Divide the the current value by the operand. + * @param op the divisor. + * @return Numeric; this object. + * @throws PropertyException for invalid combinations. + */ + public Numeric divide(Numeric op) throws PropertyException { + if (baseunit == NUMBER) { + // NUMBER is the universal multiplier + // Divide and convert to the basetype and power of the arg + value /= op.value; + power = op.power; + baseunit = op.baseunit; + } else { // this is not a NUMBER - must be unit or relative length + if (op.baseunit == NUMBER) { + // NUMBER is the universal multiplier + value /= op.value; + } else { // op not a NUMBER - must be UNIT or REL_LENGTH + if ((baseunit & UNIT ) != 0) { // this is a unit + if ((op.baseunit & UNIT) != 0) { // op is a unit + if (baseunit != op.baseunit) { // not same unit + throw new PropertyException + ("Can't divide Numerics of different " + + "baseunits: " + getBaseunitString() + + " " + op.getBaseunitString()); + } else { // same unit- divide OK + value /= op.value; + power -= op.power; + } + } else { // op is a REL_LENGTH; this is a UNIT + if (baseunit == MILLIPOINTS) { // this is a LENGTH + // Result is a length * numeric relative factor + value /= op.value; + } else { // this is a UNIT not a LENGTH + throw new PropertyException + ("Can't multiply a unit other than a " + + "length by a relative length: " + + getBaseunitString() + + " " + op.getBaseunitString()); + } + } + } else { // this is a REL_LENGTH op is UNIT or REL_LENGTH + // only valid if op is a LENGTH + if (op.baseunit == MILLIPOINTS) { + value /= op.value; + power = op.power; + baseunit = op.baseunit; + } else { // Can't be done + throw new PropertyException + ("Can't multiply a unit other than a " + + "length by a relative length: " + + getBaseunitString() + + " " + op.getBaseunitString()); + } + } + } + } // end of this == unit or relative length + // Perfom some validity checks + if (isNumeric() && power != 0) + throw new PropertyException + ("Number, Ems or Percentage with non-zero power"); + // if the operation has resulted in a non-NUMERIC reducing to + // a unit power of 0, change the type to NUMBER + if (power == 0 && ! this.isNumeric()) baseunit = NUMBER; + // Always normalize if we are dealing with degrees. + if (baseunit == DEGREES) this.value = Angle.normalize(this); + return this; + } + + /** + * Divide the the current value by the double operand. + * @param op The divisor. + * @return Numeric; this object. + */ + public Numeric divide(double op) { + value /= op; + if (baseunit == DEGREES) this.value = Angle.normalize(this); + return this; + } + + /** + * Negate the value of the property. + * @return Numeric; this object. + */ + public Numeric negate() { + value = -value; + // I think this is OK + if (baseunit == DEGREES) this.value = Angle.normalize(this); + return this; + } + + /** + * Return the absolute value of this Numeric. This is an + * implementation of the core function library abs function. + * It is only valid on an absolute numeric of unit power zero. + * @return A double containing the absolute value. + * @exception PropertyException if value is not unit power zero. + */ + public double abs() throws PropertyException { + if (power != 0) + throw new PropertyException + ("abs requires absolute numeric of unit power zero"); + return Math.abs(value); + } + + /** + * Return a double which is the maximum of the current value and + * the operand. This is an implementation of the core function library + * max function. It is only valid for comparison of two + * absolute Numeric values. + * @param op a Numeric representing the comparison value. + * @return a double representing the max of + * this.value and the value of op. + * @throws PropertyException If the power of this + * object and the operand are different or not 0. + */ + public double max(Numeric op) throws PropertyException { + // Only compare if both have unit power 0 + if (power == op.power && power == 0) { + return Math.max(value, op.value); + } + throw new PropertyException + ("max() must compare numerics of unit power 0."); + } + + /** + * Return a double which is the minimum of the current value and + * the operand. This is an implementation of the core function library + * min function. It is only valid for comparison of two + * absolute Numeric values. + * @param op a Numeric representing the comparison value. + * @return a double representing the min of + * this.value and the value of op. + * @throws PropertyException If the power of this + * object and the operand are different or not 0. + */ + public double min(Numeric op) throws PropertyException { + // Only compare if both have unit power 0 + if (power == op.power && power == 0) { + return Math.min(value, op.value); + } + throw new PropertyException + ("min() must compare numerics of unit power 0."); + } + + /** + * Return a double which is the ceiling of the current value. + * This is an implementation of the core function library + * ceiling function. It is only valid for an absolute + * numeric value of unit power 0. + * @return a double representing the ceiling value. + * @throws PropertyException If the unit power of the + * object is not 0. + */ + public double ceiling() throws PropertyException { + + if (power == 0) { + return Math.ceil(value); + } + throw new PropertyException + ("ceiling() requires unit power 0."); + } + + /** + * Return a double which is the floor of the current value. + * This is an implementation of the core function library + * floor function. It is only valid for an absolute + * numeric value of unit power 0. + * @return a double representing the floor value. + * @throws PropertyException If the unit power of the + * object is not 0. + */ + public double floor() throws PropertyException { + + if (power == 0) { + return Math.floor(value); + } + throw new PropertyException + ("floor() requires unit power 0."); + } + + /** + * Return a long which is the rounded current value. + * This is an implementation of the core function library + * round function. It is only valid for an absolute + * numeric value of unit power 0. + * @return a long representing the rounded value. + * Note that although the method returns a long, + * the XSL funtion is expressed in terms of a numeric. + * @throws PropertyException If the unit power of the + * object is not 0. + */ + public long round() throws PropertyException { + + if (power == 0) { + return Math.round(value); + } + throw new PropertyException + ("round() requires unit power 0."); + } + + /** + * @param baseunit an init encoding the base unit. + * @return a String containing the text name of the baseunit + * type or notification of an unrecognized baseunit/ + */ + public String getUnitTypeString(int baseunit) { + switch (baseunit) { + case NUMBER: + return "numeric"; + case PERCENTAGE: + return "percentage"; + case MILLIPOINTS: + return "millipoints"; + case HERTZ: + return "Hertz"; + case MILLISECS: + return "milliseconds"; + case DEGREES: + return "degrees"; + default: + return "Unrecognized baseunit type: " + baseunit; + } + + } + + /** + * @return a String containing the text name of the current baseunit + * type or notification of an unrecognized baseunit/ + */ + public String getBaseunitString() { + return getUnitTypeString(baseunit); + } + + /** + * @return a String containing the text name of the original + * baseunit type or notification of an unrecognized baseunit/ + */ + public String getOriginalBaseunitString() { + return getUnitTypeString(originalBaseUnit); + } + + /** + * @return a String containing the text name of the original + * unit type or notification of an unrecognized unit. + * Defined relative to the originalBaseUnit. + */ + public String getOriginalUnitString() { + switch (originalBaseUnit) { + case NUMBER: + return ""; + case PERCENTAGE: + return "%"; + case MILLIPOINTS: + return Length.getUnitName(originalUnit); + case HERTZ: + return Frequency.getUnitName(originalUnit); + case MILLISECS: + return Time.getUnitName(originalUnit); + case DEGREES: + return Angle.getUnitName(originalUnit); + default: + return "Unrecognized original baseunit type: " + originalBaseUnit; + } + + } + + /** + * @param unit an int encoding a Time unit. + * @return the String name of the unit. + */ + public static String getUnitName(int unit) { + switch (unit) { + case NUMBER: + return ""; + case PERCENTAGE: + return "%"; + default: + return ""; + } + } + + public String toString() { + return "" + value + getBaseunitString() + + (power != 0 ? "^" + power : "") + + "\n" + super.toString(); + } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/src/org/apache/fop/datatypes/Percentage.java b/src/org/apache/fop/datatypes/Percentage.java new file mode 100644 index 000000000..12c23be09 --- /dev/null +++ b/src/org/apache/fop/datatypes/Percentage.java @@ -0,0 +1,59 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; + +/* + * Percentage.java + * + * + * Created: Wed Nov 21 15:39:30 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Constructor class for Percentage datatype. Constructs a Numeric. + */ + +public class Percentage { + + /** + * Private constructor - don't instantiate a Percentage object. + */ + private Percentage() {} + + /** + * Construct a Numeric with a given quantity. + * The unit power is assumed as 0. The base unit is PERCENTAGE. + * @param property the index of the property with which this value + * is associated. + * @param percentage. This value will be normalized. + * @return a Numeric representing this Percentage. + */ + public static Numeric makePercentage(int property, double percentage) + throws PropertyException + { + return new Numeric(property, percentage / 100.0, + Numeric.PERCENTAGE, 0, 0); + } + + /** + * Construct a Numeric with a given quantity. + * The unit power is assumed as 0. The base unit is PERCENTAGE. + * @param propertyName the name of the property with which this value + * is associated. + * @param percentage. This value will be normalized. + * @return a Numeric representing this Percentage. + */ + public static Numeric makePercentage + (String propertyName, double percentage) + throws PropertyException + { + return new Numeric(propertyName, percentage / 100.0, + Numeric.PERCENTAGE, 0, 0); + } + +} diff --git a/src/org/apache/fop/datatypes/Script.java b/src/org/apache/fop/datatypes/Script.java new file mode 100644 index 000000000..16894b00d --- /dev/null +++ b/src/org/apache/fop/datatypes/Script.java @@ -0,0 +1,55 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.PropertyConsts; +import org.apache.fop.fo.Properties; +import org.apache.fop.configuration.Configuration; + +/* + * Script.java + * $Id$ + * + * Created: Mon Nov 26 22:46:05 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * A class for script specifiers. + */ + +public class Script extends NCName { + + public Script(int property, String scriptCode) throws PropertyException + { + super(property, scriptCode); + // Validate the code + if (Configuration.getHashMapEntry("scriptsMap", scriptCode) + == null) throw new PropertyException + ("Invalid script code: " + scriptCode); + } + + public Script(String propertyName, String scriptCode) + throws PropertyException + { + this(PropertyConsts.getPropertyIndex(propertyName), scriptCode); + } + + /** + * @return the String script code. + */ + public String getScript() { + return string; + } + + /** + * Validate the Script against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.SCRIPT_T); + } + +} diff --git a/src/org/apache/fop/datatypes/ShadowEffect.java b/src/org/apache/fop/datatypes/ShadowEffect.java new file mode 100644 index 000000000..292d7f858 --- /dev/null +++ b/src/org/apache/fop/datatypes/ShadowEffect.java @@ -0,0 +1,191 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.expr.PropertyValueList; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.Properties; +import org.apache.fop.fo.PropertyConsts; +import org.apache.fop.fo.PropNames; + +import java.util.Iterator; + +/* + * ShadowEffect.java + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Class to represent ShadowEffect values. This class is a holder for a + * set of PropertyValue objects, and will be placed in a PropertyValueList, + * as text shadow effects are specified in a list. See 7.16.5. + */ + +public class ShadowEffect extends AbstractPropertyValue { + + /** + * The shadow's "horizontal distance to the right of the text" (mandatory). + */ + private Numeric inlineOffset; + + /** + * The shadow's "vertical distance below the text" (mandatory). + */ + private Numeric blockOffset; + + /** + * The shadow's blur radius (optional) + */ + private Numeric blurRadius; + + /** + * The shadow's color (optional) + */ + private ColorType color; + + /** + * Construct a ShadowEffect from a given PropertyValueList. + * An individual shadow effect is specified as a list comprising a + * mandatory pair of Lengths, the inline-progression offset and + * the block-progression offset, with an otpional third Length + * for the blur radius. The shadow effect may optionally include a + * color value, specified as a ColorType. The ColorType + * may precede or follow the Length specifiers. + * @param property the index of the property with which this value + * is associated. + * @param list the PropertyValueList containing details of one + * shadow effect + */ + public ShadowEffect(int property, PropertyValueList list) + throws PropertyException + { + super(property); + Object entry; + Iterator entries = list.iterator(); + switch (list.size()) { + case 2: + // Must be the inline and block offsets + setInlineAndBlock(entries); + break; + case 3: + // Must have inline and block offsets; may have blur radius or + // a colour specifier + if (list.getFirst() instanceof Numeric) { + if (list.getLast() instanceof Numeric) { + setInlineBlockAndBlur(entries); + } else { // last element must be a color + setInlineAndBlock(entries); + setColor(entries); + } + } + else { // First entry is not Numeric; has to be color + setColor(entries); + setInlineAndBlock(entries); + } + break; + case 4: + // Must have inline and block offsets, blur radius and colour + // specifier + if (list.getFirst() instanceof Numeric) { + setInlineBlockAndBlur(entries); + setColor(entries); + } + else { // First entry is not Numeric; has to be color + setColor(entries); + setInlineBlockAndBlur(entries); + } + break; + default: + throw new PropertyException + ("Invalid number of elements in ShadowEffect: " + + list.size()); + } + } + + /** + * Construct a ShadowEffect from a given PropertyValueList. + * @param propertyName the name of the property with which this value + * is associated. + * @param list the PropertyValueList containing details of one + * shadow effect + */ + public ShadowEffect(String propertyName, PropertyValueList list) + throws PropertyException + { + this(PropertyConsts.getPropertyIndex(propertyName), list); + } + + /** + * Pick up two Numeric entries through the Iterator + * and assign them to the inlineOffset and blockOffset + * @param entries an Iterator already initialised elsewhere + */ + private void setInlineAndBlock(Iterator entries) + throws PropertyException + { + Object entry; + entry = entries.next(); + if (! (entry instanceof Numeric)) + throw new PropertyException + ("Numeric value expected for text-shadow"); + inlineOffset = (Numeric)entry; + entry = entries.next(); + if (! (entry instanceof Numeric)) + throw new PropertyException + ("Numeric value expected for text-shadow"); + blockOffset = (Numeric)entry; + } + + /** + * Pick up three Numeric entries through the Iterator + * and assign them to the inlineOffset, blockOffset and blurRadius + * @param entries an Iterator already initialised elsewhere + */ + private void setInlineBlockAndBlur(Iterator entries) + throws PropertyException + { + Object entry; + setInlineAndBlock(entries); + entry = entries.next(); + if (! (entry instanceof Numeric)) + throw new PropertyException + ("Numeric blur radius value expected for text-shadow"); + blurRadius = (Numeric)entry; + } + + /** + * Set the shadow color from the next entry returned by the entries + * iterator. A color entry must be either a ColorType already, + * or an NCName containing one of the standard XSL color + * keywords. + * @param entries an Iterator. + */ + private void setColor(Iterator entries) throws PropertyException { + Object entry; + entry = entries.next(); + if (entry instanceof ColorType) { + color = (ColorType)entry; + } else if (entry instanceof NCName) { + color = new ColorType + (property, + PropertyConsts.getEnumIndex + (PropNames.TEXT_SHADOW, ((NCName)entry).getNCName())); + } + } + + /** + * Validate this ShadowEffect. Check that it is allowed on the + * associated property. A ShadowEffect may also encode a single + * character; i.e. a <character> type. If the + * validation against LITERAL fails, try CHARACTER_T. + */ + public void validate() throws PropertyException { + if (property != PropNames.TEXT_SHADOW) + throw new PropertyException + ("ShadowEffects only valid for text-shadow'"); + } + +} diff --git a/src/org/apache/fop/datatypes/StringType.java b/src/org/apache/fop/datatypes/StringType.java new file mode 100644 index 000000000..12cee28c8 --- /dev/null +++ b/src/org/apache/fop/datatypes/StringType.java @@ -0,0 +1,70 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.Properties; + +/* + * StringType.java + * $Id$ + * + * Created: Fri Nov 23 15:21:37 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * The base class for most datatypes which resolve to a String. + */ + +public class StringType extends AbstractPropertyValue { + + protected String string; + + /** + * @param property the int index of the property on which + * this value is being defined. + * @param string the String. + * @exception PropertyException + */ + public StringType (int property, String string) + throws PropertyException + { + super(property); + this.string = string; + } + + /** + * @param propertyName the StringString. + * @exception PropertyException + */ + public StringType (String propertyName, String string) + throws PropertyException + { + super(propertyName); + this.string = string; + } + + /** + * @return the String. + */ + public String getString() { + return string; + } + + /** + * validate the StringType against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.STRING_TYPE); + } + + public String toString() { + return string + "\n" + super.toString(); + } +} diff --git a/src/org/apache/fop/datatypes/TextDecorations.java b/src/org/apache/fop/datatypes/TextDecorations.java new file mode 100644 index 000000000..5cb1a1c41 --- /dev/null +++ b/src/org/apache/fop/datatypes/TextDecorations.java @@ -0,0 +1,82 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.Properties; +import org.apache.fop.fo.PropNames; +import org.apache.fop.datatypes.TextDecorator; + +/* + * TextDecorations.java + * $Id$ + * + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Class for + */ + +public class TextDecorations + extends AbstractPropertyValue implements Cloneable +{ + + /** + * The decorations specified by this object + */ + private byte decorations; + + /** + * @param property the int index of the property on which + * this value is being defined. + * @exception PropertyException + */ + public TextDecorations(int property, byte decorations) + throws PropertyException + { + super(property); + this.decorations = decorations; + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. + * @exception PropertyException + */ + public TextDecorations(String propertyName) + throws PropertyException + { + super(propertyName); + this.decorations = decorations; + } + + /** + * @return byte decorations value + */ + public byte getDecorations() { + return decorations; + } + + public byte maskDecorations(TextDecorator decorator) { + decorations |= decorator.onMask; + decorations &= ( ~ decorator.offMask ); + return decorations; + } + + /** + * validate the TextDecorations against the associated property. + */ + public void validate() throws PropertyException { + if (property != PropNames.TEXT_DECORATION) + throw new PropertyException + ("TextDecorations only valid for 'text-decoration'"); + } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + +} diff --git a/src/org/apache/fop/datatypes/TextDecorator.java b/src/org/apache/fop/datatypes/TextDecorator.java new file mode 100644 index 000000000..df0a30c19 --- /dev/null +++ b/src/org/apache/fop/datatypes/TextDecorator.java @@ -0,0 +1,73 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.Properties; +import org.apache.fop.fo.PropNames; + +/* + * TextDecorator.java + * $Id$ + * + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Class for "text-decoration" specification. This class specifies the + * text decoration modifiers which are to be applied to the current + * text-decoration value. + *

It is applied to a TextDecorations object, to modify the decorations + * by applying these values. + */ + +public class TextDecorator extends AbstractPropertyValue { + + /** + * OR mask to turn decorations on + */ + public final byte onMask; + + /** + * NAND mask to turn decorations off + */ + public final byte offMask; + + /** + * @param property the int index of the property on which + * this value is being defined. + * @exception PropertyException + */ + public TextDecorator(int property, byte onMask, byte offMask) + throws PropertyException + { + super(property); + this.onMask = onMask; + this.offMask = offMask; + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. + * @exception PropertyException + */ + public TextDecorator(String propertyName, byte onMask, byte offMask) + throws PropertyException + { + super(propertyName); + this.onMask = onMask; + this.offMask = offMask; + } + + /** + * validate the TextDecorator against the associated property. + */ + public void validate() throws PropertyException { + if (property != PropNames.TEXT_DECORATION) + throw new PropertyException + ("TextDecorator only valid for 'text-decoration'"); + } + +} diff --git a/src/org/apache/fop/datatypes/Time.java b/src/org/apache/fop/datatypes/Time.java new file mode 100644 index 000000000..15e8687c8 --- /dev/null +++ b/src/org/apache/fop/datatypes/Time.java @@ -0,0 +1,99 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; +//import org.apache.fop.fo.Properties; +//import org.apache.fop.fo.PropertyConsts; +//import org.apache.fop.fo.PropNames; + +/* + * Time.java + * $Id$ + * Created: Wed Nov 21 15:39:30 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Time is a front for the manufacture of Numeric objects. + * Because Numerics are so malleable, it makes no sense to tie + * a Numeric object to any particular type by subclassing Numeric. + * Instead, each of the Numeric types provides static methods to generate + * a Numeric representing, as originally created, a particular type of + * number or measure. The constructor for this class is private. + */ + +public class Time { + /* + * Constants for UnitNames + */ + public static final int NOUNIT = 0; + public static final int MSEC = 1; + public static final int SEC = 2; + + /** + * Array of constant conversion factors from unit to milliseconds, + * indexed by integer unit constant. Keep this array in sync with + * the integer constants or bear the consequences. + */ + public static final double[] msPerUnit = { + 0.0 + ,1.0 + ,1000.0 + }; + + /** + * Private constructor - don't instantiate a Time object. + */ + private Time() {} + + /** + * Construct a Numeric with a given unit and quantity. + * The unit power is assumed as 1. The base unit is milliseconds. + * @param property the index of the property with which this value + * is associated. + * @param value the number of units. + * @param unit an integer constant representing the unit + * @return a Numeric representing this Time. + */ + public static Numeric makeTime(int property, double value, int unit) + throws PropertyException + { + return new Numeric(property, value * msPerUnit[unit], + Numeric.MILLISECS, 1, unit); + } + + /** + * Construct a Numeric with a given unit and quantity. + * The unit power is assumed as 1. The base unit is milliseconds. + * @param propertyName the name of the property with which this value + * is associated. + * @param value the number of units. + * @param unit an integer constant representing the unit + * @return a Numeric representing this Time. + */ + public static Numeric makeTime(String propertyName, double value, int unit) + throws PropertyException + { + return new Numeric(propertyName, value * msPerUnit[unit], + Numeric.MILLISECS, 1, unit); + } + + /** + * @param unit an int encoding a Time unit. + * @return the String name of the unit. + */ + public static String getUnitName(int unit) { + switch (unit) { + case MSEC: + return "ms"; + case SEC: + return "s"; + default: + return ""; + } + } + +} diff --git a/src/org/apache/fop/datatypes/UriType.java b/src/org/apache/fop/datatypes/UriType.java new file mode 100644 index 000000000..ce08d6848 --- /dev/null +++ b/src/org/apache/fop/datatypes/UriType.java @@ -0,0 +1,71 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.AbstractPropertyValue; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.Properties; + +/* + * UriType.java + * $Id$ + * + * Created: Tue Nov 20 22:18:11 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Class for URLs specified with uri() function. + */ + +public class UriType extends AbstractPropertyValue { + + /** + * A URI Specification + */ + private String uri; + + /** + * @param property the int index of the property on which + * this value is being defined. + * @param uri the String containing the uri extracted from + * url(...). + * @exception PropertyException + */ + public UriType(int property, String uri) + throws PropertyException + { + super(property); + this.uri = uri; + } + + /** + * @param propertyName the String name of the property on which + * this value is being defined. + * @param uri the String containing the uri extracted from + * url(...). + * @exception PropertyException + */ + public UriType(String propertyName, String uri) + throws PropertyException + { + super(propertyName); + this.uri = uri; + } + + /** + * @return a String containing the URI. + */ + public String getUri() { + return uri; + } + + /** + * validate the UriType against the associated property. + */ + public void validate() throws PropertyException { + super.validate(Properties.URI_SPECIFICATION); + } + +}