/** * Converts a Paint definition to a concrete <code>java.awt.Paint</code> instance according to the * specified parameters. * * @param paintedElement the element interested in a Paint * @param paintedNode the graphics node to paint (objectBoundingBox) * @param paintDef the paint definition * @param opacity the opacity to consider for the Paint * @param ctx the bridge context */ public static Paint convertPaint( Element paintedElement, GraphicsNode paintedNode, Value paintDef, float opacity, BridgeContext ctx) { if (paintDef.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { switch (paintDef.getPrimitiveType()) { case CSSPrimitiveValue.CSS_IDENT: return null; // none case CSSPrimitiveValue.CSS_RGBCOLOR: return convertColor(paintDef, opacity); case CSSPrimitiveValue.CSS_URI: return convertURIPaint(paintedElement, paintedNode, paintDef, opacity, ctx); default: throw new IllegalArgumentException("Paint argument is not an appropriate CSS value"); } } else { // List Value v = paintDef.item(0); switch (v.getPrimitiveType()) { case CSSPrimitiveValue.CSS_RGBCOLOR: return convertRGBICCColor(paintedElement, v, (ICCColor) paintDef.item(1), opacity, ctx); case CSSPrimitiveValue.CSS_URI: { Paint result = silentConvertURIPaint(paintedElement, paintedNode, v, opacity, ctx); if (result != null) return result; v = paintDef.item(1); switch (v.getPrimitiveType()) { case CSSPrimitiveValue.CSS_IDENT: return null; // none case CSSPrimitiveValue.CSS_RGBCOLOR: if (paintDef.getLength() == 2) { return convertColor(v, opacity); } else { return convertRGBICCColor( paintedElement, v, (ICCColor) paintDef.item(2), opacity, ctx); } default: throw new IllegalArgumentException( "Paint argument is not an appropriate CSS value"); } } default: // can't be reached throw new IllegalArgumentException("Paint argument is not an appropriate CSS value"); } } }
/** * 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; }