/** * Implements {@link * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}. */ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) { switch (value.getCssValueType()) { case CSSValue.CSS_PRIMITIVE_VALUE: return value; } ListValue lv = (ListValue)value; ListValue result = new ListValue(' '); for (int i = 0; i < lv.getLength(); i++) { result.append(super.computeValue(elt, pseudo, engine, idx, sm, lv.item(i))); } return result; }
/** * Implements {@link * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}. */ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) { if ((value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) && (value.getPrimitiveType() == CSSPrimitiveValue.CSS_URI)) { // Reveal the absolute value as the cssText now. return new URIValue(value.getStringValue(), value.getStringValue()); } return value; }
/** * Implements {@link * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}. */ public Value computeValue(CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) { if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { ListValue lv = (ListValue)value; int len = lv.getLength(); ListValue result = new ListValue(' '); for (int i=0; i<len; i++) { Value v = lv.item(0); if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_URI) { // Reveal the absolute value as the cssText now. result.append(new URIValue(v.getStringValue(), v.getStringValue())); } else { result.append(v); } } return result; } return super.computeValue(elt, pseudo, engine, idx, sm, value); }
/** * Creates a CSSValue to manage the value at the given index. */ protected CSSValue createCSSValue(int idx) { if (idx > SVGCSSEngine.FINAL_INDEX) { if (cssEngine.getValueManagers()[idx] instanceof SVGPaintManager) { return new ComputedCSSPaintValue(idx); } if (cssEngine.getValueManagers()[idx] instanceof SVGColorManager) { return new ComputedCSSColorValue(idx); } } else { switch (idx) { case SVGCSSEngine.FILL_INDEX: case SVGCSSEngine.STROKE_INDEX: return new ComputedCSSPaintValue(idx); case SVGCSSEngine.FLOOD_COLOR_INDEX: case SVGCSSEngine.LIGHTING_COLOR_INDEX: case SVGCSSEngine.STOP_COLOR_INDEX: return new ComputedCSSColorValue(idx); } } return super.createCSSValue(idx); }
/** * <b>DOM</b>: Implements {@link org.w3c.dom.css.CSSValueList#item(int)}. */ public CSSValue item(int index) { int len = valueProvider.getValue().getLength(); if (index < 0 || index >= len) { return null; } if (items == null) { items = new CSSValue[valueProvider.getValue().getLength()]; } else if (items.length < len) { CSSValue[] nitems = new CSSValue[len]; System.arraycopy( items, 0, nitems, 0, items.length ); items = nitems; } CSSValue result = items[index]; if (result == null) { items[index] = result = new ListComponent(index); } return result; }
/** * Creates the CSS value associated with the given property. */ protected CSSValue createCSSValue(String name) { int idx = cssEngine.getPropertyIndex(name); if (idx > SVGCSSEngine.FINAL_INDEX) { if (cssEngine.getValueManagers()[idx] instanceof SVGPaintManager) { return new StyleDeclarationPaintValue(name); } if (cssEngine.getValueManagers()[idx] instanceof SVGColorManager) { return new StyleDeclarationColorValue(name); } } else { switch (idx) { case SVGCSSEngine.FILL_INDEX: case SVGCSSEngine.STROKE_INDEX: return new StyleDeclarationPaintValue(name); case SVGCSSEngine.FLOOD_COLOR_INDEX: case SVGCSSEngine.LIGHTING_COLOR_INDEX: case SVGCSSEngine.STOP_COLOR_INDEX: return new StyleDeclarationColorValue(name); } } return super.createCSSValue(name); }
/** * <b>DOM</b>: Implements {@link * org.w3c.dom.svg.SVGColor#getColorType()}. */ public short getColorType() { Value value = valueProvider.getValue(); int cssValueType = value.getCssValueType(); switch ( cssValueType ) { case CSSValue.CSS_PRIMITIVE_VALUE: int primitiveType = value.getPrimitiveType(); switch ( primitiveType ) { case CSSPrimitiveValue.CSS_IDENT: { if (value.getStringValue().equalsIgnoreCase (CSSConstants.CSS_CURRENTCOLOR_VALUE)) return SVG_COLORTYPE_CURRENTCOLOR; return SVG_COLORTYPE_RGBCOLOR; } case CSSPrimitiveValue.CSS_RGBCOLOR: return SVG_COLORTYPE_RGBCOLOR; } // there was no case for this primitiveType, prevent throwing the other exception throw new IllegalStateException("Found unexpected PrimitiveType:" + primitiveType ); case CSSValue.CSS_VALUE_LIST: return SVG_COLORTYPE_RGBCOLOR_ICCCOLOR; } // should not happen throw new IllegalStateException("Found unexpected CssValueType:" + cssValueType ); }
/** * Computes a CSS {@link Value} and performance inheritance if the * specified value is 'inherit'. */ protected Value computeValue(CSSStylableElement elt, String pn, Value v) { ValueManager[] vms = cssEngine.getValueManagers(); int idx = cssEngine.getPropertyIndex(pn); if (idx != -1) { if (v.getCssValueType() == CSSValue.CSS_INHERIT) { elt = CSSEngine.getParentCSSStylableElement(elt); if (elt != null) { return cssEngine.getComputedStyle(elt, null, idx); } return vms[idx].getDefaultValue(); } v = vms[idx].computeValue(elt, null, cssEngine, idx, dummyStyleMap, v); } return v; }
/** * Returns the subregion of user space where access to the * background image is allowed to happen. * * @param e the container element */ public static Rectangle2D convertEnableBackground(Element e /*, UnitProcessor.Context uctx*/) { Value v = getComputedStyle(e, SVGCSSEngine.ENABLE_BACKGROUND_INDEX); if (v.getCssValueType() != CSSValue.CSS_VALUE_LIST) { return null; // accumulate } ListValue lv = (ListValue)v; int length = lv.getLength(); switch (length) { case 1: return CompositeGraphicsNode.VIEWPORT; // new case 5: // new <x>,<y>,<width>,<height> float x = lv.item(1).getFloatValue(); float y = lv.item(2).getFloatValue(); float w = lv.item(3).getFloatValue(); float h = lv.item(4).getFloatValue(); return new Rectangle2D.Float(x, y, w, h); default: throw new IllegalStateException("Unexpected length:" + length ); // Cannot happen } }
/** * Converts the 'stroke-dasharray' property to a list of float * number in user units. * * @param v the CSS value describing the dasharray property */ public static float [] convertStrokeDasharray(Value v) { float [] dasharray = null; if (v.getCssValueType() == CSSValue.CSS_VALUE_LIST) { int length = v.getLength(); dasharray = new float[length]; float sum = 0; for (int i = 0; i < dasharray.length; ++i) { dasharray[i] = v.item(i).getFloatValue(); sum += dasharray[i]; } if (sum == 0) { /* 11.4 - If the sum of the <length>'s is zero, then * the stroke is rendered as if a value of none were specified. */ dasharray = null; } } return dasharray; }
@Override public List buildDeclarations(CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) { checkValueCount(cssName, 1, values.size()); CSSPrimitiveValue value = (CSSPrimitiveValue) values.get(0); checkInheritAllowed(value, inheritAllowed); if (value.getCssValueType() != CSSValue.CSS_INHERIT) { checkIdentOrURIType(cssName, value); if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { IdentValue ident = checkIdent(cssName, value); checkValidity(cssName, ALLOWED, ident); } } return Collections.singletonList(new PropertyDeclaration(cssName, value, important, origin)); }
@Override public List buildDeclarations( CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) { checkValueCount(cssName, 1, values.size()); PropertyValue value = (PropertyValue)values.get(0); checkInheritAllowed(value, inheritAllowed); if (value.getCssValueType() != CSSValue.CSS_INHERIT) { checkIdentLengthOrPercentType(cssName, value); if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { IdentValue ident = checkIdent(cssName, value); checkValidity(cssName, getAllowed(), ident); } else if (! isNegativeValuesAllowed() && value.getFloatValue() < 0.0f) { throw new CSSParseException(cssName + " may not be negative", -1); } } return Collections.singletonList( new PropertyDeclaration(cssName, value, important, origin)); }
@Override public List buildDeclarations(CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) { checkValueCount(cssName, 1, values.size()); CSSPrimitiveValue value = (CSSPrimitiveValue) values.get(0); checkInheritAllowed(value, inheritAllowed); if (value.getCssValueType() != CSSValue.CSS_INHERIT) { checkIdentType(cssName, value); IdentValue ident = checkIdent(cssName, value); checkValidity(cssName, getAllowed(), ident); } return Collections.singletonList(new PropertyDeclaration(cssName, value, important, origin)); }
@Override public List buildDeclarations(CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) { checkValueCount(cssName, 1, values.size()); PropertyValue value = (PropertyValue) values.get(0); checkInheritAllowed(value, inheritAllowed); if (value.getCssValueType() != CSSValue.CSS_INHERIT) { checkIdentNumberOrPercentType(cssName, value); if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { IdentValue ident = checkIdent(cssName, value); checkValidity(cssName, allowed, ident); } else if (value.getFloatValue() < 0.0f) { throw new CSSParseException(cssName + " may not be negative", -1); } } return Collections.singletonList(new PropertyDeclaration(cssName, value, important, origin)); }
@Override public List buildDeclarations(CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) { checkValueCount(cssName, 1, values.size()); PropertyValue value = (PropertyValue) values.get(0); checkInheritAllowed(value, inheritAllowed); if (value.getCssValueType() != CSSValue.CSS_INHERIT) { checkLengthOrPercentType(cssName, value); if (!isNegativeValuesAllowed() && value.getFloatValue() < 0.0f) { throw new CSSParseException(cssName + " may not be negative", -1); } } return Collections.singletonList(new PropertyDeclaration(cssName, value, important, origin)); }
@Override public List buildDeclarations(CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) { checkValueCount(cssName, 1, values.size()); PropertyValue value = (PropertyValue) values.get(0); checkInheritAllowed(value, inheritAllowed); if (value.getCssValueType() != CSSValue.CSS_INHERIT) { checkIdentNumberType(cssName, value); if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { IdentValue ident = checkIdent(cssName, value); checkValidity(cssName, allowed, ident); } else if (value.getFloatValue() < 0.0f) { throw new CSSParseException(cssName + " may not be negative", -1); } } return Collections.singletonList(new PropertyDeclaration(cssName, value, important, origin)); }
@Override public List buildDeclarations(CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) { checkValueCount(cssName, 1, values.size()); CSSPrimitiveValue value = (CSSPrimitiveValue) values.get(0); checkInheritAllowed(value, inheritAllowed); if (value.getCssValueType() != CSSValue.CSS_INHERIT) { checkIdentOrColorType(cssName, value); if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { FSRGBColor color = Conversions.getColor(value.getStringValue()); if (color != null) { return Collections.singletonList( new PropertyDeclaration(cssName, new PropertyValue(color), important, origin)); } IdentValue ident = checkIdent(cssName, value); checkValidity(cssName, ALLOWED, ident); } } return Collections.singletonList(new PropertyDeclaration(cssName, value, important, origin)); }
private ColorDefinition getColor( CSSValue value ) { if ( value != null && value instanceof RGBColorValue ) { RGBColorValue color = (RGBColorValue) value; try { return goFactory.createColorDefinition( Math.round( color.getRed( ) .getFloatValue( CSSPrimitiveValue.CSS_NUMBER ) ), Math.round( color.getGreen( ) .getFloatValue( CSSPrimitiveValue.CSS_NUMBER ) ), Math.round( color.getBlue( ) .getFloatValue( CSSPrimitiveValue.CSS_NUMBER ) ) ); } catch ( RuntimeException ex ) { logger.log( Level.WARNING.intValue( ), "invalid color: {0}" + value.toString( ) ); //$NON-NLS-1$ } } return null; }
/** * Build the Text-Decoration style string. * * @param styleBuffer * The <code>StringBuffer</code> to which the result is output. * @param linethrough * The line-through value. * @param underline * The underline value. * @param overline * The overline value. */ public static void buildTextDecoration( StringBuffer styleBuffer, IStyle style ) { CSSValue linethrough = style.getProperty(IStyle.STYLE_TEXT_LINETHROUGH); CSSValue underline = style.getProperty(IStyle.STYLE_TEXT_UNDERLINE); CSSValue overline = style.getProperty(IStyle.STYLE_TEXT_OVERLINE); if (linethrough == IStyle.LINE_THROUGH_VALUE || underline == IStyle.UNDERLINE_VALUE || overline == IStyle.OVERLINE_VALUE) { styleBuffer.append( " text-decoration:" ); //$NON-NLS-1$ if (IStyle.LINE_THROUGH_VALUE == linethrough ) { addPropValue( styleBuffer, "line-through" ); } if ( IStyle.UNDERLINE_VALUE == underline) { addPropValue( styleBuffer, "underline" ); } if ( IStyle.OVERLINE_VALUE == overline) { addPropValue( styleBuffer, "overline" ); } styleBuffer.append( ';' ); } }