protected CSSValue parseFirstPosition(final LexicalUnit value) {
    if (value == null) {
      return null;
    }

    if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
      if ("left".equalsIgnoreCase(value.getStringValue())) {
        return LEFT;
      } else if ("center".equalsIgnoreCase(value.getStringValue())) {
        return CENTER;
      } else if ("right".equalsIgnoreCase(value.getStringValue())) {
        return RIGHT;
      } else if ("top".equalsIgnoreCase(value.getStringValue())) {
        return TOP;
      } else if ("bottom".equalsIgnoreCase(value.getStringValue())) {
        return BOTTOM;
      }

      // ignore this rule.
      return null;
    }

    if (value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE) {
      return CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, value.getFloatValue());
    }
    if (CSSValueFactory.isLengthValue(value)) {
      return CSSValueFactory.createLengthValue(value);
    }
    // contains errors, we ignore this rule.
    return null;
  }
  public CSSValue createValue(StyleKey name, LexicalUnit value) {
    if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
      String ident = value.getStringValue();
      if (ident.equalsIgnoreCase("auto")) {
        return CSSAutoValue.getInstance();
      }
      final PageSize ps = PageSizeFactory.getInstance().getPageSizeByName(ident);
      if (ps == null) {
        return null;
      }

      value = value.getNextLexicalUnit();
      int pageOrientation = PageFormat.PORTRAIT;
      if (value != null) {
        if (value.getLexicalUnitType() != LexicalUnit.SAC_IDENT) {
          return null;
        }

        if (value.getStringValue().equalsIgnoreCase("landscape")) {
          pageOrientation = PageFormat.LANDSCAPE;
        } else if (value.getStringValue().equalsIgnoreCase("reverse-landscape")) {
          pageOrientation = PageFormat.REVERSE_LANDSCAPE;
        } else if (value.getStringValue().equalsIgnoreCase("portrait")) {
          pageOrientation = PageFormat.PORTRAIT;
        } else {
          return null;
        }
      }

      if (pageOrientation == PageFormat.LANDSCAPE
          || pageOrientation == PageFormat.REVERSE_LANDSCAPE) {
        return new CSSValuePair(
            CSSNumericValue.createPtValue(ps.getHeight()),
            CSSNumericValue.createPtValue(ps.getWidth()));
      } else {
        return new CSSValuePair(
            CSSNumericValue.createPtValue(ps.getWidth()),
            CSSNumericValue.createPtValue(ps.getHeight()));
      }
    } else {
      final CSSNumericValue horizontalWidth = (CSSNumericValue) parseWidth(value);
      if (horizontalWidth == null) {
        return null;
      }

      value = value.getNextLexicalUnit();

      final CSSNumericValue verticalWidth;
      if (value == null) {
        verticalWidth = horizontalWidth;
      } else {
        verticalWidth = (CSSNumericValue) parseWidth(value);
        if (verticalWidth == null) {
          return null;
        }
      }

      return new CSSValuePair(horizontalWidth, verticalWidth);
    }
  }
  public CSSValue createValue(StyleKey name, LexicalUnit value) {
    if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
      final String text = value.getStringValue();
      if (ContentValues.NONE.getCSSText().equals(text)) {
        return ContentValues.NONE;
      }
      if (ContentValues.INHIBIT.getCSSText().equals(text)) {
        return ContentValues.INHIBIT;
      }
      if (ContentValues.NORMAL.getCSSText().equals(text)) {
        return ContentValues.NORMAL;
      }
    }

    final ArrayList contents = new ArrayList();
    final ArrayList contentList = new ArrayList();
    while (value != null) {
      if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
        CSSValue o = lookupValue(value);
        if (o == null) {
          // parse error ...
          return null;
        }
        contentList.add(o);
      } else if (value.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE) {
        contentList.add(new CSSStringValue(CSSStringType.STRING, value.getStringValue()));
      } else if (value.getLexicalUnitType() == LexicalUnit.SAC_URI) {
        final CSSStringValue uriValue = CSSValueFactory.createUriValue(value);
        if (uriValue == null) {
          return null;
        }
        contentList.add(uriValue);
      } else if (value.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION
          || value.getLexicalUnitType() == LexicalUnit.SAC_COUNTER_FUNCTION
          || value.getLexicalUnitType() == LexicalUnit.SAC_COUNTERS_FUNCTION) {
        final CSSFunctionValue functionValue = CSSValueFactory.parseFunction(value);
        if (functionValue == null) {
          return null;
        }
        contentList.add(functionValue);
      } else if (value.getLexicalUnitType() == LexicalUnit.SAC_ATTR) {
        final CSSAttrFunction attrFn = CSSValueFactory.parseAttrFunction(value);
        if (attrFn == null) {
          return null;
        }
        contentList.add(attrFn);
      } else if (value.getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_COMMA) {
        final CSSValue[] values =
            (CSSValue[]) contentList.toArray(new CSSValue[contentList.size()]);
        contents.add(new CSSValueList(values));
        contentList.clear();
      }
      value = value.getNextLexicalUnit();
    }

    final CSSValue[] values = (CSSValue[]) contentList.toArray(new CSSValue[contentList.size()]);
    contents.add(new CSSValueList(values));
    return new CSSValueList(contents);
  }
Exemplo n.º 4
0
  /** Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}. */
  public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException {
    switch (lu.getLexicalUnitType()) {
      case LexicalUnit.SAC_INHERIT:
        return ValueConstants.INHERIT_VALUE;

      case LexicalUnit.SAC_URI:
        return new URIValue(
            lu.getStringValue(), resolveURI(engine.getCSSBaseURI(), lu.getStringValue()));

      case LexicalUnit.SAC_IDENT:
        if (lu.getStringValue().equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) {
          return ValueConstants.NONE_VALUE;
        }
    }
    throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType());
  }
  private CSSValue parseSingleSpacingValue(final LexicalUnit value) {
    if (value == null) {
      return null;
    }

    if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
      if (value.getStringValue().equalsIgnoreCase("normal")) {
        return SpacingLimitReadHandler.NORMAL;
      }
      return null;
    }
    if (value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE) {
      return CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, value.getFloatValue());
    }

    return CSSValueFactory.createLengthValue(value);
  }
 public CSSValue createValue(StyleKey name, LexicalUnit value) {
   if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
     if (value.getStringValue().equalsIgnoreCase("none")) {
       return new CSSConstant("none");
     }
   }
   return CSSValueFactory.createNumericValue(value);
 }
 protected CSSValue parseWidth(final LexicalUnit value) {
   if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
     if (value.getStringValue().equalsIgnoreCase("dash")) {
       return TextDecorationWidth.DASH;
     }
     if (value.getStringValue().equalsIgnoreCase("bold")) {
       return TextDecorationWidth.BOLD;
     }
   }
   return super.parseWidth(value);
 }
Exemplo n.º 8
0
  /** Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}. */
  public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException {
    switch (lu.getLexicalUnitType()) {
      case LexicalUnit.SAC_INHERIT:
        return InheritValue.INSTANCE;

      case LexicalUnit.SAC_IDENT:
        if (lu.getStringValue().equalsIgnoreCase(CSSConstants.CSS_AUTO_VALUE)) {
          return ValueConstants.AUTO_VALUE;
        }
    }
    return super.createValue(lu, engine);
  }
Exemplo n.º 9
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);
     }
   }
 }
 public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException {
   switch (lu.getLexicalUnitType()) {
     case LexicalUnit.SAC_IDENT:
       String s = lu.getStringValue().toLowerCase().intern();
       Object v = values.get(s);
       if (v == null) {
         throw createInvalidIdentifierDOMException(lu.getStringValue());
       }
       return (Value) v;
   }
   return super.createValue(lu, engine);
 }
Exemplo n.º 11
0
  private float calculateInternal(
      final LexicalUnit lu, final Styles parentStyles, final Styles styles) {

    final DisplayDevice device = DisplayDevice.getCurrent();
    float baseFontSize = DEFAULT_FONT_SIZE_POINTS * device.getVerticalPPI() / 72;

    if (parentStyles != null) {
      baseFontSize = parentStyles.getFontSize();
    }

    if (lu == null) {
      return baseFontSize;
    } else if (isLength(lu)) {
      return getFloatLength(lu, baseFontSize, device.getVerticalPPI());
    } else if (isPercentage(lu)) {
      return baseFontSize * lu.getFloatValue() / 100;
    } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
      final String s = lu.getStringValue();

      if (s.equals(CSS.XX_SMALL)) {
        return baseFontSize * FONT_FACTOR_XX_SMALL;

      } else if (s.equals(CSS.X_SMALL)) {
        return baseFontSize * FONT_FACTOR_X_SMALL;

      } else if (s.equals(CSS.SMALL)) {
        return baseFontSize * FONT_FACTOR_SMALL;

      } else if (s.equals(CSS.MEDIUM)) {
        return baseFontSize * FONT_FACTOR_MEDIUM;

      } else if (s.equals(CSS.LARGE)) {
        return baseFontSize * FONT_FACTOR_LARGE;

      } else if (s.equals(CSS.X_LARGE)) {
        return baseFontSize * FONT_FACTOR_X_LARGE;

      } else if (s.equals(CSS.XX_LARGE)) {
        return baseFontSize * FONT_FACTOR_XX_LARGE;

      } else if (s.equals(CSS.SMALLER)) {
        return baseFontSize / FONT_SIZE_FACTOR;

      } else if (s.equals(CSS.LARGER)) {
        return baseFontSize * FONT_SIZE_FACTOR;

      } else {
        return baseFontSize;
      }
    } else {
      return baseFontSize;
    }
  }
  public CSSValue createValue(StyleKey name, LexicalUnit value) {
    if (value.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
      final String stringValue = value.getStringValue();
      if (stringValue.equalsIgnoreCase("auto")) {
        return CSSAutoValue.getInstance();
      }
    }

    final CSSValue firstPosition = parseFirstPosition(value);
    if (firstPosition == null) {
      return null;
    }

    value = value.getNextLexicalUnit();
    final CSSValue secondPosition = parseSecondPosition(value, firstPosition);
    if (secondPosition == null) {
      return null;
    }

    return createResultList(firstPosition, secondPosition);
  }
Exemplo n.º 13
0
 /**
  * Returns true if the given lexical unit represents a font size.
  *
  * @param lu LexicalUnit to check.
  */
 public static boolean isFontSize(final LexicalUnit lu) {
   if (lu == null) {
     return false;
   } else if (isLength(lu)) {
     return true;
   } else if (isPercentage(lu)) {
     return true;
   } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
     final String s = lu.getStringValue();
     return s.equals(CSS.XX_SMALL)
         || s.equals(CSS.X_SMALL)
         || s.equals(CSS.SMALL)
         || s.equals(CSS.MEDIUM)
         || s.equals(CSS.LARGE)
         || s.equals(CSS.X_LARGE)
         || s.equals(CSS.XX_LARGE)
         || s.equals(CSS.SMALLER)
         || s.equals(CSS.LARGER);
   } else {
     return false;
   }
 }
Exemplo n.º 14
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");
   }
 }