Changeset 6002 in josm for trunk/src/com/kitfox/svg/RenderableElement.java
- Timestamp:
- 2013-06-11T01:01:28+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.