-
Notifications
You must be signed in to change notification settings - Fork 228
Detect the desired size from the path or Query parameters. #3431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Detect the desired size from the path or Query parameters. #3431
Conversation
Test Results 1 998 files - 899 1 998 suites - 899 44m 28s ⏱️ - 1h 40m 49s For more details on these failures, see this check. Results for commit f7e1298. ± Comparison against base commit 02fc196. This pull request removes 1735 and adds 11 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
| 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))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldnt one of them be matcher.group(2) ?
bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java
Outdated
Show resolved
Hide resolved
fc3b77a to
123c69a
Compare
Currently Icons can be organized in folders like /icons/16x16, /icons/32x32 and so on for high resolution support. Currently if one want to replace such structure with SVG it is required to scale down the SVG to 16x16 pixel document size as otherwise they get rendered at there native size (what usually is much larger). As it is not really desirable to restrict the size of the SVG design for technical reasons, JFace now can detect two cases: 1) the SVG is places in a folder with "classic" folder layout the size is extracted and passed down as a hint for dynamic sizable icons 2) one can additionally add a query parameter, e.g. if I have an icon like /icons/obj16/search.svg and I have two places where I want to use it one for a toolbar (16x16) and once for a Wizard Images (usually 128x128) I can use the url bundle:/example.id/icons/obj16/search.svg?size=16x16 and bundle:/example.id/icons/obj16/search.svg?size=128x128 to accomplish this task without the need to even store two SVGs
123c69a to
7a4c784
Compare
|
This pull request changes some projects for the first time in this development cycle. An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch. Git patchFurther information are available in Common Build Issues - Missing version increments. |
|
Some test are failing here because Equinox is not parsing query strings correctly, I tried to address this here: |
Currently we have the problem that I want to replace some icons with a SVG variant. Currently Icons can be organized in folders like
/icons/16x16/search.png,/icons/32x32/search.pngand so on for high resolution support. Currently if one want to replace such structure with SVG it is required to scale down the SVG to 16x16 pixel document size as otherwise they get rendered at there native size (what usually is much larger).As it is not really desirable to restrict the size of the SVG design for technical reasons, JFace now can detect two cases:
/icons/obj16/search.svgand I have two places where I want to use it one for a toolbar (16x16) and once for a Wizard Images (usually 128x128) I can use the urlbundle:/example.id/icons/obj16/search.svg?size=16x16andbundle:/example.id/icons/obj16/search.svg?size=128x128to accomplish this task without the need to even store two SVGs