private String getRadialGradientElement ( String id , RadialGradientPaint rgp ) { StringBuilder b = new StringBuilder ( "<radialGradient id=\"" ) . append ( id ) . append ( "\" gradientUnits=\"userSpaceOnUse\" " ) ; Point2D center = rgp . getCenterPoint ( ) ; Point2D focus = rgp . getFocusPoint ( ) ; float radius = rgp . getRadius ( ) ; b . append ( "cx=\"" ) . append ( geomDP ( center . getX ( ) ) ) . append ( "\" " ) ; b . append ( "cy=\"" ) . append ( geomDP ( center . getY ( ) ) ) . append ( "\" " ) ; b . append ( "r=\"" ) . append ( geomDP ( radius ) ) . append ( "\" " ) ; b . append ( "fx=\"" ) . append ( geomDP ( focus . getX ( ) ) ) . append ( "\" " ) ; b . append ( "fy=\"" ) . append ( geomDP ( focus . getY ( ) ) ) . append ( "\">" ) ; Color [ ] colors = rgp . getColors ( ) ; float [ ] fractions = rgp . getFractions ( ) ; for ( int i = 0 ; i < colors . length ; i ++ ) { Color c = colors [ i ] ; float f = fractions [ i ] ; b . append ( "<stop offset=\"" ) . append ( geomDP ( f * 100 ) ) . append ( "%\" " ) ; b . append ( "stop-color=\"" ) . append ( rgbColorStr ( c ) ) . append ( "\"" ) ; if ( c . getAlpha ( ) < 255 ) { double alphaPercent = c . getAlpha ( ) / 255.0 ; b . append ( " stop-opacity=\"" ) . append ( transformDP ( alphaPercent ) ) . append ( "\"" ) ; } b . append ( "/>" ) ; } return b . append ( "</radialGradient>" ) . toString ( ) ; }
Returns an element to represent a radial gradient . All the radial gradients that are used get written to the DEFS element in the SVG .