import org.apache.fop.fo.FObj;
import org.apache.fop.fo.Property;
import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.properties.PropertyMaker;
public class ToBeImplementedProperty extends Property {
- public static class Maker extends Property.Maker {
+ public static class Maker extends PropertyMaker {
public Maker(int propId) {
super(propId);
*/
package org.apache.fop.fo;
+import org.apache.fop.fo.properties.PropertyMaker;
+
/**
* Shorthand property parser for Box properties
*/
*/
protected Property convertValueForProperty(int propId,
ListProperty listProperty,
- Property.Maker maker,
+ PropertyMaker maker,
PropertyList propertyList) {
String name = FOPropertyMapping.getPropertyName(propId);
Property p = null;
*/
package org.apache.fop.fo;
+import org.apache.fop.fo.properties.PropertyMaker;
+
/**
* Superclass for properties that wrap a character value
*/
/**
* Inner class for creating instances of CharacterProperty
*/
- public static class Maker extends Property.Maker {
+ public static class Maker extends PropertyMaker {
/**
* @param propName name of property for which a Maker should be created
package org.apache.fop.fo;
import org.apache.fop.datatypes.ColorType;
+import org.apache.fop.fo.properties.PropertyMaker;
/**
* Superclass for properties that wrap ColorType values
/**
* Inner class for creating instances of ColorTypeProperty
*/
- public static class Maker extends Property.Maker {
+ public static class Maker extends PropertyMaker {
/**
* @param propName name of property for which a Maker should be created
+++ /dev/null
-/*
- * $Id$
- * ============================================================================
- * The Apache Software License, Version 1.1
- * ============================================================================
- *
- * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modifica-
- * tion, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. The end-user documentation included with the redistribution, if any, must
- * include the following acknowledgment: "This product includes software
- * developed by the Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself, if
- * and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "FOP" and "Apache Software Foundation" must not be used to
- * endorse or promote products derived from this software without prior
- * written permission. For written permission, please contact
- * apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache", nor may
- * "Apache" appear in their name, without prior written permission of the
- * Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * ============================================================================
- *
- * This software consists of voluntary contributions made by many individuals
- * on behalf of the Apache Software Foundation and was originally created by
- * James Tauber <jtauber@jtauber.com>. For more information on the Apache
- * Software Foundation, please see <http://www.apache.org/>.
- */
-package org.apache.fop.fo;
-
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.datatypes.CompoundDatatype;
-
-/**
- * @author me
- *
- * To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-/**
- * This class extends Property.Maker with support for sub-properties.
- */
-public class CompoundPropertyMaker extends Property.Maker {
- /**
- * The list of subproperty makers supported by this compound maker.
- */
- private Property.Maker[] subproperties =
- new Property.Maker[Constants.COMPOUND_COUNT];
-
- /**
- * The first subproperty maker which has a setByShorthand of true.
- */
- private Property.Maker shorthandMaker = null;
-
- /**
- * Construct an instance of a CompoundPropertyMaker for the given property.
- * @param propId The Constant ID of the property to be made.
- */
- public CompoundPropertyMaker(int propId) {
- super(propId);
- }
-
- /**
- * @see org.apache.fop.fo.Property.Maker#useGeneric(Property.Maker)
- */
- public void useGeneric(Property.Maker generic) {
- super.useGeneric(generic);
- if (generic instanceof CompoundPropertyMaker) {
- CompoundPropertyMaker compoundGeneric = (CompoundPropertyMaker) generic;
- for (int i = 0; i < Constants.COMPOUND_COUNT; i++) {
- Property.Maker submaker = compoundGeneric.subproperties[i];
- if (submaker != null) {
- addSubpropMaker((Property.Maker) submaker.clone());
- }
- }
- }
- }
-
- /**
- * Add a subproperty to this maker.
- * @param subproperty
- */
- public void addSubpropMaker(Property.Maker subproperty) {
- // Place the base propId in the propId of the subproperty.
- subproperty.propId &= Constants.COMPOUND_MASK;
- subproperty.propId |= this.propId;
-
- subproperties[getSubpropIndex(subproperty.getPropId())] = subproperty;
-
- // Store the first subproperty with a setByShorthand. That subproperty
- // will be used for converting a value set on the base property.
- if (shorthandMaker == null && subproperty.setByShorthand) {
- shorthandMaker = subproperty;
- }
- }
-
-
- /**
- * Return a Maker object which is used to set the values on components
- * of compound property types, such as "space".
- * Overridden by property maker subclasses which handle
- * compound properties.
- * @param subprop The Constants ID of the component for which a Maker is to
- * returned, for example CP_OPTIMUM, if the FO attribute is
- * space.optimum='10pt'.
- * @return the Maker object specified
- */
- public Property.Maker getSubpropMaker(int subpropId) {
- return subproperties[getSubpropIndex(subpropId)];
- }
-
- /**
- * Calculate the real value of a subproperty by unmasking and shifting
- * the value into the range [0 - (COMPOUND_COUNT-1)].
- * The value is used as index into the subproperties array.
- * @param propId the property id of the sub property.
- * @return the array index.
- */
- private int getSubpropIndex(int subpropId) {
- return ((subpropId & Constants.COMPOUND_MASK) >>
- Constants.COMPOUND_SHIFT)-1;
- }
-
- /**
- * For compound properties which can take enumerate values.
- * Delegate the enumeration check to one of the subpropeties.
- * @param value the string containing the property value
- * @return the Property encapsulating the enumerated equivalent of the
- * input value
- */
- protected Property checkEnumValues(String value) {
- if (shorthandMaker != null) {
- return shorthandMaker.checkEnumValues(value);
- }
- return null;
- }
-
- /**
- * Return the property on the current FlowObject. Depending on the passed flags,
- * this will try to compute it based on other properties, or if it is
- * inheritable, to return the inherited value. If all else fails, it returns
- * the default value.
- * @param subpropId The subproperty id of the property being retrieved.
- * Is 0 when retriving a base property.
- * @param propertylist The PropertyList object being built for this FO.
- * @param bTryInherit true if inherited properties should be examined.
- * @param bTryDefault true if the default value should be returned.
- */
- public Property get(int subpropId, PropertyList propertyList,
- boolean bTryInherit, boolean bTryDefault)
- throws FOPException
- {
- Property p = super.get(subpropId, propertyList, bTryInherit, bTryDefault);
- if (subpropId != 0 && p != null) {
- p = getSubprop(p, subpropId);
- }
- return p;
- }
-
- /**
- * Return a Property object based on the passed Property object.
- * This method is called if the Property object built by the parser
- * isn't the right type for this compound property.
- * @param p The Property object return by the expression parser
- * @param propertyList The PropertyList object being built for this FO.
- * @param fo The current FO whose properties are being set.
- * @return A Property of the correct type or null if the parsed value
- * can't be converted to the correct type.
- * @throws FOPException for invalid or inconsistent FO input
- */
- protected Property convertProperty(Property p,
- PropertyList propertyList,
- FObj fo) throws FOPException {
- if (!EnumProperty.class.isAssignableFrom(p.getClass())) {
- // delegate to the subprop maker to do conversions
- p = shorthandMaker.convertProperty(p, propertyList, fo);
- }
-
- if (p != null) {
- Property prop = makeCompound(propertyList, fo);
- CompoundDatatype pval = (CompoundDatatype) prop.getObject();
- for (int i = 0; i < Constants.COMPOUND_COUNT; i++) {
- Property.Maker submaker = subproperties[i];
- if (submaker != null && submaker.setByShorthand) {
- pval.setComponent(submaker.getPropId() & Constants.COMPOUND_MASK, p, false);
- }
- }
- return prop;
- }
- return null;
- }
-
- /**
- * Make a compound property with default values.
- * @param propertyList The PropertyList object being built for this FO.
- * @return the Property object corresponding to the parameters
- * @throws FOPException for invalid or inconsisten FO input
- */
- public Property make(PropertyList propertyList) throws FOPException {
- return makeCompound(propertyList, propertyList.getParentFObj());
- }
-
- /**
- * Create a Property object from an attribute specification.
- * @param propertyList The PropertyList object being built for this FO.
- * @param value The attribute value.
- * @param fo The current FO whose properties are being set.
- * @return The initialized Property object.
- * @throws FOPException for invalid or inconsistent FO input
- */
- public Property make(PropertyList propertyList, String value,
- FObj fo) throws FOPException {
- Property p = super.make(propertyList, value, fo);
- p = convertProperty(p, propertyList, fo);
- return p;
- }
-
- /**
- * Return a property value for a compound property. If the property
- * value is already partially initialized, this method will modify it.
- * @param baseProp The Property object representing the compound property,
- * for example: SpaceProperty.
- * @param subpropId The Constants ID of the subproperty (component)
- * whose value is specified.
- * @param propertyList The propertyList being built.
- * @param fo The FO whose properties are being set.
- * @param value the value of the
- * @return baseProp (or if null, a new compound property object) with
- * the new subproperty added
- * @throws FOPException for invalid or inconsistent FO input
- */
- public Property make(Property baseProp, int subpropId,
- PropertyList propertyList, String value,
- FObj fo) throws FOPException {
- if (baseProp == null) {
- baseProp = makeCompound(propertyList, fo);
- }
-
- Property.Maker spMaker = getSubpropMaker(subpropId);
-
- if (spMaker != null) {
- Property p = spMaker.make(propertyList, value, fo);
- if (p != null) {
- return setSubprop(baseProp, subpropId & Constants.COMPOUND_MASK, p);
- }
- } else {
- //getLogger().error("compound property component "
- // + partName + " unknown.");
- }
- return baseProp;
- }
-
- /**
- * Create a empty compound property and fill it with default values for
- * the subproperties.
- * @param propertyList The propertyList being built.
- * @param parentFO The parent FO for the FO whose property is being made.
- * @return a Property subclass object holding a "compound" property object
- * initialized to the default values for each component.
- * @throws FOPException
- */
- protected Property makeCompound(PropertyList propertyList, FObj parentFO)
- throws FOPException
- {
- Property p = makeNewProperty();
- CompoundDatatype data = (CompoundDatatype) p.getObject();
- for (int i = 0; i < Constants.COMPOUND_COUNT; i++) {
- Property.Maker submaker = subproperties[i];
- if (submaker != null) {
- Property subprop = submaker.make(propertyList, submaker.defaultValue, parentFO);
- data.setComponent(submaker.getPropId() & Constants.COMPOUND_MASK, subprop, true);
- }
- }
- return p;
- }
-}
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.CondLength;
import org.apache.fop.datatypes.Length;
+import org.apache.fop.fo.properties.CompoundPropertyMaker;
/**
* Superclass for properties that have conditional lengths
+++ /dev/null
-/*
- * Created on Jan 12, 2004
- *
- * To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-package org.apache.fop.fo;
-
-import org.apache.fop.apps.FOPException;
-
-/**
- */
-public class CorrespondingPropertyMaker {
- protected Property.Maker baseMaker;
- protected int lr_tb;
- protected int rl_tb;
- protected int tb_rl;
- private boolean useParent;
- private boolean relative;
-
- CorrespondingPropertyMaker(Property.Maker baseMaker) {
- this.baseMaker = baseMaker;
- baseMaker.setCorresponding(this);
- }
-
-
- public void setCorresponding(int lr_tb, int rl_tb, int tb_rl) {
- this.lr_tb = lr_tb;
- this.rl_tb = rl_tb;
- this.tb_rl = tb_rl;
- }
-
- public void setUseParent(boolean useParent) {
- this.useParent = useParent;
- }
-
- public void setRelative(boolean relative) {
- this.relative = relative;
- }
-
- /**
- * For properties that operate on a relative direction (before, after,
- * start, end) instead of an absolute direction (top, bottom, left,
- * right), this method determines whether a corresponding property
- * is specified on the corresponding absolute direction. For example,
- * the border-start-color property in a lr-tb writing-mode specifies
- * the same thing that the border-left-color property specifies. In this
- * example, if the Maker for the border-start-color property is testing,
- * and if the border-left-color is specified in the properties,
- * this method should return true.
- * @param propertyList collection of properties to be tested
- * @return true iff 1) the property operates on a relative direction,
- * AND 2) the property has a corresponding property on an absolute
- * direction, AND 3) the corresponding property on that absolute
- * direction has been specified in the input properties
- */
- public boolean isCorrespondingForced(PropertyList propertyList) {
- if (!relative) {
- return false;
- }
- PropertyList pList;
- if (useParent) {
- pList = propertyList.getParentFObj().propertyList;
- } else {
- pList = propertyList;
- }
- int correspondingId = pList.wmMap(lr_tb, rl_tb, tb_rl);
- if (propertyList.getExplicit(correspondingId) != null)
- return true;
- return false;
- }
-
- /**
- * Return a Property object representing the value of this property,
- * based on other property values for this FO.
- * A special case is properties which inherit the specified value,
- * rather than the computed value.
- * @param propertyList The PropertyList for the FO.
- * @return Property A computed Property value or null if no rules
- * are specified (in foproperties.xml) to compute the value.
- * @throws FOPException for invalid or inconsistent FO input
- */
- public Property compute(PropertyList propertyList) throws FOPException {
- PropertyList pList;
- if (useParent) {
- pList = propertyList.getParentPropertyList();
- if (pList == null) {
- return null;
- }
- } else {
- pList = propertyList;
- }
- int correspondingId = pList.wmMap(lr_tb, rl_tb, tb_rl);
-
- Property p = propertyList.getExplicitOrShorthand(correspondingId);
- if (p != null) {
- FObj parentFO = propertyList.getParentFObj();
- p = baseMaker.convertProperty(p, propertyList, parentFO);
- }
- return p;
- }
-}
-
+++ /dev/null
-/*
- * Created on Jan 1, 2004
- *
- * To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-package org.apache.fop.fo;
-
-import org.apache.fop.apps.FOPException;
-
-/**
- * @author me
- *
- * To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-public class DimensionPropertyMaker extends CorrespondingPropertyMaker {
- int[][] extraCorresponding = null;
-
- public DimensionPropertyMaker(Property.Maker baseMaker) {
- super(baseMaker);
- }
-
- public void setExtraCorresponding(int[][] extraCorresponding) {
- this.extraCorresponding = extraCorresponding;
- }
-
- public boolean isCorrespondingForced(PropertyList propertyList) {
- if (super.isCorrespondingForced(propertyList))
- return true;
- for (int i = 0; i < extraCorresponding.length; i++) {
- int wmcorr = extraCorresponding[i][0]; //propertyList.getWritingMode()];
- if (propertyList.getExplicit(wmcorr) != null)
- return true;
- }
- return false;
- }
-
- public Property compute(PropertyList propertyList) throws FOPException {
- // Based on [width|height]
- Property p = super.compute(propertyList);
- if (p == null) {
- p = baseMaker.make(propertyList);
- }
-
- // Based on min-[width|height]
- int wmcorr = propertyList.wmMap(extraCorresponding[0][0],
- extraCorresponding[0][1],
- extraCorresponding[0][2]);
- Property subprop = propertyList.getExplicitOrShorthand(wmcorr);
- if (subprop != null) {
- baseMaker.setSubprop(p, Constants.CP_MINIMUM, subprop);
- }
-
- // Based on max-[width|height]
- wmcorr = propertyList.wmMap(extraCorresponding[1][0],
- extraCorresponding[1][1],
- extraCorresponding[1][2]);
- subprop = propertyList.getExplicitOrShorthand(wmcorr);
- // TODO: Don't set when NONE.
- if (subprop != null) {
- baseMaker.setSubprop(p, Constants.CP_MAXIMUM, subprop);
- }
-
- return p;
- }
-}
package org.apache.fop.fo;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.properties.PropertyMaker;
/**
* Superclass for properties that wrap an enumeration value
/**
* Inner class for creating EnumProperty instances
*/
- public static class Maker extends Property.Maker {
+ public static class Maker extends PropertyMaker {
/**
* @param propName name of property for which a Maker should be created
import org.apache.fop.datatypes.ColorType;
import org.apache.fop.datatypes.LengthBase;
import org.apache.fop.datatypes.ToBeImplementedProperty;
+import org.apache.fop.fo.properties.CorrespondingPropertyMaker;
+import org.apache.fop.fo.properties.DimensionPropertyMaker;
+import org.apache.fop.fo.properties.IndentPropertyMaker;
+import org.apache.fop.fo.properties.LineHeightPropertyMaker;
+import org.apache.fop.fo.properties.PropertyMaker;
/**
* This class creates and returns an array of Property.Maker instances
private static Map s_htSubPropNames = new HashMap();
private static Map s_htPropIds = new HashMap();
- private static Property.Maker[] s_generics =
- new Property.Maker[PROPERTY_COUNT + 1];
+ private static PropertyMaker[] s_generics =
+ new PropertyMaker[PROPERTY_COUNT + 1];
// The rest is only used during the building of the s_generics array.
private Property[] enums = null;
- private Property.Maker genericColor = null;
- private Property.Maker genericBoolean = null;
- private Property.Maker genericKeep = null;
- private Property.Maker genericCondLength = null;
- private Property.Maker genericCondPadding = null;
- private Property.Maker genericPadding = null;
- private Property.Maker genericCondBorderWidth = null;
- private Property.Maker genericBorderWidth = null;
- private Property.Maker genericBorderStyle = null;
- private Property.Maker genericBreak = null;
- private Property.Maker genericSpace = null;
+ private PropertyMaker genericColor = null;
+ private PropertyMaker genericBoolean = null;
+ private PropertyMaker genericKeep = null;
+ private PropertyMaker genericCondLength = null;
+ private PropertyMaker genericCondPadding = null;
+ private PropertyMaker genericPadding = null;
+ private PropertyMaker genericCondBorderWidth = null;
+ private PropertyMaker genericBorderWidth = null;
+ private PropertyMaker genericBorderStyle = null;
+ private PropertyMaker genericBreak = null;
+ private PropertyMaker genericSpace = null;
/**
* Create the generic property maker templates. These templates
* are used be the actual makers as a parameter to .useGeneric(...).
*/
public void createGenerics() {
- Property.Maker sub;
+ PropertyMaker sub;
genericColor = new ColorTypeProperty.Maker(0);
genericColor.addKeyword("aliceblue", "#f0f8ff");
* @param name the name of the property maker.
* @param maker the maker.
*/
- private static void addPropertyMaker(String name, Property.Maker maker) {
+ private static void addPropertyMaker(String name, PropertyMaker maker) {
s_generics[maker.getPropId()] = maker;
s_htPropNames.put(name, new Integer(maker.getPropId()));
s_htPropIds.put(new Integer(maker.getPropId()), name);
* Return the array of Makers.
* @return the maker array.
*/
- public static Property.Maker[] getGenericMappings() {
+ public static PropertyMaker[] getGenericMappings() {
FOPropertyMapping gp = new FOPropertyMapping();
// Create the shorthand first, they are referenced by the real properties.
gp.createShorthandProperties();
}
private void createAccessibilityProperties() {
- Property.Maker m;
+ PropertyMaker m;
// source-document
m = new StringProperty.Maker(PR_SOURCE_DOCUMENT);
}
private void createAbsolutePositionProperties() {
- Property.Maker m;
+ PropertyMaker m;
LengthProperty.Maker l;
// absolute-position
}
private void createAuralProperties() {
- Property.Maker m;
+ PropertyMaker m;
// azimuth
m = new ToBeImplementedProperty.Maker(PR_AZIMUTH);
}
private void createBorderPaddingBackgroundProperties() {
- Property.Maker m;
+ PropertyMaker m;
BorderWidthPropertyMaker bwm;
CorrespondingPropertyMaker corr;
}
private void createFontProperties() {
- Property.Maker m;
+ PropertyMaker m;
// font-family
m = new StringProperty.Maker(PR_FONT_FAMILY);
}
private void createHyphenationProperties() {
- Property.Maker m;
+ PropertyMaker m;
// country
m = new StringProperty.Maker(PR_COUNTRY);
}
private void createMarginBlockProperties() {
- Property.Maker m;
+ PropertyMaker m;
CorrespondingPropertyMaker corr;
// margin-top
}
private void createMarginInlineProperties() {
- Property.Maker m;
+ PropertyMaker m;
// space-end
m = new SpaceProperty.Maker(PR_SPACE_END);
}
private void createRelativePosProperties() {
- Property.Maker m;
+ PropertyMaker m;
// relative-position
m = new ToBeImplementedProperty.Maker(PR_RELATIVE_POSITION);
}
private void createAreaAlignmentProperties() {
- Property.Maker m;
+ PropertyMaker m;
// alignment-adjust
m = new ToBeImplementedProperty.Maker(PR_ALIGNMENT_ADJUST);
}
private void createAreaDimensionProperties() {
- Property.Maker m;
+ PropertyMaker m;
LengthProperty.Maker l;
DimensionPropertyMaker pdim;
CorrespondingPropertyMaker corr;
}
private void createBlockAndLineProperties() {
- Property.Maker m;
+ PropertyMaker m;
// hyphenation-keep
m = new ToBeImplementedProperty.Maker(PR_HYPHENATION_KEEP);
}
private void createCharacterProperties() {
- Property.Maker m;
+ PropertyMaker m;
// character
m = new CharacterProperty.Maker(PR_CHARACTER);
}
private void createColorProperties() {
- Property.Maker m;
+ PropertyMaker m;
// color
m = new ColorTypeProperty.Maker(PR_COLOR);
}
private void createFloatProperties() {
- Property.Maker m;
+ PropertyMaker m;
// clear
m = new ToBeImplementedProperty.Maker(PR_CLEAR);
}
private void createKeepsAndBreaksProperties() {
- Property.Maker m;
+ PropertyMaker m;
// break-after
m = new EnumProperty.Maker(PR_BREAK_AFTER);
}
private void createLayoutProperties() {
- Property.Maker m;
+ PropertyMaker m;
// clip
m = new ToBeImplementedProperty.Maker(PR_CLIP);
}
private void createLeaderAndRuleProperties() {
- Property.Maker m;
- Property.Maker sub;
+ PropertyMaker m;
+ PropertyMaker sub;
// leader-alignment
m = new EnumProperty.Maker(PR_LEADER_ALIGNMENT);
}
private void createDynamicProperties() {
- Property.Maker m;
+ PropertyMaker m;
// active-state
m = new ToBeImplementedProperty.Maker(PR_ACTIVE_STATE);
}
private void createMarkersProperties() {
- Property.Maker m;
+ PropertyMaker m;
// marker-class-name
m = new StringProperty.Maker(PR_MARKER_CLASS_NAME);
}
private void createNumberToStringProperties() {
- Property.Maker m;
+ PropertyMaker m;
// format
m = new StringProperty.Maker(PR_FORMAT);
}
private void createPaginationAndLayoutProperties() {
- Property.Maker m;
+ PropertyMaker m;
LengthProperty.Maker l;
// blank-or-not-blank
}
private void createTableProperties() {
- Property.Maker m;
- Property.Maker sub;
+ PropertyMaker m;
+ PropertyMaker sub;
// border-after-precedence
m = new ToBeImplementedProperty.Maker(PR_BORDER_AFTER_PRECEDENCE);
}
private void createWritingModeProperties() {
- Property.Maker m;
+ PropertyMaker m;
// direction
m = new ToBeImplementedProperty.Maker(PR_DIRECTION);
}
private void createMiscProperties() {
- Property.Maker m;
+ PropertyMaker m;
// content-type
m = new ToBeImplementedProperty.Maker(PR_CONTENT_TYPE);
}
private void createShorthandProperties() {
- Property.Maker m;
+ PropertyMaker m;
// background
m = new ToBeImplementedProperty.Maker(PR_BACKGROUND);
import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.flow.Marker;
+import org.apache.fop.fo.properties.PropertyMaker;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
*/
public class FObj extends FONode implements Constants {
private static final String FO_URI = "http://www.w3.org/1999/XSL/Format";
- public static Property.Maker[] propertyListTable = null;
+ public static PropertyMaker[] propertyListTable = null;
/**
* Formatting properties for this fo element.
super(parent);
if (propertyListTable == null) {
- propertyListTable = new Property.Maker[Constants.PROPERTY_COUNT+1];
- Property.Maker[] list = FOPropertyMapping.getGenericMappings();
+ propertyListTable = new PropertyMaker[Constants.PROPERTY_COUNT+1];
+ PropertyMaker[] list = FOPropertyMapping.getGenericMappings();
for (int i = 1; i < list.length; i++) {
if (list[i] != null)
propertyListTable[i] = list[i];
import java.util.Enumeration;
+import org.apache.fop.fo.properties.PropertyMaker;
+
public class GenericShorthandParser implements ShorthandParser {
/**
// Used for: border, border-top, border-right etc
public Property getValueForProperty(int propId,
ListProperty listProperty,
- Property.Maker maker,
+ PropertyMaker maker,
PropertyList propertyList) {
Property prop = null;
// Check for keyword "inherit"
*/
protected Property convertValueForProperty(int propId,
ListProperty listProperty,
- Property.Maker maker,
+ PropertyMaker maker,
PropertyList propertyList) {
Property prop = null;
// Try each of the stored values in turn
+++ /dev/null
-/*
- * $Id$
- * ============================================================================
- * The Apache Software License, Version 1.1
- * ============================================================================
- *
- * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modifica-
- * tion, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. The end-user documentation included with the redistribution, if any, must
- * include the following acknowledgment: "This product includes software
- * developed by the Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself, if
- * and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "FOP" and "Apache Software Foundation" must not be used to
- * endorse or promote products derived from this software without prior
- * written permission. For written permission, please contact
- * apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache", nor may
- * "Apache" appear in their name, without prior written permission of the
- * Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * ============================================================================
- *
- * This software consists of voluntary contributions made by many individuals
- * on behalf of the Apache Software Foundation and was originally created by
- * James Tauber <jtauber@jtauber.com>. For more information on the Apache
- * Software Foundation, please see <http://www.apache.org/>.
- */
-package org.apache.fop.fo;
-
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.datatypes.FixedLength;
-import org.apache.fop.fo.expr.Numeric;
-
-/**
- * This property maker handles the calculations described in 5.3.2 which
- * involves the sizes of the corresponding margin-* properties and the
- * padding-* and border-*-width properties.
- */
-public class IndentPropertyMaker extends CorrespondingPropertyMaker {
- /**
- * The corresponding padding-* propIds
- */
- private int[] paddingCorresponding = null;
-
- /**
- * The corresponding border-*-width propIds
- */
- private int[] borderWidthCorresponding = null;
-
- /**
- * Create a start-indent or end-indent property maker.
- * @param baseMaker
- */
- public IndentPropertyMaker(Property.Maker baseMaker) {
- super(baseMaker);
- }
-
- /**
- * Set the corresponding values for the padding-* properties.
- * @param paddingCorresponding the corresping propids.
- */
- public void setPaddingCorresponding(int[] paddingCorresponding) {
- this.paddingCorresponding = paddingCorresponding;
- }
-
- /**
- * Set the corresponding values for the border-*-width properties.
- * @param borderWidthCorresponding the corresping propids.
- */
- public void setBorderWidthCorresponding(int[] borderWidthCorresponding) {
- this.borderWidthCorresponding = borderWidthCorresponding;
- }
-
- /**
- * Calculate the corresponding value for start-indent and end-indent.
- * @see CorrespondingPropertyMaker#compute(PropertyList)
- */
- public Property compute(PropertyList propertyList) throws FOPException {
- // TODO: bckfnn reenable
- if (propertyList.getExplicitOrShorthand(propertyList.wmMap(lr_tb, rl_tb, tb_rl)) == null) {
- return null;
- }
- // Calculate the values as described in 5.3.2.
- try {
- Numeric v = new Numeric(new FixedLength(0));
- /*
- if (!propertyList.getFObj().generatesInlineAreas()) {
- String propName = FOPropertyMapping.getPropertyName(this.propId);
- v = v.add(propertyList.getInherited(propName).getNumeric());
- }
- */
- v = v.add(propertyList.get(propertyList.wmMap(lr_tb, rl_tb, tb_rl)).getNumeric());
- v = v.add(getCorresponding(paddingCorresponding, propertyList).getNumeric());
- v = v.add(getCorresponding(borderWidthCorresponding, propertyList).getNumeric());
- return new LengthProperty(v.asLength());
- } catch (org.apache.fop.fo.expr.PropertyException propEx) {
- String propName = FOPropertyMapping.getPropertyName(baseMaker.getPropId());
- throw new FOPException("Error in " + propName
- + " calculation " + propEx);
- }
- }
-
- private Property getCorresponding(int[] corresponding, PropertyList propertyList) {
- int wmcorr = propertyList.wmMap(corresponding[0], corresponding[1], corresponding[2]);
- return propertyList.get(wmcorr);
- }
-}
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.Keep;
+import org.apache.fop.fo.properties.CompoundPropertyMaker;
/**
* Superclass for properties that wrap Keep values
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.LengthPair;
+import org.apache.fop.fo.properties.CompoundPropertyMaker;
/**
* Superclass for properties wrapping a LengthPair value
import org.apache.fop.datatypes.Length;
import org.apache.fop.datatypes.AutoLength;
import org.apache.fop.fo.expr.Numeric;
+import org.apache.fop.fo.properties.PropertyMaker;
import org.apache.fop.apps.FOPException;
/**
/**
* Inner class for making instances of LengthProperty
*/
- public static class Maker extends Property.Maker {
+ public static class Maker extends PropertyMaker {
private boolean autoOk = false;
/**
package org.apache.fop.fo;
import org.apache.fop.datatypes.LengthRange;
+import org.apache.fop.fo.properties.CompoundPropertyMaker;
import org.apache.fop.apps.FOPException;
/**
+++ /dev/null
-/*
- * $Id$
- * ============================================================================
- * The Apache Software License, Version 1.1
- * ============================================================================
- *
- * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modifica-
- * tion, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. The end-user documentation included with the redistribution, if any, must
- * include the following acknowledgment: "This product includes software
- * developed by the Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself, if
- * and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "FOP" and "Apache Software Foundation" must not be used to
- * endorse or promote products derived from this software without prior
- * written permission. For written permission, please contact
- * apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache", nor may
- * "Apache" appear in their name, without prior written permission of the
- * Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * ============================================================================
- *
- * This software consists of voluntary contributions made by many individuals
- * on behalf of the Apache Software Foundation and was originally created by
- * James Tauber <jtauber@jtauber.com>. For more information on the Apache
- * Software Foundation, please see <http://www.apache.org/>.
- */
-package org.apache.fop.fo;
-
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.datatypes.PercentLength;
-
-/**
- * A maker which calculates the line-height property.
- * This property maker is special because line-height inherit the specified
- * value, instead of the computed value.
- * So when a line-height is create based on a attribute, the specified value
- * is stored in the property and in compute() the stored specified value of
- * the nearest specified is used to recalculate the line-height.
- */
-
-public class LineHeightPropertyMaker extends LengthProperty.Maker {
- /**
- * Create a maker for line-height.
- * @param propId the is for linehight.
- */
- public LineHeightPropertyMaker(int propId) {
- super(propId);
- }
-
- /**
- * Make a property as normal, and save the specified value.
- * @see Property.Maker#make(PropertyList, String, FObj)
- */
- public Property make(PropertyList propertyList, String value,
- FObj fo) throws FOPException {
- Property p = super.make(propertyList, value, fo);
- p.setSpecifiedValue(checkValueKeywords(value));
- return p;
- }
-
- /**
- * Recalculate the line-height value based on the nearest specified
- * value.
- * @see Property.Maker#compute(PropertyList)
- */
- protected Property compute(PropertyList propertyList) throws FOPException {
- // recalculate based on last specified value
- // Climb up propertylist and find last spec'd value
- Property specProp = propertyList.getNearestSpecified(propId);
- if (specProp != null) {
- String specVal = specProp.getSpecifiedValue();
- if (specVal != null) {
- try {
- return make(propertyList, specVal,
- propertyList.getParentFObj());
- } catch (FOPException e) {
- //getLogger()error("Error computing property value for "
- // + propName + " from "
- // + specVal);
- return null;
- }
- }
- }
- return null;
- }
-
- protected Property convertPropertyDatatype(Property p,
- PropertyList propertyList,
- FObj fo) {
- Number numval = p.getNumber();
- if (numval != null) {
- return new LengthProperty(
- new PercentLength(numval.doubleValue(), getPercentBase(fo,propertyList)));
- }
- return super.convertPropertyDatatype(p, propertyList, fo);
- }
-}
import java.util.Vector;
+import org.apache.fop.fo.properties.PropertyMaker;
+
/**
* Superclass for properties that are lists of other properties
*/
/**
* Inner class for creating instances of ListProperty
*/
- public static class Maker extends Property.Maker {
+ public static class Maker extends PropertyMaker {
/**
* @param name name of property for which Maker should be created
import org.apache.fop.datatypes.ColorType;
import org.apache.fop.fo.expr.Numeric;
+import org.apache.fop.fo.properties.PropertyMaker;
/**
* Class for handling numeric properties
/**
* Inner class for making NumberProperty objects
*/
- public static class Maker extends Property.Maker {
+ public static class Maker extends PropertyMaker {
/**
* Constructor for NumberProperty.Maker
import org.apache.fop.datatypes.ColorType;
import org.apache.fop.datatypes.CondLength;
-import org.apache.fop.datatypes.CompoundDatatype;
import org.apache.fop.datatypes.Keep;
import org.apache.fop.datatypes.Length;
import org.apache.fop.datatypes.LengthPair;
import org.apache.fop.datatypes.LengthRange;
-import org.apache.fop.datatypes.PercentBase;
-import org.apache.fop.datatypes.LengthBase;
import org.apache.fop.datatypes.Space;
import org.apache.fop.fo.expr.Numeric;
-import org.apache.fop.fo.expr.PropertyParser;
-import org.apache.fop.fo.expr.PropertyInfo;
-import org.apache.fop.apps.FOPException;
import java.util.Vector;
-import java.util.HashMap;
-import java.util.Map;
/**
* Base class for all property objects
*/
public class Property {
- /**
- * Base class for all property makers
- * @author unascribed
- */
- public static class Maker implements Cloneable {
- protected int propId;
- private boolean inherited = true;
- private Map enums = null;
- private Map keywords = null;
- protected String defaultValue = null;
- protected boolean contextDep = false;
- protected boolean setByShorthand = false;
- private int percentBase = -1;
- private Property.Maker[] shorthands = null;
- private ShorthandParser datatypeParser;
-
- protected Property defaultProperty;
- protected CorrespondingPropertyMaker corresponding;
-
- /**
- * @return the name of the property for this Maker
- */
- protected int getPropId() {
- return propId;
- }
-
- /**
- * Construct an instance of a Property.Maker for the given property.
- * @param propId The Constant ID of the property to be made.
- */
- public Maker(int propId) {
- this.propId = propId;
- }
-
- /**
- * Copy all the values from the generic maker to this maker.
- * @param generic a generic property maker.
- */
- public void useGeneric(Property.Maker generic) {
- contextDep = generic.contextDep;
- inherited = generic.inherited;
- defaultValue = generic.defaultValue;
- percentBase = generic.percentBase;
- if (generic.shorthands != null) {
- shorthands = new Property.Maker[generic.shorthands.length];
- System.arraycopy(shorthands, 0, generic.shorthands, 0, shorthands.length);
- }
- if (generic.enums != null) {
- enums = new HashMap(generic.enums);
- }
- if (generic.keywords != null) {
- keywords = new HashMap(generic.keywords);
- }
- }
-
- /**
- * Set the inherited flag.
- * @param inherited
- */
- public void setInherited(boolean inherited) {
- this.inherited = inherited;
- }
-
- /**
- * Add a keyword-equiv to the maker.
- * @param keyword
- * @param value
- */
- public void addKeyword(String keyword, String value) {
- if (keywords == null) {
- keywords = new HashMap();
- }
- keywords.put(keyword, value);
- }
-
- /**
- * Add a enum constant.
- * @param constant
- * @param value
- */
- public void addEnum(String constant, Property value) {
- if (enums == null) {
- enums = new HashMap();
- }
- enums.put(constant, value);
- }
-
- /**
- * Add a subproperty to this maker.
- * @param subproperty
- */
- public void addSubpropMaker(Property.Maker subproperty) {
- throw new RuntimeException("Unable to add subproperties " + getClass());
- }
-
- /**
- * Return a subproperty maker for the subpropId.
- * @param subpropId The subpropId of the maker.
- * @return The subproperty maker.
- */
- public Property.Maker getSubpropMaker(int subpropId) {
- throw new RuntimeException("Unable to add subproperties");
- }
-
- /**
- * Add a shorthand to this maker. Only an Integer is added to the
- * shorthands list. Later the Integers are replaced with references
- * to the actual shorthand property makers.
- * @param shorthand a property maker thar is that is checked for
- * shorthand values.
- */
- public void addShorthand(Property.Maker shorthand) {
- if (shorthands == null) {
- shorthands = new Property.Maker[3];
- }
- for (int i = 0; i < shorthands.length; i++) {
- if (shorthands[i] == null) {
- shorthands[i] = shorthand;
- break;
- }
- }
- }
-
- /**
- * Set the shorthand datatype parser.
- * @param subproperty
- */
- public void setDatatypeParser(ShorthandParser parser) {
- datatypeParser = parser;
- }
-
- /**
- * Set the default value for this maker.
- * @param defaultValue the default value.
- */
- public void setDefault(String defaultValue) {
- this.defaultValue = defaultValue;
- }
-
- /**
- * Set the default value for this maker.
- * @param defaultValue
- * @param contextDep true when the value context dependent and
- * must not be cached.
- */
- public void setDefault(String defaultValue, boolean contextDep) {
- this.defaultValue = defaultValue;
- this.contextDep = contextDep;
- }
-
- /**
- * Set the percent base identifier for this maker.
- * @param percentBase
- */
- public void setPercentBase(int percentBase) {
- this.percentBase = percentBase;
- }
-
- /**
- * Set the byShorthand flag which only is applicable for subproperty
- * makers. It should be true for the subproperties which must be
- * assigned a value when the base property is assigned a attribute
- * value directly.
- * @param defaultValue
- */
- public void setByShorthand(boolean setByShorthand) {
- this.setByShorthand = setByShorthand;
- }
-
- /**
- * Set the correspoding property information.
- * @param corresponding a corresponding maker where the
- * isForcedCorresponding and compute methods are delegated to.
- */
- public void setCorresponding(CorrespondingPropertyMaker corresponding) {
- this.corresponding = corresponding;
- }
-
- /**
- * Create a new empty property. Must be overriden in compound
- * subclasses.
- * @return a new instance of the Property for which this is a maker.
- */
- public Property makeNewProperty() {
- return null;
- }
-
- /*
- * If the property is a relative property with a corresponding absolute
- * value specified, the absolute value is used. This is also true of
- * the inheritance priority (I think...)
- * If the property is an "absolute" property and it isn't specified, then
- * we try to compute it from the corresponding relative property: this
- * happens in computeProperty.
- */
- protected Property findProperty(PropertyList propertyList,
- boolean bTryInherit)
- throws FOPException
- {
- Property p = null;
-
- if (corresponding != null && corresponding.isCorrespondingForced(propertyList)) {
- p = corresponding.compute(propertyList);
- } else {
- p = propertyList.getExplicitBaseProp(propId);
- if (p == null) {
- p = this.compute(propertyList);
- }
- if (p == null) { // check for shorthand specification
- p = getShorthand(propertyList);
- }
- if (p == null && bTryInherit) {
- // else inherit (if has parent and is inheritable)
- PropertyList parentPropertyList = propertyList.getParentPropertyList();
- if (parentPropertyList != null && isInherited()) {
- p = findProperty(parentPropertyList, true);
- }
- }
- }
- return p;
- }
-
- /**
- * Return the property on the current FlowObject. Depending on the passed flags,
- * this will try to compute it based on other properties, or if it is
- * inheritable, to return the inherited value. If all else fails, it returns
- * the default value.
- * @param subpropId The subproperty id of the property being retrieved.
- * Is 0 when retriving a base property.
- * @param propertylist The PropertyList object being built for this FO.
- * @param bTryInherit true if inherited properties should be examined.
- * @param bTryDefault true if the default value should be returned.
- */
- public Property get(int subpropId, PropertyList propertyList,
- boolean bTryInherit, boolean bTryDefault)
- throws FOPException
- {
- Property p = findProperty(propertyList, bTryInherit);
- if (p == null && bTryDefault) { // default value for this FO!
- try {
- p = make(propertyList);
- } catch (FOPException e) {
- // don't know what to do here
- }
- }
- return p;
- }
-
- /**
- * Default implementation of isInherited.
- * @return A boolean indicating whether this property is inherited.
- */
- public boolean isInherited() {
- return inherited;
- }
-
- /**
- * This is used to handle properties specified as a percentage of
- * some "base length", such as the content width of their containing
- * box.
- * Overridden by subclasses which allow percent specifications. See
- * the documentation on properties.xsl for details.
- * @param fo the FObj containing the PercentBase
- * @param pl the PropertyList containing the property. (TODO: explain
- * what this is used for, or remove it from the signature.)
- * @return an object implementing the PercentBase interface.
- */
- public PercentBase getPercentBase(FObj fo, PropertyList pl) {
- if (percentBase == -1)
- return null;
- return new LengthBase(fo, pl, percentBase);
- }
-
- /**
- * Return a property value for the given component of a compound
- * property.
- * @param p A property value for a compound property type such as
- * SpaceProperty.
- * @param subprop The Constants ID of the component whose value is to be
- * returned.
- * NOTE: this is only to ease porting when calls are made to
- * PropertyList.get() using a component name of a compound property,
- * such as get("space.optimum"). The recommended technique is:
- * get("space").getOptimum().
- * Overridden by property maker subclasses which handle
- * compound properties.
- * @return the Property containing the subproperty
- */
- public Property getSubprop(Property p, int subpropId) {
- CompoundDatatype val = (CompoundDatatype) p.getObject();
- return val.getComponent(subpropId);
- }
-
- /**
- * Set a component in a compound property and return the modified
- * compound property object.
- * This default implementation returns the original base property
- * without modifying it.
- * It is overridden by property maker subclasses which handle
- * compound properties.
- * @param baseProp The Property object representing the compound property,
- * such as SpaceProperty.
- * @param partId The ID of the component whose value is specified.
- * @param subProp A Property object holding the specified value of the
- * component to be set.
- * @return The modified compound property object.
- */
- protected Property setSubprop(Property baseProp, int partId,
- Property subProp) {
- CompoundDatatype val = (CompoundDatatype) baseProp.getObject();
- val.setComponent(partId, subProp, false);
- return baseProp;
- }
-
- /**
- * Return the default value.
- * @param propertyList The PropertyList object being built for this FO.
- * @return the Property object corresponding to the parameters
- * @throws FOPException for invalid or inconsisten FO input
- */
- public Property make(PropertyList propertyList) throws FOPException {
- if (defaultProperty != null) {
- return defaultProperty;
- }
- Property p = make(propertyList, defaultValue, propertyList.getParentFObj());
- if (!contextDep) {
- defaultProperty = p;
- }
- return p;
- }
-
- /**
- * Create a Property object from an attribute specification.
- * @param propertyList The PropertyList object being built for this FO.
- * @param value The attribute value.
- * @param fo The current FO whose properties are being set.
- * @return The initialized Property object.
- * @throws FOPException for invalid or inconsistent FO input
- */
- public Property make(PropertyList propertyList, String value,
- FObj fo) throws FOPException {
- try {
- Property newProp = null;
- String pvalue = value;
- if ("inherit".equals(value)) {
- newProp = propertyList.getFromParent(this.propId);
- } else {
- newProp = checkEnumValues(value);
- }
- if (newProp == null) {
- /* Check for keyword shorthand values to be substituted. */
- pvalue = checkValueKeywords(value);
- // Override parsePropertyValue in each subclass of Property.Maker
- Property p = PropertyParser.parse(pvalue,
- new PropertyInfo(this,
- propertyList, fo));
- newProp = convertProperty(p, propertyList, fo);
- }
- if (newProp == null) {
- throw new org.apache.fop.fo.expr.PropertyException("No conversion defined");
- }
- return newProp;
- } catch (org.apache.fop.fo.expr.PropertyException propEx) {
- String propName = FOPropertyMapping.getPropertyName(this.propId);
- throw new FOPException("Error in " + propName
- + " property value '" + value + "': "
- + propEx);
- }
- }
-
- /**
- * Make a property value for a compound property. If the property
- * value is already partially initialized, this method will modify it.
- * @param baseProp The Property object representing the compound property,
- * for example: SpaceProperty.
- * @param subpropId The Constants ID of the subproperty (component)
- * whose value is specified.
- * @param propertyList The propertyList being built.
- * @param fo The FO whose properties are being set.
- * @param value the value of the
- * @return baseProp (or if null, a new compound property object) with
- * the new subproperty added
- * @throws FOPException for invalid or inconsistent FO input
- */
- public Property make(Property baseProp, int subpropId,
- PropertyList propertyList, String value,
- FObj fo) throws FOPException {
- //getLogger().error("compound property component "
- // + partName + " unknown.");
- return baseProp;
- }
-
- public Property convertShorthandProperty(PropertyList propertyList,
- Property prop, FObj fo) {
- Property pret = null;
- try {
- pret = convertProperty(prop, propertyList, fo);
- if (pret == null) {
- // If value is a name token, may be keyword or Enum
- String sval = prop.getNCname();
- if (sval != null) {
- // System.err.println("Convert shorthand ncname " + sval);
- pret = checkEnumValues(sval);
- if (pret == null) {
- /* Check for keyword shorthand values to be substituted. */
- String pvalue = checkValueKeywords(sval);
- if (!pvalue.equals(sval)) {
- // System.err.println("Convert shorthand keyword" + pvalue);
- // Substituted a value: must parse it
- Property p =
- PropertyParser.parse(pvalue,
- new PropertyInfo(this,
- propertyList,
- fo));
- pret = convertProperty(p, propertyList, fo);
- }
- }
- }
- }
- } catch (FOPException e) {
-
- //getLogger().error("convertShorthandProperty caught FOPException "
- // + e);
- } catch (org.apache.fop.fo.expr.PropertyException propEx) {
- //getLogger().error("convertShorthandProperty caught PropertyException "
- // + propEx);
- }
- if (pret != null) {
- /*
- * System.err.println("Return shorthand value " + pret.getString() +
- * " for " + getPropName());
- */
- }
- return pret;
- }
-
- /**
- * For properties that contain enumerated values.
- * This method should be overridden by subclasses.
- * @param value the string containing the property value
- * @return the Property encapsulating the enumerated equivalent of the
- * input value
- */
- protected Property checkEnumValues(String value) {
- if (enums != null) {
- return (Property) enums.get(value);
- }
- return null;
- }
-
- /**
- * Return a String to be parsed if the passed value corresponds to
- * a keyword which can be parsed and used to initialize the property.
- * For example, the border-width family of properties can have the
- * initializers "thin", "medium", or "thick". The FOPropertyMapping
- * file specifies a length value equivalent for these keywords,
- * such as "0.5pt" for "thin".
- * @param value The string value of property attribute.
- * @return A String containging a parseable equivalent or null if
- * the passed value isn't a keyword initializer for this Property.
- */
- protected String checkValueKeywords(String keyword) {
- if (keywords != null) {
- String value = (String)keywords.get(keyword);
- if (value != null) {
- return value;
- }
- }
- return keyword;
- }
-
- /**
- * Return a Property object based on the passed Property object.
- * This method is called if the Property object built by the parser
- * isn't the right type for this property.
- * It is overridden by subclasses.
- * @param p The Property object return by the expression parser
- * @param propertyList The PropertyList object being built for this FO.
- * @param fo The current FO whose properties are being set.
- * @return A Property of the correct type or null if the parsed value
- * can't be converted to the correct type.
- * @throws FOPException for invalid or inconsistent FO input
- */
- protected Property convertProperty(Property p,
- PropertyList propertyList,
- FObj fo) throws FOPException {
- return null;
- }
-
- /**
- * For properties that have more than one legal way to be specified,
- * this routine should be overridden to attempt to set them based upon
- * the other methods. For example, colors may be specified using an RGB
- * model, or they may be specified using an NCname.
- * @param p property whose datatype should be converted
- * @param propertyList collection of properties. (TODO: explain why
- * this is needed, or remove it from the signature.)
- * @param fo the FObj to which this property is attached. (TODO: explain
- * why this is needed, or remove it from the signature).
- * @return an Property with the appropriate datatype used
- */
- protected Property convertPropertyDatatype(Property p,
- PropertyList propertyList,
- FObj fo) {
- return null;
- }
-
- /**
- * Return a Property object representing the value of this property,
- * based on other property values for this FO.
- * A special case is properties which inherit the specified value,
- * rather than the computed value.
- * @param propertyList The PropertyList for the FO.
- * @return Property A computed Property value or null if no rules
- * are specified to compute the value.
- * @throws FOPException for invalid or inconsistent FO input
- */
- protected Property compute(PropertyList propertyList)
- throws FOPException {
- if (corresponding != null) {
- return corresponding.compute(propertyList);
- }
- return null; // standard
- }
-
- /**
- * For properties that can be set by shorthand properties, this method
- * should return the Property, if any, that is parsed from any
- * shorthand properties that affect this property.
- * This method expects to be overridden by subclasses.
- * For example, the border-right-width property could be set implicitly
- * from the border shorthand property, the border-width shorthand
- * property, or the border-right shorthand property. This method should
- * be overridden in the appropriate subclass to check each of these, and
- * return an appropriate border-right-width Property object.
- * @param propertyList the collection of properties to be considered
- * @return the Property, if found, the correspons, otherwise, null
- */
- protected Property getShorthand(PropertyList propertyList) {
- if (shorthands == null) {
- return null;
- }
- ListProperty listprop;
- int n = shorthands.length;
- for (int i = 0; i < n && shorthands[i] != null; i++) {
- Property.Maker shorthand = shorthands[i];
- listprop = (ListProperty)propertyList.getExplicit(shorthand.propId);
- if (listprop != null) {
- ShorthandParser parser = shorthand.datatypeParser;
- Property p = parser.getValueForProperty(getPropId(),
- listprop, this, propertyList);
- if (p != null) {
- return p;
- }
- }
- }
- return null;
- }
-
- /**
- * Return a clone of the makers. Used by useGeneric() to clone the
- * subproperty makers of the generic compound makers.
- */
- public Object clone() {
- try {
- return super.clone();
- } catch (CloneNotSupportedException exc) {
- return null;
- }
- }
- } // end of nested Maker class
-
/**
* The original specified value for properties which inherit
* specified values.
// FOP
import org.apache.fop.apps.FOPException;
-import org.apache.fop.fo.Property.Maker;
+import org.apache.fop.fo.properties.PropertyMaker;
/**
* Class containing the collection of properties for a given FObj.
private Property get(int propId, boolean bTryInherit,
boolean bTryDefault) {
- Property.Maker propertyMaker = findMaker(propId & Constants.PROPERTY_MASK);
+ PropertyMaker propertyMaker = findMaker(propId & Constants.PROPERTY_MASK);
try {
return propertyMaker.get(propId & Constants.COMPOUND_MASK, this,
bTryInherit, bTryDefault);
String attributeName,
String attributeValue) {
- Property.Maker propertyMaker = null;
+ PropertyMaker propertyMaker = null;
FObj parentFO = fobj.findNearestAncestorFObj();
/* Handle "compound" properties, ex. space-before.minimum */
private Property findBaseProperty(Attributes attributes,
FObj parentFO,
String basePropName,
- Maker propertyMaker)
+ PropertyMaker propertyMaker)
throws FOPException {
/* If the baseProperty has already been created, return it
*/
private Property getSubpropValue(Property p, int propId) {
- Property.Maker maker = findMaker(propId & Constants.PROPERTY_MASK);
+ PropertyMaker maker = findMaker(propId & Constants.PROPERTY_MASK);
if (maker != null) {
return maker.getSubprop(p, propId & Constants.COMPOUND_MASK);
* @return new Property object
*/
private Property getShorthand(int propId) {
- Property.Maker propertyMaker = findMaker(propId);
+ PropertyMaker propertyMaker = findMaker(propId);
if (propertyMaker != null) {
return propertyMaker.getShorthand(this);
private Property makeProperty(int propId) throws FOPException {
Property p = null;
- Property.Maker propertyMaker = findMaker(propId);
+ PropertyMaker propertyMaker = findMaker(propId);
if (propertyMaker != null) {
p = propertyMaker.make(this);
private boolean isInherited(int propId) {
if (inheritableProperty == null) {
inheritableProperty = new boolean[Constants.PROPERTY_COUNT + 1];
- Property.Maker maker = null;
+ PropertyMaker maker = null;
for (int prop = 1; prop <= Constants.PROPERTY_COUNT; prop++) {
maker = findMaker(prop);
inheritableProperty[prop] = (maker != null && maker.isInherited());
* @param propId Id of property
* @return the Property.Maker for this property
*/
- private Property.Maker findMaker(int propId) {
+ private PropertyMaker findMaker(int propId) {
if (propId < 1 || propId > Constants.PROPERTY_COUNT) {
return null;
*/
package org.apache.fop.fo;
+import org.apache.fop.fo.properties.PropertyMaker;
+
/**
* Interface used to provide parsing capabilities to Properties with shorthand
* characteristics (those with multiple components).
*/
Property getValueForProperty(int propId,
ListProperty listProperty,
- Property.Maker maker,
+ PropertyMaker maker,
PropertyList propertyList);
}
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.LengthRange;
import org.apache.fop.datatypes.Space;
+import org.apache.fop.fo.properties.CompoundPropertyMaker;
/**
* Base class used for handling properties of the fo:space-before and
*/
package org.apache.fop.fo;
+import org.apache.fop.fo.properties.PropertyMaker;
+
/**
* Exists primarily as a container for its Maker inner class, which is
* extended by many string-based FO property classes.
/**
* Inner class for making instances of StringProperty
*/
- public static class Maker extends Property.Maker {
+ public static class Maker extends PropertyMaker {
/**
* @param propName name of property for which to create a Maker
import java.util.Stack;
import org.apache.fop.fo.Constants;
-import org.apache.fop.fo.Property;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.properties.PropertyMaker;
import org.apache.fop.datatypes.PercentBase;
* built, and the FObj parent of the FObj for which the property is being set.
*/
public class PropertyInfo {
- private Property.Maker maker;
+ private PropertyMaker maker;
private PropertyList plist;
private FObj fo;
private Stack stkFunction; // Stack of functions being evaluated
* @param plist PropertyList object
* @param fo FObj
*/
- public PropertyInfo(Property.Maker maker, PropertyList plist, FObj fo) {
+ public PropertyInfo(PropertyMaker maker, PropertyList plist, FObj fo) {
this.maker = maker;
this.plist = plist;
this.fo = fo;
--- /dev/null
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.fo.properties;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.datatypes.CompoundDatatype;
+import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.EnumProperty;
+import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.Property;
+import org.apache.fop.fo.PropertyList;
+
+/**
+ * @author me
+ *
+ * To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+/**
+ * This class extends Property.Maker with support for sub-properties.
+ */
+public class CompoundPropertyMaker extends PropertyMaker {
+ /**
+ * The list of subproperty makers supported by this compound maker.
+ */
+ private PropertyMaker[] subproperties =
+ new PropertyMaker[Constants.COMPOUND_COUNT];
+
+ /**
+ * The first subproperty maker which has a setByShorthand of true.
+ */
+ private PropertyMaker shorthandMaker = null;
+
+ /**
+ * Construct an instance of a CompoundPropertyMaker for the given property.
+ * @param propId The Constant ID of the property to be made.
+ */
+ public CompoundPropertyMaker(int propId) {
+ super(propId);
+ }
+
+ /**
+ * @see org.apache.fop.fo.Property.Maker#useGeneric(Property.Maker)
+ */
+ public void useGeneric(PropertyMaker generic) {
+ super.useGeneric(generic);
+ if (generic instanceof CompoundPropertyMaker) {
+ CompoundPropertyMaker compoundGeneric = (CompoundPropertyMaker) generic;
+ for (int i = 0; i < Constants.COMPOUND_COUNT; i++) {
+ PropertyMaker submaker = compoundGeneric.subproperties[i];
+ if (submaker != null) {
+ addSubpropMaker((PropertyMaker) submaker.clone());
+ }
+ }
+ }
+ }
+
+ /**
+ * Add a subproperty to this maker.
+ * @param subproperty
+ */
+ public void addSubpropMaker(PropertyMaker subproperty) {
+ // Place the base propId in the propId of the subproperty.
+ subproperty.propId &= Constants.COMPOUND_MASK;
+ subproperty.propId |= this.propId;
+
+ subproperties[getSubpropIndex(subproperty.getPropId())] = subproperty;
+
+ // Store the first subproperty with a setByShorthand. That subproperty
+ // will be used for converting a value set on the base property.
+ if (shorthandMaker == null && subproperty.setByShorthand) {
+ shorthandMaker = subproperty;
+ }
+ }
+
+
+ /**
+ * Return a Maker object which is used to set the values on components
+ * of compound property types, such as "space".
+ * Overridden by property maker subclasses which handle
+ * compound properties.
+ * @param subprop The Constants ID of the component for which a Maker is to
+ * returned, for example CP_OPTIMUM, if the FO attribute is
+ * space.optimum='10pt'.
+ * @return the Maker object specified
+ */
+ public PropertyMaker getSubpropMaker(int subpropId) {
+ return subproperties[getSubpropIndex(subpropId)];
+ }
+
+ /**
+ * Calculate the real value of a subproperty by unmasking and shifting
+ * the value into the range [0 - (COMPOUND_COUNT-1)].
+ * The value is used as index into the subproperties array.
+ * @param propId the property id of the sub property.
+ * @return the array index.
+ */
+ private int getSubpropIndex(int subpropId) {
+ return ((subpropId & Constants.COMPOUND_MASK) >>
+ Constants.COMPOUND_SHIFT)-1;
+ }
+
+ /**
+ * For compound properties which can take enumerate values.
+ * Delegate the enumeration check to one of the subpropeties.
+ * @param value the string containing the property value
+ * @return the Property encapsulating the enumerated equivalent of the
+ * input value
+ */
+ protected Property checkEnumValues(String value) {
+ if (shorthandMaker != null) {
+ return shorthandMaker.checkEnumValues(value);
+ }
+ return null;
+ }
+
+ /**
+ * Return the property on the current FlowObject. Depending on the passed flags,
+ * this will try to compute it based on other properties, or if it is
+ * inheritable, to return the inherited value. If all else fails, it returns
+ * the default value.
+ * @param subpropId The subproperty id of the property being retrieved.
+ * Is 0 when retriving a base property.
+ * @param propertylist The PropertyList object being built for this FO.
+ * @param bTryInherit true if inherited properties should be examined.
+ * @param bTryDefault true if the default value should be returned.
+ */
+ public Property get(int subpropId, PropertyList propertyList,
+ boolean bTryInherit, boolean bTryDefault)
+ throws FOPException
+ {
+ Property p = super.get(subpropId, propertyList, bTryInherit, bTryDefault);
+ if (subpropId != 0 && p != null) {
+ p = getSubprop(p, subpropId);
+ }
+ return p;
+ }
+
+ /**
+ * Return a Property object based on the passed Property object.
+ * This method is called if the Property object built by the parser
+ * isn't the right type for this compound property.
+ * @param p The Property object return by the expression parser
+ * @param propertyList The PropertyList object being built for this FO.
+ * @param fo The current FO whose properties are being set.
+ * @return A Property of the correct type or null if the parsed value
+ * can't be converted to the correct type.
+ * @throws FOPException for invalid or inconsistent FO input
+ */
+ protected Property convertProperty(Property p,
+ PropertyList propertyList,
+ FObj fo) throws FOPException {
+ if (!EnumProperty.class.isAssignableFrom(p.getClass())) {
+ // delegate to the subprop maker to do conversions
+ p = shorthandMaker.convertProperty(p, propertyList, fo);
+ }
+
+ if (p != null) {
+ Property prop = makeCompound(propertyList, fo);
+ CompoundDatatype pval = (CompoundDatatype) prop.getObject();
+ for (int i = 0; i < Constants.COMPOUND_COUNT; i++) {
+ PropertyMaker submaker = subproperties[i];
+ if (submaker != null && submaker.setByShorthand) {
+ pval.setComponent(submaker.getPropId() & Constants.COMPOUND_MASK, p, false);
+ }
+ }
+ return prop;
+ }
+ return null;
+ }
+
+ /**
+ * Make a compound property with default values.
+ * @param propertyList The PropertyList object being built for this FO.
+ * @return the Property object corresponding to the parameters
+ * @throws FOPException for invalid or inconsisten FO input
+ */
+ public Property make(PropertyList propertyList) throws FOPException {
+ return makeCompound(propertyList, propertyList.getParentFObj());
+ }
+
+ /**
+ * Create a Property object from an attribute specification.
+ * @param propertyList The PropertyList object being built for this FO.
+ * @param value The attribute value.
+ * @param fo The current FO whose properties are being set.
+ * @return The initialized Property object.
+ * @throws FOPException for invalid or inconsistent FO input
+ */
+ public Property make(PropertyList propertyList, String value,
+ FObj fo) throws FOPException {
+ Property p = super.make(propertyList, value, fo);
+ p = convertProperty(p, propertyList, fo);
+ return p;
+ }
+
+ /**
+ * Return a property value for a compound property. If the property
+ * value is already partially initialized, this method will modify it.
+ * @param baseProp The Property object representing the compound property,
+ * for example: SpaceProperty.
+ * @param subpropId The Constants ID of the subproperty (component)
+ * whose value is specified.
+ * @param propertyList The propertyList being built.
+ * @param fo The FO whose properties are being set.
+ * @param value the value of the
+ * @return baseProp (or if null, a new compound property object) with
+ * the new subproperty added
+ * @throws FOPException for invalid or inconsistent FO input
+ */
+ public Property make(Property baseProp, int subpropId,
+ PropertyList propertyList, String value,
+ FObj fo) throws FOPException {
+ if (baseProp == null) {
+ baseProp = makeCompound(propertyList, fo);
+ }
+
+ PropertyMaker spMaker = getSubpropMaker(subpropId);
+
+ if (spMaker != null) {
+ Property p = spMaker.make(propertyList, value, fo);
+ if (p != null) {
+ return setSubprop(baseProp, subpropId & Constants.COMPOUND_MASK, p);
+ }
+ } else {
+ //getLogger().error("compound property component "
+ // + partName + " unknown.");
+ }
+ return baseProp;
+ }
+
+ /**
+ * Create a empty compound property and fill it with default values for
+ * the subproperties.
+ * @param propertyList The propertyList being built.
+ * @param parentFO The parent FO for the FO whose property is being made.
+ * @return a Property subclass object holding a "compound" property object
+ * initialized to the default values for each component.
+ * @throws FOPException
+ */
+ protected Property makeCompound(PropertyList propertyList, FObj parentFO)
+ throws FOPException
+ {
+ Property p = makeNewProperty();
+ CompoundDatatype data = (CompoundDatatype) p.getObject();
+ for (int i = 0; i < Constants.COMPOUND_COUNT; i++) {
+ PropertyMaker submaker = subproperties[i];
+ if (submaker != null) {
+ Property subprop = submaker.make(propertyList, submaker.defaultValue, parentFO);
+ data.setComponent(submaker.getPropId() & Constants.COMPOUND_MASK, subprop, true);
+ }
+ }
+ return p;
+ }
+}
--- /dev/null
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.fo.properties;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.Property;
+import org.apache.fop.fo.PropertyList;
+
+/**
+ */
+public class CorrespondingPropertyMaker {
+ protected PropertyMaker baseMaker;
+ protected int lr_tb;
+ protected int rl_tb;
+ protected int tb_rl;
+ private boolean useParent;
+ private boolean relative;
+
+ public CorrespondingPropertyMaker(PropertyMaker baseMaker) {
+ this.baseMaker = baseMaker;
+ baseMaker.setCorresponding(this);
+ }
+
+
+ public void setCorresponding(int lr_tb, int rl_tb, int tb_rl) {
+ this.lr_tb = lr_tb;
+ this.rl_tb = rl_tb;
+ this.tb_rl = tb_rl;
+ }
+
+ public void setUseParent(boolean useParent) {
+ this.useParent = useParent;
+ }
+
+ public void setRelative(boolean relative) {
+ this.relative = relative;
+ }
+
+ /**
+ * For properties that operate on a relative direction (before, after,
+ * start, end) instead of an absolute direction (top, bottom, left,
+ * right), this method determines whether a corresponding property
+ * is specified on the corresponding absolute direction. For example,
+ * the border-start-color property in a lr-tb writing-mode specifies
+ * the same thing that the border-left-color property specifies. In this
+ * example, if the Maker for the border-start-color property is testing,
+ * and if the border-left-color is specified in the properties,
+ * this method should return true.
+ * @param propertyList collection of properties to be tested
+ * @return true iff 1) the property operates on a relative direction,
+ * AND 2) the property has a corresponding property on an absolute
+ * direction, AND 3) the corresponding property on that absolute
+ * direction has been specified in the input properties
+ */
+ public boolean isCorrespondingForced(PropertyList propertyList) {
+ if (!relative) {
+ return false;
+ }
+ PropertyList pList;
+ if (useParent) {
+ pList = propertyList.getParentFObj().propertyList;
+ } else {
+ pList = propertyList;
+ }
+ int correspondingId = pList.wmMap(lr_tb, rl_tb, tb_rl);
+ if (propertyList.getExplicit(correspondingId) != null)
+ return true;
+ return false;
+ }
+
+ /**
+ * Return a Property object representing the value of this property,
+ * based on other property values for this FO.
+ * A special case is properties which inherit the specified value,
+ * rather than the computed value.
+ * @param propertyList The PropertyList for the FO.
+ * @return Property A computed Property value or null if no rules
+ * are specified (in foproperties.xml) to compute the value.
+ * @throws FOPException for invalid or inconsistent FO input
+ */
+ public Property compute(PropertyList propertyList) throws FOPException {
+ PropertyList pList;
+ if (useParent) {
+ pList = propertyList.getParentPropertyList();
+ if (pList == null) {
+ return null;
+ }
+ } else {
+ pList = propertyList;
+ }
+ int correspondingId = pList.wmMap(lr_tb, rl_tb, tb_rl);
+
+ Property p = propertyList.getExplicitOrShorthand(correspondingId);
+ if (p != null) {
+ FObj parentFO = propertyList.getParentFObj();
+ p = baseMaker.convertProperty(p, propertyList, parentFO);
+ }
+ return p;
+ }
+}
+
--- /dev/null
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.fo.properties;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.Property;
+import org.apache.fop.fo.PropertyList;
+
+/**
+ * @author me
+ *
+ * To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+public class DimensionPropertyMaker extends CorrespondingPropertyMaker {
+ int[][] extraCorresponding = null;
+
+ public DimensionPropertyMaker(PropertyMaker baseMaker) {
+ super(baseMaker);
+ }
+
+ public void setExtraCorresponding(int[][] extraCorresponding) {
+ this.extraCorresponding = extraCorresponding;
+ }
+
+ public boolean isCorrespondingForced(PropertyList propertyList) {
+ if (super.isCorrespondingForced(propertyList))
+ return true;
+ for (int i = 0; i < extraCorresponding.length; i++) {
+ int wmcorr = extraCorresponding[i][0]; //propertyList.getWritingMode()];
+ if (propertyList.getExplicit(wmcorr) != null)
+ return true;
+ }
+ return false;
+ }
+
+ public Property compute(PropertyList propertyList) throws FOPException {
+ // Based on [width|height]
+ Property p = super.compute(propertyList);
+ if (p == null) {
+ p = baseMaker.make(propertyList);
+ }
+
+ // Based on min-[width|height]
+ int wmcorr = propertyList.wmMap(extraCorresponding[0][0],
+ extraCorresponding[0][1],
+ extraCorresponding[0][2]);
+ Property subprop = propertyList.getExplicitOrShorthand(wmcorr);
+ if (subprop != null) {
+ baseMaker.setSubprop(p, Constants.CP_MINIMUM, subprop);
+ }
+
+ // Based on max-[width|height]
+ wmcorr = propertyList.wmMap(extraCorresponding[1][0],
+ extraCorresponding[1][1],
+ extraCorresponding[1][2]);
+ subprop = propertyList.getExplicitOrShorthand(wmcorr);
+ // TODO: Don't set when NONE.
+ if (subprop != null) {
+ baseMaker.setSubprop(p, Constants.CP_MAXIMUM, subprop);
+ }
+
+ return p;
+ }
+}
--- /dev/null
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.fo.properties;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.datatypes.FixedLength;
+import org.apache.fop.fo.FOPropertyMapping;
+import org.apache.fop.fo.LengthProperty;
+import org.apache.fop.fo.Property;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.expr.Numeric;
+
+/**
+ * This property maker handles the calculations described in 5.3.2 which
+ * involves the sizes of the corresponding margin-* properties and the
+ * padding-* and border-*-width properties.
+ */
+public class IndentPropertyMaker extends CorrespondingPropertyMaker {
+ /**
+ * The corresponding padding-* propIds
+ */
+ private int[] paddingCorresponding = null;
+
+ /**
+ * The corresponding border-*-width propIds
+ */
+ private int[] borderWidthCorresponding = null;
+
+ /**
+ * Create a start-indent or end-indent property maker.
+ * @param baseMaker
+ */
+ public IndentPropertyMaker(PropertyMaker baseMaker) {
+ super(baseMaker);
+ }
+
+ /**
+ * Set the corresponding values for the padding-* properties.
+ * @param paddingCorresponding the corresping propids.
+ */
+ public void setPaddingCorresponding(int[] paddingCorresponding) {
+ this.paddingCorresponding = paddingCorresponding;
+ }
+
+ /**
+ * Set the corresponding values for the border-*-width properties.
+ * @param borderWidthCorresponding the corresping propids.
+ */
+ public void setBorderWidthCorresponding(int[] borderWidthCorresponding) {
+ this.borderWidthCorresponding = borderWidthCorresponding;
+ }
+
+ /**
+ * Calculate the corresponding value for start-indent and end-indent.
+ * @see CorrespondingPropertyMaker#compute(PropertyList)
+ */
+ public Property compute(PropertyList propertyList) throws FOPException {
+ // TODO: bckfnn reenable
+ if (propertyList.getExplicitOrShorthand(propertyList.wmMap(lr_tb, rl_tb, tb_rl)) == null) {
+ return null;
+ }
+ // Calculate the values as described in 5.3.2.
+ try {
+ Numeric v = new Numeric(new FixedLength(0));
+ /*
+ if (!propertyList.getFObj().generatesInlineAreas()) {
+ String propName = FOPropertyMapping.getPropertyName(this.propId);
+ v = v.add(propertyList.getInherited(propName).getNumeric());
+ }
+ */
+ v = v.add(propertyList.get(propertyList.wmMap(lr_tb, rl_tb, tb_rl)).getNumeric());
+ v = v.add(getCorresponding(paddingCorresponding, propertyList).getNumeric());
+ v = v.add(getCorresponding(borderWidthCorresponding, propertyList).getNumeric());
+ return new LengthProperty(v.asLength());
+ } catch (org.apache.fop.fo.expr.PropertyException propEx) {
+ String propName = FOPropertyMapping.getPropertyName(baseMaker.getPropId());
+ throw new FOPException("Error in " + propName
+ + " calculation " + propEx);
+ }
+ }
+
+ private Property getCorresponding(int[] corresponding, PropertyList propertyList) {
+ int wmcorr = propertyList.wmMap(corresponding[0], corresponding[1], corresponding[2]);
+ return propertyList.get(wmcorr);
+ }
+}
--- /dev/null
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.fo.properties;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.datatypes.PercentLength;
+import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.LengthProperty;
+import org.apache.fop.fo.Property;
+import org.apache.fop.fo.PropertyList;
+
+/**
+ * A maker which calculates the line-height property.
+ * This property maker is special because line-height inherit the specified
+ * value, instead of the computed value.
+ * So when a line-height is create based on a attribute, the specified value
+ * is stored in the property and in compute() the stored specified value of
+ * the nearest specified is used to recalculate the line-height.
+ */
+
+public class LineHeightPropertyMaker extends LengthProperty.Maker {
+ /**
+ * Create a maker for line-height.
+ * @param propId the is for linehight.
+ */
+ public LineHeightPropertyMaker(int propId) {
+ super(propId);
+ }
+
+ /**
+ * Make a property as normal, and save the specified value.
+ * @see Property.Maker#make(PropertyList, String, FObj)
+ */
+ public Property make(PropertyList propertyList, String value,
+ FObj fo) throws FOPException {
+ Property p = super.make(propertyList, value, fo);
+ p.setSpecifiedValue(checkValueKeywords(value));
+ return p;
+ }
+
+ /**
+ * Recalculate the line-height value based on the nearest specified
+ * value.
+ * @see Property.Maker#compute(PropertyList)
+ */
+ protected Property compute(PropertyList propertyList) throws FOPException {
+ // recalculate based on last specified value
+ // Climb up propertylist and find last spec'd value
+ Property specProp = propertyList.getNearestSpecified(propId);
+ if (specProp != null) {
+ String specVal = specProp.getSpecifiedValue();
+ if (specVal != null) {
+ try {
+ return make(propertyList, specVal,
+ propertyList.getParentFObj());
+ } catch (FOPException e) {
+ //getLogger()error("Error computing property value for "
+ // + propName + " from "
+ // + specVal);
+ return null;
+ }
+ }
+ }
+ return null;
+ }
+
+ protected Property convertPropertyDatatype(Property p,
+ PropertyList propertyList,
+ FObj fo) {
+ Number numval = p.getNumber();
+ if (numval != null) {
+ return new LengthProperty(
+ new PercentLength(numval.doubleValue(), getPercentBase(fo,propertyList)));
+ }
+ return super.convertPropertyDatatype(p, propertyList, fo);
+ }
+}
--- /dev/null
+/*
+ * $Id$
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+package org.apache.fop.fo.properties;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.datatypes.CompoundDatatype;
+import org.apache.fop.datatypes.LengthBase;
+import org.apache.fop.datatypes.PercentBase;
+import org.apache.fop.fo.FOPropertyMapping;
+import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.ListProperty;
+import org.apache.fop.fo.Property;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.ShorthandParser;
+import org.apache.fop.fo.expr.PropertyInfo;
+import org.apache.fop.fo.expr.PropertyParser;
+
+
+/**
+ * Base class for all property makers
+ * @author unascribed
+ */
+public class PropertyMaker implements Cloneable {
+ protected int propId;
+ private boolean inherited = true;
+ private Map enums = null;
+ private Map keywords = null;
+ protected String defaultValue = null;
+ protected boolean contextDep = false;
+ protected boolean setByShorthand = false;
+ private int percentBase = -1;
+ private PropertyMaker[] shorthands = null;
+ private ShorthandParser datatypeParser;
+
+ protected Property defaultProperty;
+ protected CorrespondingPropertyMaker corresponding;
+
+ /**
+ * @return the name of the property for this Maker
+ */
+ public int getPropId() {
+ return propId;
+ }
+
+ /**
+ * Construct an instance of a Property.Maker for the given property.
+ * @param propId The Constant ID of the property to be made.
+ */
+ public PropertyMaker(int propId) {
+ this.propId = propId;
+ }
+
+ /**
+ * Copy all the values from the generic maker to this maker.
+ * @param generic a generic property maker.
+ */
+ public void useGeneric(PropertyMaker generic) {
+ contextDep = generic.contextDep;
+ inherited = generic.inherited;
+ defaultValue = generic.defaultValue;
+ percentBase = generic.percentBase;
+ if (generic.shorthands != null) {
+ shorthands = new PropertyMaker[generic.shorthands.length];
+ System.arraycopy(shorthands, 0, generic.shorthands, 0, shorthands.length);
+ }
+ if (generic.enums != null) {
+ enums = new HashMap(generic.enums);
+ }
+ if (generic.keywords != null) {
+ keywords = new HashMap(generic.keywords);
+ }
+ }
+
+ /**
+ * Set the inherited flag.
+ * @param inherited
+ */
+ public void setInherited(boolean inherited) {
+ this.inherited = inherited;
+ }
+
+ /**
+ * Add a keyword-equiv to the maker.
+ * @param keyword
+ * @param value
+ */
+ public void addKeyword(String keyword, String value) {
+ if (keywords == null) {
+ keywords = new HashMap();
+ }
+ keywords.put(keyword, value);
+ }
+
+ /**
+ * Add a enum constant.
+ * @param constant
+ * @param value
+ */
+ public void addEnum(String constant, Property value) {
+ if (enums == null) {
+ enums = new HashMap();
+ }
+ enums.put(constant, value);
+ }
+
+ /**
+ * Add a subproperty to this maker.
+ * @param subproperty
+ */
+ public void addSubpropMaker(PropertyMaker subproperty) {
+ throw new RuntimeException("Unable to add subproperties " + getClass());
+ }
+
+ /**
+ * Return a subproperty maker for the subpropId.
+ * @param subpropId The subpropId of the maker.
+ * @return The subproperty maker.
+ */
+ public PropertyMaker getSubpropMaker(int subpropId) {
+ throw new RuntimeException("Unable to add subproperties");
+ }
+
+ /**
+ * Add a shorthand to this maker. Only an Integer is added to the
+ * shorthands list. Later the Integers are replaced with references
+ * to the actual shorthand property makers.
+ * @param shorthand a property maker thar is that is checked for
+ * shorthand values.
+ */
+ public void addShorthand(PropertyMaker shorthand) {
+ if (shorthands == null) {
+ shorthands = new PropertyMaker[3];
+ }
+ for (int i = 0; i < shorthands.length; i++) {
+ if (shorthands[i] == null) {
+ shorthands[i] = shorthand;
+ break;
+ }
+ }
+ }
+
+ /**
+ * Set the shorthand datatype parser.
+ * @param subproperty
+ */
+ public void setDatatypeParser(ShorthandParser parser) {
+ datatypeParser = parser;
+ }
+
+ /**
+ * Set the default value for this maker.
+ * @param defaultValue the default value.
+ */
+ public void setDefault(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ /**
+ * Set the default value for this maker.
+ * @param defaultValue
+ * @param contextDep true when the value context dependent and
+ * must not be cached.
+ */
+ public void setDefault(String defaultValue, boolean contextDep) {
+ this.defaultValue = defaultValue;
+ this.contextDep = contextDep;
+ }
+
+ /**
+ * Set the percent base identifier for this maker.
+ * @param percentBase
+ */
+ public void setPercentBase(int percentBase) {
+ this.percentBase = percentBase;
+ }
+
+ /**
+ * Set the byShorthand flag which only is applicable for subproperty
+ * makers. It should be true for the subproperties which must be
+ * assigned a value when the base property is assigned a attribute
+ * value directly.
+ * @param defaultValue
+ */
+ public void setByShorthand(boolean setByShorthand) {
+ this.setByShorthand = setByShorthand;
+ }
+
+ /**
+ * Set the correspoding property information.
+ * @param corresponding a corresponding maker where the
+ * isForcedCorresponding and compute methods are delegated to.
+ */
+ public void setCorresponding(CorrespondingPropertyMaker corresponding) {
+ this.corresponding = corresponding;
+ }
+
+ /**
+ * Create a new empty property. Must be overriden in compound
+ * subclasses.
+ * @return a new instance of the Property for which this is a maker.
+ */
+ public Property makeNewProperty() {
+ return null;
+ }
+
+ /*
+ * If the property is a relative property with a corresponding absolute
+ * value specified, the absolute value is used. This is also true of
+ * the inheritance priority (I think...)
+ * If the property is an "absolute" property and it isn't specified, then
+ * we try to compute it from the corresponding relative property: this
+ * happens in computeProperty.
+ */
+ protected Property findProperty(PropertyList propertyList,
+ boolean bTryInherit)
+ throws FOPException
+ {
+ Property p = null;
+
+ if (corresponding != null && corresponding.isCorrespondingForced(propertyList)) {
+ p = corresponding.compute(propertyList);
+ } else {
+ p = propertyList.getExplicitBaseProp(propId);
+ if (p == null) {
+ p = this.compute(propertyList);
+ }
+ if (p == null) { // check for shorthand specification
+ p = getShorthand(propertyList);
+ }
+ if (p == null && bTryInherit) {
+ // else inherit (if has parent and is inheritable)
+ PropertyList parentPropertyList = propertyList.getParentPropertyList();
+ if (parentPropertyList != null && isInherited()) {
+ p = findProperty(parentPropertyList, true);
+ }
+ }
+ }
+ return p;
+ }
+
+ /**
+ * Return the property on the current FlowObject. Depending on the passed flags,
+ * this will try to compute it based on other properties, or if it is
+ * inheritable, to return the inherited value. If all else fails, it returns
+ * the default value.
+ * @param subpropId The subproperty id of the property being retrieved.
+ * Is 0 when retriving a base property.
+ * @param propertylist The PropertyList object being built for this FO.
+ * @param bTryInherit true if inherited properties should be examined.
+ * @param bTryDefault true if the default value should be returned.
+ */
+ public Property get(int subpropId, PropertyList propertyList,
+ boolean bTryInherit, boolean bTryDefault)
+ throws FOPException
+ {
+ Property p = findProperty(propertyList, bTryInherit);
+ if (p == null && bTryDefault) { // default value for this FO!
+ try {
+ p = make(propertyList);
+ } catch (FOPException e) {
+ // don't know what to do here
+ }
+ }
+ return p;
+ }
+
+ /**
+ * Default implementation of isInherited.
+ * @return A boolean indicating whether this property is inherited.
+ */
+ public boolean isInherited() {
+ return inherited;
+ }
+
+ /**
+ * This is used to handle properties specified as a percentage of
+ * some "base length", such as the content width of their containing
+ * box.
+ * Overridden by subclasses which allow percent specifications. See
+ * the documentation on properties.xsl for details.
+ * @param fo the FObj containing the PercentBase
+ * @param pl the PropertyList containing the property. (TODO: explain
+ * what this is used for, or remove it from the signature.)
+ * @return an object implementing the PercentBase interface.
+ */
+ public PercentBase getPercentBase(FObj fo, PropertyList pl) {
+ if (percentBase == -1)
+ return null;
+ return new LengthBase(fo, pl, percentBase);
+ }
+
+ /**
+ * Return a property value for the given component of a compound
+ * property.
+ * @param p A property value for a compound property type such as
+ * SpaceProperty.
+ * @param subprop The Constants ID of the component whose value is to be
+ * returned.
+ * NOTE: this is only to ease porting when calls are made to
+ * PropertyList.get() using a component name of a compound property,
+ * such as get("space.optimum"). The recommended technique is:
+ * get("space").getOptimum().
+ * Overridden by property maker subclasses which handle
+ * compound properties.
+ * @return the Property containing the subproperty
+ */
+ public Property getSubprop(Property p, int subpropId) {
+ CompoundDatatype val = (CompoundDatatype) p.getObject();
+ return val.getComponent(subpropId);
+ }
+
+ /**
+ * Set a component in a compound property and return the modified
+ * compound property object.
+ * This default implementation returns the original base property
+ * without modifying it.
+ * It is overridden by property maker subclasses which handle
+ * compound properties.
+ * @param baseProp The Property object representing the compound property,
+ * such as SpaceProperty.
+ * @param partId The ID of the component whose value is specified.
+ * @param subProp A Property object holding the specified value of the
+ * component to be set.
+ * @return The modified compound property object.
+ */
+ protected Property setSubprop(Property baseProp, int partId,
+ Property subProp) {
+ CompoundDatatype val = (CompoundDatatype) baseProp.getObject();
+ val.setComponent(partId, subProp, false);
+ return baseProp;
+ }
+
+ /**
+ * Return the default value.
+ * @param propertyList The PropertyList object being built for this FO.
+ * @return the Property object corresponding to the parameters
+ * @throws FOPException for invalid or inconsisten FO input
+ */
+ public Property make(PropertyList propertyList) throws FOPException {
+ if (defaultProperty != null) {
+ return defaultProperty;
+ }
+ Property p = make(propertyList, defaultValue, propertyList.getParentFObj());
+ if (!contextDep) {
+ defaultProperty = p;
+ }
+ return p;
+ }
+
+ /**
+ * Create a Property object from an attribute specification.
+ * @param propertyList The PropertyList object being built for this FO.
+ * @param value The attribute value.
+ * @param fo The current FO whose properties are being set.
+ * @return The initialized Property object.
+ * @throws FOPException for invalid or inconsistent FO input
+ */
+ public Property make(PropertyList propertyList, String value,
+ FObj fo) throws FOPException {
+ try {
+ Property newProp = null;
+ String pvalue = value;
+ if ("inherit".equals(value)) {
+ newProp = propertyList.getFromParent(this.propId);
+ } else {
+ newProp = checkEnumValues(value);
+ }
+ if (newProp == null) {
+ /* Check for keyword shorthand values to be substituted. */
+ pvalue = checkValueKeywords(value);
+ // Override parsePropertyValue in each subclass of Property.Maker
+ Property p = PropertyParser.parse(pvalue,
+ new PropertyInfo(this,
+ propertyList, fo));
+ newProp = convertProperty(p, propertyList, fo);
+ }
+ if (newProp == null) {
+ throw new org.apache.fop.fo.expr.PropertyException("No conversion defined");
+ }
+ return newProp;
+ } catch (org.apache.fop.fo.expr.PropertyException propEx) {
+ String propName = FOPropertyMapping.getPropertyName(this.propId);
+ throw new FOPException("Error in " + propName
+ + " property value '" + value + "': "
+ + propEx);
+ }
+ }
+
+ /**
+ * Make a property value for a compound property. If the property
+ * value is already partially initialized, this method will modify it.
+ * @param baseProp The Property object representing the compound property,
+ * for example: SpaceProperty.
+ * @param subpropId The Constants ID of the subproperty (component)
+ * whose value is specified.
+ * @param propertyList The propertyList being built.
+ * @param fo The FO whose properties are being set.
+ * @param value the value of the
+ * @return baseProp (or if null, a new compound property object) with
+ * the new subproperty added
+ * @throws FOPException for invalid or inconsistent FO input
+ */
+ public Property make(Property baseProp, int subpropId,
+ PropertyList propertyList, String value,
+ FObj fo) throws FOPException {
+ //getLogger().error("compound property component "
+ // + partName + " unknown.");
+ return baseProp;
+ }
+
+ public Property convertShorthandProperty(PropertyList propertyList,
+ Property prop, FObj fo) {
+ Property pret = null;
+ try {
+ pret = convertProperty(prop, propertyList, fo);
+ if (pret == null) {
+ // If value is a name token, may be keyword or Enum
+ String sval = prop.getNCname();
+ if (sval != null) {
+ // System.err.println("Convert shorthand ncname " + sval);
+ pret = checkEnumValues(sval);
+ if (pret == null) {
+ /* Check for keyword shorthand values to be substituted. */
+ String pvalue = checkValueKeywords(sval);
+ if (!pvalue.equals(sval)) {
+ // System.err.println("Convert shorthand keyword" + pvalue);
+ // Substituted a value: must parse it
+ Property p =
+ PropertyParser.parse(pvalue,
+ new PropertyInfo(this,
+ propertyList,
+ fo));
+ pret = convertProperty(p, propertyList, fo);
+ }
+ }
+ }
+ }
+ } catch (FOPException e) {
+
+ //getLogger().error("convertShorthandProperty caught FOPException "
+ // + e);
+ } catch (org.apache.fop.fo.expr.PropertyException propEx) {
+ //getLogger().error("convertShorthandProperty caught PropertyException "
+ // + propEx);
+ }
+ if (pret != null) {
+ /*
+ * System.err.println("Return shorthand value " + pret.getString() +
+ * " for " + getPropName());
+ */
+ }
+ return pret;
+ }
+
+ /**
+ * For properties that contain enumerated values.
+ * This method should be overridden by subclasses.
+ * @param value the string containing the property value
+ * @return the Property encapsulating the enumerated equivalent of the
+ * input value
+ */
+ protected Property checkEnumValues(String value) {
+ if (enums != null) {
+ return (Property) enums.get(value);
+ }
+ return null;
+ }
+
+ /**
+ * Return a String to be parsed if the passed value corresponds to
+ * a keyword which can be parsed and used to initialize the property.
+ * For example, the border-width family of properties can have the
+ * initializers "thin", "medium", or "thick". The FOPropertyMapping
+ * file specifies a length value equivalent for these keywords,
+ * such as "0.5pt" for "thin".
+ * @param value The string value of property attribute.
+ * @return A String containging a parseable equivalent or null if
+ * the passed value isn't a keyword initializer for this Property.
+ */
+ protected String checkValueKeywords(String keyword) {
+ if (keywords != null) {
+ String value = (String)keywords.get(keyword);
+ if (value != null) {
+ return value;
+ }
+ }
+ return keyword;
+ }
+
+ /**
+ * Return a Property object based on the passed Property object.
+ * This method is called if the Property object built by the parser
+ * isn't the right type for this property.
+ * It is overridden by subclasses.
+ * @param p The Property object return by the expression parser
+ * @param propertyList The PropertyList object being built for this FO.
+ * @param fo The current FO whose properties are being set.
+ * @return A Property of the correct type or null if the parsed value
+ * can't be converted to the correct type.
+ * @throws FOPException for invalid or inconsistent FO input
+ */
+ protected Property convertProperty(Property p,
+ PropertyList propertyList,
+ FObj fo) throws FOPException {
+ return null;
+ }
+
+ /**
+ * For properties that have more than one legal way to be specified,
+ * this routine should be overridden to attempt to set them based upon
+ * the other methods. For example, colors may be specified using an RGB
+ * model, or they may be specified using an NCname.
+ * @param p property whose datatype should be converted
+ * @param propertyList collection of properties. (TODO: explain why
+ * this is needed, or remove it from the signature.)
+ * @param fo the FObj to which this property is attached. (TODO: explain
+ * why this is needed, or remove it from the signature).
+ * @return an Property with the appropriate datatype used
+ */
+ protected Property convertPropertyDatatype(Property p,
+ PropertyList propertyList,
+ FObj fo) {
+ return null;
+ }
+
+ /**
+ * Return a Property object representing the value of this property,
+ * based on other property values for this FO.
+ * A special case is properties which inherit the specified value,
+ * rather than the computed value.
+ * @param propertyList The PropertyList for the FO.
+ * @return Property A computed Property value or null if no rules
+ * are specified to compute the value.
+ * @throws FOPException for invalid or inconsistent FO input
+ */
+ protected Property compute(PropertyList propertyList)
+ throws FOPException {
+ if (corresponding != null) {
+ return corresponding.compute(propertyList);
+ }
+ return null; // standard
+ }
+
+ /**
+ * For properties that can be set by shorthand properties, this method
+ * should return the Property, if any, that is parsed from any
+ * shorthand properties that affect this property.
+ * This method expects to be overridden by subclasses.
+ * For example, the border-right-width property could be set implicitly
+ * from the border shorthand property, the border-width shorthand
+ * property, or the border-right shorthand property. This method should
+ * be overridden in the appropriate subclass to check each of these, and
+ * return an appropriate border-right-width Property object.
+ * @param propertyList the collection of properties to be considered
+ * @return the Property, if found, the correspons, otherwise, null
+ */
+ public Property getShorthand(PropertyList propertyList) {
+ if (shorthands == null) {
+ return null;
+ }
+ ListProperty listprop;
+ int n = shorthands.length;
+ for (int i = 0; i < n && shorthands[i] != null; i++) {
+ PropertyMaker shorthand = shorthands[i];
+ listprop = (ListProperty)propertyList.getExplicit(shorthand.propId);
+ if (listprop != null) {
+ ShorthandParser parser = shorthand.datatypeParser;
+ Property p = parser.getValueForProperty(getPropId(),
+ listprop, this, propertyList);
+ if (p != null) {
+ return p;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return a clone of the makers. Used by useGeneric() to clone the
+ * subproperty makers of the generic compound makers.
+ */
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException exc) {
+ return null;
+ }
+ }
+}
\ No newline at end of file