24
24
import java .net .URL ;
25
25
import java .nio .file .Files ;
26
26
import java .nio .file .Path ;
27
+ import java .util .regex .Matcher ;
28
+ import java .util .regex .Pattern ;
27
29
28
30
import org .eclipse .core .runtime .FileLocator ;
29
31
import org .eclipse .core .runtime .IAdaptable ;
@@ -69,7 +71,7 @@ public String getImagePath(int zoom) {
69
71
return xResult ;
70
72
}
71
73
}
72
- String xpath = FileImageDescriptor . getxPath (url , zoom );
74
+ String xpath = getxPath (url , zoom );
73
75
if (xpath != null ) {
74
76
URL xPathUrl = getURL (xpath );
75
77
if (xPathUrl != null ) {
@@ -148,7 +150,7 @@ private static ImageData getImageData(String url, int zoom) {
148
150
return xdata ;
149
151
}
150
152
}
151
- String xpath = FileImageDescriptor . getxPath (url , zoom );
153
+ String xpath = getxPath (url , zoom );
152
154
if (xpath != null ) {
153
155
URL xPathUrl = getURL (xpath );
154
156
if (xPathUrl != null ) {
@@ -159,6 +161,26 @@ private static ImageData getImageData(String url, int zoom) {
159
161
return null ;
160
162
}
161
163
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
+
162
184
private static ImageData getImageData (URL url ) {
163
185
ImageData result = null ;
164
186
try (InputStream in = getStream (url )) {
0 commit comments