1 18 package org.apache.batik.bridge; 19 20 import java.awt.Color ; 21 import java.awt.Paint ; 22 import java.awt.geom.AffineTransform ; 23 import java.awt.geom.Point2D ; 24 25 import org.apache.batik.ext.awt.MultipleGradientPaint; 26 import org.apache.batik.ext.awt.RadialGradientPaint; 27 import org.apache.batik.gvt.GraphicsNode; 28 import org.w3c.dom.Element ; 29 30 36 public class SVGRadialGradientElementBridge 37 extends AbstractSVGGradientElementBridge { 38 39 40 43 public SVGRadialGradientElementBridge() {} 44 45 48 public String getLocalName() { 49 return SVG_RADIAL_GRADIENT_TAG; 50 } 51 52 65 protected 66 Paint buildGradient(Element paintElement, 67 Element paintedElement, 68 GraphicsNode paintedNode, 69 MultipleGradientPaint.CycleMethodEnum spreadMethod, 70 MultipleGradientPaint.ColorSpaceEnum colorSpace, 71 AffineTransform transform, 72 Color [] colors, 73 float [] offsets, 74 BridgeContext ctx) { 75 76 String cxStr = SVGUtilities.getChainableAttributeNS 78 (paintElement, null, SVG_CX_ATTRIBUTE, ctx); 79 if (cxStr.length() == 0) { 80 cxStr = SVG_RADIAL_GRADIENT_CX_DEFAULT_VALUE; 81 } 82 83 String cyStr = SVGUtilities.getChainableAttributeNS 85 (paintElement, null, SVG_CY_ATTRIBUTE, ctx); 86 if (cyStr.length() == 0) { 87 cyStr = SVG_RADIAL_GRADIENT_CY_DEFAULT_VALUE; 88 } 89 90 String rStr = SVGUtilities.getChainableAttributeNS 92 (paintElement, null, SVG_R_ATTRIBUTE, ctx); 93 if (rStr.length() == 0) { 94 rStr = SVG_RADIAL_GRADIENT_R_DEFAULT_VALUE; 95 } 96 97 String fxStr = SVGUtilities.getChainableAttributeNS 99 (paintElement, null, SVG_FX_ATTRIBUTE, ctx); 100 if (fxStr.length() == 0) { 101 fxStr = cxStr; 102 } 103 104 String fyStr = SVGUtilities.getChainableAttributeNS 106 (paintElement, null, SVG_FY_ATTRIBUTE, ctx); 107 if (fyStr.length() == 0) { 108 fyStr = cyStr; 109 } 110 111 short coordSystemType; 113 String s = SVGUtilities.getChainableAttributeNS 114 (paintElement, null, SVG_GRADIENT_UNITS_ATTRIBUTE, ctx); 115 if (s.length() == 0) { 116 coordSystemType = SVGUtilities.OBJECT_BOUNDING_BOX; 117 } else { 118 coordSystemType = SVGUtilities.parseCoordinateSystem 119 (paintElement, SVG_GRADIENT_UNITS_ATTRIBUTE, s); 120 } 121 122 if (coordSystemType == SVGUtilities.OBJECT_BOUNDING_BOX) { 124 transform = SVGUtilities.toObjectBBox(transform, 125 paintedNode); 126 } 127 UnitProcessor.Context uctx 128 = UnitProcessor.createContext(ctx, paintElement); 129 130 float r = SVGUtilities.convertLength(rStr, 131 SVG_R_ATTRIBUTE, 132 coordSystemType, 133 uctx); 134 if (r == 0) { 137 return colors[colors.length-1]; 138 } else { 139 Point2D c = SVGUtilities.convertPoint(cxStr, 140 SVG_CX_ATTRIBUTE, 141 cyStr, 142 SVG_CY_ATTRIBUTE, 143 coordSystemType, 144 uctx); 145 146 Point2D f = SVGUtilities.convertPoint(fxStr, 147 SVG_FX_ATTRIBUTE, 148 fyStr, 149 SVG_FY_ATTRIBUTE, 150 coordSystemType, 151 uctx); 152 153 return new RadialGradientPaint(c, 155 r, 156 f, 157 offsets, 158 colors, 159 spreadMethod, 160 RadialGradientPaint.SRGB, 161 transform); 162 } 163 } 164 } 165 | Popular Tags |