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