Changeset 6002 in josm for trunk/src/com/kitfox/svg
- Timestamp:
- 2013-06-11T01:01:28+02:00 (11 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 132 //If glyph path was specified, calculate it 133 if (commandList != null) 134 { 135 // StyleAttribute atyleAttrib = getStyle("fill-rule"); 136 String fillRule = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero"; 137 138 PathCommand[] commands = parsePathList(commandList); 139 140 // ExtendedGeneralPath buildPath = new ExtendedGeneralPath( 141 GeneralPath buildPath = new GeneralPath( 142 fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO, 143 commands.length); 144 145 BuildHistory hist = new BuildHistory(); 146 147 for (int i = 0; i < commands.length; i++) 148 { 149 PathCommand cmd = commands[i]; 150 cmd.appendPath(buildPath, hist); 151 } 152 153 //Reflect glyph path to put it in user coordinate system 154 AffineTransform at = new AffineTransform(); 155 at.scale(1, -1); 156 path = at.createTransformedShape(buildPath); 157 } 158 159 160 //Read glyph spacing info 161 if (getPres(sty.setName("horiz-adv-x"))) horizAdvX = sty.getIntValue(); 162 163 if (getPres(sty.setName("vert-origin-x"))) vertOriginX = sty.getIntValue(); 164 165 if (getPres(sty.setName("vert-origin-y"))) vertOriginY = sty.getIntValue(); 166 167 if (getPres(sty.setName("vert-adv-y"))) vertAdvY = sty.getIntValue(); 129 if (getPres(sty.setName("horiz-adv-x"))) 130 { 131 horizAdvX = sty.getIntValue(); 132 } 133 134 if (getPres(sty.setName("vert-origin-x"))) 135 { 136 vertOriginX = sty.getIntValue(); 137 } 138 139 if (getPres(sty.setName("vert-origin-y"))) 140 { 141 vertOriginY = sty.getIntValue(); 142 } 143 144 if (getPres(sty.setName("vert-adv-y"))) 145 { 146 vertAdvY = sty.getIntValue(); 147 } 168 148 } 169 149 … … 177 157 //Do not push or pop stack 178 158 179 if (path != null) renderShape(g, path); 180 159 if (path != null) 160 { 161 renderShape(g, path); 162 } 163 181 164 Iterator it = children.iterator(); 182 165 while (it.hasNext()) 183 166 { 184 SVGElement ele = (SVGElement) it.next();167 SVGElement ele = (SVGElement) it.next(); 185 168 if (ele instanceof RenderableElement) 186 169 { 187 ((RenderableElement) ele).render(g);170 ((RenderableElement) ele).render(g); 188 171 } 189 172 } … … 195 178 { 196 179 if (horizAdvX == -1) 197 horizAdvX = ((Font)parent).getHorizAdvX(); 180 { 181 horizAdvX = ((Font) parent).getHorizAdvX(); 182 } 198 183 return horizAdvX; 199 184 } … … 202 187 { 203 188 if (vertOriginX == -1) 189 { 204 190 vertOriginX = getHorizAdvX() / 2; 191 } 205 192 return vertOriginX; 206 193 } … … 209 196 { 210 197 if (vertOriginY == -1) 211 vertOriginY = ((Font)parent).getFontFace().getAscent(); 198 { 199 vertOriginY = ((Font) parent).getFontFace().getAscent(); 200 } 212 201 return vertOriginY; 213 202 } … … 216 205 { 217 206 if (vertAdvY == -1) 218 vertAdvY = ((Font)parent).getFontFace().getUnitsPerEm(); 207 { 208 vertAdvY = ((Font) parent).getFontFace().getUnitsPerEm(); 209 } 219 210 return vertAdvY; 220 211 … … 223 214 public Shape getShape() 224 215 { 225 if (path != null) return shapeToParent(path); 216 if (path != null) 217 { 218 return shapeToParent(path); 219 } 226 220 return null; 227 221 } … … 229 223 public Rectangle2D getBoundingBox() throws SVGException 230 224 { 231 if (path != null) return boundsToParent(includeStrokeInBounds(path.getBounds2D())); 225 if (path != null) 226 { 227 return boundsToParent(includeStrokeInBounds(path.getBounds2D())); 228 } 232 229 return null; 233 230 } 234 231 235 232 /** 236 * Updates all attributes in this diagram associated with a time event. 237 * Ie, all attributes with track information. 233 * Updates all attributes in this diagram associated with a time event. Ie, 234 * all attributes with track information. 235 * 238 236 * @return - true if this node has changed state as a result of the time 239 237 * update -
trunk/src/com/kitfox/svg/Path.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 java.awt.*; 32 import java.awt.geom.*; 33 34 import com.kitfox.svg.pathcmd.*; 35 import com.kitfox.svg.xml.*; 36 import org.xml.sax.*; 39 import java.awt.Graphics2D; 40 import java.awt.Shape; 41 import java.awt.geom.GeneralPath; 42 import java.awt.geom.Rectangle2D; 37 43 38 44 //import org.apache.batik.ext.awt.geom.ExtendedGeneralPath; 39 40 45 /** 41 46 * @author Mark McKay 42 47 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 43 48 */ 44 public class Path extends ShapeElement { 49 public class Path extends ShapeElement 50 { 45 51 52 public static final String TAG_NAME = "path"; 46 53 // PathCommand[] commands = null; 47 48 54 int fillRule = GeneralPath.WIND_NON_ZERO; 49 55 String d = ""; … … 51 57 GeneralPath path; 52 58 53 /** Creates a new instance of Rect */ 54 public Path() { 59 /** 60 * Creates a new instance of Rect 61 */ 62 public Path() 63 { 55 64 } 56 65 57 /* 58 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 66 public String getTagName() 59 67 { 60 //Load style string 61 super.loaderStartElement(helper, attrs, parent);68 return TAG_NAME; 69 } 62 70 63 StyleAttribute styleAttrib = getStyle("fill-rule");64 String fillRule = (styleAttrib == null) ? "nonzero" : styleAttrib.getStringValue();65 66 String d = attrs.getValue("d");67 path = buildPath(d, fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO);68 }69 */70 71 71 protected void build() throws SVGException 72 72 { 73 73 super.build(); 74 74 75 75 StyleAttribute sty = new StyleAttribute(); 76 77 78 String fillRuleStrn 76 77 78 String fillRuleStrn = (getStyle(sty.setName("fill-rule"))) ? sty.getStringValue() : "nonzero"; 79 79 fillRule = fillRuleStrn.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO; 80 81 // String d = "";82 if (getPres(sty.setName("d"))) d = sty.getStringValue();83 80 84 //System.err.println(d); 85 81 if (getPres(sty.setName("d"))) 82 { 83 d = sty.getStringValue(); 84 } 85 86 86 path = buildPath(d, fillRule); 87 88 //System.err.println(d);89 87 } 90 88 91 89 public void render(Graphics2D g) throws SVGException 92 90 { … … 107 105 108 106 /** 109 * Updates all attributes in this diagram associated with a time event. 110 * Ie, all attributes with track information. 107 * Updates all attributes in this diagram associated with a time event. Ie, 108 * all attributes with track information. 109 * 111 110 * @return - true if this node has changed state as a result of the time 112 111 * update … … 120 119 StyleAttribute sty = new StyleAttribute(); 121 120 boolean shapeChange = false; 122 121 123 122 if (getStyle(sty.setName("fill-rule"))) 124 123 { 125 int newVal = sty.getStringValue().equals("evenodd") 126 ? GeneralPath.WIND_EVEN_ODD 124 int newVal = sty.getStringValue().equals("evenodd") 125 ? GeneralPath.WIND_EVEN_ODD 127 126 : GeneralPath.WIND_NON_ZERO; 128 127 if (newVal != fillRule) … … 132 131 } 133 132 } 134 133 135 134 if (getPres(sty.setName("d"))) 136 135 { … … 142 141 } 143 142 } 144 143 145 144 if (shapeChange) 146 145 { … … 149 148 // return true; 150 149 } 151 150 152 151 return changeState || shapeChange; 153 152 } -
trunk/src/com/kitfox/svg/PatternSVG.java
r4256 r6002 1 1 /* 2 * Gradient.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, 3:25 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 38 import com.kitfox.svg.pattern.PatternPaint; 30 39 import com.kitfox.svg.xml.StyleAttribute; 31 import java.net.*; 32 import java.util.*; 33 import java.awt.geom.*; 34 import java.awt.*; 35 import java.awt.image.*; 36 37 import com.kitfox.svg.pattern.*; 38 import com.kitfox.svg.xml.*; 39 import org.xml.sax.*; 40 import java.awt.Graphics2D; 41 import java.awt.Paint; 42 import java.awt.RenderingHints; 43 import java.awt.TexturePaint; 44 import java.awt.geom.AffineTransform; 45 import java.awt.geom.Point2D; 46 import java.awt.geom.Rectangle2D; 47 import java.awt.image.BufferedImage; 48 import java.net.URI; 49 import java.util.Iterator; 50 import java.util.logging.Level; 51 import java.util.logging.Logger; 40 52 41 53 /** … … 43 55 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 44 56 */ 45 public class PatternSVG extends FillElement { 46 57 public class PatternSVG extends FillElement 58 { 59 public static final String TAG_NAME = "pattern"; 60 47 61 public static final int GU_OBJECT_BOUNDING_BOX = 0; 48 62 public static final int GU_USER_SPACE_ON_USE = 1; 49 50 63 int gradientUnits = GU_OBJECT_BOUNDING_BOX; 51 52 64 float x; 53 65 float y; 54 66 float width; 55 67 float height; 56 57 68 AffineTransform patternXform = new AffineTransform(); 58 69 Rectangle2D.Float viewBox; 59 60 70 Paint texPaint; 61 71 62 /** Creates a new instance of Gradient */ 63 public PatternSVG() { 64 } 65 /* 66 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 67 { 68 //Load style string 69 super.loaderStartElement(helper, attrs, parent); 70 71 String href = attrs.getValue("xlink:href"); 72 //If we have a link to another pattern, initialize ourselves with it's values 73 if (href != null) 74 { 75 //System.err.println("Gradient.loaderStartElement() href '" + href + "'"); 76 try { 77 URI src = getXMLBase().resolve(href); 78 // URL url = srcUrl.toURL(); 79 // URL url = new URL(helper.docRoot, href); 80 PatternSVG patSrc = (PatternSVG)helper.universe.getElement(src); 81 82 gradientUnits = patSrc.gradientUnits; 83 x = patSrc.x; 84 y = patSrc.y; 85 width = patSrc.width; 86 height = patSrc.height; 87 viewBox = patSrc.viewBox; 88 patternXform.setTransform(patSrc.patternXform); 89 members.addAll(patSrc.members); 90 } 91 catch (Exception e) 92 { 93 e.printStackTrace(); 94 } 95 } 96 97 98 String gradientUnits = attrs.getValue("gradientUnits"); 99 100 if (gradientUnits != null) 101 { 102 if (gradientUnits.toLowerCase().equals("userspaceonuse")) this.gradientUnits = GU_USER_SPACE_ON_USE; 103 else this.gradientUnits = GU_OBJECT_BOUNDING_BOX; 104 } 105 106 String patternTransform = attrs.getValue("patternTransform"); 107 if (patternTransform != null) 108 { 109 patternXform = parseTransform(patternTransform); 110 } 111 112 String x = attrs.getValue("x"); 113 String y = attrs.getValue("y"); 114 String width = attrs.getValue("width"); 115 String height = attrs.getValue("height"); 116 117 if (x != null) this.x = XMLParseUtil.parseFloat(x); 118 if (y != null) this.y = XMLParseUtil.parseFloat(y); 119 if (width != null) this.width = XMLParseUtil.parseFloat(width); 120 if (height != null) this.height = XMLParseUtil.parseFloat(height); 121 122 String viewBoxStrn = attrs.getValue("viewBox"); 123 if (viewBoxStrn != null) 124 { 125 float[] dim = XMLParseUtil.parseFloatList(viewBoxStrn); 126 viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]); 127 } 128 } 129 */ 72 /** 73 * Creates a new instance of Gradient 74 */ 75 public PatternSVG() 76 { 77 } 78 79 public String getTagName() 80 { 81 return TAG_NAME; 82 } 83 130 84 /** 131 85 * Called after the start element but before the end element to indicate … … 135 89 { 136 90 super.loaderAddChild(helper, child); 137 138 // members.add(child); 139 } 140 91 } 92 141 93 protected void build() throws SVGException 142 94 { 143 95 super.build(); 144 96 145 97 StyleAttribute sty = new StyleAttribute(); 146 147 98 99 //Load style string 148 100 String href = null; 149 if (getPres(sty.setName("xlink:href"))) href = sty.getStringValue(); 101 if (getPres(sty.setName("xlink:href"))) 102 { 103 href = sty.getStringValue(); 104 } 150 105 //String href = attrs.getValue("xlink:href"); 151 106 //If we have a link to another pattern, initialize ourselves with it's values … … 153 108 { 154 109 //System.err.println("Gradient.loaderStartElement() href '" + href + "'"); 155 try { 110 try 111 { 156 112 URI src = getXMLBase().resolve(href); 157 PatternSVG patSrc = (PatternSVG) diagram.getUniverse().getElement(src);113 PatternSVG patSrc = (PatternSVG) diagram.getUniverse().getElement(src); 158 114 159 115 gradientUnits = patSrc.gradientUnits; … … 165 121 patternXform.setTransform(patSrc.patternXform); 166 122 children.addAll(patSrc.children); 123 } catch (Exception e) 124 { 125 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 126 "Could not parse xlink:href", e); 167 127 } 168 catch (Exception e)169 {170 e.printStackTrace();171 }172 128 } 173 129 174 130 String gradientUnits = ""; 175 if (getPres(sty.setName("gradientUnits"))) gradientUnits = sty.getStringValue().toLowerCase(); 176 if (gradientUnits.equals("userspaceonuse")) this.gradientUnits = GU_USER_SPACE_ON_USE; 177 else this.gradientUnits = GU_OBJECT_BOUNDING_BOX; 131 if (getPres(sty.setName("gradientUnits"))) 132 { 133 gradientUnits = sty.getStringValue().toLowerCase(); 134 } 135 if (gradientUnits.equals("userspaceonuse")) 136 { 137 this.gradientUnits = GU_USER_SPACE_ON_USE; 138 } else 139 { 140 this.gradientUnits = GU_OBJECT_BOUNDING_BOX; 141 } 178 142 179 143 String patternTransform = ""; 180 if (getPres(sty.setName("patternTransform"))) patternTransform = sty.getStringValue(); 144 if (getPres(sty.setName("patternTransform"))) 145 { 146 patternTransform = sty.getStringValue(); 147 } 181 148 patternXform = parseTransform(patternTransform); 182 149 183 184 if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits(); 185 186 if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits(); 187 188 if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits(); 189 190 if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits(); 191 150 151 if (getPres(sty.setName("x"))) 152 { 153 x = sty.getFloatValueWithUnits(); 154 } 155 156 if (getPres(sty.setName("y"))) 157 { 158 y = sty.getFloatValueWithUnits(); 159 } 160 161 if (getPres(sty.setName("width"))) 162 { 163 width = sty.getFloatValueWithUnits(); 164 } 165 166 if (getPres(sty.setName("height"))) 167 { 168 height = sty.getFloatValueWithUnits(); 169 } 170 192 171 if (getPres(sty.setName("viewBox"))) 193 172 { … … 195 174 viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]); 196 175 } 197 176 198 177 preparePattern(); 199 178 } 200 201 /* 202 public void loaderEndElement(SVGLoaderHelper helper) 203 { 204 build(); 205 } 206 */ 207 179 180 /* 181 public void loaderEndElement(SVGLoaderHelper helper) 182 { 183 build(); 184 } 185 */ 208 186 protected void preparePattern() throws SVGException 209 187 { 210 188 //For now, treat all fills as UserSpaceOnUse. Otherwise, we'll need 211 189 // a different paint for every object. 212 int tileWidth = (int) width;213 int tileHeight = (int) height;190 int tileWidth = (int) width; 191 int tileHeight = (int) height; 214 192 215 193 float stretchX = 1f, stretchY = 1f; … … 217 195 { 218 196 //Scale our source tile so that we can have nice sampling from it. 219 float xlateX = (float) patternXform.getTranslateX();220 float xlateY = (float) patternXform.getTranslateY();197 float xlateX = (float) patternXform.getTranslateX(); 198 float xlateY = (float) patternXform.getTranslateY(); 221 199 222 200 Point2D.Float pt = new Point2D.Float(), pt2 = new Point2D.Float(); … … 226 204 pt2.x -= xlateX; 227 205 pt2.y -= xlateY; 228 stretchX = (float) Math.sqrt(pt2.x * pt2.x + pt2.y * pt2.y) * 1.5f / width;206 stretchX = (float) Math.sqrt(pt2.x * pt2.x + pt2.y * pt2.y) * 1.5f / width; 229 207 230 208 pt.setLocation(height, 0); … … 232 210 pt2.x -= xlateX; 233 211 pt2.y -= xlateY; 234 stretchY = (float) Math.sqrt(pt2.x * pt2.x + pt2.y * pt2.y) * 1.5f / height;212 stretchY = (float) Math.sqrt(pt2.x * pt2.x + pt2.y * pt2.y) * 1.5f / height; 235 213 236 214 tileWidth *= stretchX; … … 238 216 } 239 217 240 if (tileWidth == 0 || tileHeight == 0) 218 if (tileWidth == 0 || tileHeight == 0) 241 219 { 242 220 //Use defaults if tile has degenerate size 243 221 return; 244 222 } 245 223 246 224 BufferedImage buf = new BufferedImage(tileWidth, tileHeight, BufferedImage.TYPE_INT_ARGB); 247 225 Graphics2D g = buf.createGraphics(); … … 251 229 for (Iterator it = children.iterator(); it.hasNext();) 252 230 { 253 SVGElement ele = (SVGElement) it.next();231 SVGElement ele = (SVGElement) it.next(); 254 232 if (ele instanceof RenderableElement) 255 233 { … … 259 237 { 260 238 xform.translate(-x, -y); 261 } 262 else 239 } else 263 240 { 264 241 xform.scale(tileWidth / viewBox.width, tileHeight / viewBox.height); … … 267 244 268 245 g.setTransform(xform); 269 ((RenderableElement) ele).render(g);246 ((RenderableElement) ele).render(g); 270 247 } 271 248 } … … 280 257 { 281 258 texPaint = new TexturePaint(buf, new Rectangle2D.Float(x, y, width, height)); 282 } 283 else 259 } else 284 260 { 285 261 patternXform.scale(1 / stretchX, 1 / stretchY); … … 294 270 295 271 /** 296 * Updates all attributes in this diagram associated with a time event. 297 * Ie, all attributes with track information. 272 * Updates all attributes in this diagram associated with a time event. Ie, 273 * all attributes with track information. 274 * 298 275 * @return - true if this node has changed state as a result of the time 299 276 * update -
trunk/src/com/kitfox/svg/Polygon.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 39 import com.kitfox.svg.xml.XMLParseUtil; 32 import java.awt.geom.*; 33 import java.awt.*; 34 35 import com.kitfox.svg.xml.*; 36 import org.xml.sax.*; 40 import java.awt.Graphics2D; 41 import java.awt.Shape; 42 import java.awt.geom.GeneralPath; 43 import java.awt.geom.Rectangle2D; 37 44 38 45 /** … … 40 47 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 41 48 */ 42 public class Polygon extends ShapeElement { 49 public class Polygon extends ShapeElement 50 { 51 public static final String TAG_NAME = "polygon"; 43 52 44 53 int fillRule = GeneralPath.WIND_NON_ZERO; 45 54 String pointsStrn = ""; 46 // float[] points = null;47 55 GeneralPath path; 48 56 49 /** Creates a new instance of Rect */ 50 public Polygon() { 57 /** 58 * Creates a new instance of Rect 59 */ 60 public Polygon() 61 { 51 62 } 52 /* 53 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)63 64 public String getTagName() 54 65 { 55 //Load style string 56 super.loaderStartElement(helper, attrs, parent);66 return TAG_NAME; 67 } 57 68 58 59 points = XMLParseUtil.parseFloatList(attrs.getValue("points"));60 61 build();62 }63 */64 /*65 public void build()66 {67 StyleAttribute styleAttrib = getStyle("fill-rule");68 String fillRule = (styleAttrib == null) ? "nonzero" : styleAttrib.getStringValue();69 70 path = new GeneralPath(71 fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO,72 points.length / 2);73 74 path.moveTo(points[0], points[1]);75 for (int i = 2; i < points.length; i += 2)76 {77 path.lineTo(points[i], points[i + 1]);78 }79 path.closePath();80 }81 */82 83 //static int yyyyy = 0;84 85 69 protected void build() throws SVGException 86 70 { 87 71 super.build(); 88 72 89 73 StyleAttribute sty = new StyleAttribute(); 90 91 if (getPres(sty.setName("points"))) pointsStrn = sty.getStringValue(); 92 74 75 if (getPres(sty.setName("points"))) 76 { 77 pointsStrn = sty.getStringValue(); 78 } 79 93 80 String fillRuleStrn = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero"; 94 81 fillRule = fillRuleStrn.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO; … … 96 83 buildPath(); 97 84 } 98 85 99 86 protected void buildPath() 100 87 { … … 109 96 path.closePath(); 110 97 } 111 98 112 99 public void render(Graphics2D g) throws SVGException 113 100 { … … 116 103 finishLayer(g); 117 104 } 118 119 105 120 106 public Shape getShape() … … 128 114 } 129 115 130 131 116 /** 132 * Updates all attributes in this diagram associated with a time event. 133 * 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 * 134 120 * @return - true if this node has changed state as a result of the time 135 121 * update … … 143 129 StyleAttribute sty = new StyleAttribute(); 144 130 boolean shapeChange = false; 145 131 146 132 if (getStyle(sty.setName("fill-rule"))) 147 133 { 148 int newVal = sty.getStringValue().equals("evenodd") 149 ? GeneralPath.WIND_EVEN_ODD 134 int newVal = sty.getStringValue().equals("evenodd") 135 ? GeneralPath.WIND_EVEN_ODD 150 136 : GeneralPath.WIND_NON_ZERO; 151 137 if (newVal != fillRule) … … 155 141 } 156 142 } 157 143 158 144 if (getPres(sty.setName("points"))) 159 145 { … … 165 151 } 166 152 } 167 168 153 154 169 155 if (shapeChange) 170 156 { … … 173 159 // return true; 174 160 } 175 161 176 162 return changeState || shapeChange; 177 163 } -
trunk/src/com/kitfox/svg/Polyline.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 import java.awt.geom.*; 31 import java.awt.*; 32 33 import com.kitfox.svg.xml.*; 38 import com.kitfox.svg.xml.StyleAttribute; 39 import com.kitfox.svg.xml.XMLParseUtil; 40 import java.awt.Graphics2D; 41 import java.awt.Shape; 42 import java.awt.geom.GeneralPath; 43 import java.awt.geom.Rectangle2D; 34 44 35 45 /** … … 37 47 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 38 48 */ 39 public class Polyline extends ShapeElement { 40 49 public class Polyline extends ShapeElement 50 { 51 public static final String TAG_NAME = "polyline"; 52 41 53 int fillRule = GeneralPath.WIND_NON_ZERO; 42 54 String pointsStrn = ""; 43 // float[] points = null;44 55 GeneralPath path; 45 56 46 /** Creates a new instance of Rect */ 47 public Polyline() { 57 /** 58 * Creates a new instance of Rect 59 */ 60 public Polyline() 61 { 48 62 } 49 63 50 /* 51 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 64 public String getTagName() 52 65 { 53 //Load style string 54 super.loaderStartElement(helper, attrs, parent); 55 56 57 points = XMLParseUtil.parseFloatList(attrs.getValue("points")); 58 59 build(); 66 return TAG_NAME; 60 67 } 61 */62 68 63 69 public void build() throws SVGException 64 70 { 65 71 super.build(); 66 72 67 73 StyleAttribute sty = new StyleAttribute(); 68 69 if (getPres(sty.setName("points"))) pointsStrn = sty.getStringValue(); 70 74 75 if (getPres(sty.setName("points"))) 76 { 77 pointsStrn = sty.getStringValue(); 78 } 79 71 80 String fillRuleStrn = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero"; 72 81 fillRule = fillRuleStrn.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO; … … 74 83 buildPath(); 75 84 } 76 85 77 86 protected void buildPath() 78 87 { … … 105 114 106 115 /** 107 * Updates all attributes in this diagram associated with a time event. 108 * Ie, all attributes with track information. 116 * Updates all attributes in this diagram associated with a time event. Ie, 117 * all attributes with track information. 118 * 109 119 * @return - true if this node has changed state as a result of the time 110 120 * update … … 118 128 StyleAttribute sty = new StyleAttribute(); 119 129 boolean shapeChange = false; 120 130 121 131 if (getStyle(sty.setName("fill-rule"))) 122 132 { 123 int newVal = sty.getStringValue().equals("evenodd") 124 ? GeneralPath.WIND_EVEN_ODD 133 int newVal = sty.getStringValue().equals("evenodd") 134 ? GeneralPath.WIND_EVEN_ODD 125 135 : GeneralPath.WIND_NON_ZERO; 126 136 if (newVal != fillRule) … … 130 140 } 131 141 } 132 142 133 143 if (getPres(sty.setName("points"))) 134 144 { … … 140 150 } 141 151 } 142 143 152 153 144 154 if (shapeChange) 145 155 { … … 148 158 // return true; 149 159 } 150 160 151 161 return changeState || shapeChange; 152 162 } -
trunk/src/com/kitfox/svg/RadialGradient.java
r4256 r6002 1 1 /* 2 * RadialGradient.java 3 * 4 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * 22 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other 23 * projects can be found at http://www.kitfox.com 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or 7 * without modification, are permitted provided that the following 8 * conditions are met: 9 * 10 * - Redistributions of source code must retain the above 11 * copyright notice, this list of conditions and the following 12 * disclaimer. 13 * - Redistributions in binary form must reproduce the above 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials 16 * provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other 32 * projects can be found at http://www.kitfox.com 24 33 * 25 34 * Created on January 26, 2004, 1:55 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 import com.kitfox.svg.xml.StyleAttribute; 31 import java.awt.geom.*; 32 import java.awt.*; 33 34 import com.kitfox.svg.xml.*; 35 import org.xml.sax.*; 36 37 //import org.apache.batik.ext.awt.*; 38 import com.kitfox.svg.batik.*; 39 39 import java.awt.Color; 40 import java.awt.Paint; 41 import java.awt.geom.AffineTransform; 42 import java.awt.geom.Point2D; 43 import java.awt.geom.Rectangle2D; 40 44 41 45 /** … … 43 47 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 44 48 */ 45 public class RadialGradient extends Gradient { 49 public class RadialGradient extends Gradient 50 { 51 public static final String TAG_NAME = "radialgradient"; 46 52 47 53 float cx = 0.5f; … … 51 57 float r = 0.5f; 52 58 53 /** Creates a new instance of RadialGradient */ 54 public RadialGradient() { 55 } 56 /* 57 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 58 { 59 //Load style string 60 super.loaderStartElement(helper, attrs, parent); 61 62 String cx = attrs.getValue("cx"); 63 String cy = attrs.getValue("cy"); 64 String fx = attrs.getValue("fx"); 65 String fy = attrs.getValue("fy"); 66 String r = attrs.getValue("r"); 67 68 if (cx != null) this.cx = (float)XMLParseUtil.parseRatio(cx); 69 if (cy != null) this.cy = (float)XMLParseUtil.parseRatio(cy); 70 if (fx != null) this.fx = (float)XMLParseUtil.parseRatio(fx); 71 if (fy != null) this.fy = (float)XMLParseUtil.parseRatio(fy); 72 if (r != null) this.r = (float)XMLParseUtil.parseRatio(r); 73 } 74 */ 75 76 /* 77 public void loaderEndElement(SVGLoaderHelper helper) 78 { 79 super.loaderEndElement(helper); 80 81 build(); 82 } 59 /** 60 * Creates a new instance of RadialGradient 83 61 */ 84 62 public RadialGradient() 63 { 64 } 65 66 public String getTagName() 67 { 68 return TAG_NAME; 69 } 70 85 71 protected void build() throws SVGException 86 72 { 87 73 super.build(); 88 74 89 75 StyleAttribute sty = new StyleAttribute(); 90 91 if (getPres(sty.setName("cx"))) cx = sty.getFloatValueWithUnits(); 92 93 if (getPres(sty.setName("cy"))) cy = sty.getFloatValueWithUnits(); 94 95 if (getPres(sty.setName("fx"))) fx = sty.getFloatValueWithUnits(); 96 97 if (getPres(sty.setName("fy"))) fy = sty.getFloatValueWithUnits(); 98 99 if (getPres(sty.setName("r"))) r = sty.getFloatValueWithUnits(); 100 } 101 76 77 if (getPres(sty.setName("cx"))) 78 { 79 cx = sty.getFloatValueWithUnits(); 80 } 81 82 if (getPres(sty.setName("cy"))) 83 { 84 cy = sty.getFloatValueWithUnits(); 85 } 86 87 if (getPres(sty.setName("fx"))) 88 { 89 fx = sty.getFloatValueWithUnits(); 90 } 91 92 if (getPres(sty.setName("fy"))) 93 { 94 fy = sty.getFloatValueWithUnits(); 95 } 96 97 if (getPres(sty.setName("r"))) 98 { 99 r = sty.getFloatValueWithUnits(); 100 } 101 } 102 102 103 public Paint getPaint(Rectangle2D bounds, AffineTransform xform) 103 104 { … … 117 118 } 118 119 119 com.kitfox.svg.batik.RadialGradientPaint paint; 120 121 if (gradientUnits == GU_USER_SPACE_ON_USE) 120 Paint paint; 121 Point2D.Float pt1 = new Point2D.Float(cx, cy); 122 Point2D.Float pt2 = new Point2D.Float(fx, fy); 123 if (pt1.equals(pt2)) 124 { 125 Color[] colors = getStopColors(); 126 paint = colors.length > 0 ? colors[0] : Color.black; 127 } else if (gradientUnits == GU_USER_SPACE_ON_USE) 122 128 { 123 129 paint = new com.kitfox.svg.batik.RadialGradientPaint( 124 new Point2D.Float(cx, cy),130 pt1, 125 131 r, 126 new Point2D.Float(fx, fy),132 pt2, 127 133 getStopFractions(), 128 134 getStopColors(), … … 130 136 com.kitfox.svg.batik.MultipleGradientPaint.SRGB, 131 137 gradientTransform); 132 } 133 else 138 } else 134 139 { 135 140 AffineTransform viewXform = new AffineTransform(); … … 140 145 141 146 paint = new com.kitfox.svg.batik.RadialGradientPaint( 142 new Point2D.Float(cx, cy),147 pt1, 143 148 r, 144 new Point2D.Float(fx, fy),149 pt2, 145 150 getStopFractions(), 146 151 getStopColors(), … … 154 159 155 160 /** 156 * Updates all attributes in this diagram associated with a time event. 157 * Ie, all attributes with track information. 161 * Updates all attributes in this diagram associated with a time event. Ie, 162 * all attributes with track information. 163 * 158 164 * @return - true if this node has changed state as a result of the time 159 165 * update … … 167 173 StyleAttribute sty = new StyleAttribute(); 168 174 boolean shapeChange = false; 169 175 170 176 if (getPres(sty.setName("cx"))) 171 177 { … … 177 183 } 178 184 } 179 185 180 186 if (getPres(sty.setName("cy"))) 181 187 { … … 187 193 } 188 194 } 189 195 190 196 if (getPres(sty.setName("fx"))) 191 197 { … … 197 203 } 198 204 } 199 205 200 206 if (getPres(sty.setName("fy"))) 201 207 { … … 207 213 } 208 214 } 209 215 210 216 if (getPres(sty.setName("r"))) 211 217 { … … 217 223 } 218 224 } 219 225 220 226 return changeState; 221 227 } -
trunk/src/com/kitfox/svg/Rect.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 32 import java.awt.*; 33 import java.awt.geom.*; 39 import java.awt.Graphics2D; 40 import java.awt.Shape; 41 import java.awt.geom.Rectangle2D; 42 import java.awt.geom.RectangularShape; 43 import java.awt.geom.RoundRectangle2D; 34 44 import java.io.IOException; 35 45 import java.io.ObjectInputStream; … … 40 50 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 41 51 */ 42 public class Rect extends ShapeElement { 52 public class Rect extends ShapeElement 53 { 54 public static final String TAG_NAME = "rect"; 43 55 44 56 float x = 0f; … … 48 60 float rx = 0f; 49 61 float ry = 0f; 50 51 62 RectangularShape rect; 52 63 53 /** Creates a new instance of Rect */ 54 public Rect() { 55 } 56 57 private void writeObject(ObjectOutputStream out) throws IOException 64 /** 65 * Creates a new instance of Rect 66 */ 67 public Rect() 68 { 69 } 70 71 public String getTagName() 72 { 73 return TAG_NAME; 74 } 75 76 private void writeObject(ObjectOutputStream out) throws IOException 58 77 { 59 78 out.writeFloat(x); … … 64 83 out.writeFloat(ry); 65 84 } 66 85 67 86 private void readObject(ObjectInputStream in) throws IOException 68 87 { … … 73 92 rx = in.readFloat(); 74 93 ry = in.readFloat(); 75 94 76 95 if (rx == 0f && ry == 0f) 77 96 { 78 97 rect = new Rectangle2D.Float(x, y, width, height); 79 } 80 else 98 } else 81 99 { 82 100 rect = new RoundRectangle2D.Float(x, y, width, height, rx * 2, ry * 2); 83 101 } 84 102 } 85 103 86 104 /* 87 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 88 { 89 //Load style string 90 super.loaderStartElement(helper, attrs, parent); 91 92 String x = attrs.getValue("x"); 93 String y = attrs.getValue("y"); 94 String width = attrs.getValue("width"); 95 String height = attrs.getValue("height"); 96 String rx = attrs.getValue("rx"); 97 String ry = attrs.getValue("ry"); 98 99 if (rx == null) rx = ry; 100 if (ry == null) ry = rx; 101 102 this.x = XMLParseUtil.parseFloat(x); 103 this.y = XMLParseUtil.parseFloat(y); 104 this.width = XMLParseUtil.parseFloat(width); 105 this.height = XMLParseUtil.parseFloat(height); 106 if (rx != null) 107 { 108 this.rx = XMLParseUtil.parseFloat(rx); 109 this.ry = XMLParseUtil.parseFloat(ry); 110 } 111 112 build(); 113 // setBounds(this.x, this.y, this.width, this.height); 114 } 115 */ 116 105 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 106 { 107 //Load style string 108 super.loaderStartElement(helper, attrs, parent); 109 110 String x = attrs.getValue("x"); 111 String y = attrs.getValue("y"); 112 String width = attrs.getValue("width"); 113 String height = attrs.getValue("height"); 114 String rx = attrs.getValue("rx"); 115 String ry = attrs.getValue("ry"); 116 117 if (rx == null) rx = ry; 118 if (ry == null) ry = rx; 119 120 this.x = XMLParseUtil.parseFloat(x); 121 this.y = XMLParseUtil.parseFloat(y); 122 this.width = XMLParseUtil.parseFloat(width); 123 this.height = XMLParseUtil.parseFloat(height); 124 if (rx != null) 125 { 126 this.rx = XMLParseUtil.parseFloat(rx); 127 this.ry = XMLParseUtil.parseFloat(ry); 128 } 129 130 build(); 131 // setBounds(this.x, this.y, this.width, this.height); 132 } 133 */ 117 134 protected void build() throws SVGException 118 135 { 119 136 super.build(); 120 137 121 138 StyleAttribute sty = new StyleAttribute(); 122 139 123 140 // SVGElement parent = this.getParent(); 124 141 // if (parent instanceof RenderableElement) … … 128 145 // bounds = null; 129 146 // } 130 131 132 if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits(); 133 134 if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits(); 135 136 if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits(); 137 138 if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits(); 147 148 149 if (getPres(sty.setName("x"))) 150 { 151 x = sty.getFloatValueWithUnits(); 152 } 153 154 if (getPres(sty.setName("y"))) 155 { 156 y = sty.getFloatValueWithUnits(); 157 } 158 159 if (getPres(sty.setName("width"))) 160 { 161 width = sty.getFloatValueWithUnits(); 162 } 163 164 if (getPres(sty.setName("height"))) 165 { 166 height = sty.getFloatValueWithUnits(); 167 } 139 168 140 169 boolean rxSet = false; 141 if (getPres(sty.setName("rx"))) { rx = sty.getFloatValueWithUnits(); rxSet = true; } 142 170 if (getPres(sty.setName("rx"))) 171 { 172 rx = sty.getFloatValueWithUnits(); 173 rxSet = true; 174 } 175 143 176 boolean rySet = false; 144 if (getPres(sty.setName("ry"))) { ry = sty.getFloatValueWithUnits(); rySet = true; } 145 146 if (!rxSet) rx = ry; 147 if (!rySet) ry = rx; 148 149 177 if (getPres(sty.setName("ry"))) 178 { 179 ry = sty.getFloatValueWithUnits(); 180 rySet = true; 181 } 182 183 if (!rxSet) 184 { 185 rx = ry; 186 } 187 if (!rySet) 188 { 189 ry = rx; 190 } 191 192 150 193 if (rx == 0f && ry == 0f) 151 194 { 152 195 rect = new Rectangle2D.Float(x, y, width, height); 153 } 154 else 196 } else 155 197 { 156 198 rect = new RoundRectangle2D.Float(x, y, width, height, rx * 2, ry * 2); … … 176 218 177 219 /** 178 * Updates all attributes in this diagram associated with a time event. 179 * Ie, all attributes with track information. 220 * Updates all attributes in this diagram associated with a time event. Ie, 221 * all attributes with track information. 222 * 180 223 * @return - true if this node has changed state as a result of the time 181 224 * update … … 189 232 StyleAttribute sty = new StyleAttribute(); 190 233 boolean shapeChange = false; 191 234 192 235 if (getPres(sty.setName("x"))) 193 236 { … … 263 306 // return true; 264 307 } 265 308 266 309 return changeState || shapeChange; 267 310 } -
trunk/src/com/kitfox/svg/RenderableElement.java
r4256 r6002 1 1 /* 2 * BoundedElement.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, 9:00 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 … … 38 46 import java.util.List; 39 47 40 41 42 48 /** 43 49 * Maintains bounding box for this element … … 46 52 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 47 53 */ 48 abstract public class RenderableElement extends TransformableElement 54 abstract public class RenderableElement extends TransformableElement 49 55 { 50 51 56 AffineTransform cachedXform = null; 57 52 58 Shape cachedClip = null; 53 54 59 public static final int VECTOR_EFFECT_NONE = 0; 55 60 public static final int VECTOR_EFFECT_NON_SCALING_STROKE = 1; 56 61 int vectorEffect; 57 62 58 /** Creates a new instance of BoundedElement */ 59 public RenderableElement() { 63 /** 64 * Creates a new instance of BoundedElement 65 */ 66 public RenderableElement() 67 { 60 68 } 61 69 … … 68 76 { 69 77 super.build(); 70 78 71 79 StyleAttribute sty = new StyleAttribute(); 72 80 73 81 if (getPres(sty.setName("vector-effect"))) 74 82 { … … 76 84 { 77 85 vectorEffect = VECTOR_EFFECT_NON_SCALING_STROKE; 78 } 79 else 86 } else 80 87 { 81 88 vectorEffect = VECTOR_EFFECT_NONE; 82 89 } 83 } 84 else 90 } else 85 91 { 86 92 vectorEffect = VECTOR_EFFECT_NONE; 87 93 } 88 94 } 89 95 90 96 abstract public void render(Graphics2D g) throws SVGException; 91 97 92 98 abstract void pick(Point2D point, boolean boundingBox, List retVec) throws SVGException; 93 99 94 100 abstract void pick(Rectangle2D pickArea, AffineTransform ltw, boolean boundingBox, List retVec) throws SVGException; 95 101 96 102 abstract public Rectangle2D getBoundingBox() throws SVGException; 97 /* 98 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 99 { 100 super.loaderStartElement(helper, attrs, parent); 101 } 102 */ 103 /* 104 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 105 { 106 super.loaderStartElement(helper, attrs, parent); 107 } 108 */ 109 103 110 /** 104 111 * Pushes transform stack, transforms to local coordinates and sets up … … 114 121 115 122 StyleAttribute styleAttrib = new StyleAttribute(); 116 123 117 124 //Get clipping path 118 125 // StyleAttribute styleAttrib = getStyle("clip-path", false); 119 126 Shape clipPath = null; 120 127 int clipPathUnits = ClipPath.CP_USER_SPACE_ON_USE; 121 if (getStyle(styleAttrib.setName("clip-path"))) 128 if (getStyle(styleAttrib.setName("clip-path"), false) 129 && !"none".equals(styleAttrib.getStringValue())) 122 130 { 123 131 URI uri = styleAttrib.getURIValue(getXMLBase()); 124 132 if (uri != null) 125 133 { 126 ClipPath ele = (ClipPath) diagram.getUniverse().getElement(uri);134 ClipPath ele = (ClipPath) diagram.getUniverse().getElement(uri); 127 135 clipPath = ele.getClipPathShape(); 128 136 clipPathUnits = ele.getClipPathUnits(); … … 135 143 if (clipPathUnits == ClipPath.CP_OBJECT_BOUNDING_BOX && (this instanceof ShapeElement)) 136 144 { 137 Rectangle2D rect = ((ShapeElement) this).getBoundingBox();145 Rectangle2D rect = ((ShapeElement) this).getBoundingBox(); 138 146 AffineTransform at = new AffineTransform(); 139 147 at.scale(rect.getWidth(), rect.getHeight()); … … 142 150 143 151 cachedClip = g.getClip(); 144 Area newClip = new Area(cachedClip); 145 newClip.intersect(new Area(clipPath)); 146 g.setClip(newClip); 152 if (cachedClip == null) 153 { 154 g.setClip(clipPath); 155 } else 156 { 157 Area newClip = new Area(cachedClip); 158 newClip.intersect(new Area(clipPath)); 159 g.setClip(newClip); 160 } 147 161 } 148 162 } 149 163 150 164 /** 151 * Restores transform and clipping values to the way they were before 152 * thislayer was drawn.165 * Restores transform and clipping values to the way they were before this 166 * layer was drawn. 153 167 */ 154 168 protected void finishLayer(Graphics2D g) … … 164 178 } 165 179 } 166 167 180 } -
trunk/src/com/kitfox/svg/SVGCache.java
r4256 r6002 1 1 /* 2 * SVGUniverseSingleton.java 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 3 33 * 4 34 * Created on April 2, 2005, 1:54 AM -
trunk/src/com/kitfox/svg/SVGDiagram.java
r4256 r6002 1 1 /* 2 * SVGDiagram.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 18, 2004, 5:04 PM … … 38 47 import java.util.HashMap; 39 48 import java.util.List; 49 import java.util.logging.Level; 50 import java.util.logging.Logger; 40 51 41 52 … … 203 214 { 204 215 this.root = root; 216 root.setDiagram(this); 205 217 } 206 218 … … 239 251 } catch (SVGException ex) 240 252 { 241 ex.printStackTrace(); 253 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 254 "Could not build document", ex); 242 255 } 243 256 } -
trunk/src/com/kitfox/svg/SVGDisplayPanel.java
r4256 r6002 1 1 /* 2 * SVGDisplayPanel.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, 12:29 PM … … 31 40 import java.awt.*; 32 41 import java.awt.geom.*; 42 import java.util.logging.Level; 43 import java.util.logging.Logger; 33 44 34 45 /** … … 124 135 catch (SVGException e) 125 136 { 126 e.printStackTrace(); 137 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 138 "Could not render diagram", e); 127 139 } 128 140 } -
trunk/src/com/kitfox/svg/SVGElement.java
r4256 r6002 1 1 /* 2 * SVGElement.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:59 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 import java.util.*; 31 import java.util.regex.*; 32 import java.net.*; 33 import java.awt.geom.*; 34 35 import org.xml.sax.*; 36 import com.kitfox.svg.pathcmd.*; 37 import com.kitfox.svg.xml.*; 38 import com.kitfox.svg.pathcmd.Arc; 39 import com.kitfox.svg.pathcmd.BuildHistory; 40 import com.kitfox.svg.pathcmd.Cubic; 41 import com.kitfox.svg.pathcmd.CubicSmooth; 42 import com.kitfox.svg.pathcmd.Horizontal; 43 import com.kitfox.svg.pathcmd.LineTo; 44 import com.kitfox.svg.pathcmd.MoveTo; 45 import com.kitfox.svg.pathcmd.PathCommand; 46 import com.kitfox.svg.pathcmd.Quadratic; 47 import com.kitfox.svg.pathcmd.QuadraticSmooth; 48 import com.kitfox.svg.pathcmd.Terminal; 49 import com.kitfox.svg.pathcmd.Vertical; 50 import com.kitfox.svg.xml.StyleAttribute; 51 import com.kitfox.svg.xml.StyleSheet; 52 import com.kitfox.svg.xml.XMLParseUtil; 53 import java.awt.geom.AffineTransform; 54 import java.awt.geom.GeneralPath; 38 55 import java.io.Serializable; 56 import java.net.URI; 57 import java.util.ArrayList; 58 import java.util.Collections; 59 import java.util.HashMap; 60 import java.util.HashSet; 61 import java.util.Iterator; 62 import java.util.LinkedList; 63 import java.util.List; 64 import java.util.Set; 65 import java.util.regex.Matcher; 66 import java.util.regex.Pattern; 67 import org.xml.sax.Attributes; 68 import org.xml.sax.SAXException; 69 39 70 40 71 /** … … 44 75 abstract public class SVGElement implements Serializable 45 76 { 77 46 78 public static final long serialVersionUID = 0; 47 48 79 public static final String SVG_NS = "http://www.w3.org/2000/svg"; 49 50 80 protected SVGElement parent = null; 51 52 81 protected final ArrayList children = new ArrayList(); 53 54 82 protected String id = null; 55 83 /** 56 * CSS class. 84 * CSS class. Used for applying style sheet information. 57 85 */ 58 86 protected String cssClass = null; 59 60 87 /** 61 88 * Styles defined for this elemnt via the <b>style</b> attribute. 62 89 */ 63 90 protected final HashMap inlineStyles = new HashMap(); 64 65 /** 66 * Presentation attributes set for this element. Ie, any attribute other 91 /** 92 * Presentation attributes set for this element. Ie, any attribute other 67 93 * than the <b>style</b> attribute. 68 94 */ 69 95 protected final HashMap presAttribs = new HashMap(); 70 71 96 /** 72 97 * A list of presentation attributes to not include in the presentation … … 74 99 */ 75 100 protected static final Set ignorePresAttrib; 101 76 102 static 77 103 { … … 81 107 // set.add("style"); 82 108 // set.add("xml:base"); 83 109 84 110 ignorePresAttrib = Collections.unmodifiableSet(set); 85 111 } 86 87 /** 88 * This element may override the URI we resolve against with an 89 * xml:base attribute. If so, a copy is placed here. Otherwise, we defer 90 * to our parent for the reolution base 112 /** 113 * This element may override the URI we resolve against with an xml:base 114 * attribute. If so, a copy is placed here. Otherwise, we defer to our 115 * parent for the reolution base 91 116 */ 92 117 protected URI xmlBase = null; 93 94 118 /** 95 119 * The diagram this element belongs to 96 120 */ 97 121 protected SVGDiagram diagram; 98 /**99 * Link to the universe we reside in100 */101 // protected SVGUniverse universe;102 103 122 boolean dirty = true; 104 123 105 // public static final Matcher adobeId = Pattern.compile("(.*)_1_").matcher(""); 106 // static final String fpNumRe = "[-+]?((\\d+)|(\\d*\\.\\d+))([-+]?[eE]\\d+)?"; 107 108 /** Creates a new instance of SVGElement */ 124 /** 125 * Creates a new instance of SVGElement 126 */ 109 127 public SVGElement() 110 128 { 111 129 this(null, null, null); 112 130 } 113 131 114 132 public SVGElement(String id, SVGElement parent) 115 133 { 116 134 this(id, null, parent); 117 135 } 118 136 119 137 public SVGElement(String id, String cssClass, SVGElement parent) 120 138 { … … 123 141 this.parent = parent; 124 142 } 125 143 144 abstract public String getTagName(); 145 126 146 public SVGElement getParent() 127 147 { 128 148 return parent; 129 149 } 130 150 131 151 void setParent(SVGElement parent) 132 152 { 133 153 this.parent = parent; 134 154 } 135 155 136 156 /** 137 157 * @return an ordered list of nodes from the root of the tree to this node … … 139 159 public List getPath(List retVec) 140 160 { 141 if (retVec == null) retVec = new ArrayList(); 142 161 if (retVec == null) 162 { 163 retVec = new ArrayList(); 164 } 165 143 166 if (parent != null) 144 167 { … … 146 169 } 147 170 retVec.add(this); 148 171 149 172 return retVec; 150 173 } 151 152 /** 153 * @param retVec - A list to add all children to. 174 175 /** 176 * @param retVec - A list to add all children to. If null, a new list is 154 177 * created and children of this group are added. 155 178 * … … 158 181 public List getChildren(List retVec) 159 182 { 160 if (retVec == null) retVec = new ArrayList(); 161 183 if (retVec == null) 184 { 185 retVec = new ArrayList(); 186 } 187 162 188 retVec.addAll(children); 163 189 164 190 return retVec; 165 191 } 166 192 167 193 /** 168 194 * @param id - Id of svg element to return … … 173 199 for (Iterator it = children.iterator(); it.hasNext();) 174 200 { 175 SVGElement ele = (SVGElement) it.next();201 SVGElement ele = (SVGElement) it.next(); 176 202 String eleId = ele.getId(); 177 if (eleId != null && eleId.equals(id)) return ele; 178 } 179 203 if (eleId != null && eleId.equals(id)) 204 { 205 return ele; 206 } 207 } 208 180 209 return null; 181 210 } 182 183 /** 184 * Searches children for given element. 211 212 /** 213 * Searches children for given element. If found, returns index of child. 185 214 * Otherwise returns -1. 186 215 */ … … 189 218 return children.indexOf(child); 190 219 } 191 220 192 221 /** 193 222 * Swaps 2 elements in children. 223 * 194 224 * @i index of first 195 225 * @j index of second … … 203 233 return; 204 234 } 205 235 206 236 Object temp = children.get(i); 207 237 children.set(i, children.get(j)); … … 209 239 build(); 210 240 } 211 212 /** 213 * Called during SAX load process to notify that this tag has begun the process 214 * of being loaded 241 242 /** 243 * Called during SAX load process to notify that this tag has begun the 244 * process of being loaded 245 * 215 246 * @param attrs - Attributes of this tag 216 * @param helper - An object passed to all SVG elements involved in this build217 * process to aid in sharing information.247 * @param helper - An object passed to all SVG elements involved in this 248 * build process to aid in sharing information. 218 249 */ 219 250 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) throws SAXException … … 222 253 this.parent = parent; 223 254 this.diagram = helper.diagram; 224 255 225 256 this.id = attrs.getValue("id"); 226 257 if (this.id != null && !this.id.equals("")) … … 228 259 diagram.setElement(this.id, this); 229 260 } 230 261 231 262 String className = attrs.getValue("class"); 232 263 this.cssClass = (className == null || className.equals("")) ? null : className; 233 264 //docRoot = helper.docRoot; 234 265 //universe = helper.universe; 235 266 236 267 //Parse style string, if any 237 268 String style = attrs.getValue("style"); … … 240 271 HashMap map = XMLParseUtil.parseStyle(style, inlineStyles); 241 272 } 242 273 243 274 String base = attrs.getValue("xml:base"); 244 275 if (base != null && !base.equals("")) … … 247 278 { 248 279 xmlBase = new URI(base); 249 } 250 catch (Exception e) 280 } catch (Exception e) 251 281 { 252 282 throw new SAXException(e); 253 283 } 254 284 } 255 285 256 286 //Place all other attributes into the presentation attribute list 257 287 int numAttrs = attrs.getLength(); … … 259 289 { 260 290 String name = attrs.getQName(i); 261 if (ignorePresAttrib.contains(name)) continue; 291 if (ignorePresAttrib.contains(name)) 292 { 293 continue; 294 } 262 295 String value = attrs.getValue(i); 263 296 264 297 presAttribs.put(name, new StyleAttribute(name, value)); 265 298 } 266 299 } 267 300 268 301 /** 269 302 * @return a set of Strings that corespond to CSS attributes on this element … … 273 306 return inlineStyles.keySet(); 274 307 } 275 308 276 309 /** 277 310 * @return a set of Strings that corespond to XML attributes on this element … … 281 314 return presAttribs.keySet(); 282 315 } 283 316 284 317 /** 285 318 * Called after the start element but before the end element to indicate … … 292 325 child.setDiagram(diagram); 293 326 } 294 295 pr ivatevoid setDiagram(SVGDiagram diagram)327 328 protected void setDiagram(SVGDiagram diagram) 296 329 { 297 330 this.diagram = diagram; … … 299 332 for (Iterator it = children.iterator(); it.hasNext();) 300 333 { 301 SVGElement ele = (SVGElement) it.next();334 SVGElement ele = (SVGElement) it.next(); 302 335 ele.setDiagram(diagram); 303 336 } 304 337 } 305 338 306 339 public void removeChild(SVGElement child) throws SVGElementException 307 340 { … … 310 343 throw new SVGElementException(this, "Element does not contain child " + child); 311 344 } 312 345 313 346 children.remove(child); 314 347 } 315 348 316 349 /** 317 350 * Called during load process to add text scanned within a tag … … 320 353 { 321 354 } 322 323 /** 324 * Called to indicate that this tag and the tags it contains have been completely325 * processed, and that it should finish any load processes.355 356 /** 357 * Called to indicate that this tag and the tags it contains have been 358 * completely processed, and that it should finish any load processes. 326 359 */ 327 360 public void loaderEndElement(SVGLoaderHelper helper) throws SVGParseException 328 361 { 329 try330 {331 build();332 }333 catch (SVGException se)334 {335 throw new SVGParseException(se);336 }337 } 338 339 /** 340 * Called by internal processes to rebuild the geometry of this node 341 * fromit's presentation attributes, style attributes and animated tracks.362 // try 363 // { 364 // build(); 365 // } 366 // catch (SVGException se) 367 // { 368 // throw new SVGParseException(se); 369 // } 370 } 371 372 /** 373 * Called by internal processes to rebuild the geometry of this node from 374 * it's presentation attributes, style attributes and animated tracks. 342 375 */ 343 376 protected void build() throws SVGException 344 377 { 345 378 StyleAttribute sty = new StyleAttribute(); 346 379 347 380 if (getPres(sty.setName("id"))) 348 381 { … … 355 388 } 356 389 } 357 if (getPres(sty.setName("class"))) cssClass = sty.getStringValue(); 358 if (getPres(sty.setName("xml:base"))) xmlBase = sty.getURIValue(); 359 } 360 390 if (getPres(sty.setName("class"))) 391 { 392 cssClass = sty.getStringValue(); 393 } 394 if (getPres(sty.setName("xml:base"))) 395 { 396 xmlBase = sty.getURIValue(); 397 } 398 399 //Build children 400 for (int i = 0; i < children.size(); ++i) 401 { 402 SVGElement ele = (SVGElement) children.get(i); 403 ele.build(); 404 } 405 } 406 361 407 public URI getXMLBase() 362 408 { 363 return xmlBase != null ? xmlBase :364 (parent != null ? parent.getXMLBase() : diagram.getXMLBase());365 } 366 367 /** 368 * @return the id assigned to this node. 409 return xmlBase != null ? xmlBase 410 : (parent != null ? parent.getXMLBase() : diagram.getXMLBase()); 411 } 412 413 /** 414 * @return the id assigned to this node. Null if no id explicitly set. 369 415 */ 370 416 public String getId() 371 417 { 372 return id; 373 } 374 375 418 return id; 419 } 376 420 LinkedList contexts = new LinkedList(); 377 378 /** 379 * Hack to allow nodes to temporarily change their parents. 421 422 /** 423 * Hack to allow nodes to temporarily change their parents. The Use tag will 380 424 * need this so it can alter the attributes that a particular node uses. 381 425 */ … … 387 431 protected SVGElement popParentContext() 388 432 { 389 return (SVGElement) contexts.removeLast();390 } 391 433 return (SVGElement) contexts.removeLast(); 434 } 435 392 436 protected SVGElement getParentContext() 393 437 { 394 return contexts.isEmpty() ? null : (SVGElement)contexts.getLast(); 395 } 396 438 return contexts.isEmpty() ? null : (SVGElement) contexts.getLast(); 439 } 440 441 public SVGRoot getRoot() 442 { 443 return parent == null ? null : parent.getRoot(); 444 } 445 397 446 /* 398 447 * Returns the named style attribute. Checks for inline styles first, then … … 408 457 return getStyle(attrib, true); 409 458 } 410 411 /** 412 * Copies the current style into the passed style attribute. Checks for 413 * inline styles first, then internal and extranal style sheets, and 414 * finally checks for presentation attributes. Recursively checks parents. 415 * @param attrib - Attribute to write style data to. Must have it's name 416 * set to the name of the style being queried. 417 * @param recursive - If true and this object does not contain the 418 * named style attribute, checks attributes of parents abck to root until 419 * one found. 459 460 /** 461 * Copies the current style into the passed style attribute. Checks for 462 * inline styles first, then internal and extranal style sheets, and finally 463 * checks for presentation attributes. Recursively checks parents. 464 * 465 * @param attrib - Attribute to write style data to. Must have it's name set 466 * to the name of the style being queried. 467 * @param recursive - If true and this object does not contain the named 468 * style attribute, checks attributes of parents back to root until one 469 * found. 420 470 */ 421 471 public boolean getStyle(StyleAttribute attrib, boolean recursive) throws SVGException 422 472 { 423 473 String styName = attrib.getName(); 424 474 425 475 //Check for local inline styles 426 476 StyleAttribute styAttr = (StyleAttribute)inlineStyles.get(styName); 427 477 428 478 attrib.setStringValue(styAttr == null ? "" : styAttr.getStringValue()); 429 479 430 480 //Return if we've found a non animated style 431 if (styAttr != null) return true;432 433 434 435 //Implement style sheet lookup later 436 481 if (styAttr != null) 482 { 483 return true; 484 } 485 486 437 487 //Check for presentation attribute 438 488 StyleAttribute presAttr = (StyleAttribute)presAttribs.get(styName); 439 489 440 490 attrib.setStringValue(presAttr == null ? "" : presAttr.getStringValue()); 441 491 442 492 //Return if we've found a presentation attribute instead 443 if (presAttr != null) return true; 444 445 493 if (presAttr != null) 494 { 495 return true; 496 } 497 498 //Check for style sheet 499 SVGRoot root = getRoot(); 500 if (root != null) 501 { 502 StyleSheet ss = root.getStyleSheet(); 503 if (ss != null) 504 { 505 return ss.getStyle(attrib, getTagName(), cssClass); 506 } 507 } 508 446 509 //If we're recursive, check parents 447 510 if (recursive) 448 511 { 449 512 SVGElement parentContext = getParentContext(); 450 if (parentContext != null) return parentContext.getStyle(attrib, true); 451 if (parent != null) return parent.getStyle(attrib, true); 452 } 453 513 if (parentContext != null) 514 { 515 return parentContext.getStyle(attrib, true); 516 } 517 if (parent != null) 518 { 519 return parent.getStyle(attrib, true); 520 } 521 } 522 454 523 //Unsuccessful reading style attribute 455 524 return false; 456 525 } 457 458 /** 459 * @return the raw style value of this attribute. Does not take the460 * presentation value or animation into consideration. Used by animations461 * todetermine the base to animate from.526 527 /** 528 * @return the raw style value of this attribute. Does not take the 529 * presentation value or animation into consideration. Used by animations to 530 * determine the base to animate from. 462 531 */ 463 532 public StyleAttribute getStyleAbsolute(String styName) 464 533 { 465 534 //Check for local inline styles 466 return (StyleAttribute) inlineStyles.get(styName);467 } 468 535 return (StyleAttribute) inlineStyles.get(styName); 536 } 537 469 538 /** 470 539 * Copies the presentation attribute into the passed one. 540 * 471 541 * @return - True if attribute was read successfully 472 542 */ … … 474 544 { 475 545 String presName = attrib.getName(); 476 546 477 547 //Make sure we have a coresponding presentation attribute 478 StyleAttribute presAttr = (StyleAttribute) presAttribs.get(presName);479 548 StyleAttribute presAttr = (StyleAttribute) presAttribs.get(presName); 549 480 550 //Copy presentation value directly 481 551 attrib.setStringValue(presAttr == null ? "" : presAttr.getStringValue()); 482 552 483 553 //Return if we found presentation attribute 484 if (presAttr != null) return true; 485 554 if (presAttr != null) 555 { 556 return true; 557 } 558 486 559 return false; 487 560 } 488 489 /** 490 * @return the raw presentation value of this attribute. Ignores any491 * modifications applied by style attributes or animation. Used by561 562 /** 563 * @return the raw presentation value of this attribute. Ignores any 564 * modifications applied by style attributes or animation. Used by 492 565 * animations to determine the starting point to animate from 493 566 */ … … 495 568 { 496 569 //Check for local inline styles 497 return (StyleAttribute) presAttribs.get(styName);498 } 499 570 return (StyleAttribute) presAttribs.get(styName); 571 } 572 500 573 static protected AffineTransform parseTransform(String val) throws SVGException 501 574 { 502 575 final Matcher matchExpression = Pattern.compile("\\w+\\([^)]*\\)").matcher(""); 503 576 504 577 AffineTransform retXform = new AffineTransform(); 505 578 506 579 matchExpression.reset(val); 507 580 while (matchExpression.find()) … … 509 582 retXform.concatenate(parseSingleTransform(matchExpression.group())); 510 583 } 511 584 512 585 return retXform; 513 586 } 514 587 515 588 static public AffineTransform parseSingleTransform(String val) throws SVGException 516 589 { 517 590 final Matcher matchWord = Pattern.compile("[-.\\w]+").matcher(""); 518 591 519 592 AffineTransform retXform = new AffineTransform(); 520 593 521 594 matchWord.reset(val); 522 595 if (!matchWord.find()) … … 525 598 return retXform; 526 599 } 527 600 528 601 String function = matchWord.group().toLowerCase(); 529 602 530 603 LinkedList termList = new LinkedList(); 531 604 while (matchWord.find()) … … 533 606 termList.add(matchWord.group()); 534 607 } 535 536 608 609 537 610 double[] terms = new double[termList.size()]; 538 611 Iterator it = termList.iterator(); … … 540 613 while (it.hasNext()) 541 614 { 542 terms[count++] = XMLParseUtil.parseDouble((String) it.next());543 } 544 615 terms[count++] = XMLParseUtil.parseDouble((String) it.next()); 616 } 617 545 618 //Calculate transformation 546 619 if (function.equals("matrix")) 547 620 { 548 621 retXform.setTransform(terms[0], terms[1], terms[2], terms[3], terms[4], terms[5]); 549 } 550 else if (function.equals("translate")) 551 { 552 retXform.setToTranslation(terms[0], terms[1]); 553 } 554 else if (function.equals("scale")) 622 } else if (function.equals("translate")) 623 { 624 if (terms.length == 1) 625 { 626 retXform.setToTranslation(terms[0], 0); 627 } else 628 { 629 retXform.setToTranslation(terms[0], terms[1]); 630 } 631 } else if (function.equals("scale")) 555 632 { 556 633 if (terms.length > 1) 634 { 557 635 retXform.setToScale(terms[0], terms[1]); 558 else 636 } else 637 { 559 638 retXform.setToScale(terms[0], terms[0]); 560 }561 else if (function.equals("rotate"))639 } 640 } else if (function.equals("rotate")) 562 641 { 563 642 if (terms.length > 2) 643 { 564 644 retXform.setToRotation(Math.toRadians(terms[0]), terms[1], terms[2]); 565 else 645 } else 646 { 566 647 retXform.setToRotation(Math.toRadians(terms[0])); 567 }568 else if (function.equals("skewx"))648 } 649 } else if (function.equals("skewx")) 569 650 { 570 651 retXform.setToShear(Math.toRadians(terms[0]), 0.0); 571 } 572 else if (function.equals("skewy")) 652 } else if (function.equals("skewy")) 573 653 { 574 654 retXform.setToShear(0.0, Math.toRadians(terms[0])); 575 } 576 else 655 } else 577 656 { 578 657 throw new SVGException("Unknown transform type"); 579 658 } 580 659 581 660 return retXform; 582 661 } 583 662 584 663 static protected float nextFloat(LinkedList l) 585 664 { 586 String s = (String) l.removeFirst();665 String s = (String) l.removeFirst(); 587 666 return Float.parseFloat(s); 588 667 } 589 668 590 669 static protected PathCommand[] parsePathList(String list) 591 670 { 592 671 final Matcher matchPathCmd = Pattern.compile("([MmLlHhVvAaQqTtCcSsZz])|([-+]?((\\d*\\.\\d+)|(\\d+))([eE][-+]?\\d+)?)").matcher(list); 593 672 594 673 //Tokenize 595 674 LinkedList tokens = new LinkedList(); … … 598 677 tokens.addLast(matchPathCmd.group()); 599 678 } 600 601 679 680 602 681 boolean defaultRelative = false; 603 682 LinkedList cmdList = new LinkedList(); … … 605 684 while (tokens.size() != 0) 606 685 { 607 String curToken = (String) tokens.removeFirst();686 String curToken = (String) tokens.removeFirst(); 608 687 char initChar = curToken.charAt(0); 609 if ((initChar >= 'A' && initChar <= 'Z') || (initChar >= 'a' && initChar <='z'))688 if ((initChar >= 'A' && initChar <= 'Z') || (initChar >= 'a' && initChar <= 'z')) 610 689 { 611 690 curCmd = initChar; 612 } 613 else 691 } else 614 692 { 615 693 tokens.addFirst(curToken); 616 694 } 617 695 618 696 PathCommand cmd = null; 619 697 620 698 switch (curCmd) 621 699 { … … 648 726 case 'A': 649 727 cmd = new Arc(false, nextFloat(tokens), nextFloat(tokens), 650 651 652 728 nextFloat(tokens), 729 nextFloat(tokens) == 1f, nextFloat(tokens) == 1f, 730 nextFloat(tokens), nextFloat(tokens)); 653 731 break; 654 732 case 'a': 655 733 cmd = new Arc(true, nextFloat(tokens), nextFloat(tokens), 656 657 658 734 nextFloat(tokens), 735 nextFloat(tokens) == 1f, nextFloat(tokens) == 1f, 736 nextFloat(tokens), nextFloat(tokens)); 659 737 break; 660 738 case 'Q': 661 739 cmd = new Quadratic(false, nextFloat(tokens), nextFloat(tokens), 662 740 nextFloat(tokens), nextFloat(tokens)); 663 741 break; 664 742 case 'q': 665 743 cmd = new Quadratic(true, nextFloat(tokens), nextFloat(tokens), 666 744 nextFloat(tokens), nextFloat(tokens)); 667 745 break; 668 746 case 'T': … … 674 752 case 'C': 675 753 cmd = new Cubic(false, nextFloat(tokens), nextFloat(tokens), 676 677 754 nextFloat(tokens), nextFloat(tokens), 755 nextFloat(tokens), nextFloat(tokens)); 678 756 break; 679 757 case 'c': 680 758 cmd = new Cubic(true, nextFloat(tokens), nextFloat(tokens), 681 682 759 nextFloat(tokens), nextFloat(tokens), 760 nextFloat(tokens), nextFloat(tokens)); 683 761 break; 684 762 case 'S': 685 763 cmd = new CubicSmooth(false, nextFloat(tokens), nextFloat(tokens), 686 764 nextFloat(tokens), nextFloat(tokens)); 687 765 break; 688 766 case 's': 689 767 cmd = new CubicSmooth(true, nextFloat(tokens), nextFloat(tokens), 690 768 nextFloat(tokens), nextFloat(tokens)); 691 769 break; 692 770 case 'Z': … … 697 775 throw new RuntimeException("Invalid path element"); 698 776 } 699 777 700 778 cmdList.add(cmd); 701 779 defaultRelative = cmd.isRelative; 702 780 } 703 781 704 782 PathCommand[] retArr = new PathCommand[cmdList.size()]; 705 783 cmdList.toArray(retArr); 706 784 return retArr; 707 785 } 708 786 709 787 static protected GeneralPath buildPath(String text, int windingRule) 710 788 { 711 789 PathCommand[] commands = parsePathList(text); 712 790 713 791 int numKnots = 2; 714 792 for (int i = 0; i < commands.length; i++) … … 716 794 numKnots += commands[i].getNumKnotsAdded(); 717 795 } 718 719 796 797 720 798 GeneralPath path = new GeneralPath(windingRule, numKnots); 721 799 722 800 BuildHistory hist = new BuildHistory(); 723 801 724 802 for (int i = 0; i < commands.length; i++) 725 803 { … … 727 805 cmd.appendPath(path, hist); 728 806 } 729 807 730 808 return path; 731 809 } 732 733 734 735 /** 736 * Updates all attributes in this diagram associated with a time event. 737 * Ie, all attributes with track information. 810 811 /** 812 * Updates all attributes in this diagram associated with a time event. Ie, 813 * all attributes with track information. 814 * 738 815 * @return - true if this node has changed state as a result of the time 739 816 * update … … 748 825 public SVGElement getChild(int i) 749 826 { 750 return (SVGElement)children.get(i); 751 } 752 827 return (SVGElement) children.get(i); 828 } 829 830 public double lerp(double t0, double t1, double alpha) 831 { 832 return (1 - alpha) * t0 + alpha * t1; 833 } 753 834 } -
trunk/src/com/kitfox/svg/SVGElementException.java
r4256 r6002 1 1 /* 2 * SVGException.java 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 3 33 * 4 34 * Created on May 12, 2005, 11:32 PM 5 *6 * To change this template, choose Tools | Options and locate the template under7 * the Source Creation and Management node. Right-click the template and choose8 * Open. You can then make changes to the template in the Source Editor.9 35 */ 10 36 -
trunk/src/com/kitfox/svg/SVGException.java
r4256 r6002 1 1 /* 2 * SVGException.java 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 3 33 * 4 34 * Created on May 12, 2005, 11:32 PM 5 *6 * To change this template, choose Tools | Options and locate the template under7 * the Source Creation and Management node. Right-click the template and choose8 * Open. You can then make changes to the template in the Source Editor.9 35 */ 10 36 -
trunk/src/com/kitfox/svg/SVGLoader.java
r4256 r6002 1 1 /* 2 * SVGLoader.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 18, 2004, 5:09 PM … … 33 42 import org.xml.sax.*; 34 43 import org.xml.sax.helpers.DefaultHandler; 44 45 import java.util.logging.Level; 46 import java.util.logging.Logger; 35 47 36 48 /** … … 186 198 catch (Exception e) 187 199 { 188 e.printStackTrace(); 200 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 201 "Could not load", e); 189 202 throw new SAXException(e); 190 203 } … … 222 235 223 236 SVGElement parent = null; 224 if (buildStack.size() != 0) parent = (SVGElement)buildStack.getLast(); 237 if (buildStack.size() != 0) 238 { 239 parent = (SVGElement)buildStack.getLast(); 240 } 225 241 //else loadRoot = (SVGElement)svgEle; 226 242 227 if (parent != null) parent.loaderAddChild(helper, svgEle); 228 else diagram.setRoot((SVGRoot)svgEle); 243 if (parent != null) 244 { 245 parent.loaderAddChild(helper, svgEle); 246 } 247 else 248 { 249 diagram.setRoot((SVGRoot)svgEle); 250 } 229 251 230 252 } 231 253 catch (Exception e) 232 254 { 233 e.printStackTrace(); 255 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 256 "Could not parse", e); 234 257 throw new SAXException(e); 235 258 } -
trunk/src/com/kitfox/svg/SVGLoaderHelper.java
r4256 r6002 1 1 /* 2 * SVGLoaderHelper.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 18, 2004, 5:37 PM … … 47 56 48 57 public final URI xmlBase; 49 58 50 59 /** Creates a new instance of SVGLoaderHelper */ 51 60 public SVGLoaderHelper(URI xmlBase, SVGUniverse universe, SVGDiagram diagram) 52 61 { 53 /*54 URI docURI = null;55 try56 {57 docURI = new URI(docRoot.toString());58 }59 catch (Exception e)60 {61 e.printStackTrace();62 }63 */64 65 62 this.xmlBase = xmlBase; 66 // this.docRoot = docURI;67 63 this.universe = universe; 68 64 this.diagram = diagram; -
trunk/src/com/kitfox/svg/SVGParseException.java
r4256 r6002 1 1 /* 2 * SVGException.java 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 3 33 * 4 34 * Created on May 12, 2005, 11:32 PM 5 *6 * To change this template, choose Tools | Options and locate the template under7 * the Source Creation and Management node. Right-click the template and choose8 * Open. You can then make changes to the template in the Source Editor.9 35 */ 10 36 -
trunk/src/com/kitfox/svg/SVGRoot.java
r4256 r6002 1 1 /* 2 * SVGRoot.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 18, 2004, 5:33 PM … … 30 39 import com.kitfox.svg.xml.NumberWithUnits; 31 40 import com.kitfox.svg.xml.StyleAttribute; 32 import java.awt.geom.*; 33 import java.awt.*; 41 import com.kitfox.svg.xml.StyleSheet; 42 import java.awt.Graphics2D; 43 import java.awt.Rectangle; 44 import java.awt.Shape; 45 import java.awt.geom.AffineTransform; 46 import java.awt.geom.Rectangle2D; 34 47 35 48 /** … … 41 54 public class SVGRoot extends Group 42 55 { 56 public static final String TAG_NAME = "svg"; 57 43 58 NumberWithUnits x; 44 59 NumberWithUnits y; … … 46 61 NumberWithUnits height; 47 62 48 49 // final Rectangle2D.Float viewBox = new Rectangle2D.Float();50 63 Rectangle2D.Float viewBox = null; 51 64 … … 70 83 final Rectangle2D.Float clipRect = new Rectangle2D.Float(); 71 84 85 private StyleSheet styleSheet; 86 72 87 /** Creates a new instance of SVGRoot */ 73 88 public SVGRoot() 74 89 { 75 90 } 76 /* 77 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 78 { 79 //Load style string 80 super.loaderStartElement(helper, attrs, parent); 81 82 x = XMLParseUtil.parseNumberWithUnits(attrs.getValue("x")); 83 y = XMLParseUtil.parseNumberWithUnits(attrs.getValue("y")); 84 width = XMLParseUtil.parseNumberWithUnits(attrs.getValue("width")); 85 height = XMLParseUtil.parseNumberWithUnits(attrs.getValue("height")); 86 87 String viewBox = attrs.getValue("viewBox"); 88 float[] coords = XMLParseUtil.parseFloatList(viewBox); 89 90 if (coords == null) 91 { 92 //this.viewBox.setRect(0, 0, width.getValue(), height.getValue()); 93 this.viewBox = null; 94 } 95 else 96 { 97 this.viewBox = new Rectangle2D.Float(coords[0], coords[1], coords[2], coords[3]); 98 } 99 100 String par = attrs.getValue("preserveAspectRatio"); 101 if (par != null) 102 { 103 String[] parList = XMLParseUtil.parseStringList(par); 104 105 if (parList[0].equals("none")) { parAlignX = PA_X_NONE; parAlignY = PA_Y_NONE; } 106 else if (parList[0].equals("xMinYMin")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MIN; } 107 else if (parList[0].equals("xMidYMin")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MIN; } 108 else if (parList[0].equals("xMaxYMin")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MIN; } 109 else if (parList[0].equals("xMinYMid")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MID; } 110 else if (parList[0].equals("xMidYMid")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MID; } 111 else if (parList[0].equals("xMaxYMid")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MID; } 112 else if (parList[0].equals("xMinYMax")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MAX; } 113 else if (parList[0].equals("xMidYMax")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MAX; } 114 else if (parList[0].equals("xMaxYMax")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MAX; } 115 116 if (parList[1].equals("meet")) parSpecifier = PS_MEET; 117 else if (parList[1].equals("slice")) parSpecifier = PS_SLICE; 118 } 119 120 build(); 121 } 122 */ 91 92 public String getTagName() 93 { 94 return TAG_NAME; 95 } 123 96 124 97 public void build() throws SVGException … … 128 101 StyleAttribute sty = new StyleAttribute(); 129 102 130 if (getPres(sty.setName("x"))) x = sty.getNumberWithUnits(); 131 132 if (getPres(sty.setName("y"))) y = sty.getNumberWithUnits(); 133 134 if (getPres(sty.setName("width"))) width = sty.getNumberWithUnits(); 135 136 if (getPres(sty.setName("height"))) height = sty.getNumberWithUnits(); 103 if (getPres(sty.setName("x"))) 104 { 105 x = sty.getNumberWithUnits(); 106 } 107 108 if (getPres(sty.setName("y"))) 109 { 110 y = sty.getNumberWithUnits(); 111 } 112 113 if (getPres(sty.setName("width"))) 114 { 115 width = sty.getNumberWithUnits(); 116 } 117 118 if (getPres(sty.setName("height"))) 119 { 120 height = sty.getNumberWithUnits(); 121 } 137 122 138 123 if (getPres(sty.setName("viewBox"))) … … 157 142 else if (contains(preserve, "xMaxYMax")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MAX; } 158 143 159 if (contains(preserve, "meet")) parSpecifier = PS_MEET; 160 else if (contains(preserve, "slice")) parSpecifier = PS_SLICE; 161 162 /* 163 String[] parList = sty.getStringList(); 164 165 if (parList[0].equals("none")) { parAlignX = PA_X_NONE; parAlignY = PA_Y_NONE; } 166 else if (parList[0].equals("xMinYMin")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MIN; } 167 else if (parList[0].equals("xMidYMin")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MIN; } 168 else if (parList[0].equals("xMaxYMin")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MIN; } 169 else if (parList[0].equals("xMinYMid")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MID; } 170 else if (parList[0].equals("xMidYMid")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MID; } 171 else if (parList[0].equals("xMaxYMid")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MID; } 172 else if (parList[0].equals("xMinYMax")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MAX; } 173 else if (parList[0].equals("xMidYMax")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MAX; } 174 else if (parList[0].equals("xMaxYMax")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MAX; } 175 176 if (parList[1].equals("meet")) parSpecifier = PS_MEET; 177 else if (parList[1].equals("slice")) parSpecifier = PS_SLICE; 178 */ 144 if (contains(preserve, "meet")) 145 { 146 parSpecifier = PS_MEET; 147 } 148 else if (contains(preserve, "slice")) 149 { 150 parSpecifier = PS_SLICE; 151 } 179 152 } 180 153 … … 185 158 { 186 159 return (text.indexOf(find) != -1); 160 } 161 162 public SVGRoot getRoot() 163 { 164 return this; 187 165 } 188 166 … … 195 173 { 196 174 defaultBounds = getBoundingBox(); 197 } catch (SVGException ex) 175 } 176 catch (SVGException ex) 198 177 { 199 178 defaultBounds= new Rectangle2D.Float(); … … 213 192 ww = StyleAttribute.convertUnitsToPixels(width.getUnits(), width.getValue()); 214 193 } 215 // setAttribute("x", AnimationElement.AT_XML, "" + xx);216 // setAttribute("width", AnimationElement.AT_XML, "" + ww);217 194 } 218 195 else if (viewBox != null) … … 273 250 viewXform.translate(-viewBox.x, -viewBox.y); 274 251 } 275 276 277 //For now, treat all preserveAspectRatio as 'none'278 // viewXform.setToTranslation(viewBox.x, viewBox.y);279 // viewXform.scale(clipRect.width / viewBox.width, clipRect.height / viewBox.height);280 // viewXform.translate(-clipRect.x, -clipRect.y);281 252 } 282 253 … … 393 364 } 394 365 366 /** 367 * @return the styleSheet 368 */ 369 public StyleSheet getStyleSheet() 370 { 371 if (styleSheet == null) 372 { 373 for (int i = 0; i < getNumChildren(); ++i) 374 { 375 SVGElement ele = getChild(i); 376 if (ele instanceof Style) 377 { 378 return ((Style)ele).getStyleSheet(); 379 } 380 } 381 } 382 383 return styleSheet; 384 } 385 386 /** 387 * @param styleSheet the styleSheet to set 388 */ 389 public void setStyleSheet(StyleSheet styleSheet) 390 { 391 this.styleSheet = styleSheet; 392 } 393 395 394 } -
trunk/src/com/kitfox/svg/SVGUniverse.java
r4256 r6002 1 1 /* 2 * SVGUniverse.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 18, 2004, 11:43 PM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 … … 36 44 import java.io.ByteArrayInputStream; 37 45 import java.io.ByteArrayOutputStream; 38 import java.io.File;39 46 import java.io.IOException; 40 47 import java.io.InputStream; … … 46 53 import java.net.MalformedURLException; 47 54 import java.net.URI; 55 import java.net.URISyntaxException; 48 56 import java.net.URL; 49 57 import java.net.URLConnection; … … 51 59 import java.util.HashMap; 52 60 import java.util.Iterator; 61 import java.util.logging.Level; 62 import java.util.logging.Logger; 53 63 import java.util.zip.GZIPInputStream; 54 64 import javax.imageio.ImageIO; … … 61 71 62 72 /** 63 * Many SVG files can be loaded at one time. These files will quite likely64 * need to reference one another. The SVG universe provides a container for65 * all thesefiles and the means for them to relate to each other.73 * Many SVG files can be loaded at one time. These files will quite likely need 74 * to reference one another. The SVG universe provides a container for all these 75 * files and the means for them to relate to each other. 66 76 * 67 77 * @author Mark McKay … … 70 80 public class SVGUniverse implements Serializable 71 81 { 82 72 83 public static final long serialVersionUID = 0; 73 74 84 transient private PropertyChangeSupport changes = new PropertyChangeSupport(this); 75 76 /** 77 * Maps document URIs to their loaded SVG diagrams. Note that URIs for 85 /** 86 * Maps document URIs to their loaded SVG diagrams. Note that URIs for 78 87 * documents loaded from URLs will reflect their URLs and URIs for documents 79 88 * initiated from streams will have the scheme <i>svgSalamander</i>. 80 89 */ 81 90 final HashMap loadedDocs = new HashMap(); 82 83 91 final HashMap loadedFonts = new HashMap(); 84 85 92 final HashMap loadedImages = new HashMap(); 86 87 93 public static final String INPUTSTREAM_SCHEME = "svgSalamander"; 88 89 /** 90 * Current time in this universe. Used for resolving attributes that 91 * are influenced by track information. Time is in milliseconds. Time 92 * 0 coresponds to the time of 0 in each member diagram. 94 /** 95 * Current time in this universe. Used for resolving attributes that are 96 * influenced by track information. Time is in milliseconds. Time 0 97 * coresponds to the time of 0 in each member diagram. 93 98 */ 94 99 protected double curTime = 0.0; 95 96 100 private boolean verbose = false; 97 98 101 //Cache reader for efficiency 99 102 XMLReader cachedReader; 100 101 /** Creates a new instance of SVGUniverse */ 103 104 /** 105 * Creates a new instance of SVGUniverse 106 */ 102 107 public SVGUniverse() 103 108 { 104 109 } 105 110 106 111 public void addPropertyChangeListener(PropertyChangeListener l) 107 112 { 108 113 changes.addPropertyChangeListener(l); 109 114 } 110 115 111 116 public void removePropertyChangeListener(PropertyChangeListener l) 112 117 { 113 118 changes.removePropertyChangeListener(l); 114 119 } 115 120 116 121 /** 117 122 * Release all loaded SVG document from memory … … 123 128 loadedImages.clear(); 124 129 } 125 130 126 131 /** 127 132 * Returns the current animation time in milliseconds. 128 133 */ 129 134 public double getCurTime() 130 { 131 return curTime; 132 } 133 135 { 136 return curTime; 137 } 138 134 139 public void setCurTime(double curTime) 135 140 { 136 141 double oldTime = this.curTime; 137 this.curTime = curTime; 142 this.curTime = curTime; 138 143 changes.firePropertyChange("curTime", new Double(oldTime), new Double(curTime)); 139 144 } 140 145 141 146 /** 142 147 * Updates all time influenced style and presentation attributes in all SVG … … 147 152 for (Iterator it = loadedDocs.values().iterator(); it.hasNext();) 148 153 { 149 SVGDiagram dia = (SVGDiagram) it.next();154 SVGDiagram dia = (SVGDiagram) it.next(); 150 155 dia.updateTime(curTime); 151 156 } 152 157 } 153 158 154 159 /** 155 160 * Called by the Font element to let the universe know that a font has been … … 160 165 loadedFonts.put(font.getFontFace().getFontFamily(), font); 161 166 } 162 167 163 168 public Font getDefaultFont() 164 169 { 165 170 for (Iterator it = loadedFonts.values().iterator(); it.hasNext();) 166 171 { 167 return (Font) it.next();172 return (Font) it.next(); 168 173 } 169 174 return null; 170 175 } 171 176 172 177 public Font getFont(String fontName) 173 178 { 174 return (Font) loadedFonts.get(fontName);179 return (Font) loadedFonts.get(fontName); 175 180 } 176 181 … … 188 193 { 189 194 content = content.substring(6); 190 try { 195 try 196 { 191 197 byte[] buf = new sun.misc.BASE64Decoder().decodeBuffer(content); 192 198 ByteArrayInputStream bais = new ByteArrayInputStream(buf); … … 209 215 210 216 return url; 211 } catch (IOException ex) { 212 ex.printStackTrace(); 217 } catch (IOException ex) 218 { 219 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 220 "Could not decode inline image", ex); 213 221 } 214 222 } 215 223 return null; 216 } 217 else218 {219 try{224 } else 225 { 226 try 227 { 220 228 URL url = imageURI.toURL(); 221 229 registerImage(url); 222 230 return url; 223 } catch (MalformedURLException ex) { 224 ex.printStackTrace(); 231 } catch (MalformedURLException ex) 232 { 233 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 234 "Bad url", ex); 225 235 } 226 236 return null; … … 230 240 void registerImage(URL imageURL) 231 241 { 232 if (loadedImages.containsKey(imageURL)) return; 233 242 if (loadedImages.containsKey(imageURL)) 243 { 244 return; 245 } 246 234 247 SoftReference ref; 235 248 try … … 240 253 SVGIcon icon = new SVGIcon(); 241 254 icon.setSvgURI(imageURL.toURI()); 242 255 243 256 BufferedImage img = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); 244 257 Graphics2D g = img.createGraphics(); … … 246 259 g.dispose(); 247 260 ref = new SoftReference(img); 248 } 249 else 261 } else 250 262 { 251 263 BufferedImage img = ImageIO.read(imageURL); … … 253 265 } 254 266 loadedImages.put(imageURL, ref); 255 } 256 catch (Exception e) 257 { 258 System.err.println("Could not load image: " + imageURL); 259 e.printStackTrace(); 260 } 261 } 262 267 } catch (Exception e) 268 { 269 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 270 "Could not load image: " + imageURL, e); 271 } 272 } 273 263 274 BufferedImage getImage(URL imageURL) 264 275 { 265 SoftReference ref = (SoftReference)loadedImages.get(imageURL); 266 if (ref == null) return null; 267 268 BufferedImage img = (BufferedImage)ref.get(); 276 SoftReference ref = (SoftReference) loadedImages.get(imageURL); 277 if (ref == null) 278 { 279 return null; 280 } 281 282 BufferedImage img = (BufferedImage) ref.get(); 269 283 //If image was cleared from memory, reload it 270 284 if (img == null) … … 273 287 { 274 288 img = ImageIO.read(imageURL); 275 } 276 catch (Exception e) 277 { e.printStackTrace(); } 289 } catch (Exception e) 290 { 291 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 292 "Could not load image", e); 293 } 278 294 ref = new SoftReference(img); 279 295 loadedImages.put(imageURL, ref); 280 296 } 281 297 282 298 return img; 283 299 } 284 285 /** 286 * Returns the element of the document at the given URI. If the document287 * isnot already loaded, it will be.300 301 /** 302 * Returns the element of the document at the given URI. If the document is 303 * not already loaded, it will be. 288 304 */ 289 305 public SVGElement getElement(URI path) … … 291 307 return getElement(path, true); 292 308 } 293 309 294 310 public SVGElement getElement(URL path) 295 311 { … … 298 314 URI uri = new URI(path.toString()); 299 315 return getElement(uri, true); 300 } 301 catch (Exception e)302 {303 e.printStackTrace();316 } catch (Exception e) 317 { 318 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 319 "Could not parse url " + path, e); 304 320 } 305 321 return null; 306 322 } 307 308 /** 309 * Looks up a href within our universe. If the href refers to a document that310 * is not loaded, it will be loaded. The URL #target will then be checked311 * against the SVG diagram's index and the coresponding element returned.312 * If there is no coresponding index, null is returned.323 324 /** 325 * Looks up a href within our universe. If the href refers to a document 326 * that is not loaded, it will be loaded. The URL #target will then be 327 * checked against the SVG diagram's index and the coresponding element 328 * returned. If there is no coresponding index, null is returned. 313 329 */ 314 330 public SVGElement getElement(URI path, boolean loadIfAbsent) … … 318 334 //Strip fragment from URI 319 335 URI xmlBase = new URI(path.getScheme(), path.getSchemeSpecificPart(), null); 320 321 SVGDiagram dia = (SVGDiagram) loadedDocs.get(xmlBase);336 337 SVGDiagram dia = (SVGDiagram) loadedDocs.get(xmlBase); 322 338 if (dia == null && loadIfAbsent) 323 339 { … … 325 341 //javax.swing.JOptionPane.showMessageDialog(null, xmlBase.toString()); 326 342 URL url = xmlBase.toURL(); 327 343 328 344 loadSVG(url, false); 329 dia = (SVGDiagram)loadedDocs.get(xmlBase); 330 if (dia == null) return null; 331 } 332 345 dia = (SVGDiagram) loadedDocs.get(xmlBase); 346 if (dia == null) 347 { 348 return null; 349 } 350 } 351 333 352 String fragment = path.getFragment(); 334 353 return fragment == null ? dia.getRoot() : dia.getElement(fragment); 335 } 336 catch (Exception e)337 {338 e.printStackTrace();339 return null; 340 } 341 } 342 354 } catch (Exception e) 355 { 356 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 357 "Could not parse path " + path, e); 358 return null; 359 } 360 } 361 343 362 public SVGDiagram getDiagram(URI xmlBase) 344 363 { 345 364 return getDiagram(xmlBase, true); 346 365 } 347 348 /** 349 * Returns the diagram that has been loaded from this root. 366 367 /** 368 * Returns the diagram that has been loaded from this root. If diagram is 350 369 * not already loaded, returns null. 351 370 */ 352 371 public SVGDiagram getDiagram(URI xmlBase, boolean loadIfAbsent) 353 372 { 354 if (xmlBase == null) return null; 355 356 SVGDiagram dia = (SVGDiagram)loadedDocs.get(xmlBase); 357 if (dia != null || !loadIfAbsent) return dia; 358 373 if (xmlBase == null) 374 { 375 return null; 376 } 377 378 SVGDiagram dia = (SVGDiagram) loadedDocs.get(xmlBase); 379 if (dia != null || !loadIfAbsent) 380 { 381 return dia; 382 } 383 359 384 //Load missing diagram 360 385 try … … 372 397 } 373 398 374 399 375 400 loadSVG(url, false); 376 dia = (SVGDiagram) loadedDocs.get(xmlBase);401 dia = (SVGDiagram) loadedDocs.get(xmlBase); 377 402 return dia; 378 } 379 catch (Exception e)380 {381 e.printStackTrace();382 } 383 403 } catch (Exception e) 404 { 405 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 406 "Could not parse", e); 407 } 408 384 409 return null; 385 410 } 386 387 /** 388 * Wraps input stream in a BufferedInputStream. 411 412 /** 413 * Wraps input stream in a BufferedInputStream. If it is detected that this 389 414 * input stream is GZIPped, also wraps in a GZIPInputStream for inflation. 390 * 415 * 391 416 * @param is Raw input stream 392 417 * @return Uncompressed stream of SVG data … … 406 431 GZIPInputStream iis = new GZIPInputStream(bin); 407 432 return iis; 408 } 409 else 433 } else 410 434 { 411 435 //Plain text … … 413 437 } 414 438 } 415 439 416 440 public URI loadSVG(URL docRoot) 417 441 { 418 442 return loadSVG(docRoot, false); 419 443 } 420 444 421 445 /** 422 446 * Loads an SVG file and all the files it references from the URL provided. 423 447 * If a referenced file already exists in the SVG universe, it is not 424 448 * reloaded. 449 * 425 450 * @param docRoot - URL to the location where this SVG file can be found. 426 451 * @param forceLoad - if true, ignore cached diagram and reload … … 432 457 { 433 458 URI uri = new URI(docRoot.toString()); 434 if (loadedDocs.containsKey(uri) && !forceLoad) return uri; 435 459 if (loadedDocs.containsKey(uri) && !forceLoad) 460 { 461 return uri; 462 } 463 436 464 InputStream is = docRoot.openStream(); 437 465 return loadSVG(uri, new InputSource(createDocumentInputStream(is))); 438 } 439 catch (Throwable t) 440 { 441 t.printStackTrace(); 442 } 443 466 } catch (URISyntaxException ex) 467 { 468 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 469 "Could not parse", ex); 470 } catch (IOException e) 471 { 472 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 473 "Could not parse", e); 474 } 475 444 476 return null; 445 477 } 446 447 478 448 479 public URI loadSVG(InputStream is, String name) throws IOException 449 480 { 450 481 return loadSVG(is, name, false); 451 482 } 452 483 453 484 public URI loadSVG(InputStream is, String name, boolean forceLoad) throws IOException 454 485 { 455 486 URI uri = getStreamBuiltURI(name); 456 if (uri == null) return null; 457 if (loadedDocs.containsKey(uri) && !forceLoad) return uri; 458 487 if (uri == null) 488 { 489 return null; 490 } 491 if (loadedDocs.containsKey(uri) && !forceLoad) 492 { 493 return uri; 494 } 495 459 496 return loadSVG(uri, new InputSource(createDocumentInputStream(is))); 460 497 } 461 498 462 499 public URI loadSVG(Reader reader, String name) 463 500 { 464 501 return loadSVG(reader, name, false); 465 502 } 466 503 467 504 /** 468 505 * This routine allows you to create SVG documents from data streams that 469 * may not necessarily have a URL to load from. 470 * must be identified by a unique URL, Salamander provides a method to 471 * fake this for streams by defining it's own protocol - svgSalamander -472 * for SVGdocuments without a formal URL.506 * may not necessarily have a URL to load from. Since every SVG document 507 * must be identified by a unique URL, Salamander provides a method to fake 508 * this for streams by defining it's own protocol - svgSalamander - for SVG 509 * documents without a formal URL. 473 510 * 474 511 * @param reader - A stream containing a valid SVG document 475 * @param name - <p>A unique name for this document. 512 * @param name - <p>A unique name for this document. It will be used to 476 513 * construct a unique URI to refer to this document and perform resolution 477 * with relative URIs within this document.</p> 478 * <p>For example, a name of "/myScene" will produce the URI 479 * svgSalamander:/myScene. "/maps/canada/toronto" will produce 480 * svgSalamander:/maps/canada/toronto. If this second document then 481 * contained the href "../uk/london", it would resolve by default to 482 * svgSalamander:/maps/uk/london. That is, SVG Salamander defines the 483 * URI scheme svgSalamander for it's own internal use and uses it 484 * for uniquely identfying documents loaded by stream.</p> 485 * <p>If you need to link to documents outside of this scheme, you can 486 * either supply full hrefs (eg, href="url(http://www.kitfox.com/index.html)") 487 * or put the xml:base attribute in a tag to change the defaultbase 488 * URIs are resolved against</p> 489 * <p>If a name does not start with the character '/', it will be automatically 490 * prefixed to it.</p> 514 * with relative URIs within this document.</p> <p>For example, a name of 515 * "/myScene" will produce the URI svgSalamander:/myScene. 516 * "/maps/canada/toronto" will produce svgSalamander:/maps/canada/toronto. 517 * If this second document then contained the href "../uk/london", it would 518 * resolve by default to svgSalamander:/maps/uk/london. That is, SVG 519 * Salamander defines the URI scheme svgSalamander for it's own internal use 520 * and uses it for uniquely identfying documents loaded by stream.</p> <p>If 521 * you need to link to documents outside of this scheme, you can either 522 * supply full hrefs (eg, href="url(http://www.kitfox.com/index.html)") or 523 * put the xml:base attribute in a tag to change the defaultbase URIs are 524 * resolved against</p> <p>If a name does not start with the character '/', 525 * it will be automatically prefixed to it.</p> 491 526 * @param forceLoad - if true, ignore cached diagram and reload 492 527 * … … 498 533 //Synthesize URI for this stream 499 534 URI uri = getStreamBuiltURI(name); 500 if (uri == null) return null; 501 if (loadedDocs.containsKey(uri) && !forceLoad) return uri; 502 535 if (uri == null) 536 { 537 return null; 538 } 539 if (loadedDocs.containsKey(uri) && !forceLoad) 540 { 541 return uri; 542 } 543 503 544 return loadSVG(uri, new InputSource(reader)); 504 545 } 505 546 506 547 /** 507 548 * Synthesize a URI for an SVGDiagram constructed from a stream. 549 * 508 550 * @param name - Name given the document constructed from a stream. 509 551 */ 510 552 public URI getStreamBuiltURI(String name) 511 553 { 512 if (name == null || name.length() == 0) return null; 513 514 if (name.charAt(0) != '/') name = '/' + name; 515 554 if (name == null || name.length() == 0) 555 { 556 return null; 557 } 558 559 if (name.charAt(0) != '/') 560 { 561 name = '/' + name; 562 } 563 516 564 try 517 565 { 518 566 //Dummy URL for SVG documents built from image streams 519 567 return new URI(INPUTSTREAM_SCHEME, name, null); 520 } 521 catch (Exception e)522 {523 e.printStackTrace();524 return null; 525 } 526 } 527 568 } catch (Exception e) 569 { 570 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 571 "Could not parse", e); 572 return null; 573 } 574 } 575 528 576 private XMLReader getXMLReaderCached() throws SAXException 529 577 { … … 534 582 return cachedReader; 535 583 } 536 537 // protected URI loadSVG(URI xmlBase, InputStream is) 584 538 585 protected URI loadSVG(URI xmlBase, InputSource is) 539 586 { 540 587 // Use an instance of ourselves as the SAX event handler 541 588 SVGLoader handler = new SVGLoader(xmlBase, this, verbose); 542 589 543 590 //Place this docment in the universe before it is completely loaded 544 591 // so that the load process can refer to references within it's current 545 592 // document 546 //System.err.println("SVGUniverse: loading dia " + xmlBase);547 593 loadedDocs.put(xmlBase, handler.getLoadedDiagram()); 548 549 // Use the default (non-validating) parser 550 // SAXParserFactory factory = SAXParserFactory.newInstance(); 551 // factory.setValidating(false); 552 // factory.setNamespaceAware(true); 553 594 554 595 try 555 596 { … … 564 605 return new InputSource(new ByteArrayInputStream(new byte[0])); 565 606 } 566 } 567 ); 607 }); 568 608 reader.setContentHandler(handler); 569 609 reader.parse(is); 570 571 // SAXParser saxParser = factory.newSAXParser(); 572 // saxParser.parse(new InputSource(new BufferedReader(is)), handler); 610 611 handler.getLoadedDiagram().updateTime(curTime); 573 612 return xmlBase; 574 } 575 catch (SAXParseException sex) 613 } catch (SAXParseException sex) 576 614 { 577 615 System.err.println("Error processing " + xmlBase); 578 616 System.err.println(sex.getMessage()); 579 617 580 618 loadedDocs.remove(xmlBase); 581 619 return null; 582 } 583 catch (Throwable t)584 {585 t.printStackTrace();586 } 587 620 } catch (Throwable e) 621 { 622 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 623 "Could not load SVG " + xmlBase, e); 624 } 625 588 626 return null; 589 627 } 590 591 public static void main(String argv[])592 {593 try594 {595 URL url = new URL("svgSalamander", "localhost", -1, "abc.svg",596 new URLStreamHandler()597 {598 protected URLConnection openConnection(URL u)599 {600 return null;601 }602 }603 );604 // URL url2 = new URL("svgSalamander", "localhost", -1, "abc.svg");605 606 //Investigate URI resolution607 URI uriA, uriB, uriC, uriD, uriE;608 609 uriA = new URI("svgSalamander", "/names/mySpecialName", null);610 // uriA = new URI("http://www.kitfox.com/salamander");611 // uriA = new URI("svgSalamander://mySpecialName/grape");612 System.err.println(uriA.toString());613 System.err.println(uriA.getScheme());614 615 uriB = uriA.resolve("#begin");616 System.err.println(uriB.toString());617 618 uriC = uriA.resolve("tree#boing");619 System.err.println(uriC.toString());620 621 uriC = uriA.resolve("../tree#boing");622 System.err.println(uriC.toString());623 }624 catch (Exception e)625 {626 e.printStackTrace(); 627 } 628 }629 628 629 // public static void main(String argv[]) 630 // { 631 // try 632 // { 633 // URL url = new URL("svgSalamander", "localhost", -1, "abc.svg", 634 // new URLStreamHandler() 635 // { 636 // protected URLConnection openConnection(URL u) 637 // { 638 // return null; 639 // } 640 // } 641 // ); 642 //// URL url2 = new URL("svgSalamander", "localhost", -1, "abc.svg"); 643 // 644 // //Investigate URI resolution 645 // URI uriA, uriB, uriC, uriD, uriE; 646 // 647 // uriA = new URI("svgSalamander", "/names/mySpecialName", null); 648 //// uriA = new URI("http://www.kitfox.com/salamander"); 649 //// uriA = new URI("svgSalamander://mySpecialName/grape"); 650 // System.err.println(uriA.toString()); 651 // System.err.println(uriA.getScheme()); 652 // 653 // uriB = uriA.resolve("#begin"); 654 // System.err.println(uriB.toString()); 655 // 656 // uriC = uriA.resolve("tree#boing"); 657 // System.err.println(uriC.toString()); 658 // 659 // uriC = uriA.resolve("../tree#boing"); 660 // System.err.println(uriC.toString()); 661 // } 662 // catch (Exception e) 663 // { 664 // Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 665 // "Could not parse", e); 666 // } 667 // } 630 668 public boolean isVerbose() 631 669 { … … 637 675 this.verbose = verbose; 638 676 } 639 677 640 678 /** 641 679 * Uses serialization to duplicate this universe. … … 650 688 ByteArrayInputStream bin = new ByteArrayInputStream(bs.toByteArray()); 651 689 ObjectInputStream is = new ObjectInputStream(bin); 652 SVGUniverse universe = (SVGUniverse) is.readObject();690 SVGUniverse universe = (SVGUniverse) is.readObject(); 653 691 is.close(); 654 692 -
trunk/src/com/kitfox/svg/ShapeElement.java
r4256 r6002 1 1 /* 2 * ShapeElement.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:21 PM … … 96 105 } 97 106 107 private Paint handleCurrentColor(StyleAttribute styleAttrib) throws SVGException 108 { 109 if (styleAttrib.getStringValue().equals("currentColor")) 110 { 111 StyleAttribute currentColorAttrib = new StyleAttribute(); 112 if (getStyle(currentColorAttrib.setName("color"))) 113 { 114 if (!currentColorAttrib.getStringValue().equals("none")) 115 { 116 return currentColorAttrib.getColorValue(); 117 } 118 } 119 return null; 120 } 121 else 122 { 123 return styleAttrib.getColorValue(); 124 } 125 } 126 98 127 protected void renderShape(Graphics2D g, Shape shape) throws SVGException 99 128 { … … 120 149 else 121 150 { 122 fillPaint = styleAttrib.getColorValue();151 fillPaint = handleCurrentColor(styleAttrib); 123 152 if (fillPaint == null) 124 153 { … … 130 159 131 160 SVGElement ele = diagram.getUniverse().getElement(uri); 132 fillPaint = ((FillElement)ele).getPaint(bounds, xform); 161 if (ele != null) 162 { 163 fillPaint = ((FillElement)ele).getPaint(bounds, xform); 164 } 133 165 } 134 166 } … … 156 188 else 157 189 { 158 strokePaint = styleAttrib.getColorValue();190 strokePaint = handleCurrentColor(styleAttrib); 159 191 if (strokePaint == null) 160 192 { … … 166 198 167 199 SVGElement ele = diagram.getUniverse().getElement(uri); 168 strokePaint = ((FillElement)ele).getPaint(bounds, xform); 200 if (ele != null) 201 { 202 strokePaint = ((FillElement)ele).getPaint(bounds, xform); 203 } 169 204 } 170 205 } … … 303 338 } 304 339 305 Shape strokeShape = stroke.createStrokedShape(shape); 340 Shape strokeShape; 341 AffineTransform cacheXform = g.getTransform(); 342 if (vectorEffect == VECTOR_EFFECT_NON_SCALING_STROKE) 343 { 344 strokeShape = cacheXform.createTransformedShape(shape); 345 strokeShape = stroke.createStrokedShape(strokeShape); 346 } 347 else 348 { 349 strokeShape = stroke.createStrokedShape(shape); 350 } 306 351 307 352 if (strokeOpacity <= 0) … … 309 354 //Do nothing 310 355 } 311 else if (strokeOpacity < 1f)356 else 312 357 { 313 358 Composite cachedComposite = g.getComposite(); 314 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, strokeOpacity)); 359 360 if (strokeOpacity < 1f) 361 { 362 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, strokeOpacity)); 363 } 364 365 if (vectorEffect == VECTOR_EFFECT_NON_SCALING_STROKE) 366 { 367 //Set to identity 368 g.setTransform(new AffineTransform()); 369 } 315 370 316 371 g.setPaint(strokePaint); 317 372 g.fill(strokeShape); 318 373 319 g.setComposite(cachedComposite); 320 } 321 else 322 { 323 g.setPaint(strokePaint); 324 g.fill(strokeShape); 374 if (vectorEffect == VECTOR_EFFECT_NON_SCALING_STROKE) 375 { 376 //Set to identity 377 g.setTransform(cacheXform); 378 } 379 380 if (strokeOpacity < 1f) 381 { 382 g.setComposite(cachedComposite); 383 } 325 384 } 326 385 } -
trunk/src/com/kitfox/svg/Stop.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 import java.awt.*; 32 import java.util.*; 33 34 import com.kitfox.svg.xml.*; 35 import org.xml.sax.*; 39 import java.awt.Color; 36 40 37 41 /** … … 39 43 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 40 44 */ 41 public class Stop extends SVGElement { 45 public class Stop extends SVGElement 46 { 42 47 48 public static final String TAG_NAME = "stop"; 43 49 float offset = 0f; 44 50 float opacity = 1f; 45 51 Color color = Color.black; 46 52 47 /** Creates a new instance of Stop */ 48 public Stop() { 53 /** 54 * Creates a new instance of Stop 55 */ 56 public Stop() 57 { 49 58 } 50 /* 51 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)59 60 public String getTagName() 52 61 { 53 //Load style string 54 super.loaderStartElement(helper, attrs, parent);62 return TAG_NAME; 63 } 55 64 56 String offset = attrs.getValue("offset");57 this.offset = (float)XMLParseUtil.parseRatio(offset);58 59 buildStop();60 }61 */62 63 65 protected void build() throws SVGException 64 66 { 65 67 super.build(); 66 68 67 69 StyleAttribute sty = new StyleAttribute(); 68 70 69 71 if (getPres(sty.setName("offset"))) 70 72 { 71 73 offset = sty.getFloatValue(); 72 74 String units = sty.getUnits(); 73 if (units != null && units.equals("%")) offset /= 100f; 74 if (offset > 1) offset = 1; 75 if (offset < 0) offset = 0; 75 if (units != null && units.equals("%")) 76 { 77 offset /= 100f; 78 } 79 if (offset > 1) 80 { 81 offset = 1; 82 } 83 if (offset < 0) 84 { 85 offset = 0; 86 } 76 87 } 77 78 if (getStyle(sty.setName("stop-color"))) color = sty.getColorValue();79 88 80 if (getStyle(sty.setName("stop-opacity"))) opacity = sty.getRatioValue(); 89 if (getStyle(sty.setName("stop-color"))) 90 { 91 color = sty.getColorValue(); 92 } 93 94 if (getStyle(sty.setName("stop-opacity"))) 95 { 96 opacity = sty.getRatioValue(); 97 } 81 98 } 82 99 83 100 /** 84 * Updates all attributes in this diagram associated with a time event. 85 * Ie, all attributes with track information. 101 * Updates all attributes in this diagram associated with a time event. Ie, 102 * all attributes with track information. 103 * 86 104 * @return - true if this node has changed state as a result of the time 87 105 * update … … 94 112 StyleAttribute sty = new StyleAttribute(); 95 113 boolean shapeChange = false; 96 114 97 115 if (getPres(sty.setName("offset"))) 98 116 { … … 104 122 } 105 123 } 106 107 if (get Pres(sty.setName("stop-color")))124 125 if (getStyle(sty.setName("stop-color"))) 108 126 { 109 127 Color newVal = sty.getColorValue(); … … 114 132 } 115 133 } 116 117 if (get Pres(sty.setName("stop-opacity")))134 135 if (getStyle(sty.setName("stop-opacity"))) 118 136 { 119 137 float newVal = sty.getFloatValue(); … … 124 142 } 125 143 } 126 144 127 145 return shapeChange; 128 146 } -
trunk/src/com/kitfox/svg/Style.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 import com.kitfox.svg.xml.StyleAttribute; 31 import com.kitfox.svg.xml.*; 32 import org.xml.sax.*; 33 39 import com.kitfox.svg.xml.StyleSheet; 34 40 35 41 /** … … 39 45 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 40 46 */ 41 public class Style extends SVGElement { 47 public class Style extends SVGElement 48 { 42 49 50 public static final String TAG_NAME = "style"; 43 51 //Should be set to "text/css" 44 52 String type; 45 53 StringBuffer text = new StringBuffer(); 46 54 47 /** Creates a new instance of Stop */ 48 public Style() { 55 StyleSheet styleSheet; 56 57 /** 58 * Creates a new instance of Stop 59 */ 60 public Style() 61 { 49 62 } 50 /* 51 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)63 64 public String getTagName() 52 65 { 53 //Load style string 54 super.loaderStartElement(helper, attrs, parent);66 return TAG_NAME; 67 } 55 68 56 this.type = attrs.getValue("type");57 }58 */59 69 /** 60 70 * Called during load process to add text scanned within a tag … … 63 73 { 64 74 this.text.append(text); 75 76 //Invalidate style sheet 77 styleSheet = null; 65 78 } 66 79 67 68 80 protected void build() throws SVGException 69 81 { 70 82 super.build(); 71 83 72 84 StyleAttribute sty = new StyleAttribute(); 73 74 if (getPres(sty.setName("type"))) type = sty.getStringValue(); 85 86 if (getPres(sty.setName("type"))) 87 { 88 type = sty.getStringValue(); 89 } 75 90 } 76 91 77 92 public boolean updateTime(double curTime) throws SVGException 78 93 { 79 94 //Style sheet doesn't change 80 95 return false; 81 } 82 96 } 97 98 public StyleSheet getStyleSheet() 99 { 100 if (styleSheet == null && text.length() > 0) 101 { 102 styleSheet = StyleSheet.parseSheet(text.toString()); 103 } 104 return styleSheet; 105 } 83 106 } -
trunk/src/com/kitfox/svg/Symbol.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 33 import com.kitfox.svg.xml.*; 38 import com.kitfox.svg.xml.StyleAttribute; 39 import java.awt.Graphics2D; 40 import java.awt.Rectangle; 41 import java.awt.Shape; 42 import java.awt.geom.AffineTransform; 43 import java.awt.geom.Rectangle2D; 34 44 35 45 /** … … 39 49 public class Symbol extends Group 40 50 { 51 52 public static final String TAG_NAME = "symbol"; 41 53 AffineTransform viewXform; 42 54 Rectangle2D viewBox; 43 55 44 /** Creates a new instance of Stop */ 45 public Symbol() { 56 /** 57 * Creates a new instance of Stop 58 */ 59 public Symbol() 60 { 46 61 } 47 /* 48 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)62 63 public String getTagName() 49 64 { 50 //Load style string 51 super.loaderStartElement(helper, attrs, parent);65 return TAG_NAME; 66 } 52 67 53 String viewBoxStrn = attrs.getValue("viewBox");54 if (viewBoxStrn != null)55 {56 float[] dim = XMLParseUtil.parseFloatList(viewBoxStrn);57 viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);58 }59 }60 */61 /*62 public void loaderEndElement(SVGLoaderHelper helper)63 {64 if (viewBox == null)65 {66 viewBox = super.getBoundingBox();67 }68 69 //Transform pattern onto unit square70 viewXform = new AffineTransform();71 viewXform.scale(1.0 / viewBox.getWidth(), 1.0 / viewBox.getHeight());72 viewXform.translate(-viewBox.getX(), -viewBox.getY());73 }74 */75 76 68 protected void build() throws SVGException 77 69 { 78 70 super.build(); 79 71 80 72 StyleAttribute sty = new StyleAttribute(); 81 73 82 74 // sty = getPres("unicode"); 83 75 // if (sty != null) unicode = sty.getStringValue(); … … 89 81 viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]); 90 82 } 91 83 92 84 if (viewBox == null) 93 85 { … … 104 96 protected boolean outsideClip(Graphics2D g) throws SVGException 105 97 { 106 g.getClipBounds(clipBounds); 98 Shape clip = g.getClip(); 99 // g.getClipBounds(clipBounds); 107 100 Rectangle2D rect = super.getBoundingBox(); 108 if ( rect.intersects(clipBounds))101 if (clip == null || clip.intersects(rect)) 109 102 { 110 103 return false; … … 138 131 139 132 /** 140 * Updates all attributes in this diagram associated with a time event. 141 * Ie, all attributes with track information. 133 * Updates all attributes in this diagram associated with a time event. Ie, 134 * all attributes with track information. 135 * 142 136 * @return - true if this node has changed state as a result of the time 143 137 * update … … 147 141 // if (trackManager.getNumTracks() == 0) return false; 148 142 boolean changeState = super.updateTime(curTime); 149 143 150 144 //View box properties do not change 151 145 152 146 return changeState; 153 147 } 154 155 148 } -
trunk/src/com/kitfox/svg/Text.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 import java.awt.*; 32 import java.awt.font.*; 33 import java.awt.geom.*; 34 import java.util.*; 35 import java.util.regex.*; 39 import java.awt.Graphics2D; 40 import java.awt.Shape; 41 import java.awt.font.FontRenderContext; 42 import java.awt.geom.AffineTransform; 43 import java.awt.geom.GeneralPath; 44 import java.awt.geom.Rectangle2D; 45 import java.util.Iterator; 46 import java.util.LinkedList; 47 import java.util.regex.Matcher; 48 import java.util.regex.Pattern; 36 49 37 50 //import org.apache.batik.ext.awt.geom.ExtendedGeneralPath; 38 39 51 /** 40 52 * @author Mark McKay … … 43 55 public class Text extends ShapeElement 44 56 { 57 public static final String TAG_NAME = "text"; 45 58 46 59 float x = 0; 47 60 float y = 0; 48 61 AffineTransform transform = null; 49 50 62 String fontFamily; 51 63 float fontSize; 52 53 64 //List of strings and tspans containing the content of this node 54 65 LinkedList content = new LinkedList(); 55 56 66 Shape textShape; 57 58 67 public static final int TXAN_START = 0; 59 68 public static final int TXAN_MIDDLE = 1; 60 69 public static final int TXAN_END = 2; 61 70 int textAnchor = TXAN_START; 62 63 71 public static final int TXST_NORMAL = 0; 64 72 public static final int TXST_ITALIC = 1; 65 73 public static final int TXST_OBLIQUE = 2; 66 74 int fontStyle; 67 68 75 public static final int TXWE_NORMAL = 0; 69 76 public static final int TXWE_BOLD = 1; … … 80 87 public static final int TXWE_900 = 12; 81 88 int fontWeight; 82 83 /** Creates a new instance of Stop */ 89 90 /** 91 * Creates a new instance of Stop 92 */ 84 93 public Text() 85 94 { 86 95 } 87 96 97 public String getTagName() 98 { 99 return TAG_NAME; 100 } 101 88 102 public void appendText(String text) 89 103 { 90 104 content.addLast(text); 91 105 } 92 106 93 107 public void appendTspan(Tspan tspan) throws SVGElementException 94 108 { 95 109 super.loaderAddChild(null, tspan); 96 110 content.addLast(tspan); 97 // tspan.setParent(this); 98 } 99 111 } 112 100 113 /** 101 114 * Discard cached information … … 105 118 build(); 106 119 } 107 120 108 121 public java.util.List getContent() 109 122 { 110 123 return content; 111 124 } 112 /* 113 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 114 { 115 //Load style string 116 super.loaderStartElement(helper, attrs, parent); 117 118 String x = attrs.getValue("x"); 119 String y = attrs.getValue("y"); 120 //String transform = attrs.getValue("transform"); 121 122 this.x = XMLParseUtil.parseFloat(x); 123 this.y = XMLParseUtil.parseFloat(y); 124 } 125 */ 125 126 126 /** 127 127 * Called after the start element but before the end element to indicate … … 131 131 { 132 132 super.loaderAddChild(helper, child); 133 133 134 134 content.addLast(child); 135 135 } 136 136 137 137 /** 138 138 * Called during load process to add text scanned within a tag … … 141 141 { 142 142 Matcher matchWs = Pattern.compile("\\s*").matcher(text); 143 if (!matchWs.matches()) content.addLast(text); 144 } 145 143 if (!matchWs.matches()) 144 { 145 content.addLast(text); 146 } 147 } 148 146 149 public void build() throws SVGException 147 150 { 148 151 super.build(); 149 152 150 153 StyleAttribute sty = new StyleAttribute(); 151 152 if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits(); 153 154 if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits(); 155 156 if (getStyle(sty.setName("font-family"))) fontFamily = sty.getStringValue(); 157 else fontFamily = "Sans Serif"; 158 159 if (getStyle(sty.setName("font-size"))) fontSize = sty.getFloatValueWithUnits(); 160 else fontSize = 12f; 161 154 155 if (getPres(sty.setName("x"))) 156 { 157 x = sty.getFloatValueWithUnits(); 158 } 159 160 if (getPres(sty.setName("y"))) 161 { 162 y = sty.getFloatValueWithUnits(); 163 } 164 165 if (getStyle(sty.setName("font-family"))) 166 { 167 fontFamily = sty.getStringValue(); 168 } else 169 { 170 fontFamily = "Sans Serif"; 171 } 172 173 if (getStyle(sty.setName("font-size"))) 174 { 175 fontSize = sty.getFloatValueWithUnits(); 176 } else 177 { 178 fontSize = 12f; 179 } 180 162 181 if (getStyle(sty.setName("font-style"))) 163 182 { … … 166 185 { 167 186 fontStyle = TXST_NORMAL; 168 } 169 else if ("italic".equals(s)) 187 } else if ("italic".equals(s)) 170 188 { 171 189 fontStyle = TXST_ITALIC; 172 } 173 else if ("oblique".equals(s)) 190 } else if ("oblique".equals(s)) 174 191 { 175 192 fontStyle = TXST_OBLIQUE; 176 193 } 177 } 178 else fontStyle = TXST_NORMAL; 179 194 } else 195 { 196 fontStyle = TXST_NORMAL; 197 } 198 180 199 if (getStyle(sty.setName("font-weight"))) 181 200 { … … 184 203 { 185 204 fontWeight = TXWE_NORMAL; 186 } 187 else if ("bold".equals(s)) 205 } else if ("bold".equals(s)) 188 206 { 189 207 fontWeight = TXWE_BOLD; 190 208 } 191 } 192 else fontWeight = TXWE_BOLD; 193 209 } else 210 { 211 fontWeight = TXWE_BOLD; 212 } 213 194 214 if (getStyle(sty.setName("text-anchor"))) 195 215 { 196 216 String s = sty.getStringValue(); 197 if (s.equals("middle")) textAnchor = TXAN_MIDDLE; 198 else if (s.equals("end")) textAnchor = TXAN_END; 199 else textAnchor = TXAN_START; 200 } 201 else textAnchor = TXAN_START; 202 217 if (s.equals("middle")) 218 { 219 textAnchor = TXAN_MIDDLE; 220 } else if (s.equals("end")) 221 { 222 textAnchor = TXAN_END; 223 } else 224 { 225 textAnchor = TXAN_START; 226 } 227 } else 228 { 229 textAnchor = TXAN_START; 230 } 231 203 232 //text anchor 204 233 //text-decoration 205 234 //text-rendering 206 235 207 236 buildFont(); 208 237 } 209 238 210 239 protected void buildFont() throws SVGException 211 240 { … … 232 261 break; 233 262 } 234 263 235 264 //Get font 236 265 Font font = diagram.getUniverse().getFont(fontFamily); … … 238 267 { 239 268 // System.err.println("Could not load font"); 240 241 java.awt.Font sysFont = new java.awt.Font(fontFamily, style | weight, (int) fontSize);269 270 java.awt.Font sysFont = new java.awt.Font(fontFamily, style | weight, (int) fontSize); 242 271 buildSysFont(sysFont); 243 272 return; 244 273 } 245 274 246 275 // font = new java.awt.Font(font.getFamily(), style | weight, font.getSize()); 247 276 248 277 // Area textArea = new Area(); 249 278 GeneralPath textPath = new GeneralPath(); 250 279 textShape = textPath; 251 280 252 281 float cursorX = x, cursorY = y; 253 282 254 283 FontFace fontFace = font.getFontFace(); 255 284 //int unitsPerEm = fontFace.getUnitsPerEm(); 256 285 int ascent = fontFace.getAscent(); 257 float fontScale = fontSize / (float) ascent;258 286 float fontScale = fontSize / (float) ascent; 287 259 288 // AffineTransform oldXform = g.getTransform(); 260 289 AffineTransform xform = new AffineTransform(); 261 290 262 291 for (Iterator it = content.iterator(); it.hasNext();) 263 292 { 264 293 Object obj = it.next(); 265 294 266 295 if (obj instanceof String) 267 296 { 268 String text = (String)obj; 269 297 String text = (String) obj; 298 if (text != null) 299 { 300 text = text.trim(); 301 } 302 270 303 strokeWidthScalar = 1f / fontScale; 271 304 272 305 for (int i = 0; i < text.length(); i++) 273 306 { … … 276 309 xform.scale(fontScale, fontScale); 277 310 // g.transform(xform); 278 311 279 312 String unicode = text.substring(i, i + 1); 280 313 MissingGlyph glyph = font.getGlyph(unicode); 281 314 282 315 Shape path = glyph.getPath(); 283 316 if (path != null) … … 287 320 } 288 321 // else glyph.render(g); 289 322 290 323 cursorX += fontScale * glyph.getHorizAdvX(); 291 324 292 325 // g.setTransform(oldXform); 293 326 } 294 327 295 328 strokeWidthScalar = 1f; 296 } 297 else if (obj instanceof Tspan) 298 { 299 Tspan tspan = (Tspan)obj; 300 329 } else if (obj instanceof Tspan) 330 { 331 Tspan tspan = (Tspan) obj; 332 301 333 xform.setToIdentity(); 302 334 xform.setToTranslation(cursorX, cursorY); … … 304 336 // tspan.setCursorX(cursorX); 305 337 // tspan.setCursorY(cursorY); 306 338 307 339 Shape tspanShape = tspan.getShape(); 308 340 tspanShape = xform.createTransformedShape(tspanShape); … … 312 344 // cursorY = tspan.getCursorY(); 313 345 } 314 315 } 316 346 347 } 348 317 349 switch (textAnchor) 318 350 { … … 333 365 } 334 366 } 335 367 336 368 private void buildSysFont(java.awt.Font font) throws SVGException 337 369 { 338 370 GeneralPath textPath = new GeneralPath(); 339 371 textShape = textPath; 340 372 341 373 float cursorX = x, cursorY = y; 342 374 343 375 // FontMetrics fm = g.getFontMetrics(font); 344 376 FontRenderContext frc = new FontRenderContext(null, true, true); 345 377 346 378 // FontFace fontFace = font.getFontFace(); 347 379 //int unitsPerEm = fontFace.getUnitsPerEm(); 348 380 // int ascent = fm.getAscent(); 349 381 // float fontScale = fontSize / (float)ascent; 350 382 351 383 // AffineTransform oldXform = g.getTransform(); 352 384 AffineTransform xform = new AffineTransform(); 353 385 354 386 for (Iterator it = content.iterator(); it.hasNext();) 355 387 { 356 388 Object obj = it.next(); 357 389 358 390 if (obj instanceof String) 359 391 { 360 String text = (String) obj;361 392 String text = (String) obj; 393 362 394 Shape textShape = font.createGlyphVector(frc, text).getOutline(cursorX, cursorY); 363 395 textPath.append(textShape, false); 364 396 // renderShape(g, textShape); 365 397 // g.drawString(text, cursorX, cursorY); 366 398 367 399 Rectangle2D rect = font.getStringBounds(text, frc); 368 cursorX += (float)rect.getWidth(); 369 } 370 else if (obj instanceof Tspan) 400 cursorX += (float) rect.getWidth(); 401 } else if (obj instanceof Tspan) 371 402 { 372 403 /* 373 Tspan tspan = (Tspan)obj;404 Tspan tspan = (Tspan)obj; 374 405 375 xform.setToIdentity();376 xform.setToTranslation(cursorX, cursorY);406 xform.setToIdentity(); 407 xform.setToTranslation(cursorX, cursorY); 377 408 378 Shape tspanShape = tspan.getShape();379 tspanShape = xform.createTransformedShape(tspanShape);380 textArea.add(new Area(tspanShape));409 Shape tspanShape = tspan.getShape(); 410 tspanShape = xform.createTransformedShape(tspanShape); 411 textArea.add(new Area(tspanShape)); 381 412 382 cursorX += tspanShape.getBounds2D().getWidth();413 cursorX += tspanShape.getBounds2D().getWidth(); 383 414 */ 384 385 386 Tspan tspan = (Tspan) obj;415 416 417 Tspan tspan = (Tspan) obj; 387 418 tspan.setCursorX(cursorX); 388 419 tspan.setCursorY(cursorY); … … 390 421 cursorX = tspan.getCursorX(); 391 422 cursorY = tspan.getCursorY(); 392 393 } 394 } 395 423 424 } 425 } 426 396 427 switch (textAnchor) 397 428 { … … 412 443 } 413 444 } 414 415 445 416 446 public void render(Graphics2D g) throws SVGException 417 447 { … … 420 450 finishLayer(g); 421 451 } 422 452 423 453 public Shape getShape() 424 454 { 425 455 return shapeToParent(textShape); 426 456 } 427 457 428 458 public Rectangle2D getBoundingBox() throws SVGException 429 459 { 430 460 return boundsToParent(includeStrokeInBounds(textShape.getBounds2D())); 431 461 } 432 462 433 463 /** 434 * Updates all attributes in this diagram associated with a time event. 435 * Ie, all attributes with track information. 464 * Updates all attributes in this diagram associated with a time event. Ie, 465 * all attributes with track information. 466 * 436 467 * @return - true if this node has changed state as a result of the time 437 468 * update … … 441 472 // if (trackManager.getNumTracks() == 0) return false; 442 473 boolean changeState = super.updateTime(curTime); 443 474 444 475 //Get current values for parameters 445 476 StyleAttribute sty = new StyleAttribute(); 446 477 boolean shapeChange = false; 447 478 448 479 if (getPres(sty.setName("x"))) 449 480 { … … 455 486 } 456 487 } 457 488 458 489 if (getPres(sty.setName("y"))) 459 490 { … … 465 496 } 466 497 } 467 498 468 499 if (getPres(sty.setName("font-family"))) 469 500 { … … 475 506 } 476 507 } 477 508 478 509 if (getPres(sty.setName("font-size"))) 479 510 { … … 485 516 } 486 517 } 487 488 518 519 489 520 if (getStyle(sty.setName("font-style"))) 490 521 { … … 494 525 { 495 526 newVal = TXST_NORMAL; 496 } 497 else if ("italic".equals(s)) 527 } else if ("italic".equals(s)) 498 528 { 499 529 newVal = TXST_ITALIC; 500 } 501 else if ("oblique".equals(s)) 530 } else if ("oblique".equals(s)) 502 531 { 503 532 newVal = TXST_OBLIQUE; … … 509 538 } 510 539 } 511 540 512 541 if (getStyle(sty.setName("font-weight"))) 513 542 { … … 517 546 { 518 547 newVal = TXWE_NORMAL; 519 } 520 else if ("bold".equals(s)) 548 } else if ("bold".equals(s)) 521 549 { 522 550 newVal = TXWE_BOLD; … … 528 556 } 529 557 } 530 558 531 559 if (shapeChange) 532 560 { … … 535 563 // return true; 536 564 } 537 565 538 566 return changeState || shapeChange; 539 567 } -
trunk/src/com/kitfox/svg/Title.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 Title extends SVGElement { 37 44 public class Title extends SVGElement 45 { 46 public static final String TAG_NAME = "title"; 47 38 48 StringBuffer text = new StringBuffer(); 39 49 40 /** Creates a new instance of Stop */ 41 public Title() { 50 /** 51 * Creates a new instance of Stop 52 */ 53 public Title() 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 /** 55 * Updates all attributes in this diagram associated with a time event. 56 * Ie, all attributes with track information. 76 * Updates all attributes in this diagram associated with a time event. Ie, 77 * all attributes with track information. 78 * 57 79 * @return - true if this node has changed state as a result of the time 58 80 * update -
trunk/src/com/kitfox/svg/TransformableElement.java
r4453 r6002 1 1 /* 2 * BoundedElement.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, 9:00 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 … … 33 41 import java.awt.geom.Rectangle2D; 34 42 35 36 43 /** 37 44 * Maintains bounding box for this element … … 40 47 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 41 48 */ 42 public class TransformableElement extends SVGElement 49 abstract public class TransformableElement extends SVGElement 43 50 { 51 AffineTransform xform = null; 44 52 45 AffineTransform xform = null;46 // AffineTransform invXform = null; 47 48 /** Creates a new instance of BoundedElement */49 public TransformableElement(){53 /** 54 * Creates a new instance of BoundedElement 55 */ 56 public TransformableElement() 57 { 50 58 } 51 59 … … 55 63 } 56 64 65 /** 66 * Fetches a copy of the cached AffineTransform. Note that this value will 67 * only be valid after the node has been updated. 68 * 69 * @return 70 */ 57 71 public AffineTransform getXForm() 58 72 { 59 return xform ;73 return xform != null ? new AffineTransform(xform) : null; 60 74 } 61 /*62 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)63 {64 65 75 /* 76 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 77 { 78 //Load style string 79 super.loaderStartElement(helper, attrs, parent); 66 80 67 68 69 70 71 72 }73 */74 81 String transform = attrs.getValue("transform"); 82 if (transform != null) 83 { 84 xform = parseTransform(transform); 85 } 86 } 87 */ 88 75 89 protected void build() throws SVGException 76 90 { 77 91 super.build(); 78 92 79 93 StyleAttribute sty = new StyleAttribute(); 80 94 81 95 if (getPres(sty.setName("transform"))) 82 96 { … … 84 98 } 85 99 } 86 100 87 101 protected Shape shapeToParent(Shape shape) 88 102 { 89 if (xform == null) return shape; 103 if (xform == null) 104 { 105 return shape; 106 } 90 107 return xform.createTransformedShape(shape); 91 108 } … … 93 110 protected Rectangle2D boundsToParent(Rectangle2D rect) 94 111 { 95 if (xform == null) return rect; 112 if (xform == null) 113 { 114 return rect; 115 } 96 116 return xform.createTransformedShape(rect).getBounds2D(); 97 117 } 98 118 99 119 /** 100 * Updates all attributes in this diagram associated with a time event. 101 * Ie, all attributes with track information. 120 * Updates all attributes in this diagram associated with a time event. Ie, 121 * all attributes with track information. 122 * 102 123 * @return - true if this node has changed state as a result of the time 103 124 * update … … 106 127 { 107 128 StyleAttribute sty = new StyleAttribute(); 108 129 109 130 if (getPres(sty.setName("transform"))) 110 131 { … … 116 137 } 117 138 } 118 139 119 140 return false; 120 141 } -
trunk/src/com/kitfox/svg/Tspan.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 import java.awt.*; 32 import java.awt.font.*; 33 import java.awt.geom.*; 34 import java.util.*; 35 36 import com.kitfox.svg.xml.*; 37 import org.xml.sax.*; 38 39 //import org.apache.batik.ext.awt.geom.ExtendedGeneralPath; 39 import java.awt.Graphics2D; 40 import java.awt.Shape; 41 import java.awt.font.FontRenderContext; 42 import java.awt.font.GlyphMetrics; 43 import java.awt.font.GlyphVector; 44 import java.awt.geom.AffineTransform; 45 import java.awt.geom.GeneralPath; 46 import java.awt.geom.Rectangle2D; 40 47 41 48 /** … … 43 50 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 44 51 */ 45 public class Tspan extends ShapeElement { 46 52 public class Tspan extends ShapeElement 53 { 54 55 public static final String TAG_NAME = "tspan"; 47 56 float[] x = null; 48 57 float[] y = null; … … 50 59 float[] dy = null; 51 60 float[] rotate = null; 52 53 61 private String text = ""; 54 55 62 float cursorX; 56 63 float cursorY; 57 64 58 65 // Shape tspanShape; 59 60 /** Creates a new instance of Stop */ 61 public Tspan() { 62 } 63 64 public float getCursorX() { return cursorX; } 65 public float getCursorY() { return cursorY; } 66 /** 67 * Creates a new instance of Stop 68 */ 69 public Tspan() 70 { 71 } 72 73 public String getTagName() 74 { 75 return TAG_NAME; 76 } 77 78 public float getCursorX() 79 { 80 return cursorX; 81 } 82 83 public float getCursorY() 84 { 85 return cursorY; 86 } 66 87 67 88 public void setCursorX(float cursorX) … … 74 95 this.cursorY = cursorY; 75 96 } 76 /*77 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)78 {79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 }99 */97 /* 98 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 99 { 100 //Load style string 101 super.loaderStartElement(helper, attrs, parent); 102 103 String x = attrs.getValue("x"); 104 String y = attrs.getValue("y"); 105 String dx = attrs.getValue("dx"); 106 String dy = attrs.getValue("dy"); 107 String rotate = attrs.getValue("rotate"); 108 109 if (x != null) this.x = XMLParseUtil.parseFloatList(x); 110 if (y != null) this.y = XMLParseUtil.parseFloatList(y); 111 if (dx != null) this.dx = XMLParseUtil.parseFloatList(dx); 112 if (dy != null) this.dy = XMLParseUtil.parseFloatList(dy); 113 if (rotate != null) 114 { 115 this.rotate = XMLParseUtil.parseFloatList(rotate); 116 for (int i = 0; i < this.rotate.length; i++) 117 this.rotate[i] = (float)Math.toRadians(this.rotate[i]); 118 } 119 } 120 */ 100 121 101 122 /** … … 107 128 } 108 129 109 110 130 protected void build() throws SVGException 111 131 { 112 132 super.build(); 113 133 114 134 StyleAttribute sty = new StyleAttribute(); 115 116 if (getPres(sty.setName("x"))) x = sty.getFloatList(); 117 118 if (getPres(sty.setName("y"))) y = sty.getFloatList(); 119 120 if (getPres(sty.setName("dx"))) dx = sty.getFloatList(); 121 122 if (getPres(sty.setName("dy"))) dy = sty.getFloatList(); 135 136 if (getPres(sty.setName("x"))) 137 { 138 x = sty.getFloatList(); 139 } 140 141 if (getPres(sty.setName("y"))) 142 { 143 y = sty.getFloatList(); 144 } 145 146 if (getPres(sty.setName("dx"))) 147 { 148 dx = sty.getFloatList(); 149 } 150 151 if (getPres(sty.setName("dy"))) 152 { 153 dy = sty.getFloatList(); 154 } 123 155 124 156 if (getPres(sty.setName("rotate"))) … … 127 159 for (int i = 0; i < this.rotate.length; i++) 128 160 { 129 rotate[i] = (float) Math.toRadians(this.rotate[i]);130 } 131 132 } 133 } 134 161 rotate[i] = (float) Math.toRadians(this.rotate[i]); 162 } 163 164 } 165 } 166 135 167 public void addShape(GeneralPath addShape) throws SVGException 136 168 { … … 138 170 { 139 171 cursorX = x[0]; 172 } else if (dx != null) 173 { 174 cursorX += dx[0]; 175 } 176 177 if (y != null) 178 { 140 179 cursorY = y[0]; 141 } 142 else if (dx != null) 143 { 144 cursorX += dx[0]; 180 } else if (dy != null) 181 { 145 182 cursorY += dy[0]; 146 183 } 147 184 148 185 StyleAttribute sty = new StyleAttribute(); 149 186 150 187 String fontFamily = null; 151 188 if (getStyle(sty.setName("font-family"))) … … 160 197 fontSize = sty.getFloatValueWithUnits(); 161 198 } 199 200 float letterSpacing = 0; 201 if (getStyle(sty.setName("letter-spacing"))) 202 { 203 letterSpacing = sty.getFloatValueWithUnits(); 204 } 205 162 206 163 207 //Get font … … 165 209 if (font == null) 166 210 { 167 addShapeSysFont(addShape, font, fontFamily, fontSize );211 addShapeSysFont(addShape, font, fontFamily, fontSize, letterSpacing); 168 212 return; 169 213 } … … 171 215 FontFace fontFace = font.getFontFace(); 172 216 int ascent = fontFace.getAscent(); 173 float fontScale = fontSize / (float) ascent;217 float fontScale = fontSize / (float) ascent; 174 218 175 219 AffineTransform xform = new AffineTransform(); … … 184 228 xform.setToTranslation(cursorX, cursorY); 185 229 xform.scale(fontScale, fontScale); 186 if (rotate != null) xform.rotate(rotate[posPtr]); 230 if (rotate != null) 231 { 232 xform.rotate(rotate[posPtr]); 233 } 187 234 188 235 String unicode = text.substring(i, i + 1); … … 200 247 cursorX = x[posPtr]; 201 248 cursorY = y[posPtr++]; 202 } 203 else if (dx != null && posPtr < dx.length) 249 } else if (dx != null && posPtr < dx.length) 204 250 { 205 251 cursorX += dx[posPtr]; … … 207 253 } 208 254 209 cursorX += fontScale * glyph.getHorizAdvX() ;255 cursorX += fontScale * glyph.getHorizAdvX() + letterSpacing; 210 256 } 211 257 … … 213 259 } 214 260 215 private void addShapeSysFont(GeneralPath addShape, Font font, String fontFamily, float fontSize) 216 { 217 java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int)fontSize); 261 private void addShapeSysFont(GeneralPath addShape, Font font, 262 String fontFamily, float fontSize, float letterSpacing) 263 { 264 java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int) fontSize); 218 265 219 266 FontRenderContext frc = new FontRenderContext(null, true, true); … … 226 273 { 227 274 xform.setToIdentity(); 228 xform.setToTranslation(cursorX, cursorY); 229 if (rotate != null) xform.rotate(rotate[Math.min(i, rotate.length - 1)]); 275 xform.setToTranslation(cursorX + i * letterSpacing, cursorY); 276 if (rotate != null) 277 { 278 xform.rotate(rotate[Math.min(i, rotate.length - 1)]); 279 } 230 280 231 281 String unicode = text.substring(i, i + 1); … … 240 290 cursorX = x[posPtr]; 241 291 cursorY = y[posPtr++]; 242 } 243 else if (dx != null && posPtr < dx.length) 292 } else if (dx != null && posPtr < dx.length) 244 293 { 245 294 cursorX += dx[posPtr]; … … 255 304 cursorX = x[0]; 256 305 cursorY = y[0]; 257 } 258 else if (dx != null) 306 } else if (dx != null) 259 307 { 260 308 cursorX += dx[0]; … … 263 311 264 312 StyleAttribute sty = new StyleAttribute(); 265 313 266 314 String fontFamily = null; 267 315 if (getPres(sty.setName("font-family"))) … … 282 330 { 283 331 System.err.println("Could not load font"); 284 java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int) fontSize);332 java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int) fontSize); 285 333 renderSysFont(g, sysFont); 286 334 return; … … 290 338 FontFace fontFace = font.getFontFace(); 291 339 int ascent = fontFace.getAscent(); 292 float fontScale = fontSize / (float) ascent;340 float fontScale = fontSize / (float) ascent; 293 341 294 342 AffineTransform oldXform = g.getTransform(); … … 312 360 { 313 361 renderShape(g, path); 314 } 315 else glyph.render(g); 362 } else 363 { 364 glyph.render(g); 365 } 316 366 317 367 if (x != null && posPtr < x.length) … … 319 369 cursorX = x[posPtr]; 320 370 cursorY = y[posPtr++]; 321 } 322 else if (dx != null && posPtr < dx.length) 371 } else if (dx != null && posPtr < dx.length) 323 372 { 324 373 cursorX += dx[posPtr]; … … 342 391 renderShape(g, textShape); 343 392 Rectangle2D rect = font.getStringBounds(text, frc); 344 cursorX += (float) rect.getWidth();393 cursorX += (float) rect.getWidth(); 345 394 } 346 395 … … 358 407 359 408 /** 360 * Updates all attributes in this diagram associated with a time event. 361 * Ie, all attributes with track information. 409 * Updates all attributes in this diagram associated with a time event. Ie, 410 * all attributes with track information. 411 * 362 412 * @return - true if this node has changed state as a result of the time 363 413 * update -
trunk/src/com/kitfox/svg/Use.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 … … 39 47 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 40 48 */ 41 public class Use extends ShapeElement { 42 49 public class Use extends ShapeElement 50 { 51 public static final String TAG_NAME = "use"; 52 43 53 float x = 0f; 44 54 float y = 0f; 45 55 float width = 1f; 46 56 float height = 1f; 47 48 SVGElement href = null; 49 57 // SVGElement href = null; 58 URI href = null; 50 59 AffineTransform refXform; 51 60 52 /** Creates a new instance of LinearGradient */ 53 public Use() { 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 x = attrs.getValue("x"); 62 String y = attrs.getValue("y"); 63 String width = attrs.getValue("width"); 64 String height = attrs.getValue("height"); 65 String href = attrs.getValue("xlink:href"); 66 67 if (x != null) this.x = (float)XMLParseUtil.parseRatio(x); 68 if (y != null) this.y = (float)XMLParseUtil.parseRatio(y); 69 if (width != null) this.width = (float)XMLParseUtil.parseRatio(width); 70 if (height != null) this.height = (float)XMLParseUtil.parseRatio(height); 71 72 73 if (href != null) 74 { 75 try { 76 URI src = getXMLBase().resolve(href); 77 this.href = helper.universe.getElement(src); 78 } 79 catch (Exception e) 80 { 81 e.printStackTrace(); 82 } 61 /** 62 * Creates a new instance of LinearGradient 63 */ 64 public Use() 65 { 66 } 67 68 public String getTagName() 69 { 70 return TAG_NAME; 71 } 72 73 protected void build() throws SVGException 74 { 75 super.build(); 76 77 StyleAttribute sty = new StyleAttribute(); 78 79 if (getPres(sty.setName("x"))) 80 { 81 x = sty.getFloatValueWithUnits(); 82 } 83 84 if (getPres(sty.setName("y"))) 85 { 86 y = sty.getFloatValueWithUnits(); 87 } 88 89 if (getPres(sty.setName("width"))) 90 { 91 width = sty.getFloatValueWithUnits(); 92 } 93 94 if (getPres(sty.setName("height"))) 95 { 96 height = sty.getFloatValueWithUnits(); 97 } 98 99 if (getPres(sty.setName("xlink:href"))) 100 { 101 URI src = sty.getURIValue(getXMLBase()); 102 href = src; 103 // href = diagram.getUniverse().getElement(src); 83 104 } 84 105 … … 86 107 refXform = new AffineTransform(); 87 108 refXform.translate(this.x, this.y); 88 refXform.scale(this.width, this.height); 89 } 90 */ 91 protected void build() throws SVGException 92 { 93 super.build(); 94 95 StyleAttribute sty = new StyleAttribute(); 96 97 if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits(); 98 99 if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits(); 100 101 if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits(); 102 103 if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits(); 104 105 if (getPres(sty.setName("xlink:href"))) 106 { 107 URI src = sty.getURIValue(getXMLBase()); 108 href = diagram.getUniverse().getElement(src); 109 } 110 111 //Determine use offset/scale 112 refXform = new AffineTransform(); 113 refXform.translate(this.x, this.y); 114 } 115 109 } 110 116 111 public void render(Graphics2D g) throws SVGException 117 112 { … … 122 117 g.transform(refXform); 123 118 124 if (href == null || !(href instanceof RenderableElement)) return; 125 126 RenderableElement rendEle = (RenderableElement)href; 119 SVGElement ref = diagram.getUniverse().getElement(href); 120 121 if (ref == null || !(ref instanceof RenderableElement)) 122 { 123 return; 124 } 125 126 RenderableElement rendEle = (RenderableElement) ref; 127 127 rendEle.pushParentContext(this); 128 128 rendEle.render(g); … … 136 136 public Shape getShape() 137 137 { 138 if (href instanceof ShapeElement) 139 { 140 Shape shape = ((ShapeElement)href).getShape(); 138 SVGElement ref = diagram.getUniverse().getElement(href); 139 if (ref instanceof ShapeElement) 140 { 141 Shape shape = ((ShapeElement) ref).getShape(); 141 142 shape = refXform.createTransformedShape(shape); 142 143 shape = shapeToParent(shape); … … 149 150 public Rectangle2D getBoundingBox() throws SVGException 150 151 { 151 if (href instanceof ShapeElement) 152 { 153 ShapeElement shapeEle = (ShapeElement)href; 152 SVGElement ref = diagram.getUniverse().getElement(href); 153 if (ref instanceof ShapeElement) 154 { 155 ShapeElement shapeEle = (ShapeElement) ref; 154 156 shapeEle.pushParentContext(this); 155 157 Rectangle2D bounds = shapeEle.getBoundingBox(); 156 158 shapeEle.popParentContext(); 157 159 158 160 bounds = refXform.createTransformedShape(bounds).getBounds2D(); 159 161 bounds = boundsToParent(bounds); … … 166 168 167 169 /** 168 * Updates all attributes in this diagram associated with a time event. 169 * Ie, all attributes with track information. 170 * Updates all attributes in this diagram associated with a time event. Ie, 171 * all attributes with track information. 172 * 170 173 * @return - true if this node has changed state as a result of the time 171 174 * update … … 179 182 StyleAttribute sty = new StyleAttribute(); 180 183 boolean shapeChange = false; 184 185 if (getPres(sty.setName("x"))) 186 { 187 float newVal = sty.getFloatValueWithUnits(); 188 if (newVal != x) 189 { 190 x = newVal; 191 shapeChange = true; 192 } 193 } 194 195 if (getPres(sty.setName("y"))) 196 { 197 float newVal = sty.getFloatValueWithUnits(); 198 if (newVal != y) 199 { 200 y = newVal; 201 shapeChange = true; 202 } 203 } 204 205 if (getPres(sty.setName("width"))) 206 { 207 float newVal = sty.getFloatValueWithUnits(); 208 if (newVal != width) 209 { 210 width = newVal; 211 shapeChange = true; 212 } 213 } 214 215 if (getPres(sty.setName("height"))) 216 { 217 float newVal = sty.getFloatValueWithUnits(); 218 if (newVal != height) 219 { 220 height = newVal; 221 shapeChange = true; 222 } 223 } 224 225 if (getPres(sty.setName("xlink:href"))) 226 { 227 URI src = sty.getURIValue(getXMLBase()); 228 // SVGElement newVal = diagram.getUniverse().getElement(src); 229 if (!src.equals(href)) 230 { 231 href = src; 232 shapeChange = true; 233 } 234 } 235 /* 236 if (getPres(sty.setName("xlink:href"))) 237 { 238 URI src = sty.getURIValue(getXMLBase()); 239 href = diagram.getUniverse().getElement(src); 240 } 181 241 182 if (getPres(sty.setName("x"))) 183 { 184 float newVal = sty.getFloatValueWithUnits(); 185 if (newVal != x) 186 { 187 x = newVal; 188 shapeChange = true; 189 } 190 } 191 192 if (getPres(sty.setName("y"))) 193 { 194 float newVal = sty.getFloatValueWithUnits(); 195 if (newVal != y) 196 { 197 y = newVal; 198 shapeChange = true; 199 } 200 } 201 202 if (getPres(sty.setName("width"))) 203 { 204 float newVal = sty.getFloatValueWithUnits(); 205 if (newVal != width) 206 { 207 width = newVal; 208 shapeChange = true; 209 } 210 } 211 212 if (getPres(sty.setName("height"))) 213 { 214 float newVal = sty.getFloatValueWithUnits(); 215 if (newVal != height) 216 { 217 height = newVal; 218 shapeChange = true; 219 } 220 } 221 222 if (getPres(sty.setName("xlink:href"))) 223 { 224 URI src = sty.getURIValue(getXMLBase()); 225 SVGElement newVal = diagram.getUniverse().getElement(src); 226 if (newVal != href) 227 { 228 href = newVal; 229 shapeChange = true; 230 } 231 } 232 /* 233 if (getPres(sty.setName("xlink:href"))) 234 { 235 URI src = sty.getURIValue(getXMLBase()); 236 href = diagram.getUniverse().getElement(src); 237 } 238 239 //Determine use offset/scale 240 refXform = new AffineTransform(); 241 refXform.translate(this.x, this.y); 242 refXform.scale(this.width, this.height); 243 */ 242 //Determine use offset/scale 243 refXform = new AffineTransform(); 244 refXform.translate(this.x, this.y); 245 refXform.scale(this.width, this.height); 246 */ 244 247 if (shapeChange) 245 248 { … … 250 253 // return true; 251 254 } 252 255 253 256 return changeState || shapeChange; 254 257 } -
trunk/src/com/kitfox/svg/app/beans/SVGIcon.java
r4256 r6002 1 1 /* 2 * SVGIcon.java 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 3 33 * 4 34 * Created on April 21, 2005, 10:45 AM … … 7 37 package com.kitfox.svg.app.beans; 8 38 9 import javax.swing.*;39 import com.kitfox.svg.*; 10 40 import java.awt.*; 11 41 import java.awt.geom.*; 42 import java.beans.*; 12 43 import java.net.*; 13 import java.beans.*; 14 15 import com.kitfox.svg.*; 44 import javax.swing.*; 16 45 17 46 /** … … 69 98 70 99 SVGDiagram diagram = svgUniverse.getDiagram(svgURI); 71 if (diagram == null) return 0; 100 if (diagram == null) 101 { 102 return 0; 103 } 72 104 return (int)diagram.getHeight(); 73 105 } … … 84 116 85 117 SVGDiagram diagram = svgUniverse.getDiagram(svgURI); 86 if (diagram == null) return 0; 118 if (diagram == null) 119 { 120 return 0; 121 } 87 122 return (int)diagram.getWidth(); 88 123 } … … 97 132 public void paintIcon(Component comp, Graphics gg, int x, int y) 98 133 { 99 Graphics2D g = (Graphics2D)gg; 100 134 //Copy graphics object so that 135 Graphics2D g = (Graphics2D)gg.create(); 136 paintIcon(comp, g, x, y); 137 g.dispose(); 138 } 139 140 private void paintIcon(Component comp, Graphics2D g, int x, int y) 141 { 101 142 Object oldAliasHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING); 102 143 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); … … 118 159 119 160 SVGDiagram diagram = svgUniverse.getDiagram(svgURI); 120 if (diagram == null) return; 161 if (diagram == null) 162 { 163 return; 164 } 121 165 122 166 g.translate(x, y); … … 189 233 190 234 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAliasHint); 191 if (oldInterpolationHint != null) g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldInterpolationHint); 235 if (oldInterpolationHint != null) 236 { 237 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldInterpolationHint); 238 } 192 239 } 193 240 -
trunk/src/com/kitfox/svg/app/data/Handler.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 34 6 35 package com.kitfox.svg.app.data; 7 36 37 import com.kitfox.svg.SVGConst; 8 38 import java.io.ByteArrayInputStream; 9 39 import java.io.IOException; … … 12 42 import java.net.URLConnection; 13 43 import java.net.URLStreamHandler; 44 import java.util.logging.Level; 45 import java.util.logging.Logger; 14 46 15 47 /** … … 36 68 { 37 69 content = content.substring(7); 38 try { 70 try 71 { 39 72 buf = new sun.misc.BASE64Decoder().decodeBuffer(content); 40 } catch (IOException ex) { 41 ex.printStackTrace(); 73 } 74 catch (IOException e) 75 { 76 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 42 77 } 43 78 } -
trunk/src/com/kitfox/svg/batik/LinearGradientPaint.java
r4256 r6002 9 9 package com.kitfox.svg.batik; 10 10 11 import com.kitfox.svg.SVGConst; 11 12 import java.awt.Color; 12 13 import java.awt.PaintContext; … … 18 19 import java.awt.geom.Rectangle2D; 19 20 import java.awt.image.ColorModel; 21 import java.util.logging.Level; 22 import java.util.logging.Logger; 20 23 21 24 /** … … 323 326 colorSpace); 324 327 } 325 326 catch(NoninvertibleTransformException e){327 e.printStackTrace();328 catch(NoninvertibleTransformException e) 329 { 330 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 328 331 throw new IllegalArgumentException("transform should be" + 329 332 "invertible"); -
trunk/src/com/kitfox/svg/composite/AdobeComposite.java
r4256 r6002 1 1 /* 2 * AdobeComposite.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 April 1, 2004, 6:40 AM … … 28 37 package com.kitfox.svg.composite; 29 38 39 import com.kitfox.svg.SVGConst; 30 40 import java.awt.*; 31 41 import java.awt.image.*; 42 import java.util.logging.Level; 43 import java.util.logging.Logger; 32 44 33 45 /** … … 52 64 if (compositeType < 0 || compositeType >= CT_LAST) 53 65 { 54 new Exception("Invalid composite type").printStackTrace();66 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, "Invalid composite type"); 55 67 } 56 68 57 69 if (extraAlpha < 0f || extraAlpha > 1f) 58 70 { 59 new Exception("Invalid alpha").printStackTrace();71 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, "Invalid alpha"); 60 72 } 61 73 } -
trunk/src/com/kitfox/svg/composite/AdobeCompositeContext.java
r4256 r6002 1 1 /* 2 * AdobeCompositeContext.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 April 1, 2004, 6:41 AM -
trunk/src/com/kitfox/svg/pathcmd/Arc.java
r4256 r6002 1 1 /* 2 * MoveTo.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, 8:40 PM … … 70 79 public void appendPath(GeneralPath path, BuildHistory hist) 71 80 { 72 float offx = isRelative ? hist.history[0].x : 0f; 73 float offy = isRelative ? hist.history[0].y : 0f; 74 75 arcTo(path, rx, ry, xAxisRot, largeArc, sweep, x + offx, y + offy, hist.history[0].x, hist.history[0].y); 81 float offx = isRelative ? hist.lastPoint.x : 0f; 82 float offy = isRelative ? hist.lastPoint.y : 0f; 83 84 arcTo(path, rx, ry, xAxisRot, largeArc, sweep, 85 x + offx, y + offy, 86 hist.lastPoint.x, hist.lastPoint.y); 76 87 // path.lineTo(x + offx, y + offy); 77 hist.setPoint(x + offx, y + offy); 88 // hist.setPoint(x + offx, y + offy); 89 hist.setLastPoint(x + offx, y + offy); 90 hist.setLastKnot(x + offx, y + offy); 78 91 } 79 92 … … 243 256 return arc; 244 257 } 258 259 public String toString() 260 { 261 return "A " + rx + " " + ry 262 + " " + xAxisRot + " " + largeArc 263 + " " + sweep 264 + " " + x + " " + y; 265 } 245 266 } -
trunk/src/com/kitfox/svg/pathcmd/BuildHistory.java
r4256 r6002 1 1 /* 2 * BuildHistory.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, 9:18 PM 26 35 */ 27 28 36 package com.kitfox.svg.pathcmd; 29 37 … … 32 40 /** 33 41 * When building a path from command segments, most need to cache information 34 * (such as the point finished at) for future commands. 42 * (such as the point finished at) for future commands. This structure allows 35 43 * that 36 44 * … … 38 46 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 39 47 */ 40 public class BuildHistory { 48 public class BuildHistory 49 { 41 50 42 51 // Point2D.Float[] history = new Point2D.Float[2]; 43 Point2D.Float[] history = {new Point2D.Float(), new Point2D.Float()}; 44 Point2D.Float start = new Point2D.Float(); 45 int length = 0; 52 // Point2D.Float[] history = {new Point2D.Float(), new Point2D.Float()}; 53 // Point2D.Float start = new Point2D.Float(); 54 Point2D.Float startPoint = new Point2D.Float(); 55 Point2D.Float lastPoint = new Point2D.Float(); 56 Point2D.Float lastKnot = new Point2D.Float(); 57 boolean init; 58 //int length = 0; 46 59 47 /** Creates a new instance of BuildHistory */ 48 public BuildHistory() { 60 /** 61 * Creates a new instance of BuildHistory 62 */ 63 public BuildHistory() 64 { 49 65 } 50 51 public void set Point(float x, float y)66 67 public void setStartPoint(float x, float y) 52 68 { 53 history[0].setLocation(x, y); 54 length = 1; 69 startPoint.setLocation(x, y); 55 70 } 56 57 public void set Start(float x, float y)71 72 public void setLastPoint(float x, float y) 58 73 { 59 start.setLocation(x, y);74 lastPoint.setLocation(x, y); 60 75 } 61 62 public void set PointAndKnot(float x, float y, float kx, float ky)76 77 public void setLastKnot(float x, float y) 63 78 { 64 history[0].setLocation(x, y); 65 history[1].setLocation(kx, ky); 66 length = 2; 79 lastKnot.setLocation(x, y); 67 80 } 81 // public void setPoint(float x, float y) 82 // { 83 // history[0].setLocation(x, y); 84 // length = 1; 85 // } 86 // public void setStart(float x, float y) 87 // { 88 // start.setLocation(x, y); 89 // } 90 // public void setPointAndKnot(float x, float y, float kx, float ky) 91 // { 92 // history[0].setLocation(x, y); 93 // history[1].setLocation(kx, ky); 94 // length = 2; 95 // } 68 96 } -
trunk/src/com/kitfox/svg/pathcmd/Cubic.java
r4256 r6002 1 1 /* 2 * MoveTo.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, 8:40 PM … … 48 57 } 49 58 59 public String toString() 60 { 61 return "C " + k1x + " " + k1y 62 + " " + k2x + " " + k2y 63 + " " + x + " " + y; 64 } 65 50 66 public Cubic(boolean isRelative, float k1x, float k1y, float k2x, float k2y, float x, float y) { 51 67 super(isRelative); … … 61 77 public void appendPath(GeneralPath path, BuildHistory hist) 62 78 { 63 float offx = isRelative ? hist. history[0].x : 0f;64 float offy = isRelative ? hist. history[0].y : 0f;79 float offx = isRelative ? hist.lastPoint.x : 0f; 80 float offy = isRelative ? hist.lastPoint.y : 0f; 65 81 66 path.curveTo(k1x + offx, k1y + offy, k2x + offx, k2y + offy, x + offx, y + offy); 67 hist.setPointAndKnot(x + offx, y + offy, k2x + offx, k2y + offy); 82 path.curveTo(k1x + offx, k1y + offy, 83 k2x + offx, k2y + offy, 84 x + offx, y + offy); 85 // hist.setPointAndKnot(x + offx, y + offy, k2x + offx, k2y + offy); 86 hist.setLastPoint(x + offx, y + offy); 87 hist.setLastKnot(k2x + offx, k2y + offy); 68 88 } 69 89 -
trunk/src/com/kitfox/svg/pathcmd/CubicSmooth.java
r4256 r6002 1 1 /* 2 * MoveTo.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, 8:40 PM … … 57 66 public void appendPath(GeneralPath path, BuildHistory hist) 58 67 { 59 float offx = isRelative ? hist. history[0].x : 0f;60 float offy = isRelative ? hist. history[0].y : 0f;68 float offx = isRelative ? hist.lastPoint.x : 0f; 69 float offy = isRelative ? hist.lastPoint.y : 0f; 61 70 62 float oldKx = hist. history.length >= 2 ? hist.history[1].x : hist.history[0].x;63 float oldKy = hist. history.length >= 2 ? hist.history[1].y : hist.history[0].y;64 float oldX = hist. history[0].x;65 float oldY = hist. history[0].y;71 float oldKx = hist.lastKnot.x; 72 float oldKy = hist.lastKnot.y; 73 float oldX = hist.lastPoint.x; 74 float oldY = hist.lastPoint.y; 66 75 //Calc knot as reflection of old knot 67 76 float k1x = oldX * 2f - oldKx; … … 69 78 70 79 path.curveTo(k1x, k1y, k2x + offx, k2y + offy, x + offx, y + offy); 71 hist.setPointAndKnot(x + offx, y + offy, k2x + offx, k2y + offy); 80 hist.setLastPoint(x + offx, y + offy); 81 hist.setLastKnot(k2x + offx, k2y + offy); 72 82 } 73 83 … … 76 86 return 6; 77 87 } 88 89 public String toString() 90 { 91 return "S " + k2x + " " + k2y 92 + " " + x + " " + y; 93 } 78 94 } -
trunk/src/com/kitfox/svg/pathcmd/Horizontal.java
r4256 r6002 1 1 /* 2 * MoveTo.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, 8:40 PM … … 43 52 } 44 53 54 public String toString() 55 { 56 return "H " + x; 57 } 58 45 59 public Horizontal(boolean isRelative, float x) { 46 60 super(isRelative); … … 52 66 public void appendPath(GeneralPath path, BuildHistory hist) 53 67 { 54 float offx = isRelative ? hist. history[0].x : 0f;55 float offy = hist. history[0].y;68 float offx = isRelative ? hist.lastPoint.x : 0f; 69 float offy = hist.lastPoint.y; 56 70 57 71 path.lineTo(x + offx, offy); 58 hist.setPoint(x + offx, offy); 72 hist.setLastPoint(x + offx, offy); 73 hist.setLastKnot(x + offx, offy); 59 74 } 60 75 -
trunk/src/com/kitfox/svg/pathcmd/LineTo.java
r4256 r6002 1 1 /* 2 * MoveTo.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, 8:40 PM … … 54 63 public void appendPath(GeneralPath path, BuildHistory hist) 55 64 { 56 float offx = isRelative ? hist. history[0].x : 0f;57 float offy = isRelative ? hist. history[0].y : 0f;65 float offx = isRelative ? hist.lastPoint.x : 0f; 66 float offy = isRelative ? hist.lastPoint.y : 0f; 58 67 59 68 path.lineTo(x + offx, y + offy); 60 hist.setPoint(x + offx, y + offy); 69 hist.setLastPoint(x + offx, y + offy); 70 hist.setLastKnot(x + offx, y + offy); 61 71 } 62 72 … … 65 75 return 2; 66 76 } 77 78 public String toString() 79 { 80 return "L " + x + " " + y; 81 } 67 82 } -
trunk/src/com/kitfox/svg/pathcmd/MoveTo.java
r4256 r6002 1 1 /* 2 * MoveTo.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, 8:40 PM … … 53 62 public void appendPath(GeneralPath path, BuildHistory hist) 54 63 { 55 float offx = isRelative ? hist. history[0].x : 0f;56 float offy = isRelative ? hist. history[0].y : 0f;64 float offx = isRelative ? hist.lastPoint.x : 0f; 65 float offy = isRelative ? hist.lastPoint.y : 0f; 57 66 58 67 path.moveTo(x + offx, y + offy); 59 hist.setPoint(x + offx, y + offy); 60 hist.setStart(x + offx, y + offy); 68 hist.setStartPoint(x + offx, y + offy); 69 hist.setLastPoint(x + offx, y + offy); 70 hist.setLastKnot(x + offx, y + offy); 61 71 } 62 72 … … 65 75 return 2; 66 76 } 77 78 public String toString() 79 { 80 return "M " + x + " " + y; 81 } 82 83 67 84 } -
trunk/src/com/kitfox/svg/pathcmd/PathCommand.java
r4256 r6002 1 1 /* 2 * PathCommand.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, 8:39 PM -
trunk/src/com/kitfox/svg/pathcmd/PathUtil.java
r4256 r6002 1 1 /* 2 * PathUtil.java 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 3 33 * 4 34 * Created on May 10, 2005, 5:56 AM 5 *6 * To change this template, choose Tools | Options and locate the template under7 * the Source Creation and Management node. Right-click the template and choose8 * Open. You can then make changes to the template in the Source Editor.9 35 */ 10 36 -
trunk/src/com/kitfox/svg/pathcmd/Quadratic.java
r4256 r6002 1 1 /* 2 * MoveTo.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, 8:40 PM … … 46 55 } 47 56 57 public String toString() 58 { 59 return "Q " + kx + " " + ky 60 + " " + x + " " + y; 61 } 62 48 63 public Quadratic(boolean isRelative, float kx, float ky, float x, float y) { 49 64 super(isRelative); … … 57 72 public void appendPath(GeneralPath path, BuildHistory hist) 58 73 { 59 float offx = isRelative ? hist. history[0].x : 0f;60 float offy = isRelative ? hist. history[0].y : 0f;74 float offx = isRelative ? hist.lastPoint.x : 0f; 75 float offy = isRelative ? hist.lastPoint.y : 0f; 61 76 62 77 path.quadTo(kx + offx, ky + offy, x + offx, y + offy); 63 hist.setPointAndKnot(x + offx, y + offy, kx + offx, ky + offy); 78 hist.setLastPoint(x + offx, y + offy); 79 hist.setLastKnot(kx + offx, ky + offy); 64 80 } 65 81 -
trunk/src/com/kitfox/svg/pathcmd/QuadraticSmooth.java
r4256 r6002 1 1 /* 2 * MoveTo.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, 8:40 PM … … 44 53 } 45 54 55 public String toString() 56 { 57 return "T " + x + " " + y; 58 } 59 46 60 public QuadraticSmooth(boolean isRelative, float x, float y) { 47 61 super(isRelative); … … 53 67 public void appendPath(GeneralPath path, BuildHistory hist) 54 68 { 55 float offx = isRelative ? hist. history[0].x : 0f;56 float offy = isRelative ? hist. history[0].y : 0f;69 float offx = isRelative ? hist.lastPoint.x : 0f; 70 float offy = isRelative ? hist.lastPoint.y : 0f; 57 71 58 float oldKx = hist. history.length >= 2 ? hist.history[1].x : hist.history[0].x;59 float oldKy = hist. history.length >= 2 ? hist.history[1].y : hist.history[0].y;60 float oldX = hist. history[0].x;61 float oldY = hist. history[0].y;72 float oldKx = hist.lastKnot.x; 73 float oldKy = hist.lastKnot.y; 74 float oldX = hist.lastPoint.x; 75 float oldY = hist.lastPoint.y; 62 76 //Calc knot as reflection of old knot 63 77 float kx = oldX * 2f - oldKx; … … 65 79 66 80 path.quadTo(kx, ky, x + offx, y + offy); 67 hist.setPointAndKnot(x + offx, y + offy, kx, ky); 81 hist.setLastPoint(x + offx, y + offy); 82 hist.setLastKnot(kx, ky); 68 83 } 69 84 -
trunk/src/com/kitfox/svg/pathcmd/Terminal.java
r4256 r6002 1 1 /* 2 * MoveTo.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, 8:40 PM … … 43 52 } 44 53 54 public String toString() 55 { 56 return "Z"; 57 } 58 45 59 46 60 // public void appendPath(ExtendedGeneralPath path, BuildHistory hist) … … 48 62 { 49 63 path.closePath(); 50 hist.setPoint(hist.start.x, hist.start.y); 64 hist.setLastPoint(hist.startPoint.x, hist.startPoint.y); 65 hist.setLastKnot(hist.startPoint.x, hist.startPoint.y); 51 66 } 52 67 -
trunk/src/com/kitfox/svg/pathcmd/Vertical.java
r4256 r6002 1 1 /* 2 * MoveTo.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, 8:40 PM … … 43 52 } 44 53 54 public String toString() 55 { 56 return "V " + y; 57 } 58 45 59 public Vertical(boolean isRelative, float y) { 46 60 super(isRelative); … … 51 65 public void appendPath(GeneralPath path, BuildHistory hist) 52 66 { 53 float offx = hist. history[0].x;54 float offy = isRelative ? hist. history[0].y : 0f;67 float offx = hist.lastPoint.x; 68 float offy = isRelative ? hist.lastPoint.y : 0f; 55 69 56 70 path.lineTo(offx, y + offy); 57 hist.setPoint(offx, y + offy); 71 hist.setLastPoint(offx, y + offy); 72 hist.setLastKnot(offx, y + offy); 58 73 } 59 74 -
trunk/src/com/kitfox/svg/pattern/PatternPaint.java
r4256 r6002 1 1 /* 2 * PatternPaint.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 April 1, 2004, 3:37 AM -
trunk/src/com/kitfox/svg/pattern/PatternPaintContext.java
r4256 r6002 1 1 /* 2 * PatternPaintContext.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 April 1, 2004, 3:37 AM … … 28 37 package com.kitfox.svg.pattern; 29 38 39 import com.kitfox.svg.SVGConst; 30 40 import java.awt.*; 31 41 import java.awt.geom.*; 32 42 import java.awt.image.*; 43 import java.util.logging.Level; 44 import java.util.logging.Logger; 33 45 34 46 /** … … 66 78 xform.concatenate(userXform.createInverse()); 67 79 } 68 catch (Exception e) { e.printStackTrace(); } 80 catch (Exception e) 81 { 82 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 83 } 69 84 70 85 sourceWidth = source.getWidth(); -
trunk/src/com/kitfox/svg/xml/Base64InputStream.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 34 -
trunk/src/com/kitfox/svg/xml/Base64OutputStream.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 34 -
trunk/src/com/kitfox/svg/xml/Base64Util.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 34 -
trunk/src/com/kitfox/svg/xml/ColorTable.java
r4256 r6002 1 1 /* 2 * ColorTable.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, 4:34 AM -
trunk/src/com/kitfox/svg/xml/NumberWithUnits.java
r4256 r6002 1 1 /* 2 * NumberWithUnits.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 18, 2004, 2:43 PM -
trunk/src/com/kitfox/svg/xml/ReadableXMLElement.java
r4256 r6002 1 1 /* 2 * LoadableObject.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 1, 2003, 1:46 AM -
trunk/src/com/kitfox/svg/xml/StyleAttribute.java
r4256 r6002 1 1 /* 2 * StyleAttribute.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 27, 2004, 2:53 PM … … 28 37 package com.kitfox.svg.xml; 29 38 39 import com.kitfox.svg.SVGConst; 30 40 import java.awt.*; 41 import java.io.*; 31 42 import java.net.*; 32 import java.io.*; 43 import java.util.logging.Level; 44 import java.util.logging.Logger; 33 45 import java.util.regex.*; 34 46 … … 41 53 public static final long serialVersionUID = 0; 42 54 43 static final Matcher matchUrl = Pattern.compile("\\s*url\\((.*)\\)\\s*").matcher("");55 static final Pattern patternUrl = Pattern.compile("\\s*url\\((.*)\\)\\s*"); 44 56 static final Matcher matchFpNumUnits = Pattern.compile("\\s*([-+]?((\\d*\\.\\d+)|(\\d+))([-+]?[eE]\\d+)?)\\s*(px|cm|mm|in|pc|pt|em|ex)\\s*").matcher(""); 45 57 … … 68 80 } 69 81 70 public String getName() { return name; } 71 public StyleAttribute setName(String name) { this.name = name; return this; } 72 73 public String getStringValue() { return stringValue; } 82 public String getName() { 83 return name; 84 } 85 86 public StyleAttribute setName(String name) 87 { 88 this.name = name; 89 return this; 90 } 91 92 public String getStringValue() 93 { 94 return stringValue; 95 } 74 96 75 97 public String[] getStringList() … … 177 199 public String parseURLFn() 178 200 { 179 matchUrl.reset(stringValue); 180 if (!matchUrl.matches()) return null; 201 Matcher matchUrl = patternUrl.matcher(stringValue); 202 if (!matchUrl.matches()) 203 { 204 return null; 205 } 181 206 return matchUrl.group(1); 182 207 } … … 191 216 catch (Exception e) 192 217 { 193 e.printStackTrace();218 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 194 219 return null; 195 220 } … … 206 231 catch (Exception e) 207 232 { 208 e.printStackTrace();233 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 209 234 return null; 210 235 } … … 264 289 catch (Exception e) 265 290 { 266 e.printStackTrace();291 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 267 292 return null; 268 293 } … … 285 310 catch (Exception e) 286 311 { 287 e.printStackTrace();312 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 288 313 } 289 314 } -
trunk/src/com/kitfox/svg/xml/WritableXMLElement.java
r4256 r6002 1 1 /* 2 * LoadableObject.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 1, 2003, 1:46 AM -
trunk/src/com/kitfox/svg/xml/XMLParseUtil.java
r4256 r6002 1 1 /* 2 * XMLParseUtil.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 18, 2004, 1:49 PM … … 28 37 package com.kitfox.svg.xml; 29 38 39 import com.kitfox.svg.SVGConst; 30 40 import org.w3c.dom.*; 31 41 import java.awt.*; … … 34 44 import java.util.regex.*; 35 45 import java.lang.reflect.*; 46 import java.util.logging.Level; 47 import java.util.logging.Logger; 36 48 37 49 /** … … 140 152 catch (StringIndexOutOfBoundsException e) 141 153 { 142 System.err.println("XMLParseUtil: regex parse problem: '" + val + "'");143 e.printStackTrace();154 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 155 "XMLParseUtil: regex parse problem: '" + val + "'", e); 144 156 } 145 157 … … 537 549 538 550 ReadableXMLElement newObj = null; 539 try { newObj = (ReadableXMLElement)classType.newInstance(); } 540 catch (Exception e) { e.printStackTrace(); continue; } 551 try 552 { 553 newObj = (ReadableXMLElement)classType.newInstance(); 554 } 555 catch (Exception e) 556 { 557 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 558 continue; 559 } 541 560 newObj.read(ele, docRoot); 542 561 … … 567 586 HashMap retMap = new HashMap(); 568 587 569 /*570 Class[] params = {Element.class, URL.class};571 Method loadMethod = null;572 try { loadMethod = classType.getMethod("load", params); }573 catch (Exception e) { e.printStackTrace(); return null; }574 575 */576 588 NodeList nl = root.getChildNodes(); 577 589 int size = nl.getLength(); … … 584 596 585 597 ReadableXMLElement newObj = null; 586 try { newObj = (ReadableXMLElement)classType.newInstance(); } 587 catch (Exception e) { e.printStackTrace(); continue; } 598 try 599 { 600 newObj = (ReadableXMLElement)classType.newInstance(); 601 } 602 catch (Exception e) 603 { 604 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 605 continue; 606 } 588 607 newObj.read(ele, docRoot); 589 /* 590 Object[] args = {ele, source}; 591 Object obj = null; 592 try { obj = loadMethod.invoke(null, args); } 593 catch (Exception e) { e.printStackTrace(); } 594 595 */ 608 596 609 if (newObj == null) continue; 597 610 … … 614 627 615 628 HashSet retSet = new HashSet(); 616 617 /*618 Class[] params = {Element.class, URL.class};619 Method loadMethod = null;620 try { loadMethod = classType.getMethod("load", params); }621 catch (Exception e) { e.printStackTrace(); return null; }622 */623 629 624 630 NodeList nl = root.getChildNodes(); … … 632 638 633 639 ReadableXMLElement newObj = null; 634 try { newObj = (ReadableXMLElement)classType.newInstance(); } 635 catch (Exception e) { e.printStackTrace(); continue; } 640 try 641 { 642 newObj = (ReadableXMLElement)classType.newInstance(); 643 } 644 catch (Exception e) 645 { 646 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 647 continue; 648 } 636 649 newObj.read(ele, docRoot); 637 /* 638 Object[] args = {ele, source}; 639 Object obj = null; 640 try { obj = loadMethod.invoke(null, args); } 641 catch (Exception e) { e.printStackTrace(); } 642 */ 643 644 if (newObj == null) continue; 650 651 if (newObj == null) 652 { 653 continue; 654 } 645 655 646 656 retSet.add(newObj); … … 672 682 673 683 ReadableXMLElement newObj = null; 674 try { newObj = (ReadableXMLElement)classType.newInstance(); } 675 catch (Exception e) { e.printStackTrace(); continue; } 684 try 685 { 686 newObj = (ReadableXMLElement)classType.newInstance(); 687 } 688 catch (Exception e) 689 { 690 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 691 continue; 692 } 676 693 newObj.read(ele, docRoot); 677 694 … … 790 807 public static HashMap parseStyle(String styleString, HashMap map) { 791 808 final Pattern patSemi = Pattern.compile(";"); 792 final Pattern patColonSpace = Pattern.compile(":");793 794 //Strips left and right whitespace795 final Matcher matcherContent = Pattern.compile("\\s*([^\\s](.*[^\\s])?)\\s*").matcher("");796 809 797 810 String[] styles = patSemi.split(styleString); … … 804 817 } 805 818 806 String[] vals = patColonSpace.split(styles[i]); 807 808 matcherContent.reset(vals[0]); 809 matcherContent.matches(); 810 vals[0] = matcherContent.group(1); 811 812 matcherContent.reset(vals[1]); 813 matcherContent.matches(); 814 vals[1] = matcherContent.group(1); 815 816 map.put(vals[0], new StyleAttribute(vals[0], vals[1])); 819 int colon = styles[i].indexOf(':'); 820 if (colon == -1) 821 { 822 continue; 823 } 824 825 String key = styles[i].substring(0, colon).trim(); 826 String value = styles[i].substring(colon + 1).trim(); 827 828 map.put(key, new StyleAttribute(key, value)); 817 829 } 818 830 -
trunk/src/com/kitfox/svg/xml/cpx/CPXConsts.java
r4256 r6002 1 1 /* 2 * CPXConst.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 12, 2004, 12:51 PM -
trunk/src/com/kitfox/svg/xml/cpx/CPXInputStream.java
r4256 r6002 1 1 /* 2 * CPXInputStream.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 12, 2004, 10:34 AM … … 28 37 package com.kitfox.svg.xml.cpx; 29 38 39 import com.kitfox.svg.SVGConst; 30 40 import java.io.*; 31 41 import java.util.*; 32 42 import java.util.zip.*; 33 43 import java.security.*; 44 import java.util.logging.Level; 45 import java.util.logging.Logger; 34 46 import javax.crypto.*; 35 47 … … 201 213 catch (Exception e) 202 214 { 203 e.printStackTrace();215 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 204 216 return -1; 205 217 } … … 207 219 if (!inflater.finished()) 208 220 { 209 new Exception("Inflation incomplete").printStackTrace(); 221 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 222 "Inflation imncomplete"); 210 223 } 211 224 … … 213 226 } 214 227 215 try { 228 try 229 { 216 230 return inflater.inflate(b, off, len); 217 231 } 218 232 catch (DataFormatException e) 219 233 { 220 e.printStackTrace();234 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 221 235 return -1; 222 236 } -
trunk/src/com/kitfox/svg/xml/cpx/CPXOutputStream.java
r4256 r6002 1 1 /* 2 * CPXOutputStream.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 12, 2004, 12:50 PM -
trunk/src/com/kitfox/svg/xml/cpx/CPXTest.java
r4256 r6002 1 1 /* 2 * CPXTest.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 12, 2004, 2:45 PM … … 28 37 package com.kitfox.svg.xml.cpx; 29 38 39 import com.kitfox.svg.SVGConst; 30 40 import java.io.*; 31 import java.net.*; 41 import java.util.logging.Level; 42 import java.util.logging.Logger; 32 43 33 44 /** … … 65 76 catch (Exception e) 66 77 { 67 e.printStackTrace();78 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 68 79 } 69 80 } … … 87 98 catch (Exception e) 88 99 { 89 e.printStackTrace();100 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); 90 101 } 91 102 } … … 94 105 * @param args the command line arguments 95 106 */ 96 public static void main(String[] args) { 107 public static void main(String[] args) 108 { 97 109 new CPXTest(); 98 110 }
Note:
See TracChangeset
for help on using the changeset viewer.