Changeset 6002 in josm for trunk/src/com/kitfox/svg/RadialGradient.java
- Timestamp:
- 2013-06-11T01:01:28+02:00 (13 years ago)
- File:
-
- 1 edited
-
trunk/src/com/kitfox/svg/RadialGradient.java (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/RadialGradient.java
r4256 r6002 1 1 /* 2 * RadialGradient.java 3 * 4 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * 22 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other 23 * projects can be found at http://www.kitfox.com 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or 7 * without modification, are permitted provided that the following 8 * conditions are met: 9 * 10 * - Redistributions of source code must retain the above 11 * copyright notice, this list of conditions and the following 12 * disclaimer. 13 * - Redistributions in binary form must reproduce the above 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials 16 * provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other 32 * projects can be found at http://www.kitfox.com 24 33 * 25 34 * Created on January 26, 2004, 1:55 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 import com.kitfox.svg.xml.StyleAttribute; 31 import java.awt.geom.*; 32 import java.awt.*; 33 34 import com.kitfox.svg.xml.*; 35 import org.xml.sax.*; 36 37 //import org.apache.batik.ext.awt.*; 38 import com.kitfox.svg.batik.*; 39 39 import java.awt.Color; 40 import java.awt.Paint; 41 import java.awt.geom.AffineTransform; 42 import java.awt.geom.Point2D; 43 import java.awt.geom.Rectangle2D; 40 44 41 45 /** … … 43 47 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 44 48 */ 45 public class RadialGradient extends Gradient { 49 public class RadialGradient extends Gradient 50 { 51 public static final String TAG_NAME = "radialgradient"; 46 52 47 53 float cx = 0.5f; … … 51 57 float r = 0.5f; 52 58 53 /** Creates a new instance of RadialGradient */ 54 public RadialGradient() { 55 } 56 /* 57 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 58 { 59 //Load style string 60 super.loaderStartElement(helper, attrs, parent); 61 62 String cx = attrs.getValue("cx"); 63 String cy = attrs.getValue("cy"); 64 String fx = attrs.getValue("fx"); 65 String fy = attrs.getValue("fy"); 66 String r = attrs.getValue("r"); 67 68 if (cx != null) this.cx = (float)XMLParseUtil.parseRatio(cx); 69 if (cy != null) this.cy = (float)XMLParseUtil.parseRatio(cy); 70 if (fx != null) this.fx = (float)XMLParseUtil.parseRatio(fx); 71 if (fy != null) this.fy = (float)XMLParseUtil.parseRatio(fy); 72 if (r != null) this.r = (float)XMLParseUtil.parseRatio(r); 73 } 74 */ 75 76 /* 77 public void loaderEndElement(SVGLoaderHelper helper) 78 { 79 super.loaderEndElement(helper); 80 81 build(); 82 } 59 /** 60 * Creates a new instance of RadialGradient 83 61 */ 84 62 public RadialGradient() 63 { 64 } 65 66 public String getTagName() 67 { 68 return TAG_NAME; 69 } 70 85 71 protected void build() throws SVGException 86 72 { 87 73 super.build(); 88 74 89 75 StyleAttribute sty = new StyleAttribute(); 90 91 if (getPres(sty.setName("cx"))) cx = sty.getFloatValueWithUnits(); 92 93 if (getPres(sty.setName("cy"))) cy = sty.getFloatValueWithUnits(); 94 95 if (getPres(sty.setName("fx"))) fx = sty.getFloatValueWithUnits(); 96 97 if (getPres(sty.setName("fy"))) fy = sty.getFloatValueWithUnits(); 98 99 if (getPres(sty.setName("r"))) r = sty.getFloatValueWithUnits(); 100 } 101 76 77 if (getPres(sty.setName("cx"))) 78 { 79 cx = sty.getFloatValueWithUnits(); 80 } 81 82 if (getPres(sty.setName("cy"))) 83 { 84 cy = sty.getFloatValueWithUnits(); 85 } 86 87 if (getPres(sty.setName("fx"))) 88 { 89 fx = sty.getFloatValueWithUnits(); 90 } 91 92 if (getPres(sty.setName("fy"))) 93 { 94 fy = sty.getFloatValueWithUnits(); 95 } 96 97 if (getPres(sty.setName("r"))) 98 { 99 r = sty.getFloatValueWithUnits(); 100 } 101 } 102 102 103 public Paint getPaint(Rectangle2D bounds, AffineTransform xform) 103 104 { … … 117 118 } 118 119 119 com.kitfox.svg.batik.RadialGradientPaint paint; 120 121 if (gradientUnits == GU_USER_SPACE_ON_USE) 120 Paint paint; 121 Point2D.Float pt1 = new Point2D.Float(cx, cy); 122 Point2D.Float pt2 = new Point2D.Float(fx, fy); 123 if (pt1.equals(pt2)) 124 { 125 Color[] colors = getStopColors(); 126 paint = colors.length > 0 ? colors[0] : Color.black; 127 } else if (gradientUnits == GU_USER_SPACE_ON_USE) 122 128 { 123 129 paint = new com.kitfox.svg.batik.RadialGradientPaint( 124 new Point2D.Float(cx, cy),130 pt1, 125 131 r, 126 new Point2D.Float(fx, fy),132 pt2, 127 133 getStopFractions(), 128 134 getStopColors(), … … 130 136 com.kitfox.svg.batik.MultipleGradientPaint.SRGB, 131 137 gradientTransform); 132 } 133 else 138 } else 134 139 { 135 140 AffineTransform viewXform = new AffineTransform(); … … 140 145 141 146 paint = new com.kitfox.svg.batik.RadialGradientPaint( 142 new Point2D.Float(cx, cy),147 pt1, 143 148 r, 144 new Point2D.Float(fx, fy),149 pt2, 145 150 getStopFractions(), 146 151 getStopColors(), … … 154 159 155 160 /** 156 * Updates all attributes in this diagram associated with a time event. 157 * Ie, all attributes with track information. 161 * Updates all attributes in this diagram associated with a time event. Ie, 162 * all attributes with track information. 163 * 158 164 * @return - true if this node has changed state as a result of the time 159 165 * update … … 167 173 StyleAttribute sty = new StyleAttribute(); 168 174 boolean shapeChange = false; 169 175 170 176 if (getPres(sty.setName("cx"))) 171 177 { … … 177 183 } 178 184 } 179 185 180 186 if (getPres(sty.setName("cy"))) 181 187 { … … 187 193 } 188 194 } 189 195 190 196 if (getPres(sty.setName("fx"))) 191 197 { … … 197 203 } 198 204 } 199 205 200 206 if (getPres(sty.setName("fy"))) 201 207 { … … 207 213 } 208 214 } 209 215 210 216 if (getPres(sty.setName("r"))) 211 217 { … … 217 223 } 218 224 } 219 225 220 226 return changeState; 221 227 }
Note:
See TracChangeset
for help on using the changeset viewer.
