From 61d372a192e1a5e92437d100f8ec38124e8bc6fd Mon Sep 17 00:00:00 2001 From: Karen Lease Date: Tue, 2 Jan 2001 21:35:44 +0000 Subject: [PATCH] Modify compound property handling; add support for corresponding properties and mixed property types git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193940 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/fo/ColorTypeProperty.java | 2 +- src/org/apache/fop/fo/CondLengthProperty.java | 20 ++-- src/org/apache/fop/fo/EnumProperty.java | 24 ++--- src/org/apache/fop/fo/FObj.java | 19 ++++ src/org/apache/fop/fo/KeepProperty.java | 74 +++++++++++++++ src/org/apache/fop/fo/LengthProperty.java | 2 +- .../apache/fop/fo/LengthRangeProperty.java | 2 - src/org/apache/fop/fo/NumberProperty.java | 2 +- src/org/apache/fop/fo/Property.java | 38 ++++++-- src/org/apache/fop/fo/PropertyList.java | 94 +++++++++++++++++-- .../apache/fop/fo/PropertyListBuilder.java | 18 ++++ src/org/apache/fop/fo/SpaceProperty.java | 2 - 12 files changed, 247 insertions(+), 50 deletions(-) create mode 100644 src/org/apache/fop/fo/KeepProperty.java diff --git a/src/org/apache/fop/fo/ColorTypeProperty.java b/src/org/apache/fop/fo/ColorTypeProperty.java index 6a32ff015..3aeed8240 100644 --- a/src/org/apache/fop/fo/ColorTypeProperty.java +++ b/src/org/apache/fop/fo/ColorTypeProperty.java @@ -60,7 +60,7 @@ public class ColorTypeProperty extends Property { super(propName); } - protected Property convertProperty(Property p, PropertyList propertyList, + public Property convertProperty(Property p, PropertyList propertyList, FObj fo) { if (p instanceof ColorTypeProperty) return p; diff --git a/src/org/apache/fop/fo/CondLengthProperty.java b/src/org/apache/fop/fo/CondLengthProperty.java index fc9556593..6b6a27b29 100644 --- a/src/org/apache/fop/fo/CondLengthProperty.java +++ b/src/org/apache/fop/fo/CondLengthProperty.java @@ -53,22 +53,28 @@ package org.apache.fop.fo; 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; } + } diff --git a/src/org/apache/fop/fo/EnumProperty.java b/src/org/apache/fop/fo/EnumProperty.java index c8979d804..0a46c6e53 100644 --- a/src/org/apache/fop/fo/EnumProperty.java +++ b/src/org/apache/fop/fo/EnumProperty.java @@ -61,30 +61,20 @@ public class EnumProperty extends Property { 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; diff --git a/src/org/apache/fop/fo/FObj.java b/src/org/apache/fop/fo/FObj.java index 2e396c220..cd3746a84 100644 --- a/src/org/apache/fop/fo/FObj.java +++ b/src/org/apache/fop/fo/FObj.java @@ -86,6 +86,7 @@ public class FObj extends FONode { this.properties = propertyList; propertyList.setFObj(this); this.name = "default FO"; + setWritingMode(); } /** @@ -180,5 +181,23 @@ public class FObj extends FONode { 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!!! + } + } + + } diff --git a/src/org/apache/fop/fo/KeepProperty.java b/src/org/apache/fop/fo/KeepProperty.java new file mode 100644 index 000000000..64f28af67 --- /dev/null +++ b/src/org/apache/fop/fo/KeepProperty.java @@ -0,0 +1,74 @@ +/*-- $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 . For more information on the Apache + Software Foundation, please see . + + */ +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; } + +} diff --git a/src/org/apache/fop/fo/LengthProperty.java b/src/org/apache/fop/fo/LengthProperty.java index 2234b59dd..365eb811d 100644 --- a/src/org/apache/fop/fo/LengthProperty.java +++ b/src/org/apache/fop/fo/LengthProperty.java @@ -77,7 +77,7 @@ public class LengthProperty extends Property { 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(); diff --git a/src/org/apache/fop/fo/LengthRangeProperty.java b/src/org/apache/fop/fo/LengthRangeProperty.java index b5aa7af04..20968d77f 100644 --- a/src/org/apache/fop/fo/LengthRangeProperty.java +++ b/src/org/apache/fop/fo/LengthRangeProperty.java @@ -70,8 +70,6 @@ public class LengthRangeProperty extends Property { public LengthRange getLengthRange() { return this.lengthRange; } - /* Question, should we allow this? */ - public Length getLength() { return this.lengthRange.getOptimum(); } public Object getObject() { return this.lengthRange ; } } diff --git a/src/org/apache/fop/fo/NumberProperty.java b/src/org/apache/fop/fo/NumberProperty.java index 04b38d90e..b002595c5 100644 --- a/src/org/apache/fop/fo/NumberProperty.java +++ b/src/org/apache/fop/fo/NumberProperty.java @@ -61,7 +61,7 @@ public class NumberProperty extends Property { super(propName); } - protected Property convertProperty(Property p, PropertyList propertyList, + public Property convertProperty(Property p, PropertyList propertyList, FObj fo) { if (p instanceof NumberProperty) return p; diff --git a/src/org/apache/fop/fo/Property.java b/src/org/apache/fop/fo/Property.java index c397f09bf..f2fe1bb09 100644 --- a/src/org/apache/fop/fo/Property.java +++ b/src/org/apache/fop/fo/Property.java @@ -202,15 +202,21 @@ public class Property { */ 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"); } @@ -225,6 +231,14 @@ public class Property { } } + 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. @@ -254,7 +268,7 @@ public class 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; } @@ -292,7 +306,7 @@ public class Property { * @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 @@ -314,6 +328,10 @@ public class Property { } return null; // standard } + + public boolean isCorrespondingForced(PropertyList propertyList) { + return false; + } } // end of nested Maker class @@ -345,8 +363,8 @@ public class Property { 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; } */ diff --git a/src/org/apache/fop/fo/PropertyList.java b/src/org/apache/fop/fo/PropertyList.java index 6838960c6..d3bf0541f 100644 --- a/src/org/apache/fop/fo/PropertyList.java +++ b/src/org/apache/fop/fo/PropertyList.java @@ -52,10 +52,43 @@ package org.apache.fop.fo; 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 = ""; @@ -118,20 +151,33 @@ public class PropertyList extends Hashtable { 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, @@ -229,5 +275,35 @@ public class PropertyList extends Hashtable { 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)); + } + } diff --git a/src/org/apache/fop/fo/PropertyListBuilder.java b/src/org/apache/fop/fo/PropertyListBuilder.java index e8f1ed214..c4da11f1b 100644 --- a/src/org/apache/fop/fo/PropertyListBuilder.java +++ b/src/org/apache/fop/fo/PropertyListBuilder.java @@ -90,7 +90,12 @@ public class PropertyListBuilder { 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"); } @@ -209,6 +214,19 @@ public class PropertyListBuilder { } 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 { diff --git a/src/org/apache/fop/fo/SpaceProperty.java b/src/org/apache/fop/fo/SpaceProperty.java index 4235dfccc..a958eaca7 100644 --- a/src/org/apache/fop/fo/SpaceProperty.java +++ b/src/org/apache/fop/fo/SpaceProperty.java @@ -70,8 +70,6 @@ public class SpaceProperty extends Property { 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; } -- 2.39.5