From 58b2d92b2d60f6390ac98c0e1791e690d72631da Mon Sep 17 00:00:00 2001 From: Finn Bock Date: Mon, 2 Feb 2004 15:01:41 +0000 Subject: [PATCH] Phase 2 of bug 26434. - Roll the datatypes logic into the property classes. PR: 26434. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197312 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/datatypes/AutoLength.java | 8 +- .../org/apache/fop/datatypes/ColorType.java | 691 +---------------- .../org/apache/fop/datatypes/CondLength.java | 127 --- .../org/apache/fop/datatypes/FixedLength.java | 9 +- src/java/org/apache/fop/datatypes/Keep.java | 157 ---- src/java/org/apache/fop/datatypes/Length.java | 93 +-- .../org/apache/fop/datatypes/LengthPair.java | 112 --- .../org/apache/fop/datatypes/LengthRange.java | 231 ------ .../datatypes/LinearCombinationLength.java | 6 +- .../org/apache/fop/datatypes/MixedLength.java | 21 +- .../apache/fop/datatypes/PercentLength.java | 9 +- src/java/org/apache/fop/datatypes/Space.java | 133 ---- .../apache/fop/datatypes/TableColLength.java | 9 +- .../org/apache/fop/fo/ColorTypeProperty.java | 720 +++++++++++++++++- .../org/apache/fop/fo/CondLengthProperty.java | 82 +- src/java/org/apache/fop/fo/EnumProperty.java | 2 +- .../org/apache/fop/fo/FOPropertyMapping.java | 4 +- src/java/org/apache/fop/fo/KeepProperty.java | 100 ++- .../org/apache/fop/fo/LengthPairProperty.java | 58 +- .../org/apache/fop/fo/LengthProperty.java | 117 ++- .../apache/fop/fo/LengthRangeProperty.java | 182 ++++- .../org/apache/fop/fo/NumberProperty.java | 11 +- src/java/org/apache/fop/fo/Property.java | 28 +- src/java/org/apache/fop/fo/SpaceProperty.java | 88 ++- .../org/apache/fop/fo/expr/AbsFunction.java | 4 +- .../apache/fop/fo/expr/BodyStartFunction.java | 6 +- .../apache/fop/fo/expr/LabelEndFunction.java | 9 +- .../org/apache/fop/fo/expr/MaxFunction.java | 6 +- .../org/apache/fop/fo/expr/MinFunction.java | 6 +- src/java/org/apache/fop/fo/expr/Numeric.java | 429 ----------- .../apache/fop/fo/expr/NumericProperty.java | 383 +++++++++- .../fop/fo/expr/PPColWidthFunction.java | 3 +- .../apache/fop/fo/expr/PropertyParser.java | 43 +- .../apache/fop/fo/expr/RGBColorFunction.java | 4 +- .../apache/fop/fo/flow/ExternalGraphic.java | 10 +- src/java/org/apache/fop/fo/flow/Table.java | 4 +- .../properties/BorderWidthPropertyMaker.java | 1 - .../fo/properties/CommonBorderAndPadding.java | 12 +- .../fo/properties/IndentPropertyMaker.java | 7 +- .../properties/LineHeightPropertyMaker.java | 3 +- .../render/rtf/TableAttributesConverter.java | 2 +- .../render/rtf/TextAttributesConverter.java | 6 +- src/java/org/apache/fop/traits/SpaceVal.java | 5 +- 43 files changed, 1747 insertions(+), 2194 deletions(-) delete mode 100644 src/java/org/apache/fop/datatypes/CondLength.java delete mode 100644 src/java/org/apache/fop/datatypes/Keep.java delete mode 100644 src/java/org/apache/fop/datatypes/LengthPair.java delete mode 100644 src/java/org/apache/fop/datatypes/LengthRange.java delete mode 100644 src/java/org/apache/fop/datatypes/Space.java delete mode 100644 src/java/org/apache/fop/fo/expr/Numeric.java diff --git a/src/java/org/apache/fop/datatypes/AutoLength.java b/src/java/org/apache/fop/datatypes/AutoLength.java index d31f92303..cafe3a3d7 100644 --- a/src/java/org/apache/fop/datatypes/AutoLength.java +++ b/src/java/org/apache/fop/datatypes/AutoLength.java @@ -50,10 +50,12 @@ */ package org.apache.fop.datatypes; +import org.apache.fop.fo.LengthProperty; + /** * A length quantity in XSL which is specified as "auto". */ -public class AutoLength extends Length { +public class AutoLength extends LengthProperty { /** * @see org.apache.fop.datatypes.Length#isAuto() @@ -68,9 +70,9 @@ public class AutoLength extends Length { // } /** - * @see java.lang.Object#toString() + * @see org.apache.fop.fo.Property#getString() */ - public String toString() { + public String getString() { return "auto"; } diff --git a/src/java/org/apache/fop/datatypes/ColorType.java b/src/java/org/apache/fop/datatypes/ColorType.java index 461983ea0..f0c20f3e1 100644 --- a/src/java/org/apache/fop/datatypes/ColorType.java +++ b/src/java/org/apache/fop/datatypes/ColorType.java @@ -51,716 +51,39 @@ package org.apache.fop.datatypes; import java.awt.Color; -import java.io.Serializable; -import java.util.StringTokenizer; /** * A colour quantity in XSL. */ -public class ColorType implements Serializable { - - /** - * the red component - */ - protected float red = 0f; - - /** - * the green component - */ - protected float green = 0f; - - /** - * the blue component - */ - protected float blue = 0f; - - /** - * the alpha component (indicator of opaque-ness) - * 0.0 - 1.0; 0.0 is completely transparent; 1.0 is completely opaque - * see definition at http://java.sun.com/j2se/1.3/docs/api/java/awt/Color.html - */ - protected float alpha = 1f; - - /** - * Main constructor - * @param red red component - * @param green green component - * @param blue blue component - */ - public ColorType(float red, float green, float blue) { - this.red = red; - this.green = green; - this.blue = blue; - } - - /** - * Set the colour given a particular String specifying either a - * colour name or #RGB or #RRGGBB - * @param value RGB value as String to be parsed - */ - public ColorType(String value) { - if (value.startsWith("#")) { - try { - if (value.length() == 4) { - // note: divide by 15 so F = FF = 1 and so on - this.red = Integer.parseInt(value.substring(1, 2), 16) - / 15f; - this.green = Integer.parseInt(value.substring(2, 3), 16) - / 15f; - this.blue = Integer.parseInt(value.substring(3), 16) - / 15f; - } else if (value.length() == 7) { - // note: divide by 255 so FF = 1 - this.red = Integer.parseInt(value.substring(1, 3), 16) - / 255f; - this.green = Integer.parseInt(value.substring(3, 5), 16) - / 255f; - this.blue = Integer.parseInt(value.substring(5), 16) - / 255f; - } else { - this.red = 0; - this.green = 0; - this.blue = 0; - //log.error("unknown colour format. Must be #RGB or #RRGGBB"); - } - } catch (Exception e) { - this.red = 0; - this.green = 0; - this.blue = 0; - //log.error("unknown colour format. Must be #RGB or #RRGGBB"); - } - } else if (value.startsWith("rgb(")) { - int poss = value.indexOf("("); - int pose = value.indexOf(")"); - if (poss != -1 && pose != -1) { - value = value.substring(poss + 1, pose); - StringTokenizer st = new StringTokenizer(value, ","); - try { - if (st.hasMoreTokens()) { - String str = st.nextToken().trim(); - if (str.endsWith("%")) { - this.red = - Integer.parseInt(str.substring(0, str.length() - 1)) - * 2.55f; - } else { - this.red = Integer.parseInt(str) / 255f; - } - } - if (st.hasMoreTokens()) { - String str = st.nextToken().trim(); - if (str.endsWith("%")) { - this.green = - Integer.parseInt(str.substring(0, str.length() - 1)) - * 2.55f; - } else { - this.green = Integer.parseInt(str) / 255f; - } - } - if (st.hasMoreTokens()) { - String str = st.nextToken().trim(); - if (str.endsWith("%")) { - this.blue = - Integer.parseInt(str.substring(0, str.length() - 1)) - * 2.55f; - } else { - this.blue = Integer.parseInt(str) / 255f; - } - } - } catch (Exception e) { - this.red = 0; - this.green = 0; - this.blue = 0; - //log.error("unknown colour format. Must be #RGB or #RRGGBB"); - } - } - } else if (value.startsWith("url(")) { - // refers to a gradient - } else { - if (value.toLowerCase().equals("transparent")) { - this.red = 0; - this.green = 0; - this.blue = 0; - this.alpha = 0; - } else { - boolean found = false; - for (int count = 0; count < NAMES.length; count++) { - if (value.toLowerCase().equals(NAMES[count])) { - this.red = VALUES[count][0] / 255f; - this.green = VALUES[count][1] / 255f; - this.blue = VALUES[count][2] / 255f; - found = true; - break; - } - } - if (!found) { - this.red = 0; - this.green = 0; - this.blue = 0; - //log.error("unknown colour name: " - // + value); - } - } - } - } +public interface ColorType { /** * Returns the blue component of the color. * @return float a value between 0.0 and 1.0 */ - public float getBlue() { - return this.blue; - } + public float getBlue(); /** * Returns the green component of the color. * @return float a value between 0.0 and 1.0 */ - public float getGreen() { - return this.green; - } + public float getGreen(); /** * Returns the red component of the color. * @return float a value between 0.0 and 1.0 */ - public float getRed() { - return this.red; - } + public float getRed(); /** * Returns the alpha (degree of opaque-ness) component of the color. * @return float a value between 0.0 (fully transparent) and 1.0 (fully opaque) */ - public float getAlpha() { - return this.alpha; - } + public float getAlpha(); /** * Returns an AWT instance of this color * @return float the AWT color represented by this ColorType instance */ - public Color getAWTColor() { - return new Color(this.red, this.green, this.blue, this.alpha); - } - - /** - * @param floatValue value (between 0.0 and 1.0) of color channel - * @return integer equivalent (between 0 and 255) - */ - public static int convertChannelToInteger (float floatValue) { - if (floatValue > 1.0) { - floatValue = 1.0f; - } - if (floatValue < 0) { - floatValue = 0; - } - return (int) (floatValue * 255); - } - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer sbuf = new StringBuffer(8); - sbuf.append('#'); - String s = Integer.toHexString((int)(red * 255.0)); - if (s.length() == 1) { - sbuf.append('0'); - } - sbuf.append(s); - s = Integer.toHexString((int)(green * 255.0)); - if (s.length() == 1) { - sbuf.append('0'); - } - sbuf.append(s); - s = Integer.toHexString((int)(blue * 255.0)); - if (s.length() == 1) { - sbuf.append('0'); - } - sbuf.append(s); - return sbuf.toString(); - } - - /** The names of the predefined colors */ - protected static final String[] NAMES = { - "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", - "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", - "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", - "cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue", - "darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkgrey", - "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange", - "darkorchid", "darkred", "darksalmon", "darkseagreen", - "darkslateblue", "darkslategray", "darkslategrey", "darkturquoise", - "darkviolet", "deeppink", "deepskyblue", "dimgray", "dimgrey", - "dodgerblue", "firebrick", "floralwhite", "forestgreen", "fuchsia", - "gainsboro", "lightpink", "lightsalmon", "lightseagreen", - "lightskyblue", "lightslategray", "lightslategrey", "lightsteelblue", - "lightyellow", "lime", "limegreen", "linen", "magenta", "maroon", - "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", - "mediumseagreen", "mediumslateblue", "mediumspringgreen", - "mediumturquoise", "mediumvioletred", "midnightblue", "mintcream", - "mistyrose", "moccasin", "navajowhite", "navy", "oldlace", "olive", - "olivedrab", "orange", "orangered", "orchid", "palegoldenrod", - "palegreen", "paleturquoise", "palevioletred", "papayawhip", - "peachpuff", "peru", "pink", "plum", "powderblue", "purple", "red", - "rosybrown", "royalblue", "saddlebrown", "salmon", "ghostwhite", - "gold", "goldenrod", "gray", "grey", "green", "greenyellow", - "honeydew", "hotpink", "indianred", "indigo", "ivory", "khaki", - "lavender", "lavenderblush", "lawngreen", "lemonchiffon", - "lightblue", "lightcoral", "lightcyan", "lightgoldenrodyellow", - "lightgray", "lightgreen", "lightgrey", "sandybrown", "seagreen", - "seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", - "slategrey", "snow", "springgreen", "steelblue", "tan", "teal", - "thistle", "tomato", "turquoise", "violet", "wheat", "white", - "whitesmoke", "yellow", "yellowgreen" - }; - - /** The color values for the predefined colors */ - protected static final int[][] VALUES = { - { - 240, 248, 255 - }, { - 250, 235, 215 - }, { - 0, 255, 255 - }, { - 127, 255, 212 - }, { - 240, 255, 255 - }, { - 245, 245, 220 - }, { - 255, 228, 196 - }, { - 0, 0, 0 - }, { - 255, 235, 205 - }, { - 0, 0, 255 - }, { - 138, 43, 226 - }, { - 165, 42, 42 - }, { - 222, 184, 135 - }, { - 95, 158, 160 - }, { - 127, 255, 0 - }, { - 210, 105, 30 - }, { - 255, 127, 80 - }, { - 100, 149, 237 - }, { - 255, 248, 220 - }, { - 220, 20, 60 - }, { - 0, 255, 255 - }, { - 0, 0, 139 - }, { - 0, 139, 139 - }, { - 184, 134, 11 - }, { - 169, 169, 169 - }, { - 0, 100, 0 - }, { - 169, 169, 169 - }, { - 189, 183, 107 - }, { - 139, 0, 139 - }, { - 85, 107, 47 - }, { - 255, 140, 0 - }, { - 153, 50, 204 - }, { - 139, 0, 0 - }, { - 233, 150, 122 - }, { - 143, 188, 143 - }, { - 72, 61, 139 - }, { - 47, 79, 79 - }, { - 47, 79, 79 - }, { - 0, 206, 209 - }, { - 148, 0, 211 - }, { - 255, 20, 147 - }, { - 0, 191, 255 - }, { - 105, 105, 105 - }, { - 105, 105, 105 - }, { - 30, 144, 255 - }, { - 178, 34, 34 - }, { - 255, 250, 240 - }, { - 34, 139, 34 - }, { - 255, 0, 255 - }, { - 220, 220, 220 - }, { - 255, 182, 193 - }, { - 255, 160, 122 - }, { - 32, 178, 170 - }, { - 135, 206, 250 - }, { - 119, 136, 153 - }, { - 119, 136, 153 - }, { - 176, 196, 222 - }, { - 255, 255, 224 - }, { - 0, 255, 0 - }, { - 50, 205, 50 - }, { - 250, 240, 230 - }, { - 255, 0, 255 - }, { - 128, 0, 0 - }, { - 102, 205, 170 - }, { - 0, 0, 205 - }, { - 186, 85, 211 - }, { - 147, 112, 219 - }, { - 60, 179, 113 - }, { - 123, 104, 238 - }, { - 0, 250, 154 - }, { - 72, 209, 204 - }, { - 199, 21, 133 - }, { - 25, 25, 112 - }, { - 245, 255, 250 - }, { - 255, 228, 225 - }, { - 255, 228, 181 - }, { - 255, 222, 173 - }, { - 0, 0, 128 - }, { - 253, 245, 230 - }, { - 128, 128, 0 - }, { - 107, 142, 35 - }, { - 255, 165, 0 - }, { - 255, 69, 0 - }, { - 218, 112, 214 - }, { - 238, 232, 170 - }, { - 152, 251, 152 - }, { - 175, 238, 238 - }, { - 219, 112, 147 - }, { - 255, 239, 213 - }, { - 255, 218, 185 - }, { - 205, 133, 63 - }, { - 255, 192, 203 - }, { - 221, 160, 221 - }, { - 176, 224, 230 - }, { - 128, 0, 128 - }, { - 255, 0, 0 - }, { - 188, 143, 143 - }, { - 65, 105, 225 - }, { - 139, 69, 19 - }, { - 250, 128, 114 - }, { - 248, 248, 255 - }, { - 255, 215, 0 - }, { - 218, 165, 32 - }, { - 128, 128, 128 - }, { - 128, 128, 128 - }, { - 0, 128, 0 - }, { - 173, 255, 47 - }, { - 240, 255, 240 - }, { - 255, 105, 180 - }, { - 205, 92, 92 - }, { - 75, 0, 130 - }, { - 255, 255, 240 - }, { - 240, 230, 140 - }, { - 230, 230, 250 - }, { - 255, 240, 245 - }, { - 124, 252, 0 - }, { - 255, 250, 205 - }, { - 173, 216, 230 - }, { - 240, 128, 128 - }, { - 224, 255, 255 - }, { - 250, 250, 210 - }, { - 211, 211, 211 - }, { - 144, 238, 144 - }, { - 211, 211, 211 - }, { - 244, 164, 96 - }, { - 46, 139, 87 - }, { - 255, 245, 238 - }, { - 160, 82, 45 - }, { - 192, 192, 192 - }, { - 135, 206, 235 - }, { - 106, 90, 205 - }, { - 112, 128, 144 - }, { - 112, 128, 144 - }, { - 255, 250, 250 - }, { - 0, 255, 127 - }, { - 70, 130, 180 - }, { - 210, 180, 140 - }, { - 0, 128, 128 - }, { - 216, 191, 216 - }, { - 255, 99, 71 - }, { - 64, 224, 208 - }, { - 238, 130, 238 - }, { - 245, 222, 179 - }, { - 255, 255, 255 - }, { - 245, 245, 245 - }, { - 255, 255, 0 - }, { - 154, 205, 50 - } - }; -} - -/* - * aliceblue rgb(240, 248, 255) - * antiquewhite rgb(250, 235, 215) - * aqua rgb( 0, 255, 255) - * aquamarine rgb(127, 255, 212) - * azure rgb(240, 255, 255) - * beige rgb(245, 245, 220) - * bisque rgb(255, 228, 196) - * black rgb( 0, 0, 0) - * blanchedalmond rgb(255, 235, 205) - * blue rgb( 0, 0, 255) - * blueviolet rgb(138, 43, 226) - * brown rgb(165, 42, 42) - * burlywood rgb(222, 184, 135) - * cadetblue rgb( 95, 158, 160) - * chartreuse rgb(127, 255, 0) - * chocolate rgb(210, 105, 30) - * coral rgb(255, 127, 80) - * cornflowerblue rgb(100, 149, 237) - * cornsilk rgb(255, 248, 220) - * crimson rgb(220, 20, 60) - * cyan rgb( 0, 255, 255) - * darkblue rgb( 0, 0, 139) - * darkcyan rgb( 0, 139, 139) - * darkgoldenrod rgb(184, 134, 11) - * darkgray rgb(169, 169, 169) - * darkgreen rgb( 0, 100, 0) - * darkgrey rgb(169, 169, 169) - * darkkhaki rgb(189, 183, 107) - * darkmagenta rgb(139, 0, 139) - * darkolivegreen rgb( 85, 107, 47) - * darkorange rgb(255, 140, 0) - * darkorchid rgb(153, 50, 204) - * darkred rgb(139, 0, 0) - * darksalmon rgb(233, 150, 122) - * darkseagreen rgb(143, 188, 143) - * darkslateblue rgb( 72, 61, 139) - * darkslategray rgb( 47, 79, 79) - * darkslategrey rgb( 47, 79, 79) - * darkturquoise rgb( 0, 206, 209) - * darkviolet rgb(148, 0, 211) - * deeppink rgb(255, 20, 147) - * deepskyblue rgb( 0, 191, 255) - * dimgray rgb(105, 105, 105) - * dimgrey rgb(105, 105, 105) - * dodgerblue rgb( 30, 144, 255) - * firebrick rgb(178, 34, 34) - * floralwhite rgb(255, 250, 240) - * forestgreen rgb( 34, 139, 34) - * fuchsia rgb(255, 0, 255) - * gainsboro rgb(220, 220, 220) - * lightpink rgb(255, 182, 193) - * lightsalmon rgb(255, 160, 122) - * lightseagreen rgb( 32, 178, 170) - * lightskyblue rgb(135, 206, 250) - * lightslategray rgb(119, 136, 153) - * lightslategrey rgb(119, 136, 153) - * lightsteelblue rgb(176, 196, 222) - * lightyellow rgb(255, 255, 224) - * lime rgb( 0, 255, 0) - * limegreen rgb( 50, 205, 50) - * linen rgb(250, 240, 230) - * magenta rgb(255, 0, 255) - * maroon rgb(128, 0, 0) - * mediumaquamarine rgb(102, 205, 170) - * mediumblue rgb( 0, 0, 205) - * mediumorchid rgb(186, 85, 211) - * mediumpurple rgb(147, 112, 219) - * mediumseagreen rgb( 60, 179, 113) - * mediumslateblue rgb(123, 104, 238) - * mediumspringgreen rgb( 0, 250, 154) - * mediumturquoise rgb( 72, 209, 204) - * mediumvioletred rgb(199, 21, 133) - * midnightblue rgb( 25, 25, 112) - * mintcream rgb(245, 255, 250) - * mistyrose rgb(255, 228, 225) - * moccasin rgb(255, 228, 181) - * navajowhite rgb(255, 222, 173) - * navy rgb( 0, 0, 128) - * oldlace rgb(253, 245, 230) - * olive rgb(128, 128, 0) - * olivedrab rgb(107, 142, 35) - * orange rgb(255, 165, 0) - * orangered rgb(255, 69, 0) - * orchid rgb(218, 112, 214) - * palegoldenrod rgb(238, 232, 170) - * palegreen rgb(152, 251, 152) - * paleturquoise rgb(175, 238, 238) - * palevioletred rgb(219, 112, 147) - * papayawhip rgb(255, 239, 213) - * peachpuff rgb(255, 218, 185) - * peru rgb(205, 133, 63) - * pink rgb(255, 192, 203) - * plum rgb(221, 160, 221) - * powderblue rgb(176, 224, 230) - * purple rgb(128, 0, 128) - * red rgb(255, 0, 0) - * rosybrown rgb(188, 143, 143) - * royalblue rgb( 65, 105, 225) - * saddlebrown rgb(139, 69, 19) - * salmon rgb(250, 128, 114) - * ghostwhite rgb(248, 248, 255) - * gold rgb(255, 215, 0) - * goldenrod rgb(218, 165, 32) - * gray rgb(128, 128, 128) - * grey rgb(128, 128, 128) - * green rgb( 0, 128, 0) - * greenyellow rgb(173, 255, 47) - * honeydew rgb(240, 255, 240) - * hotpink rgb(255, 105, 180) - * indianred rgb(205, 92, 92) - * indigo rgb( 75, 0, 130) - * ivory rgb(255, 255, 240) - * khaki rgb(240, 230, 140) - * lavender rgb(230, 230, 250) - * lavenderblush rgb(255, 240, 245) - * lawngreen rgb(124, 252, 0) - * lemonchiffon rgb(255, 250, 205) - * lightblue rgb(173, 216, 230) - * lightcoral rgb(240, 128, 128) - * lightcyan rgb(224, 255, 255) - * lightgoldenrodyellow rgb(250, 250, 210) - * lightgray rgb(211, 211, 211) - * lightgreen rgb(144, 238, 144) - * lightgrey rgb(211, 211, 211) - * sandybrown rgb(244, 164, 96) - * seagreen rgb( 46, 139, 87) - * seashell rgb(255, 245, 238) - * sienna rgb(160, 82, 45) - * silver rgb(192, 192, 192) - * skyblue rgb(135, 206, 235) - * slateblue rgb(106, 90, 205) - * slategray rgb(112, 128, 144) - * slategrey rgb(112, 128, 144) - * snow rgb(255, 250, 250) - * springgreen rgb( 0, 255, 127) - * steelblue rgb( 70, 130, 180) - * tan rgb(210, 180, 140) - * teal rgb( 0, 128, 128) - * thistle rgb(216, 191, 216) - * tomato rgb(255, 99, 71) - * turquoise rgb( 64, 224, 208) - * violet rgb(238, 130, 238) - * wheat rgb(245, 222, 179) - * white rgb(255, 255, 255) - * whitesmoke rgb(245, 245, 245) - * yellow rgb(255, 255, 0) - * yellowgreen rgb(154, 205, 50) - */ + public Color getAWTColor(); +} \ No newline at end of file diff --git a/src/java/org/apache/fop/datatypes/CondLength.java b/src/java/org/apache/fop/datatypes/CondLength.java deleted file mode 100644 index 18ca33d2b..000000000 --- a/src/java/org/apache/fop/datatypes/CondLength.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * $Id: CondLength.java,v 1.7 2003/03/05 20:38:23 jeremias Exp $ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.datatypes; - -import org.apache.fop.fo.Property; -import org.apache.fop.fo.Constants; - -/** - * A space quantity in XSL (space-before, space-after). - * See length-conditional datatype in the specs. - */ -public class CondLength implements CompoundDatatype { - - private Property length; - private Property conditionality; - - /** - * @see org.apache.fop.datatypes.CompoundDatatype#setComponent(int, Property, boolean) - */ - public void setComponent(int cmpId, Property cmpnValue, - boolean bIsDefault) { - if (cmpId == CP_LENGTH) { - length = cmpnValue; - } else if (cmpId == CP_CONDITIONALITY) { - conditionality = cmpnValue; - } - } - - /** - * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int) - */ - public Property getComponent(int cmpId) { - if (cmpId == CP_LENGTH) { - return length; - } else if (cmpId == CP_CONDITIONALITY) { - return conditionality; - } else { - return null; - } - } - - /** - * Returns the conditionality. - * @return the conditionality - */ - public Property getConditionality() { - return this.conditionality; - } - - /** - * Returns the length. - * @return the length - */ - public Property getLength() { - return this.length; - } - - /** - * Indicates if the length can be discarded on certain conditions. - * @return true if the length can be discarded. - */ - public boolean isDiscard() { - return this.conditionality.getEnum() == Constants.DISCARD; - } - - /** - * Returns the computed length value. - * @return the length in millipoints - */ - public int getLengthValue() { - return this.length.getLength().getValue(); - } - - public String toString() { - return "CondLength[" + (isDiscard() ? "discard, " : "") + - length.getObject().toString() + "]"; - } -} - diff --git a/src/java/org/apache/fop/datatypes/FixedLength.java b/src/java/org/apache/fop/datatypes/FixedLength.java index 445bc4e93..7572c1cf6 100644 --- a/src/java/org/apache/fop/datatypes/FixedLength.java +++ b/src/java/org/apache/fop/datatypes/FixedLength.java @@ -50,12 +50,13 @@ */ package org.apache.fop.datatypes; -import org.apache.fop.fo.expr.Numeric; +import org.apache.fop.fo.LengthProperty; +import org.apache.fop.fo.expr.NumericProperty; /** * a length quantity in XSL */ -public class FixedLength extends Length { +public class FixedLength extends LengthProperty { /** * Set the length given @@ -120,8 +121,8 @@ public class FixedLength extends Length { /** * @return Numeric equivalent of this */ - public Numeric asNumeric() { - return new Numeric(this); + public NumericProperty asNumeric() { + return new NumericProperty(this); } } diff --git a/src/java/org/apache/fop/datatypes/Keep.java b/src/java/org/apache/fop/datatypes/Keep.java deleted file mode 100644 index 09fb31483..000000000 --- a/src/java/org/apache/fop/datatypes/Keep.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * $Id: Keep.java,v 1.5 2003/03/05 20:38:23 jeremias Exp $ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.datatypes; - -import org.apache.fop.fo.Property; - - -/** - * XSL FO Keep Property datatype (keep-together, etc) - */ -public class Keep implements CompoundDatatype { - private Property withinLine; - private Property withinColumn; - private Property withinPage; - - /** - * Constructor - */ - public Keep() { - } - - - /** - * @see org.apache.fop.datatypes.CompoundDatatype#setComponent(int, Property, boolean) - */ - public void setComponent(int cmpId, Property cmpnValue, - boolean bIsDefault) { - if (cmpId == CP_WITHIN_LINE) { - setWithinLine(cmpnValue, bIsDefault); - } else if (cmpId == CP_WITHIN_COLUMN) { - setWithinColumn(cmpnValue, bIsDefault); - } else if (cmpId == CP_WITHIN_PAGE) { - setWithinPage(cmpnValue, bIsDefault); - } - } - - /** - * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int) - */ - public Property getComponent(int cmpId) { - if (cmpId == CP_WITHIN_LINE) { - return getWithinLine(); - } else if (cmpId == CP_WITHIN_COLUMN) { - return getWithinColumn(); - } else if (cmpId == CP_WITHIN_PAGE) { - return getWithinPage(); - } else { - return null; - } - } - - /** - * @param withinLine withinLine property to set - * @param bIsDefault not used (??) - */ - public void setWithinLine(Property withinLine, boolean bIsDefault) { - this.withinLine = withinLine; - } - - /** - * @param withinColumn withinColumn property to set - * @param bIsDefault not used (??) - */ - protected void setWithinColumn(Property withinColumn, - boolean bIsDefault) { - this.withinColumn = withinColumn; - } - - /** - * @param withinPage withinPage property to set - * @param bIsDefault not used (??) - */ - public void setWithinPage(Property withinPage, boolean bIsDefault) { - this.withinPage = withinPage; - } - - /** - * @return the withinLine property - */ - public Property getWithinLine() { - return this.withinLine; - } - - /** - * @return the withinColumn property - */ - public Property getWithinColumn() { - return this.withinColumn; - } - - /** - * @return the withinPage property - */ - public Property getWithinPage() { - return this.withinPage; - } - - /** - * Not sure what to do here. There isn't really a meaningful single value. - * @return String representation - */ - public String toString() { - return "Keep[" + - "withinLine:" + getWithinLine().getObject() + - ", withinColumn:" + getWithinColumn().getObject() + - ", withinPage:" + getWithinPage().getObject() + "]"; - } - -} diff --git a/src/java/org/apache/fop/datatypes/Length.java b/src/java/org/apache/fop/datatypes/Length.java index e5db3b762..2d14804e7 100644 --- a/src/java/org/apache/fop/datatypes/Length.java +++ b/src/java/org/apache/fop/datatypes/Length.java @@ -50,102 +50,15 @@ */ package org.apache.fop.datatypes; -import org.apache.fop.fo.expr.Numeric; - /** * A length quantity in XSL */ -public class Length { - - /** Holds the length in millipoints. */ - protected int millipoints = 0; - /** Indicates if the value has been computed, or not. */ - protected boolean bIsComputed = false; +public interface Length { /** * Returns the length in 1/1000ths of a point (millipoints) * @return the length in millipoints */ - public int getValue() { - if (!bIsComputed) { - computeValue(); - } - return millipoints; - } - - /** - * Computes the value. - */ - protected void computeValue() { - } - - - /** - * Sets the computed value. - * @param millipoints the length in millipoints - */ - protected void setComputedValue(int millipoints) { - setComputedValue(millipoints, true); - } - - /** - * Sets the computed value. - * @param millipoints the length in millipoints - * @param bSetComputed True if the isComputed flag should be set. - */ - protected void setComputedValue(int millipoints, boolean bSetComputed) { - this.millipoints = millipoints; - this.bIsComputed = bSetComputed; - } - - /** - * Indicates if the length has the "auto" value. - * @return True if the length is set to "auto" - */ - public boolean isAuto() { - return false; - } - - /** - * Indicates if the length has been computed. - * @return True if the length has been computed - */ - public boolean isComputed() { - return this.bIsComputed; - } - - /** - * Return the number of table units which are included in this - * length specification. - * This will always be 0 unless the property specification used - * the proportional-column-width() function (only only table - * column FOs). - *

If this value is not 0, the actual value of the Length cannot - * be known without looking at all of the columns in the table to - * determine the value of a "table-unit". - * @return The number of table units which are included in this - * length specification. - */ - public double getTableUnits() { - return 0.0; - } - - public void resolveTableUnit(double dTableUnit) { - } - - /** - * @return null (cannot be converted to a Numeric ??) - */ - public Numeric asNumeric() { - return null; - } - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - String s = millipoints + "mpt"; - return s; - } - + public int getValue(); + public boolean isAuto(); } diff --git a/src/java/org/apache/fop/datatypes/LengthPair.java b/src/java/org/apache/fop/datatypes/LengthPair.java deleted file mode 100644 index aeb7e1e45..000000000 --- a/src/java/org/apache/fop/datatypes/LengthPair.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * $Id: LengthPair.java,v 1.6 2003/03/05 20:38:24 jeremias Exp $ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.datatypes; - -import org.apache.fop.fo.Property; - - -/** - * Models a pair of lengths, one specifiying the dimensions for the - * inline-progression-direction, the other for the block-progression-direction. - * It is currently only used to specify border-separation in tables. - */ -public class LengthPair implements CompoundDatatype { - - private Property ipd; - private Property bpd; - - /** - * @see org.apache.fop.datatypes.CompoundDatatype#setComponent(int, Property, boolean) - */ - public void setComponent(int cmpId, Property cmpnValue, - boolean bIsDefault) { - if (cmpId == CP_BLOCK_PROGRESSION_DIRECTION) { - bpd = cmpnValue; - } else if (cmpId == CP_INLINE_PROGRESSION_DIRECTION) { - ipd = cmpnValue; - } - } - - /** - * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int) - */ - public Property getComponent(int cmpId) { - if (cmpId == CP_BLOCK_PROGRESSION_DIRECTION) { - return getBPD(); - } else if (cmpId == CP_INLINE_PROGRESSION_DIRECTION) { - return getIPD(); - } else { - return null; // SHOULDN'T HAPPEN - } - } - - /** - * @return Property holding the ipd length - */ - public Property getIPD() { - return this.ipd; - } - - /** - * @return Property holding the bpd length - */ - public Property getBPD() { - return this.bpd; - } - - public String toString() { - return "LengthPair[" + - "ipd:" + getIPD().getObject() + - ", bpd:" + getBPD().getObject() + "]"; - } - -} - diff --git a/src/java/org/apache/fop/datatypes/LengthRange.java b/src/java/org/apache/fop/datatypes/LengthRange.java deleted file mode 100644 index 52e224788..000000000 --- a/src/java/org/apache/fop/datatypes/LengthRange.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * $Id: LengthRange.java,v 1.10 2003/03/05 20:38:23 jeremias Exp $ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.datatypes; - -import org.apache.fop.fo.Property; - -/** - * A "progression-dimension" quantity. - * Examples: block-progression-dimension, inline-progression-dimension. - * Corresponds to the triplet min-height, height, max-height (or width). - */ -public class LengthRange implements CompoundDatatype { - - private Property minimum; - private Property optimum; - private Property maximum; - private static final int MINSET = 1; - private static final int OPTSET = 2; - private static final int MAXSET = 4; - private int bfSet = 0; // bit field - private boolean bChecked = false; - - /** - * @see org.apache.fop.datatypes.CompoundDatatype#setComponent(int, Property, boolean) - */ - public void setComponent(int cmpId, Property cmpnValue, - boolean bIsDefault) { - if (cmpId == CP_MINIMUM) { - setMinimum(cmpnValue, bIsDefault); - } else if (cmpId == CP_OPTIMUM) { - setOptimum(cmpnValue, bIsDefault); - } else if (cmpId == CP_MAXIMUM) { - setMaximum(cmpnValue, bIsDefault); - } - } - - /** - * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int) - */ - public Property getComponent(int cmpId) { - if (cmpId == CP_MINIMUM) { - return getMinimum(); - } else if (cmpId == CP_OPTIMUM) { - return getOptimum(); - } else if (cmpId == CP_MAXIMUM) { - return getMaximum(); - } else { - return null; // SHOULDN'T HAPPEN - } - } - - /** - * Set minimum value to min. - * @param minimum A Length value specifying the minimum value for this - * LengthRange. - * @param bIsDefault If true, this is set as a "default" value - * and not a user-specified explicit value. - */ - protected void setMinimum(Property minimum, boolean bIsDefault) { - this.minimum = minimum; - if (!bIsDefault) { - bfSet |= MINSET; - } - } - - - /** - * Set maximum value to max if it is >= optimum or optimum isn't set. - * @param max A Length value specifying the maximum value for this - * @param bIsDefault If true, this is set as a "default" value - * and not a user-specified explicit value. - */ - protected void setMaximum(Property max, boolean bIsDefault) { - maximum = max; - if (!bIsDefault) { - bfSet |= MAXSET; - } - } - - - /** - * Set the optimum value. - * @param opt A Length value specifying the optimum value for this - * @param bIsDefault If true, this is set as a "default" value - * and not a user-specified explicit value. - */ - protected void setOptimum(Property opt, boolean bIsDefault) { - optimum = opt; - if (!bIsDefault) { - bfSet |= OPTSET; - } - } - - // Minimum is prioritaire, if explicit - private void checkConsistency() { - if (bChecked) { - return; - } - // Make sure max >= min - // Must also control if have any allowed enum values! - - /** - * ******************* - * if (minimum.mvalue() > maximum.mvalue()) { - * if ((bfSet&MINSET)!=0) { - * // if minimum is explicit, force max to min - * if ((bfSet&MAXSET)!=0) { - * // Warning: min>max, resetting max to min - * log.error("forcing max to min in LengthRange"); - * } - * maximum = minimum ; - * } - * else { - * minimum = maximum; // minimum was default value - * } - * } - * // Now make sure opt <= max and opt >= min - * if (optimum.mvalue() > maximum.mvalue()) { - * if ((bfSet&OPTSET)!=0) { - * if ((bfSet&MAXSET)!=0) { - * // Warning: opt > max, resetting opt to max - * log.error("forcing opt to max in LengthRange"); - * optimum = maximum ; - * } - * else { - * maximum = optimum; // maximum was default value - * } - * } - * else { - * // opt is default and max is explicit or default - * optimum = maximum ; - * } - * } - * else if (optimum.mvalue() < minimum.mvalue()) { - * if ((bfSet&MINSET)!=0) { - * // if minimum is explicit, force opt to min - * if ((bfSet&OPTSET)!=0) { - * log.error("forcing opt to min in LengthRange"); - * } - * optimum = minimum ; - * } - * else { - * minimum = optimum; // minimum was default value - * } - * } - * *******$******* - */ - bChecked = true; - } - - /** - * @return minimum length - */ - public Property getMinimum() { - checkConsistency(); - return this.minimum; - } - - /** - * @return maximum length - */ - public Property getMaximum() { - checkConsistency(); - return this.maximum; - } - - /** - * @return optimum length - */ - public Property getOptimum() { - checkConsistency(); - return this.optimum; - } - - public String toString() { - return "LengthRange[" + - "min:" + getMinimum().getObject() + - ", max:" + getMaximum().getObject() + - ", opt:" + getOptimum().getObject() + "]"; - } - -} - diff --git a/src/java/org/apache/fop/datatypes/LinearCombinationLength.java b/src/java/org/apache/fop/datatypes/LinearCombinationLength.java index 5ddd1e0ca..a853417dd 100644 --- a/src/java/org/apache/fop/datatypes/LinearCombinationLength.java +++ b/src/java/org/apache/fop/datatypes/LinearCombinationLength.java @@ -52,10 +52,12 @@ package org.apache.fop.datatypes; import java.util.Vector; +import org.apache.fop.fo.LengthProperty; + /** * Class modelling lengths that are build up by combining other lengths */ -public class LinearCombinationLength extends Length { +public class LinearCombinationLength extends LengthProperty { /** Collection of factors (1-1 correspondence with {@link #lengths} */ protected Vector factors; @@ -75,7 +77,7 @@ public class LinearCombinationLength extends Length { * @param factor the factor to be added * @param length the Length to be added */ - public void addTerm(double factor, Length length) { + public void addTerm(double factor, LengthProperty length) { factors.addElement(new Double(factor)); lengths.addElement(length); } diff --git a/src/java/org/apache/fop/datatypes/MixedLength.java b/src/java/org/apache/fop/datatypes/MixedLength.java index 3e547fc7c..bc7dd1536 100644 --- a/src/java/org/apache/fop/datatypes/MixedLength.java +++ b/src/java/org/apache/fop/datatypes/MixedLength.java @@ -50,10 +50,11 @@ */ package org.apache.fop.datatypes; -import java.util.Vector; import java.util.Enumeration; +import java.util.Vector; -import org.apache.fop.fo.expr.Numeric; +import org.apache.fop.fo.LengthProperty; +import org.apache.fop.fo.expr.NumericProperty; import org.apache.fop.fo.expr.PropertyException; /** @@ -61,7 +62,7 @@ import org.apache.fop.fo.expr.PropertyException; * of absolute and relative and/or percent components. * The actual value may not be computable before layout is done. */ -public class MixedLength extends Length { +public class MixedLength extends LengthProperty { /** The collection of Length objects comprising this MixedLength object */ private Vector lengths ; @@ -84,7 +85,7 @@ public class MixedLength extends Length { boolean bAllComputed = true; Enumeration e = lengths.elements(); while (e.hasMoreElements()) { - Length l = (Length) e.nextElement(); + LengthProperty l = (LengthProperty) e.nextElement(); computedValue += l.getValue(); if (!l.isComputed()) { bAllComputed = false; @@ -98,7 +99,7 @@ public class MixedLength extends Length { double tableUnits = 0.0; Enumeration e = lengths.elements(); while (e.hasMoreElements()) { - tableUnits += ((Length) e.nextElement()).getTableUnits(); + tableUnits += ((LengthProperty) e.nextElement()).getTableUnits(); } return tableUnits; } @@ -106,7 +107,7 @@ public class MixedLength extends Length { public void resolveTableUnit(double dTableUnit) { Enumeration e = lengths.elements(); while (e.hasMoreElements()) { - ((Length) e.nextElement()).resolveTableUnit(dTableUnit); + ((LengthProperty) e.nextElement()).resolveTableUnit(dTableUnit); } } @@ -128,15 +129,15 @@ public class MixedLength extends Length { /** * @return Numeric equivalent of this */ - public Numeric asNumeric() { - Numeric numeric = null; + public NumericProperty asNumeric() { + NumericProperty numeric = null; for (Enumeration e = lengths.elements(); e.hasMoreElements();) { - Length l = (Length) e.nextElement(); + LengthProperty l = (LengthProperty) e.nextElement(); if (numeric == null) { numeric = l.asNumeric(); } else { try { - Numeric sum = numeric.add(l.asNumeric()); + NumericProperty sum = numeric.add(l.asNumeric()); numeric = sum; } catch (PropertyException pe) { System.err.println( diff --git a/src/java/org/apache/fop/datatypes/PercentLength.java b/src/java/org/apache/fop/datatypes/PercentLength.java index 9699be3b2..9d96e7989 100644 --- a/src/java/org/apache/fop/datatypes/PercentLength.java +++ b/src/java/org/apache/fop/datatypes/PercentLength.java @@ -50,12 +50,13 @@ */ package org.apache.fop.datatypes; -import org.apache.fop.fo.expr.Numeric; +import org.apache.fop.fo.LengthProperty; +import org.apache.fop.fo.expr.NumericProperty; /** * a percent specified length quantity in XSL */ -public class PercentLength extends Length { +public class PercentLength extends LengthProperty { /** * The percentage itself, expressed as a decimal value, e.g. for 95%, set @@ -132,8 +133,8 @@ public class PercentLength extends Length { /** * @return new Numeric object that is equivalent to this */ - public Numeric asNumeric() { - return new Numeric(this); + public NumericProperty asNumeric() { + return new NumericProperty(this); } } diff --git a/src/java/org/apache/fop/datatypes/Space.java b/src/java/org/apache/fop/datatypes/Space.java deleted file mode 100644 index b7421cafd..000000000 --- a/src/java/org/apache/fop/datatypes/Space.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * $Id: Space.java,v 1.8 2003/03/05 20:38:23 jeremias Exp $ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.datatypes; - -import org.apache.fop.fo.Property; - -/** - * a space quantity in XSL (space-before, space-after) - */ -public class Space extends LengthRange { - - private Property precedence; - private Property conditionality; - - /** - * @see org.apache.fop.datatypes.CompoundDatatype#setComponent(int, Property, boolean) - */ - public void setComponent(int cmpId, Property cmpnValue, - boolean bIsDefault) { - if (cmpId == CP_PRECEDENCE) { - setPrecedence(cmpnValue, bIsDefault); - } else if (cmpId == CP_CONDITIONALITY) { - setConditionality(cmpnValue, bIsDefault); - } else { - super.setComponent(cmpId, cmpnValue, bIsDefault); - } - } - - /** - * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int) - */ - public Property getComponent(int cmpId) { - if (cmpId == CP_PRECEDENCE) { - return getPrecedence(); - } else if (cmpId == CP_CONDITIONALITY) { - return getConditionality(); - } else { - return super.getComponent(cmpId); - } - } - - /** - * - * @param precedence precedence Property to set - * @param bIsDefault (is not used anywhere) - */ - protected void setPrecedence(Property precedence, boolean bIsDefault) { - this.precedence = precedence; - } - - /** - * - * @param conditionality conditionality Property to set - * @param bIsDefault (is not used anywhere) - */ - protected void setConditionality(Property conditionality, - boolean bIsDefault) { - this.conditionality = conditionality; - } - - /** - * @return precedence Property - */ - public Property getPrecedence() { - return this.precedence; - } - - /** - * @return conditionality Property - */ - public Property getConditionality() { - return this.conditionality; - } - - public String toString() { - return "Space[" + - "min:" + getMinimum().getObject() + - ", max:" + getMaximum().getObject() + - ", opt:" + getOptimum().getObject() + - ", precedence:" + precedence.getObject() + - ", conditionality:" + conditionality.getObject() + "]"; - } - -} - diff --git a/src/java/org/apache/fop/datatypes/TableColLength.java b/src/java/org/apache/fop/datatypes/TableColLength.java index d431c1e44..28b9ec436 100644 --- a/src/java/org/apache/fop/datatypes/TableColLength.java +++ b/src/java/org/apache/fop/datatypes/TableColLength.java @@ -50,7 +50,8 @@ */ package org.apache.fop.datatypes; -import org.apache.fop.fo.expr.Numeric; +import org.apache.fop.fo.LengthProperty; +import org.apache.fop.fo.expr.NumericProperty; /** * A table-column width specification, possibly including some @@ -63,7 +64,7 @@ import org.apache.fop.fo.expr.Numeric; * during layout. * NOTE: this is only supposed to be allowed if table-layout=fixed. */ -public class TableColLength extends Length { +public class TableColLength extends LengthProperty { /** * Number of table-column proportional units @@ -114,8 +115,8 @@ public class TableColLength extends Length { * Converts this to a new Numeric object * @return the Numeric object */ - public Numeric asNumeric() { - return new Numeric(this); + public NumericProperty asNumeric() { + return new NumericProperty(this); } } diff --git a/src/java/org/apache/fop/fo/ColorTypeProperty.java b/src/java/org/apache/fop/fo/ColorTypeProperty.java index 9487193bd..125e1dbc4 100644 --- a/src/java/org/apache/fop/fo/ColorTypeProperty.java +++ b/src/java/org/apache/fop/fo/ColorTypeProperty.java @@ -50,13 +50,37 @@ */ package org.apache.fop.fo; +import java.awt.Color; +import java.util.StringTokenizer; + import org.apache.fop.datatypes.ColorType; import org.apache.fop.fo.properties.PropertyMaker; /** * Superclass for properties that wrap ColorType values */ -public class ColorTypeProperty extends Property { +public class ColorTypeProperty extends Property implements ColorType { + /** + * the red component + */ + protected float red = 0f; + + /** + * the green component + */ + protected float green = 0f; + + /** + * the blue component + */ + protected float blue = 0f; + + /** + * the alpha component (indicator of opaque-ness) + * 0.0 - 1.0; 0.0 is completely transparent; 1.0 is completely opaque + * see definition at http://java.sun.com/j2se/1.3/docs/api/java/awt/Color.html + */ + protected float alpha = 1f; /** * Inner class for creating instances of ColorTypeProperty @@ -75,39 +99,711 @@ public class ColorTypeProperty extends Property { if (p instanceof ColorTypeProperty) { return p; } - ColorType val = p.getColorType(); + ColorTypeProperty val = p.getColorType(); if (val != null) { - return new ColorTypeProperty(val); + return val; } return convertPropertyDatatype(p, propertyList, fo); } } - private ColorType colorType; + /** + * Main constructor + * @param red red component + * @param green green component + * @param blue blue component + */ + public ColorTypeProperty(float red, float green, float blue) { + this.red = red; + this.green = green; + this.blue = blue; + } /** - * @param colorType color type object which is to be wrapped in this - * Property + * Set the colour given a particular String specifying either a + * colour name or #RGB or #RRGGBB + * @param value RGB value as String to be parsed */ - public ColorTypeProperty(ColorType colorType) { - this.colorType = colorType; + public ColorTypeProperty(String value) { + if (value.startsWith("#")) { + try { + if (value.length() == 4) { + // note: divide by 15 so F = FF = 1 and so on + this.red = Integer.parseInt(value.substring(1, 2), 16) + / 15f; + this.green = Integer.parseInt(value.substring(2, 3), 16) + / 15f; + this.blue = Integer.parseInt(value.substring(3), 16) + / 15f; + } else if (value.length() == 7) { + // note: divide by 255 so FF = 1 + this.red = Integer.parseInt(value.substring(1, 3), 16) + / 255f; + this.green = Integer.parseInt(value.substring(3, 5), 16) + / 255f; + this.blue = Integer.parseInt(value.substring(5), 16) + / 255f; + } else { + this.red = 0; + this.green = 0; + this.blue = 0; + //log.error("unknown colour format. Must be #RGB or #RRGGBB"); + } + } catch (Exception e) { + this.red = 0; + this.green = 0; + this.blue = 0; + //log.error("unknown colour format. Must be #RGB or #RRGGBB"); + } + } else if (value.startsWith("rgb(")) { + int poss = value.indexOf("("); + int pose = value.indexOf(")"); + if (poss != -1 && pose != -1) { + value = value.substring(poss + 1, pose); + StringTokenizer st = new StringTokenizer(value, ","); + try { + if (st.hasMoreTokens()) { + String str = st.nextToken().trim(); + if (str.endsWith("%")) { + this.red = + Integer.parseInt(str.substring(0, str.length() - 1)) + * 2.55f; + } else { + this.red = Integer.parseInt(str) / 255f; + } + } + if (st.hasMoreTokens()) { + String str = st.nextToken().trim(); + if (str.endsWith("%")) { + this.green = + Integer.parseInt(str.substring(0, str.length() - 1)) + * 2.55f; + } else { + this.green = Integer.parseInt(str) / 255f; + } + } + if (st.hasMoreTokens()) { + String str = st.nextToken().trim(); + if (str.endsWith("%")) { + this.blue = + Integer.parseInt(str.substring(0, str.length() - 1)) + * 2.55f; + } else { + this.blue = Integer.parseInt(str) / 255f; + } + } + } catch (Exception e) { + this.red = 0; + this.green = 0; + this.blue = 0; + //log.error("unknown colour format. Must be #RGB or #RRGGBB"); + } + } + } else if (value.startsWith("url(")) { + // refers to a gradient + } else { + if (value.toLowerCase().equals("transparent")) { + this.red = 0; + this.green = 0; + this.blue = 0; + this.alpha = 0; + } else { + boolean found = false; + for (int count = 0; count < NAMES.length; count++) { + if (value.toLowerCase().equals(NAMES[count])) { + this.red = VALUES[count][0] / 255f; + this.green = VALUES[count][1] / 255f; + this.blue = VALUES[count][2] / 255f; + found = true; + break; + } + } + if (!found) { + this.red = 0; + this.green = 0; + this.blue = 0; + //log.error("unknown colour name: " + // + value); + } + } + } + } + + /** + * Returns the blue component of the color. + * @return float a value between 0.0 and 1.0 + */ + public float getBlue() { + return this.blue; } + /** + * Returns the green component of the color. + * @return float a value between 0.0 and 1.0 + */ + public float getGreen() { + return this.green; + } + + /** + * Returns the red component of the color. + * @return float a value between 0.0 and 1.0 + */ + public float getRed() { + return this.red; + } + + /** + * Returns the alpha (degree of opaque-ness) component of the color. + * @return float a value between 0.0 (fully transparent) and 1.0 (fully opaque) + */ + public float getAlpha() { + return this.alpha; + } + + /** + * Returns an AWT instance of this color + * @return float the AWT color represented by this ColorType instance + */ + public Color getAWTColor() { + return new Color(this.red, this.green, this.blue, this.alpha); + } + + /** + * @param floatValue value (between 0.0 and 1.0) of color channel + * @return integer equivalent (between 0 and 255) + */ + public static int convertChannelToInteger (float floatValue) { + if (floatValue > 1.0) { + floatValue = 1.0f; + } + if (floatValue < 0) { + floatValue = 0; + } + return (int) (floatValue * 255); + } + + /** + * @see java.lang.Object#toString() + */ + public String toString() { + StringBuffer sbuf = new StringBuffer(8); + sbuf.append('#'); + String s = Integer.toHexString((int)(red * 255.0)); + if (s.length() == 1) { + sbuf.append('0'); + } + sbuf.append(s); + s = Integer.toHexString((int)(green * 255.0)); + if (s.length() == 1) { + sbuf.append('0'); + } + sbuf.append(s); + s = Integer.toHexString((int)(blue * 255.0)); + if (s.length() == 1) { + sbuf.append('0'); + } + sbuf.append(s); + return sbuf.toString(); + } + + /** The names of the predefined colors */ + protected static final String[] NAMES = { + "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", + "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", + "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", + "cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue", + "darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkgrey", + "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange", + "darkorchid", "darkred", "darksalmon", "darkseagreen", + "darkslateblue", "darkslategray", "darkslategrey", "darkturquoise", + "darkviolet", "deeppink", "deepskyblue", "dimgray", "dimgrey", + "dodgerblue", "firebrick", "floralwhite", "forestgreen", "fuchsia", + "gainsboro", "lightpink", "lightsalmon", "lightseagreen", + "lightskyblue", "lightslategray", "lightslategrey", "lightsteelblue", + "lightyellow", "lime", "limegreen", "linen", "magenta", "maroon", + "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", + "mediumseagreen", "mediumslateblue", "mediumspringgreen", + "mediumturquoise", "mediumvioletred", "midnightblue", "mintcream", + "mistyrose", "moccasin", "navajowhite", "navy", "oldlace", "olive", + "olivedrab", "orange", "orangered", "orchid", "palegoldenrod", + "palegreen", "paleturquoise", "palevioletred", "papayawhip", + "peachpuff", "peru", "pink", "plum", "powderblue", "purple", "red", + "rosybrown", "royalblue", "saddlebrown", "salmon", "ghostwhite", + "gold", "goldenrod", "gray", "grey", "green", "greenyellow", + "honeydew", "hotpink", "indianred", "indigo", "ivory", "khaki", + "lavender", "lavenderblush", "lawngreen", "lemonchiffon", + "lightblue", "lightcoral", "lightcyan", "lightgoldenrodyellow", + "lightgray", "lightgreen", "lightgrey", "sandybrown", "seagreen", + "seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", + "slategrey", "snow", "springgreen", "steelblue", "tan", "teal", + "thistle", "tomato", "turquoise", "violet", "wheat", "white", + "whitesmoke", "yellow", "yellowgreen" + }; + + /** The color values for the predefined colors */ + protected static final int[][] VALUES = { + { + 240, 248, 255 + }, { + 250, 235, 215 + }, { + 0, 255, 255 + }, { + 127, 255, 212 + }, { + 240, 255, 255 + }, { + 245, 245, 220 + }, { + 255, 228, 196 + }, { + 0, 0, 0 + }, { + 255, 235, 205 + }, { + 0, 0, 255 + }, { + 138, 43, 226 + }, { + 165, 42, 42 + }, { + 222, 184, 135 + }, { + 95, 158, 160 + }, { + 127, 255, 0 + }, { + 210, 105, 30 + }, { + 255, 127, 80 + }, { + 100, 149, 237 + }, { + 255, 248, 220 + }, { + 220, 20, 60 + }, { + 0, 255, 255 + }, { + 0, 0, 139 + }, { + 0, 139, 139 + }, { + 184, 134, 11 + }, { + 169, 169, 169 + }, { + 0, 100, 0 + }, { + 169, 169, 169 + }, { + 189, 183, 107 + }, { + 139, 0, 139 + }, { + 85, 107, 47 + }, { + 255, 140, 0 + }, { + 153, 50, 204 + }, { + 139, 0, 0 + }, { + 233, 150, 122 + }, { + 143, 188, 143 + }, { + 72, 61, 139 + }, { + 47, 79, 79 + }, { + 47, 79, 79 + }, { + 0, 206, 209 + }, { + 148, 0, 211 + }, { + 255, 20, 147 + }, { + 0, 191, 255 + }, { + 105, 105, 105 + }, { + 105, 105, 105 + }, { + 30, 144, 255 + }, { + 178, 34, 34 + }, { + 255, 250, 240 + }, { + 34, 139, 34 + }, { + 255, 0, 255 + }, { + 220, 220, 220 + }, { + 255, 182, 193 + }, { + 255, 160, 122 + }, { + 32, 178, 170 + }, { + 135, 206, 250 + }, { + 119, 136, 153 + }, { + 119, 136, 153 + }, { + 176, 196, 222 + }, { + 255, 255, 224 + }, { + 0, 255, 0 + }, { + 50, 205, 50 + }, { + 250, 240, 230 + }, { + 255, 0, 255 + }, { + 128, 0, 0 + }, { + 102, 205, 170 + }, { + 0, 0, 205 + }, { + 186, 85, 211 + }, { + 147, 112, 219 + }, { + 60, 179, 113 + }, { + 123, 104, 238 + }, { + 0, 250, 154 + }, { + 72, 209, 204 + }, { + 199, 21, 133 + }, { + 25, 25, 112 + }, { + 245, 255, 250 + }, { + 255, 228, 225 + }, { + 255, 228, 181 + }, { + 255, 222, 173 + }, { + 0, 0, 128 + }, { + 253, 245, 230 + }, { + 128, 128, 0 + }, { + 107, 142, 35 + }, { + 255, 165, 0 + }, { + 255, 69, 0 + }, { + 218, 112, 214 + }, { + 238, 232, 170 + }, { + 152, 251, 152 + }, { + 175, 238, 238 + }, { + 219, 112, 147 + }, { + 255, 239, 213 + }, { + 255, 218, 185 + }, { + 205, 133, 63 + }, { + 255, 192, 203 + }, { + 221, 160, 221 + }, { + 176, 224, 230 + }, { + 128, 0, 128 + }, { + 255, 0, 0 + }, { + 188, 143, 143 + }, { + 65, 105, 225 + }, { + 139, 69, 19 + }, { + 250, 128, 114 + }, { + 248, 248, 255 + }, { + 255, 215, 0 + }, { + 218, 165, 32 + }, { + 128, 128, 128 + }, { + 128, 128, 128 + }, { + 0, 128, 0 + }, { + 173, 255, 47 + }, { + 240, 255, 240 + }, { + 255, 105, 180 + }, { + 205, 92, 92 + }, { + 75, 0, 130 + }, { + 255, 255, 240 + }, { + 240, 230, 140 + }, { + 230, 230, 250 + }, { + 255, 240, 245 + }, { + 124, 252, 0 + }, { + 255, 250, 205 + }, { + 173, 216, 230 + }, { + 240, 128, 128 + }, { + 224, 255, 255 + }, { + 250, 250, 210 + }, { + 211, 211, 211 + }, { + 144, 238, 144 + }, { + 211, 211, 211 + }, { + 244, 164, 96 + }, { + 46, 139, 87 + }, { + 255, 245, 238 + }, { + 160, 82, 45 + }, { + 192, 192, 192 + }, { + 135, 206, 235 + }, { + 106, 90, 205 + }, { + 112, 128, 144 + }, { + 112, 128, 144 + }, { + 255, 250, 250 + }, { + 0, 255, 127 + }, { + 70, 130, 180 + }, { + 210, 180, 140 + }, { + 0, 128, 128 + }, { + 216, 191, 216 + }, { + 255, 99, 71 + }, { + 64, 224, 208 + }, { + 238, 130, 238 + }, { + 245, 222, 179 + }, { + 255, 255, 255 + }, { + 245, 245, 245 + }, { + 255, 255, 0 + }, { + 154, 205, 50 + } + }; + + /* + * aliceblue rgb(240, 248, 255) + * antiquewhite rgb(250, 235, 215) + * aqua rgb( 0, 255, 255) + * aquamarine rgb(127, 255, 212) + * azure rgb(240, 255, 255) + * beige rgb(245, 245, 220) + * bisque rgb(255, 228, 196) + * black rgb( 0, 0, 0) + * blanchedalmond rgb(255, 235, 205) + * blue rgb( 0, 0, 255) + * blueviolet rgb(138, 43, 226) + * brown rgb(165, 42, 42) + * burlywood rgb(222, 184, 135) + * cadetblue rgb( 95, 158, 160) + * chartreuse rgb(127, 255, 0) + * chocolate rgb(210, 105, 30) + * coral rgb(255, 127, 80) + * cornflowerblue rgb(100, 149, 237) + * cornsilk rgb(255, 248, 220) + * crimson rgb(220, 20, 60) + * cyan rgb( 0, 255, 255) + * darkblue rgb( 0, 0, 139) + * darkcyan rgb( 0, 139, 139) + * darkgoldenrod rgb(184, 134, 11) + * darkgray rgb(169, 169, 169) + * darkgreen rgb( 0, 100, 0) + * darkgrey rgb(169, 169, 169) + * darkkhaki rgb(189, 183, 107) + * darkmagenta rgb(139, 0, 139) + * darkolivegreen rgb( 85, 107, 47) + * darkorange rgb(255, 140, 0) + * darkorchid rgb(153, 50, 204) + * darkred rgb(139, 0, 0) + * darksalmon rgb(233, 150, 122) + * darkseagreen rgb(143, 188, 143) + * darkslateblue rgb( 72, 61, 139) + * darkslategray rgb( 47, 79, 79) + * darkslategrey rgb( 47, 79, 79) + * darkturquoise rgb( 0, 206, 209) + * darkviolet rgb(148, 0, 211) + * deeppink rgb(255, 20, 147) + * deepskyblue rgb( 0, 191, 255) + * dimgray rgb(105, 105, 105) + * dimgrey rgb(105, 105, 105) + * dodgerblue rgb( 30, 144, 255) + * firebrick rgb(178, 34, 34) + * floralwhite rgb(255, 250, 240) + * forestgreen rgb( 34, 139, 34) + * fuchsia rgb(255, 0, 255) + * gainsboro rgb(220, 220, 220) + * lightpink rgb(255, 182, 193) + * lightsalmon rgb(255, 160, 122) + * lightseagreen rgb( 32, 178, 170) + * lightskyblue rgb(135, 206, 250) + * lightslategray rgb(119, 136, 153) + * lightslategrey rgb(119, 136, 153) + * lightsteelblue rgb(176, 196, 222) + * lightyellow rgb(255, 255, 224) + * lime rgb( 0, 255, 0) + * limegreen rgb( 50, 205, 50) + * linen rgb(250, 240, 230) + * magenta rgb(255, 0, 255) + * maroon rgb(128, 0, 0) + * mediumaquamarine rgb(102, 205, 170) + * mediumblue rgb( 0, 0, 205) + * mediumorchid rgb(186, 85, 211) + * mediumpurple rgb(147, 112, 219) + * mediumseagreen rgb( 60, 179, 113) + * mediumslateblue rgb(123, 104, 238) + * mediumspringgreen rgb( 0, 250, 154) + * mediumturquoise rgb( 72, 209, 204) + * mediumvioletred rgb(199, 21, 133) + * midnightblue rgb( 25, 25, 112) + * mintcream rgb(245, 255, 250) + * mistyrose rgb(255, 228, 225) + * moccasin rgb(255, 228, 181) + * navajowhite rgb(255, 222, 173) + * navy rgb( 0, 0, 128) + * oldlace rgb(253, 245, 230) + * olive rgb(128, 128, 0) + * olivedrab rgb(107, 142, 35) + * orange rgb(255, 165, 0) + * orangered rgb(255, 69, 0) + * orchid rgb(218, 112, 214) + * palegoldenrod rgb(238, 232, 170) + * palegreen rgb(152, 251, 152) + * paleturquoise rgb(175, 238, 238) + * palevioletred rgb(219, 112, 147) + * papayawhip rgb(255, 239, 213) + * peachpuff rgb(255, 218, 185) + * peru rgb(205, 133, 63) + * pink rgb(255, 192, 203) + * plum rgb(221, 160, 221) + * powderblue rgb(176, 224, 230) + * purple rgb(128, 0, 128) + * red rgb(255, 0, 0) + * rosybrown rgb(188, 143, 143) + * royalblue rgb( 65, 105, 225) + * saddlebrown rgb(139, 69, 19) + * salmon rgb(250, 128, 114) + * ghostwhite rgb(248, 248, 255) + * gold rgb(255, 215, 0) + * goldenrod rgb(218, 165, 32) + * gray rgb(128, 128, 128) + * grey rgb(128, 128, 128) + * green rgb( 0, 128, 0) + * greenyellow rgb(173, 255, 47) + * honeydew rgb(240, 255, 240) + * hotpink rgb(255, 105, 180) + * indianred rgb(205, 92, 92) + * indigo rgb( 75, 0, 130) + * ivory rgb(255, 255, 240) + * khaki rgb(240, 230, 140) + * lavender rgb(230, 230, 250) + * lavenderblush rgb(255, 240, 245) + * lawngreen rgb(124, 252, 0) + * lemonchiffon rgb(255, 250, 205) + * lightblue rgb(173, 216, 230) + * lightcoral rgb(240, 128, 128) + * lightcyan rgb(224, 255, 255) + * lightgoldenrodyellow rgb(250, 250, 210) + * lightgray rgb(211, 211, 211) + * lightgreen rgb(144, 238, 144) + * lightgrey rgb(211, 211, 211) + * sandybrown rgb(244, 164, 96) + * seagreen rgb( 46, 139, 87) + * seashell rgb(255, 245, 238) + * sienna rgb(160, 82, 45) + * silver rgb(192, 192, 192) + * skyblue rgb(135, 206, 235) + * slateblue rgb(106, 90, 205) + * slategray rgb(112, 128, 144) + * slategrey rgb(112, 128, 144) + * snow rgb(255, 250, 250) + * springgreen rgb( 0, 255, 127) + * steelblue rgb( 70, 130, 180) + * tan rgb(210, 180, 140) + * teal rgb( 0, 128, 128) + * thistle rgb(216, 191, 216) + * tomato rgb(255, 99, 71) + * turquoise rgb( 64, 224, 208) + * violet rgb(238, 130, 238) + * wheat rgb(245, 222, 179) + * white rgb(255, 255, 255) + * whitesmoke rgb(245, 245, 245) + * yellow rgb(255, 255, 0) + * yellowgreen rgb(154, 205, 50) + */ + /** * Can't convert to any other types * @return this.colorType */ - public ColorType getColorType() { - return this.colorType; + public ColorTypeProperty getColorType() { + return this; } /** * @return this.colorType cast as an Object */ public Object getObject() { - return this.colorType; + return this; } - } diff --git a/src/java/org/apache/fop/fo/CondLengthProperty.java b/src/java/org/apache/fop/fo/CondLengthProperty.java index 8ee5d9e8b..aa2260a41 100644 --- a/src/java/org/apache/fop/fo/CondLengthProperty.java +++ b/src/java/org/apache/fop/fo/CondLengthProperty.java @@ -51,14 +51,15 @@ package org.apache.fop.fo; import org.apache.fop.apps.FOPException; -import org.apache.fop.datatypes.CondLength; -import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.CompoundDatatype; import org.apache.fop.fo.properties.CompoundPropertyMaker; /** * Superclass for properties that have conditional lengths */ -public class CondLengthProperty extends Property { +public class CondLengthProperty extends Property implements CompoundDatatype { + private Property length; + private Property conditionality; /** * Inner class for creating instances of CondLengthProperty @@ -77,7 +78,7 @@ public class CondLengthProperty extends Property { * @return the new instance. */ public Property makeNewProperty() { - return new CondLengthProperty(new CondLength()); + return new CondLengthProperty(); } /** @@ -93,36 +94,89 @@ public class CondLengthProperty extends Property { } } - private CondLength condLength = null; + /** + * @see org.apache.fop.datatypes.CompoundDatatype#setComponent(int, Property, boolean) + */ + public void setComponent(int cmpId, Property cmpnValue, + boolean bIsDefault) { + if (cmpId == CP_LENGTH) { + length = cmpnValue; + } else if (cmpId == CP_CONDITIONALITY) { + conditionality = cmpnValue; + } + } + + /** + * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int) + */ + public Property getComponent(int cmpId) { + if (cmpId == CP_LENGTH) { + return length; + } else if (cmpId == CP_CONDITIONALITY) { + return conditionality; + } else { + return null; + } + } /** - * @param condLength conditional length object which is to be wrapped in - * this property + * Returns the conditionality. + * @return the conditionality */ - public CondLengthProperty(CondLength condLength) { - this.condLength = condLength; + public Property getConditionality() { + return this.conditionality; } + /** + * Returns the length. + * @return the length + */ + public Property getLengthComponent() { + return this.length; + } + + /** + * Indicates if the length can be discarded on certain conditions. + * @return true if the length can be discarded. + */ + public boolean isDiscard() { + return this.conditionality.getEnum() == Constants.DISCARD; + } + + /** + * Returns the computed length value. + * @return the length in millipoints + */ + public int getLengthValue() { + return this.length.getLength().getValue(); + } + + public String toString() { + return "CondLength[" + (isDiscard() ? "discard, " : "") + + length.getObject().toString() + "]"; + } + + /** * @return this.condLength */ - public CondLength getCondLength() { - return this.condLength; + public CondLengthProperty getCondLength() { + return this; } /** * TODO: Should we allow this? * @return this.condLength cast as a Length */ - public Length getLength() { - return this.condLength.getLength().getLength(); + public LengthProperty getLength() { + return length.getLength(); } /** * @return this.condLength cast as an Object */ public Object getObject() { - return this.condLength; + return this; } } diff --git a/src/java/org/apache/fop/fo/EnumProperty.java b/src/java/org/apache/fop/fo/EnumProperty.java index 3c39b1c9f..5d09de9c7 100644 --- a/src/java/org/apache/fop/fo/EnumProperty.java +++ b/src/java/org/apache/fop/fo/EnumProperty.java @@ -66,7 +66,7 @@ public class EnumProperty extends Property { /** * @param propName name of property for which a Maker should be created */ - protected Maker(int propId) { + public Maker(int propId) { super(propId); } diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java index afe6ea959..5ca79af2a 100644 --- a/src/java/org/apache/fop/fo/FOPropertyMapping.java +++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java @@ -53,10 +53,10 @@ package org.apache.fop.fo; import java.util.HashMap; import java.util.Map; -import org.apache.fop.datatypes.ColorType; import org.apache.fop.datatypes.LengthBase; import org.apache.fop.datatypes.ToBeImplementedProperty; import org.apache.fop.fo.properties.BorderWidthPropertyMaker; +import org.apache.fop.fo.properties.CharacterProperty; import org.apache.fop.fo.properties.CorrespondingPropertyMaker; import org.apache.fop.fo.properties.DimensionPropertyMaker; import org.apache.fop.fo.properties.IndentPropertyMaker; @@ -686,7 +686,7 @@ public class FOPropertyMapping implements Constants { Property p, PropertyList propertyList, FObj fo) { String nameval = p.getNCname(); if (nameval != null) { - return new ColorTypeProperty(new ColorType(nameval)); + return new ColorTypeProperty(nameval); } return super.convertPropertyDatatype(p, propertyList, fo); } diff --git a/src/java/org/apache/fop/fo/KeepProperty.java b/src/java/org/apache/fop/fo/KeepProperty.java index a4fa0595d..a7d659dc3 100644 --- a/src/java/org/apache/fop/fo/KeepProperty.java +++ b/src/java/org/apache/fop/fo/KeepProperty.java @@ -51,13 +51,16 @@ package org.apache.fop.fo; import org.apache.fop.apps.FOPException; -import org.apache.fop.datatypes.Keep; +import org.apache.fop.datatypes.CompoundDatatype; import org.apache.fop.fo.properties.CompoundPropertyMaker; /** * Superclass for properties that wrap Keep values */ -public class KeepProperty extends Property { +public class KeepProperty extends Property implements CompoundDatatype { + private Property withinLine; + private Property withinColumn; + private Property withinPage; /** * Inner class for creating instances of KeepProperty @@ -76,7 +79,7 @@ public class KeepProperty extends Property { * @return the new instance. */ public Property makeNewProperty() { - return new KeepProperty(new Keep()); + return new KeepProperty(); } /** @@ -92,27 +95,104 @@ public class KeepProperty extends Property { } } - private Keep keep; + /** + * @see org.apache.fop.datatypes.CompoundDatatype#setComponent(int, Property, boolean) + */ + public void setComponent(int cmpId, Property cmpnValue, + boolean bIsDefault) { + if (cmpId == CP_WITHIN_LINE) { + setWithinLine(cmpnValue, bIsDefault); + } else if (cmpId == CP_WITHIN_COLUMN) { + setWithinColumn(cmpnValue, bIsDefault); + } else if (cmpId == CP_WITHIN_PAGE) { + setWithinPage(cmpnValue, bIsDefault); + } + } + + /** + * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int) + */ + public Property getComponent(int cmpId) { + if (cmpId == CP_WITHIN_LINE) { + return getWithinLine(); + } else if (cmpId == CP_WITHIN_COLUMN) { + return getWithinColumn(); + } else if (cmpId == CP_WITHIN_PAGE) { + return getWithinPage(); + } else { + return null; + } + } + + /** + * @param withinLine withinLine property to set + * @param bIsDefault not used (??) + */ + public void setWithinLine(Property withinLine, boolean bIsDefault) { + this.withinLine = withinLine; + } + + /** + * @param withinColumn withinColumn property to set + * @param bIsDefault not used (??) + */ + protected void setWithinColumn(Property withinColumn, + boolean bIsDefault) { + this.withinColumn = withinColumn; + } + + /** + * @param withinPage withinPage property to set + * @param bIsDefault not used (??) + */ + public void setWithinPage(Property withinPage, boolean bIsDefault) { + this.withinPage = withinPage; + } + + /** + * @return the withinLine property + */ + public Property getWithinLine() { + return this.withinLine; + } + + /** + * @return the withinColumn property + */ + public Property getWithinColumn() { + return this.withinColumn; + } + + /** + * @return the withinPage property + */ + public Property getWithinPage() { + return this.withinPage; + } /** - * @param keep Keep value to wrap in this Property + * Not sure what to do here. There isn't really a meaningful single value. + * @return String representation */ - public KeepProperty(Keep keep) { - this.keep = keep; + public String toString() { + return "Keep[" + + "withinLine:" + getWithinLine().getObject() + + ", withinColumn:" + getWithinColumn().getObject() + + ", withinPage:" + getWithinPage().getObject() + "]"; } /** * @return this.keep */ - public Keep getKeep() { - return this.keep; + public KeepProperty getKeep() { + return this; } /** * @return this.keep cast as Object */ public Object getObject() { - return this.keep; + return this; } } diff --git a/src/java/org/apache/fop/fo/LengthPairProperty.java b/src/java/org/apache/fop/fo/LengthPairProperty.java index d9170c268..e56bcab2b 100644 --- a/src/java/org/apache/fop/fo/LengthPairProperty.java +++ b/src/java/org/apache/fop/fo/LengthPairProperty.java @@ -51,13 +51,15 @@ package org.apache.fop.fo; import org.apache.fop.apps.FOPException; -import org.apache.fop.datatypes.LengthPair; +import org.apache.fop.datatypes.CompoundDatatype; import org.apache.fop.fo.properties.CompoundPropertyMaker; /** * Superclass for properties wrapping a LengthPair value */ -public class LengthPairProperty extends Property { +public class LengthPairProperty extends Property implements CompoundDatatype { + private Property ipd; + private Property bpd; /** * Inner class for creating instances of LengthPairProperty @@ -76,7 +78,7 @@ public class LengthPairProperty extends Property { * @return the new instance. */ public Property makeNewProperty() { - return new LengthPairProperty(new LengthPair()); + return new LengthPairProperty(); } /** @@ -92,27 +94,63 @@ public class LengthPairProperty extends Property { } } - private LengthPair lengthPair; + /** + * @see org.apache.fop.datatypes.CompoundDatatype#setComponent(int, Property, boolean) + */ + public void setComponent(int cmpId, Property cmpnValue, + boolean bIsDefault) { + if (cmpId == CP_BLOCK_PROGRESSION_DIRECTION) { + bpd = cmpnValue; + } else if (cmpId == CP_INLINE_PROGRESSION_DIRECTION) { + ipd = cmpnValue; + } + } /** - * @param lengthPair the LengthPair object to be wrapped in this Property + * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int) */ - public LengthPairProperty(LengthPair lengthPair) { - this.lengthPair = lengthPair; + public Property getComponent(int cmpId) { + if (cmpId == CP_BLOCK_PROGRESSION_DIRECTION) { + return getBPD(); + } else if (cmpId == CP_INLINE_PROGRESSION_DIRECTION) { + return getIPD(); + } else { + return null; // SHOULDN'T HAPPEN + } + } + + /** + * @return Property holding the ipd length + */ + public Property getIPD() { + return this.ipd; + } + + /** + * @return Property holding the bpd length + */ + public Property getBPD() { + return this.bpd; + } + + public String toString() { + return "LengthPair[" + + "ipd:" + getIPD().getObject() + + ", bpd:" + getBPD().getObject() + "]"; } /** * @return this.lengthPair */ - public LengthPair getLengthPair() { - return this.lengthPair; + public LengthPairProperty getLengthPair() { + return this; } /** * @return this.lengthPair cast as an Object */ public Object getObject() { - return this.lengthPair; + return this; } } diff --git a/src/java/org/apache/fop/fo/LengthProperty.java b/src/java/org/apache/fop/fo/LengthProperty.java index f42be2be9..fd69848ce 100644 --- a/src/java/org/apache/fop/fo/LengthProperty.java +++ b/src/java/org/apache/fop/fo/LengthProperty.java @@ -50,16 +50,20 @@ */ package org.apache.fop.fo; -import org.apache.fop.datatypes.Length; +import org.apache.fop.apps.FOPException; import org.apache.fop.datatypes.AutoLength; -import org.apache.fop.fo.expr.Numeric; +import org.apache.fop.datatypes.Length; +import org.apache.fop.fo.expr.NumericProperty; import org.apache.fop.fo.properties.PropertyMaker; -import org.apache.fop.apps.FOPException; /** * Superclass for properties wrapping a Length value. */ -public class LengthProperty extends Property { +public class LengthProperty extends Property implements Length { + /** Holds the length in millipoints. */ + protected int millipoints = 0; + /** Indicates if the value has been computed, or not. */ + protected boolean bIsComputed = false; /** * Inner class for making instances of LengthProperty @@ -111,60 +115,127 @@ public class LengthProperty extends Property { if (isAutoLengthAllowed()) { String pval = p.getString(); if (pval != null && pval.equals("auto")) { - return new LengthProperty(new AutoLength()); + return new AutoLength(); } } if (p instanceof LengthProperty) { return p; } - Length val = p.getLength(); + LengthProperty val = p.getLength(); if (val != null) { - return new LengthProperty(val); + return val; } return convertPropertyDatatype(p, propertyList, fo); } } - /* - * public static Property.Maker maker(String prop) { - * return new Maker(prop); - * } + + /** + * Returns the length in 1/1000ths of a point (millipoints) + * @return the length in millipoints + */ + public int getValue() { + if (!bIsComputed) { + computeValue(); + } + return millipoints; + } + + /** + * Computes the value. + */ + protected void computeValue() { + } + + + /** + * Sets the computed value. + * @param millipoints the length in millipoints + */ + protected void setComputedValue(int millipoints) { + setComputedValue(millipoints, true); + } + + /** + * Sets the computed value. + * @param millipoints the length in millipoints + * @param bSetComputed True if the isComputed flag should be set. + */ + protected void setComputedValue(int millipoints, boolean bSetComputed) { + this.millipoints = millipoints; + this.bIsComputed = bSetComputed; + } + + /** + * Indicates if the length has the "auto" value. + * @return True if the length is set to "auto" + */ + public boolean isAuto() { + return false; + } + + /** + * Indicates if the length has been computed. + * @return True if the length has been computed + */ + public boolean isComputed() { + return this.bIsComputed; + } + + /** + * Return the number of table units which are included in this + * length specification. + * This will always be 0 unless the property specification used + * the proportional-column-width() function (only only table + * column FOs). + *

If this value is not 0, the actual value of the Length cannot + * be known without looking at all of the columns in the table to + * determine the value of a "table-unit". + * @return The number of table units which are included in this + * length specification. */ + public double getTableUnits() { + return 0.0; + } + + public void resolveTableUnit(double dTableUnit) { + } /** - * This object may be also be a subclass of Length, such - * as PercentLength, TableColLength. + * @return null (cannot be converted to a Numeric ??) */ - private Length length; + public NumericProperty asNumeric() { + return null; + } /** - * @param length Length object to wrap in this + * @see java.lang.Object#toString() */ - public LengthProperty(Length length) { - this.length = length; - // System.err.println("Set LengthProperty: " + length.toString()); + public String toString() { + String s = millipoints + "mpt"; + return s; } /** * @return this.lenght cast as a Numeric */ - public Numeric getNumeric() { - return length.asNumeric() ; + public NumericProperty getNumeric() { + return asNumeric() ; } /** * @return this.length */ - public Length getLength() { - return this.length; + public LengthProperty getLength() { + return this; } /** * @return this.length cast as an Object */ public Object getObject() { - return this.length; + return this; } } diff --git a/src/java/org/apache/fop/fo/LengthRangeProperty.java b/src/java/org/apache/fop/fo/LengthRangeProperty.java index a57211cc5..218cf5514 100644 --- a/src/java/org/apache/fop/fo/LengthRangeProperty.java +++ b/src/java/org/apache/fop/fo/LengthRangeProperty.java @@ -50,14 +50,22 @@ */ package org.apache.fop.fo; -import org.apache.fop.datatypes.LengthRange; -import org.apache.fop.fo.properties.CompoundPropertyMaker; import org.apache.fop.apps.FOPException; +import org.apache.fop.datatypes.CompoundDatatype; +import org.apache.fop.fo.properties.CompoundPropertyMaker; /** * Superclass for properties that contain LengthRange values */ -public class LengthRangeProperty extends Property { +public class LengthRangeProperty extends Property implements CompoundDatatype { + private Property minimum; + private Property optimum; + private Property maximum; + private static final int MINSET = 1; + private static final int OPTSET = 2; + private static final int MAXSET = 4; + private int bfSet = 0; // bit field + private boolean bChecked = false; /** * Inner class for a Maker for LengthProperty objects @@ -76,7 +84,7 @@ public class LengthRangeProperty extends Property { * @return the new instance. */ public Property makeNewProperty() { - return new LengthRangeProperty(new LengthRange()); + return new LengthRangeProperty(); } /** @@ -92,27 +100,179 @@ public class LengthRangeProperty extends Property { } } - private LengthRange lengthRange; + + + /** + * @see org.apache.fop.datatypes.CompoundDatatype#setComponent(int, Property, boolean) + */ + public void setComponent(int cmpId, Property cmpnValue, + boolean bIsDefault) { + if (cmpId == CP_MINIMUM) { + setMinimum(cmpnValue, bIsDefault); + } else if (cmpId == CP_OPTIMUM) { + setOptimum(cmpnValue, bIsDefault); + } else if (cmpId == CP_MAXIMUM) { + setMaximum(cmpnValue, bIsDefault); + } + } + + /** + * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int) + */ + public Property getComponent(int cmpId) { + if (cmpId == CP_MINIMUM) { + return getMinimum(); + } else if (cmpId == CP_OPTIMUM) { + return getOptimum(); + } else if (cmpId == CP_MAXIMUM) { + return getMaximum(); + } else { + return null; // SHOULDN'T HAPPEN + } + } + + /** + * Set minimum value to min. + * @param minimum A Length value specifying the minimum value for this + * LengthRange. + * @param bIsDefault If true, this is set as a "default" value + * and not a user-specified explicit value. + */ + protected void setMinimum(Property minimum, boolean bIsDefault) { + this.minimum = minimum; + if (!bIsDefault) { + bfSet |= MINSET; + } + } + + + /** + * Set maximum value to max if it is >= optimum or optimum isn't set. + * @param max A Length value specifying the maximum value for this + * @param bIsDefault If true, this is set as a "default" value + * and not a user-specified explicit value. + */ + protected void setMaximum(Property max, boolean bIsDefault) { + maximum = max; + if (!bIsDefault) { + bfSet |= MAXSET; + } + } + /** - * @param lengthRange LengthRange object to wrap in this + * Set the optimum value. + * @param opt A Length value specifying the optimum value for this + * @param bIsDefault If true, this is set as a "default" value + * and not a user-specified explicit value. */ - public LengthRangeProperty(LengthRange lengthRange) { - this.lengthRange = lengthRange; + protected void setOptimum(Property opt, boolean bIsDefault) { + optimum = opt; + if (!bIsDefault) { + bfSet |= OPTSET; + } + } + + // Minimum is prioritaire, if explicit + private void checkConsistency() { + if (bChecked) { + return; + } + // Make sure max >= min + // Must also control if have any allowed enum values! + + /** + * ******************* + * if (minimum.mvalue() > maximum.mvalue()) { + * if ((bfSet&MINSET)!=0) { + * // if minimum is explicit, force max to min + * if ((bfSet&MAXSET)!=0) { + * // Warning: min>max, resetting max to min + * log.error("forcing max to min in LengthRange"); + * } + * maximum = minimum ; + * } + * else { + * minimum = maximum; // minimum was default value + * } + * } + * // Now make sure opt <= max and opt >= min + * if (optimum.mvalue() > maximum.mvalue()) { + * if ((bfSet&OPTSET)!=0) { + * if ((bfSet&MAXSET)!=0) { + * // Warning: opt > max, resetting opt to max + * log.error("forcing opt to max in LengthRange"); + * optimum = maximum ; + * } + * else { + * maximum = optimum; // maximum was default value + * } + * } + * else { + * // opt is default and max is explicit or default + * optimum = maximum ; + * } + * } + * else if (optimum.mvalue() < minimum.mvalue()) { + * if ((bfSet&MINSET)!=0) { + * // if minimum is explicit, force opt to min + * if ((bfSet&OPTSET)!=0) { + * log.error("forcing opt to min in LengthRange"); + * } + * optimum = minimum ; + * } + * else { + * minimum = optimum; // minimum was default value + * } + * } + * *******$******* + */ + bChecked = true; + } + + /** + * @return minimum length + */ + public Property getMinimum() { + checkConsistency(); + return this.minimum; + } + + /** + * @return maximum length + */ + public Property getMaximum() { + checkConsistency(); + return this.maximum; + } + + /** + * @return optimum length + */ + public Property getOptimum() { + checkConsistency(); + return this.optimum; + } + + public String toString() { + return "LengthRange[" + + "min:" + getMinimum().getObject() + + ", max:" + getMaximum().getObject() + + ", opt:" + getOptimum().getObject() + "]"; } /** * @return this.lengthRange */ - public LengthRange getLengthRange() { - return this.lengthRange; + public LengthRangeProperty getLengthRange() { + return this; } /** * @return this.lengthRange cast as an Object */ public Object getObject() { - return this.lengthRange; + return this; } } diff --git a/src/java/org/apache/fop/fo/NumberProperty.java b/src/java/org/apache/fop/fo/NumberProperty.java index 8c98dd06e..9288cb8d7 100644 --- a/src/java/org/apache/fop/fo/NumberProperty.java +++ b/src/java/org/apache/fop/fo/NumberProperty.java @@ -50,8 +50,7 @@ */ package org.apache.fop.fo; -import org.apache.fop.datatypes.ColorType; -import org.apache.fop.fo.expr.Numeric; +import org.apache.fop.fo.expr.NumericProperty; import org.apache.fop.fo.properties.PropertyMaker; /** @@ -142,18 +141,18 @@ public class NumberProperty extends Property { * Convert NumberProperty to Numeric object * @return Numeric object corresponding to this */ - public Numeric getNumeric() { - return new Numeric(this.number); + public NumericProperty getNumeric() { + return new NumericProperty(this.number); } /** * Convert NumberProperty to a ColorType. Not sure why this is needed. * @return ColorType that corresponds to black */ - public ColorType getColorType() { + public ColorTypeProperty getColorType() { // Convert numeric value to color ??? // Convert to hexadecimal and then try to make it into a color? - return new ColorType((float)0.0, (float)0.0, (float)0.0); + return new ColorTypeProperty((float)0.0, (float)0.0, (float)0.0); } } diff --git a/src/java/org/apache/fop/fo/Property.java b/src/java/org/apache/fop/fo/Property.java index 17d5d3648..80b68d4ed 100644 --- a/src/java/org/apache/fop/fo/Property.java +++ b/src/java/org/apache/fop/fo/Property.java @@ -50,14 +50,7 @@ */ package org.apache.fop.fo; -import org.apache.fop.datatypes.ColorType; -import org.apache.fop.datatypes.CondLength; -import org.apache.fop.datatypes.Keep; -import org.apache.fop.datatypes.Length; -import org.apache.fop.datatypes.LengthPair; -import org.apache.fop.datatypes.LengthRange; -import org.apache.fop.datatypes.Space; -import org.apache.fop.fo.expr.Numeric; +import org.apache.fop.fo.expr.NumericProperty; import java.util.Vector; /** @@ -97,7 +90,7 @@ public class Property { * This method expects to be overridden by subclasses * @return Length property value */ - public Length getLength() { + public LengthProperty getLength() { return null; } @@ -105,7 +98,7 @@ public class Property { * This method expects to be overridden by subclasses * @return ColorType property value */ - public ColorType getColorType() { + public ColorTypeProperty getColorType() { return null; } @@ -113,7 +106,7 @@ public class Property { * This method expects to be overridden by subclasses * @return CondLength property value */ - public CondLength getCondLength() { + public CondLengthProperty getCondLength() { return null; } @@ -121,7 +114,7 @@ public class Property { * This method expects to be overridden by subclasses * @return LenghtRange property value */ - public LengthRange getLengthRange() { + public LengthRangeProperty getLengthRange() { return null; } @@ -129,7 +122,7 @@ public class Property { * This method expects to be overridden by subclasses * @return LengthPair property value */ - public LengthPair getLengthPair() { + public LengthPairProperty getLengthPair() { return null; } @@ -137,7 +130,7 @@ public class Property { * This method expects to be overridden by subclasses * @return Space property value */ - public Space getSpace() { + public SpaceProperty getSpace() { return null; } @@ -145,7 +138,7 @@ public class Property { * This method expects to be overridden by subclasses * @return Keep property value */ - public Keep getKeep() { + public KeepProperty getKeep() { return null; } @@ -185,7 +178,7 @@ public class Property { * This method expects to be overridden by subclasses * @return Numeric property value */ - public Numeric getNumeric() { + public NumericProperty getNumeric() { return null; } @@ -210,8 +203,7 @@ public class Property { * @return String property value */ public String getString() { - Object o = getObject(); - return (o == null) ? null : o.toString(); + return null; } /** diff --git a/src/java/org/apache/fop/fo/SpaceProperty.java b/src/java/org/apache/fop/fo/SpaceProperty.java index 40d33b08a..7f2c15425 100644 --- a/src/java/org/apache/fop/fo/SpaceProperty.java +++ b/src/java/org/apache/fop/fo/SpaceProperty.java @@ -51,8 +51,6 @@ package org.apache.fop.fo; import org.apache.fop.apps.FOPException; -import org.apache.fop.datatypes.LengthRange; -import org.apache.fop.datatypes.Space; import org.apache.fop.fo.properties.CompoundPropertyMaker; /** @@ -60,7 +58,9 @@ import org.apache.fop.fo.properties.CompoundPropertyMaker; * fo:space-after variety. It is extended by org.apache.fop.fo.properties.GenericSpace, * which is extended by many other properties. */ -public class SpaceProperty extends Property { +public class SpaceProperty extends LengthRangeProperty { + private Property precedence; + private Property conditionality; /** * Inner class used to create new instances of SpaceProperty @@ -79,7 +79,7 @@ public class SpaceProperty extends Property { * @return the new instance. */ public Property makeNewProperty() { - return new SpaceProperty(new Space()); + return new SpaceProperty(); } /** @@ -95,35 +95,97 @@ public class SpaceProperty extends Property { } } - private Space space; + /** - * @param space the Space object (datatype) to be stored here + * @see org.apache.fop.datatypes.CompoundDatatype#setComponent(int, Property, boolean) */ - public SpaceProperty(Space space) { - this.space = space; + public void setComponent(int cmpId, Property cmpnValue, + boolean bIsDefault) { + if (cmpId == CP_PRECEDENCE) { + setPrecedence(cmpnValue, bIsDefault); + } else if (cmpId == CP_CONDITIONALITY) { + setConditionality(cmpnValue, bIsDefault); + } else { + super.setComponent(cmpId, cmpnValue, bIsDefault); + } + } + + /** + * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int) + */ + public Property getComponent(int cmpId) { + if (cmpId == CP_PRECEDENCE) { + return getPrecedence(); + } else if (cmpId == CP_CONDITIONALITY) { + return getConditionality(); + } else { + return super.getComponent(cmpId); + } + } + + /** + * + * @param precedence precedence Property to set + * @param bIsDefault (is not used anywhere) + */ + protected void setPrecedence(Property precedence, boolean bIsDefault) { + this.precedence = precedence; + } + + /** + * + * @param conditionality conditionality Property to set + * @param bIsDefault (is not used anywhere) + */ + protected void setConditionality(Property conditionality, + boolean bIsDefault) { + this.conditionality = conditionality; + } + + /** + * @return precedence Property + */ + public Property getPrecedence() { + return this.precedence; + } + + /** + * @return conditionality Property + */ + public Property getConditionality() { + return this.conditionality; + } + + public String toString() { + return "Space[" + + "min:" + getMinimum().getObject() + + ", max:" + getMaximum().getObject() + + ", opt:" + getOptimum().getObject() + + ", precedence:" + precedence.getObject() + + ", conditionality:" + conditionality.getObject() + "]"; } /** * @return the Space (datatype) object contained here */ - public Space getSpace() { - return this.space; + public SpaceProperty getSpace() { + return this; } /** * Space extends LengthRange. * @return the Space (datatype) object contained here */ - public LengthRange getLengthRange() { - return this.space; + public LengthRangeProperty getLengthRange() { + return this; } /** * @return the Space (datatype) object contained here */ public Object getObject() { - return this.space; + return this; } } diff --git a/src/java/org/apache/fop/fo/expr/AbsFunction.java b/src/java/org/apache/fop/fo/expr/AbsFunction.java index 9acfb1596..f29bb8c6c 100644 --- a/src/java/org/apache/fop/fo/expr/AbsFunction.java +++ b/src/java/org/apache/fop/fo/expr/AbsFunction.java @@ -73,12 +73,12 @@ public class AbsFunction extends FunctionBase { */ public Property eval(Property[] args, PropertyInfo propInfo) throws PropertyException { - Numeric num = args[0].getNumeric(); + NumericProperty num = args[0].getNumeric(); if (num == null) { throw new PropertyException("Non numeric operand to abs function"); } // TODO: What if it has relative components (percent, table-col units)? - return new NumericProperty(num.abs()); + return num.abs(); } } diff --git a/src/java/org/apache/fop/fo/expr/BodyStartFunction.java b/src/java/org/apache/fop/fo/expr/BodyStartFunction.java index 6a68d42b3..69416d770 100644 --- a/src/java/org/apache/fop/fo/expr/BodyStartFunction.java +++ b/src/java/org/apache/fop/fo/expr/BodyStartFunction.java @@ -77,7 +77,7 @@ public class BodyStartFunction extends FunctionBase { */ public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { - Numeric distance = + NumericProperty distance = pInfo.getPropertyList().get(Constants.PR_PROVISIONAL_DISTANCE_BETWEEN_STARTS).getNumeric(); FONode item = pInfo.getFO(); @@ -88,10 +88,10 @@ public class BodyStartFunction extends FunctionBase { throw new PropertyException("body-start() called from outside an fo:list-item"); } - Numeric startIndent = + NumericProperty startIndent = ((ListItem)item).propertyList.get(Constants.PR_START_INDENT).getNumeric(); - return new NumericProperty(distance.add(startIndent)); + return distance.add(startIndent); } } diff --git a/src/java/org/apache/fop/fo/expr/LabelEndFunction.java b/src/java/org/apache/fop/fo/expr/LabelEndFunction.java index 8306857d2..e44b29951 100644 --- a/src/java/org/apache/fop/fo/expr/LabelEndFunction.java +++ b/src/java/org/apache/fop/fo/expr/LabelEndFunction.java @@ -50,7 +50,6 @@ */ package org.apache.fop.fo.expr; -import org.apache.fop.datatypes.Length; import org.apache.fop.datatypes.LengthBase; import org.apache.fop.datatypes.LinearCombinationLength; import org.apache.fop.datatypes.PercentLength; @@ -84,9 +83,9 @@ public class LabelEndFunction extends FunctionBase { public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { - Length distance = + LengthProperty distance = pInfo.getPropertyList().get(Constants.PR_PROVISIONAL_DISTANCE_BETWEEN_STARTS).getLength(); - Length separation = + LengthProperty separation = pInfo.getPropertyList().getNearestSpecified(Constants.PR_PROVISIONAL_LABEL_SEPARATION).getLength(); FONode item = pInfo.getFO(); @@ -96,7 +95,7 @@ public class LabelEndFunction extends FunctionBase { if (item == null) { throw new PropertyException("label-end() called from outside an fo:list-item"); } - Length startIndent = ((ListItem)item).propertyList.get(Constants.PR_START_INDENT).getLength(); + LengthProperty startIndent = ((ListItem)item).propertyList.get(Constants.PR_START_INDENT).getLength(); LinearCombinationLength labelEnd = new LinearCombinationLength(); @@ -110,7 +109,7 @@ public class LabelEndFunction extends FunctionBase { labelEnd.addTerm(-1.0, startIndent); labelEnd.addTerm(1.0, separation); - return new LengthProperty(labelEnd); + return labelEnd; } } diff --git a/src/java/org/apache/fop/fo/expr/MaxFunction.java b/src/java/org/apache/fop/fo/expr/MaxFunction.java index dc208d0ae..40c8a407a 100644 --- a/src/java/org/apache/fop/fo/expr/MaxFunction.java +++ b/src/java/org/apache/fop/fo/expr/MaxFunction.java @@ -74,12 +74,12 @@ public class MaxFunction extends FunctionBase { */ public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { - Numeric n1 = args[0].getNumeric(); - Numeric n2 = args[1].getNumeric(); + NumericProperty n1 = args[0].getNumeric(); + NumericProperty n2 = args[1].getNumeric(); if (n1 == null || n2 == null) { throw new PropertyException("Non numeric operands to max function"); } - return new NumericProperty(n1.max(n2)); + return n1.max(n2); } } diff --git a/src/java/org/apache/fop/fo/expr/MinFunction.java b/src/java/org/apache/fop/fo/expr/MinFunction.java index 02b4e3f62..cdb9f25a3 100644 --- a/src/java/org/apache/fop/fo/expr/MinFunction.java +++ b/src/java/org/apache/fop/fo/expr/MinFunction.java @@ -74,12 +74,12 @@ public class MinFunction extends FunctionBase { */ public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { - Numeric n1 = args[0].getNumeric(); - Numeric n2 = args[1].getNumeric(); + NumericProperty n1 = args[0].getNumeric(); + NumericProperty n2 = args[1].getNumeric(); if (n1 == null || n2 == null) { throw new PropertyException("Non numeric operands to min function"); } - return new NumericProperty(n1.min(n2)); + return n1.min(n2); } } diff --git a/src/java/org/apache/fop/fo/expr/Numeric.java b/src/java/org/apache/fop/fo/expr/Numeric.java deleted file mode 100644 index 2845637e5..000000000 --- a/src/java/org/apache/fop/fo/expr/Numeric.java +++ /dev/null @@ -1,429 +0,0 @@ -/* - * $Id: Numeric.java,v 1.6 2003/03/05 20:38:26 jeremias Exp $ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.expr; - -import java.util.Vector; - -import org.apache.fop.datatypes.Length; -import org.apache.fop.datatypes.FixedLength; -import org.apache.fop.datatypes.PercentLength; -import org.apache.fop.datatypes.MixedLength; -import org.apache.fop.datatypes.TableColLength; -import org.apache.fop.datatypes.PercentBase; - -/** - * Represents a "numeric" value as defined by the XSL FO Specification. - * This consists of one or more kinds of value specifications, from - * absolute numbers (units power of 0) to lengths (unit power of 1), - * relative lengths (ems), percentage lengths. - * A Numeric can be constructed from other Property types representing - * Numbers or Length-type values. - * Numeric provides methods to return Number and Length values based on - * its current value. - * It supports basic arithmetic operations involving Numerics. - */ -public class Numeric { - // Bit fields - - /** constant for a length of absolute units (or number) */ - public static final int ABS_LENGTH = 1; - /** constant for a percentage */ - public static final int PC_LENGTH = 2; - /** constant for table units */ - public static final int TCOL_LENGTH = 4; - - private int valType; - private double absValue; - private double pcValue; - private PercentBase pcBase = null; // base value for PC_LENGTH component - private double tcolValue; - private int dim; - - - /** - * Construct a Numeric object by specifying one or more components, - * including absolute length, percent length, table units. - * @param valType A combination of bits representing the value types. - * @param absValue The value of a Number or resolved Length value if - * the ABS_LENGTH flag is set. - * @param pcValue The decimal percent value if the PC_LENGTH flag is set - * @param tcolValue The decimal table unit value if the TCOL_LENGTH flag - * is set. - * @param dim The dimension of the value. 0 for a Number, 1 for a Length - * (any type), >1, <0 if Lengths have been multiplied or divided. - * @param pcBase The PercentBase object used to calculate an actual value for - * a PC_LENGTH. - */ - protected Numeric(int valType, double absValue, double pcValue, - double tcolValue, int dim, PercentBase pcBase) { - this.valType = valType; - this.absValue = absValue; - this.pcValue = pcValue; - this.tcolValue = tcolValue; - this.dim = dim; - this.pcBase = pcBase; - } - - /** - * Construct a Numeric object of dimension 0 from a double. - * @param valType A combination of bits representing the value types. - * @param absValue The value of a Number or resolved Length value. - */ - - /** - * * - * protected Numeric(int valType, double absValue) { - * this.valType = valType; - * this.absValue = absValue; - * } - */ - - /** - * Construct a Numeric object from a Number. - * @param num The number. - */ - public Numeric(Number num) { - this(ABS_LENGTH, num.doubleValue(), 0.0, 0.0, 0, null); - } - - /** - * Construct a Numeric object from a Length. - * @param l The Length. - */ - public Numeric(FixedLength l) { - this(ABS_LENGTH, (double)l.getValue(), 0.0, 0.0, 1, null); - } - - /** - * Construct a Numeric object from a PercentLength. - * @param pclen The PercentLength. - */ - public Numeric(PercentLength pclen) { - this(PC_LENGTH, 0.0, pclen.value(), 0.0, 1, pclen.getBaseLength()); - } - - /** - * Construct a Numeric object from a TableColLength. - * @param tclen The TableColLength. - */ - public Numeric(TableColLength tclen) { - this(TCOL_LENGTH, 0.0, 0.0, tclen.getTableUnits(), 1, null); - } - - - /** - * @return the current value as a Length if possible. This constructs - * a new Length or Length subclass based on the current value type - * of the Numeric. - * If the stored value has a unit dimension other than 1, null - * is returned. - */ - public Length asLength() { - if (dim == 1) { - Vector len = new Vector(3); - if ((valType & ABS_LENGTH) != 0) { - len.add(new FixedLength((int)absValue)); - } - if ((valType & PC_LENGTH) != 0) { - len.add(new PercentLength(pcValue, pcBase)); - } - if ((valType & TCOL_LENGTH) != 0) { - len.add(new TableColLength(tcolValue)); - } - if (len.size() == 1) { - return (Length)len.elementAt(0); - } else { - return new MixedLength(len); - } - } else { - // or throw exception??? - // can't make Length if dimension != 1 - return null; - } - } - - /** - * @return the current value as a Number if possible. - * Calls asDouble(). - */ - public Number asNumber() { - return asDouble(); - } - - /** - * @return the current value as a Double - */ - public Double asDouble() { - if (dim == 0 && valType == ABS_LENGTH) { - return new Double(absValue); - } else { - // or throw exception??? - // can't make Number if dimension != 0 - return null; - } - } - - /** - * Return the current value as a Integer if possible. - * If the unit dimension is 0 and the value type is ABSOLUTE, an Integer - * is returned. Otherwise null is returned. Note: the current value is - * truncated if necessary to make an integer value. - */ - - /** - * public Integer asInteger() { - * if (dim == 0 && valType==ABS_LENGTH) { - * return new Integer((int)absValue); - * } - * else { - * // or throw exception??? - * // can't make Number if dimension != 0 - * return null; - * } - * } - */ - - /** - * Return a boolean value indiciating whether the currently stored - * value consists of different "types" of values (absolute, percent, - * and/or table-unit.) - */ - private boolean isMixedType() { - int ntype = 0; - for (int t = valType; t != 0; t = t >> 1) { - if ((t & 1) != 0) { - ++ntype; - } - } - return ntype > 1; - } - - /** - * Subtract the operand from the current value and return a new Numeric - * representing the result. - * @param op The value to subtract. - * @return A Numeric representing the result. - * @throws PropertyException If the dimension of the operand is different - * from the dimension of this Numeric. - */ - public Numeric subtract(Numeric op) throws PropertyException { - // Check of same dimension - // Add together absolute and table units - // What about percentages??? Treat as colUnits if they can't be - // in same property! - if (dim == op.dim) { - PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase - : op.pcBase; - // Subtract each type of value - return new Numeric(valType | op.valType, absValue - op.absValue, - pcValue - op.pcValue, - tcolValue - op.tcolValue, dim, npcBase); - } else { - throw new PropertyException("Can't add Numerics of different dimensions"); - } - } - - /** - * Add the operand from the current value and return a new Numeric - * representing the result. - * @param op The value to add. - * @return A Numeric representing the result. - * @throws PropertyException If the dimension of the operand is different - * from the dimension of this Numeric. - */ - public Numeric add(Numeric op) throws PropertyException { - // Check of same dimension - // Add together absolute and table units - // What about percentages??? Treat as colUnits if they can't be - // in same property! - if (dim == op.dim) { - PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase - : op.pcBase; - // Add each type of value - return new Numeric(valType | op.valType, absValue + op.absValue, - pcValue + op.pcValue, - tcolValue + op.tcolValue, dim, npcBase); - } else { - throw new PropertyException("Can't add Numerics of different dimensions"); - } - } - - /** - * Multiply the the current value by the operand and return a new Numeric - * representing the result. - * @param op The multiplier. - * @return A Numeric representing the result. - * @throws PropertyException If both Numerics have "mixed" type. - */ - public Numeric multiply(Numeric op) throws PropertyException { - // Multiply together absolute units and add dimensions (exponents) - // What about percentages??? Treat as colUnits if they can't be - // in same property! - if (dim == 0) { - // This is a dimensionless quantity, ie. a "Number" - return new Numeric(op.valType, absValue * op.absValue, - absValue * op.pcValue, - absValue * op.tcolValue, op.dim, op.pcBase); - } else if (op.dim == 0) { - double opval = op.absValue; - return new Numeric(valType, opval * absValue, opval * pcValue, - opval * tcolValue, dim, pcBase); - } else if (valType == op.valType && !isMixedType()) { - // Check same relbase and pcbase ??? - PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase - : op.pcBase; - return new Numeric(valType, absValue * op.absValue, - pcValue * op.pcValue, - tcolValue * op.tcolValue, dim + op.dim, - npcBase); - } else { - throw new PropertyException("Can't multiply mixed Numerics"); - } - } - - /** - * Divide the the current value by the operand and return a new Numeric - * representing the result. - * @param op The divisor. - * @return A Numeric representing the result. - * @throws PropertyException If both Numerics have "mixed" type. - */ - public Numeric divide(Numeric op) throws PropertyException { - // Multiply together absolute units and add dimensions (exponents) - // What about percentages??? Treat as colUnits if they can't be - // in same property! - if (dim == 0) { - // This is a dimensionless quantity, ie. a "Number" - return new Numeric(op.valType, absValue / op.absValue, - absValue / op.pcValue, - absValue / op.tcolValue, -op.dim, op.pcBase); - } else if (op.dim == 0) { - double opval = op.absValue; - return new Numeric(valType, absValue / opval, pcValue / opval, - tcolValue / opval, dim, pcBase); - } else if (valType == op.valType && !isMixedType()) { - PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase - : op.pcBase; - return new Numeric(valType, - (valType == ABS_LENGTH ? absValue / op.absValue : 0.0), - (valType == PC_LENGTH ? pcValue / op.pcValue : 0.0), - (valType == TCOL_LENGTH ? tcolValue / op.tcolValue : 0.0), - dim - op.dim, npcBase); - } else { - throw new PropertyException("Can't divide mixed Numerics."); - } - } - - /** - * Return the absolute value of this Numeric. - * @return A new Numeric object representing the absolute value. - */ - public Numeric abs() { - return new Numeric(valType, Math.abs(absValue), Math.abs(pcValue), - Math.abs(tcolValue), dim, pcBase); - } - - /** - * @param op the operand to which the current value should be compared - * @return a Numeric which is the maximum of the current value and the - * operand. - * @throws PropertyException If the dimensions or value types of the - * object and the operand are different. - */ - public Numeric max(Numeric op) throws PropertyException { - double rslt = 0.0; - // Only compare if have same dimension and value type! - if (dim == op.dim && valType == op.valType && !isMixedType()) { - if (valType == ABS_LENGTH) { - rslt = absValue - op.absValue; - } else if (valType == PC_LENGTH) { - rslt = pcValue - op.pcValue; - } else if (valType == TCOL_LENGTH) { - rslt = tcolValue - op.tcolValue; - } - if (rslt > 0.0) { - return this; - } else { - return op; - } - } - throw new PropertyException("Arguments to max() must have same dimension and value type."); - } - - /** - * @param op the operand to which the current value should be compared - * @return a Numeric which is the minimum of the current value and the - * operand. - * @throws PropertyException If the dimensions or value types of the - * object and the operand are different. - */ - public Numeric min(Numeric op) throws PropertyException { - double rslt = 0.0; - // Only compare if have same dimension and value type! - if (dim == op.dim && valType == op.valType && !isMixedType()) { - if (valType == ABS_LENGTH) { - rslt = absValue - op.absValue; - } else if (valType == PC_LENGTH) { - rslt = pcValue - op.pcValue; - } else if (valType == TCOL_LENGTH) { - rslt = tcolValue - op.tcolValue; - } - if (rslt > 0.0) { - return op; - } else { - return this; - } - } - throw new PropertyException("Arguments to min() must have same dimension and value type."); - } - -} - diff --git a/src/java/org/apache/fop/fo/expr/NumericProperty.java b/src/java/org/apache/fop/fo/expr/NumericProperty.java index 9f28e14e8..3d9028cba 100644 --- a/src/java/org/apache/fop/fo/expr/NumericProperty.java +++ b/src/java/org/apache/fop/fo/expr/NumericProperty.java @@ -50,36 +50,393 @@ */ package org.apache.fop.fo.expr; +import java.util.Vector; + +import org.apache.fop.datatypes.PercentBase; +import org.apache.fop.datatypes.FixedLength; +import org.apache.fop.datatypes.TableColLength; +import org.apache.fop.datatypes.PercentLength; +import org.apache.fop.datatypes.MixedLength; + +import org.apache.fop.fo.ColorTypeProperty; +import org.apache.fop.fo.LengthProperty; import org.apache.fop.fo.Property; -import org.apache.fop.datatypes.Length; -import org.apache.fop.datatypes.ColorType; -class NumericProperty extends Property { - private Numeric numeric; +public class NumericProperty extends Property { + // Bit fields + + /** constant for a length of absolute units (or number) */ + public static final int ABS_LENGTH = 1; + /** constant for a percentage */ + public static final int PC_LENGTH = 2; + /** constant for table units */ + public static final int TCOL_LENGTH = 4; + + private int valType; + private double absValue; + private double pcValue; + private PercentBase pcBase = null; // base value for PC_LENGTH component + private double tcolValue; + private int dim; + + + /** + * Construct a Numeric object by specifying one or more components, + * including absolute length, percent length, table units. + * @param valType A combination of bits representing the value types. + * @param absValue The value of a Number or resolved Length value if + * the ABS_LENGTH flag is set. + * @param pcValue The decimal percent value if the PC_LENGTH flag is set + * @param tcolValue The decimal table unit value if the TCOL_LENGTH flag + * is set. + * @param dim The dimension of the value. 0 for a Number, 1 for a Length + * (any type), >1, <0 if Lengths have been multiplied or divided. + * @param pcBase The PercentBase object used to calculate an actual value for + * a PC_LENGTH. + */ + protected NumericProperty(int valType, double absValue, double pcValue, + double tcolValue, int dim, PercentBase pcBase) { + this.valType = valType; + this.absValue = absValue; + this.pcValue = pcValue; + this.tcolValue = tcolValue; + this.dim = dim; + this.pcBase = pcBase; + } + + /** + * Construct a Numeric object of dimension 0 from a double. + * @param valType A combination of bits representing the value types. + * @param absValue The value of a Number or resolved Length value. + */ + + /** + * * + * protected Numeric(int valType, double absValue) { + * this.valType = valType; + * this.absValue = absValue; + * } + */ + + /** + * Construct a Numeric object from a Number. + * @param num The number. + */ + public NumericProperty(Number num) { + this(ABS_LENGTH, num.doubleValue(), 0.0, 0.0, 0, null); + } + + /** + * Construct a Numeric object from a Length. + * @param l The Length. + */ + public NumericProperty(FixedLength l) { + this(ABS_LENGTH, (double)l.getValue(), 0.0, 0.0, 1, null); + } + + /** + * Construct a Numeric object from a PercentLength. + * @param pclen The PercentLength. + */ + public NumericProperty(PercentLength pclen) { + this(PC_LENGTH, 0.0, pclen.value(), 0.0, 1, pclen.getBaseLength()); + } + + /** + * Construct a Numeric object from a TableColLength. + * @param tclen The TableColLength. + */ + public NumericProperty(TableColLength tclen) { + this(TCOL_LENGTH, 0.0, 0.0, tclen.getTableUnits(), 1, null); + } + + + /** + * @return the current value as a Length if possible. This constructs + * a new Length or Length subclass based on the current value type + * of the Numeric. + * If the stored value has a unit dimension other than 1, null + * is returned. + */ + public LengthProperty asLength() { + if (dim == 1) { + Vector len = new Vector(3); + if ((valType & ABS_LENGTH) != 0) { + len.add(new FixedLength((int)absValue)); + } + if ((valType & PC_LENGTH) != 0) { + len.add(new PercentLength(pcValue, pcBase)); + } + if ((valType & TCOL_LENGTH) != 0) { + len.add(new TableColLength(tcolValue)); + } + if (len.size() == 1) { + return (LengthProperty)len.elementAt(0); + } else { + return new MixedLength(len); + } + } else { + // or throw exception??? + // can't make Length if dimension != 1 + return null; + } + } + + /** + * @return the current value as a Number if possible. + * Calls asDouble(). + */ + public Number asNumber() { + return asDouble(); + } + + /** + * @return the current value as a Double + */ + public Double asDouble() { + if (dim == 0 && valType == ABS_LENGTH) { + return new Double(absValue); + } else { + // or throw exception??? + // can't make Number if dimension != 0 + return null; + } + } + + /** + * Return the current value as a Integer if possible. + * If the unit dimension is 0 and the value type is ABSOLUTE, an Integer + * is returned. Otherwise null is returned. Note: the current value is + * truncated if necessary to make an integer value. + */ + + /** + * public Integer asInteger() { + * if (dim == 0 && valType==ABS_LENGTH) { + * return new Integer((int)absValue); + * } + * else { + * // or throw exception??? + * // can't make Number if dimension != 0 + * return null; + * } + * } + */ + + /** + * Return a boolean value indiciating whether the currently stored + * value consists of different "types" of values (absolute, percent, + * and/or table-unit.) + */ + private boolean isMixedType() { + int ntype = 0; + for (int t = valType; t != 0; t = t >> 1) { + if ((t & 1) != 0) { + ++ntype; + } + } + return ntype > 1; + } + + /** + * Subtract the operand from the current value and return a new Numeric + * representing the result. + * @param op The value to subtract. + * @return A Numeric representing the result. + * @throws PropertyException If the dimension of the operand is different + * from the dimension of this Numeric. + */ + public NumericProperty subtract(NumericProperty op) throws PropertyException { + // Check of same dimension + // Add together absolute and table units + // What about percentages??? Treat as colUnits if they can't be + // in same property! + if (dim == op.dim) { + PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase + : op.pcBase; + // Subtract each type of value + return new NumericProperty(valType | op.valType, absValue - op.absValue, + pcValue - op.pcValue, + tcolValue - op.tcolValue, dim, npcBase); + } else { + throw new PropertyException("Can't add Numerics of different dimensions"); + } + } + + /** + * Add the operand from the current value and return a new Numeric + * representing the result. + * @param op The value to add. + * @return A Numeric representing the result. + * @throws PropertyException If the dimension of the operand is different + * from the dimension of this Numeric. + */ + public NumericProperty add(NumericProperty op) throws PropertyException { + // Check of same dimension + // Add together absolute and table units + // What about percentages??? Treat as colUnits if they can't be + // in same property! + if (dim == op.dim) { + PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase + : op.pcBase; + // Add each type of value + return new NumericProperty(valType | op.valType, absValue + op.absValue, + pcValue + op.pcValue, + tcolValue + op.tcolValue, dim, npcBase); + } else { + throw new PropertyException("Can't add Numerics of different dimensions"); + } + } + + /** + * Multiply the the current value by the operand and return a new Numeric + * representing the result. + * @param op The multiplier. + * @return A Numeric representing the result. + * @throws PropertyException If both Numerics have "mixed" type. + */ + public NumericProperty multiply(NumericProperty op) throws PropertyException { + // Multiply together absolute units and add dimensions (exponents) + // What about percentages??? Treat as colUnits if they can't be + // in same property! + if (dim == 0) { + // This is a dimensionless quantity, ie. a "Number" + return new NumericProperty(op.valType, absValue * op.absValue, + absValue * op.pcValue, + absValue * op.tcolValue, op.dim, op.pcBase); + } else if (op.dim == 0) { + double opval = op.absValue; + return new NumericProperty(valType, opval * absValue, opval * pcValue, + opval * tcolValue, dim, pcBase); + } else if (valType == op.valType && !isMixedType()) { + // Check same relbase and pcbase ??? + PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase + : op.pcBase; + return new NumericProperty(valType, absValue * op.absValue, + pcValue * op.pcValue, + tcolValue * op.tcolValue, dim + op.dim, + npcBase); + } else { + throw new PropertyException("Can't multiply mixed Numerics"); + } + } + + /** + * Divide the the current value by the operand and return a new Numeric + * representing the result. + * @param op The divisor. + * @return A Numeric representing the result. + * @throws PropertyException If both Numerics have "mixed" type. + */ + public NumericProperty divide(NumericProperty op) throws PropertyException { + // Multiply together absolute units and add dimensions (exponents) + // What about percentages??? Treat as colUnits if they can't be + // in same property! + if (dim == 0) { + // This is a dimensionless quantity, ie. a "Number" + return new NumericProperty(op.valType, absValue / op.absValue, + absValue / op.pcValue, + absValue / op.tcolValue, -op.dim, op.pcBase); + } else if (op.dim == 0) { + double opval = op.absValue; + return new NumericProperty(valType, absValue / opval, pcValue / opval, + tcolValue / opval, dim, pcBase); + } else if (valType == op.valType && !isMixedType()) { + PercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase + : op.pcBase; + return new NumericProperty(valType, + (valType == ABS_LENGTH ? absValue / op.absValue : 0.0), + (valType == PC_LENGTH ? pcValue / op.pcValue : 0.0), + (valType == TCOL_LENGTH ? tcolValue / op.tcolValue : 0.0), + dim - op.dim, npcBase); + } else { + throw new PropertyException("Can't divide mixed Numerics."); + } + } + + /** + * Return the absolute value of this Numeric. + * @return A new Numeric object representing the absolute value. + */ + public NumericProperty abs() { + return new NumericProperty(valType, Math.abs(absValue), Math.abs(pcValue), + Math.abs(tcolValue), dim, pcBase); + } + + /** + * @param op the operand to which the current value should be compared + * @return a Numeric which is the maximum of the current value and the + * operand. + * @throws PropertyException If the dimensions or value types of the + * object and the operand are different. + */ + public NumericProperty max(NumericProperty op) throws PropertyException { + double rslt = 0.0; + // Only compare if have same dimension and value type! + if (dim == op.dim && valType == op.valType && !isMixedType()) { + if (valType == ABS_LENGTH) { + rslt = absValue - op.absValue; + } else if (valType == PC_LENGTH) { + rslt = pcValue - op.pcValue; + } else if (valType == TCOL_LENGTH) { + rslt = tcolValue - op.tcolValue; + } + if (rslt > 0.0) { + return this; + } else { + return op; + } + } + throw new PropertyException("Arguments to max() must have same dimension and value type."); + } - NumericProperty(Numeric value) { - this.numeric = value; + /** + * @param op the operand to which the current value should be compared + * @return a Numeric which is the minimum of the current value and the + * operand. + * @throws PropertyException If the dimensions or value types of the + * object and the operand are different. + */ + public NumericProperty min(NumericProperty op) throws PropertyException { + double rslt = 0.0; + // Only compare if have same dimension and value type! + if (dim == op.dim && valType == op.valType && !isMixedType()) { + if (valType == ABS_LENGTH) { + rslt = absValue - op.absValue; + } else if (valType == PC_LENGTH) { + rslt = pcValue - op.pcValue; + } else if (valType == TCOL_LENGTH) { + rslt = tcolValue - op.tcolValue; + } + if (rslt > 0.0) { + return op; + } else { + return this; + } + } + throw new PropertyException("Arguments to min() must have same dimension and value type."); } + - public Numeric getNumeric() { - return this.numeric; + public NumericProperty getNumeric() { + return this; } public Number getNumber() { - return numeric.asNumber(); + return asNumber(); } - public Length getLength() { - return numeric.asLength(); + public LengthProperty getLength() { + return asLength(); } - public ColorType getColorType() { + public ColorTypeProperty getColorType() { // try converting to numeric number and then to color return null; } public Object getObject() { - return this.numeric; + return this; } } diff --git a/src/java/org/apache/fop/fo/expr/PPColWidthFunction.java b/src/java/org/apache/fop/fo/expr/PPColWidthFunction.java index 1c66675c1..4d2ce74fc 100644 --- a/src/java/org/apache/fop/fo/expr/PPColWidthFunction.java +++ b/src/java/org/apache/fop/fo/expr/PPColWidthFunction.java @@ -52,7 +52,6 @@ package org.apache.fop.fo.expr; import org.apache.fop.fo.Property; -import org.apache.fop.fo.LengthProperty; import org.apache.fop.datatypes.TableColLength; /** @@ -90,7 +89,7 @@ public class PPColWidthFunction extends FunctionBase { + "may only be used on table-column FO"); } // Check if table-layout is "fixed"... - return new LengthProperty(new TableColLength(d.doubleValue())); + return new TableColLength(d.doubleValue()); } } diff --git a/src/java/org/apache/fop/fo/expr/PropertyParser.java b/src/java/org/apache/fop/fo/expr/PropertyParser.java index 3d2c9b3e2..4a2bcca09 100644 --- a/src/java/org/apache/fop/fo/expr/PropertyParser.java +++ b/src/java/org/apache/fop/fo/expr/PropertyParser.java @@ -50,17 +50,15 @@ */ package org.apache.fop.fo.expr; -import org.apache.fop.datatypes.ColorType; import org.apache.fop.datatypes.FixedLength; -import org.apache.fop.datatypes.Length; import org.apache.fop.datatypes.PercentBase; import org.apache.fop.datatypes.PercentLength; import org.apache.fop.fo.Property; +import org.apache.fop.fo.ColorTypeProperty; import org.apache.fop.fo.ListProperty; import org.apache.fop.fo.LengthProperty; import org.apache.fop.fo.NumberProperty; import org.apache.fop.fo.StringProperty; -import org.apache.fop.fo.ColorTypeProperty; import java.util.HashMap; @@ -73,7 +71,7 @@ public class PropertyParser extends PropertyTokenizer { private PropertyInfo propInfo; // Maker and propertyList related info private static final String RELUNIT = "em"; - private static final Numeric NEGATIVE_ONE = new Numeric(new Double(-1.0)); + private static final NumericProperty NEGATIVE_ONE = new NumericProperty(new Double(-1.0)); private static final HashMap FUNCTION_TABLE = new HashMap(); static { @@ -299,8 +297,7 @@ public class PropertyParser extends PropertyTokenizer { if (pcBase.getDimension() == 0) { prop = new NumberProperty(pcval * pcBase.getBaseValue()); } else if (pcBase.getDimension() == 1) { - prop = new LengthProperty(new PercentLength(pcval, - pcBase)); + prop = new PercentLength(pcval, pcBase); } else { throw new PropertyException("Illegal percent dimension value"); } @@ -316,7 +313,7 @@ public class PropertyParser extends PropertyTokenizer { String unitPart = currentTokenValue.substring(numLen); Double numPart = new Double(currentTokenValue.substring(0, numLen)); - Length length = null; + LengthProperty length = null; if (unitPart.equals(RELUNIT)) { length = new FixedLength(numPart.doubleValue(), propInfo.currentFontSize()); @@ -327,12 +324,12 @@ public class PropertyParser extends PropertyTokenizer { throw new PropertyException("unrecognized unit name: " + currentTokenValue); } else { - prop = new LengthProperty(length); + prop = length; } break; case TOK_COLORSPEC: - prop = new ColorTypeProperty(new ColorType(currentTokenValue)); + prop = new ColorTypeProperty(currentTokenValue); break; case TOK_FUNCTION_LPAR: { @@ -404,12 +401,12 @@ public class PropertyParser extends PropertyTokenizer { * the sum of the two operands. * @throws PropertyException If either operand is null. */ - private Property evalAddition(Numeric op1, - Numeric op2) throws PropertyException { + private Property evalAddition(NumericProperty op1, + NumericProperty op2) throws PropertyException { if (op1 == null || op2 == null) { throw new PropertyException("Non numeric operand in addition"); } - return new NumericProperty(op1.add(op2)); + return op1.add(op2); } /** @@ -421,12 +418,12 @@ public class PropertyParser extends PropertyTokenizer { * the difference of the two operands. * @throws PropertyException If either operand is null. */ - private Property evalSubtraction(Numeric op1, - Numeric op2) throws PropertyException { + private Property evalSubtraction(NumericProperty op1, + NumericProperty op2) throws PropertyException { if (op1 == null || op2 == null) { throw new PropertyException("Non numeric operand in subtraction"); } - return new NumericProperty(op1.subtract(op2)); + return op1.subtract(op2); } /** @@ -437,11 +434,11 @@ public class PropertyParser extends PropertyTokenizer { * the negative of the operand (multiplication by *1). * @throws PropertyException If the operand is null. */ - private Property evalNegate(Numeric op) throws PropertyException { + private Property evalNegate(NumericProperty op) throws PropertyException { if (op == null) { throw new PropertyException("Non numeric operand to unary minus"); } - return new NumericProperty(op.multiply(NEGATIVE_ONE)); + return op.multiply(NEGATIVE_ONE); } /** @@ -453,12 +450,12 @@ public class PropertyParser extends PropertyTokenizer { * the product of the two operands. * @throws PropertyException If either operand is null. */ - private Property evalMultiply(Numeric op1, - Numeric op2) throws PropertyException { + private Property evalMultiply(NumericProperty op1, + NumericProperty op2) throws PropertyException { if (op1 == null || op2 == null) { throw new PropertyException("Non numeric operand in multiplication"); } - return new NumericProperty(op1.multiply(op2)); + return op1.multiply(op2); } @@ -471,12 +468,12 @@ public class PropertyParser extends PropertyTokenizer { * op1 divided by op2. * @throws PropertyException If either operand is null. */ - private Property evalDivide(Numeric op1, - Numeric op2) throws PropertyException { + private Property evalDivide(NumericProperty op1, + NumericProperty op2) throws PropertyException { if (op1 == null || op2 == null) { throw new PropertyException("Non numeric operand in division"); } - return new NumericProperty(op1.divide(op2)); + return op1.divide(op2); } /** diff --git a/src/java/org/apache/fop/fo/expr/RGBColorFunction.java b/src/java/org/apache/fop/fo/expr/RGBColorFunction.java index 6b0b439aa..00b58a359 100644 --- a/src/java/org/apache/fop/fo/expr/RGBColorFunction.java +++ b/src/java/org/apache/fop/fo/expr/RGBColorFunction.java @@ -53,7 +53,6 @@ package org.apache.fop.fo.expr; import org.apache.fop.fo.Property; import org.apache.fop.fo.ColorTypeProperty; -import org.apache.fop.datatypes.ColorType; import org.apache.fop.datatypes.PercentBase; class RGBColorFunction extends FunctionBase { @@ -88,8 +87,7 @@ class RGBColorFunction extends FunctionBase { } cfvals[i] = colorVal; } - return new ColorTypeProperty(new ColorType(cfvals[0], cfvals[1], - cfvals[2])); + return new ColorTypeProperty(cfvals[0], cfvals[1], cfvals[2]); } diff --git a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java index 441125769..06141c983 100644 --- a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java +++ b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java @@ -58,9 +58,9 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; import org.apache.fop.fo.FOTreeVisitor; +import org.apache.fop.fo.LengthProperty; import org.apache.fop.image.ImageFactory; import org.apache.fop.image.FopImage; -import org.apache.fop.datatypes.Length; // Java import java.awt.geom.Rectangle2D; @@ -104,7 +104,7 @@ public class ExternalGraphic extends FObj { url = ImageFactory.getURL(url); // assume lr-tb for now and just use the .optimum value of the range - Length ipd = propertyList.get(PR_INLINE_PROGRESSION_DIMENSION). + LengthProperty ipd = propertyList.get(PR_INLINE_PROGRESSION_DIMENSION). getLengthRange().getOptimum().getLength(); if (!ipd.isAuto()) { viewWidth = ipd.getValue(); @@ -114,7 +114,7 @@ public class ExternalGraphic extends FObj { viewWidth = ipd.getValue(); } } - Length bpd = propertyList.get(PR_BLOCK_PROGRESSION_DIMENSION | CP_OPTIMUM).getLength(); + LengthProperty bpd = propertyList.get(PR_BLOCK_PROGRESSION_DIMENSION | CP_OPTIMUM).getLength(); if (!bpd.isAuto()) { viewHeight = bpd.getValue(); } else { @@ -129,7 +129,7 @@ public class ExternalGraphic extends FObj { int cwidth = -1; int cheight = -1; - Length ch = propertyList.get(PR_CONTENT_HEIGHT).getLength(); + LengthProperty ch = propertyList.get(PR_CONTENT_HEIGHT).getLength(); if (!ch.isAuto()) { /*if (ch.scaleToFit()) { if (viewHeight != -1) { @@ -138,7 +138,7 @@ public class ExternalGraphic extends FObj { } else {*/ cheight = ch.getValue(); } - Length cw = propertyList.get(PR_CONTENT_WIDTH).getLength(); + LengthProperty cw = propertyList.get(PR_CONTENT_WIDTH).getLength(); if (!cw.isAuto()) { /*if (cw.scaleToFit()) { if (viewWidth != -1) { diff --git a/src/java/org/apache/fop/fo/flow/Table.java b/src/java/org/apache/fop/fo/flow/Table.java index fbe6be427..ad531aa6f 100644 --- a/src/java/org/apache/fop/fo/flow/Table.java +++ b/src/java/org/apache/fop/fo/flow/Table.java @@ -59,7 +59,7 @@ import org.xml.sax.Attributes; // FOP import org.apache.fop.apps.FOPException; import org.apache.fop.datatypes.ColorType; -import org.apache.fop.datatypes.LengthRange; +import org.apache.fop.fo.LengthRangeProperty; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; import org.apache.fop.fo.FOTreeVisitor; @@ -88,7 +88,7 @@ public class Table extends FObj { private int spaceBefore; private int spaceAfter; private ColorType backgroundColor; - private LengthRange ipd; + private LengthRangeProperty ipd; private int height; private boolean bAutoLayout = false; diff --git a/src/java/org/apache/fop/fo/properties/BorderWidthPropertyMaker.java b/src/java/org/apache/fop/fo/properties/BorderWidthPropertyMaker.java index 36fae49ef..637a62845 100644 --- a/src/java/org/apache/fop/fo/properties/BorderWidthPropertyMaker.java +++ b/src/java/org/apache/fop/fo/properties/BorderWidthPropertyMaker.java @@ -55,7 +55,6 @@ import org.apache.fop.fo.Constants; import org.apache.fop.fo.LengthProperty; import org.apache.fop.fo.Property; import org.apache.fop.fo.PropertyList; -import org.apache.fop.fo.LengthProperty.Maker; /** * This subclass of LengthProperty.Maker handles the special treatment of diff --git a/src/java/org/apache/fop/fo/properties/CommonBorderAndPadding.java b/src/java/org/apache/fop/fo/properties/CommonBorderAndPadding.java index 6f6420fd9..aa72ad6de 100644 --- a/src/java/org/apache/fop/fo/properties/CommonBorderAndPadding.java +++ b/src/java/org/apache/fop/fo/properties/CommonBorderAndPadding.java @@ -50,9 +50,9 @@ */ package org.apache.fop.fo.properties; -import org.apache.fop.fo.Constants; import org.apache.fop.datatypes.ColorType; -import org.apache.fop.datatypes.CondLength; +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.CondLengthProperty; /** * Stores all common border and padding properties. @@ -78,7 +78,7 @@ public class CommonBorderAndPadding implements Cloneable { private int iLength; // Resolved length value private boolean bDiscard; - public ResolvedCondLength(CondLength length) { + public ResolvedCondLength(CondLengthProperty length) { bDiscard = length.isDiscard(); iLength = length.getLengthValue(); } @@ -114,7 +114,7 @@ public class CommonBorderAndPadding implements Cloneable { private ColorType mColor; // Border color private ResolvedCondLength mWidth; - BorderInfo(int style, CondLength width, ColorType color) { + BorderInfo(int style, CondLengthProperty width, ColorType color) { mStyle = style; mWidth = new ResolvedCondLength(width); mColor = color; @@ -131,12 +131,12 @@ public class CommonBorderAndPadding implements Cloneable { private BorderInfo[] borderInfo = new BorderInfo[4]; private ResolvedCondLength[] padding = new ResolvedCondLength[4]; - public void setBorder(int side, int style, CondLength width, + public void setBorder(int side, int style, CondLengthProperty width, ColorType color) { borderInfo[side] = new BorderInfo(style, width, color); } - public void setPadding(int side, CondLength width) { + public void setPadding(int side, CondLengthProperty width) { padding[side] = new ResolvedCondLength(width); } diff --git a/src/java/org/apache/fop/fo/properties/IndentPropertyMaker.java b/src/java/org/apache/fop/fo/properties/IndentPropertyMaker.java index e2927a687..7a19e784e 100644 --- a/src/java/org/apache/fop/fo/properties/IndentPropertyMaker.java +++ b/src/java/org/apache/fop/fo/properties/IndentPropertyMaker.java @@ -53,10 +53,9 @@ package org.apache.fop.fo.properties; import org.apache.fop.apps.FOPException; import org.apache.fop.datatypes.FixedLength; import org.apache.fop.fo.FOPropertyMapping; -import org.apache.fop.fo.LengthProperty; import org.apache.fop.fo.Property; import org.apache.fop.fo.PropertyList; -import org.apache.fop.fo.expr.Numeric; +import org.apache.fop.fo.expr.NumericProperty; /** * This property maker handles the calculations described in 5.3.2 which @@ -109,7 +108,7 @@ public class IndentPropertyMaker extends CorrespondingPropertyMaker { } // Calculate the values as described in 5.3.2. try { - Numeric v = new Numeric(new FixedLength(0)); + NumericProperty v = new NumericProperty(new FixedLength(0)); /* if (!propertyList.getFObj().generatesInlineAreas()) { String propName = FOPropertyMapping.getPropertyName(this.propId); @@ -119,7 +118,7 @@ public class IndentPropertyMaker extends CorrespondingPropertyMaker { v = v.add(propertyList.get(propertyList.wmMap(lr_tb, rl_tb, tb_rl)).getNumeric()); v = v.add(getCorresponding(paddingCorresponding, propertyList).getNumeric()); v = v.add(getCorresponding(borderWidthCorresponding, propertyList).getNumeric()); - return new LengthProperty(v.asLength()); + return v.asLength(); } catch (org.apache.fop.fo.expr.PropertyException propEx) { String propName = FOPropertyMapping.getPropertyName(baseMaker.getPropId()); throw new FOPException("Error in " + propName diff --git a/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java b/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java index c2dbb51f8..b5bf98a76 100644 --- a/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java +++ b/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java @@ -117,8 +117,7 @@ public class LineHeightPropertyMaker extends LengthProperty.Maker { FObj fo) { Number numval = p.getNumber(); if (numval != null) { - return new LengthProperty( - new PercentLength(numval.doubleValue(), getPercentBase(fo,propertyList))); + return new PercentLength(numval.doubleValue(), getPercentBase(fo,propertyList)); } return super.convertPropertyDatatype(p, propertyList, fo); } diff --git a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java index 8f00f4434..e7aef684e 100644 --- a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java @@ -178,7 +178,7 @@ public class TableAttributesConverter { ListProperty listprop = (ListProperty) p; ColorType color = null; if (listprop.getList().get(0) instanceof NCnameProperty) { - color = new ColorType(((NCnameProperty)listprop.getList().get(0)).getNCname()); + color = new ColorTypeProperty(((NCnameProperty)listprop.getList().get(0)).getNCname()); } else if (listprop.getList().get(0) instanceof ColorTypeProperty) { color = ((ColorTypeProperty)listprop.getList().get(0)).getColorType(); } diff --git a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java index 4d6dc9f73..d7f7f0d5c 100644 --- a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java @@ -327,9 +327,9 @@ class TextAttributesConverter { * @return integer pointing into the RTF color table */ public static int convertFOPColorToRTF(ColorType fopColor) { - int redComponent = ColorType.convertChannelToInteger (fopColor.getRed()); - int greenComponent = ColorType.convertChannelToInteger (fopColor.getGreen()); - int blueComponent = ColorType.convertChannelToInteger (fopColor.getBlue()); + int redComponent = ColorTypeProperty.convertChannelToInteger (fopColor.getRed()); + int greenComponent = ColorTypeProperty.convertChannelToInteger (fopColor.getGreen()); + int blueComponent = ColorTypeProperty.convertChannelToInteger (fopColor.getBlue()); return RtfColorTable.getInstance().getColorNumber(redComponent, greenComponent, blueComponent).intValue(); } diff --git a/src/java/org/apache/fop/traits/SpaceVal.java b/src/java/org/apache/fop/traits/SpaceVal.java index bdb038ee2..b15e8cb49 100644 --- a/src/java/org/apache/fop/traits/SpaceVal.java +++ b/src/java/org/apache/fop/traits/SpaceVal.java @@ -50,9 +50,8 @@ */ package org.apache.fop.traits; -import org.apache.fop.datatypes.Space; - import org.apache.fop.fo.Property; +import org.apache.fop.fo.SpaceProperty; import org.apache.fop.fo.Constants; /** @@ -70,7 +69,7 @@ public class SpaceVal { * Constructor for SpaceVal objects based on Space objects. * @param spaceprop Space object to use */ - public SpaceVal(Space spaceprop) { + public SpaceVal(SpaceProperty spaceprop) { space = new MinOptMax(spaceprop.getMinimum().getLength().getValue(), spaceprop.getOptimum().getLength().getValue(), spaceprop.getMaximum().getLength().getValue()); -- 2.39.5