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); } }
/** * 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; }
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); }