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.LinearGradientPaint; 26 import org.apache.batik.ext.awt.MultipleGradientPaint; 27 import org.apache.batik.gvt.GraphicsNode; 28 import org.w3c.dom.Element ; 29 30 36 public class SVGLinearGradientElementBridge 37 extends AbstractSVGGradientElementBridge { 38 39 42 public SVGLinearGradientElementBridge() {} 43 44 47 public String getLocalName() { 48 return SVG_LINEAR_GRADIENT_TAG; 49 } 50 51 64 protected 65 Paint buildGradient(Element paintElement, 66 Element paintedElement, 67 GraphicsNode paintedNode, 68 MultipleGradientPaint.CycleMethodEnum spreadMethod, 69 MultipleGradientPaint.ColorSpaceEnum colorSpace, 70 AffineTransform transform, 71 Color [] colors, 72 float [] offsets, 73 BridgeContext ctx) { 74 75 String x1Str = SVGUtilities.getChainableAttributeNS 77 (paintElement, null, SVG_X1_ATTRIBUTE, ctx); 78 if (x1Str.length() == 0) { 79 x1Str = SVG_LINEAR_GRADIENT_X1_DEFAULT_VALUE; 80 } 81 82 String y1Str = SVGUtilities.getChainableAttributeNS 84 (paintElement, null, SVG_Y1_ATTRIBUTE, ctx); 85 if (y1Str.length() == 0) { 86 y1Str = SVG_LINEAR_GRADIENT_Y1_DEFAULT_VALUE; 87 } 88 89 String x2Str = SVGUtilities.getChainableAttributeNS 91 (paintElement, null, SVG_X2_ATTRIBUTE, ctx); 92 if (x2Str.length() == 0) { 93 x2Str = SVG_LINEAR_GRADIENT_X2_DEFAULT_VALUE; 94 } 95 96 String y2Str = SVGUtilities.getChainableAttributeNS 98 (paintElement, null, SVG_Y2_ATTRIBUTE, ctx); 99 if (y2Str.length() == 0) { 100 y2Str = SVG_LINEAR_GRADIENT_Y2_DEFAULT_VALUE; 101 } 102 103 short coordSystemType; 105 String s = SVGUtilities.getChainableAttributeNS 106 (paintElement, null, SVG_GRADIENT_UNITS_ATTRIBUTE, ctx); 107 if (s.length() == 0) { 108 coordSystemType = SVGUtilities.OBJECT_BOUNDING_BOX; 109 } else { 110 coordSystemType = SVGUtilities.parseCoordinateSystem 111 (paintElement, SVG_GRADIENT_UNITS_ATTRIBUTE, s); 112 } 113 114 if (coordSystemType == SVGUtilities.OBJECT_BOUNDING_BOX) { 116 transform = SVGUtilities.toObjectBBox(transform, paintedNode); 117 } 118 UnitProcessor.Context uctx 119 = UnitProcessor.createContext(ctx, paintElement); 120 121 Point2D p1 = SVGUtilities.convertPoint(x1Str, 122 SVG_X1_ATTRIBUTE, 123 y1Str, 124 SVG_Y1_ATTRIBUTE, 125 coordSystemType, 126 uctx); 127 128 Point2D p2 = SVGUtilities.convertPoint(x2Str, 129 SVG_X2_ATTRIBUTE, 130 y2Str, 131 SVG_Y2_ATTRIBUTE, 132 coordSystemType, 133 uctx); 134 135 if (p1.getX() == p2.getX() && p1.getY() == p2.getY()) { 139 return colors[colors.length-1]; 140 } else { 141 return new LinearGradientPaint(p1, 142 p2, 143 offsets, 144 colors, 145 spreadMethod, 146 colorSpace, 147 transform); 148 } 149 } 150 } 151 | Popular Tags |