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
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(1)));
}
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 Down Expand Up @@ -133,7 +135,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 @@ -147,8 +149,10 @@
}

@SuppressWarnings("restriction")
private static ImageData loadImageFromStream(InputStream stream, int fileZoom, int targetZoom) {
return NativeImageLoader.load(new ElementAtZoom<>(stream, fileZoom), new ImageLoader(), targetZoom).get(0)
private static ImageData loadImageFromStream(InputStream stream, int fileZoom, int targetZoom,
Supplier<Point> hintProvider) {
return NativeImageLoader
.load(new ElementAtZoom<>(stream, fileZoom), new ImageLoader(), targetZoom, hintProvider).get(0)

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

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Member

ERROR: ) The method load(InputStream, ImageLoader, int, int) in the type NativeImageLoader is not applicable for the arguments (new ElementAtZoom<>(stream, fileZoom), ImageLoader, int, Supplier

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

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Type

ERROR: Cannot infer type arguments for ElementAtZoom<>
.element();
}

Expand Down
Loading