Browse Source

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
pull/32/head
Karen Lease 23 years ago
parent
commit
7489531375

+ 1
- 1
src/org/apache/fop/fo/ColorTypeProperty.java View File

@@ -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;

+ 13
- 7
src/org/apache/fop/fo/CondLengthProperty.java View File

@@ -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; }

}

+ 7
- 17
src/org/apache/fop/fo/EnumProperty.java View File

@@ -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;

+ 19
- 0
src/org/apache/fop/fo/FObj.java View File

@@ -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!!!
}
}


}


+ 74
- 0
src/org/apache/fop/fo/KeepProperty.java View File

@@ -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 <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; }

}

+ 1
- 1
src/org/apache/fop/fo/LengthProperty.java View File

@@ -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();

+ 0
- 2
src/org/apache/fop/fo/LengthRangeProperty.java View File

@@ -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 ; }

}

+ 1
- 1
src/org/apache/fop/fo/NumberProperty.java View File

@@ -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;

+ 28
- 10
src/org/apache/fop/fo/Property.java View File

@@ -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; }
*/

+ 85
- 9
src/org/apache/fop/fo/PropertyList.java View File

@@ -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));
}

}


+ 18
- 0
src/org/apache/fop/fo/PropertyListBuilder.java View File

@@ -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 {

+ 0
- 2
src/org/apache/fop/fo/SpaceProperty.java View File

@@ -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; }

Loading…
Cancel
Save