/** * Converts the 'values' attribute of the specified feColorMatrix * filter primitive element for the 'saturate' type. * * @param filterElement the filter element * @param ctx the BridgeContext to use for error information */ protected static float convertValuesToSaturate(Element filterElement, BridgeContext ctx) { String s = filterElement.getAttributeNS(null, SVG_VALUES_ATTRIBUTE); if (s.length() == 0) return 1; // default is 1 try { return SVGUtilities.convertSVGNumber(s); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {SVG_VALUES_ATTRIBUTE, s}); } }
/** * Converts the 'values' attribute of the specified feColorMatrix * filter primitive element for the 'hueRotate' type. * * @param filterElement the filter element * @param ctx the BridgeContext to use for error information */ protected static float convertValuesToHueRotate(Element filterElement, BridgeContext ctx) { String s = filterElement.getAttributeNS(null, SVG_VALUES_ATTRIBUTE); if (s.length() == 0) return 0; // default is 0 try { return (float) Math.toRadians( SVGUtilities.convertSVGNumber(s) ); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object [] {SVG_VALUES_ATTRIBUTE, s}); } }
/** * Converts the 'values' attribute of the specified feColorMatrix * filter primitive element for the 'saturate' type. * * @param filterElement the filter element * @param ctx the BridgeContext to use for error information */ protected static float convertValuesToSaturate(Element filterElement, BridgeContext ctx) { String s = filterElement.getAttributeNS(null, SVG_VALUES_ATTRIBUTE); if (s.length() == 0) return 1; // default is 1 try { return SVGUtilities.convertSVGNumber(s); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {SVG_VALUES_ATTRIBUTE, s}); } }
public static ArrayList svgRotateArrayToFloats(Element element, String attrName, String valueStr, BridgeContext ctx) { StringTokenizer st = new StringTokenizer(valueStr, ", ", false); ArrayList values = new ArrayList(); String s; while (st.hasMoreTokens()) { try { s = st.nextToken(); values.add (new Float(Math.toRadians (SVGUtilities.convertSVGNumber(s)))); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, element, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object [] {attrName, valueStr}); } } return values; }
public static ArrayList svgRotateArrayToFloats(Element element, String attrName, String valueStr, BridgeContext ctx) { StringTokenizer st = new StringTokenizer(valueStr, ", ", false); ArrayList values = new ArrayList(); String s; while (st.hasMoreTokens()) { try { s = st.nextToken(); values.add ((float) Math.toRadians (SVGUtilities.convertSVGNumber(s))); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, element, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object [] {attrName, valueStr}); } } return values; }
/** * Converts the 'values' attribute of the specified feColorMatrix * filter primitive element for the 'hueRotate' type. * * @param filterElement the filter element * @param ctx the BridgeContext to use for error information */ protected static float convertValuesToHueRotate(Element filterElement, BridgeContext ctx) { String s = filterElement.getAttributeNS(null, SVG_VALUES_ATTRIBUTE); if (s.length() == 0) return 0; // default is 0 try { return (float) Math.toRadians( SVGUtilities.convertSVGNumber(s) ); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object [] {SVG_VALUES_ATTRIBUTE, s}); } }
/** * Converts the 'values' attribute of the specified feColorMatrix * filter primitive element for the 'hueRotate' type. * * @param filterElement the filter element * @param ctx the BridgeContext to use for error information */ protected static float convertValuesToHueRotate(Element filterElement, BridgeContext ctx) { String s = filterElement.getAttributeNS(null, SVG_VALUES_ATTRIBUTE); if (s.length() == 0) return 0; // default is 0 try { return (float) Math.toRadians( SVGUtilities.convertSVGNumber(s) ); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object [] {SVG_VALUES_ATTRIBUTE, s}); } }
/** * Converts the 'values' attribute of the specified feColorMatrix * filter primitive element for the 'saturate' type. * * @param filterElement the filter element * @param ctx the BridgeContext to use for error information */ protected static float convertValuesToSaturate(Element filterElement, BridgeContext ctx) { String s = filterElement.getAttributeNS(null, SVG_VALUES_ATTRIBUTE); if (s.length() == 0) return 1; // default is 1 try { return SVGUtilities.convertSVGNumber(s); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {SVG_VALUES_ATTRIBUTE, s}); } }
public static ArrayList svgRotateArrayToFloats(Element element, String attrName, String valueStr, BridgeContext ctx) { StringTokenizer st = new StringTokenizer(valueStr, ", ", false); ArrayList values = new ArrayList(); String s; while (st.hasMoreTokens()) { try { s = st.nextToken(); values.add ((float) Math.toRadians (SVGUtilities.convertSVGNumber(s))); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, element, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object [] {attrName, valueStr}); } } return values; }
/** * Converts the 'tableValues' attribute of the specified component * transfer function element. * * @param e the element that represents a component transfer function * @param ctx the BridgeContext to use for error information */ protected static float [] convertTableValues(Element e, BridgeContext ctx) { String s = e.getAttributeNS(null, SVG_TABLE_VALUES_ATTRIBUTE); if (s.length() == 0) { return null; } StringTokenizer tokens = new StringTokenizer(s, " ,"); float [] v = new float[tokens.countTokens()]; try { for (int i = 0; tokens.hasMoreTokens(); ++i) { v[i] = SVGUtilities.convertSVGNumber(tokens.nextToken()); } } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, e, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {SVG_TABLE_VALUES_ATTRIBUTE, s}); } return v; }
/** * Converts on the specified filter primitive element, the specified * attribute that represents a float and with the specified * default value. * * @param filterElement the filter primitive element * @param attrName the name of the attribute * @param defaultValue the default value of the attribute * @param ctx the BridgeContext to use for error information */ protected static float convertNumber(Element filterElement, String attrName, float defaultValue, BridgeContext ctx) { String s = filterElement.getAttributeNS(null, attrName); if (s.length() == 0) { return defaultValue; } else { try { return SVGUtilities.convertSVGNumber(s); } catch (NumberFormatException nfEx) { throw new BridgeException (ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {attrName, s, nfEx}); } } } }
/** * Converts on the specified filter primitive element, the specified * attribute that represents a float and with the specified * default value. * * @param filterElement the filter primitive element * @param attrName the name of the attribute * @param defaultValue the default value of the attribute * @param ctx the BridgeContext to use for error information */ protected static float convertNumber(Element filterElement, String attrName, float defaultValue, BridgeContext ctx) { String s = filterElement.getAttributeNS(null, attrName); if (s.length() == 0) { return defaultValue; } else { try { return SVGUtilities.convertSVGNumber(s); } catch (NumberFormatException nfEx) { throw new BridgeException (ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {attrName, s, nfEx}); } } } }
/** * Converts the 'tableValues' attribute of the specified component * transfer function element. * * @param e the element that represents a component transfer function * @param ctx the BridgeContext to use for error information */ protected static float [] convertTableValues(Element e, BridgeContext ctx) { String s = e.getAttributeNS(null, SVG_TABLE_VALUES_ATTRIBUTE); if (s.length() == 0) { return null; } StringTokenizer tokens = new StringTokenizer(s, " ,"); float [] v = new float[tokens.countTokens()]; try { for (int i = 0; tokens.hasMoreTokens(); ++i) { v[i] = SVGUtilities.convertSVGNumber(tokens.nextToken()); } } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, e, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {SVG_TABLE_VALUES_ATTRIBUTE, s}); } return v; }
/** * Converts the 'tableValues' attribute of the specified component * transfer function element. * * @param e the element that represents a component transfer function * @param ctx the BridgeContext to use for error information */ protected static float [] convertTableValues(Element e, BridgeContext ctx) { String s = e.getAttributeNS(null, SVG_TABLE_VALUES_ATTRIBUTE); if (s.length() == 0) { return null; } StringTokenizer tokens = new StringTokenizer(s, " ,"); float [] v = new float[tokens.countTokens()]; try { for (int i = 0; tokens.hasMoreTokens(); ++i) { v[i] = SVGUtilities.convertSVGNumber(tokens.nextToken()); } } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, e, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {SVG_TABLE_VALUES_ATTRIBUTE, s}); } return v; }
/** * Convert the 'divisor' attribute of the specified feConvolveMatrix * filter primitive element. * * @param filterElement the feConvolveMatrix filter primitive element * @param kernelMatrix the value of the 'kernelMatrix' attribute * @param ctx the BridgeContext to use for error information */ protected static float convertDivisor(Element filterElement, float[] kernelMatrix, BridgeContext ctx) { String s = filterElement.getAttributeNS(null, SVG_DIVISOR_ATTRIBUTE); if (s.length() == 0) { // default is sum of kernel values (if sum is zero then 1.0) float sum = 0; for (float aKernelMatrix : kernelMatrix) { sum += aKernelMatrix; } return (sum == 0) ? 1.0f : sum; } else { try { return SVGUtilities.convertSVGNumber(s); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {SVG_DIVISOR_ATTRIBUTE, s, nfEx }); } } }
/** * Converts on the specified filter primitive element, the specified * attribute that represents a float and with the specified * default value. * * @param filterElement the filter primitive element * @param attrName the name of the attribute * @param defaultValue the default value of the attribute * @param ctx the BridgeContext to use for error information */ protected static float convertNumber(Element filterElement, String attrName, float defaultValue, BridgeContext ctx) { String s = filterElement.getAttributeNS(null, attrName); if (s.length() == 0) { return defaultValue; } else { try { return SVGUtilities.convertSVGNumber(s); } catch (NumberFormatException nfEx) { throw new BridgeException (ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {attrName, s, nfEx}); } } } }
/** * Convert the 'divisor' attribute of the specified feConvolveMatrix * filter primitive element. * * @param filterElement the feConvolveMatrix filter primitive element * @param kernelMatrix the value of the 'kernelMatrix' attribute * @param ctx the BridgeContext to use for error information */ protected static float convertDivisor(Element filterElement, float[] kernelMatrix, BridgeContext ctx) { String s = filterElement.getAttributeNS(null, SVG_DIVISOR_ATTRIBUTE); if (s.length() == 0) { // default is sum of kernel values (if sum is zero then 1.0) float sum = 0; for (float aKernelMatrix : kernelMatrix) { sum += aKernelMatrix; } return (sum == 0) ? 1.0f : sum; } else { try { return SVGUtilities.convertSVGNumber(s); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {SVG_DIVISOR_ATTRIBUTE, s, nfEx }); } } }
StringTokenizer tokens = new StringTokenizer(s, " ,"); try { units[0] = SVGUtilities.convertSVGNumber(tokens.nextToken()); if (tokens.hasMoreTokens()) { units[1] = SVGUtilities.convertSVGNumber(tokens.nextToken()); } else { units[1] = units[0];
/** * Convert the 'divisor' attribute of the specified feConvolveMatrix * filter primitive element. * * @param filterElement the feConvolveMatrix filter primitive element * @param kernelMatrix the value of the 'kernelMatrix' attribute * @param ctx the BridgeContext to use for error information */ protected static float convertDivisor(Element filterElement, float[] kernelMatrix, BridgeContext ctx) { String s = filterElement.getAttributeNS(null, SVG_DIVISOR_ATTRIBUTE); if (s.length() == 0) { // default is sum of kernel values (if sum is zero then 1.0) float sum = 0; for (int i=0; i < kernelMatrix.length; ++i) { sum += kernelMatrix[i]; } return (sum == 0) ? 1.0f : sum; } else { try { return SVGUtilities.convertSVGNumber(s); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {SVG_DIVISOR_ATTRIBUTE, s, nfEx }); } } }
/** * Returns the specular exponent of the specular feSpecularLighting * filter primitive element. * * @param filterElement the feSpecularLighting filter primitive element * @param ctx the BridgeContext to use for error information */ protected static float convertSpecularExponent(Element filterElement, BridgeContext ctx) { String s = filterElement.getAttributeNS (null, SVG_SPECULAR_EXPONENT_ATTRIBUTE); if (s.length() == 0) { return 1; // default is 1 } else { try { float v = SVGUtilities.convertSVGNumber(s); if (v < 1 || v > 128) { throw new BridgeException (ctx, filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {SVG_SPECULAR_CONSTANT_ATTRIBUTE, s}); } return v; } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, filterElement, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {SVG_SPECULAR_CONSTANT_ATTRIBUTE, s, nfEx }); } } } }