Changeset 6002 in josm for trunk/src/com/kitfox/svg
- Timestamp:
- 2013-06-11T01:01:28+02:00 (10 years ago)
- Location:
- trunk/src/com/kitfox/svg
- Files:
-
- 3 added
- 2 deleted
- 85 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/A.java
r4256 r6002 1 1 /* 2 * Stop.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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:56 AM … … 29 38 30 39 import com.kitfox.svg.xml.StyleAttribute; 31 import java.awt.*;32 40 import java.net.URI; 33 41 … … 36 44 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 37 45 */ 38 public class A extends Group { 46 public class A extends Group 47 { 48 public static final String TAG_NAME = "a"; 39 49 40 50 URI href; … … 42 52 43 53 /** Creates a new instance of Stop */ 44 public A() { 54 public A() 55 { 45 56 } 46 /* 47 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)57 58 public String getTagName() 48 59 { 49 //Load style string 50 super.loaderStartElement(helper, attrs, parent); 51 52 String offset = attrs.getValue("offset"); 53 this.offset = (float)XMLParseUtil.parseRatio(offset); 54 55 buildStop(); 60 return TAG_NAME; 56 61 } 57 */58 62 59 63 protected void build() throws SVGException -
trunk/src/com/kitfox/svg/Circle.java
r4256 r6002 1 1 /* 2 * Rect.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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, 5:25 PM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 … … 38 46 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 39 47 */ 40 public class Circle extends ShapeElement 48 public class Circle extends ShapeElement 41 49 { 42 50 51 public static final String TAG_NAME = "circle"; 43 52 float cx = 0f; 44 53 float cy = 0f; 45 54 float r = 0f; 46 47 48 55 Ellipse2D.Float circle = new Ellipse2D.Float(); 49 56 50 /** Creates a new instance of Rect */ 51 public Circle() { 57 /** 58 * Creates a new instance of Rect 59 */ 60 public Circle() 61 { 52 62 } 53 /* 54 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)63 64 public String getTagName() 55 65 { 56 //Load style string 57 super.loaderStartElement(helper, attrs, parent);66 return TAG_NAME; 67 } 58 68 59 String cx = attrs.getValue("cx");60 String cy = attrs.getValue("cy");61 String r = attrs.getValue("r");62 63 this.cx = XMLParseUtil.parseFloat(cx);64 this.cy = XMLParseUtil.parseFloat(cy);65 this.r = XMLParseUtil.parseFloat(r);66 67 build();68 69 //setBounds(this.cx - this.r, this.cy - this.r, this.r * 2.0, this.r * 2.0);70 }71 */72 /*73 public void loaderEndElement(SVGLoaderHelper helper)74 {75 // super.loaderEndElement(helper);76 77 // build();78 }79 */80 81 69 protected void build() throws SVGException 82 70 { 83 71 super.build(); 84 72 85 73 StyleAttribute sty = new StyleAttribute(); 86 87 if (getPres(sty.setName("cx"))) cx = sty.getFloatValueWithUnits(); 88 89 if (getPres(sty.setName("cy"))) cy = sty.getFloatValueWithUnits(); 90 91 if (getPres(sty.setName("r"))) r = sty.getFloatValueWithUnits(); 92 74 75 if (getPres(sty.setName("cx"))) 76 { 77 cx = sty.getFloatValueWithUnits(); 78 } 79 80 if (getPres(sty.setName("cy"))) 81 { 82 cy = sty.getFloatValueWithUnits(); 83 } 84 85 if (getPres(sty.setName("r"))) 86 { 87 r = sty.getFloatValueWithUnits(); 88 } 89 93 90 circle.setFrame(cx - r, cy - r, r * 2f, r * 2f); 94 91 } … … 112 109 113 110 /** 114 * Updates all attributes in this diagram associated with a time event. 115 * Ie, all attributes with track information. 111 * Updates all attributes in this diagram associated with a time event. Ie, 112 * all attributes with track information. 113 * 116 114 * @return - true if this node has changed state as a result of the time 117 115 * update … … 125 123 StyleAttribute sty = new StyleAttribute(); 126 124 boolean shapeChange = false; 127 125 128 126 if (getPres(sty.setName("cx"))) 129 127 { … … 135 133 } 136 134 } 137 135 138 136 if (getPres(sty.setName("cy"))) 139 137 { … … 145 143 } 146 144 } 147 145 148 146 if (getPres(sty.setName("r"))) 149 147 { … … 155 153 } 156 154 } 157 155 158 156 if (shapeChange) 159 157 { … … 162 160 // return true; 163 161 } 164 162 165 163 return changeState || shapeChange; 166 164 } 167 168 165 } 169 170 171 -
trunk/src/com/kitfox/svg/ClipPath.java
r4256 r6002 1 1 /* 2 * Stop.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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:56 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 … … 37 45 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 38 46 */ 39 public class ClipPath extends SVGElement 47 public class ClipPath extends SVGElement 40 48 { 41 49 50 public static final String TAG_NAME = "clippath"; 42 51 public static final int CP_USER_SPACE_ON_USE = 0; 43 52 public static final int CP_OBJECT_BOUNDING_BOX = 1; 44 45 53 int clipPathUnits = CP_USER_SPACE_ON_USE; 46 54 47 /** Creates a new instance of Stop */ 48 public ClipPath() { 55 /** 56 * Creates a new instance of Stop 57 */ 58 public ClipPath() 59 { 49 60 } 50 /* 51 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)61 62 public String getTagName() 52 63 { 53 //Load style string 54 super.loaderStartElement(helper, attrs, parent);64 return TAG_NAME; 65 } 55 66 56 String clipPathUnits = attrs.getValue("clipPathUnits");57 58 if (clipPathUnits.equals("objectBoundingBox")) this.clipPathUnits = CP_OBJECT_BOUNDING_BOX;59 60 }61 */62 67 /** 63 68 * Called after the start element but before the end element to indicate … … 66 71 public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException 67 72 { 68 super.loaderAddChild(helper, child); 69 70 // if (child instanceof ShapeElement) members.add(child); 73 super.loaderAddChild(helper, child); 71 74 } 72 75 73 /*74 public void loaderEndElement(SVGLoaderHelper helper)75 {76 // super.loaderEndElement(helper);77 78 // build();79 }80 */81 82 76 protected void build() throws SVGException 83 77 { 84 78 super.build(); 85 79 86 80 StyleAttribute sty = new StyleAttribute(); 87 81 88 82 clipPathUnits = (getPres(sty.setName("clipPathUnits")) 89 && sty.getStringValue().equals("objectBoundingBox")) 90 ? CP_OBJECT_BOUNDING_BOX 83 && sty.getStringValue().equals("objectBoundingBox")) 84 ? CP_OBJECT_BOUNDING_BOX 91 85 : CP_USER_SPACE_ON_USE; 92 86 } 93 87 94 88 public int getClipPathUnits() 95 89 { … … 99 93 public Shape getClipPathShape() 100 94 { 101 if (children.size() == 0) return null; 102 if (children.size() == 1) return ((ShapeElement)children.get(0)).getShape(); 95 if (children.isEmpty()) 96 { 97 return null; 98 } 99 if (children.size() == 1) 100 { 101 return ((ShapeElement) children.get(0)).getShape(); 102 } 103 103 104 104 Area clipArea = null; 105 105 for (Iterator it = children.iterator(); it.hasNext();) 106 106 { 107 ShapeElement se = (ShapeElement) it.next();107 ShapeElement se = (ShapeElement) it.next(); 108 108 109 109 if (clipArea == null) 110 110 { 111 111 Shape shape = se.getShape(); 112 if (shape != null) clipArea = new Area(se.getShape()); 112 if (shape != null) 113 { 114 clipArea = new Area(se.getShape()); 115 } 113 116 continue; 114 117 } 115 118 116 119 Shape shape = se.getShape(); 117 if (shape != null) clipArea.intersect(new Area(shape)); 120 if (shape != null) 121 { 122 clipArea.intersect(new Area(shape)); 123 } 118 124 } 119 125 … … 122 128 123 129 /** 124 * Updates all attributes in this diagram associated with a time event. 125 * Ie, all attributes with track information. 130 * Updates all attributes in this diagram associated with a time event. Ie, 131 * all attributes with track information. 132 * 126 133 * @return - true if this node has changed state as a result of the time 127 134 * update … … 129 136 public boolean updateTime(double curTime) throws SVGException 130 137 { 131 // if (trackManager.getNumTracks() == 0) return false;132 133 138 //Get current values for parameters 134 139 StyleAttribute sty = new StyleAttribute(); 135 140 boolean shapeChange = false; 136 141 137 142 138 143 if (getPres(sty.setName("clipPathUnits"))) 139 144 { 140 145 String newUnitsStrn = sty.getStringValue(); 141 146 int newUnits = newUnitsStrn.equals("objectBoundingBox") 142 ? CP_OBJECT_BOUNDING_BOX 147 ? CP_OBJECT_BOUNDING_BOX 143 148 : CP_USER_SPACE_ON_USE; 144 149 145 150 if (newUnits != clipPathUnits) 146 151 { -
trunk/src/com/kitfox/svg/Defs.java
r4256 r6002 1 1 /* 2 * Stop.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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:56 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 import java.awt.*; 31 import java.awt.geom.*; 32 import java.util.*; 33 34 import com.kitfox.svg.xml.*; 35 import org.xml.sax.*; 38 import java.util.Iterator; 36 39 37 40 /** … … 42 45 { 43 46 44 /** Creates a new instance of Stop */ 45 public Defs() { 47 public static final String TAG_NAME = "defs"; 48 49 /** 50 * Creates a new instance of Stop 51 */ 52 public Defs() 53 { 54 } 55 56 public String getTagName() 57 { 58 return TAG_NAME; 46 59 } 47 60 … … 52 65 public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException 53 66 { 54 67 super.loaderAddChild(helper, child); 55 68 56 69 // members.add(child); … … 62 75 for (Iterator it = children.iterator(); it.hasNext();) 63 76 { 64 SVGElement ele = (SVGElement) it.next();77 SVGElement ele = (SVGElement) it.next(); 65 78 stateChange = stateChange || ele.updateTime(curTime); 66 79 } 67 80 68 81 return super.updateTime(curTime) || stateChange; 69 82 } -
trunk/src/com/kitfox/svg/Desc.java
r4256 r6002 1 1 /* 2 * Stop.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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 September 19, 2004, 1:56 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 … … 34 42 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 35 43 */ 36 public class Desc extends SVGElement { 44 public class Desc extends SVGElement 45 { 37 46 47 public static final String TAG_NAME = "desc"; 38 48 StringBuffer text = new StringBuffer(); 39 49 40 /** Creates a new instance of Stop */ 41 public Desc() { 50 /** 51 * Creates a new instance of Stop 52 */ 53 public Desc() 54 { 55 } 56 57 public String getTagName() 58 { 59 return TAG_NAME; 42 60 } 43 61 … … 50 68 } 51 69 52 public String getText() { return text.toString(); } 53 70 public String getText() 71 { 72 return text.toString(); 73 } 74 54 75 public boolean updateTime(double curTime) 55 76 { -
trunk/src/com/kitfox/svg/Ellipse.java
r4256 r6002 1 1 /* 2 * Rect.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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, 5:25 PM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 import com.kitfox.svg.xml.StyleAttribute; 31 import com.kitfox.svg.xml.*; 32 import org.xml.sax.*; 33 34 import java.awt.*; 35 import java.awt.geom.*; 39 import java.awt.Graphics2D; 40 import java.awt.Shape; 41 import java.awt.geom.Ellipse2D; 42 import java.awt.geom.Rectangle2D; 36 43 37 44 /** … … 39 46 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 40 47 */ 41 public class Ellipse extends ShapeElement { 48 public class Ellipse extends ShapeElement 49 { 42 50 51 public static final String TAG_NAME = "ellipse"; 43 52 float cx = 0.0f; 44 53 float cy = 0.0f; 45 54 float rx = 0.0f; 46 55 float ry = 0.0f; 47 48 56 Ellipse2D.Float ellipse = new Ellipse2D.Float(); 49 57 50 /** Creates a new instance of Rect */ 51 public Ellipse() { 58 /** 59 * Creates a new instance of Rect 60 */ 61 public Ellipse() 62 { 52 63 } 53 /*54 protected void init(String idIn, Style parentStyle, String cx, String cy, String rx, String ry) {55 super.init(idIn, parentStyle);56 64 57 this.cx = parseDouble(cx);58 this.cy = parseDouble(cy);59 this.rx = parseDouble(rx);60 this.ry = parseDouble(ry);65 public String getTagName() 66 { 67 return TAG_NAME; 68 } 61 69 62 setBounds(this.cx - this.rx, this.cy - this.ry, this.rx * 2.0, this.ry * 2.0);63 }64 */65 /*66 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)67 {68 //Load style string69 super.loaderStartElement(helper, attrs, parent);70 71 String cx = attrs.getValue("cx");72 String cy = attrs.getValue("cy");73 String rx = attrs.getValue("rx");74 String ry = attrs.getValue("ry");75 76 this.cx = XMLParseUtil.parseDouble(cx);77 this.cy = XMLParseUtil.parseDouble(cy);78 this.rx = XMLParseUtil.parseDouble(rx);79 this.ry = XMLParseUtil.parseDouble(ry);80 81 build();82 }83 */84 85 /*86 public void loaderEndElement(SVGLoaderHelper helper)87 {88 super.loaderEndElement(helper);89 90 build();91 }92 */93 94 70 protected void build() throws SVGException 95 71 { 96 72 super.build(); 97 73 98 74 StyleAttribute sty = new StyleAttribute(); 99 100 if (getPres(sty.setName("cx"))) cx = sty.getFloatValueWithUnits(); 101 102 if (getPres(sty.setName("cy"))) cy = sty.getFloatValueWithUnits(); 103 104 if (getPres(sty.setName("rx"))) rx = sty.getFloatValueWithUnits(); 105 106 if (getPres(sty.setName("ry"))) ry = sty.getFloatValueWithUnits(); 107 75 76 if (getPres(sty.setName("cx"))) 77 { 78 cx = sty.getFloatValueWithUnits(); 79 } 80 81 if (getPres(sty.setName("cy"))) 82 { 83 cy = sty.getFloatValueWithUnits(); 84 } 85 86 if (getPres(sty.setName("rx"))) 87 { 88 rx = sty.getFloatValueWithUnits(); 89 } 90 91 if (getPres(sty.setName("ry"))) 92 { 93 ry = sty.getFloatValueWithUnits(); 94 } 95 108 96 ellipse.setFrame(cx - rx, cy - ry, rx * 2f, ry * 2f); 109 97 } … … 125 113 return boundsToParent(includeStrokeInBounds(ellipse.getBounds2D())); 126 114 } 127 115 128 116 /** 129 * Updates all attributes in this diagram associated with a time event. 130 * Ie, all attributes with track information. 117 * Updates all attributes in this diagram associated with a time event. Ie, 118 * all attributes with track information. 119 * 131 120 * @return - true if this node has changed state as a result of the time 132 121 * update … … 140 129 StyleAttribute sty = new StyleAttribute(); 141 130 boolean shapeChange = false; 142 131 143 132 if (getPres(sty.setName("cx"))) 144 133 { … … 150 139 } 151 140 } 152 141 153 142 if (getPres(sty.setName("cy"))) 154 143 { … … 160 149 } 161 150 } 162 151 163 152 if (getPres(sty.setName("rx"))) 164 153 { … … 170 159 } 171 160 } 172 161 173 162 if (getPres(sty.setName("ry"))) 174 163 { … … 180 169 } 181 170 } 182 171 183 172 if (shapeChange) 184 173 { … … 187 176 // return true; 188 177 } 189 178 190 179 return changeState || shapeChange; 191 180 } -
trunk/src/com/kitfox/svg/FeDistantLight.java
r4256 r6002 1 1 /* 2 * FillElement.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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 March 18, 2004, 6:52 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 import com.kitfox.svg.xml.StyleAttribute; 31 import java.awt.*;32 import java.awt.geom.*;33 import java.net.*;34 import java.util.*;35 36 import com.kitfox.svg.xml.*;37 import org.xml.sax.*;38 39 39 40 /** … … 41 42 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 42 43 */ 43 public class FeDistantLight extends FeLight 44 public class FeDistantLight extends FeLight 44 45 { 46 47 public static final String TAG_NAME = "fedistantlight"; 45 48 float azimuth = 0f; 46 49 float elevation = 0f; 47 48 50 49 /** Creates a new instance of FillElement */ 50 public FeDistantLight() { 51 /** 52 * Creates a new instance of FillElement 53 */ 54 public FeDistantLight() 55 { 51 56 } 52 57 53 58 public String getTagName() 59 { 60 return TAG_NAME; 61 } 62 54 63 protected void build() throws SVGException 55 64 { 56 65 super.build(); 57 66 58 67 StyleAttribute sty = new StyleAttribute(); 59 68 String strn; 60 61 if (getPres(sty.setName("azimuth"))) azimuth = sty.getFloatValueWithUnits(); 62 63 if (getPres(sty.setName("elevation"))) elevation = sty.getFloatValueWithUnits(); 69 70 if (getPres(sty.setName("azimuth"))) 71 { 72 azimuth = sty.getFloatValueWithUnits(); 73 } 74 75 if (getPres(sty.setName("elevation"))) 76 { 77 elevation = sty.getFloatValueWithUnits(); 78 } 64 79 } 65 80 66 public float getAzimuth() { return azimuth; } 67 public float getElevation() { return elevation; } 68 81 public float getAzimuth() 82 { 83 return azimuth; 84 } 85 86 public float getElevation() 87 { 88 return elevation; 89 } 90 69 91 public boolean updateTime(double curTime) throws SVGException 70 92 { … … 74 96 StyleAttribute sty = new StyleAttribute(); 75 97 boolean stateChange = false; 76 98 77 99 if (getPres(sty.setName("azimuth"))) 78 100 { … … 84 106 } 85 107 } 86 108 87 109 if (getPres(sty.setName("elevation"))) 88 110 { … … 94 116 } 95 117 } 96 118 97 119 return stateChange; 98 120 } 99 121 } 100 -
trunk/src/com/kitfox/svg/FeLight.java
r4256 r6002 1 1 /* 2 * FillElement.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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 March 18, 2004, 6:52 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 30 import java.awt.*;31 import java.awt.geom.*;32 import java.net.*;33 import java.util.*;34 35 import com.kitfox.svg.xml.*;36 import org.xml.sax.*;37 37 38 38 /** … … 40 40 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 41 41 */ 42 abstract public class FeLight extends FilterEffects 42 abstract public class FeLight extends FilterEffects 43 43 { 44 44 45 /** Creates a new instance of FillElement */ 46 public FeLight() { 45 public static final String TAG_NAME = "feLight"; 46 47 /** 48 * Creates a new instance of FillElement 49 */ 50 public FeLight() 51 { 47 52 } 48 53 54 public String getTagName() 55 { 56 return TAG_NAME; 57 } 49 58 } 50 -
trunk/src/com/kitfox/svg/FePointLight.java
r4256 r6002 1 1 /* 2 * FillElement.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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 March 18, 2004, 6:52 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 import com.kitfox.svg.xml.StyleAttribute; 31 import java.awt.*;32 import java.awt.geom.*;33 import java.net.*;34 import java.util.*;35 36 import com.kitfox.svg.xml.*;37 import org.xml.sax.*;38 39 39 40 /** … … 41 42 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 42 43 */ 43 public class FePointLight extends FeLight 44 public class FePointLight extends FeLight 44 45 { 46 47 public static final String TAG_NAME = "fepointlight"; 45 48 float x = 0f; 46 49 float y = 0f; 47 50 float z = 0f; 48 49 51 50 /** Creates a new instance of FillElement */ 51 public FePointLight() { 52 /** 53 * Creates a new instance of FillElement 54 */ 55 public FePointLight() 56 { 52 57 } 53 58 54 59 public String getTagName() 60 { 61 return TAG_NAME; 62 } 63 55 64 protected void build() throws SVGException 56 65 { 57 66 super.build(); 58 67 59 68 StyleAttribute sty = new StyleAttribute(); 60 69 String strn; 61 62 if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits(); 63 64 if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits(); 65 66 if (getPres(sty.setName("z"))) z = sty.getFloatValueWithUnits(); 70 71 if (getPres(sty.setName("x"))) 72 { 73 x = sty.getFloatValueWithUnits(); 74 } 75 76 if (getPres(sty.setName("y"))) 77 { 78 y = sty.getFloatValueWithUnits(); 79 } 80 81 if (getPres(sty.setName("z"))) 82 { 83 z = sty.getFloatValueWithUnits(); 84 } 67 85 } 68 86 69 public float getX() { return x; } 70 public float getY() { return y; } 71 public float getZ() { return z; } 72 87 public float getX() 88 { 89 return x; 90 } 91 92 public float getY() 93 { 94 return y; 95 } 96 97 public float getZ() 98 { 99 return z; 100 } 101 73 102 public boolean updateTime(double curTime) throws SVGException 74 103 { … … 78 107 StyleAttribute sty = new StyleAttribute(); 79 108 boolean stateChange = false; 80 109 81 110 if (getPres(sty.setName("x"))) 82 111 { … … 88 117 } 89 118 } 90 119 91 120 if (getPres(sty.setName("y"))) 92 121 { … … 98 127 } 99 128 } 100 129 101 130 if (getPres(sty.setName("z"))) 102 131 { … … 108 137 } 109 138 } 110 139 111 140 return stateChange; 112 141 } 113 142 } 114 -
trunk/src/com/kitfox/svg/FeSpotLight.java
r4256 r6002 1 1 /* 2 * FillElement.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 March 18, 2004, 6:52 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 import com.kitfox.svg.xml.StyleAttribute; 31 import java.awt.*;32 import java.awt.geom.*;33 import java.net.*;34 import java.util.*;35 36 import com.kitfox.svg.xml.*;37 import org.xml.sax.*;38 39 39 40 /** … … 41 42 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 42 43 */ 43 public class FeSpotLight extends FeLight 44 public class FeSpotLight extends FeLight 44 45 { 46 47 public static final String TAG_NAME = "fespotlight"; 45 48 float x = 0f; 46 49 float y = 0f; … … 51 54 float specularComponent = 0f; 52 55 float limitingConeAngle = 0f; 53 54 55 /** Creates a new instance of FillElement */ 56 public FeSpotLight() { 57 } 58 59 56 57 /** 58 * Creates a new instance of FillElement 59 */ 60 public FeSpotLight() 61 { 62 } 63 64 public String getTagName() 65 { 66 return TAG_NAME; 67 } 68 60 69 protected void build() throws SVGException 61 70 { 62 71 super.build(); 63 72 64 73 StyleAttribute sty = new StyleAttribute(); 65 74 String strn; 66 67 if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits(); 68 if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits(); 69 if (getPres(sty.setName("z"))) z = sty.getFloatValueWithUnits(); 70 if (getPres(sty.setName("pointsAtX"))) pointsAtX = sty.getFloatValueWithUnits(); 71 if (getPres(sty.setName("pointsAtY"))) pointsAtY = sty.getFloatValueWithUnits(); 72 if (getPres(sty.setName("pointsAtZ"))) pointsAtZ = sty.getFloatValueWithUnits(); 73 if (getPres(sty.setName("specularComponent"))) specularComponent = sty.getFloatValueWithUnits(); 74 if (getPres(sty.setName("limitingConeAngle"))) limitingConeAngle = sty.getFloatValueWithUnits(); 75 } 76 77 public float getX() { return x; } 78 public float getY() { return y; } 79 public float getZ() { return z; } 80 public float getPointsAtX() { return pointsAtX; } 81 public float getPointsAtY() { return pointsAtY; } 82 public float getPointsAtZ() { return pointsAtZ; } 83 public float getSpecularComponent() { return specularComponent; } 84 public float getLimitingConeAngle() { return limitingConeAngle; } 85 75 76 if (getPres(sty.setName("x"))) 77 { 78 x = sty.getFloatValueWithUnits(); 79 } 80 if (getPres(sty.setName("y"))) 81 { 82 y = sty.getFloatValueWithUnits(); 83 } 84 if (getPres(sty.setName("z"))) 85 { 86 z = sty.getFloatValueWithUnits(); 87 } 88 if (getPres(sty.setName("pointsAtX"))) 89 { 90 pointsAtX = sty.getFloatValueWithUnits(); 91 } 92 if (getPres(sty.setName("pointsAtY"))) 93 { 94 pointsAtY = sty.getFloatValueWithUnits(); 95 } 96 if (getPres(sty.setName("pointsAtZ"))) 97 { 98 pointsAtZ = sty.getFloatValueWithUnits(); 99 } 100 if (getPres(sty.setName("specularComponent"))) 101 { 102 specularComponent = sty.getFloatValueWithUnits(); 103 } 104 if (getPres(sty.setName("limitingConeAngle"))) 105 { 106 limitingConeAngle = sty.getFloatValueWithUnits(); 107 } 108 } 109 110 public float getX() 111 { 112 return x; 113 } 114 115 public float getY() 116 { 117 return y; 118 } 119 120 public float getZ() 121 { 122 return z; 123 } 124 125 public float getPointsAtX() 126 { 127 return pointsAtX; 128 } 129 130 public float getPointsAtY() 131 { 132 return pointsAtY; 133 } 134 135 public float getPointsAtZ() 136 { 137 return pointsAtZ; 138 } 139 140 public float getSpecularComponent() 141 { 142 return specularComponent; 143 } 144 145 public float getLimitingConeAngle() 146 { 147 return limitingConeAngle; 148 } 149 86 150 public boolean updateTime(double curTime) throws SVGException 87 151 { … … 91 155 StyleAttribute sty = new StyleAttribute(); 92 156 boolean stateChange = false; 93 157 94 158 if (getPres(sty.setName("x"))) 95 159 { … … 101 165 } 102 166 } 103 167 104 168 if (getPres(sty.setName("y"))) 105 169 { … … 111 175 } 112 176 } 113 177 114 178 if (getPres(sty.setName("z"))) 115 179 { … … 121 185 } 122 186 } 123 187 124 188 if (getPres(sty.setName("pointsAtX"))) 125 189 { … … 131 195 } 132 196 } 133 197 134 198 if (getPres(sty.setName("pointsAtY"))) 135 199 { … … 141 205 } 142 206 } 143 207 144 208 if (getPres(sty.setName("pointsAtZ"))) 145 209 { … … 151 215 } 152 216 } 153 217 154 218 if (getPres(sty.setName("specularComponent"))) 155 219 { … … 161 225 } 162 226 } 163 227 164 228 if (getPres(sty.setName("limitingConeAngle"))) 165 229 { … … 171 235 } 172 236 } 173 237 174 238 return stateChange; 175 239 } 176 240 } 177 -
trunk/src/com/kitfox/svg/FillElement.java
r4256 r6002 1 1 /* 2 * FillElement.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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 March 18, 2004, 6:52 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 … … 35 43 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 36 44 */ 37 abstract public class FillElement extends SVGElement { 38 39 /** Creates a new instance of FillElement */ 40 public FillElement() { 45 abstract public class FillElement extends SVGElement 46 { 47 /** 48 * Creates a new instance of FillElement 49 */ 50 public FillElement() 51 { 41 52 } 42 53 43 54 /** 44 * Requests the paint defined by this element. Passes in information 45 * to allow paint to be customized 55 * Requests the paint defined by this element. Passes in information to 56 * allow paint to be customized 57 * 46 58 * @param bounds - bounding box of shape being rendered 47 * @param xform - The current transformation that the shape is being rendered48 * under.59 * @param xform - The current transformation that the shape is being 60 * rendered under. 49 61 */ 50 62 abstract public Paint getPaint(Rectangle2D bounds, AffineTransform xform); -
trunk/src/com/kitfox/svg/Filter.java
r4256 r6002 1 1 /* 2 * FillElement.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 March 18, 2004, 6:52 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 import java.awt.geom.*;31 import java. net.*;32 import java. util.*;33 34 import com.kitfox.svg.xml.*;38 import com.kitfox.svg.xml.StyleAttribute; 39 import java.awt.geom.Point2D; 40 import java.net.URI; 41 import java.net.URL; 42 import java.util.ArrayList; 35 43 36 44 /** … … 38 46 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 39 47 */ 40 public class Filter extends SVGElement 48 public class Filter extends SVGElement 41 49 { 50 51 public static final String TAG_NAME = "filter"; 42 52 public static final int FU_OBJECT_BOUNDING_BOX = 0; 43 53 public static final int FU_USER_SPACE_ON_USE = 1; 44 45 54 protected int filterUnits = FU_OBJECT_BOUNDING_BOX; 46 47 55 public static final int PU_OBJECT_BOUNDING_BOX = 0; 48 56 public static final int PU_USER_SPACE_ON_USE = 1; 49 50 57 protected int primitiveUnits = PU_OBJECT_BOUNDING_BOX; 51 52 58 float x = 0f; 53 59 float y = 0f; 54 60 float width = 1f; 55 61 float height = 1f; 56 57 62 Point2D filterRes = new Point2D.Double(); 58 59 63 URL href = null; 60 61 64 final ArrayList filterEffects = new ArrayList(); 62 65 63 /** Creates a new instance of FillElement */ 64 public Filter() { 66 /** 67 * Creates a new instance of FillElement 68 */ 69 public Filter() 70 { 71 } 72 73 public String getTagName() 74 { 75 return TAG_NAME; 65 76 } 66 77 … … 78 89 } 79 90 } 80 91 81 92 protected void build() throws SVGException 82 93 { 83 94 super.build(); 84 95 85 96 StyleAttribute sty = new StyleAttribute(); 86 97 String strn; 87 98 88 99 if (getPres(sty.setName("filterUnits"))) 89 100 { 90 101 strn = sty.getStringValue().toLowerCase(); 91 if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE; 92 else filterUnits = FU_OBJECT_BOUNDING_BOX; 102 if (strn.equals("userspaceonuse")) 103 { 104 filterUnits = FU_USER_SPACE_ON_USE; 105 } else 106 { 107 filterUnits = FU_OBJECT_BOUNDING_BOX; 108 } 93 109 } 94 110 … … 96 112 { 97 113 strn = sty.getStringValue().toLowerCase(); 98 if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE; 99 else primitiveUnits = PU_OBJECT_BOUNDING_BOX; 100 } 101 102 if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits(); 103 104 if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits(); 105 106 if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits(); 107 108 if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits(); 109 110 try { 114 if (strn.equals("userspaceonuse")) 115 { 116 primitiveUnits = PU_USER_SPACE_ON_USE; 117 } else 118 { 119 primitiveUnits = PU_OBJECT_BOUNDING_BOX; 120 } 121 } 122 123 if (getPres(sty.setName("x"))) 124 { 125 x = sty.getFloatValueWithUnits(); 126 } 127 128 if (getPres(sty.setName("y"))) 129 { 130 y = sty.getFloatValueWithUnits(); 131 } 132 133 if (getPres(sty.setName("width"))) 134 { 135 width = sty.getFloatValueWithUnits(); 136 } 137 138 if (getPres(sty.setName("height"))) 139 { 140 height = sty.getFloatValueWithUnits(); 141 } 142 143 try 144 { 111 145 if (getPres(sty.setName("xlink:href"))) 112 146 { … … 114 148 href = src.toURL(); 115 149 } 116 } 117 catch (Exception e) 150 } catch (Exception e) 118 151 { 119 152 throw new SVGException(e); … … 122 155 } 123 156 124 public float getX() { return x; } 125 public float getY() { return y; } 126 public float getWidth() { return width; } 127 public float getHeight() { return height; } 128 157 public float getX() 158 { 159 return x; 160 } 161 162 public float getY() 163 { 164 return y; 165 } 166 167 public float getWidth() 168 { 169 return width; 170 } 171 172 public float getHeight() 173 { 174 return height; 175 } 176 129 177 public boolean updateTime(double curTime) throws SVGException 130 178 { … … 134 182 StyleAttribute sty = new StyleAttribute(); 135 183 boolean stateChange = false; 136 184 137 185 if (getPres(sty.setName("x"))) 138 186 { … … 144 192 } 145 193 } 146 194 147 195 if (getPres(sty.setName("y"))) 148 196 { … … 154 202 } 155 203 } 156 204 157 205 if (getPres(sty.setName("width"))) 158 206 { … … 164 212 } 165 213 } 166 214 167 215 if (getPres(sty.setName("height"))) 168 216 { … … 174 222 } 175 223 } 176 177 try { 224 225 try 226 { 178 227 if (getPres(sty.setName("xlink:href"))) 179 228 { 180 229 URI src = sty.getURIValue(getXMLBase()); 181 230 URL newVal = src.toURL(); 182 231 183 232 if (!newVal.equals(href)) 184 233 { … … 187 236 } 188 237 } 189 } 190 catch (Exception e) 238 } catch (Exception e) 191 239 { 192 240 throw new SVGException(e); … … 197 245 int newVal; 198 246 String strn = sty.getStringValue().toLowerCase(); 199 if (strn.equals("userspaceonuse")) newVal = FU_USER_SPACE_ON_USE; 200 else newVal = FU_OBJECT_BOUNDING_BOX; 247 if (strn.equals("userspaceonuse")) 248 { 249 newVal = FU_USER_SPACE_ON_USE; 250 } else 251 { 252 newVal = FU_OBJECT_BOUNDING_BOX; 253 } 201 254 if (newVal != filterUnits) 202 255 { … … 210 263 int newVal; 211 264 String strn = sty.getStringValue().toLowerCase(); 212 if (strn.equals("userspaceonuse")) newVal = PU_USER_SPACE_ON_USE; 213 else newVal = PU_OBJECT_BOUNDING_BOX; 265 if (strn.equals("userspaceonuse")) 266 { 267 newVal = PU_USER_SPACE_ON_USE; 268 } else 269 { 270 newVal = PU_OBJECT_BOUNDING_BOX; 271 } 214 272 if (newVal != filterUnits) 215 273 { … … 219 277 } 220 278 221 222 279 280 223 281 return stateChange; 224 282 } 225 283 } 226 -
trunk/src/com/kitfox/svg/FilterEffects.java
r4256 r6002 1 1 /* 2 * FillElement.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 March 18, 2004, 6:52 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 import com.kitfox.svg.xml.StyleAttribute; 31 import java.awt.*; 32 import java.awt.geom.*; 33 import java.net.*; 34 import java.util.*; 35 36 import com.kitfox.svg.xml.*; 37 import org.xml.sax.*; 39 import java.net.URI; 40 import java.net.URL; 38 41 39 42 /** … … 41 44 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 42 45 */ 43 public class FilterEffects extends SVGElement 46 public class FilterEffects extends SVGElement 44 47 { 48 public static final String TAG_NAME = "filtereffects"; 49 45 50 public static final int FP_SOURCE_GRAPHIC = 0; 46 51 public static final int FP_SOURCE_ALPHA = 1; … … 50 55 public static final int FP_STROKE_PAINT = 5; 51 56 public static final int FP_CUSTOM = 5; 52 53 57 private int filterPrimitiveTypeIn; 54 58 private String filterPrimitiveRefIn; 55 56 57 59 float x = 0f; 58 60 float y = 0f; 59 61 float width = 1f; 60 62 float height = 1f; 61 62 63 String result = "defaultFilterName"; 63 64 65 66 64 URL href = null; 67 65 68 69 /** Creates a new instance of FillElement */ 70 public FilterEffects() { 66 /** 67 * Creates a new instance of FillElement 68 */ 69 public FilterEffects() 70 { 71 } 72 73 public String getTagName() 74 { 75 return TAG_NAME; 71 76 } 72 77 … … 84 89 } 85 90 } 86 91 87 92 protected void build() throws SVGException 88 93 { 89 94 super.build(); 90 95 91 96 StyleAttribute sty = new StyleAttribute(); 92 97 String strn; 93 98 /* 94 if (getPres(sty.setName("filterUnits"))) 95 { 96 strn = sty.getStringValue().toLowerCase(); 97 if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE; 98 else filterUnits = FU_OBJECT_BOUNDING_BOX; 99 } 100 101 if (getPres(sty.setName("primitiveUnits"))) 102 { 103 strn = sty.getStringValue().toLowerCase(); 104 if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE; 105 else primitiveUnits = PU_OBJECT_BOUNDING_BOX; 106 } 107 108 if (getPres(sty.setName("x"))) x = sty.getFloatValue(); 109 110 if (getPres(sty.setName("y"))) y = sty.getFloatValue(); 111 112 if (getPres(sty.setName("width"))) width = sty.getFloatValue(); 113 114 if (getPres(sty.setName("height"))) height = sty.getFloatValue(); 115 116 try { 117 if (getPres(sty.setName("xlink:href"))) 118 { 119 URI src = sty.getURIValue(getXMLBase()); 120 href = src.toURL(); 121 } 122 } 123 catch (Exception e) 124 { 125 throw new SVGException(e); 126 } 127 */ 128 } 129 130 public float getX() { return x; } 131 public float getY() { return y; } 132 public float getWidth() { return width; } 133 public float getHeight() { return height; } 134 99 if (getPres(sty.setName("filterUnits"))) 100 { 101 strn = sty.getStringValue().toLowerCase(); 102 if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE; 103 else filterUnits = FU_OBJECT_BOUNDING_BOX; 104 } 105 106 if (getPres(sty.setName("primitiveUnits"))) 107 { 108 strn = sty.getStringValue().toLowerCase(); 109 if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE; 110 else primitiveUnits = PU_OBJECT_BOUNDING_BOX; 111 } 112 113 if (getPres(sty.setName("x"))) x = sty.getFloatValue(); 114 115 if (getPres(sty.setName("y"))) y = sty.getFloatValue(); 116 117 if (getPres(sty.setName("width"))) width = sty.getFloatValue(); 118 119 if (getPres(sty.setName("height"))) height = sty.getFloatValue(); 120 121 try { 122 if (getPres(sty.setName("xlink:href"))) 123 { 124 URI src = sty.getURIValue(getXMLBase()); 125 href = src.toURL(); 126 } 127 } 128 catch (Exception e) 129 { 130 throw new SVGException(e); 131 } 132 */ 133 } 134 135 public float getX() 136 { 137 return x; 138 } 139 140 public float getY() 141 { 142 return y; 143 } 144 145 public float getWidth() 146 { 147 return width; 148 } 149 150 public float getHeight() 151 { 152 return height; 153 } 154 135 155 public boolean updateTime(double curTime) throws SVGException 136 156 { … … 140 160 StyleAttribute sty = new StyleAttribute(); 141 161 boolean stateChange = false; 142 162 143 163 if (getPres(sty.setName("x"))) 144 164 { … … 150 170 } 151 171 } 152 172 153 173 if (getPres(sty.setName("y"))) 154 174 { … … 160 180 } 161 181 } 162 182 163 183 if (getPres(sty.setName("width"))) 164 184 { … … 170 190 } 171 191 } 172 192 173 193 if (getPres(sty.setName("height"))) 174 194 { … … 180 200 } 181 201 } 182 183 try { 202 203 try 204 { 184 205 if (getPres(sty.setName("xlink:href"))) 185 206 { 186 207 URI src = sty.getURIValue(getXMLBase()); 187 208 URL newVal = src.toURL(); 188 209 189 210 if (!newVal.equals(href)) 190 211 { … … 193 214 } 194 215 } 195 } 196 catch (Exception e) 216 } catch (Exception e) 197 217 { 198 218 throw new SVGException(e); … … 200 220 201 221 /* 202 if (getPres(sty.setName("filterUnits")))203 {204 205 206 207 208 209 210 211 212 213 }214 215 if (getPres(sty.setName("primitiveUnits")))216 {217 218 219 220 221 222 223 224 225 226 }227 228 */229 222 if (getPres(sty.setName("filterUnits"))) 223 { 224 int newVal; 225 String strn = sty.getStringValue().toLowerCase(); 226 if (strn.equals("userspaceonuse")) newVal = FU_USER_SPACE_ON_USE; 227 else newVal = FU_OBJECT_BOUNDING_BOX; 228 if (newVal != filterUnits) 229 { 230 filterUnits = newVal; 231 stateChange = true; 232 } 233 } 234 235 if (getPres(sty.setName("primitiveUnits"))) 236 { 237 int newVal; 238 String strn = sty.getStringValue().toLowerCase(); 239 if (strn.equals("userspaceonuse")) newVal = PU_USER_SPACE_ON_USE; 240 else newVal = PU_OBJECT_BOUNDING_BOX; 241 if (newVal != filterUnits) 242 { 243 primitiveUnits = newVal; 244 stateChange = true; 245 } 246 } 247 248 */ 249 230 250 return stateChange; 231 251 } 232 252 } 233 -
trunk/src/com/kitfox/svg/Font.java
r4256 r6002 1 1 /* 2 * Font.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 February 20, 2004, 10:00 PM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 import com.kitfox.svg.xml.StyleAttribute; 31 import com.kitfox.svg.xml.*; 32 import org.xml.sax.*; 33 34 import java.util.*; 39 import java.util.HashMap; 35 40 36 41 /** … … 44 49 public class Font extends SVGElement 45 50 { 51 52 public static final String TAG_NAME = "font"; 46 53 int horizOriginX = 0; 47 54 int horizOriginY = 0; … … 50 57 int vertOriginY = -1; //Defaults to font's ascent 51 58 int vertAdvY = -1; //Defaults to one 'em'. See font-face 52 53 59 FontFace fontFace = null; 54 60 MissingGlyph missingGlyph = null; 55 61 final HashMap glyphs = new HashMap(); 56 62 57 /** Creates a new instance of Font */ 63 /** 64 * Creates a new instance of Font 65 */ 58 66 public Font() 59 67 { 60 68 } 61 /* 62 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 63 { 64 //Load style string 65 super.loaderStartElement(helper, attrs, parent); 66 67 String horizOriginX = attrs.getValue("horiz-origin-x"); 68 String horizOriginY = attrs.getValue("horiz-origin-y"); 69 String horizAdvX = attrs.getValue("horiz-adv-x"); 70 String vertOriginX = attrs.getValue("vert-origin-x"); 71 String vertOriginY = attrs.getValue("vert-origin-y"); 72 String vertAdvY = attrs.getValue("vert-adv-y"); 73 74 if (horizOriginX != null) this.horizOriginX = XMLParseUtil.parseInt(horizOriginX); 75 if (horizOriginY != null) this.horizOriginY = XMLParseUtil.parseInt(horizOriginY); 76 if (horizAdvX != null) this.horizAdvX = XMLParseUtil.parseInt(horizAdvX); 77 if (vertOriginX != null) this.vertOriginX = XMLParseUtil.parseInt(vertOriginX); 78 if (vertOriginY != null) this.vertOriginY = XMLParseUtil.parseInt(vertOriginY); 79 if (vertAdvY != null) this.vertAdvY = XMLParseUtil.parseInt(vertAdvY); 80 81 } 82 */ 69 70 public String getTagName() 71 { 72 return TAG_NAME; 73 } 74 83 75 /** 84 76 * Called after the start element but before the end element to indicate … … 87 79 public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException 88 80 { 89 81 super.loaderAddChild(helper, child); 90 82 91 83 if (child instanceof Glyph) 92 84 { 93 glyphs.put(((Glyph)child).getUnicode(), child); 94 } 95 else if (child instanceof MissingGlyph) 96 { 97 missingGlyph = (MissingGlyph)child; 98 } 99 else if (child instanceof FontFace) 100 { 101 fontFace = (FontFace)child; 85 glyphs.put(((Glyph) child).getUnicode(), child); 86 } else if (child instanceof MissingGlyph) 87 { 88 missingGlyph = (MissingGlyph) child; 89 } else if (child instanceof FontFace) 90 { 91 fontFace = (FontFace) child; 102 92 } 103 93 } … … 108 98 109 99 //build(); 110 100 111 101 helper.universe.registerFont(this); 112 102 } 113 103 114 104 protected void build() throws SVGException 115 105 { 116 106 super.build(); 117 107 118 108 StyleAttribute sty = new StyleAttribute(); 119 120 if (getPres(sty.setName("horiz-origin-x"))) horizOriginX = sty.getIntValue(); 121 122 if (getPres(sty.setName("horiz-origin-y"))) horizOriginY = sty.getIntValue(); 123 124 if (getPres(sty.setName("horiz-adv-x"))) horizAdvX = sty.getIntValue(); 125 126 if (getPres(sty.setName("vert-origin-x"))) vertOriginX = sty.getIntValue(); 127 128 if (getPres(sty.setName("vert-origin-y"))) vertOriginY = sty.getIntValue(); 129 130 if (getPres(sty.setName("vert-adv-y"))) vertAdvY = sty.getIntValue(); 131 } 132 133 public FontFace getFontFace() { return fontFace; } 109 110 if (getPres(sty.setName("horiz-origin-x"))) 111 { 112 horizOriginX = sty.getIntValue(); 113 } 114 115 if (getPres(sty.setName("horiz-origin-y"))) 116 { 117 horizOriginY = sty.getIntValue(); 118 } 119 120 if (getPres(sty.setName("horiz-adv-x"))) 121 { 122 horizAdvX = sty.getIntValue(); 123 } 124 125 if (getPres(sty.setName("vert-origin-x"))) 126 { 127 vertOriginX = sty.getIntValue(); 128 } 129 130 if (getPres(sty.setName("vert-origin-y"))) 131 { 132 vertOriginY = sty.getIntValue(); 133 } 134 135 if (getPres(sty.setName("vert-adv-y"))) 136 { 137 vertAdvY = sty.getIntValue(); 138 } 139 } 140 141 public FontFace getFontFace() 142 { 143 return fontFace; 144 } 134 145 135 146 public MissingGlyph getGlyph(String unicode) 136 147 { 137 Glyph retVal = (Glyph)glyphs.get(unicode); 138 if (retVal == null) return missingGlyph; 148 Glyph retVal = (Glyph) glyphs.get(unicode); 149 if (retVal == null) 150 { 151 return missingGlyph; 152 } 139 153 return retVal; 140 154 } 141 155 142 public int getHorizOriginX() { return horizOriginX; } 143 public int getHorizOriginY() { return horizOriginY; } 144 public int getHorizAdvX() { return horizAdvX; } 156 public int getHorizOriginX() 157 { 158 return horizOriginX; 159 } 160 161 public int getHorizOriginY() 162 { 163 return horizOriginY; 164 } 165 166 public int getHorizAdvX() 167 { 168 return horizAdvX; 169 } 145 170 146 171 public int getVertOriginX() 147 172 { 148 if (vertOriginX != -1) return vertOriginX; 173 if (vertOriginX != -1) 174 { 175 return vertOriginX; 176 } 149 177 vertOriginX = getHorizAdvX() / 2; 150 178 return vertOriginX; … … 153 181 public int getVertOriginY() 154 182 { 155 if (vertOriginY != -1) return vertOriginY; 183 if (vertOriginY != -1) 184 { 185 return vertOriginY; 186 } 156 187 vertOriginY = fontFace.getAscent(); 157 188 return vertOriginY; … … 160 191 public int getVertAdvY() 161 192 { 162 if (vertAdvY != -1) return vertAdvY; 193 if (vertAdvY != -1) 194 { 195 return vertAdvY; 196 } 163 197 vertAdvY = fontFace.getUnitsPerEm(); 164 198 return vertAdvY; 165 199 } 166 200 167 201 /** 168 * Updates all attributes in this diagram associated with a time event. 169 * Ie, all attributes with track information. 202 * Updates all attributes in this diagram associated with a time event. Ie, 203 * all attributes with track information. 204 * 170 205 * @return - true if this node has changed state as a result of the time 171 206 * update … … 176 211 return false; 177 212 /* 178 if (trackManager.getNumTracks() == 0) return false;179 180 //Get current values for parameters181 StyleAttribute sty = new StyleAttribute();182 boolean stateChange = false;183 184 if (getPres(sty.setName("horiz-origin-x")))185 {186 187 188 189 190 191 192 }193 194 if (getPres(sty.setName("horiz-origin-y")))195 {196 197 198 199 200 201 202 }203 204 if (getPres(sty.setName("horiz-adv-x")))205 {206 207 208 209 210 211 212 }213 214 if (getPres(sty.setName("vert-origin-x")))215 {216 217 218 219 220 221 222 }223 224 if (getPres(sty.setName("vert-origin-y")))225 {226 227 228 229 230 231 232 }233 234 if (getPres(sty.setName("vert-adv-y")))235 {236 237 238 239 240 241 242 }243 244 return shapeChange;245 */213 if (trackManager.getNumTracks() == 0) return false; 214 215 //Get current values for parameters 216 StyleAttribute sty = new StyleAttribute(); 217 boolean stateChange = false; 218 219 if (getPres(sty.setName("horiz-origin-x"))) 220 { 221 int newVal = sty.getIntValue(); 222 if (newVal != horizOriginX) 223 { 224 horizOriginX = newVal; 225 stateChange = true; 226 } 227 } 228 229 if (getPres(sty.setName("horiz-origin-y"))) 230 { 231 int newVal = sty.getIntValue(); 232 if (newVal != horizOriginY) 233 { 234 horizOriginY = newVal; 235 stateChange = true; 236 } 237 } 238 239 if (getPres(sty.setName("horiz-adv-x"))) 240 { 241 int newVal = sty.getIntValue(); 242 if (newVal != horizAdvX) 243 { 244 horizAdvX = newVal; 245 stateChange = true; 246 } 247 } 248 249 if (getPres(sty.setName("vert-origin-x"))) 250 { 251 int newVal = sty.getIntValue(); 252 if (newVal != vertOriginX) 253 { 254 vertOriginX = newVal; 255 stateChange = true; 256 } 257 } 258 259 if (getPres(sty.setName("vert-origin-y"))) 260 { 261 int newVal = sty.getIntValue(); 262 if (newVal != vertOriginY) 263 { 264 vertOriginY = newVal; 265 stateChange = true; 266 } 267 } 268 269 if (getPres(sty.setName("vert-adv-y"))) 270 { 271 int newVal = sty.getIntValue(); 272 if (newVal != vertAdvY) 273 { 274 vertAdvY = newVal; 275 stateChange = true; 276 } 277 } 278 279 return shapeChange; 280 */ 246 281 } 247 282 } -
trunk/src/com/kitfox/svg/FontFace.java
r4256 r6002 1 1 /* 2 * Font.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 February 20, 2004, 10:00 PM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 import com.kitfox.svg.xml.StyleAttribute; 31 import com.kitfox.svg.xml.*;32 import org.xml.sax.*;33 34 import java.awt.geom.*;35 import java.awt.*;36 37 39 38 40 /** … … 46 48 public class FontFace extends SVGElement 47 49 { 50 51 public static final String TAG_NAME = "fontface"; 48 52 String fontFamily; 49 50 /** Em size of coordinate system font is defined in */ 53 /** 54 * Em size of coordinate system font is defined in 55 */ 51 56 int unitsPerEm = 1000; 52 53 57 int ascent = -1; 54 58 int descent = -1; 55 59 int accentHeight = -1; 56 57 60 int underlinePosition = -1; 58 61 int underlineThickness = -1; … … 62 65 int overlineThickness = -1; 63 66 64 /** Creates a new instance of Font */ 67 /** 68 * Creates a new instance of Font 69 */ 65 70 public FontFace() 66 71 { 67 72 } 68 /* 69 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 70 { 71 //Load style string 72 super.loaderStartElement(helper, attrs, parent); 73 74 fontFamily = attrs.getValue("font-family"); 75 76 String unitsPerEm = attrs.getValue("units-per-em"); 77 String ascent = attrs.getValue("ascent"); 78 String descent = attrs.getValue("descent"); 79 String accentHeight = attrs.getValue("accent-height"); 80 81 String underlinePosition = attrs.getValue("underline-position"); 82 String underlineThickness = attrs.getValue("underline-thickness"); 83 String strikethroughPosition = attrs.getValue("strikethrough-position"); 84 String strikethroughThickness = attrs.getValue("strikethrough-thickness"); 85 String overlinePosition = attrs.getValue("overline-position"); 86 String overlineThickness = attrs.getValue("overline-thickness"); 87 88 89 if (unitsPerEm != null) this.unitsPerEm = XMLParseUtil.parseInt(unitsPerEm); 90 if (ascent != null) this.ascent = XMLParseUtil.parseInt(ascent); 91 if (descent != null) this.descent = XMLParseUtil.parseInt(descent); 92 if (accentHeight != null) this.accentHeight = XMLParseUtil.parseInt(accentHeight); 93 94 if (underlinePosition != null) this.underlinePosition = XMLParseUtil.parseInt(underlinePosition); 95 if (underlineThickness != null) this.underlineThickness = XMLParseUtil.parseInt(underlineThickness); 96 if (strikethroughPosition != null) this.strikethroughPosition = XMLParseUtil.parseInt(strikethroughPosition); 97 if (strikethroughThickness != null) this.strikethroughThickness = XMLParseUtil.parseInt(strikethroughThickness); 98 if (overlinePosition != null) this.overlinePosition = XMLParseUtil.parseInt(overlinePosition); 99 if (overlineThickness != null) this.overlineThickness = XMLParseUtil.parseInt(overlineThickness); 100 101 // unitFontXform.setToScale(1.0 / (double)unitsPerEm, 1.0 / (double)unitsPerEm); 102 } 103 */ 104 /* 105 public void loaderEndElement(SVGLoaderHelper helper) 106 { 107 super.loaderEndElement(helper); 108 109 build(); 110 111 // unitFontXform.setToScale(1.0 / (double)unitsPerEm, 1.0 / (double)unitsPerEm); 112 } 113 */ 114 73 74 public String getTagName() 75 { 76 return TAG_NAME; 77 } 78 115 79 protected void build() throws SVGException 116 80 { 117 81 super.build(); 118 82 119 83 StyleAttribute sty = new StyleAttribute(); 120 121 if (getPres(sty.setName("font-family"))) fontFamily = sty.getStringValue(); 122 123 if (getPres(sty.setName("units-per-em"))) unitsPerEm = sty.getIntValue(); 124 if (getPres(sty.setName("ascent"))) ascent = sty.getIntValue(); 125 if (getPres(sty.setName("descent"))) descent = sty.getIntValue(); 126 if (getPres(sty.setName("accent-height"))) accentHeight = sty.getIntValue(); 127 128 if (getPres(sty.setName("underline-position"))) underlinePosition = sty.getIntValue(); 129 if (getPres(sty.setName("underline-thickness"))) underlineThickness = sty.getIntValue(); 130 if (getPres(sty.setName("strikethrough-position"))) strikethroughPosition = sty.getIntValue(); 131 if (getPres(sty.setName("strikethrough-thickenss"))) strikethroughThickness = sty.getIntValue(); 132 if (getPres(sty.setName("overline-position"))) overlinePosition = sty.getIntValue(); 133 if (getPres(sty.setName("overline-thickness"))) overlineThickness = sty.getIntValue(); 134 } 135 136 137 public String getFontFamily() { return fontFamily; } 138 139 public int getUnitsPerEm() { return unitsPerEm; } 84 85 if (getPres(sty.setName("font-family"))) 86 { 87 fontFamily = sty.getStringValue(); 88 } 89 90 if (getPres(sty.setName("units-per-em"))) 91 { 92 unitsPerEm = sty.getIntValue(); 93 } 94 if (getPres(sty.setName("ascent"))) 95 { 96 ascent = sty.getIntValue(); 97 } 98 if (getPres(sty.setName("descent"))) 99 { 100 descent = sty.getIntValue(); 101 } 102 if (getPres(sty.setName("accent-height"))) 103 { 104 accentHeight = sty.getIntValue(); 105 } 106 107 if (getPres(sty.setName("underline-position"))) 108 { 109 underlinePosition = sty.getIntValue(); 110 } 111 if (getPres(sty.setName("underline-thickness"))) 112 { 113 underlineThickness = sty.getIntValue(); 114 } 115 if (getPres(sty.setName("strikethrough-position"))) 116 { 117 strikethroughPosition = sty.getIntValue(); 118 } 119 if (getPres(sty.setName("strikethrough-thickenss"))) 120 { 121 strikethroughThickness = sty.getIntValue(); 122 } 123 if (getPres(sty.setName("overline-position"))) 124 { 125 overlinePosition = sty.getIntValue(); 126 } 127 if (getPres(sty.setName("overline-thickness"))) 128 { 129 overlineThickness = sty.getIntValue(); 130 } 131 } 132 133 public String getFontFamily() 134 { 135 return fontFamily; 136 } 137 138 public int getUnitsPerEm() 139 { 140 return unitsPerEm; 141 } 140 142 141 143 public int getAscent() 142 144 { 143 145 if (ascent == -1) 144 ascent = unitsPerEm - ((Font)parent).getVertOriginY(); 146 { 147 ascent = unitsPerEm - ((Font) parent).getVertOriginY(); 148 } 145 149 return ascent; 146 150 } … … 149 153 { 150 154 if (descent == -1) 151 descent = ((Font)parent).getVertOriginY(); 155 { 156 descent = ((Font) parent).getVertOriginY(); 157 } 152 158 return descent; 153 159 } … … 156 162 { 157 163 if (accentHeight == -1) 164 { 158 165 accentHeight = getAscent(); 166 } 159 167 return accentHeight; 160 168 } … … 163 171 { 164 172 if (underlinePosition == -1) 173 { 165 174 underlinePosition = unitsPerEm * 5 / 6; 175 } 166 176 return underlinePosition; 167 177 } … … 170 180 { 171 181 if (underlineThickness == -1) 182 { 172 183 underlineThickness = unitsPerEm / 20; 184 } 173 185 return underlineThickness; 174 186 } … … 177 189 { 178 190 if (strikethroughPosition == -1) 191 { 179 192 strikethroughPosition = unitsPerEm * 3 / 6; 193 } 180 194 return strikethroughPosition; 181 195 } … … 184 198 { 185 199 if (strikethroughThickness == -1) 200 { 186 201 strikethroughThickness = unitsPerEm / 20; 202 } 187 203 return strikethroughThickness; 188 204 } … … 191 207 { 192 208 if (overlinePosition == -1) 209 { 193 210 overlinePosition = unitsPerEm * 5 / 6; 211 } 194 212 return overlinePosition; 195 213 } … … 198 216 { 199 217 if (overlineThickness == -1) 218 { 200 219 overlineThickness = unitsPerEm / 20; 220 } 201 221 return overlineThickness; 202 222 } 203 223 204 224 /** 205 * Updates all attributes in this diagram associated with a time event. 206 * Ie, all attributes with track information. 225 * Updates all attributes in this diagram associated with a time event. Ie, 226 * all attributes with track information. 227 * 207 228 * @return - true if this node has changed state as a result of the time 208 229 * update -
trunk/src/com/kitfox/svg/Glyph.java
r4256 r6002 1 1 /* 2 * Font.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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 February 20, 2004, 10:00 PM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 import com.kitfox.svg.xml.StyleAttribute; 31 import com.kitfox.svg.xml.*;32 import org.xml.sax.*;33 34 import java.awt.*;35 import java.awt.geom.*;36 import java.util.*;37 38 import com.kitfox.svg.pathcmd.*;39 //import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;40 39 41 40 /** … … 49 48 public class Glyph extends MissingGlyph 50 49 { 50 51 public static final String TAG_NAME = "missingglyph"; 51 52 /** 52 * One or more characters indicating the unicode sequence that denotes 53 * thisglyph.53 * One or more characters indicating the unicode sequence that denotes this 54 * glyph. 54 55 */ 55 56 String unicode; 56 57 57 /** Creates a new instance of Font */ 58 /** 59 * Creates a new instance of Font 60 */ 58 61 public Glyph() 59 62 { 60 63 } 61 /* 62 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)64 65 public String getTagName() 63 66 { 64 //Load style string 65 super.loaderStartElement(helper, attrs, parent);67 return TAG_NAME; 68 } 66 69 67 //Get unicode sequence that maps to this glyph68 unicode = attrs.getValue("unicode");69 }70 */71 /*72 public void loaderEndElement(SVGLoaderHelper helper)73 {74 super.loaderEndElement(helper);75 76 build();77 }78 */79 80 70 protected void build() throws SVGException 81 71 { 82 72 super.build(); 83 73 84 74 StyleAttribute sty = new StyleAttribute(); 85 86 if (getPres(sty.setName("unicode"))) unicode = sty.getStringValue(); 75 76 if (getPres(sty.setName("unicode"))) 77 { 78 unicode = sty.getStringValue(); 79 } 87 80 } 88 89 public String getUnicode() { return unicode; } 90 81 82 public String getUnicode() 83 { 84 return unicode; 85 } 86 91 87 /** 92 * Updates all attributes in this diagram associated with a time event. 93 * Ie, all attributes with track information. 88 * Updates all attributes in this diagram associated with a time event. Ie, 89 * all attributes with track information. 90 * 94 91 * @return - true if this node has changed state as a result of the time 95 92 * update -
trunk/src/com/kitfox/svg/Gradient.java
r4256 r6002 1 1 /* 2 * Gradient.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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, 3:25 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 import java.net.*; 31 import java.util.*; 32 import java.awt.geom.*; 33 import java.awt.*; 34 35 import com.kitfox.svg.xml.*; 38 import com.kitfox.svg.xml.StyleAttribute; 39 import java.awt.Color; 40 import java.awt.geom.AffineTransform; 41 import java.net.URI; 42 import java.util.ArrayList; 43 import java.util.Iterator; 44 import java.util.logging.Level; 45 import java.util.logging.Logger; 36 46 37 47 /** … … 41 51 abstract public class Gradient extends FillElement 42 52 { 43 53 public static final String TAG_NAME = "gradient"; 54 44 55 public static final int SM_PAD = 0; 45 56 public static final int SM_REPEAT = 1; 46 57 public static final int SM_REFLECT = 2; 47 48 58 int spreadMethod = SM_PAD; 49 50 59 public static final int GU_OBJECT_BOUNDING_BOX = 0; 51 60 public static final int GU_USER_SPACE_ON_USE = 1; 52 53 61 protected int gradientUnits = GU_OBJECT_BOUNDING_BOX; 54 55 62 //Either this gradient contains a list of stops, or it will take it's 56 63 // stops from the referenced gradient 57 64 ArrayList stops = new ArrayList(); 58 65 URI stopRef = null; 59 // Gradient stopRef = null;60 61 66 protected AffineTransform gradientTransform = null; 62 67 63 68 //Cache arrays of stop values here 64 69 float[] stopFractions; 65 70 Color[] stopColors; 66 71 67 /** Creates a new instance of Gradient */ 68 public Gradient() { 69 } 70 72 /** 73 * Creates a new instance of Gradient 74 */ 75 public Gradient() 76 { 77 } 78 79 public String getTagName() 80 { 81 return TAG_NAME; 82 } 83 71 84 /** 72 85 * Called after the start element but before the end element to indicate … … 77 90 super.loaderAddChild(helper, child); 78 91 79 if (!(child instanceof Stop)) return; 80 appendStop((Stop)child); 92 if (!(child instanceof Stop)) 93 { 94 return; 95 } 96 appendStop((Stop) child); 81 97 } 82 98 … … 84 100 { 85 101 super.build(); 86 102 87 103 StyleAttribute sty = new StyleAttribute(); 88 104 String strn; 89 105 90 106 if (getPres(sty.setName("spreadMethod"))) 91 107 { 92 108 strn = sty.getStringValue().toLowerCase(); 93 if (strn.equals("repeat")) spreadMethod = SM_REPEAT; 94 else if (strn.equals("reflect")) spreadMethod = SM_REFLECT; 95 else spreadMethod = SM_PAD; 109 if (strn.equals("repeat")) 110 { 111 spreadMethod = SM_REPEAT; 112 } else if (strn.equals("reflect")) 113 { 114 spreadMethod = SM_REFLECT; 115 } else 116 { 117 spreadMethod = SM_PAD; 118 } 96 119 } 97 120 … … 99 122 { 100 123 strn = sty.getStringValue().toLowerCase(); 101 if (strn.equals("userspaceonuse")) gradientUnits = GU_USER_SPACE_ON_USE; 102 else gradientUnits = GU_OBJECT_BOUNDING_BOX; 103 } 104 105 if (getPres(sty.setName("gradientTransform"))) gradientTransform = parseTransform(sty.getStringValue()); 124 if (strn.equals("userspaceonuse")) 125 { 126 gradientUnits = GU_USER_SPACE_ON_USE; 127 } else 128 { 129 gradientUnits = GU_OBJECT_BOUNDING_BOX; 130 } 131 } 132 133 if (getPres(sty.setName("gradientTransform"))) 134 { 135 gradientTransform = parseTransform(sty.getStringValue()); 136 } 106 137 //If we still don't have one, set it to identity 107 if (gradientTransform == null) gradientTransform = new AffineTransform(); 108 109 138 if (gradientTransform == null) 139 { 140 gradientTransform = new AffineTransform(); 141 } 142 143 110 144 //Check to see if we're using our own stops or referencing someone else's 111 145 if (getPres(sty.setName("xlink:href"))) 112 146 { 113 try { 147 try 148 { 114 149 stopRef = sty.getURIValue(getXMLBase()); 115 150 //System.err.println("Gradient: " + sty.getStringValue() + ", " + getXMLBase() + ", " + src); 116 151 // URI src = getXMLBase().resolve(href); 117 152 // stopRef = (Gradient)diagram.getUniverse().getElement(src); 118 } 119 catch (Exception e) 153 } catch (Exception e) 120 154 { 121 155 throw new SVGException("Could not resolve relative URL in Gradient: " + sty.getStringValue() + ", " + getXMLBase(), e); … … 123 157 } 124 158 } 125 159 126 160 public float[] getStopFractions() 127 161 { 128 162 if (stopRef != null) 129 163 { 130 Gradient grad = (Gradient) diagram.getUniverse().getElement(stopRef);164 Gradient grad = (Gradient) diagram.getUniverse().getElement(stopRef); 131 165 return grad.getStopFractions(); 132 166 } 133 167 134 if (stopFractions != null) return stopFractions; 168 if (stopFractions != null) 169 { 170 return stopFractions; 171 } 135 172 136 173 stopFractions = new float[stops.size()]; … … 138 175 for (Iterator it = stops.iterator(); it.hasNext();) 139 176 { 140 Stop stop = (Stop) it.next();177 Stop stop = (Stop) it.next(); 141 178 float val = stop.offset; 142 if (idx != 0 && val < stopFractions[idx - 1]) val = stopFractions[idx - 1]; 179 if (idx != 0 && val < stopFractions[idx - 1]) 180 { 181 val = stopFractions[idx - 1]; 182 } 143 183 stopFractions[idx++] = val; 144 184 } … … 151 191 if (stopRef != null) 152 192 { 153 Gradient grad = (Gradient) diagram.getUniverse().getElement(stopRef);193 Gradient grad = (Gradient) diagram.getUniverse().getElement(stopRef); 154 194 return grad.getStopColors(); 155 195 } 156 196 157 if (stopColors != null) return stopColors; 197 if (stopColors != null) 198 { 199 return stopColors; 200 } 158 201 159 202 stopColors = new Color[stops.size()]; … … 161 204 for (Iterator it = stops.iterator(); it.hasNext();) 162 205 { 163 Stop stop = (Stop) it.next();206 Stop stop = (Stop) it.next(); 164 207 int stopColorVal = stop.color.getRGB(); 165 Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int) (stop.opacity * 255), 0, 255));208 Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int) (stop.opacity * 255), 0, 255)); 166 209 stopColors[idx++] = stopColor; 167 210 } … … 169 212 return stopColors; 170 213 } 171 214 172 215 public void setStops(Color[] colors, float[] fractions) 173 216 { … … 176 219 throw new IllegalArgumentException(); 177 220 } 178 221 179 222 this.stopColors = colors; 180 223 this.stopFractions = fractions; 181 224 stopRef = null; 182 225 } 183 226 184 227 private int clamp(int val, int min, int max) 185 228 { 186 if (val < min) return min; 187 if (val > max) return max; 229 if (val < min) 230 { 231 return min; 232 } 233 if (val > max) 234 { 235 return max; 236 } 188 237 return val; 189 238 } 190 239 191 240 public void setStopRef(URI grad) 192 241 { … … 200 249 201 250 /** 202 * Updates all attributes in this diagram associated with a time event. 203 * Ie, all attributes with track information. 251 * Updates all attributes in this diagram associated with a time event. Ie, 252 * all attributes with track information. 253 * 204 254 * @return - true if this node has changed state as a result of the time 205 255 * update … … 214 264 boolean shapeChange = false; 215 265 String strn; 216 266 217 267 218 268 if (getPres(sty.setName("spreadMethod"))) … … 220 270 int newVal; 221 271 strn = sty.getStringValue().toLowerCase(); 222 if (strn.equals("repeat")) newVal = SM_REPEAT; 223 else if (strn.equals("reflect")) newVal = SM_REFLECT; 224 else newVal = SM_PAD; 272 if (strn.equals("repeat")) 273 { 274 newVal = SM_REPEAT; 275 } else if (strn.equals("reflect")) 276 { 277 newVal = SM_REFLECT; 278 } else 279 { 280 newVal = SM_PAD; 281 } 225 282 if (spreadMethod != newVal) 226 283 { … … 229 286 } 230 287 } 231 288 232 289 if (getPres(sty.setName("gradientUnits"))) 233 290 { 234 291 int newVal; 235 292 strn = sty.getStringValue().toLowerCase(); 236 if (strn.equals("userspaceonuse")) newVal = GU_USER_SPACE_ON_USE; 237 else newVal = GU_OBJECT_BOUNDING_BOX; 293 if (strn.equals("userspaceonuse")) 294 { 295 newVal = GU_USER_SPACE_ON_USE; 296 } else 297 { 298 newVal = GU_OBJECT_BOUNDING_BOX; 299 } 238 300 if (newVal != gradientUnits) 239 301 { … … 253 315 } 254 316 255 317 256 318 //Check to see if we're using our own stops or referencing someone else's 257 319 if (getPres(sty.setName("xlink:href"))) 258 320 { 259 try { 321 try 322 { 260 323 URI newVal = sty.getURIValue(getXMLBase()); 261 324 if ((newVal == null && stopRef != null) || !newVal.equals(stopRef)) … … 264 327 stateChange = true; 265 328 } 266 } 267 catch (Exception e)268 {269 e.printStackTrace();270 } 271 } 272 329 } catch (Exception e) 330 { 331 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 332 "Could not parse xlink:href", e); 333 } 334 } 335 273 336 //Check stops, if any 274 337 for (Iterator it = stops.iterator(); it.hasNext();) 275 338 { 276 Stop stop = (Stop) it.next();339 Stop stop = (Stop) it.next(); 277 340 if (stop.updateTime(curTime)) 278 341 { … … 282 345 } 283 346 } 284 347 285 348 return stateChange; 286 349 } 287 288 350 } -
trunk/src/com/kitfox/svg/Group.java
r4256 r6002 1 1 /* 2 * Stop.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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:56 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 import com.kitfox.svg.xml.StyleAttribute; 31 39 import java.awt.Graphics2D; 32 import java.awt.Rectangle;33 40 import java.awt.Shape; 34 41 import java.awt.geom.AffineTransform; … … 40 47 import java.util.List; 41 48 42 43 49 /** 44 50 * @author Mark McKay … … 47 53 public class Group extends ShapeElement 48 54 { 49 55 public static final String TAG_NAME = "group"; 56 50 57 //Cache bounding box for faster clip testing 51 58 Rectangle2D boundingBox; 52 59 Shape cachedShape; 53 60 54 //Cache clip bounds 55 final Rectangle clipBounds = new Rectangle(); 56 57 /** Creates a new instance of Stop */ 58 public Group() { 59 } 60 61 /* 62 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 63 { 64 //Load style string 65 super.loaderStartElement(helper, attrs, parent); 66 67 //String transform = attrs.getValue("transform"); 68 } 69 */ 61 /** 62 * Creates a new instance of Stop 63 */ 64 public Group() 65 { 66 } 67 68 public String getTagName() 69 { 70 return TAG_NAME; 71 } 70 72 71 73 /** … … 76 78 { 77 79 super.loaderAddChild(helper, child); 78 79 // members.add(child);80 80 } 81 81 82 82 protected boolean outsideClip(Graphics2D g) throws SVGException 83 83 { 84 g.getClipBounds(clipBounds); 84 Shape clip = g.getClip(); 85 if (clip == null) 86 { 87 return false; 88 } 89 //g.getClipBounds(clipBounds); 85 90 Rectangle2D rect = getBoundingBox(); 86 91 87 //if (rect == null) 88 //{ 89 // rect = getBoundingBox(); 90 //} 91 92 // if (rect.intersects(clipBounds)) 93 if (rect.intersects(clipBounds)) 92 if (clip.intersects(rect)) 94 93 { 95 94 return false; … … 107 106 { 108 107 xform.inverseTransform(point, xPoint); 109 } 110 catch (NoninvertibleTransformException ex) 108 } catch (NoninvertibleTransformException ex) 111 109 { 112 110 throw new SVGException(ex); 113 111 } 114 112 } 115 116 113 114 117 115 for (Iterator it = children.iterator(); it.hasNext();) 118 116 { 119 SVGElement ele = (SVGElement) it.next();120 if (ele instanceof RenderableElement) 121 { 122 RenderableElement rendEle = (RenderableElement) ele;123 117 SVGElement ele = (SVGElement) it.next(); 118 if (ele instanceof RenderableElement) 119 { 120 RenderableElement rendEle = (RenderableElement) ele; 121 124 122 rendEle.pick(xPoint, boundingBox, retVec); 125 123 } … … 134 132 ltw.concatenate(xform); 135 133 } 136 137 134 135 138 136 for (Iterator it = children.iterator(); it.hasNext();) 139 137 { 140 SVGElement ele = (SVGElement) it.next();141 if (ele instanceof RenderableElement) 142 { 143 RenderableElement rendEle = (RenderableElement) ele;144 138 SVGElement ele = (SVGElement) it.next(); 139 if (ele instanceof RenderableElement) 140 { 141 RenderableElement rendEle = (RenderableElement) ele; 142 145 143 rendEle.pick(pickArea, ltw, boundingBox, retVec); 146 144 } … … 154 152 if (getStyle(styleAttrib.setName("visibility"))) 155 153 { 156 if (!styleAttrib.getStringValue().equals("visible")) return; 157 } 158 154 if (!styleAttrib.getStringValue().equals("visible")) 155 { 156 return; 157 } 158 } 159 159 160 //Do not process offscreen groups 160 161 boolean ignoreClip = diagram.ignoringClipHeuristic(); 161 if (!ignoreClip && outsideClip(g)) return; 162 if (!ignoreClip && outsideClip(g)) 163 { 164 return; 165 } 162 166 163 167 beginLayer(g); … … 165 169 Iterator it = children.iterator(); 166 170 167 try 168 { 169 g.getClipBounds(clipBounds); 170 } 171 catch (Exception e) 172 { 173 //For some reason, getClipBounds can throw a null pointer exception for 174 // some types of Graphics2D 175 ignoreClip = true; 176 } 177 171 // try 172 // { 173 // g.getClipBounds(clipBounds); 174 // } 175 // catch (Exception e) 176 // { 177 // //For some reason, getClipBounds can throw a null pointer exception for 178 // // some types of Graphics2D 179 // ignoreClip = true; 180 // } 181 182 Shape clip = g.getClip(); 178 183 while (it.hasNext()) 179 184 { 180 SVGElement ele = (SVGElement) it.next();181 if (ele instanceof RenderableElement) 182 { 183 RenderableElement rendEle = (RenderableElement) ele;185 SVGElement ele = (SVGElement) it.next(); 186 if (ele instanceof RenderableElement) 187 { 188 RenderableElement rendEle = (RenderableElement) ele; 184 189 185 190 // if (shapeEle == null) continue; … … 188 193 { 189 194 //Skip if clipping area is outside our bounds 190 if (!ignoreClip && !rendEle.getBoundingBox().intersects(clipBounds)) 195 if (!ignoreClip && clip != null 196 && !clip.intersects(rendEle.getBoundingBox())) 191 197 { 192 198 continue; … … 201 207 } 202 208 203 204 209 /** 205 210 * Retrieves the cached bounding box of this group … … 207 212 public Shape getShape() 208 213 { 209 if (cachedShape == null) calcShape(); 214 if (cachedShape == null) 215 { 216 calcShape(); 217 } 210 218 return cachedShape; 211 219 } … … 217 225 for (Iterator it = children.iterator(); it.hasNext();) 218 226 { 219 SVGElement ele = (SVGElement) it.next();227 SVGElement ele = (SVGElement) it.next(); 220 228 221 229 if (ele instanceof ShapeElement) 222 230 { 223 ShapeElement shpEle = (ShapeElement) ele;231 ShapeElement shpEle = (ShapeElement) ele; 224 232 Shape shape = shpEle.getShape(); 225 233 if (shape != null) … … 238 246 public Rectangle2D getBoundingBox() throws SVGException 239 247 { 240 if (boundingBox == null) calcBoundingBox(); 248 if (boundingBox == null) 249 { 250 calcBoundingBox(); 251 } 241 252 // calcBoundingBox(); 242 253 return boundingBox; … … 245 256 /** 246 257 * Recalculates the bounding box by taking the union of the bounding boxes 247 * of all children. 258 * of all children. Caches the result. 248 259 */ 249 260 public void calcBoundingBox() throws SVGException … … 254 265 for (Iterator it = children.iterator(); it.hasNext();) 255 266 { 256 SVGElement ele = (SVGElement) it.next();257 258 if (ele instanceof RenderableElement) 259 { 260 RenderableElement rendEle = (RenderableElement) ele;267 SVGElement ele = (SVGElement) it.next(); 268 269 if (ele instanceof RenderableElement) 270 { 271 RenderableElement rendEle = (RenderableElement) ele; 261 272 Rectangle2D bounds = rendEle.getBoundingBox(); 262 273 if (bounds != null) 263 274 { 264 if (retRect == null) retRect = bounds; 265 else retRect = retRect.createUnion(bounds); 275 if (retRect == null) 276 { 277 retRect = bounds; 278 } else 279 { 280 retRect = retRect.createUnion(bounds); 281 } 266 282 } 267 283 } … … 274 290 275 291 //If no contents, use degenerate rectangle 276 if (retRect == null) retRect = new Rectangle2D.Float(); 292 if (retRect == null) 293 { 294 retRect = new Rectangle2D.Float(); 295 } 277 296 278 297 boundingBox = boundsToParent(retRect); … … 287 306 while (it.hasNext()) 288 307 { 289 SVGElement ele = (SVGElement) it.next();308 SVGElement ele = (SVGElement) it.next(); 290 309 boolean updateVal = ele.updateTime(curTime); 291 310 … … 293 312 294 313 //Update our shape if shape aware children change 295 if (ele instanceof ShapeElement) cachedShape = null; 296 if (ele instanceof RenderableElement) boundingBox = null; 314 if (ele instanceof ShapeElement) 315 { 316 cachedShape = null; 317 } 318 if (ele instanceof RenderableElement) 319 { 320 boundingBox = null; 321 } 297 322 } 298 323 -
trunk/src/com/kitfox/svg/Hkern.java
r4256 r6002 1 1 /* 2 * Font.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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 February 20, 2004, 10:00 PM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 … … 36 44 public class Hkern extends SVGElement 37 45 { 46 47 public static final String TAG_NAME = "hkern"; 38 48 String u1; 39 49 String u2; 40 50 int k; 41 51 52 public String getTagName() 53 { 54 return TAG_NAME; 55 } 42 56 43 57 protected void build() throws SVGException … … 49 63 50 64 //Read glyph spacing info 51 if (getPres(sty.setName("u1"))) u1 = sty.getStringValue(); 65 if (getPres(sty.setName("u1"))) 66 { 67 u1 = sty.getStringValue(); 68 } 52 69 53 if (getPres(sty.setName("u2"))) u2 = sty.getStringValue(); 70 if (getPres(sty.setName("u2"))) 71 { 72 u2 = sty.getStringValue(); 73 } 54 74 55 if (getPres(sty.setName("k"))) k = sty.getIntValue(); 75 if (getPres(sty.setName("k"))) 76 { 77 k = sty.getIntValue(); 78 } 56 79 } 57 80 … … 61 84 return false; 62 85 } 63 64 65 86 } -
trunk/src/com/kitfox/svg/ImageSVG.java
r4256 r6002 1 1 /* 2 * Font.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 February 20, 2004, 10:00 PM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 import com.kitfox.svg.app.data.Handler; 31 import com.kitfox.svg.xml.*; 32 33 import java.awt.*; 34 import java.awt.geom.*; 35 import java.awt.image.*; 36 import java.net.*; 39 import com.kitfox.svg.xml.StyleAttribute; 40 import java.awt.AlphaComposite; 41 import java.awt.Composite; 42 import java.awt.Graphics2D; 43 import java.awt.geom.AffineTransform; 44 import java.awt.geom.Point2D; 45 import java.awt.geom.Rectangle2D; 46 import java.awt.image.BufferedImage; 47 import java.net.URI; 48 import java.net.URL; 37 49 import java.util.List; 50 import java.util.logging.Level; 51 import java.util.logging.Logger; 38 52 39 53 /** 40 * Implements an embedded font. 41 * 42 * SVG specification: http://www.w3.org/TR/SVG/fonts.html 54 * Implements an image. 43 55 * 44 56 * @author Mark McKay … … 47 59 public class ImageSVG extends RenderableElement 48 60 { 61 public static final String TAG_NAME = "image"; 62 49 63 float x = 0f; 50 64 float y = 0f; 51 65 float width = 0f; 52 66 float height = 0f; 53 54 67 // BufferedImage href = null; 55 68 URL imageSrc = null; 56 57 69 AffineTransform xform; 58 70 Rectangle2D bounds; 59 71 60 /** Creates a new instance of Font */ 72 /** 73 * Creates a new instance of Font 74 */ 61 75 public ImageSVG() 62 76 { 63 77 } 64 78 79 public String getTagName() 80 { 81 return TAG_NAME; 82 } 83 65 84 protected void build() throws SVGException 66 85 { 67 86 super.build(); 68 87 69 88 StyleAttribute sty = new StyleAttribute(); 70 71 if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits(); 72 73 if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits(); 74 75 if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits(); 76 77 if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits(); 78 79 try { 89 90 if (getPres(sty.setName("x"))) 91 { 92 x = sty.getFloatValueWithUnits(); 93 } 94 95 if (getPres(sty.setName("y"))) 96 { 97 y = sty.getFloatValueWithUnits(); 98 } 99 100 if (getPres(sty.setName("width"))) 101 { 102 width = sty.getFloatValueWithUnits(); 103 } 104 105 if (getPres(sty.setName("height"))) 106 { 107 height = sty.getFloatValueWithUnits(); 108 } 109 110 try 111 { 80 112 if (getPres(sty.setName("xlink:href"))) 81 113 { … … 84 116 { 85 117 imageSrc = new URL(null, src.toASCIIString(), new Handler()); 86 } 87 else88 {89 try{118 } else 119 { 120 try 121 { 90 122 imageSrc = src.toURL(); 91 } 92 catch (Exception e) 123 } catch (Exception e) 93 124 { 94 e.printStackTrace(); 125 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 126 "Could not parse xlink:href", e); 127 // e.printStackTrace(); 95 128 imageSrc = null; 96 129 } 97 130 } 98 131 } 99 } 100 catch (Exception e) 132 } catch (Exception e) 101 133 { 102 134 throw new SVGException(e); … … 104 136 105 137 diagram.getUniverse().registerImage(imageSrc); 106 138 107 139 //Set widths if not set 108 140 BufferedImage img = diagram.getUniverse().getImage(imageSrc); … … 113 145 return; 114 146 } 115 116 if (width == 0) width = img.getWidth(); 117 if (height == 0) height = img.getHeight(); 118 147 148 if (width == 0) 149 { 150 width = img.getWidth(); 151 } 152 if (height == 0) 153 { 154 height = img.getHeight(); 155 } 156 119 157 //Determine image xform 120 158 xform = new AffineTransform(); … … 123 161 xform.translate(this.x, this.y); 124 162 xform.scale(this.width / img.getWidth(), this.height / img.getHeight()); 125 163 126 164 bounds = new Rectangle2D.Float(this.x, this.y, this.width, this.height); 127 165 } 128 129 130 131 public float getX() { return x; } 132 public float getY() { return y; } 133 public float getWidth() { return width; } 134 public float getHeight() { return height; } 166 167 public float getX() 168 { 169 return x; 170 } 171 172 public float getY() 173 { 174 return y; 175 } 176 177 public float getWidth() 178 { 179 return width; 180 } 181 182 public float getHeight() 183 { 184 return height; 185 } 135 186 136 187 void pick(Point2D point, boolean boundingBox, List retVec) throws SVGException … … 155 206 if (getStyle(styleAttrib.setName("visibility"))) 156 207 { 157 if (!styleAttrib.getStringValue().equals("visible")) return; 158 } 159 208 if (!styleAttrib.getStringValue().equals("visible")) 209 { 210 return; 211 } 212 } 213 160 214 beginLayer(g); 161 215 162 216 float opacity = 1f; 163 217 if (getStyle(styleAttrib.setName("opacity"))) … … 165 219 opacity = styleAttrib.getRatioValue(); 166 220 } 167 168 if (opacity <= 0) return; 221 222 if (opacity <= 0) 223 { 224 return; 225 } 169 226 170 227 Composite oldComp = null; 171 228 172 229 if (opacity < 1) 173 230 { … … 176 233 g.setComposite(comp); 177 234 } 178 235 179 236 BufferedImage img = diagram.getUniverse().getImage(imageSrc); 180 if (img == null) return; 181 237 if (img == null) 238 { 239 return; 240 } 241 182 242 AffineTransform curXform = g.getTransform(); 183 243 g.transform(xform); 184 244 185 245 g.drawImage(img, 0, 0, null); 186 246 187 247 g.setTransform(curXform); 188 if (oldComp != null) g.setComposite(oldComp); 189 248 if (oldComp != null) 249 { 250 g.setComposite(oldComp); 251 } 252 190 253 finishLayer(g); 191 254 } 192 255 193 256 public Rectangle2D getBoundingBox() 194 257 { … … 197 260 198 261 /** 199 * Updates all attributes in this diagram associated with a time event. 200 * Ie, all attributes with track information. 262 * Updates all attributes in this diagram associated with a time event. Ie, 263 * all attributes with track information. 264 * 201 265 * @return - true if this node has changed state as a result of the time 202 266 * update … … 210 274 StyleAttribute sty = new StyleAttribute(); 211 275 boolean shapeChange = false; 212 276 213 277 if (getPres(sty.setName("x"))) 214 278 { … … 220 284 } 221 285 } 222 286 223 287 if (getPres(sty.setName("y"))) 224 288 { … … 230 294 } 231 295 } 232 296 233 297 if (getPres(sty.setName("width"))) 234 298 { … … 240 304 } 241 305 } 242 306 243 307 if (getPres(sty.setName("height"))) 244 308 { … … 250 314 } 251 315 } 252 253 try { 316 317 try 318 { 254 319 if (getPres(sty.setName("xlink:href"))) 255 320 { 256 321 URI src = sty.getURIValue(getXMLBase()); 257 URL newVal = src.toURL(); 258 322 323 URL newVal; 324 if ("data".equals(src.getScheme())) 325 { 326 newVal = new URL(null, src.toASCIIString(), new Handler()); 327 } else 328 { 329 newVal = src.toURL(); 330 } 331 259 332 if (!newVal.equals(imageSrc)) 260 333 { … … 263 336 } 264 337 } 265 } 266 catch (IllegalArgumentException ie) 267 { 268 new Exception("Image provided with illegal value for href: \"" + sty.getStringValue() + '"', ie).printStackTrace(); 269 } 270 catch (Exception e) 271 { 272 e.printStackTrace(); 273 } 274 275 338 } catch (IllegalArgumentException ie) 339 { 340 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 341 "Image provided with illegal value for href: \"" 342 + sty.getStringValue() + '"', ie); 343 } catch (Exception e) 344 { 345 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 346 "Could not parse xlink:href", e); 347 } 348 349 276 350 if (shapeChange) 277 351 { … … 303 377 // return true; 304 378 } 305 379 306 380 return changeState || shapeChange; 307 381 } -
trunk/src/com/kitfox/svg/Line.java
r4256 r6002 1 1 /* 2 * Rect.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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, 5:25 PM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 … … 38 46 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 39 47 */ 40 public class Line extends ShapeElement { 41 48 public class Line extends ShapeElement 49 { 50 public static final String TAG_NAME = "line"; 51 42 52 float x1 = 0f; 43 53 float y1 = 0f; 44 54 float x2 = 0f; 45 55 float y2 = 0f; 56 Line2D.Float line; 46 57 47 Line2D.Float line;48 // RectangularShape rect; 49 50 /** Creates a new instance of Rect */51 public Line(){58 /** 59 * Creates a new instance of Rect 60 */ 61 public Line() 62 { 52 63 } 53 64 54 /* 55 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 65 public String getTagName() 56 66 { 57 //Load style string 58 super.loaderStartElement(helper, attrs, parent);67 return TAG_NAME; 68 } 59 69 60 String x1 = attrs.getValue("x1");61 String y1 = attrs.getValue("y1");62 String x2 = attrs.getValue("x2");63 String y2 = attrs.getValue("y2");64 65 this.x1 = XMLParseUtil.parseFloat(x1);66 this.y1 = XMLParseUtil.parseFloat(y1);67 this.x2 = XMLParseUtil.parseFloat(x2);68 this.y2 = XMLParseUtil.parseFloat(y2);69 70 build();71 }72 */73 70 protected void build() throws SVGException 74 71 { 75 72 super.build(); 76 73 77 74 StyleAttribute sty = new StyleAttribute(); 78 79 if (getPres(sty.setName("x1"))) x1 = sty.getFloatValueWithUnits();80 75 81 if (getPres(sty.setName("y1"))) y1 = sty.getFloatValueWithUnits(); 76 if (getPres(sty.setName("x1"))) 77 { 78 x1 = sty.getFloatValueWithUnits(); 79 } 82 80 83 if (getPres(sty.setName("x2"))) x2 = sty.getFloatValueWithUnits(); 81 if (getPres(sty.setName("y1"))) 82 { 83 y1 = sty.getFloatValueWithUnits(); 84 } 84 85 85 if (getPres(sty.setName("y2"))) y2 = sty.getFloatValueWithUnits(); 86 if (getPres(sty.setName("x2"))) 87 { 88 x2 = sty.getFloatValueWithUnits(); 89 } 90 91 if (getPres(sty.setName("y2"))) 92 { 93 y2 = sty.getFloatValueWithUnits(); 94 } 86 95 87 96 line = new Line2D.Float(x1, y1, x2, y2); 88 97 } 89 90 98 91 99 public void render(Graphics2D g) throws SVGException … … 107 115 108 116 /** 109 * Updates all attributes in this diagram associated with a time event. 110 * Ie, all attributes with track information. 117 * Updates all attributes in this diagram associated with a time event. Ie, 118 * all attributes with track information. 119 * 111 120 * @return - true if this node has changed state as a result of the time 112 121 * update … … 120 129 StyleAttribute sty = new StyleAttribute(); 121 130 boolean shapeChange = false; 122 131 123 132 if (getPres(sty.setName("x1"))) 124 133 { … … 164 173 { 165 174 build(); 166 // line = new Line2D.Float(x1, y1, x2, y2);167 // return true;168 175 } 169 176 170 177 return changeState || shapeChange; 171 178 } -
trunk/src/com/kitfox/svg/LinearGradient.java
r4256 r6002 1 1 /* 2 * LinearGradient.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:54 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 LinearGradient extends Gradient { 46 49 public class LinearGradient extends Gradient 50 { 51 public static final String TAG_NAME = "lineargradient"; 52 47 53 float x1 = 0f; 48 54 float y1 = 0f; … … 50 56 float y2 = 0f; 51 57 52 /** Creates a new instance of LinearGradient */ 53 public LinearGradient() { 54 } 55 /* 56 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 57 { 58 //Load style string 59 super.loaderStartElement(helper, attrs, parent); 60 61 String x1 = attrs.getValue("x1"); 62 String x2 = attrs.getValue("x2"); 63 String y1 = attrs.getValue("y1"); 64 String y2 = attrs.getValue("y2"); 65 66 if (x1 != null) this.x1 = (float)XMLParseUtil.parseRatio(x1); 67 if (y1 != null) this.y1 = (float)XMLParseUtil.parseRatio(y1); 68 if (x2 != null) this.x2 = (float)XMLParseUtil.parseRatio(x2); 69 if (y2 != null) this.y2 = (float)XMLParseUtil.parseRatio(y2); 70 } 71 */ 72 /* 73 public void loaderEndElement(SVGLoaderHelper helper) 74 { 75 super.loaderEndElement(helper); 76 77 build(); 78 } 79 */ 80 58 /** 59 * Creates a new instance of LinearGradient 60 */ 61 public LinearGradient() 62 { 63 } 64 65 public String getTagName() 66 { 67 return TAG_NAME; 68 } 69 81 70 protected void build() throws SVGException 82 71 { 83 72 super.build(); 84 73 85 74 StyleAttribute sty = new StyleAttribute(); 86 87 if (getPres(sty.setName("x1"))) x1 = sty.getFloatValueWithUnits(); 88 89 if (getPres(sty.setName("y1"))) y1 = sty.getFloatValueWithUnits(); 90 91 if (getPres(sty.setName("x2"))) x2 = sty.getFloatValueWithUnits(); 92 93 if (getPres(sty.setName("y2"))) y2 = sty.getFloatValueWithUnits(); 94 } 95 75 76 if (getPres(sty.setName("x1"))) 77 { 78 x1 = sty.getFloatValueWithUnits(); 79 } 80 81 if (getPres(sty.setName("y1"))) 82 { 83 y1 = sty.getFloatValueWithUnits(); 84 } 85 86 if (getPres(sty.setName("x2"))) 87 { 88 x2 = sty.getFloatValueWithUnits(); 89 } 90 91 if (getPres(sty.setName("y2"))) 92 { 93 y2 = sty.getFloatValueWithUnits(); 94 } 95 } 96 96 97 public Paint getPaint(Rectangle2D bounds, AffineTransform xform) 97 98 { … … 111 112 } 112 113 113 com.kitfox.svg.batik.LinearGradientPaint paint; 114 if (gradientUnits == GU_USER_SPACE_ON_USE) 115 { 116 // paint = new LinearGradientPaint(x1, y1, x2, y2, getStopFractions(), getStopColors(), method); 114 Paint paint; 115 Point2D.Float pt1 = new Point2D.Float(x1, y1); 116 Point2D.Float pt2 = new Point2D.Float(x2, y2); 117 if (pt1.equals(pt2)) 118 { 119 Color[] colors = getStopColors(); 120 paint = colors.length > 0 ? colors[0] : Color.black; 121 } else if (gradientUnits == GU_USER_SPACE_ON_USE) 122 { 117 123 paint = new com.kitfox.svg.batik.LinearGradientPaint( 118 new Point2D.Float(x1, y1),119 new Point2D.Float(x2, y2),124 pt1, 125 pt2, 120 126 getStopFractions(), 121 127 getStopColors(), 122 128 method, 123 129 com.kitfox.svg.batik.MultipleGradientPaint.SRGB, 124 gradientTransform); 125 } 126 else 130 gradientTransform == null 131 ? new AffineTransform() 132 : gradientTransform); 133 } else 127 134 { 128 135 AffineTransform viewXform = new AffineTransform(); 129 136 viewXform.translate(bounds.getX(), bounds.getY()); 130 137 131 138 //This is a hack to get around shapes that have a width or height of 0. Should be close enough to the true answer. 132 double width = bounds.getWidth(); 133 double height = bounds.getHeight(); 134 if (width == 0) width = 1; 135 if (height == 0) height = 1; 139 double width = Math.max(1, bounds.getWidth()); 140 double height = Math.max(1, bounds.getHeight()); 136 141 viewXform.scale(width, height); 137 142 138 viewXform.concatenate(gradientTransform); 143 if (gradientTransform != null) 144 { 145 viewXform.concatenate(gradientTransform); 146 } 139 147 140 148 paint = new com.kitfox.svg.batik.LinearGradientPaint( 141 new Point2D.Float(x1, y1),142 new Point2D.Float(x2, y2),149 pt1, 150 pt2, 143 151 getStopFractions(), 144 152 getStopColors(), … … 150 158 return paint; 151 159 } 152 160 153 161 /** 154 * Updates all attributes in this diagram associated with a time event. 155 * Ie, all attributes with track information. 162 * Updates all attributes in this diagram associated with a time event. Ie, 163 * all attributes with track information. 164 * 156 165 * @return - true if this node has changed state as a result of the time 157 166 * update … … 165 174 StyleAttribute sty = new StyleAttribute(); 166 175 boolean shapeChange = false; 167 176 168 177 if (getPres(sty.setName("x1"))) 169 178 { -
trunk/src/com/kitfox/svg/Marker.java
r4256 r6002 1 1 /* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 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 4 33 */ 5 6 34 package com.kitfox.svg; 7 35 … … 21 49 public class Marker extends Group 22 50 { 51 public static final String TAG_NAME = "marker"; 52 23 53 AffineTransform viewXform; 24 54 AffineTransform markerXform; 25 55 Rectangle2D viewBox; 26 27 56 float refX; 28 57 float refY; … … 30 59 float markerHeight = 3; 31 60 float orient = Float.NaN; 61 boolean markerUnitsStrokeWidth = true; //if set to false 'userSpaceOnUse' is assumed 62 63 public String getTagName() 64 { 65 return TAG_NAME; 66 } 32 67 33 68 protected void build() throws SVGException … … 37 72 StyleAttribute sty = new StyleAttribute(); 38 73 39 if (getPres(sty.setName("refX"))) refX = sty.getFloatValueWithUnits(); 40 if (getPres(sty.setName("refY"))) refY = sty.getFloatValueWithUnits(); 41 if (getPres(sty.setName("markerWidth"))) markerWidth = sty.getFloatValueWithUnits(); 42 if (getPres(sty.setName("markerHeight"))) markerHeight = sty.getFloatValueWithUnits(); 74 if (getPres(sty.setName("refX"))) 75 { 76 refX = sty.getFloatValueWithUnits(); 77 } 78 if (getPres(sty.setName("refY"))) 79 { 80 refY = sty.getFloatValueWithUnits(); 81 } 82 if (getPres(sty.setName("markerWidth"))) 83 { 84 markerWidth = sty.getFloatValueWithUnits(); 85 } 86 if (getPres(sty.setName("markerHeight"))) 87 { 88 markerHeight = sty.getFloatValueWithUnits(); 89 } 43 90 44 91 if (getPres(sty.setName("orient"))) … … 47 94 { 48 95 orient = Float.NaN; 49 } 50 else 96 } else 51 97 { 52 98 orient = sty.getFloatValue(); … … 63 109 { 64 110 viewBox = new Rectangle(0, 0, 1, 1); 111 } 112 113 if (getPres(sty.setName("markerUnits"))) 114 { 115 String markerUnits = sty.getStringValue(); 116 if (markerUnits != null && markerUnits.equals("userSpaceOnUse")) 117 { 118 markerUnitsStrokeWidth = false; 119 } 65 120 } 66 121 … … 78 133 protected boolean outsideClip(Graphics2D g) throws SVGException 79 134 { 80 g.getClipBounds(clipBounds);135 Shape clip = g.getClip(); 81 136 Rectangle2D rect = super.getBoundingBox(); 82 if ( rect.intersects(clipBounds))137 if (clip == null || clip.intersects(rect)) 83 138 { 84 139 return false; … … 104 159 105 160 g.translate(pos.x, pos.y); 106 g.scale(strokeWidth, strokeWidth); 161 if (markerUnitsStrokeWidth) 162 { 163 g.scale(strokeWidth, strokeWidth); 164 } 165 107 166 g.rotate(Math.atan2(pos.dy, pos.dx)); 108 167 … … 127 186 128 187 /** 129 * Updates all attributes in this diagram associated with a time event. 130 * Ie, all attributes with track information. 188 * Updates all attributes in this diagram associated with a time event. Ie, 189 * all attributes with track information. 190 * 131 191 * @return - true if this node has changed state as a result of the time 132 192 * update … … 139 199 return changeState; 140 200 } 141 201 142 202 //-------------------------------- 143 203 public static final int MARKER_START = 0; … … 147 207 public static class MarkerPos 148 208 { 209 149 210 int type; 150 211 double x; … … 165 226 public static class MarkerLayout 166 227 { 228 167 229 private ArrayList markerList = new ArrayList(); 168 230 boolean started = false; … … 174 236 double[] coords = new double[6]; 175 237 for (PathIterator it = shape.getPathIterator(null); 176 238 !it.isDone(); it.next()) 177 239 { 178 240 switch (it.currentSegment(coords)) … … 202 264 double x = coords[2]; 203 265 double y = coords[3]; 266 267 268 //Best in tangent 269 if (px != k0x || py != k0y) 270 { 271 markerIn(px, py, k0x - px, k0y - py); 272 } else 273 { 274 markerIn(px, py, x - px, y - py); 275 } 276 277 //Best out tangent 278 if (x != k0x || y != k0y) 279 { 280 markerOut(x, y, x - k0x, y - k0y); 281 } else 282 { 283 markerOut(x, y, x - px, y - py); 284 } 285 204 286 markerIn(px, py, k0x - px, k0y - py); 205 287 markerOut(x, y, x - k0x, y - k0y); … … 216 298 double x = coords[4]; 217 299 double y = coords[5]; 218 markerIn(px, py, k0x - px, k0y - py); 219 markerOut(x, y, x - k1x, y - k1y); 300 301 //Best in tangent 302 if (px != k0x || py != k0y) 303 { 304 markerIn(px, py, k0x - px, k0y - py); 305 } else if (px != k1x || py != k1y) 306 { 307 markerIn(px, py, k1x - px, k1y - py); 308 } else 309 { 310 markerIn(px, py, x - px, y - py); 311 } 312 313 //Best out tangent 314 if (x != k1x || y != k1y) 315 { 316 markerOut(x, y, x - k1x, y - k1y); 317 } else if (x != k0x || y != k0y) 318 { 319 markerOut(x, y, x - k0x, y - k0y); 320 } else 321 { 322 markerOut(x, y, x - px, y - py); 323 } 220 324 px = x; 221 325 py = y; … … 227 331 for (int i = 1; i < markerList.size(); ++i) 228 332 { 229 MarkerPos prev = (MarkerPos) markerList.get(i - 1);230 MarkerPos cur = (MarkerPos) markerList.get(i);333 MarkerPos prev = (MarkerPos) markerList.get(i - 1); 334 MarkerPos cur = (MarkerPos) markerList.get(i); 231 335 232 336 if (cur.type == MARKER_START) … … 235 339 } 236 340 } 237 MarkerPos last = (MarkerPos) markerList.get(markerList.size() - 1);341 MarkerPos last = (MarkerPos) markerList.get(markerList.size() - 1); 238 342 last.type = MARKER_END; 239 343 } -
trunk/src/com/kitfox/svg/Metadata.java
r4256 r6002 1 1 /* 2 * Stop.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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 September 19, 2004, 1:56 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 /** 31 * Does not hold any information. 39 * Does not hold any information. Included to allow metadata tag to be parsed. 32 40 * 33 41 * @author Mark McKay 34 42 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 35 43 */ 36 public class Metadata extends SVGElement 44 public class Metadata extends SVGElement 37 45 { 38 /** Creates a new instance of Stop */ 39 public Metadata() { 46 public static final String TAG_NAME = "metadata"; 47 48 /** 49 * Creates a new instance of Stop 50 */ 51 public Metadata() 52 { 53 } 54 55 public String getTagName() 56 { 57 return TAG_NAME; 40 58 } 41 59 -
trunk/src/com/kitfox/svg/MissingGlyph.java
r4256 r6002 1 1 /* 2 * Font.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 February 20, 2004, 10:00 PM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 import com.kitfox.svg.xml.*; 31 32 import java.awt.*; 33 import java.awt.geom.*; 34 import java.util.*; 35 36 import com.kitfox.svg.pathcmd.*; 37 //import org.apache.batik.ext.awt.geom.ExtendedGeneralPath; 38 import com.kitfox.svg.pathcmd.BuildHistory; 39 import com.kitfox.svg.pathcmd.PathCommand; 40 import com.kitfox.svg.xml.StyleAttribute; 41 import java.awt.Graphics2D; 42 import java.awt.Shape; 43 import java.awt.geom.AffineTransform; 44 import java.awt.geom.GeneralPath; 45 import java.awt.geom.Rectangle2D; 46 import java.util.Iterator; 38 47 39 48 /** … … 47 56 public class MissingGlyph extends ShapeElement 48 57 { 58 public static final String TAG_NAME = "missingglyph"; 59 49 60 //We may define a path 50 // ExtendedGeneralPath path = null;51 61 Shape path = null; 52 53 62 //Alternately, we may have child graphical elements 54 55 63 int horizAdvX = -1; //Inherits font's value if not set 56 64 int vertOriginX = -1; //Inherits font's value if not set … … 58 66 int vertAdvY = -1; //Inherits font's value if not set 59 67 60 /** Creates a new instance of Font */ 68 /** 69 * Creates a new instance of Font 70 */ 61 71 public MissingGlyph() 62 72 { 63 73 } 64 /* 65 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 66 { 67 //Load style string 68 super.loaderStartElement(helper, attrs, parent); 74 75 public String getTagName() 76 { 77 return TAG_NAME; 78 } 79 80 /** 81 * Called after the start element but before the end element to indicate 82 * each child tag that has been processed 83 */ 84 public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException 85 { 86 super.loaderAddChild(helper, child); 87 } 88 89 protected void build() throws SVGException 90 { 91 super.build(); 92 93 StyleAttribute sty = new StyleAttribute(); 94 95 String commandList = ""; 96 if (getPres(sty.setName("d"))) 97 { 98 commandList = sty.getStringValue(); 99 } 100 69 101 70 102 //If glyph path was specified, calculate it 71 String commandList = attrs.getValue("d");72 103 if (commandList != null) 73 104 { 74 StyleAttribute atyleAttrib = getStyle("fill-rule"); 75 String fillRule = (atyleAttrib == null) ? "nonzero" : atyleAttrib.getStringValue(); 105 String fillRule = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero"; 76 106 77 107 PathCommand[] commands = parsePathList(commandList); 78 108 79 // ExtendedGeneralPath buildPath = new ExtendedGeneralPath(80 109 GeneralPath buildPath = new GeneralPath( 81 110 fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO, … … 98 127 99 128 //Read glyph spacing info 100 String horizAdvX = attrs.getValue("horiz-adv-x"); 101 String vertOriginX = attrs.getValue("vert-origin-x"); 102 String vertOriginY = attrs.getValue("vert-origin-y"); 103 String vertAdvY = attrs.getValue("vert-adv-y"); 104 105 if (horizAdvX != null) this.horizAdvX = XMLParseUtil.parseInt(horizAdvX); 106 if (vertOriginX != null) this.vertOriginX = XMLParseUtil.parseInt(vertOriginX); 107 if (vertOriginY != null) this.vertOriginY = XMLParseUtil.parseInt(vertOriginY); 108 if (vertAdvY != null) this.vertAdvY = XMLParseUtil.parseInt(vertAdvY); 109 110 } 111 */ 112 /** 113 * Called after the start element but before the end element to indicate 114 * each child tag that has been processed 115 */ 116 public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException 117 { 118 super.loaderAddChild(helper, child); 119 } 120 121 122 protected void build() throws SVGException 123 { 124 super.build(); 125 126 StyleAttribute sty = new StyleAttribute(); 127 128 String commandList = ""; 129 if (getPres(sty.setName("d"))) commandList = sty.getStringValue(); 130 131<