- Timestamp:
- 2018-10-14T15:15:50+02:00 (6 years ago)
- Location:
- trunk/src
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/ClipPath.java
r11525 r14328 132 132 * all attributes with track information. 133 133 * 134 * @param curTime 134 * @param curTime Time at which to evaluate node 135 135 * @return - true if this node has changed state as a result of the time 136 136 * update -
trunk/src/com/kitfox/svg/FillElement.java
r8084 r14328 59 59 * @param xform - The current transformation that the shape is being 60 60 * rendered under. 61 * @return paint object 61 62 */ 62 63 abstract public Paint getPaint(Rectangle2D bounds, AffineTransform xform); -
trunk/src/com/kitfox/svg/Gradient.java
r11525 r14328 160 160 } 161 161 162 private void buildStops() 163 { 164 ArrayList<Stop> stopList = new ArrayList<>(stops); 165 stopList.sort((o1, o2) -> Float.compare(o1.offset, o2.offset)); 166 167 //Remove doubles 168 for (int i = stopList.size() - 2; i > 0; --i) 169 { 170 if (stopList.get(i + 1).offset == stopList.get(i).offset) 171 { 172 stopList.remove(i + 1); 173 } 174 } 175 176 stopFractions = new float[stopList.size()]; 177 stopColors = new Color[stopList.size()]; 178 int idx = 0; 179 for (Stop stop : stopList) 180 { 181 int stopColorVal = stop.color.getRGB(); 182 Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int) (stop.opacity * 255), 0, 255)); 183 184 stopColors[idx] = stopColor; 185 stopFractions[idx] = stop.offset; 186 idx++; 187 } 188 } 189 162 190 public float[] getStopFractions() 163 191 { … … 173 201 } 174 202 175 stopFractions = new float[stops.size()]; 176 int idx = 0; 177 for (Stop stop : stops) { 178 float val = stop.offset; 179 if (idx != 0 && val < stopFractions[idx - 1]) 180 { 181 val = stopFractions[idx - 1]; 182 } 183 stopFractions[idx++] = val; 184 } 203 buildStops(); 185 204 186 205 return stopFractions; … … 200 219 } 201 220 202 stopColors = new Color[stops.size()]; 203 int idx = 0; 204 for (Stop stop : stops) { 205 int stopColorVal = stop.color.getRGB(); 206 Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int) (stop.opacity * 255), 0, 255)); 207 stopColors[idx++] = stopColor; 208 } 221 buildStops(); 209 222 210 223 return stopColors; 211 }212 213 public void setStops(Color[] colors, float[] fractions)214 {215 if (colors.length != fractions.length)216 {217 throw new IllegalArgumentException();218 }219 220 this.stopColors = colors;221 this.stopFractions = fractions;222 stopRef = null;223 224 } 224 225 -
trunk/src/com/kitfox/svg/Group.java
r11525 r14328 259 259 * Recalculates the bounding box by taking the union of the bounding boxes 260 260 * of all children. Caches the result. 261 * @throws com.kitfox.svg.SVGException 261 262 */ 262 263 public void calcBoundingBox() throws SVGException -
trunk/src/com/kitfox/svg/ImageSVG.java
r11526 r14328 115 115 { 116 116 URI src = sty.getURIValue(getXMLBase()); 117 // CVE-2017-5617: Allow only data scheme118 117 if ("data".equals(src.getScheme())) 119 118 { 120 119 imageSrc = new URL(null, src.toASCIIString(), new Handler()); 121 120 } 121 else 122 { 123 if (!diagram.getUniverse().isImageDataInlineOnly()) 124 { 125 try 126 { 127 imageSrc = src.toURL(); 128 } catch (Exception e) 129 { 130 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 131 "Could not parse xlink:href " + src, e); 132 imageSrc = null; 133 } 134 } 135 } 122 136 } 123 137 } catch (Exception e) … … 126 140 } 127 141 128 if (imageSrc != null) 129 { 130 diagram.getUniverse().registerImage(imageSrc); 131 132 //Set widths if not set 133 BufferedImage img = diagram.getUniverse().getImage(imageSrc); 134 if (img == null) 135 { 136 xform = new AffineTransform(); 137 bounds = new Rectangle2D.Float(); 138 return; 139 } 140 141 if (width == 0) 142 { 143 width = img.getWidth(); 144 } 145 if (height == 0) 146 { 147 height = img.getHeight(); 148 } 149 150 //Determine image xform 142 diagram.getUniverse().registerImage(imageSrc); 143 144 //Set widths if not set 145 BufferedImage img = diagram.getUniverse().getImage(imageSrc); 146 if (img == null) 147 { 151 148 xform = new AffineTransform(); 152 xform.translate(this.x, this.y); 153 xform.scale(this.width / img.getWidth(), this.height / img.getHeight()); 154 } 149 bounds = new Rectangle2D.Float(); 150 return; 151 } 152 153 if (width == 0) 154 { 155 width = img.getWidth(); 156 } 157 if (height == 0) 158 { 159 height = img.getHeight(); 160 } 161 162 //Determine image xform 163 xform = new AffineTransform(); 164 xform.translate(this.x, this.y); 165 xform.scale(this.width / img.getWidth(), this.height / img.getHeight()); 155 166 156 167 bounds = new Rectangle2D.Float(this.x, this.y, this.width, this.height); … … 326 337 URI src = sty.getURIValue(getXMLBase()); 327 338 328 URL newVal = null; 329 // CVE-2017-5617: Allow only data scheme 339 URL newVal; 330 340 if ("data".equals(src.getScheme())) 331 341 { 332 342 newVal = new URL(null, src.toASCIIString(), new Handler()); 343 } else 344 { 345 newVal = src.toURL(); 333 346 } 334 347 335 if ( newVal != null &&!newVal.equals(imageSrc))348 if (!newVal.equals(imageSrc)) 336 349 { 337 350 imageSrc = newVal; -
trunk/src/com/kitfox/svg/MissingGlyph.java
r11525 r14328 61 61 private Shape path = null; 62 62 //Alternately, we may have child graphical elements 63 private int horizAdvX = -1; //Inherits font's value if not set64 private int vertOriginX = -1; //Inherits font's value if not set65 private int vertOriginY = -1; //Inherits font's value if not set66 private int vertAdvY = -1; //Inherits font's value if not set63 private float horizAdvX = -1; //Inherits font's value if not set 64 private float vertOriginX = -1; //Inherits font's value if not set 65 private float vertOriginY = -1; //Inherits font's value if not set 66 private float vertAdvY = -1; //Inherits font's value if not set 67 67 68 68 /** … … 132 132 if (getPres(sty.setName("horiz-adv-x"))) 133 133 { 134 horizAdvX = sty.get IntValue();134 horizAdvX = sty.getFloatValue(); 135 135 } 136 136 137 137 if (getPres(sty.setName("vert-origin-x"))) 138 138 { 139 vertOriginX = sty.get IntValue();139 vertOriginX = sty.getFloatValue(); 140 140 } 141 141 142 142 if (getPres(sty.setName("vert-origin-y"))) 143 143 { 144 vertOriginY = sty.get IntValue();144 vertOriginY = sty.getFloatValue(); 145 145 } 146 146 147 147 if (getPres(sty.setName("vert-adv-y"))) 148 148 { 149 vertAdvY = sty.get IntValue();149 vertAdvY = sty.getFloatValue(); 150 150 } 151 151 } … … 179 179 } 180 180 181 public int getHorizAdvX()181 public float getHorizAdvX() 182 182 { 183 183 if (horizAdvX == -1) … … 188 188 } 189 189 190 public int getVertOriginX()190 public float getVertOriginX() 191 191 { 192 192 if (vertOriginX == -1) … … 197 197 } 198 198 199 public int getVertOriginY()199 public float getVertOriginY() 200 200 { 201 201 if (vertOriginY == -1) … … 206 206 } 207 207 208 public int getVertAdvY()208 public float getVertAdvY() 209 209 { 210 210 if (vertAdvY == -1) … … 261 261 * @param horizAdvX the horizAdvX to set 262 262 */ 263 public void setHorizAdvX( int horizAdvX)263 public void setHorizAdvX(float horizAdvX) 264 264 { 265 265 this.horizAdvX = horizAdvX; … … 269 269 * @param vertOriginX the vertOriginX to set 270 270 */ 271 public void setVertOriginX( int vertOriginX)271 public void setVertOriginX(float vertOriginX) 272 272 { 273 273 this.vertOriginX = vertOriginX; … … 277 277 * @param vertOriginY the vertOriginY to set 278 278 */ 279 public void setVertOriginY( int vertOriginY)279 public void setVertOriginY(float vertOriginY) 280 280 { 281 281 this.vertOriginY = vertOriginY; … … 285 285 * @param vertAdvY the vertAdvY to set 286 286 */ 287 public void setVertAdvY( int vertAdvY)287 public void setVertAdvY(float vertAdvY) 288 288 { 289 289 this.vertAdvY = vertAdvY; -
trunk/src/com/kitfox/svg/RadialGradient.java
r11525 r14328 37 37 38 38 import com.kitfox.svg.xml.StyleAttribute; 39 import java.awt.Color; 39 40 import java.awt.MultipleGradientPaint; 40 41 import java.awt.Paint; … … 129 130 Point2D.Float pt1 = new Point2D.Float(cx, cy); 130 131 Point2D.Float pt2 = hasFocus ? new Point2D.Float(fx, fy) : pt1; 132 float[] stopFractions = getStopFractions(); 133 Color[] stopColors = getStopColors(); 131 134 if (gradientUnits == GU_USER_SPACE_ON_USE) 132 135 { … … 135 138 r, 136 139 pt2, 137 getStopFractions(),138 getStopColors(),140 stopFractions, 141 stopColors, 139 142 method, 140 143 MultipleGradientPaint.ColorSpaceType.SRGB, … … 152 155 r, 153 156 pt2, 154 getStopFractions(),155 getStopColors(),157 stopFractions, 158 stopColors, 156 159 method, 157 160 MultipleGradientPaint.ColorSpaceType.SRGB, -
trunk/src/com/kitfox/svg/RenderableElement.java
r11525 r14328 112 112 * Pushes transform stack, transforms to local coordinates and sets up 113 113 * clipping mask. 114 * 115 * @param g Graphics context 116 * @throws com.kitfox.svg.SVGException 114 117 */ 115 118 protected void beginLayer(Graphics2D g) throws SVGException … … 166 169 * Restores transform and clipping values to the way they were before this 167 170 * layer was drawn. 171 * @param g 168 172 */ 169 173 protected void finishLayer(Graphics2D g) -
trunk/src/com/kitfox/svg/SVGDiagram.java
r11525 r14328 90 90 final URI xmlBase; 91 91 92 /** Creates a new instance of SVGDiagram */ 92 /** 93 * Creates a new instance of SVGDiagram 94 * @param xmlBase 95 * @param universe 96 */ 93 97 public SVGDiagram(URI xmlBase, SVGUniverse universe) 94 98 { … … 100 104 /** 101 105 * Draws this diagram to the passed graphics context 106 * @param g 107 * @throws com.kitfox.svg.SVGException 102 108 */ 103 109 public void render(Graphics2D g) throws SVGException … … 114 120 * SVGElement.getPath() is added for each entry. 115 121 * 122 * @param point 123 * @param retVec 116 124 * @return the passed in list 125 * @throws com.kitfox.svg.SVGException 117 126 */ 118 127 public List<List<SVGElement>> pick(Point2D point, List<List<SVGElement>> retVec) throws SVGException … … 179 188 /** 180 189 * Returns the viewing rectangle of this diagram in device coordinates. 190 * @param rect 191 * @return 181 192 */ 182 193 public Rectangle2D getViewRect(Rectangle2D rect) … … 224 235 * Updates all attributes in this diagram associated with a time event. 225 236 * Ie, all attributes with track information. 237 * @param curTime 238 * @throws com.kitfox.svg.SVGException 226 239 */ 227 240 public void updateTime(double curTime) throws SVGException … … 240 253 * SVGRoot when its x, y, width or height parameters are specified as 241 254 * percentages. 255 * @param deviceViewport 242 256 */ 243 257 public void setDeviceViewport(Rectangle deviceViewport) -
trunk/src/com/kitfox/svg/SVGElement.java
r11525 r14328 156 156 157 157 /** 158 * @param retVec 158 159 * @return an ordered list of nodes from the root of the tree to this node 159 160 */ … … 212 213 * Searches children for given element. If found, returns index of child. 213 214 * Otherwise returns -1. 215 * @param child 216 * @return index of child 214 217 */ 215 218 public int indexOfChild(SVGElement child) … … 221 224 * Swaps 2 elements in children. 222 225 * 223 * @i index of first 224 * @j index of second 225 * 226 * @return true if successful, false otherwise 226 * @param i index of first child 227 * @param j index of second child 228 * @throws com.kitfox.svg.SVGException 227 229 */ 228 230 public void swapChildren(int i, int j) throws SVGException … … 246 248 * @param helper - An object passed to all SVG elements involved in this 247 249 * build process to aid in sharing information. 250 * @param parent 251 * @throws org.xml.sax.SAXException 248 252 */ 249 253 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) throws SAXException … … 317 321 * Called after the start element but before the end element to indicate 318 322 * each child tag that has been processed 323 * @param helper 324 * @param child 325 * @throws com.kitfox.svg.SVGElementException 319 326 */ 320 327 public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException … … 346 353 /** 347 354 * Called during load process to add text scanned within a tag 355 * @param helper 356 * @param text 348 357 */ 349 358 public void loaderAddText(SVGLoaderHelper helper, String text) … … 354 363 * Called to indicate that this tag and the tags it contains have been 355 364 * completely processed, and that it should finish any load processes. 365 * @param helper 366 * @throws com.kitfox.svg.SVGParseException 356 367 */ 357 368 public void loaderEndElement(SVGLoaderHelper helper) throws SVGParseException … … 370 381 * Called by internal processes to rebuild the geometry of this node from 371 382 * it's presentation attributes, style attributes and animated tracks. 383 * @throws com.kitfox.svg.SVGException 372 384 */ 373 385 protected void build() throws SVGException … … 420 432 * Hack to allow nodes to temporarily change their parents. The Use tag will 421 433 * need this so it can alter the attributes that a particular node uses. 434 * @param context 422 435 */ 423 436 protected void pushParentContext(SVGElement context) … … 465 478 * style attribute, checks attributes of parents back to root until one 466 479 * found. 480 * @return 467 481 */ 468 482 public boolean getStyle(StyleAttribute attrib, boolean recursive) throws SVGException … … 523 537 524 538 /** 539 * @param styName 525 540 * @return the raw style value of this attribute. Does not take the 526 541 * presentation value or animation into consideration. Used by animations to … … 536 551 * Copies the presentation attribute into the passed one. 537 552 * 553 * @param attrib 538 554 * @return - True if attribute was read successfully 555 * @throws com.kitfox.svg.SVGException 539 556 */ 540 557 public boolean getPres(StyleAttribute attrib) throws SVGException … … 558 575 559 576 /** 577 * @param styName 560 578 * @return the raw presentation value of this attribute. Ignores any 561 579 * modifications applied by style attributes or animation. Used by … … 810 828 * all attributes with track information. 811 829 * 830 * @param curTime 812 831 * @return - true if this node has changed state as a result of the time 813 832 * update 833 * @throws com.kitfox.svg.SVGException 814 834 */ 815 835 abstract public boolean updateTime(double curTime) throws SVGException; -
trunk/src/com/kitfox/svg/SVGElementException.java
r8084 r14328 49 49 /** 50 50 * Creates a new instance of <code>SVGException</code> without detail message. 51 * @param element 51 52 */ 52 53 public SVGElementException(SVGElement element) … … 58 59 /** 59 60 * Constructs an instance of <code>SVGException</code> with the specified detail message. 61 * @param element 60 62 * @param msg the detail message. 61 63 */ -
trunk/src/com/kitfox/svg/SVGLoader.java
r11525 r14328 76 76 77 77 final boolean verbose; 78 79 /** Creates a new instance of SVGLoader */ 78 79 /** 80 * Creates a new instance of SVGLoader 81 * @param xmlBase 82 * @param universe 83 */ 80 84 public SVGLoader(URI xmlBase, SVGUniverse universe) 81 85 { -
trunk/src/com/kitfox/svg/SVGLoaderHelper.java
r11525 r14328 57 57 public final URI xmlBase; 58 58 59 /** Creates a new instance of SVGLoaderHelper */ 59 /** 60 * Creates a new instance of SVGLoaderHelper 61 * @param xmlBase 62 * @param universe 63 * @param diagram 64 */ 60 65 public SVGLoaderHelper(URI xmlBase, SVGUniverse universe, SVGDiagram diagram) 61 66 { -
trunk/src/com/kitfox/svg/SVGUniverse.java
r11525 r14328 105 105 XMLReader cachedReader; 106 106 107 //If true, <imageSVG> elements will only load image data that is included using inline data: uris 108 private boolean imageDataInlineOnly = false; 109 107 110 /** 108 111 * Creates a new instance of SVGUniverse … … 130 133 loadedFonts.clear(); 131 134 loadedImages.clear(); 135 } 136 137 /** 138 * Returns the current animation time in milliseconds. 139 */ 140 public double getCurTime() 141 { 142 return curTime; 143 } 144 145 public void setCurTime(double curTime) 146 { 147 double oldTime = this.curTime; 148 this.curTime = curTime; 149 changes.firePropertyChange("curTime", new Double(oldTime), new Double(curTime)); 150 } 151 152 /** 153 * Updates all time influenced style and presentation attributes in all SVG 154 * documents in this universe. 155 */ 156 public void updateTime() throws SVGException 157 { 158 for (SVGDiagram dia : loadedDocs.values()) { 159 dia.updateTime(curTime); 160 } 132 161 } 133 162 … … 648 677 return universe; 649 678 } 679 680 /** 681 * @return the imageDataInlineOnly 682 */ 683 public boolean isImageDataInlineOnly() 684 { 685 return imageDataInlineOnly; 686 } 687 688 /** 689 * @param imageDataInlineOnly the imageDataInlineOnly to set 690 */ 691 public void setImageDataInlineOnly(boolean imageDataInlineOnly) 692 { 693 this.imageDataInlineOnly = imageDataInlineOnly; 694 } 650 695 } -
trunk/src/com/kitfox/svg/Text.java
r11525 r14328 272 272 for (int i = 0; i < families.length; ++i) 273 273 { 274 font = diagram.getUniverse().getFont(f ontFamily);274 font = diagram.getUniverse().getFont(families[i]); 275 275 if (font != null) 276 276 { … … 278 278 } 279 279 } 280 280 281 281 if (font == null) 282 282 { 283 font = new FontSystem(fontFamily, fontStyle, fontWeight, (int)fontSize); 283 //Check system fonts 284 font = FontSystem.createFont(fontFamily, fontStyle, fontWeight, (int)fontSize); 285 } 286 287 if (font == null) 288 { 289 font = FontSystem.createFont("Serif", fontStyle, fontWeight, fontStyle); 284 290 } 285 291 -
trunk/src/com/kitfox/svg/Tspan.java
r11525 r14328 231 231 if (font == null) 232 232 { 233 font = new FontSystem(fontFamily, fontStyle, fontWeight, (int)fontSize);233 font = FontSystem.createFont(fontFamily, fontStyle, fontWeight, (int)fontSize); 234 234 } 235 235 -
trunk/src/com/kitfox/svg/pathcmd/Arc.java
r11525 r14328 104 104 * point of the arc. 105 105 * 106 * @param path The path that the arc will be appended to. 107 * 106 108 * @param rx the x radius of the ellipse 107 109 * @param ry the y radius of the ellipse … … 160 162 * AffineTransform.getRotateInstance 161 163 * (angle, arc.getX()+arc.getWidth()/2, arc.getY()+arc.getHeight()/2); 164 * 165 * @param x0 origin of arc in x 166 * @param y0 origin of arc in y 167 * @param rx radius of arc in x 168 * @param ry radius of arc in y 169 * @param angle number of radians in arc 170 * @param largeArcFlag 171 * @param sweepFlag 172 * @param x ending coordinate of arc in x 173 * @param y ending coordinate of arc in y 174 * @return arc shape 175 * 162 176 */ 163 177 public static Arc2D computeArc(double x0, double y0, -
trunk/src/com/kitfox/svg/util/FontSystem.java
r11525 r14328 42 42 import java.awt.Canvas; 43 43 import java.awt.FontMetrics; 44 import java.awt.GraphicsEnvironment; 44 45 import java.awt.font.FontRenderContext; 45 46 import java.awt.font.GlyphMetrics; 46 47 import java.awt.font.GlyphVector; 47 48 import java.util.HashMap; 49 import java.util.HashSet; 48 50 49 51 /** … … 58 60 HashMap<String, Glyph> glyphCache = new HashMap<String, Glyph>(); 59 61 60 public FontSystem(String fontFamily, int fontStyle, int fontWeight, int fontSize) 62 static HashSet<String> sysFontNames = new HashSet<String>(); 63 64 public static boolean checkIfSystemFontExists(String fontName) 65 { 66 if (sysFontNames.isEmpty()) 67 { 68 for (String name: GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()) 69 { 70 sysFontNames.add(name); 71 } 72 } 73 74 return sysFontNames.contains(fontName); 75 } 76 77 public static FontSystem createFont(String fontFamily, int fontStyle, int fontWeight, int fontSize) 78 { 79 String[] families = fontFamily.split(","); 80 for (String fontName: families) 81 { 82 if (checkIfSystemFontExists(fontName)) 83 { 84 return new FontSystem(fontName, fontStyle, fontWeight, fontSize); 85 } 86 } 87 88 return null; 89 } 90 91 private FontSystem(String fontFamily, int fontStyle, int fontWeight, int fontSize) 61 92 { 62 93 int style; … … 82 113 break; 83 114 } 84 sysFont = new java.awt.Font(fontFamily, style | weight, (int) fontSize); 115 116 sysFont = new java.awt.Font(fontFamily, style | weight, fontSize); 85 117 86 118 Canvas c = new Canvas(); … … 100 132 GlyphVector vec = sysFont.createGlyphVector(frc, unicode); 101 133 102 Glyph glyph = (Glyph)glyphCache.get(unicode);134 Glyph glyph = glyphCache.get(unicode); 103 135 if (glyph == null) 104 136 { … … 107 139 108 140 GlyphMetrics gm = vec.getGlyphMetrics(0); 109 glyph.setHorizAdvX( (int)gm.getAdvanceX());110 glyph.setVertAdvY( (int)gm.getAdvanceY());141 glyph.setHorizAdvX(gm.getAdvanceX()); 142 glyph.setVertAdvY(gm.getAdvanceY()); 111 143 glyph.setVertOriginX(0); 112 144 glyph.setVertOriginY(0); -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r14290 r14328 1656 1656 if (svgUniverse == null) { 1657 1657 svgUniverse = new SVGUniverse(); 1658 // CVE-2017-5617: Allow only data scheme (see #14319) 1659 svgUniverse.setImageDataInlineOnly(true); 1658 1660 } 1659 1661 return svgUniverse;
Note:
See TracChangeset
for help on using the changeset viewer.