From: Peter Bernard West Date: Wed, 21 Apr 2004 15:21:18 +0000 (+0000) Subject: W.I.P. on corresponding properties X-Git-Tag: Defoe_export~218 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1801ebea95a4f5c30c51018b0c55f362ac5291e8;p=xmlgraphics-fop.git W.I.P. on corresponding properties git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@197526 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fo/properties/AbsoluteCorrespondingProperty.java b/src/java/org/apache/fop/fo/properties/AbsoluteCorrespondingProperty.java index e719032c1..4eb298165 100644 --- a/src/java/org/apache/fop/fo/properties/AbsoluteCorrespondingProperty.java +++ b/src/java/org/apache/fop/fo/properties/AbsoluteCorrespondingProperty.java @@ -30,9 +30,8 @@ import org.apache.fop.fo.expr.PropertyException; * @author pbw * @version $Revision$ $Name$ */ -public interface AbsoluteCorrespondingProperty { - public int getWritingMode (FONode foNode) - throws PropertyException; +public interface AbsoluteCorrespondingProperty +extends CorrespondingProperty { public int getCorrespondingRelativeProperty(FONode foNode) throws PropertyException; public boolean overridesCorresponding(FONode foNode); diff --git a/src/java/org/apache/fop/fo/properties/AbstractCorrespondingProperty.java b/src/java/org/apache/fop/fo/properties/AbstractCorrespondingProperty.java new file mode 100644 index 000000000..fe7de8757 --- /dev/null +++ b/src/java/org/apache/fop/fo/properties/AbstractCorrespondingProperty.java @@ -0,0 +1,48 @@ +/* + * + * Copyright 2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Created on 21/04/2004 + * $Id$ + */ +package org.apache.fop.fo.properties; + +import org.apache.fop.datatypes.EnumType; +import org.apache.fop.datatypes.PropertyValue; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.PropNames; +import org.apache.fop.fo.expr.PropertyException; + +/** + * @author pbw + * @version $Revision$ $Name$ + */ +public abstract class AbstractCorrespondingProperty extends Property + implements + CorrespondingProperty { + /* (non-Javadoc) + * @see org.apache.fop.fo.properties.CorrespondingProperty#getWritingMode(org.apache.fop.fo.FONode) + */ + public int getWritingMode(FONode foNode) + throws PropertyException { + PropertyValue wm = foNode.getPropertyValue(PropNames.WRITING_MODE); + return EnumType.getEnumValue(wm); + } + /* (non-Javadoc) + * @see org.apache.fop.fo.properties.CorrespondingProperty#getCorrespondingProperty(org.apache.fop.fo.FONode) + */ + public abstract int getCorrespondingProperty(FONode foNode) + throws PropertyException; +} diff --git a/src/java/org/apache/fop/fo/properties/BorderAfterStyle.java b/src/java/org/apache/fop/fo/properties/BorderAfterStyle.java index 829e8474b..328c832b7 100644 --- a/src/java/org/apache/fop/fo/properties/BorderAfterStyle.java +++ b/src/java/org/apache/fop/fo/properties/BorderAfterStyle.java @@ -53,8 +53,8 @@ extends BorderCommonStyleRelative { public int getCorrespondingAbsoluteProperty(FONode foNode) throws PropertyException { - return WritingMode.getCorrespondingAbsoluteEdge( - getWritingMode(foNode), WritingMode.AFTER); + return getCorrespondingAbsoluteStyleProperty( + foNode, WritingMode.AFTER); } public boolean correspondingOverrides(FONode foNode) { diff --git a/src/java/org/apache/fop/fo/properties/BorderBeforeStyle.java b/src/java/org/apache/fop/fo/properties/BorderBeforeStyle.java index 7addf2d9d..aad8ac11e 100644 --- a/src/java/org/apache/fop/fo/properties/BorderBeforeStyle.java +++ b/src/java/org/apache/fop/fo/properties/BorderBeforeStyle.java @@ -53,8 +53,8 @@ extends BorderCommonStyleRelative { public int getCorrespondingAbsoluteProperty(FONode foNode) throws PropertyException { - return WritingMode.getCorrespondingAbsoluteEdge( - getWritingMode(foNode), WritingMode.BEFORE); + return getCorrespondingAbsoluteStyleProperty( + foNode, WritingMode.BEFORE); } public boolean correspondingOverrides(FONode foNode) { diff --git a/src/java/org/apache/fop/fo/properties/BorderBottomStyle.java b/src/java/org/apache/fop/fo/properties/BorderBottomStyle.java index cabcbb659..f4aa8897c 100644 --- a/src/java/org/apache/fop/fo/properties/BorderBottomStyle.java +++ b/src/java/org/apache/fop/fo/properties/BorderBottomStyle.java @@ -53,8 +53,8 @@ extends BorderCommonStyleAbsolute { public int getCorrespondingRelativeProperty(FONode foNode) throws PropertyException { - return WritingMode.getCorrespondingRelativeEdge( - getWritingMode(foNode), WritingMode.BOTTOM); + return getCorrespondingRelativeStyleProperty( + foNode, WritingMode.BOTTOM); } public boolean correspondingOverrides(FONode foNode) { diff --git a/src/java/org/apache/fop/fo/properties/BorderCommonStyle.java b/src/java/org/apache/fop/fo/properties/BorderCommonStyle.java index 3df1b619c..186bd8e89 100644 --- a/src/java/org/apache/fop/fo/properties/BorderCommonStyle.java +++ b/src/java/org/apache/fop/fo/properties/BorderCommonStyle.java @@ -23,13 +23,14 @@ package org.apache.fop.fo.properties; import java.util.HashMap; import org.apache.fop.datatypes.Ints; +import org.apache.fop.fo.FONode; import org.apache.fop.fo.expr.PropertyException; /** * Pseudo-property class for common border style values occurring in a * number of classes. */ -public class BorderCommonStyle extends Property { +public class BorderCommonStyle extends AbstractCorrespondingProperty { public static final int HIDDEN = 1; public static final int DOTTED = 2; public static final int DASHED = 3; @@ -78,5 +79,10 @@ public class BorderCommonStyle extends Property { return rwEnums[index]; } + public int getCorrespondingProperty(FONode foNode) + throws PropertyException { + throw new PropertyException("Called from superclass"); + } + } diff --git a/src/java/org/apache/fop/fo/properties/BorderCommonStyleAbsolute.java b/src/java/org/apache/fop/fo/properties/BorderCommonStyleAbsolute.java index c92ba35cf..50683b76a 100644 --- a/src/java/org/apache/fop/fo/properties/BorderCommonStyleAbsolute.java +++ b/src/java/org/apache/fop/fo/properties/BorderCommonStyleAbsolute.java @@ -43,6 +43,11 @@ implements AbsoluteCorrespondingProperty { PropertyValue wm = foNode.getPropertyValue(PropNames.WRITING_MODE); return EnumType.getEnumValue(wm); } + + public int getCorrespondingProperty(FONode foNode) + throws PropertyException { + return getCorrespondingRelativeProperty(foNode); + } /* (non-Javadoc) * @see org.apache.fop.fo.properties.AbsoluteCorrespondingProperty#getCorrespondingRelativeProperty() */ @@ -50,10 +55,44 @@ implements AbsoluteCorrespondingProperty { throws PropertyException { throw new PropertyException("Called from superclass"); } + + /** Array of relative border style properties, + * indexed by relative edge constants */ + private static int[] relBorderStyleProps = { + PropNames.NO_PROPERTY + ,PropNames.BORDER_BEFORE_STYLE + ,PropNames.BORDER_AFTER_STYLE + ,PropNames.BORDER_START_STYLE + ,PropNames.BORDER_END_STYLE + }; + + /** + * Gets the relative border style property corresponding to the given + * absolute edge + * @param foNode the node on which the property is being defined + * @param absoluteEdge + * @return the relative border style property index + * @throws PropertyException + */ + protected int getCorrespondingRelativeStyleProperty( + FONode foNode, int absoluteEdge) + throws PropertyException { + int relEdge = WritingMode.getCorrespondingRelativeEdge( + getWritingMode(foNode), absoluteEdge); + return relBorderStyleProps[relEdge]; + } + /* (non-Javadoc) * @see org.apache.fop.fo.properties.AbsoluteCorrespondingProperty#overridesCorresponding() */ public boolean overridesCorresponding(FONode foNode) { return false; } + + /* (non-Javadoc) + * @see org.apache.fop.fo.properties.Property#isCorrespondingAbsolute() + */ + public static boolean isCorrespondingAbsolute() { + return true; + } } diff --git a/src/java/org/apache/fop/fo/properties/BorderCommonStyleRelative.java b/src/java/org/apache/fop/fo/properties/BorderCommonStyleRelative.java index 2d8f5bc40..202f1820a 100644 --- a/src/java/org/apache/fop/fo/properties/BorderCommonStyleRelative.java +++ b/src/java/org/apache/fop/fo/properties/BorderCommonStyleRelative.java @@ -43,6 +43,11 @@ implements RelativeCorrespondingProperty { PropertyValue wm = foNode.getPropertyValue(PropNames.WRITING_MODE); return EnumType.getEnumValue(wm); } + + public int getCorrespondingProperty(FONode foNode) + throws PropertyException { + return getCorrespondingAbsoluteProperty(foNode); + } /* (non-Javadoc) * @see org.apache.fop.fo.properties.RelativeCorrespondingProperty#getCorrespondingAbsoluteProperty(org.apache.fop.fo.FONode) */ @@ -50,10 +55,45 @@ implements RelativeCorrespondingProperty { throws PropertyException { throw new PropertyException("Called from superclass"); } + + /** Array of absolute border style properties, + * indexed by absolute edge constants */ + private static int[] absBorderStyleProps = { + PropNames.NO_PROPERTY + ,PropNames.BORDER_TOP_STYLE + ,PropNames.BORDER_BOTTOM_STYLE + ,PropNames.BORDER_LEFT_STYLE + ,PropNames.BORDER_RIGHT_STYLE + }; + + /** + * Gets the absolute border style property corresponding to the given + * relative edge + * @param foNode the node on which the property is being defined + * @param relativeEdge + * @return the absolute border style property index + * @throws PropertyException + */ + protected int getCorrespondingAbsoluteStyleProperty( + FONode foNode, int relativeEdge) + throws PropertyException { + int absEdge = WritingMode.getCorrespondingAbsoluteEdge( + getWritingMode(foNode), relativeEdge); + return absBorderStyleProps[absEdge]; + } + /* (non-Javadoc) * @see org.apache.fop.fo.properties.RelativeCorrespondingProperty#correspondingOverrides(org.apache.fop.fo.FONode) */ public boolean correspondingOverrides(FONode foNode) { return false; } + + /* (non-Javadoc) + * @see org.apache.fop.fo.properties.Property#isCorrespondingRelative() + */ + public static boolean isCorrespondingRelative() { + return true; + } + } diff --git a/src/java/org/apache/fop/fo/properties/BorderEndStyle.java b/src/java/org/apache/fop/fo/properties/BorderEndStyle.java index 9df311550..8b226728b 100644 --- a/src/java/org/apache/fop/fo/properties/BorderEndStyle.java +++ b/src/java/org/apache/fop/fo/properties/BorderEndStyle.java @@ -53,8 +53,8 @@ extends BorderCommonStyleRelative { public int getCorrespondingAbsoluteProperty(FONode foNode) throws PropertyException { - return WritingMode.getCorrespondingAbsoluteEdge( - getWritingMode(foNode), WritingMode.END); + return getCorrespondingAbsoluteStyleProperty( + foNode, WritingMode.END); } public boolean correspondingOverrides(FONode foNode) { diff --git a/src/java/org/apache/fop/fo/properties/BorderLeftStyle.java b/src/java/org/apache/fop/fo/properties/BorderLeftStyle.java index 79df9f81c..6b290ae1c 100644 --- a/src/java/org/apache/fop/fo/properties/BorderLeftStyle.java +++ b/src/java/org/apache/fop/fo/properties/BorderLeftStyle.java @@ -53,8 +53,8 @@ extends BorderCommonStyleAbsolute { public int getCorrespondingRelativeProperty(FONode foNode) throws PropertyException { - return WritingMode.getCorrespondingRelativeEdge( - getWritingMode(foNode), WritingMode.LEFT); + return getCorrespondingRelativeStyleProperty( + foNode, WritingMode.LEFT); } public boolean correspondingOverrides(FONode foNode) { diff --git a/src/java/org/apache/fop/fo/properties/BorderRightStyle.java b/src/java/org/apache/fop/fo/properties/BorderRightStyle.java index f1353831d..f18cb3bc5 100644 --- a/src/java/org/apache/fop/fo/properties/BorderRightStyle.java +++ b/src/java/org/apache/fop/fo/properties/BorderRightStyle.java @@ -53,8 +53,8 @@ extends BorderCommonStyleAbsolute { public int getCorrespondingRelativeProperty(FONode foNode) throws PropertyException { - return WritingMode.getCorrespondingRelativeEdge( - getWritingMode(foNode), WritingMode.RIGHT); + return getCorrespondingRelativeStyleProperty( + foNode, WritingMode.RIGHT); } public boolean correspondingOverrides(FONode foNode) { diff --git a/src/java/org/apache/fop/fo/properties/BorderStartStyle.java b/src/java/org/apache/fop/fo/properties/BorderStartStyle.java index aa3fd1971..5f07a465f 100644 --- a/src/java/org/apache/fop/fo/properties/BorderStartStyle.java +++ b/src/java/org/apache/fop/fo/properties/BorderStartStyle.java @@ -53,8 +53,8 @@ extends BorderCommonStyleRelative { public int getCorrespondingAbsoluteProperty(FONode foNode) throws PropertyException { - return WritingMode.getCorrespondingAbsoluteEdge( - getWritingMode(foNode), WritingMode.START); + return getCorrespondingAbsoluteStyleProperty( + foNode, WritingMode.START); } public boolean correspondingOverrides(FONode foNode) { diff --git a/src/java/org/apache/fop/fo/properties/BorderTopStyle.java b/src/java/org/apache/fop/fo/properties/BorderTopStyle.java index ea68c1b06..60f33913d 100644 --- a/src/java/org/apache/fop/fo/properties/BorderTopStyle.java +++ b/src/java/org/apache/fop/fo/properties/BorderTopStyle.java @@ -52,8 +52,8 @@ extends BorderCommonStyleAbsolute { public int getCorrespondingRelativeProperty(FONode foNode) throws PropertyException { - return WritingMode.getCorrespondingRelativeEdge( - getWritingMode(foNode), WritingMode.TOP); + return getCorrespondingRelativeStyleProperty( + foNode, WritingMode.TOP); } public boolean correspondingOverrides(FONode foNode) { diff --git a/src/java/org/apache/fop/fo/properties/CorrespondingProperty.java b/src/java/org/apache/fop/fo/properties/CorrespondingProperty.java new file mode 100644 index 000000000..e526098ce --- /dev/null +++ b/src/java/org/apache/fop/fo/properties/CorrespondingProperty.java @@ -0,0 +1,37 @@ +/* + * + * Copyright 2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Created on 21/04/2004 + * $Id$ + */ +package org.apache.fop.fo.properties; + +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.expr.PropertyException; + +/** + * Interface implemented by those Property classes which have + * corresponding properties. + * + * @author pbw + * @version $Revision$ $Name$ + */ +public interface CorrespondingProperty { + public int getWritingMode (FONode foNode) + throws PropertyException; + public int getCorrespondingProperty(FONode foNode) + throws PropertyException; +} diff --git a/src/java/org/apache/fop/fo/properties/Property.java b/src/java/org/apache/fop/fo/properties/Property.java index 8d370a516..12760a3a0 100644 --- a/src/java/org/apache/fop/fo/properties/Property.java +++ b/src/java/org/apache/fop/fo/properties/Property.java @@ -246,6 +246,24 @@ public class Property { public static Map enumHash = null; + /** + * Is this a corresponding absolute property? + * Such properties must override this method. + * @return answer + */ + public static boolean isCorrespondingAbsolute() { + return false; + } + + /** + * Is this a corresponding relative property? + * Such properties must override this method. + * @return answer + */ + public static boolean isCorrespondingRelative() { + return false; + } + public Property() {} /** diff --git a/src/java/org/apache/fop/fo/properties/RelativeCorrespondingProperty.java b/src/java/org/apache/fop/fo/properties/RelativeCorrespondingProperty.java index a8353acfe..b71ce994f 100644 --- a/src/java/org/apache/fop/fo/properties/RelativeCorrespondingProperty.java +++ b/src/java/org/apache/fop/fo/properties/RelativeCorrespondingProperty.java @@ -30,9 +30,8 @@ import org.apache.fop.fo.expr.PropertyException; * @author pbw * @version $Revision$ $Name$ */ -public interface RelativeCorrespondingProperty { - public int getWritingMode(FONode foNode) - throws PropertyException; +public interface RelativeCorrespondingProperty +extends CorrespondingProperty { public int getCorrespondingAbsoluteProperty(FONode foNode) throws PropertyException; public boolean correspondingOverrides(FONode foNode);