Changeset 10787 in josm for trunk/src/com/kitfox/svg
- Timestamp:
- 2016-08-12T03:16:58+02:00 (8 years ago)
- Location:
- trunk/src/com/kitfox/svg
- Files:
-
- 4 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/LinearGradient.java
r8084 r10787 38 38 import com.kitfox.svg.xml.StyleAttribute; 39 39 import java.awt.Color; 40 import java.awt.LinearGradientPaint; 41 import java.awt.MultipleGradientPaint; 40 42 import java.awt.Paint; 41 43 import java.awt.geom.AffineTransform; … … 97 99 public Paint getPaint(Rectangle2D bounds, AffineTransform xform) 98 100 { 99 com.kitfox.svg.batik.MultipleGradientPaint.CycleMethodEnummethod;101 MultipleGradientPaint.CycleMethod method; 100 102 switch (spreadMethod) 101 103 { 102 104 default: 103 105 case SM_PAD: 104 method = com.kitfox.svg.batik.MultipleGradientPaint.NO_CYCLE;106 method = MultipleGradientPaint.CycleMethod.NO_CYCLE; 105 107 break; 106 108 case SM_REPEAT: 107 method = com.kitfox.svg.batik.MultipleGradientPaint.REPEAT;109 method = MultipleGradientPaint.CycleMethod.REPEAT; 108 110 break; 109 111 case SM_REFLECT: 110 method = com.kitfox.svg.batik.MultipleGradientPaint.REFLECT;112 method = MultipleGradientPaint.CycleMethod.REFLECT; 111 113 break; 112 114 } … … 121 123 } else if (gradientUnits == GU_USER_SPACE_ON_USE) 122 124 { 123 paint = new com.kitfox.svg.batik.LinearGradientPaint(125 paint = new LinearGradientPaint( 124 126 pt1, 125 127 pt2, … … 127 129 getStopColors(), 128 130 method, 129 com.kitfox.svg.batik.MultipleGradientPaint.SRGB,131 MultipleGradientPaint.ColorSpaceType.SRGB, 130 132 gradientTransform == null 131 133 ? new AffineTransform() … … 146 148 } 147 149 148 paint = new com.kitfox.svg.batik.LinearGradientPaint(150 paint = new LinearGradientPaint( 149 151 pt1, 150 152 pt2, … … 152 154 getStopColors(), 153 155 method, 154 com.kitfox.svg.batik.MultipleGradientPaint.SRGB,156 MultipleGradientPaint.ColorSpaceType.SRGB, 155 157 viewXform); 156 158 } -
trunk/src/com/kitfox/svg/Path.java
r8084 r10787 42 42 import java.awt.geom.Rectangle2D; 43 43 44 //import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;45 44 /** 46 45 * @author Mark McKay -
trunk/src/com/kitfox/svg/RadialGradient.java
r8084 r10787 4 4 * All rights reserved. 5 5 * 6 * Redistribution and use in source and binary forms, with or 6 * Redistribution and use in source and binary forms, with or 7 7 * without modification, are permitted provided that the following 8 8 * conditions are met: 9 9 * 10 * - Redistributions of source code must retain the above 10 * - Redistributions of source code must retain the above 11 11 * copyright notice, this list of conditions and the following 12 12 * disclaimer. 13 13 * - Redistributions in binary form must reproduce the above 14 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials 15 * disclaimer in the documentation and/or other materials 16 16 * provided with the distribution. 17 17 * … … 27 27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 31 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other 32 32 * projects can be found at http://www.kitfox.com … … 36 36 package com.kitfox.svg; 37 37 38 import com.kitfox.svg.xml.StyleAttribute; 39 import java.awt.Color; 38 import java.awt.MultipleGradientPaint; 40 39 import java.awt.Paint; 40 import java.awt.RadialGradientPaint; 41 41 import java.awt.geom.AffineTransform; 42 42 import java.awt.geom.Point2D; 43 43 import java.awt.geom.Rectangle2D; 44 import java.util.Arrays; 45 46 import com.kitfox.svg.xml.StyleAttribute; 44 47 45 48 /** … … 53 56 float cx = 0.5f; 54 57 float cy = 0.5f; 55 float fx = 0.5f; 56 float fy = 0.5f; 58 boolean hasFocus = false; 59 float fx = 0f; 60 float fy = 0f; 57 61 float r = 0.5f; 58 62 … … 64 68 } 65 69 70 @Override 66 71 public String getTagName() 67 72 { … … 69 74 } 70 75 76 @Override 71 77 protected void build() throws SVGException 72 78 { … … 85 91 } 86 92 93 hasFocus = false; 87 94 if (getPres(sty.setName("fx"))) 88 95 { 89 96 fx = sty.getFloatValueWithUnits(); 97 hasFocus = true; 90 98 } 91 99 … … 93 101 { 94 102 fy = sty.getFloatValueWithUnits(); 103 hasFocus = true; 95 104 } 96 105 … … 101 110 } 102 111 112 @Override 103 113 public Paint getPaint(Rectangle2D bounds, AffineTransform xform) 104 114 { 105 com.kitfox.svg.batik.MultipleGradientPaint.CycleMethodEnummethod;115 MultipleGradientPaint.CycleMethod method; 106 116 switch (spreadMethod) 107 117 { 108 118 default: 109 119 case SM_PAD: 110 method = com.kitfox.svg.batik.MultipleGradientPaint.NO_CYCLE;120 method = MultipleGradientPaint.CycleMethod.NO_CYCLE; 111 121 break; 112 122 case SM_REPEAT: 113 method = com.kitfox.svg.batik.MultipleGradientPaint.REPEAT;123 method = MultipleGradientPaint.CycleMethod.REPEAT; 114 124 break; 115 125 case SM_REFLECT: 116 method = com.kitfox.svg.batik.MultipleGradientPaint.REFLECT;126 method = MultipleGradientPaint.CycleMethod.REFLECT; 117 127 break; 118 128 } … … 120 130 Paint paint; 121 131 Point2D.Float pt1 = new Point2D.Float(cx, cy); 122 Point2D.Float pt2 = new Point2D.Float(fx, fy);132 Point2D.Float pt2 = hasFocus ? new Point2D.Float(fx, fy) : pt1; 123 133 if (gradientUnits == GU_USER_SPACE_ON_USE) 124 134 { 125 paint = new com.kitfox.svg.batik.RadialGradientPaint(135 paint = new RadialGradientPaint( 126 136 pt1, 127 137 r, … … 130 140 getStopColors(), 131 141 method, 132 com.kitfox.svg.batik.MultipleGradientPaint.SRGB,142 MultipleGradientPaint.ColorSpaceType.SRGB, 133 143 gradientTransform); 134 144 } else … … 140 150 viewXform.concatenate(gradientTransform); 141 151 142 paint = new com.kitfox.svg.batik.RadialGradientPaint(152 paint = new RadialGradientPaint( 143 153 pt1, 144 154 r, … … 147 157 getStopColors(), 148 158 method, 149 com.kitfox.svg.batik.MultipleGradientPaint.SRGB,159 MultipleGradientPaint.ColorSpaceType.SRGB, 150 160 viewXform); 151 161 } … … 161 171 * update 162 172 */ 173 @Override 163 174 public boolean updateTime(double curTime) throws SVGException 164 175 { -
trunk/src/com/kitfox/svg/SVGRoot.java
r8084 r10787 263 263 prepareViewport(); 264 264 265 Rectangle targetViewport = g.getClipBounds(); 266 267 Rectangle deviceViewport = diagram.getDeviceViewport(); 268 if (width != null && height != null) 269 { 270 float xx, yy, ww, hh; 271 272 xx = (x == null) ? 0 : StyleAttribute.convertUnitsToPixels(x.getUnits(), x.getValue()); 273 if (width.getUnits() == NumberWithUnits.UT_PERCENT) 274 { 275 ww = width.getValue() * deviceViewport.width; 276 } 277 else 278 { 279 ww = StyleAttribute.convertUnitsToPixels(width.getUnits(), width.getValue()); 280 } 281 282 yy = (y == null) ? 0 : StyleAttribute.convertUnitsToPixels(y.getUnits(), y.getValue()); 283 if (height.getUnits() == NumberWithUnits.UT_PERCENT) 284 { 285 hh = height.getValue() * deviceViewport.height; 286 } 287 else 288 { 289 hh = StyleAttribute.convertUnitsToPixels(height.getUnits(), height.getValue()); 290 } 291 292 targetViewport = new Rectangle((int)xx, (int)yy, (int)ww, (int)hh); 293 } 294 else 295 { 296 targetViewport = new Rectangle(deviceViewport); 297 } 298 clipRect.setRect(targetViewport); 299 265 300 if (viewBox == null) 266 301 { … … 269 304 else 270 305 { 271 Rectangle deviceViewport = g.getClipBounds();272 //If viewport window is set, we are drawing to entire viewport273 clipRect.setRect(deviceViewport);274 275 306 viewXform.setToIdentity(); 276 viewXform.setToTranslation( deviceViewport.x, deviceViewport.y);277 viewXform.scale( deviceViewport.width, deviceViewport.height);307 viewXform.setToTranslation(targetViewport.x, targetViewport.y); 308 viewXform.scale(targetViewport.width, targetViewport.height); 278 309 viewXform.scale(1 / viewBox.width, 1 / viewBox.height); 279 310 viewXform.translate(-viewBox.x, -viewBox.y); -
trunk/src/com/kitfox/svg/ShapeElement.java
r8084 r10787 76 76 } 77 77 78 @Override 78 79 abstract public void render(java.awt.Graphics2D g) throws SVGException; 79 80 … … 85 86 */ 86 87 88 @Override 87 89 void pick(Point2D point, boolean boundingBox, List retVec) throws SVGException 88 90 { … … 95 97 } 96 98 99 @Override 97 100 void pick(Rectangle2D pickArea, AffineTransform ltw, boolean boundingBox, List retVec) throws SVGException 98 101 { … … 161 164 if (ele != null) 162 165 { 163 fillPaint = ((FillElement)ele).getPaint(bounds, xform); 166 try { 167 fillPaint = ((FillElement)ele).getPaint(bounds, xform); 168 } catch (IllegalArgumentException e) { 169 throw new SVGException(e); 170 } 164 171 } 165 172 } -
trunk/src/com/kitfox/svg/Text.java
r8084 r10787 37 37 38 38 import com.kitfox.svg.util.FontSystem; 39 import com.kitfox.svg.util.TextBuilder;40 39 import com.kitfox.svg.xml.StyleAttribute; 41 40 import java.awt.Graphics2D; 42 41 import java.awt.Shape; 43 import java.awt.font.FontRenderContext;44 42 import java.awt.geom.AffineTransform; 45 43 import java.awt.geom.GeneralPath; … … 51 49 import java.util.regex.Pattern; 52 50 53 //import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;54 51 /** 55 52 * @author Mark McKay … … 265 262 protected void buildText() throws SVGException 266 263 { 267 268 264 //Get font 269 Font font = diagram.getUniverse().getFont(fontFamily); 265 String[] families = fontFamily.split(","); 266 Font font = null; 267 for (int i = 0; i < families.length; ++i) 268 { 269 font = diagram.getUniverse().getFont(fontFamily); 270 if (font != null) 271 { 272 break; 273 } 274 } 275 270 276 if (font == null) 271 277 { 272 // System.err.println("Could not load font");273 274 278 font = new FontSystem(fontFamily, fontStyle, fontWeight, (int)fontSize); 275 // java.awt.Font sysFont = new java.awt.Font(fontFamily, style | weight, (int)fontSize); 276 // buildSysFont(sysFont); 277 // return; 278 } 279 280 // font = new java.awt.Font(font.getFamily(), style | weight, font.getSize()); 281 282 // Area textArea = new Area(); 279 } 280 283 281 GeneralPath textPath = new GeneralPath(); 284 282 textShape = textPath; … … 286 284 float cursorX = x, cursorY = y; 287 285 288 FontFace fontFace = font.getFontFace();289 //int unitsPerEm = fontFace.getUnitsPerEm();290 int ascent = fontFace.getAscent();291 float fontScale = fontSize / (float) ascent;292 293 // AffineTransform oldXform = g.getTransform();294 // TextBuilder builder = new TextBuilder();295 //296 // for (Iterator it = content.iterator(); it.hasNext();)297 // {298 // Object obj = it.next();299 //300 // if (obj instanceof String)301 // {302 // String text = (String) obj;303 // if (text != null)304 // {305 // text = text.trim();306 // }307 //308 // for (int i = 0; i < text.length(); i++)309 // {310 // String unicode = text.substring(i, i + 1);311 // MissingGlyph glyph = font.getGlyph(unicode);312 //313 // builder.appendGlyph(glyph);314 // }315 // }316 // else if (obj instanceof Tspan)317 // {318 // Tspan tspan = (Tspan)obj;319 // tspan.buildGlyphs(builder);320 // }321 // }322 //323 // builder.formatGlyphs();324 325 326 327 328 329 330 331 332 286 AffineTransform xform = new AffineTransform(); 333 287 … … 344 298 } 345 299 346 strokeWidthScalar = 1f / fontScale;347 348 300 for (int i = 0; i < text.length(); i++) 349 301 { 350 302 xform.setToIdentity(); 351 303 xform.setToTranslation(cursorX, cursorY); 352 xform.scale(fontScale, fontScale);353 // g.transform(xform);354 304 355 305 String unicode = text.substring(i, i + 1); … … 362 312 textPath.append(path, false); 363 313 } 364 // else glyph.render(g); 365 366 cursorX += fontScale * glyph.getHorizAdvX(); 367 368 // g.setTransform(oldXform); 314 315 cursorX += glyph.getHorizAdvX(); 369 316 } 370 317 -
trunk/src/com/kitfox/svg/Tspan.java
r8084 r10787 231 231 { 232 232 font = new FontSystem(fontFamily, fontStyle, fontWeight, (int)fontSize); 233 // addShapeSysFont(addShape, font, fontFamily, fontSize, letterSpacing, cursor); 234 // return; 235 } 236 237 FontFace fontFace = font.getFontFace(); 238 int ascent = fontFace.getAscent(); 239 float fontScale = fontSize / (float) ascent; 233 } 240 234 241 235 AffineTransform xform = new AffineTransform(); 242 243 strokeWidthScalar = 1f / fontScale;244 236 245 237 float cursorX = (float)cursor.getX(); 246 238 float cursorY = (float)cursor.getY(); 247 239 248 // int i = 0;249 250 240 String drawText = this.text; 251 241 drawText = drawText.trim(); … … 267 257 cursorY += dy[i]; 268 258 } 269 // i++;270 259 271 260 xform.setToIdentity(); 272 261 xform.setToTranslation(cursorX, cursorY); 273 xform.scale(fontScale, fontScale);274 262 if (rotate != null) 275 263 { … … 287 275 } 288 276 289 cursorX += fontScale *glyph.getHorizAdvX() + letterSpacing;277 cursorX += glyph.getHorizAdvX() + letterSpacing; 290 278 } 291 279 -
trunk/src/com/kitfox/svg/app/beans/SVGIcon.java
r8084 r10787 37 37 package com.kitfox.svg.app.beans; 38 38 39 import com.kitfox.svg.*; 40 import java.awt.*; 41 import java.awt.geom.*; 42 import java.beans.*; 43 import java.net.*; 44 import javax.swing.*; 39 import com.kitfox.svg.SVGCache; 40 import com.kitfox.svg.SVGDiagram; 41 import com.kitfox.svg.SVGException; 42 import com.kitfox.svg.SVGUniverse; 43 import java.awt.Component; 44 import java.awt.Dimension; 45 import java.awt.Graphics; 46 import java.awt.Graphics2D; 47 import java.awt.Image; 48 import java.awt.Rectangle; 49 import java.awt.RenderingHints; 50 import java.awt.geom.AffineTransform; 51 import java.awt.geom.Rectangle2D; 52 import java.awt.image.BufferedImage; 53 import java.beans.PropertyChangeListener; 54 import java.beans.PropertyChangeSupport; 55 import java.net.URI; 56 import javax.swing.ImageIcon; 57 45 58 46 59 /** … … 48 61 * @author kitfox 49 62 */ 50 public class SVGIcon implementsIcon63 public class SVGIcon extends ImageIcon 51 64 { 52 65 public static final long serialVersionUID = 1; … … 94 107 } 95 108 109 public Image getImage() 110 { 111 BufferedImage bi = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB); 112 paintIcon(null, bi.getGraphics(), 0, 0); 113 return bi; 114 } 115 96 116 /** 97 117 * @return height of this icon -
trunk/src/com/kitfox/svg/util/FontSystem.java
r8084 r10787 1 1 /* 2 * To change this license header, choose License Headers in Project Properties. 3 * To change this template file, choose Tools | Templates 4 * 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 33 * 34 * Created on April 24, 2015 5 35 */ 6 36 package com.kitfox.svg.util; -
trunk/src/com/kitfox/svg/util/TextBuilder.java
r8084 r10787 1 1 /* 2 * To change this license header, choose License Headers in Project Properties. 3 * To change this template file, choose Tools | Templates 4 * 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 33 * 34 * Created on April 24, 2015 5 35 */ 6 36 package com.kitfox.svg.util;
Note:
See TracChangeset
for help on using the changeset viewer.