Coverage Report - net.sourceforge.jeuclid.elements.support.attributes.AttributesHelper
 
Classes in this File Line Coverage Branch Coverage Complexity
AttributesHelper
67%
138/203
48%
41/84
5,909
 
 1  
 /*
 2  
  * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 /* $Id: AttributesHelper.java,v 1e57f05a780b 2009/10/28 09:06:45 max $ */
 18  
 
 19  
 package net.sourceforge.jeuclid.elements.support.attributes;
 20  
 
 21  
 import java.awt.Color;
 22  
 import java.util.HashMap;
 23  
 import java.util.Locale;
 24  
 import java.util.Map;
 25  
 import java.util.StringTokenizer;
 26  
 
 27  
 import net.sourceforge.jeuclid.Constants;
 28  
 import net.sourceforge.jeuclid.LayoutContext;
 29  
 import net.sourceforge.jeuclid.elements.AbstractJEuclidElement;
 30  
 import net.sourceforge.jeuclid.elements.support.GraphicsSupport;
 31  
 import net.sourceforge.jeuclid.elements.support.operatordict.OperatorDictionary;
 32  
 
 33  
 import org.apache.commons.logging.Log;
 34  
 import org.apache.commons.logging.LogFactory;
 35  
 
 36  
 /**
 37  
  * Class contains utility methods for working with elements attributes.
 38  
  * 
 39  
  * @version $Revision: 1e57f05a780b $
 40  
  */
 41  
 public final class AttributesHelper {
 42  
 
 43  
     /**
 44  
      * Constant for "Transparent" color.
 45  
      */
 46  
     public static final String COLOR_TRANSPARENT = "transparent";
 47  
 
 48  
     /**
 49  
      * Width of veryverythinmath space according to 3.3.4.2.
 50  
      */
 51  
     public static final String VERYVERYTHINMATHSPACE = "0.0555556em";
 52  
 
 53  
     /**
 54  
      * Width of verythinmath space according to 3.3.4.2.
 55  
      */
 56  
     public static final String VERYTHINMATHSPACE = "0.111111em";
 57  
 
 58  
     /**
 59  
      * Width of thinmath space according to 3.3.4.2.
 60  
      */
 61  
     public static final String THINMATHSPACE = "0.166667em";
 62  
 
 63  
     /**
 64  
      * Width of mediummath space according to 3.3.4.2.
 65  
      */
 66  
     public static final String MEDIUMMATHSPACE = "0.222222em";
 67  
 
 68  
     /**
 69  
      * Width of tickmath space according to 3.3.4.2.
 70  
      */
 71  
     public static final String THICKMATHSPACE = "0.277778em";
 72  
 
 73  
     /**
 74  
      * Width of verytickmath space according to 3.3.4.2.
 75  
      */
 76  
     public static final String VERYTHICKMATHSPACE = "0.333333em";
 77  
 
 78  
     /**
 79  
      * Width of veryverytickmath space according to 3.3.4.2.
 80  
      */
 81  
     public static final String VERYVERYTHICKMATHSPACE = "0.388889em";
 82  
 
 83  
     /**
 84  
      * Unit for pt.
 85  
      */
 86  
     public static final String PT = "pt";
 87  
 
 88  
     /**
 89  
      * Infinity. Should be reasonably large.
 90  
      */
 91  
     public static final String INFINITY = "9999999pt";
 92  
 
 93  
     private static final String ERROR_PARSING_NUMBER = "Error Parsing number: ";
 94  
 
 95  
     private static final int HASHSHORT_ALPHA = 5;
 96  
 
 97  
     private static final int HASHSHORT_NO_ALPHA = 4;
 98  
 
 99  
     private static final int SHORT_INDEX_RED = 1;
 100  
 
 101  
     private static final int SHORT_INDEX_GREEN = 2;
 102  
 
 103  
     private static final int SHORT_INDEX_BLUE = 3;
 104  
 
 105  
     private static final int HASHLEN_ALPHA = 9;
 106  
 
 107  
     private static final int HASHLEN_NO_ALPHA = 7;
 108  
 
 109  
     private static final int HEXBASE = 16;
 110  
 
 111  
     private static final float MAX_HEXCHAR_AS_FLOAT = 15f;
 112  
 
 113  
     private static final int MAX_BYTE = 255;
 114  
 
 115  
     private static final float MAX_PERCENT_AS_FLOAT = 100.0f;
 116  
 
 117  
     private static final float MAX_BYTE_AS_FLOAT = 255f;
 118  
 
 119  
     private static final String PERCENT_SIGN = "%";
 120  
 
 121  
     private static final String COMMA = ",";
 122  
 
 123  
     /**
 124  
      * Value of EM (horizontal size).
 125  
      * <p>
 126  
      * Please note: This is a typical value, according to
 127  
      * http://kb.mozillazine.org/Em_vs._ex It is not dependent on the actual
 128  
      * font used, as it should be.
 129  
      */
 130  
     private static final float EM = 0.83888888888888888888f;
 131  
 
 132  
     /**
 133  
      * Value of EX (vertical size).
 134  
      * <p>
 135  
      * Please note: This is a typical value, according to
 136  
      * http://kb.mozillazine.org/Em_vs._ex It is not dependent on the actual
 137  
      * font used, as it should be.
 138  
      */
 139  
     private static final float EX = 0.5f;
 140  
 
 141  
     /**
 142  
      * Default DPI value for all Java apps.
 143  
      */
 144  
     private static final float DPI = 72.0f;
 145  
 
 146  
     private static final float PERCENT = 0.01f;
 147  
 
 148  
     private static final float CM_PER_INCH = 2.54f;
 149  
 
 150  
     private static final float MM_PER_INCH = AttributesHelper.CM_PER_INCH * 10.0f;
 151  
 
 152  
     private static final float PT_PER_PC = 12.0f;
 153  
 
 154  209
     private static final Map<String, String> SIZETRANSLATIONS = new HashMap<String, String>();
 155  
 
 156  209
     private static final Map<String, Float> RELATIVE_UNITS = new HashMap<String, Float>();
 157  
 
 158  209
     private static final Map<String, Float> ABSOLUTE_UNITS = new HashMap<String, Float>();
 159  
 
 160  209
     private static final Map<String, Color> COLOR_MAPPINGS = new HashMap<String, Color>();
 161  
 
 162  
     /**
 163  
      * Logger for this class.
 164  
      */
 165  209
     private static final Log LOGGER = LogFactory
 166  
             .getLog(AbstractJEuclidElement.class);
 167  
 
 168  
     /**
 169  
      * Private constructor: it's forbidden to create instance of this utility
 170  
      * class.
 171  
      */
 172  0
     private AttributesHelper() {
 173  0
     }
 174  
 
 175  
     /**
 176  
      * Parse a size that is relative to a given size.
 177  
      * 
 178  
      * @param sizeString
 179  
      *            sizeString to parse
 180  
      * @param context
 181  
      *            Context to use to calculate for absolute sizes.
 182  
      * @param relativeTo
 183  
      *            This size is relative to the given size (must be in pt).
 184  
      * @return a size in pt.
 185  
      */
 186  
     public static float parseRelativeSize(final String sizeString,
 187  
             final LayoutContext context, final float relativeTo) {
 188  15048
         if (sizeString == null) {
 189  0
             return relativeTo;
 190  
         }
 191  15048
         final String tSize = AttributesHelper.prepareSizeString(sizeString);
 192  
         float retVal;
 193  
         try {
 194  15048
             if (tSize.length() >= 2) {
 195  7524
                 final int valueLen = tSize.length() - 2;
 196  7524
                 final String unit = tSize.substring(valueLen);
 197  7524
                 final float value = Float.parseFloat(tSize.substring(0,
 198  
                         valueLen));
 199  7524
                 if (AttributesHelper.ABSOLUTE_UNITS.containsKey(unit)) {
 200  7524
                     retVal = AttributesHelper.convertSizeToPt(sizeString,
 201  
                             context, AttributesHelper.PT);
 202  0
                 } else if (AttributesHelper.RELATIVE_UNITS.containsKey(unit)) {
 203  0
                     retVal = value * relativeTo
 204  
                             * AttributesHelper.RELATIVE_UNITS.get(unit);
 205  
                 } else {
 206  0
                     retVal = Float.parseFloat(tSize) * relativeTo;
 207  
                 }
 208  7524
             } else {
 209  7524
                 retVal = Float.parseFloat(tSize) * relativeTo;
 210  
             }
 211  0
         } catch (final NumberFormatException nfe) {
 212  0
             retVal = relativeTo;
 213  0
             AttributesHelper.LOGGER.warn(AttributesHelper.ERROR_PARSING_NUMBER
 214  
                     + sizeString);
 215  15048
         }
 216  15048
         return retVal;
 217  
     }
 218  
 
 219  
     /**
 220  
      * Translates size into pt.
 221  
      * 
 222  
      * @param sizeString
 223  
      *            string to convert
 224  
      * @param context
 225  
      *            LayoutContext this size is relative to. This is usually the
 226  
      *            context of the parent or the element itself.
 227  
      * @param defaultUnit
 228  
      *            default Unit to use in this context. May be px, pt, em, etc.
 229  
      * @return Translated value of the size attribute into Point (=Java Pixels).
 230  
      */
 231  
     public static float convertSizeToPt(final String sizeString,
 232  
             final LayoutContext context, final String defaultUnit) {
 233  94259
         final String tSize = AttributesHelper.prepareSizeString(sizeString);
 234  94259
         if (tSize.length() == 0) {
 235  0
             return 0;
 236  
         }
 237  
         float retVal;
 238  
         try {
 239  
             final String unit;
 240  
             final float value;
 241  94259
             if (tSize.length() <= 2) {
 242  3344
                 unit = defaultUnit;
 243  3344
                 value = Float.parseFloat(tSize);
 244  
             } else {
 245  90915
                 final int valueLen = tSize.length() - 2;
 246  90915
                 unit = tSize.substring(valueLen);
 247  90915
                 value = Float.parseFloat(tSize.substring(0, valueLen));
 248  
             }
 249  94259
             if (value == 0) {
 250  46189
                 retVal = 0.0f;
 251  48070
             } else if (AttributesHelper.RELATIVE_UNITS.containsKey(unit)) {
 252  40546
                 retVal = value * GraphicsSupport.getFontsizeInPoint(context)
 253  
                         * AttributesHelper.RELATIVE_UNITS.get(unit);
 254  7524
             } else if (AttributesHelper.ABSOLUTE_UNITS.containsKey(unit)) {
 255  7524
                 retVal = value * AttributesHelper.ABSOLUTE_UNITS.get(unit);
 256  0
             } else if (defaultUnit.length() > 0) {
 257  0
                 retVal = AttributesHelper.convertSizeToPt(sizeString
 258  
                         + defaultUnit, context, "");
 259  
             } else {
 260  0
                 retVal = Float.parseFloat(tSize);
 261  0
                 AttributesHelper.LOGGER.warn("Error Parsing attribute: "
 262  
                         + sizeString + " assuming " + retVal
 263  
                         + AttributesHelper.PT);
 264  
             }
 265  0
         } catch (final NumberFormatException nfe) {
 266  0
             retVal = 1.0f;
 267  0
             AttributesHelper.LOGGER.warn(AttributesHelper.ERROR_PARSING_NUMBER
 268  
                     + sizeString + " falling back to " + retVal
 269  
                     + AttributesHelper.PT);
 270  94259
         }
 271  94259
         return retVal;
 272  
     }
 273  
 
 274  
     private static String prepareSizeString(final String sizeString) {
 275  109307
         if (sizeString == null) {
 276  0
             return "";
 277  
         }
 278  109307
         String tSize = sizeString.trim().toLowerCase(Locale.ENGLISH);
 279  
 
 280  109307
         final String translatesTo = AttributesHelper.SIZETRANSLATIONS
 281  
                 .get(tSize);
 282  109307
         if (translatesTo != null) {
 283  18183
             tSize = translatesTo;
 284  
         }
 285  109307
         if (tSize.endsWith(AttributesHelper.PERCENT_SIGN)) {
 286  
             // A nice trick because all other units are exactly 2 chars long.
 287  0
             tSize = new StringBuilder(tSize).append(' ').toString();
 288  
         }
 289  109307
         return tSize;
 290  
     }
 291  
 
 292  
     /**
 293  
      * Creates a color from a given string.
 294  
      * <p>
 295  
      * This function supports a wide variety of inputs.
 296  
      * <ul>
 297  
      * <li>#RGB (hex 0..f)</li>
 298  
      * <li>#RGBA (hex 0..f)</li>
 299  
      * <li>#RRGGBB (hex 00..ff)</li>
 300  
      * <li>#RRGGBBAA (hex 00..ff)</li>
 301  
      * <li>rgb(r,g,b) (0..255 or 0%..100%)</li>
 302  
      * <li>java.awt.Color[r=r,g=g,b=b] (0..255)</li>
 303  
      * <li>system-color(colorname)</li>
 304  
      * <li>transparent</li>
 305  
      * <li>colorname</li>
 306  
      * </ul>
 307  
      * 
 308  
      * @param value
 309  
      *            the string to parse.
 310  
      * @return a Color representing the string if possible
 311  
      * @param defaultValue
 312  
      *            a default color to use in case of failure.
 313  
      */
 314  
     public static Color stringToColor(final String value,
 315  
             final Color defaultValue) {
 316  17974
         if (value == null) {
 317  17347
             return null;
 318  
         }
 319  
 
 320  627
         final String lowVal = value.toLowerCase(Locale.ENGLISH);
 321  627
         Color parsedColor = null;
 322  
 
 323  627
         if (AttributesHelper.COLOR_MAPPINGS.containsKey(lowVal)) {
 324  209
             parsedColor = AttributesHelper.COLOR_MAPPINGS.get(lowVal);
 325  
         } else {
 326  418
             if (value.charAt(0) == '#') {
 327  0
                 parsedColor = AttributesHelper.parseWithHash(value);
 328  418
             } else if (value.startsWith("rgb(")) {
 329  209
                 parsedColor = AttributesHelper.parseAsRGB(value);
 330  209
             } else if (value.startsWith("java.awt.Color")) {
 331  0
                 parsedColor = AttributesHelper.parseAsJavaAWTColor(value);
 332  
             }
 333  
 
 334  418
             if (parsedColor == null) {
 335  209
                 parsedColor = defaultValue;
 336  
             }
 337  
 
 338  418
             if (parsedColor != null) {
 339  209
                 AttributesHelper.COLOR_MAPPINGS.put(value, parsedColor);
 340  
             }
 341  
         }
 342  627
         return parsedColor;
 343  
     }
 344  
 
 345  
     /**
 346  
      * Tries to parse the standard java.awt.Color toString output.
 347  
      * 
 348  
      * @param value
 349  
      *            the complete line
 350  
      * @return a color if possible
 351  
      * @see java.awt.Color#toString()
 352  
      */
 353  
     private static Color parseAsJavaAWTColor(final String value) {
 354  
         final Color parsedColor;
 355  0
         final int poss = value.indexOf('[');
 356  0
         final int pose = value.indexOf(']');
 357  0
         if ((poss == -1) || (pose == -1)) {
 358  0
             parsedColor = null;
 359  
         } else {
 360  0
             parsedColor = AttributesHelper.parseCommaSeparatedString(value
 361  
                     .substring(poss + 1, pose));
 362  
         }
 363  0
         return parsedColor;
 364  
     }
 365  
 
 366  
     /**
 367  
      * Parse a color given with the rgb() function.
 368  
      * 
 369  
      * @param value
 370  
      *            the complete line
 371  
      * @return a color if possible
 372  
      */
 373  
     private static Color parseAsRGB(final String value) {
 374  
         final Color parsedColor;
 375  209
         final int poss = value.indexOf('(');
 376  209
         final int pose = value.indexOf(')');
 377  209
         if ((poss == -1) || (pose == -1)) {
 378  0
             parsedColor = null;
 379  
         } else {
 380  209
             parsedColor = AttributesHelper.parseCommaSeparatedString(value
 381  
                     .substring(poss + 1, pose));
 382  
         }
 383  209
         return parsedColor;
 384  
     }
 385  
 
 386  
     private static Color parseCommaSeparatedString(final String value) {
 387  
         Color parsedColor;
 388  209
         final StringTokenizer st = new StringTokenizer(value,
 389  
                 AttributesHelper.COMMA);
 390  
         try {
 391  209
             float red = 0.0f;
 392  209
             float green = 0.0f;
 393  209
             float blue = 0.0f;
 394  209
             if (st.hasMoreTokens()) {
 395  209
                 final String str = st.nextToken().trim();
 396  209
                 red = AttributesHelper.parseFloatOrPercent(str);
 397  
             }
 398  209
             if (st.hasMoreTokens()) {
 399  209
                 final String str = st.nextToken().trim();
 400  209
                 green = AttributesHelper.parseFloatOrPercent(str);
 401  
             }
 402  209
             if (st.hasMoreTokens()) {
 403  209
                 final String str = st.nextToken().trim();
 404  209
                 blue = AttributesHelper.parseFloatOrPercent(str);
 405  
             }
 406  209
             parsedColor = new Color(red, green, blue);
 407  0
         } catch (final NumberFormatException e) {
 408  0
             AttributesHelper.LOGGER.warn(e);
 409  0
             parsedColor = null;
 410  209
         }
 411  209
         return parsedColor;
 412  
     }
 413  
 
 414  
     private static float parseFloatOrPercent(final String str) {
 415  
         final float value;
 416  627
         if (str.endsWith(AttributesHelper.PERCENT_SIGN)) {
 417  0
             value = Float.parseFloat(str.substring(0, str.length() - 1))
 418  
                     / AttributesHelper.MAX_PERCENT_AS_FLOAT;
 419  
         } else {
 420  627
             value = Float.parseFloat(str) / AttributesHelper.MAX_BYTE_AS_FLOAT;
 421  
         }
 422  627
         if ((value < 0.0f) || (value > 1.0f)) {
 423  0
             throw new NumberFormatException(str + " is out of Range");
 424  
         }
 425  627
         return value;
 426  
     }
 427  
 
 428  
     /**
 429  
      * parse a color given in the #.... format.
 430  
      * 
 431  
      * @param value
 432  
      *            the complete line
 433  
      * @return a color if possible
 434  
      */
 435  
     private static Color parseWithHash(final String value) {
 436  0
         Color parsedColor = null;
 437  
         try {
 438  0
             final int len = value.length();
 439  0
             if ((len >= AttributesHelper.HASHSHORT_NO_ALPHA)
 440  
                     && (len <= AttributesHelper.HASHSHORT_ALPHA)) {
 441  
                 // note: divide by 15 so F = FF = 1 and so on
 442  0
                 final float red = Integer.parseInt(value.substring(
 443  
                         AttributesHelper.SHORT_INDEX_RED,
 444  
                         AttributesHelper.SHORT_INDEX_RED + 1),
 445  
                         AttributesHelper.HEXBASE)
 446  
                         / AttributesHelper.MAX_HEXCHAR_AS_FLOAT;
 447  0
                 final float green = Integer.parseInt(value.substring(
 448  
                         AttributesHelper.SHORT_INDEX_GREEN,
 449  
                         AttributesHelper.SHORT_INDEX_GREEN + 1),
 450  
                         AttributesHelper.HEXBASE)
 451  
                         / AttributesHelper.MAX_HEXCHAR_AS_FLOAT;
 452  0
                 final float blue = Integer.parseInt(value.substring(
 453  
                         AttributesHelper.SHORT_INDEX_BLUE,
 454  
                         AttributesHelper.SHORT_INDEX_BLUE + 1),
 455  
                         AttributesHelper.HEXBASE)
 456  
                         / AttributesHelper.MAX_HEXCHAR_AS_FLOAT;
 457  0
                 float alpha = 1.0f;
 458  0
                 if (len == AttributesHelper.HASHSHORT_ALPHA) {
 459  0
                     alpha = Integer.parseInt(value
 460  
                             .substring(AttributesHelper.HASHSHORT_NO_ALPHA),
 461  
                             AttributesHelper.HEXBASE)
 462  
                             / AttributesHelper.MAX_HEXCHAR_AS_FLOAT;
 463  
                 }
 464  0
                 parsedColor = new Color(red, green, blue, alpha);
 465  0
             } else if ((len == AttributesHelper.HASHLEN_NO_ALPHA)
 466  
                     || (len == AttributesHelper.HASHLEN_ALPHA)) {
 467  0
                 final int red = Integer.parseInt(value.substring(1, 3),
 468  
                         AttributesHelper.HEXBASE);
 469  0
                 final int green = Integer.parseInt(value.substring(3, 5),
 470  
                         AttributesHelper.HEXBASE);
 471  0
                 final int blue = Integer.parseInt(value.substring(5,
 472  
                         AttributesHelper.HASHLEN_NO_ALPHA),
 473  
                         AttributesHelper.HEXBASE);
 474  0
                 int alpha = AttributesHelper.MAX_BYTE;
 475  0
                 if (len == AttributesHelper.HASHLEN_ALPHA) {
 476  0
                     alpha = Integer.parseInt(value
 477  
                             .substring(AttributesHelper.HASHLEN_NO_ALPHA),
 478  
                             AttributesHelper.HEXBASE);
 479  
                 }
 480  0
                 parsedColor = new Color(red, green, blue, alpha);
 481  0
             } else {
 482  0
                 throw new NumberFormatException();
 483  
             }
 484  0
         } catch (final NumberFormatException e) {
 485  0
             return null;
 486  0
         }
 487  0
         return parsedColor;
 488  
     }
 489  
 
 490  
     /**
 491  
      * Creates a re-parsable string representation of the given color.
 492  
      * <p>
 493  
      * First, the color will be converted into the sRGB colorspace. It will then
 494  
      * be printed as #rrggbb, or as #rrrggbbaa if an alpha value is present.
 495  
      * 
 496  
      * @param color
 497  
      *            the color to represent.
 498  
      * @return a re-parsable string representadion.
 499  
      */
 500  
     public static String colorTOsRGBString(final Color color) {
 501  209
         if (color == null) {
 502  0
             return AttributesHelper.COLOR_TRANSPARENT;
 503  
         }
 504  209
         final StringBuffer sbuf = new StringBuffer(10);
 505  209
         sbuf.append('#');
 506  209
         String s = Integer.toHexString(color.getRed());
 507  209
         if (s.length() == 1) {
 508  0
             sbuf.append('0');
 509  
         }
 510  209
         sbuf.append(s);
 511  209
         s = Integer.toHexString(color.getGreen());
 512  209
         if (s.length() == 1) {
 513  0
             sbuf.append('0');
 514  
         }
 515  209
         sbuf.append(s);
 516  209
         s = Integer.toHexString(color.getBlue());
 517  209
         if (s.length() == 1) {
 518  0
             sbuf.append('0');
 519  
         }
 520  209
         sbuf.append(s);
 521  209
         if (color.getAlpha() != AttributesHelper.MAX_BYTE) {
 522  0
             s = Integer.toHexString(color.getAlpha());
 523  0
             if (s.length() == 1) {
 524  0
                 sbuf.append('0');
 525  
             }
 526  0
             sbuf.append(s);
 527  
         }
 528  209
         return sbuf.toString();
 529  
 
 530  
     }
 531  
 
 532  
     // CHECKSTYLE:OFF
 533  
     static {
 534  
 
 535  
         // Mostly taken from 2.4.4.2
 536  209
         AttributesHelper.SIZETRANSLATIONS.put(
 537  
                 OperatorDictionary.NAME_VERYVERYTHINMATHSPACE,
 538  
                 AttributesHelper.VERYVERYTHINMATHSPACE);
 539  209
         AttributesHelper.SIZETRANSLATIONS.put(
 540  
                 OperatorDictionary.NAME_VERYTHINMATHSPACE,
 541  
                 AttributesHelper.VERYTHINMATHSPACE);
 542  209
         AttributesHelper.SIZETRANSLATIONS.put(
 543  
                 OperatorDictionary.NAME_THINMATHSPACE,
 544  
                 AttributesHelper.THINMATHSPACE);
 545  209
         AttributesHelper.SIZETRANSLATIONS.put(
 546  
                 OperatorDictionary.NAME_MEDIUMMATHSPACE,
 547  
                 AttributesHelper.MEDIUMMATHSPACE);
 548  209
         AttributesHelper.SIZETRANSLATIONS.put(
 549  
                 OperatorDictionary.NAME_THICKMATHSPACE,
 550  
                 AttributesHelper.THICKMATHSPACE);
 551  209
         AttributesHelper.SIZETRANSLATIONS.put(
 552  
                 OperatorDictionary.NAME_VERYTHICKMATHSPACE,
 553  
                 AttributesHelper.VERYTHICKMATHSPACE);
 554  209
         AttributesHelper.SIZETRANSLATIONS.put(
 555  
                 OperatorDictionary.NAME_VERYVERYTHICKMATHSPACE,
 556  
                 AttributesHelper.VERYVERYTHICKMATHSPACE);
 557  209
         AttributesHelper.SIZETRANSLATIONS.put(OperatorDictionary.NAME_INFINITY,
 558  
                 AttributesHelper.INFINITY);
 559  209
         AttributesHelper.SIZETRANSLATIONS.put("small", "68%");
 560  209
         AttributesHelper.SIZETRANSLATIONS.put("normal", "100%");
 561  209
         AttributesHelper.SIZETRANSLATIONS.put("big", "147%");
 562  
 
 563  
         // For mfrac, as of 3.3.2.2
 564  209
         AttributesHelper.SIZETRANSLATIONS.put("thin", "0.5");
 565  209
         AttributesHelper.SIZETRANSLATIONS.put("medium", "1");
 566  209
         AttributesHelper.SIZETRANSLATIONS.put("thick", "2");
 567  
 
 568  209
         AttributesHelper.SIZETRANSLATIONS.put("null", Constants.ZERO);
 569  
 
 570  209
         AttributesHelper.RELATIVE_UNITS.put("em", AttributesHelper.EM);
 571  209
         AttributesHelper.RELATIVE_UNITS.put("ex", AttributesHelper.EX);
 572  209
         AttributesHelper.RELATIVE_UNITS.put("% ", AttributesHelper.PERCENT);
 573  
 
 574  209
         AttributesHelper.ABSOLUTE_UNITS.put("px", 1.0f);
 575  209
         AttributesHelper.ABSOLUTE_UNITS.put("in", AttributesHelper.DPI);
 576  209
         AttributesHelper.ABSOLUTE_UNITS.put("cm", AttributesHelper.DPI
 577  
                 / AttributesHelper.CM_PER_INCH);
 578  209
         AttributesHelper.ABSOLUTE_UNITS.put("mm", AttributesHelper.DPI
 579  
                 / AttributesHelper.MM_PER_INCH);
 580  209
         AttributesHelper.ABSOLUTE_UNITS.put(AttributesHelper.PT, 1.0f);
 581  209
         AttributesHelper.ABSOLUTE_UNITS.put("pc", AttributesHelper.PT_PER_PC);
 582  
 
 583  
         // Defined in 3.2.2.2
 584  209
         AttributesHelper.COLOR_MAPPINGS.put("aqua", new Color(0, 255, 255));
 585  209
         AttributesHelper.COLOR_MAPPINGS.put("black", Color.BLACK);
 586  209
         AttributesHelper.COLOR_MAPPINGS.put("blue", Color.BLUE);
 587  209
         AttributesHelper.COLOR_MAPPINGS.put("fuchsia", new Color(255, 0, 255));
 588  209
         AttributesHelper.COLOR_MAPPINGS.put("gray", Color.GRAY);
 589  209
         AttributesHelper.COLOR_MAPPINGS.put("green", Color.GREEN);
 590  209
         AttributesHelper.COLOR_MAPPINGS.put("lime", new Color(0, 255, 0));
 591  209
         AttributesHelper.COLOR_MAPPINGS.put("maroon", new Color(128, 0, 0));
 592  209
         AttributesHelper.COLOR_MAPPINGS.put("navy", new Color(0, 0, 128));
 593  209
         AttributesHelper.COLOR_MAPPINGS.put("olive", new Color(128, 128, 0));
 594  209
         AttributesHelper.COLOR_MAPPINGS.put("purple", new Color(128, 0, 128));
 595  209
         AttributesHelper.COLOR_MAPPINGS.put("red", Color.RED);
 596  209
         AttributesHelper.COLOR_MAPPINGS.put("silver", new Color(192, 192, 192));
 597  209
         AttributesHelper.COLOR_MAPPINGS.put("teal", new Color(0, 128, 128));
 598  209
         AttributesHelper.COLOR_MAPPINGS.put("white", Color.WHITE);
 599  209
         AttributesHelper.COLOR_MAPPINGS.put("yellow", Color.YELLOW);
 600  
 
 601  
         // Additional colors
 602  209
         AttributesHelper.COLOR_MAPPINGS.put(AttributesHelper.COLOR_TRANSPARENT,
 603  
                 null);
 604  209
         AttributesHelper.COLOR_MAPPINGS.put("null", null);
 605  209
         AttributesHelper.COLOR_MAPPINGS.put("", null);
 606  209
     }
 607  
     // CHECKSTYLE:ON
 608  
 }