Ticket #16733: 16733-v2.patch
File 16733-v2.patch, 30.4 KB (added by , 5 years ago) |
---|
-
build.xml
diff --git a/build.xml b/build.xml index 8146da263..1b9be0763 100644
a b Build-Date: ${build.tstamp} 905 905 </taskdef> 906 906 <checkstyle config="${checkstyle.dir}/josm_checks.xml"> 907 907 <fileset dir="${base.dir}/src/org/openstreetmap/josm" includes="**/*.java" 908 excludes="gui/mappaint/mapcss/parsergen/*.java "/>908 excludes="gui/mappaint/mapcss/parsergen/*.java,images/**"/> 909 909 <fileset dir="${base.dir}/test" includes="**/*.java"/> 910 910 <fileset dir="${base.dir}/scripts" includes="**/*.java"/> 911 911 <formatter type="plain"/> … … Build-Date: ${build.tstamp} 1148 1148 <ivy:retrieve pattern="${lib.dir}/compile/[artifact]-[type].[ext]" conf="compile"/> 1149 1149 <ivy:retrieve pattern="${lib.dir}/runtime/[artifact]-[type].[ext]" conf="runtime"/> 1150 1150 <ivy:retrieve pattern="${lib.dir}/sources/[artifact]-[type].[ext]" conf="sources"/> 1151 <ivy:retrieve file="${tools.ivy}" pattern="${lib.dir}/radiance-photon/[artifact]-[type].[ext]" conf="radiance-photon"/> 1151 1152 <ivy:retrieve pattern="${lib.dir}/tools/[artifact]-[type].[ext]" conf="javacc,checkstyle" file="${tools.ivy}"/> 1152 1153 </target> 1154 <target name="transform-svg" depends="resolve"> 1155 <ivy:cachepath file="${tools.ivy}" pathid="radiance-photon.classpath" conf="radiance-photon"/> 1156 <mkdir dir="src/org/openstreetmap/josm/images"/> 1157 <java classname="org.pushingpixels.photon.api.transcoder.SvgDeepBatchConverter" failonerror="true"> 1158 <classpath refid="radiance-photon.classpath"/> 1159 <classpath path="${tools.dir}/radiance-photon"/> 1160 <arg value="sourceRootFolder=resources/images/"/> 1161 <arg value="outputRootFolder=src/org/openstreetmap/josm/images"/> 1162 <arg value="outputRootPackageName=org.openstreetmap.josm.images"/> 1163 <arg value="outputClassNamePrefix=img_"/> 1164 <arg value="outputLanguage=java"/> 1165 <arg value="templateFile=/JosmSvgIcon.templ"/> 1166 </java> 1167 </target> 1153 1168 </project> -
ivy.xml
diff --git a/ivy.xml b/ivy.xml index e9888acb7..f0febed81 100644
a b 26 26 <dependency org="org.tukaani" name="xz" rev="1.8" conf="api->default"/> 27 27 <dependency org="com.drewnoakes" name="metadata-extractor" rev="2.13.0" conf="api->default"/> 28 28 <dependency org="ch.poole" name="OpeningHoursParser" rev="0.21.1" conf="api->default"/> 29 <dependency org="org.pushing-pixels" name="radiance-neon" rev="3.0-SNAPSHOT" conf="api->default"/> 29 30 <!-- sources->sources --> 30 31 <dependency org="org.openstreetmap.jmapviewer" name="jmapviewer" rev="2.13" conf="sources->sources"/> 31 32 <dependency org="javax.json" name="javax.json-api" rev="1.1.4" conf="sources->sources"/> -
ivysettings.xml
diff --git a/ivysettings.xml b/ivysettings.xml index c8451d120..f77ea6a6f 100644
a b 2 2 <!-- License: GPL. For details, see LICENSE file. --> 3 3 <ivysettings> 4 4 <settings defaultResolver="chain"/> 5 <property name="m2-pattern" value="${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]" override="false" /> 5 6 <resolvers> 6 7 <chain name="chain"> 8 <filesystem name="local-maven2" m2compatible="true" > 9 <artifact pattern="${m2-pattern}"/> 10 <ivy pattern="${m2-pattern}"/> 11 </filesystem> 7 12 <ibiblio name="josm-nexus" m2compatible="true" root="https://josm.openstreetmap.de/nexus/content/repositories/public/" /> 8 13 <ibiblio name="josm-nexus-snapshots" m2compatible="true" root="https://josm.openstreetmap.de/nexus/content/repositories/snapshots/" /> 9 14 <ibiblio name="jcenter" m2compatible="true" root="https://jcenter.bintray.com/" /> -
src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java index c477314de..9b6dad7b7 100644
a b 86 86 import org.openstreetmap.josm.tools.HiDPISupport; 87 87 import org.openstreetmap.josm.tools.ImageProvider; 88 88 import org.openstreetmap.josm.tools.JosmRuntimeException; 89 import org.openstreetmap.josm.tools.JosmSvgIcon; 89 90 import org.openstreetmap.josm.tools.Logging; 90 91 import org.openstreetmap.josm.tools.ShapeClipper; 91 92 import org.openstreetmap.josm.tools.Utils; … … private void drawIcon(MapViewPoint p, MapImage img, boolean disabled, boolean se 839 840 temporaryGraphics.rotate(theta); 840 841 int drawX = -img.getWidth() / 2 + img.offsetX; 841 842 int drawY = -img.getHeight() / 2 + img.offsetY; 842 temporaryGraphics.drawImage(img.getImage(disabled), drawX, drawY, nc); 843 final JosmSvgIcon icon = img.getJosmSvgIcon(); 844 if (icon != null) { 845 Logging.trace("drawIcon {0}", icon); 846 icon.paintIcon(nc, temporaryGraphics, drawX, drawY); 847 } else { 848 temporaryGraphics.drawImage(img.getImage(disabled), drawX, drawY, nc); 849 } 843 850 if (selected || member) { 844 851 selectionDrawer.accept(temporaryGraphics, new Rectangle2D.Double(drawX - 2d, drawY - 2d, img.getWidth() + 4d, img.getHeight() + 4d)); 845 852 } -
src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
diff --git a/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java b/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java index 22944e1f7..a3678c34e 100644
a b 24 24 import org.openstreetmap.josm.io.FileWatcher; 25 25 import org.openstreetmap.josm.spi.preferences.Config; 26 26 import org.openstreetmap.josm.tools.ImageProvider; 27 import org.openstreetmap.josm.tools.ImageResource; 27 28 import org.openstreetmap.josm.tools.ListenerList; 28 29 import org.openstreetmap.josm.tools.Logging; 29 30 import org.openstreetmap.josm.tools.Stopwatch; … … public static ImageIcon getIcon(IconReference ref, int width, int height) { 199 200 * - josm's default icon 200 201 * can be null if the defaults are turned off by user 201 202 */ 202 public static Image IcongetNoIconIcon(StyleSource source) {203 public static ImageResource getNoIconIcon(StyleSource source) { 203 204 return new ImageProvider("presets/misc/no_icon") 204 205 .setDirs(getIconSourceDirs(source)) 205 206 .setId("mappaint."+source.getPrefName()) 206 207 .setArchive(source.zipIcons) 207 208 .setInArchiveDir(source.getZipEntryDirName()) 208 .setOptional(true).get ();209 .setOptional(true).getResource(); 209 210 } 210 211 211 212 /** -
src/org/openstreetmap/josm/gui/mappaint/styleelement/MapImage.java
diff --git a/src/org/openstreetmap/josm/gui/mappaint/styleelement/MapImage.java b/src/org/openstreetmap/josm/gui/mappaint/styleelement/MapImage.java index 6bc869d67..a5823e62a 100644
a b 13 13 import java.util.concurrent.ExecutionException; 14 14 import java.util.function.Consumer; 15 15 16 import javax.swing.ImageIcon;17 18 16 import org.openstreetmap.josm.gui.MainApplication; 19 17 import org.openstreetmap.josm.gui.MapView; 20 18 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; … … 24 22 import org.openstreetmap.josm.gui.util.GuiHelper; 25 23 import org.openstreetmap.josm.tools.ImageProvider; 26 24 import org.openstreetmap.josm.tools.ImageResource; 25 import org.openstreetmap.josm.tools.JosmSvgIcon; 27 26 import org.openstreetmap.josm.tools.Logging; 28 27 import org.openstreetmap.josm.tools.Utils; 29 28 … … 33 32 public class MapImage { 34 33 35 34 private static final int MAX_SIZE = 48; 35 private static final ImageResource TEMPORARY = new ImageProvider("clock").getResource(); 36 36 37 37 /** 38 * ImageIconcan change while the image is loading.38 * {@link ImageResource} can change while the image is loading. 39 39 */ 40 private Image img; 41 private ImageResource imageResource; 40 private ImageResource imageResource = TEMPORARY; 42 41 43 42 /** 44 43 * The alpha (opacity) value of the image. It is multiplied to the image alpha channel. … … 74 73 */ 75 74 public int offsetY; 76 75 77 private boolean temporary;78 79 76 /** 80 77 * A cache that holds a disabled (gray) version of this image 81 78 */ … … public ImageResource getImageResource() { 134 131 return imageResource; 135 132 } 136 133 134 public JosmSvgIcon getJosmSvgIcon() { 135 return imageResource.getJosmSvgIcon(); 136 } 137 137 138 private Image getDisabled() { 138 139 if (disabledImgCache != null) 139 140 return disabledImgCache; 140 if (i mg == null)141 if (isTemporary()) 141 142 getImage(); // fix #7498 ? 142 Image disImg = GuiHelper.getDisabledImage( img);143 Image disImg = GuiHelper.getDisabledImage(getImage()); 143 144 if (disImg instanceof BufferedImage) { 144 145 disabledImgCache = (BufferedImage) disImg; 145 146 } else { … … private Image getDisabled() { 152 153 } 153 154 154 155 private Image getImage() { 155 if (img != null) 156 return img; 157 temporary = false; 158 loadImage(); 159 synchronized (this) { 160 if (img == null) { 161 img = ImageProvider.get("clock").getImage(); 162 temporary = true; 163 } 156 if (isTemporary()) { 157 loadImage(); 164 158 } 165 return img;159 return rescale(imageResource.getImageIcon(new Dimension(width, height)).getImage()); 166 160 } 167 161 168 162 private CompletableFuture<Void> load(Consumer<? super ImageResource> action) { … … private Image getImage() { 183 177 private CompletableFuture<Void> loadImage() { 184 178 return load(result -> { 185 179 synchronized (this) { 186 imageResource = result; 187 if (result == null) { 188 source.logWarning(tr("Failed to locate image ''{0}''", name)); 189 ImageIcon noIcon = MapPaintStyles.getNoIconIcon(source); 190 img = noIcon == null ? null : noIcon.getImage(); 191 } else { 192 img = rescale(result.getImageIcon(new Dimension(width, height)).getImage()); 193 } 180 final boolean temporary = isTemporary(); // setImageResource changes isTemporary 181 setImageResource(result); 194 182 if (temporary) { 195 183 disabledImgCache = null; 196 184 MapView mapView = MainApplication.getMap().mapView; 197 185 mapView.preferenceChanged(null); // otherwise repaint is ignored, because layer hasn't changed 198 186 mapView.repaint(); 199 187 } 200 temporary = false;201 188 } 202 189 }); 203 190 } … … private Image getImage() { 210 197 private CompletableFuture<Void> loadImageResource() { 211 198 return load(result -> { 212 199 synchronized (this) { 213 imageResource = result; 214 if (result == null) { 215 source.logWarning(tr("Failed to locate image ''{0}''", name)); 216 } 200 setImageResource(result); 217 201 } 218 202 }); 219 203 } 220 204 205 private void setImageResource(ImageResource result) { 206 if (result == null) { 207 source.logWarning(tr("Failed to locate image ''{0}''", name)); 208 imageResource = MapPaintStyles.getNoIconIcon(source); 209 } else { 210 imageResource = result; 211 } 212 } 213 221 214 /** 222 215 * Gets the image width 223 216 * @return The real image width 224 217 */ 225 218 public int getWidth() { 219 final JosmSvgIcon icon = getJosmSvgIcon(); 220 if (icon != null) { 221 return icon.getIconWidth(); 222 } 226 223 return getImage().getWidth(null); 227 224 } 228 225 … … public int getWidth() { 231 228 * @return The real image height 232 229 */ 233 230 public int getHeight() { 231 final JosmSvgIcon icon = getJosmSvgIcon(); 232 if (icon != null) { 233 return icon.getIconHeight(); 234 } 234 235 return getImage().getHeight(null); 235 236 } 236 237 … … public float getAlphaFloat() { 247 248 * @return {@code true} if image is not completely loaded and getImage() returns a temporary image 248 249 */ 249 250 public boolean isTemporary() { 250 return temporary;251 return imageResource == TEMPORARY; 251 252 } 252 253 253 254 protected class MapImageBoxProvider implements BoxProvider { 254 255 @Override 255 256 public BoxProviderResult get() { 256 return new BoxProviderResult(box(), temporary);257 return new BoxProviderResult(box(), isTemporary()); 257 258 } 258 259 259 260 private Rectangle box() { … … public boolean equals(Object obj) { 281 282 if (obj instanceof MapImageBoxProvider) { 282 283 MapImageBoxProvider other = (MapImageBoxProvider) obj; 283 284 return MapImage.this.equals(other.getParent()); 284 } else if ( temporary) {285 } else if (isTemporary()) { 285 286 return false; 286 287 } else { 287 288 final BoxProvider other = (BoxProvider) obj; -
src/org/openstreetmap/josm/tools/ImageProvider.java
diff --git a/src/org/openstreetmap/josm/tools/ImageProvider.java b/src/org/openstreetmap/josm/tools/ImageProvider.java index 89de2b570..2b167c594 100644
a b 15 15 import java.awt.RenderingHints; 16 16 import java.awt.Toolkit; 17 17 import java.awt.Transparency; 18 import java.awt.geom.Dimension2D; 18 19 import java.awt.image.BufferedImage; 19 20 import java.awt.image.ColorModel; 20 21 import java.awt.image.FilteredImageSource; … … private ImageResource getIfAvailableImpl() { 853 854 // for example in loops in map entries (ie freeze when such entry is retrieved) 854 855 855 856 String prefix = isDisabled ? "dis:" : ""; 857 858 if (Utils.hasExtension(name, "svg")) { 859 final ImageResource ir = getJosmSvgIcon(); 860 if (ir != null) { 861 cache.put(prefix + name, ir); 862 return ir; 863 } 864 } 865 856 866 if (name.startsWith("data:")) { 857 867 String url = name; 858 868 ImageResource ir = cache.get(prefix + url); … … private ImageResource getIfAvailableImpl() { 955 965 return null; 956 966 } 957 967 968 private ImageResource getJosmSvgIcon() { 969 try { 970 // rewrite foo/bar/baz.svg to org.openstreetmap.josm.images.foo.bar.img_baz (class is prefixed with img_) 971 final String[] nameParts = name.replaceAll("[ -]", "_").split("/"); 972 nameParts[nameParts.length - 1] = "img_" + nameParts[nameParts.length - 1].replaceFirst(".svg$", ""); 973 final String className = "org.openstreetmap.josm.images." + String.join(".", nameParts); 974 final Class<?> imageClass = Class.forName(className); 975 final JosmSvgIcon icon = (JosmSvgIcon) imageClass.getConstructor(int.class, int.class).newInstance(16, 16); 976 977 Logging.trace("ImageProvider: For image {0}, using {1}", name, imageClass); 978 return new ImageResource(icon); 979 980 } catch (Exception ex) { 981 Logging.warn(ex); 982 } 983 return null; 984 } 985 958 986 /** 959 987 * Internal implementation of the image request for URL's. 960 988 * … … public static BufferedImage createImageFromSvg(SVGDiagram svg, Dimension dim) { 1640 1668 } 1641 1669 final float sourceWidth = svg.getWidth(); 1642 1670 final float sourceHeight = svg.getHeight(); 1643 final float realWidth;1644 final float realHeight;1645 if (dim.width >= 0) {1646 realWidth = dim.width;1647 if (dim.height >= 0) {1648 realHeight = dim.height;1649 } else {1650 realHeight = sourceHeight * realWidth / sourceWidth;1651 }1652 } else if (dim.height >= 0) {1653 realHeight = dim.height;1654 realWidth = sourceWidth * realHeight / sourceHeight;1655 } else {1656 realWidth = GuiSizesHelper.getSizeDpiAdjusted(sourceWidth);1657 realHeight = GuiSizesHelper.getSizeDpiAdjusted(sourceHeight);1658 }1659 1671 1660 int roundedWidth = Math.round(realWidth); 1661 int roundedHeight = Math.round(realHeight); 1672 final Dimension2D realDimension = new ComputedDimension(dim, sourceWidth, sourceHeight); 1673 int roundedWidth = (int) Math.round(realDimension.getWidth()); 1674 int roundedHeight = (int) Math.round(realDimension.getHeight()); 1662 1675 if (roundedWidth <= 0 || roundedHeight <= 0 || roundedWidth >= Integer.MAX_VALUE || roundedHeight >= Integer.MAX_VALUE) { 1663 Logging.error("createImageFromSvg: {0} {1} realWidth={2} realHeight={3}", 1664 svg.getXMLBase(), dim, Float.toString(realWidth), Float.toString(realHeight)); 1676 Logging.error("createImageFromSvg: {0} {1} realDimension={2}", svg.getXMLBase(), dim, realDimension); 1665 1677 return null; 1666 1678 } 1667 1679 BufferedImage img = new BufferedImage(roundedWidth, roundedHeight, BufferedImage.TYPE_INT_ARGB); 1668 1680 Graphics2D g = img.createGraphics(); 1669 1681 g.setClip(0, 0, img.getWidth(), img.getHeight()); 1670 g.scale( realWidth / sourceWidth, realHeight/ sourceHeight);1682 g.scale((float) realDimension.getWidth() / sourceWidth, (float) realDimension.getHeight() / sourceHeight); 1671 1683 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 1672 1684 try { 1673 1685 synchronized (getSvgUniverse()) { … … public String toString() { 2123 2135 + (archive != null ? "archive=" + archive + ", " : "") 2124 2136 + (inArchiveDir != null && !inArchiveDir.isEmpty() ? "inArchiveDir=" + inArchiveDir : "") + ']').replaceAll(", \\]", "]"); 2125 2137 } 2138 2139 static class ComputedDimension extends Dimension2D { 2140 private final float realWidth; 2141 private final float realHeight; 2142 2143 ComputedDimension(Dimension dim, float sourceWidth, float sourceHeight) { 2144 dim = GuiSizesHelper.getDimensionDpiAdjusted(dim); 2145 if (dim.width >= 0) { 2146 realWidth = dim.width; 2147 if (dim.height >= 0) { 2148 realHeight = dim.height; 2149 } else { 2150 realHeight = sourceHeight * realWidth / sourceWidth; 2151 } 2152 } else if (dim.height >= 0) { 2153 realHeight = dim.height; 2154 realWidth = sourceWidth * realHeight / sourceHeight; 2155 } else { 2156 realWidth = GuiSizesHelper.getSizeDpiAdjusted(sourceWidth); 2157 realHeight = GuiSizesHelper.getSizeDpiAdjusted(sourceHeight); 2158 } 2159 } 2160 2161 @Override 2162 public double getWidth() { 2163 return realWidth; 2164 } 2165 2166 @Override 2167 public double getHeight() { 2168 return realHeight; 2169 } 2170 2171 @Override 2172 public void setSize(double width, double height) { 2173 throw new UnsupportedOperationException(); 2174 } 2175 2176 @Override 2177 public String toString() { 2178 return "ComputedDimension{realWidth=" + realWidth + ", realHeight=" + realHeight + '}'; 2179 } 2180 } 2126 2181 } -
src/org/openstreetmap/josm/tools/ImageResource.java
diff --git a/src/org/openstreetmap/josm/tools/ImageResource.java b/src/org/openstreetmap/josm/tools/ImageResource.java index 56f5d4f87..482be937b 100644
a b 3 3 4 4 import java.awt.Dimension; 5 5 import java.awt.Image; 6 import java.awt.geom.Dimension2D; 6 7 import java.awt.image.BufferedImage; 7 8 import java.util.List; 8 9 import java.util.Map; 9 10 import java.util.concurrent.ConcurrentHashMap; 11 import java.util.function.Consumer; 10 12 11 13 import javax.swing.AbstractAction; 12 14 import javax.swing.Action; … … 35 37 * SVG diagram information in case of SVG vector image. 36 38 */ 37 39 private SVGDiagram svg; 40 41 private JosmSvgIcon josmSvgIcon; 38 42 /** 39 43 * Use this dimension to request original file dimension. 40 44 */ … … public ImageResource(SVGDiagram svg) { 70 74 this.svg = svg; 71 75 } 72 76 77 public ImageResource(JosmSvgIcon josmSvgIcon) { 78 CheckParameterUtil.ensureParameterNotNull(josmSvgIcon); 79 this.josmSvgIcon = josmSvgIcon; 80 } 81 73 82 /** 74 83 * Constructs a new {@code ImageResource} from another one and sets overlays. 75 84 * @param res the existing resource … … public ImageResource(SVGDiagram svg) { 78 87 */ 79 88 public ImageResource(ImageResource res, List<ImageOverlay> overlayInfo) { 80 89 this.svg = res.svg; 90 this.josmSvgIcon = res.josmSvgIcon; 81 91 this.baseImage = res.baseImage; 82 92 this.overlayInfo = overlayInfo; 83 93 } … … public ImageResource setDisabled(boolean disabled) { 94 104 return this; 95 105 } 96 106 107 private void attachImageIcon(ImageProvider.ImageSizes size, Consumer<Icon> iconConsumer) { 108 iconConsumer.accept(josmSvgIcon != null 109 ? josmSvgIcon.withDimension(size.getVirtualWidth(), size.getVirtualHeight()) 110 : getImageIconBounded(size.getImageDimension())); 111 } 112 97 113 /** 98 114 * Set both icons of an Action 99 115 * @param a The action for the icons 100 116 * @since 10369 101 117 */ 102 118 public void attachImageIcon(AbstractAction a) { 103 Dimension iconDimension = ImageProvider.ImageSizes.SMALLICON.getImageDimension(); 104 ImageIcon icon = getImageIconBounded(iconDimension); 105 a.putValue(Action.SMALL_ICON, icon); 106 107 iconDimension = ImageProvider.ImageSizes.LARGEICON.getImageDimension(); 108 icon = getImageIconBounded(iconDimension); 109 a.putValue(Action.LARGE_ICON_KEY, icon); 119 attachImageIcon(ImageProvider.ImageSizes.SMALLICON, icon -> a.putValue(Action.SMALL_ICON, icon)); 120 attachImageIcon(ImageProvider.ImageSizes.LARGEICON, icon -> a.putValue(Action.LARGE_ICON_KEY, icon)); 110 121 } 111 122 112 123 /** … … public ImageIcon getImageIcon(Dimension dim, boolean multiResolution) { 158 169 () -> dim + " is invalid"); 159 170 BufferedImage img = imgCache.get(dim); 160 171 if (img == null) { 161 if (svg != null) { 162 Dimension realDim = GuiSizesHelper.getDimensionDpiAdjusted(dim); 163 img = ImageProvider.createImageFromSvg(svg, realDim); 172 if (josmSvgIcon != null) { 173 final Dimension2D dimension = new ImageProvider.ComputedDimension( 174 dim, josmSvgIcon.getIconWidth(), josmSvgIcon.getIconHeight()); 175 img = josmSvgIcon.withDimension((int) dimension.getWidth(), (int) dimension.getHeight()).toImage(); 176 } else if (svg != null) { 177 img = ImageProvider.createImageFromSvg(svg, dim); 164 178 if (img == null) { 165 179 return null; 166 180 } … … public ImageIcon getImageIconBounded(Dimension maxSize, boolean multiResolution) 248 262 float sourceHeight; 249 263 int maxWidth = maxSize.width; 250 264 int maxHeight = maxSize.height; 251 if (svg != null) { 265 if (josmSvgIcon != null) { 266 sourceHeight = josmSvgIcon.getIconHeight(); 267 sourceWidth = josmSvgIcon.getIconWidth(); 268 } else if (svg != null) { 252 269 sourceWidth = svg.getWidth(); 253 270 sourceHeight = svg.getHeight(); 254 271 } else { … … public ImageIcon getPaddedIcon(Dimension iconSize) { 292 309 return new ImageIcon(image); 293 310 } 294 311 312 public JosmSvgIcon getJosmSvgIcon() { 313 return josmSvgIcon; 314 } 315 295 316 @Override 296 317 public String toString() { 297 318 return "ImageResource [" -
new file src/org/openstreetmap/josm/tools/JosmSvgIcon.java
diff --git a/src/org/openstreetmap/josm/tools/JosmSvgIcon.java b/src/org/openstreetmap/josm/tools/JosmSvgIcon.java new file mode 100644 index 000000000..a1deadfaf
- + 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.tools; 3 4 import java.awt.image.BufferedImage; 5 6 import javax.swing.Icon; 7 8 import org.pushingpixels.neon.api.NeonCortex; 9 10 /** 11 * An SVG icon as compiled Java class. 12 */ 13 public interface JosmSvgIcon extends Icon { 14 15 /** 16 * Creates a copy this this icon with the specified dimension. 17 * 18 * @param width the width of the copy 19 * @param height the height of the copy 20 * @return a copy this this icon with the specified dimension. 21 */ 22 JosmSvgIcon withDimension(int width, int height); 23 24 /** 25 * Returns the X of the bounding box of the original SVG image. 26 * 27 * @return The X of the bounding box of the original SVG image. 28 */ 29 double getOrigX(); 30 31 /** 32 * Returns the Y of the bounding box of the original SVG image. 33 * 34 * @return The Y of the bounding box of the original SVG image. 35 */ 36 double getOrigY(); 37 38 /** 39 * Returns the width of the bounding box of the original SVG image. 40 * 41 * @return The width of the bounding box of the original SVG image. 42 */ 43 double getOrigWidth(); 44 45 /** 46 * Returns the height of the bounding box of the original SVG image. 47 * 48 * @return The height of the bounding box of the original SVG image. 49 */ 50 double getOrigHeight(); 51 52 default BufferedImage toImage() { 53 BufferedImage result = NeonCortex.getBlankImage(this.getIconWidth(), this.getIconHeight()); 54 this.paintIcon(null, result.getGraphics(), 0, 0); 55 return result; 56 } 57 } -
tools/ivy.xml
diff --git a/tools/ivy.xml b/tools/ivy.xml index dd4fc3b9b..f3c990041 100644
a b 8 8 <conf name="proguard" description="Everything needed for running ProGuard"/> 9 9 <conf name="pmd" description="Everything needed for running PMD"/> 10 10 <conf name="spotbugs" description="Everything needed for running SpotBugs"/> 11 <conf name="radiance-photon" description="Everything needed for running radiance-photon"/> 11 12 </configurations> 12 13 <dependencies> 13 14 <!-- javacc->default --> … … 26 27 <!-- spotbugs->default --> 27 28 <dependency org="com.github.spotbugs" name="spotbugs" rev="3.1.12" conf="spotbugs->default"/> 28 29 <dependency org="com.github.spotbugs" name="spotbugs-ant" rev="3.1.12" conf="spotbugs->default"/> 30 <!-- radiance-photon->default --> 31 <dependency org="org.pushing-pixels" name="radiance-photon" rev="3.0-SNAPSHOT" conf="radiance-photon->default"/> 32 <dependency org="org.apache.xmlgraphics" name="batik-all" rev="1.12" conf="radiance-photon->default"> 33 <artifact name="batik-all" type="pom" ext="pom"/> 34 </dependency> 29 35 </dependencies> 30 36 </ivy-module> -
new file tools/radiance-photon/JosmSvgIcon.templ
diff --git a/tools/radiance-photon/JosmSvgIcon.templ b/tools/radiance-photon/JosmSvgIcon.templ new file mode 100644 index 000000000..b06a68356
- + 1 TOKEN_PACKAGE 2 3 import java.awt.*; 4 import java.awt.geom.*; 5 import java.awt.image.BufferedImage; 6 import java.io.*; 7 import java.lang.ref.WeakReference; 8 import java.util.Base64; 9 import java.util.Stack; 10 import javax.imageio.ImageIO; 11 12 /** 13 * This class has been automatically generated using <a 14 * href="https://github.com/kirill-grouchnikov/radiance">Photon SVG transcoder</a>. 15 */ 16 public class TOKEN_CLASSNAME implements org.openstreetmap.josm.tools.JosmSvgIcon { 17 private Shape shape = null; 18 private GeneralPath generalPath = null; 19 private Paint paint = null; 20 private Stroke stroke = null; 21 private Shape clip = null; 22 private Stack<AffineTransform> transformsStack = new Stack<>(); 23 24 TOKEN_RASTER_CODE 25 26 TOKEN_PAINTING_CODE 27 28 @SuppressWarnings("unused") 29 private void innerPaint(Graphics2D g) { 30 float origAlpha = 1.0f; 31 Composite origComposite = g.getComposite(); 32 if (origComposite instanceof AlphaComposite) { 33 AlphaComposite origAlphaComposite = 34 (AlphaComposite) origComposite; 35 if (origAlphaComposite.getRule() == AlphaComposite.SRC_OVER) { 36 origAlpha = origAlphaComposite.getAlpha(); 37 } 38 } 39 40 TOKEN_PAINTING_INVOCATIONS 41 42 shape = null; 43 generalPath = null; 44 paint = null; 45 stroke = null; 46 clip = null; 47 transformsStack.clear(); 48 } 49 50 @Override 51 public double getOrigX() { 52 return TOKEN_ORIG_X; 53 } 54 55 @Override 56 public double getOrigY() { 57 return TOKEN_ORIG_Y; 58 } 59 60 @Override 61 public double getOrigWidth() { 62 return TOKEN_ORIG_WIDTH; 63 } 64 65 @Override 66 public double getOrigHeight() { 67 return TOKEN_ORIG_HEIGHT; 68 } 69 70 /** 71 * The current width of this resizable icon. 72 */ 73 private final int width; 74 75 /** 76 * The current height of this resizable icon. 77 */ 78 private final int height; 79 80 /** 81 * Creates a new transcoded SVG image with the original dimension. 82 */ 83 public TOKEN_CLASSNAME() { 84 this.width = (int) getOrigWidth(); 85 this.height = (int) getOrigHeight(); 86 } 87 88 /** 89 * Creates a new transcoded SVG image with the specified dimension. 90 * 91 * @param width the width of the icon 92 * @param height the height of the icon 93 */ 94 public TOKEN_CLASSNAME(int width, int height) { 95 this.width = width; 96 this.height = height; 97 } 98 99 @Override 100 public int getIconHeight() { 101 return height; 102 } 103 104 @Override 105 public int getIconWidth() { 106 return width; 107 } 108 109 @Override 110 public void paintIcon(Component c, Graphics g, int x, int y) { 111 g.translate(x, y); 112 113 double coef1 = (double) this.width / getOrigWidth(); 114 double coef2 = (double) this.height / getOrigHeight(); 115 double coef = Math.min(coef1, coef2); 116 g.clipRect(0, 0, this.width, this.height); 117 ((Graphics2D) g).scale(coef, coef); 118 ((Graphics2D) g).translate(-getOrigX(), -getOrigY()); 119 if (coef1 != coef2) { 120 if (coef1 < coef2) { 121 int extraDy = (int) ((getOrigWidth() - getOrigHeight()) / 2.0); 122 g.translate(0, extraDy); 123 } else { 124 int extraDx = (int) ((getOrigHeight() - getOrigWidth()) / 2.0); 125 g.translate(extraDx, 0); 126 } 127 } 128 Graphics2D gInner = (Graphics2D) g.create(); 129 innerPaint(gInner); 130 gInner.dispose(); 131 g.dispose(); 132 } 133 134 @Override 135 public TOKEN_CLASSNAME withDimension(int width, int height) { 136 return new TOKEN_CLASSNAME(width, height); 137 } 138 }