return enumValue;
}
+ /**
+ * Return the ENUM value from a PropertyValue.
+ * @param pv
+ * @return the ENUM constant
+ * @exception PropertyException if the <code>PropertyValue</code> is not
+ * an <code>EnumType</code>
+ */
+ public static int getEnumValue(PropertyValue pv)
+ throws PropertyException {
+ if (pv.getType() == PropertyValue.ENUM) {
+ return ((EnumType)pv).getEnumValue();
+ }
+ throw new PropertyException("PropertyValue not an ENUM type");
+ }
+
/**
* @return the <tt>String</tt> enumeration token.
*/
--- /dev/null
+/*
+ *
+ * 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 20/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 <code>Property</code> classes which have
+ * corresponding <b><i>relative</i></b> properties; <i>i.e.</i> which are
+ * themselves corresponding <i>absolute</i> properties.
+ *
+ * @author pbw
+ * @version $Revision$ $Name$
+ */
+public interface AbsoluteCorrespondingProperty {
+ public int getWritingMode (FONode foNode)
+ throws PropertyException;
+ public int getCorrespondingRelativeProperty(FONode foNode)
+ throws PropertyException;
+ public boolean overridesCorresponding(FONode foNode);
+}
*/
package org.apache.fop.fo.properties;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.expr.PropertyException;
-public class BorderAfterStyle extends BorderCommonStyle {
+
+public class BorderAfterStyle
+extends BorderCommonStyleRelative {
public static final int dataTypes = ENUM | NONE | INHERIT;
public int getDataTypes() {
return inherited;
}
+ public int getCorrespondingAbsoluteProperty(FONode foNode)
+ throws PropertyException {
+ return WritingMode.getCorrespondingAbsoluteEdge(
+ getWritingMode(foNode), WritingMode.AFTER);
+ }
+ public boolean correspondingOverrides(FONode foNode) {
+ return false;
+ }
}
*/
package org.apache.fop.fo.properties;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.expr.PropertyException;
-public class BorderBeforeStyle extends BorderCommonStyle {
+
+public class BorderBeforeStyle
+extends BorderCommonStyleRelative {
public static final int dataTypes = ENUM | NONE | INHERIT;
public int getDataTypes() {
return inherited;
}
+ public int getCorrespondingAbsoluteProperty(FONode foNode)
+ throws PropertyException {
+ return WritingMode.getCorrespondingAbsoluteEdge(
+ getWritingMode(foNode), WritingMode.BEFORE);
+ }
+
+ public boolean correspondingOverrides(FONode foNode) {
+ return false;
+ }
}
*/
package org.apache.fop.fo.properties;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.expr.PropertyException;
-public class BorderBottomStyle extends BorderCommonStyle {
+
+public class BorderBottomStyle
+extends BorderCommonStyleAbsolute {
public static final int dataTypes = ENUM | NONE | INHERIT;
public int getDataTypes() {
return inherited;
}
+ public int getCorrespondingRelativeProperty(FONode foNode)
+ throws PropertyException {
+ return WritingMode.getCorrespondingRelativeEdge(
+ getWritingMode(foNode), WritingMode.BOTTOM);
+ }
+
+ public boolean correspondingOverrides(FONode foNode) {
+ return false;
+ }
+
}
--- /dev/null
+/*
+ *
+ * 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 20/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;
+
+/**
+ * Base class for border-<absolute>-style properties, providing the
+ * methods necessary to resolve corresponding relative properties.
+ *
+ * @author pbw
+ * @version $Revision$ $Name$
+ */
+public class BorderCommonStyleAbsolute
+extends BorderCommonStyle
+implements AbsoluteCorrespondingProperty {
+ /* (non-Javadoc)
+ * @see org.apache.fop.fo.properties.AbsoluteCorrespondingProperty#getWritingMode()
+ */
+ 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.AbsoluteCorrespondingProperty#getCorrespondingRelativeProperty()
+ */
+ public int getCorrespondingRelativeProperty(FONode foNode)
+ throws PropertyException {
+ throw new PropertyException("Called from superclass");
+ }
+ /* (non-Javadoc)
+ * @see org.apache.fop.fo.properties.AbsoluteCorrespondingProperty#overridesCorresponding()
+ */
+ public boolean overridesCorresponding(FONode foNode) {
+ return false;
+ }
+}
--- /dev/null
+/*
+ *
+ * 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 20/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;
+
+/**
+ * Base class for border-<relative>-style properties, providing the
+ * methods necessary to resolve corresponding absolute properties.
+ *
+ * @author pbw
+ * @version $Revision$ $Name$
+ */
+public class BorderCommonStyleRelative
+extends BorderCommonStyle
+implements RelativeCorrespondingProperty {
+ /* (non-Javadoc)
+ * @see org.apache.fop.fo.properties.RelativeCorrespondingProperty#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.RelativeCorrespondingProperty#getCorrespondingAbsoluteProperty(org.apache.fop.fo.FONode)
+ */
+ public int getCorrespondingAbsoluteProperty(FONode foNode)
+ throws PropertyException {
+ throw new PropertyException("Called from superclass");
+ }
+ /* (non-Javadoc)
+ * @see org.apache.fop.fo.properties.RelativeCorrespondingProperty#correspondingOverrides(org.apache.fop.fo.FONode)
+ */
+ public boolean correspondingOverrides(FONode foNode) {
+ return false;
+ }
+}
*/
package org.apache.fop.fo.properties;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.expr.PropertyException;
-public class BorderEndStyle extends BorderCommonStyle {
+
+public class BorderEndStyle
+extends BorderCommonStyleRelative {
public static final int dataTypes = ENUM | NONE | INHERIT;
public int getDataTypes() {
return inherited;
}
+ public int getCorrespondingAbsoluteProperty(FONode foNode)
+ throws PropertyException {
+ return WritingMode.getCorrespondingAbsoluteEdge(
+ getWritingMode(foNode), WritingMode.END);
+ }
+
+ public boolean correspondingOverrides(FONode foNode) {
+ return false;
+ }
}
*/
package org.apache.fop.fo.properties;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.expr.PropertyException;
-public class BorderLeftStyle extends BorderCommonStyle {
+
+public class BorderLeftStyle
+extends BorderCommonStyleAbsolute {
public static final int dataTypes = ENUM | NONE | INHERIT;
public int getDataTypes() {
return inherited;
}
+ public int getCorrespondingRelativeProperty(FONode foNode)
+ throws PropertyException {
+ return WritingMode.getCorrespondingRelativeEdge(
+ getWritingMode(foNode), WritingMode.LEFT);
+ }
+ public boolean correspondingOverrides(FONode foNode) {
+ return false;
+ }
}
*/
package org.apache.fop.fo.properties;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.expr.PropertyException;
-public class BorderRightStyle extends BorderCommonStyle {
+
+public class BorderRightStyle
+extends BorderCommonStyleAbsolute {
public static final int dataTypes = ENUM | NONE | INHERIT;
public int getDataTypes() {
return inherited;
}
+ public int getCorrespondingRelativeProperty(FONode foNode)
+ throws PropertyException {
+ return WritingMode.getCorrespondingRelativeEdge(
+ getWritingMode(foNode), WritingMode.RIGHT);
+ }
+
+ public boolean correspondingOverrides(FONode foNode) {
+ return false;
+ }
}
*/
package org.apache.fop.fo.properties;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.expr.PropertyException;
-public class BorderStartStyle extends BorderCommonStyle {
+
+public class BorderStartStyle
+extends BorderCommonStyleRelative {
public static final int dataTypes = ENUM | NONE | INHERIT;
public int getDataTypes() {
return inherited;
}
+ public int getCorrespondingAbsoluteProperty(FONode foNode)
+ throws PropertyException {
+ return WritingMode.getCorrespondingAbsoluteEdge(
+ getWritingMode(foNode), WritingMode.START);
+ }
+
+ public boolean correspondingOverrides(FONode foNode) {
+ return false;
+ }
}
*/
package org.apache.fop.fo.properties;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.expr.PropertyException;
-public class BorderTopStyle extends BorderCommonStyle {
+
+public class BorderTopStyle
+extends BorderCommonStyleAbsolute {
public static final int dataTypes = ENUM | NONE | INHERIT;
public int getDataTypes() {
return initialValueType;
}
-
public static final int inherited = NO;
public int getInherited() {
return inherited;
}
+ public int getCorrespondingRelativeProperty(FONode foNode)
+ throws PropertyException {
+ return WritingMode.getCorrespondingRelativeEdge(
+ getWritingMode(foNode), WritingMode.TOP);
+ }
+
+ public boolean correspondingOverrides(FONode foNode) {
+ return false;
+ }
}
--- /dev/null
+/*
+ *
+ * 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 20/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 <code>Property</code> classes which have
+ * corresponding <b><i>absolute</i></b> properties; <i>i.e.</i> which are
+ * themselves corresponding <i>relative</i> properties.
+ *
+ * @author pbw
+ * @version $Revision$ $Name$
+ */
+public interface RelativeCorrespondingProperty {
+ public int getWritingMode(FONode foNode)
+ throws PropertyException;
+ public int getCorrespondingAbsoluteProperty(FONode foNode)
+ throws PropertyException;
+ public boolean correspondingOverrides(FONode foNode);
+}
import java.util.HashMap;
+import org.apache.fop.datastructs.ROIntArray;
import org.apache.fop.datatypes.EnumType;
import org.apache.fop.datatypes.Ints;
import org.apache.fop.datatypes.PropertyValue;
public static final int LR_TB = 1;
public static final int RL_TB = 2;
public static final int TB_RL = 3;
- public static final int LR = 4;
- public static final int RL = 5;
- public static final int TB = 6;
+ public static final int LR = 1;
+ public static final int RL = 2;
+ public static final int TB = 3;
+ public static final int MAX_WRITING_MODE = TB_RL;
+
public PropertyValue getInitialValue(int property)
throws PropertyException
{
return inherited;
}
-
private static final String[] rwEnums = {
null
,"lr-tb"
,"rl-tb"
,"tb-rl"
- ,"lr"
- ,"rl"
- ,"tb"
};
+
+ private static final String[] rwEnumsSynon = {
+ null
+ ,"lr"
+ ,"rl"
+ ,"tb"
+ };
+
private static final HashMap rwEnumHash;
static {
- rwEnumHash = new HashMap((int)(rwEnums.length / 0.75) + 1);
+ rwEnumHash = new HashMap(9);
for (int i = 1; i < rwEnums.length; i++ ) {
rwEnumHash.put(rwEnums[i],
- Ints.consts.get(i));
+ Ints.consts.get(i));
+ rwEnumHash.put(rwEnumsSynon[i],
+ Ints.consts.get(i));
}
}
public int getEnumIndex(String enumval)
throw new PropertyException("index out of range: " + index);
return rwEnums[index];
}
+
+ public static final int BEFORE = 1;
+ public static final int AFTER = 2;
+ public static final int START = 3;
+ public static final int END = 4;
+
+ public static final int MAX_EDGE = END;
+
+ private static final String[] relativeEdges = {
+ null
+ ,"before"
+ ,"after"
+ ,"start"
+ ,"end"
+ };
+
+ public static final int TOP = 1;
+ public static final int BOTTOM = 2;
+ public static final int LEFT = 3;
+ public static final int RIGHT = 4;
+
+ private static final String[] absoluteEdges = {
+ null
+ ,"top"
+ ,"bottom"
+ ,"left"
+ ,"right"
+ };
+
+ private static final int[] lr_tbAbsRelMap = {
+ 0, BEFORE, AFTER, START, END
+ };
+
+ private static final int[] lr_tbRelAbsMap = {
+ 0, TOP, BOTTOM, LEFT, RIGHT
+ };
+
+ private static final int[] rl_tbAbsRelMap = {
+ 0, BEFORE, AFTER, END, START
+ };
+
+ private static final int[] rl_tbRelAbsMap = {
+ 0, TOP, BOTTOM, RIGHT, LEFT
+ };
+
+ private static final int[] tb_rlAbsRelMap = {
+ 0, START, END, AFTER, BEFORE
+ };
+
+ private static final int[] tb_rlRelAbsMap = {
+ 0, RIGHT, LEFT, TOP, BOTTOM
+ };
+
+ // top-to-bottom, left-to-right, e.g., Mongolian
+ // Currently unused
+ private static final int[] tb_lrAbsRelMap = {
+ 0, START, END, BEFORE, AFTER
+ };
+
+ private static int[] tb_lrRelAbsMap = {
+ 0, LEFT, RIGHT, TOP, BOTTOM
+ };
+
+ private static final ROIntArray[] relAbsROMaps = {
+ null
+ ,new ROIntArray(lr_tbRelAbsMap)
+ ,new ROIntArray(rl_tbRelAbsMap)
+ ,new ROIntArray(tb_rlRelAbsMap)
+ };
+
+ private static final ROIntArray[] absRelROMaps = {
+ null
+ ,new ROIntArray(lr_tbAbsRelMap)
+ ,new ROIntArray(rl_tbAbsRelMap)
+ ,new ROIntArray(tb_rlAbsRelMap)
+ };
+
+ /**
+ * Gets the relative-to-absolute map for the given writing mode.
+ * <code>writingMode</code> is the enumerated constant <code>int</code>
+ * value of the writing mode, from the set <code>LR_TB</code>,
+ * <code>RL_TB</code> and <code>TB_RL</code>.
+ * The result is an <code>ROIntArray</code> containing the set of absolute
+ * edge integer eumeration constants <code>TOP</code>, <code>BOTTOM</code>,
+ * <code>LEFT</code> and <code>RIGHT</code>, indexed by the relative edge
+ * integer eumeration constants <code>BEFORE</code>, <code>AFTER</code>,
+ * <code>START</code> and <code>END</code>, as appropriate for the given
+ * writing mode.
+ * @param writingMode the enumerated value of the writing mode
+ * @return an array mapping from relative edges to absolute edges for the
+ * given writing mode.
+ *
+ * @throws PropertyException if the writing mode is out of range
+ */
+ public static ROIntArray getRelAbsMap(int writingMode)
+ throws PropertyException {
+ if (writingMode > 0 && writingMode <= MAX_WRITING_MODE) {
+ return relAbsROMaps[writingMode];
+ }
+ throw new PropertyException(
+ "Writing mode out of range:" + writingMode);
+ }
+
+ /**
+ * Gets the absolute-to-relative map for the given writing mode.
+ * <code>writingMode</code> is the enumerated constant <code>int</code>
+ * value of the writing mode, from the set <code>LR_TB</code>,
+ * <code>RL_TB</code> and <code>TB_RL</code>.
+ * The result is an <code>ROIntArray</code> containing the relative edge
+ * integer eumeration constants <code>BEFORE</code>, <code>AFTER</code>,
+ * <code>START</code> and <code>END</code>, indexed by the set of absolute
+ * edge integer eumeration constants <code>TOP</code>, <code>BOTTOM</code>,
+ * <code>LEFT</code> and <code>RIGHT</code>, as appropriate for the given
+ * writing mode.
+ * @param writingMode the enumerated value of the writing mode
+ * @return an array mapping from absolute edges to relative edges for the
+ * given writing mode.
+ *
+ * @throws PropertyException if the writing mode is out of range
+ */
+ public static ROIntArray getAbsRelMap(int writingMode)
+ throws PropertyException {
+ if (writingMode > 0 && writingMode <= MAX_WRITING_MODE) {
+ return absRelROMaps[writingMode];
+ }
+ throw new PropertyException(
+ "Writing mode out of range:" + writingMode);
+ }
+
+ private static final int[][] absRelMaps = {
+ null
+ ,lr_tbAbsRelMap
+ ,rl_tbAbsRelMap
+ ,tb_rlAbsRelMap
+ };
+
+ /**
+ * Gets the relative edge corresponding to the given absolute edge for the
+ * given writing mode.
+ * <code>writingMode</code> is the enumerated constant <code>int</code>
+ * value of the writing mode, from the set <code>LR_TB</code>,
+ * <code>RL_TB</code> and <code>TB_RL</code>.
+ * <code>absoluteEdge</code> is the enumerated constant <code>int</code>
+ * value of the absolute edge, from the set <code>TOP</code>,
+ * <code>BOTTOM</code>, <code>LEFT</code> and <code>RIGHT</code>.
+ * The result is from the enumerated constant <code>int</code> set
+ * <code>BEFORE</code>, <code>AFTER</code>, <code>START</code> and
+ * <code>END</code>, as appropriate for the given writing mode.
+ * @param writingMode the enumeration value of the writing mode
+ * @param absoluteEdge the enumeration value of the absolute edge
+ * @return the enumeration value of the corresponding relative edge
+ * @throws PropertyException if the writing mode or absolute edge is
+ * out of range
+ */
+ public static int getCorrespondingRelativeEdge(
+ int writingMode, int absoluteEdge)
+ throws PropertyException {
+ if (writingMode <= 0 || writingMode > MAX_WRITING_MODE) {
+ throw new PropertyException(
+ "Writing mode out of range:" + writingMode);
+ }
+ if (absoluteEdge <= 0 || absoluteEdge > MAX_EDGE) {
+ throw new PropertyException(
+ "Absolute edge out of range:" + absoluteEdge);
+ }
+ return absRelMaps[writingMode][absoluteEdge];
+ }
+
+ private static final int[][] relAbsMaps = {
+ null
+ ,lr_tbRelAbsMap
+ ,rl_tbRelAbsMap
+ ,tb_rlRelAbsMap
+ };
+
+
+ /**
+ * Gets the absolute edge corresponding to the given relative edge for the
+ * given writing mode.
+ * <code>writingMode</code> is the enumerated constant <code>int</code>
+ * value of the writing mode, from the set <code>LR_TB</code>,
+ * <code>RL_TB</code> and <code>TB_RL</code>.
+ * <code>relativeEdge</code> is the enumerated constant <code>int</code>
+ * value of the relative edge, from the set <code>BEFORE</code>,
+ * <code>AFTER</code>, <code>START</code> and <code>END</code>.
+ * The result is from the enumerated constant <code>int</code> set
+ * <code>TOP</code>, <code>BOTTOM</code>, <code>LEFT</code> and
+ * <code>RIGHT</code>, as appropriate for the given writing mode.
+ * @param writingMode the enumeration value of the writing mode
+ * @param relativeEdge the enumeration value of the relative edge
+ * @return the enumeration value of the corresponding absolute edge
+ * @throws PropertyException if the writing mode or relative edge is
+ * out of range
+ */
+ public static int getCorrespondingAbsoluteEdge(
+ int writingMode, int relativeEdge)
+ throws PropertyException {
+ if (writingMode <= 0 || writingMode > MAX_WRITING_MODE) {
+ throw new PropertyException(
+ "Writing mode out of range:" + writingMode);
+ }
+ if (relativeEdge <= 0 || relativeEdge > MAX_EDGE) {
+ throw new PropertyException(
+ "Relative edge out of range:" + relativeEdge);
+ }
+ return relAbsMaps[writingMode][relativeEdge];
+ }
+
}