1 18 package org.apache.batik.css.engine; 19 20 import org.apache.batik.css.engine.value.Value; 21 22 28 public class StyleMap { 29 30 public final static short IMPORTANT_MASK = 0x0001; 35 public final static short COMPUTED_MASK = 0x0002; 36 public final static short NULL_CASCADED_MASK = 0x0004; 37 public final static short INHERITED_MASK = 0x0008; 38 39 public final static short LINE_HEIGHT_RELATIVE_MASK = 0x0010; 40 public final static short FONT_SIZE_RELATIVE_MASK = 0x0020; 41 public final static short COLOR_RELATIVE_MASK = 0x0040; 42 public final static short PARENT_RELATIVE_MASK = 0x0080; 43 public final static short BLOCK_WIDTH_RELATIVE_MASK = 0x0100; 44 public final static short BLOCK_HEIGHT_RELATIVE_MASK = 0x0200; 45 public final static short BOX_RELATIVE_MASK = 0x0400; 46 47 public final static short ORIGIN_MASK = (short)0xE000; 49 public final static short USER_AGENT_ORIGIN = 0; 53 public final static short USER_ORIGIN = 0x2000; public final static short NON_CSS_ORIGIN = 0x4000; public final static short AUTHOR_ORIGIN = 0x6000; public final static short INLINE_AUTHOR_ORIGIN = (short)0x8000; 58 61 protected Value[] values; 62 63 66 protected short[] masks; 67 68 71 protected boolean fixedCascadedValues; 72 73 76 public StyleMap(int size) { 77 values = new Value[size]; 78 masks = new short[size]; 79 } 80 81 84 public boolean hasFixedCascadedValues() { 85 return fixedCascadedValues; 86 } 87 88 91 public void setFixedCascadedStyle(boolean b) { 92 fixedCascadedValues = b; 93 } 94 95 98 public Value getValue(int i) { 99 return values[i]; 100 } 101 102 105 public short getMask(int i) { 106 return masks[i]; 107 } 108 109 112 public boolean isImportant(int i) { 113 return (masks[i] & IMPORTANT_MASK) != 0; 114 } 115 116 119 public boolean isComputed(int i) { 120 return (masks[i] & COMPUTED_MASK) != 0; 121 } 122 123 126 public boolean isNullCascaded(int i) { 127 return (masks[i] & NULL_CASCADED_MASK) != 0; 128 } 129 130 134 public boolean isInherited(int i) { 135 return (masks[i] & INHERITED_MASK) != 0; 136 } 137 138 141 public short getOrigin(int i) { 142 return (short)(masks[i] & ORIGIN_MASK); 143 } 144 145 148 public boolean isColorRelative(int i) { 149 return (masks[i] & COLOR_RELATIVE_MASK) != 0; 150 } 151 152 156 public boolean isParentRelative(int i) { 157 return (masks[i] & PARENT_RELATIVE_MASK) != 0; 158 } 159 160 163 public boolean isLineHeightRelative(int i) { 164 return (masks[i] & LINE_HEIGHT_RELATIVE_MASK) != 0; 165 } 166 167 170 public boolean isFontSizeRelative(int i) { 171 return (masks[i] & FONT_SIZE_RELATIVE_MASK) != 0; 172 } 173 174 178 public boolean isBlockWidthRelative(int i) { 179 return (masks[i] & BLOCK_WIDTH_RELATIVE_MASK) != 0; 180 } 181 182 186 public boolean isBlockHeightRelative(int i) { 187 return (masks[i] & BLOCK_HEIGHT_RELATIVE_MASK) != 0; 188 } 189 190 195 public void putValue(int i, Value v) { 196 values[i] = v; 197 } 198 199 204 public void putMask(int i, short m) { 205 masks[i] = m; 206 } 207 208 211 public void putImportant(int i, boolean b) { 212 if (b) masks[i] |= IMPORTANT_MASK; 213 else masks[i] &= ~IMPORTANT_MASK; 214 } 215 216 219 public void putOrigin(int i, short val) { 220 masks[i] &= ~ORIGIN_MASK; 221 masks[i] |= (short)(val & ORIGIN_MASK); 222 } 223 224 227 public void putComputed(int i, boolean b) { 228 if (b) masks[i] |= COMPUTED_MASK; 229 else masks[i] &= ~COMPUTED_MASK; 230 } 231 232 235 public void putNullCascaded(int i, boolean b) { 236 if (b) masks[i] |= NULL_CASCADED_MASK; 237 else masks[i] &= ~NULL_CASCADED_MASK; 238 } 239 240 244 public void putInherited(int i, boolean b) { 245 if (b) masks[i] |= INHERITED_MASK; 246 else masks[i] &= ~INHERITED_MASK; 247 } 248 249 252 public void putColorRelative(int i, boolean b) { 253 if (b) masks[i] |= COLOR_RELATIVE_MASK; 254 else masks[i] &= ~COLOR_RELATIVE_MASK; 255 } 256 257 260 public void putParentRelative(int i, boolean b) { 261 if (b) masks[i] |= PARENT_RELATIVE_MASK; 262 else masks[i] &= ~PARENT_RELATIVE_MASK; 263 } 264 265 268 public void putLineHeightRelative(int i, boolean b) { 269 if (b) masks[i] |= LINE_HEIGHT_RELATIVE_MASK; 270 else masks[i] &= ~LINE_HEIGHT_RELATIVE_MASK; 271 } 272 273 276 public void putFontSizeRelative(int i, boolean b) { 277 if (b) masks[i] |= FONT_SIZE_RELATIVE_MASK; 278 else masks[i] &= ~FONT_SIZE_RELATIVE_MASK; 279 } 280 281 284 public void putBlockWidthRelative(int i, boolean b) { 285 if (b) masks[i] |= BLOCK_WIDTH_RELATIVE_MASK; 286 else masks[i] &= ~BLOCK_WIDTH_RELATIVE_MASK; 287 } 288 289 292 public void putBlockHeightRelative(int i, boolean b) { 293 if (b) masks[i] |= BLOCK_HEIGHT_RELATIVE_MASK; 294 else masks[i] &= ~BLOCK_HEIGHT_RELATIVE_MASK; 295 } 296 297 300 public String toString(CSSEngine eng) { 301 StringBuffer sb = new StringBuffer (); 302 for (int i = 0; i < values.length; i++) { 303 Value v = values[i]; 304 if (v == null) continue; 305 306 sb.append(eng.getPropertyName(i)); 307 sb.append(": "); 308 sb.append(v); 309 if (isImportant(i)) sb.append(" !important"); 310 sb.append(";\n"); 311 } 312 return sb.toString(); 313 } 314 } 315 | Popular Tags |