2424import java .net .URL ;
2525import java .nio .file .Files ;
2626import java .nio .file .Path ;
27+ import java .util .regex .Matcher ;
28+ import java .util .regex .Pattern ;
2729
2830import org .eclipse .core .runtime .FileLocator ;
2931import org .eclipse .core .runtime .IAdaptable ;
@@ -69,7 +71,7 @@ public String getImagePath(int zoom) {
6971 return xResult ;
7072 }
7173 }
72- String xpath = FileImageDescriptor . getxPath (url , zoom );
74+ String xpath = getxPath (url , zoom );
7375 if (xpath != null ) {
7476 URL xPathUrl = getURL (xpath );
7577 if (xPathUrl != null ) {
@@ -148,7 +150,7 @@ private static ImageData getImageData(String url, int zoom) {
148150 return xdata ;
149151 }
150152 }
151- String xpath = FileImageDescriptor . getxPath (url , zoom );
153+ String xpath = getxPath (url , zoom );
152154 if (xpath != null ) {
153155 URL xPathUrl = getURL (xpath );
154156 if (xPathUrl != null ) {
@@ -159,6 +161,26 @@ private static ImageData getImageData(String url, int zoom) {
159161 return null ;
160162 }
161163
164+ private static final Pattern XPATH_PATTERN = Pattern .compile ("(\\ d+)x(\\ d+)" ); //$NON-NLS-1$
165+
166+ private static String getxPath (String name , int zoom ) {
167+ Matcher matcher = XPATH_PATTERN .matcher (name );
168+ if (matcher .find ()) {
169+ try {
170+ int currentWidth = Integer .parseInt (matcher .group (1 ));
171+ int desiredWidth = Math .round ((zoom / 100f ) * currentWidth );
172+ int currentHeight = Integer .parseInt (matcher .group (2 ));
173+ int desiredHeight = Math .round ((zoom / 100f ) * currentHeight );
174+ String lead = name .substring (0 , matcher .start (1 ));
175+ String tail = name .substring (matcher .end (2 ));
176+ return lead + desiredWidth + "x" + desiredHeight + tail ; //$NON-NLS-1$
177+ } catch (RuntimeException e ) {
178+ // should never happen but if then we can't use the alternative name...
179+ }
180+ }
181+ return null ;
182+ }
183+
162184 private static ImageData getImageData (URL url ) {
163185 ImageData result = null ;
164186 try (InputStream in = getStream (url )) {
0 commit comments