super(propName);
}
- protected Property convertProperty(Property p, PropertyList propertyList,
+ public Property convertProperty(Property p, PropertyList propertyList,
FObj fo) {
if (p instanceof ColorTypeProperty)
return p;
import org.apache.fop.datatypes.Length;
import org.apache.fop.datatypes.CondLength;
-public class CondLengthProperty extends LengthProperty {
+public class CondLengthProperty extends Property {
- public static class Maker extends LengthProperty.Maker {
+ public static class Maker extends Property.Maker {
- public /* protected*/ Maker(String name) {
+ public Maker(String name) {
super(name);
}
}
- public CondLengthProperty(CondLength length) {
- super(length);
- }
+ private CondLength condLength= null;
+ public CondLengthProperty(CondLength condLength) {
+ this.condLength = condLength;
+ }
public CondLength getCondLength() {
- return (CondLength)super.getLength();
+ return this.condLength;
}
+ /* Question, should we allow this? */
+ public Length getLength() { return this.condLength.getLength().getLength(); }
+
+ public Object getObject() { return this.condLength; }
+
}
super(propName);
}
- // set the Property from the String value
- public Property make(PropertyList propertyList, String value, FObj fo)
- throws FOPException
- {
- Property p = findConstant(value);
- if (p == null) {
- MessageHandler.errorln("WARNING: Unknown value for property '" +
+
+ /**
+ * Called by subclass if no match found.
+ */
+ public Property checkEnumValues(String value) {
+ MessageHandler.errorln("WARNING: Unknown enumerated value for property '" +
getPropName() + "': " + value);
- return make(propertyList); // return the default value
- }
- else {
- return p; //makeProperty(v);
- }
+ return null;
}
protected Property findConstant(String value) {
return null;
}
- /***
- protected Property makeProperty(int v) {
- return new EnumProperty(v);
- }
- ***/
}
private int value;
this.properties = propertyList;
propertyList.setFObj(this);
this.name = "default FO";
+ setWritingMode();
}
/**
return false;
}
+ /**
+ * Set writing mode for this FO.
+ * Find nearest ancestor, including self, which generates
+ * reference areas and use the value of its writing-mode property.
+ */
+ private void setWritingMode() {
+ FObj p = this;
+ while (p!= null && !p.generatesReferenceAreas())
+ p = p.getParent();
+ if (p != null) {
+ this.properties.setWritingMode(p.getProperty("writing-mode").getEnum());
+ }
+ else {
+ // shouldn't happen!!!
+ }
+ }
+
+
}
--- /dev/null
+/*-- $Id$ --
+
+ ============================================================================
+ The Apache Software License, Version 1.1
+ ============================================================================
+
+ Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. The end-user documentation included with the redistribution, if any, must
+ include the following acknowledgment: "This product includes software
+ developed by the Apache Software Foundation (http://www.apache.org/)."
+ Alternately, this acknowledgment may appear in the software itself, if
+ and wherever such third-party acknowledgments normally appear.
+
+ 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ endorse or promote products derived from this software without prior
+ written permission. For written permission, please contact
+ apache@apache.org.
+
+ 5. Products derived from this software may not be called "Apache", nor may
+ "Apache" appear in their name, without prior written permission of the
+ Apache Software Foundation.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ This software consists of voluntary contributions made by many individuals
+ on behalf of the Apache Software Foundation and was originally created by
+ James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ Software Foundation, please see <http://www.apache.org/>.
+
+ */
+package org.apache.fop.fo;
+
+import org.apache.fop.datatypes.Keep;
+
+public class KeepProperty extends Property {
+
+ public static class Maker extends Property.Maker {
+
+ protected Maker(String name) {
+ super(name);
+ }
+ }
+
+ private Keep keep ;
+
+ public KeepProperty(Keep keep) {
+ this.keep = keep;
+ }
+
+ public Keep getKeep() { return this.keep; }
+
+ public Object getObject() { return this.keep; }
+
+}
return false;
}
- protected Property convertProperty(Property p, PropertyList propertyList,
+ public Property convertProperty(Property p, PropertyList propertyList,
FObj fo) throws FOPException {
if (isAutoLengthAllowed()) {
String pval = p.getString();
public LengthRange getLengthRange() { return this.lengthRange; }
- /* Question, should we allow this? */
- public Length getLength() { return this.lengthRange.getOptimum(); }
public Object getObject() { return this.lengthRange ; }
}
super(propName);
}
- protected Property convertProperty(Property p, PropertyList propertyList,
+ public Property convertProperty(Property p, PropertyList propertyList,
FObj fo) {
if (p instanceof NumberProperty)
return p;
*/
public Property make(PropertyList propertyList, String value, FObj fo)
throws FOPException {
- // skeleton for all Makers except for Enum properties
try {
- /* Check for keyword shorthand values to be substituted. */
Property pret=null;
- String pvalue = checkValueKeywords(value);
- // Override parsePropertyValue in each subclass of Property.Maker
- Property p = PropertyParser.parse(pvalue,
- new PropertyInfo(this, propertyList, fo));
- pret = convertProperty(p, propertyList, fo);
+ String pvalue=value;
+ pret = checkEnumValues(value);
+ if (pret == 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));
+ pret = convertProperty(p, propertyList, fo);
+ }
+ else if (isCompoundMaker()) {
+ pret = convertProperty(pret, propertyList, fo);
+ }
if (pret == null) {
throw new org.apache.fop.fo.expr.PropertyException("No conversion defined");
}
}
}
+ protected boolean isCompoundMaker() {
+ return false;
+ }
+
+ public Property checkEnumValues(String 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.
* @return A Property of the correct type or null if the parsed value
* can't be converted to the correct type.
*/
- protected Property convertProperty(Property p,
+ public Property convertProperty(Property p,
PropertyList propertyList, FObj fo) throws FOPException {
return null;
}
* @return Property A computed Property value or null if no rules
* are specified (in foproperties.xml) to compute the value.
*/
- public Property compute(PropertyList propertyList) {
+ public Property compute(PropertyList propertyList) throws FOPException {
if (inheritsSpecified()) {
// recalculate based on last specified value
// Climb up propertylist and find last spec'd value
}
return null; // standard
}
+
+ public boolean isCorrespondingForced(PropertyList propertyList) {
+ return false;
+ }
} // end of nested Maker class
public CondLength getCondLength() { return null; }
public LengthRange getLengthRange() { return null; }
public Space getSpace() { return null; }
- /* KL: first decide which direction to go with this!
public Keep getKeep() { return null; }
+ /* KL: first decide which direction to go with this!
public KeepValue getKeepValue() { return null; }
public Precedence getPrecedence() { return null; }
*/
import java.util.Hashtable;
import org.apache.fop.messaging.MessageHandler;
-
+import org.apache.fop.fo.properties.WritingMode;
import org.apache.fop.apps.FOPException;
public class PropertyList extends Hashtable {
+
+ private byte[] wmtable=null; // writing-mode values
+ public static final int LEFT=0;
+ public static final int RIGHT=1;
+ public static final int TOP=2;
+ public static final int BOTTOM=3;
+ public static final int HEIGHT=4;
+ public static final int WIDTH=5;
+
+ public static final int START=0;
+ public static final int END=1;
+ public static final int BEFORE=2;
+ public static final int AFTER=3;
+ public static final int BLOCKPROGDIM=4;
+ public static final int INLINEPROGDIM=5;
+
+ private static final String[] sAbsNames= new String[]
+ {"left", "right", "top", "bottom", "height", "width"};
+
+ private static final String[] sRelNames= new String[]
+ {"start", "end", "before", "after",
+ "block-progression-dimension", "inline-progression-dimension"};
+
+ static private final Hashtable wmtables = new Hashtable(4);
+ {
+ wmtables.put(new Integer(WritingMode.LR_TB), /* lr-tb */
+ new byte[]{START, END, BEFORE, AFTER, BLOCKPROGDIM, INLINEPROGDIM });
+ wmtables.put(new Integer(WritingMode.RL_TB), /* rl-tb */
+ new byte[]{END, START, BEFORE, AFTER, BLOCKPROGDIM, INLINEPROGDIM });
+ wmtables.put(new Integer(WritingMode.TB_RL), /* tb-rl */
+ new byte[]{AFTER, BEFORE, START, END, INLINEPROGDIM, BLOCKPROGDIM });
+ }
+
private PropertyListBuilder builder;
private PropertyList parentPropertyList = null;
String namespace = "";
return null; // No builder or exception in makeProperty!
}
+ /* 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
+ * happends in computeProperty.
+ */
private Property findProperty(String propertyName) {
- Property p = getExplicit(propertyName);
- if (p == null) {
- p = this.builder.computeProperty(this,namespace, element, propertyName);
+ Property p = null;
+ if (builder.isCorrespondingForced(this, namespace, element, propertyName)) {
+ p = builder.computeProperty(this,namespace, element, propertyName);
}
- if (p == null) { // else inherit (if has parent and is inheritable)
- if (this.parentPropertyList != null &&
- builder.isInherited(namespace, element, propertyName)) {
- p = parentPropertyList.findProperty(propertyName);
+ else {
+ p = getExplicit(propertyName);
+ if (p == null) {
+ p = this.builder.computeProperty(this,namespace, element, propertyName);
+ }
+ if (p == null) { // else inherit (if has parent and is inheritable)
+ if (this.parentPropertyList != null &&
+ builder.isInherited(namespace, element, propertyName)) {
+ p = parentPropertyList.findProperty(propertyName);
+ }
}
}
return p;
}
-
+
/**
* Return the property on the current FlowObject. If it isn't set explicitly,
return null; // No builder or exception in makeProperty!
}
+ /** Given an absolute direction (top, bottom, left, right),
+ * return the corresponding writing model relative direction name
+ * for the flow object. Uses the stored writingMode.
+ */
+ public String wmAbsToRel(int absdir) {
+ if (wmtable != null) {
+ return sRelNames[wmtable[absdir]];
+ }
+ else return "";
+ }
+
+ /** Given a writing mode relative direction (start, end, before, after)
+ * return the corresponding absolute direction name
+ * for the flow object. Uses the stored writingMode.
+ */
+ public String wmRelToAbs(int reldir) {
+ if (wmtable != null) {
+ for (int i=0; i < wmtable.length; i++) {
+ if (wmtable[i]==reldir)
+ return sAbsNames[i];
+ }
+ }
+ return "";
+ }
+
+ /** Set the writing mode traits for the FO with this property list. */
+ public void setWritingMode(int writingMode) {
+ this.wmtable = (byte[])wmtables.get(new Integer(writingMode));
+ }
+
}
Property p = null;
Property.Maker propertyMaker = findMaker(space, element, propertyName);
if (propertyMaker != null) {
+ try {
p = propertyMaker.compute(propertyList);
+ } catch (FOPException e) {
+ MessageHandler.errorln("ERROR: exception occurred while computing" +
+ " value of property '" + propertyName +"': " + e.getMessage());
+ }
} else {
MessageHandler.errorln("WARNING: property " + propertyName + " ignored");
}
}
else return null;
}
+
+
+ public boolean isCorrespondingForced(PropertyList propertyList, String space,
+ String element, String propertyName) {
+ Property.Maker propertyMaker = findMaker(space, element, propertyName);
+ if (propertyMaker != null) {
+ return propertyMaker.isCorrespondingForced(propertyList);
+ } else {
+ MessageHandler.errorln("WARNING: no Maker for " + propertyName);
+ }
+ return false;
+ }
+
public Property makeProperty(PropertyList propertyList, String space, String element, String propertyName) throws FOPException {
public Space getSpace() { return this.space; }
- /* Question, should we allow this? */
- public Length getLength() { return this.space.getOptimum(); }
/* Space extends LengthRange */
public LengthRange getLengthRange() { return this.space; }
public Object getObject() { return this.space; }