Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundles/org.eclipse.jface/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Export-Package: org.eclipse.jface,
org.eclipse.jface.window,
org.eclipse.jface.wizard,
org.eclipse.jface.wizard.images
Require-Bundle: org.eclipse.swt;bundle-version="[3.126.0,4.0.0)";visibility:=reexport,
Require-Bundle: org.eclipse.swt;bundle-version="[3.132.0,3.134.0)";visibility:=reexport,
org.eclipse.core.commands;bundle-version="[3.4.0,4.0.0)";visibility:=reexport,
org.eclipse.equinox.common;bundle-version="[3.18.0,4.0.0)",
org.eclipse.equinox.bidi;bundle-version="[0.10.0,2.0.0)";resolution:=optional
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2025 Christoph Läubrich and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.jface.resource;

import java.net.URL;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.swt.graphics.Point;

class URLHintProvider implements Supplier<Point> {

private static final Pattern QUERY_PATTERN = Pattern.compile("&size=(\\d+)x(\\d+)"); //$NON-NLS-1$
private static final Pattern PATH_PATTERN = Pattern.compile("/(\\d+)x(\\d+)/"); //$NON-NLS-1$

private URL url;

public URLHintProvider(URL url) {
this.url = url;
}

@Override
public Point get() {
String query = url.getQuery();
Matcher matcher;
if (query != null && !query.isEmpty()) {
matcher = QUERY_PATTERN.matcher("&" + query); //$NON-NLS-1$
} else {
String path = url.getPath();
matcher = PATH_PATTERN.matcher(path);
}
if (matcher.find()) {
return new Point(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)));
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -42,6 +43,7 @@
import org.eclipse.swt.graphics.ImageDataProvider;
import org.eclipse.swt.graphics.ImageFileNameProvider;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.internal.DPIUtil.ElementAtZoom;
import org.eclipse.swt.internal.NativeImageLoader;
import org.eclipse.swt.internal.image.FileFormat;
Expand All @@ -59,6 +61,11 @@
if (tempURL != null) {
final boolean logIOException = zoom == 100;
if (zoom == 100) {
// Do not use file path if URL has query parameters (e.g., size hints)
// because getFilePath() strips the query and size hints would be lost
if (tempURL.getQuery() != null) {
return null;
}
// Do not take this path if the image file can be scaled up dynamically.
// The calling image will do that itself!
return getFilePath(tempURL, logIOException);
Expand Down Expand Up @@ -133,7 +140,7 @@
private static ImageData getImageData(URL url, int fileZoom, int targetZoom) {
try (InputStream in = getStream(url)) {
if (in != null) {
return loadImageFromStream(new BufferedInputStream(in), fileZoom, targetZoom);
return loadImageFromStream(new BufferedInputStream(in), fileZoom, targetZoom, new URLHintProvider(url));
}
} catch (SWTException e) {
if (e.code != SWT.ERROR_INVALID_IMAGE) {
Expand All @@ -146,8 +153,14 @@
return null;
}

@SuppressWarnings("restriction")

Check warning on line 156 in bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Unnecessary Code

NORMAL: Unnecessary @SuppressWarnings("restriction")
private static ImageData loadImageFromStream(InputStream stream, int fileZoom, int targetZoom) {
private static ImageData loadImageFromStream(InputStream stream, int fileZoom, int targetZoom,
Supplier<Point> hintProvider) {
Point hintSize = hintProvider.get();
if (hintSize != null) {
return NativeImageLoader.load(stream, new ImageLoader(), hintSize.x * targetZoom / fileZoom,
hintSize.y * targetZoom / fileZoom);
}
return NativeImageLoader.load(new ElementAtZoom<>(stream, fileZoom), new ImageLoader(), targetZoom).get(0)
.element();
}
Expand All @@ -169,8 +182,14 @@
if (InternalPolicy.OSGI_AVAILABLE) {
url = resolvePathVariables(url);
}
// For file: URLs, strip query parameters before opening the stream
// Query parameters are used for size hints but are not valid in file paths
if (FILE_PROTOCOL.equalsIgnoreCase(url.getProtocol()) && url.getQuery() != null) {
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath());

Check warning on line 188 in bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Deprecation

NORMAL: The constructor URL(String, String, int, String) is deprecated since version 20
}
return url.openStream();
} catch (IOException e) {
e.printStackTrace();
if (InternalPolicy.DEBUG_LOG_URL_IMAGE_DESCRIPTOR_MISSING_2x) {
String path = url.getPath();
if (path.endsWith("@2x.png") || path.endsWith("@1.5x.png")) { //$NON-NLS-1$ //$NON-NLS-2$
Expand Down
Loading
Loading