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); }
void write(LexicalUnit lu, String separator) { String prefix = ""; for (LexicalUnit current = lu; current != null; current = current.getNextLexicalUnit()) { write(prefix); write(current); prefix = separator; } }
public CSSValueListImpl(LexicalUnit parsePropertyValue) { values = new ArrayList<CSSValue>(); LexicalUnit unit = parsePropertyValue; while (unit != null) { values.add(CSSValueFactory.newPrimitiveValue(unit)); unit = unit.getNextLexicalUnit(); } }
protected RGBColorImpl(LexicalUnit lu) { LexicalUnit next = lu; _red = new CSSValueImpl(next, true); next = next.getNextLexicalUnit(); next = next.getNextLexicalUnit(); _green = new CSSValueImpl(next, true); next = next.getNextLexicalUnit(); next = next.getNextLexicalUnit(); _blue = new CSSValueImpl(next, true); }
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); }
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 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); }
/** 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); }
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); } } }
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); } }
/** 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); }
/** * Parses the LexicalUnit and returns a map of (StyleKey, CSSValue) pairs. * * @param unit * @return */ public Map createValues(LexicalUnit unit) { CSSValue optimum = parseSingleSpacingValue(unit); if (optimum == null) { return null; } unit = unit.getNextLexicalUnit(); CSSValue minimum = parseSingleSpacingValue(unit); if (minimum != null) { unit = unit.getNextLexicalUnit(); } CSSValue maximum = parseSingleSpacingValue(unit); final Map map = new HashMap(); map.put(getMinimumKey(), minimum); map.put(TextStyleKeys.X_MAX_LETTER_SPACING, maximum); map.put(TextStyleKeys.X_OPTIMUM_LETTER_SPACING, optimum); return map; }
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); }
/** * 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; } }
/** * Parses the LexicalUnit and returns a map of (StyleKey, CSSValue) pairs. * * @param unit * @return */ public Map createValues(LexicalUnit unit) { final Map map = new HashMap(); map.put(TextStyleKeys.TEXT_UNDERLINE_POSITION, CSSAutoValue.getInstance()); map.put(TextStyleKeys.TEXT_UNDERLINE_MODE, TextDecorationMode.CONTINUOUS); map.put(TextStyleKeys.TEXT_OVERLINE_MODE, TextDecorationMode.CONTINUOUS); map.put(TextStyleKeys.TEXT_LINE_THROUGH_MODE, TextDecorationMode.CONTINUOUS); map.put(TextStyleKeys.TEXT_UNDERLINE_COLOR, CSSSystemColors.CURRENT_COLOR); map.put(TextStyleKeys.TEXT_OVERLINE_COLOR, CSSSystemColors.CURRENT_COLOR); map.put(TextStyleKeys.TEXT_LINE_THROUGH_COLOR, CSSSystemColors.CURRENT_COLOR); map.put(TextStyleKeys.TEXT_UNDERLINE_WIDTH, CSSAutoValue.getInstance()); map.put(TextStyleKeys.TEXT_OVERLINE_WIDTH, CSSAutoValue.getInstance()); map.put(TextStyleKeys.TEXT_LINE_THROUGH_WIDTH, CSSAutoValue.getInstance()); map.put(TextStyleKeys.TEXT_UNDERLINE_STYLE, TextDecorationStyle.NONE); map.put(TextStyleKeys.TEXT_OVERLINE_STYLE, TextDecorationStyle.NONE); map.put(TextStyleKeys.TEXT_LINE_THROUGH_STYLE, TextDecorationStyle.NONE); while (unit != null) { CSSValue constant = lookupValue(unit); if (constant == null) { return null; } if (constant.getCSSText().equals("none")) { map.put(TextStyleKeys.TEXT_UNDERLINE_STYLE, TextDecorationStyle.NONE); map.put(TextStyleKeys.TEXT_OVERLINE_STYLE, TextDecorationStyle.NONE); map.put(TextStyleKeys.TEXT_LINE_THROUGH_STYLE, TextDecorationStyle.NONE); return map; } if (constant.getCSSText().equals("blink")) { map.put(TextStyleKeys.TEXT_BLINK, new CSSConstant("blink")); } else if (constant.getCSSText().equals("underline")) { map.put(TextStyleKeys.TEXT_UNDERLINE_STYLE, TextDecorationStyle.SOLID); } else if (constant.getCSSText().equals("overline")) { map.put(TextStyleKeys.TEXT_OVERLINE_STYLE, TextDecorationStyle.SOLID); } else if (constant.getCSSText().equals("line-through")) { map.put(TextStyleKeys.TEXT_LINE_THROUGH_STYLE, TextDecorationStyle.SOLID); } unit = unit.getNextLexicalUnit(); } return map; }
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"); } }
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); }