Ejemplo n.º 1
0
 private void writeHex(LexicalUnit lu) {
   write("#");
   for (LexicalUnit current = lu; current != null; current = current.getNextLexicalUnit()) {
     if (current.getLexicalUnitType() == LexicalUnit.SAC_INTEGER) {
       String value = Integer.toHexString(current.getIntegerValue());
       if (value.length() == 1) {
         value = String.format("0%s", value);
       }
       write(value);
     }
   }
 }
Ejemplo n.º 2
0
 void write(LexicalUnit lu) {
   short type = lu.getLexicalUnitType();
   switch (type) {
     case LexicalUnit.SAC_URI:
       write("url(");
       write(lu.getStringValue());
       write(")");
       break;
     case LexicalUnit.SAC_STRING_VALUE:
       write('"');
       write(lu.getStringValue());
       write('"');
       break;
     case LexicalUnit.SAC_IDENT:
       write(lu.getStringValue());
       break;
     case LexicalUnit.SAC_REAL:
       write(lu.getFloatValue());
       break;
     case LexicalUnit.SAC_PIXEL:
       write(lu.getFloatValue());
       write("px");
       break;
     case LexicalUnit.SAC_MILLIMETER:
       write(lu.getFloatValue());
       write("mm");
       break;
     case LexicalUnit.SAC_CENTIMETER:
       write(lu.getFloatValue());
       write("cm");
       break;
     case LexicalUnit.SAC_PERCENTAGE:
       write(lu.getFloatValue());
       write("%");
       break;
     case LexicalUnit.SAC_POINT:
       write(lu.getFloatValue());
       write("pt");
       break;
     case LexicalUnit.SAC_EM:
       write(lu.getFloatValue());
       write("em");
       break;
     case LexicalUnit.SAC_INTEGER:
       write(lu.getIntegerValue());
       break;
     case LexicalUnit.SAC_FUNCTION:
       write(lu.getFunctionName());
       write("(");
       write(lu.getParameters(), "");
       write(")");
       break;
     case LexicalUnit.SAC_RGBCOLOR:
       // Use hexadecimal notation instead
       writeHex(lu.getParameters());
       break;
     case LexicalUnit.SAC_OPERATOR_COMMA:
       write(",");
       break;
     case LexicalUnit.SAC_INHERIT:
       write("inherit");
       break;
     default:
       throw new UnsupportedOperationException("Lexical unit type " + type + " is not handled");
   }
 }