Changeset 6747 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2014-01-20T19:32:25+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r6615 r6747 396 396 return null; 397 397 398 try { 399 if (name.startsWith("data:")) { 400 Matcher m = dataUrlPattern.matcher(name); 401 if (m.matches()) { 402 String mediatype = m.group(1); 403 String base64 = m.group(2); 404 String data = m.group(3); 405 byte[] bytes = ";base64".equals(base64) 406 ? Base64.decodeBase64(data) 407 : URLDecoder.decode(data, "utf-8").getBytes(); 408 if (mediatype != null && mediatype.contains("image/svg+xml")) { 409 URI uri = getSvgUniverse().loadSVG(new StringReader(new String(bytes)), name); 410 return new ImageResource(getSvgUniverse().getDiagram(uri)); 411 } else { 412 try { 413 return new ImageResource(ImageIO.read(new ByteArrayInputStream(bytes))); 414 } catch (IOException e) { 415 Main.warn("IOException while reading image: "+e.getMessage()); 416 } 417 } 418 } 419 } 420 } catch (UnsupportedEncodingException ex) { 421 throw new RuntimeException(ex.getMessage(), ex); 398 if (name.startsWith("data:")) { 399 String url = name; 400 ImageResource ir = cache.get(url); 401 if (ir != null) return ir; 402 ir = getIfAvailableDataUrl(url); 403 if (ir != null) { 404 cache.put(url, ir); 405 } 406 return ir; 422 407 } 423 408 … … 535 520 } finally { 536 521 Utils.close(is); 522 } 523 } 524 525 private static ImageResource getIfAvailableDataUrl(String url) { 526 try { 527 Matcher m = dataUrlPattern.matcher(url); 528 if (m.matches()) { 529 String mediatype = m.group(1); 530 String base64 = m.group(2); 531 String data = m.group(3); 532 byte[] bytes = ";base64".equals(base64) 533 ? Base64.decodeBase64(data) 534 : URLDecoder.decode(data, "utf-8").getBytes(); 535 if (mediatype != null && mediatype.contains("image/svg+xml")) { 536 URI uri = getSvgUniverse().loadSVG(new StringReader(new String(bytes)), url); 537 return new ImageResource(getSvgUniverse().getDiagram(uri)); 538 } else { 539 try { 540 return new ImageResource(ImageIO.read(new ByteArrayInputStream(bytes))); 541 } catch (IOException e) { 542 Main.warn("IOException while reading image: "+e.getMessage()); 543 } 544 } 545 } 546 return null; 547 } catch (UnsupportedEncodingException ex) { 548 throw new RuntimeException(ex.getMessage(), ex); 537 549 } 538 550 }
Note:
See TracChangeset
for help on using the changeset viewer.