Svg css color support#8
Conversation
- Migrated all tests in org.eclipse.ltk.core.refactoring.tests to JUnit 5. - Updated RefactoringHistorySerializationTests to use Java Text Blocks for XML strings. - Fixed assertion argument order in RefactoringHistoryServiceTests and FailingParticipantTests. - Updated SimpleTestProject to use unique project names to prevent test state pollution in RefactoringHistoryServiceTests. - Note: RefactoringHistoryServiceTests.testDeleteProjectHistory0 still fails consistently in the full suite run due to persistent history state pollution, but passes in isolation.
- Migrated all tests in org.eclipse.jface.tests to JUnit 5. - Updated MANIFEST.MF to use org.junit.jupiter.api and removed JUnit 4. - Replaced JUnit 4 Rules with JUnit 5 Extensions or @tempdir. - Fixed assertion and assumption parameter order for JUnit 5. - Removed unused JFaceActionRule. - Replaced JUnit 3 AssertionFailedError with IllegalStateException in TestLazyModelContentProvider.
- Copied delete_obj.svg, filenav_nav.svg, and prop_ps.svg from workbench bundles. - Updated plugin.xml to reference the new SVG icons. - Removed the original GIF files. - Updated build.properties to include the icons directory in the binary build.
…es.tabbed.article
This change introduces a new CSS property `-eclipse-svg-filter` that
allows developers to dynamically change the color of monochrome SVG
icons loaded via CSS.
The property supports the following values:
- `color <color>`: Replaces all colors in the SVG with the specified
color while preserving the alpha channel.
- `none`: Removes any previously applied SVG filter.
Usage example in CSS:
Label {
image: url("platform:/plugin/org.eclipse.ui/icons/full/obj16/file_obj.svg");
-eclipse-svg-filter: color #FF0000; /* Makes the icon red */
}
Implementation details:
- Added `ColorMatrix` and `ColorMatrixImageDescriptor` to
`org.eclipse.jface.resource` to support per-pixel color transformations.
- Added `createWithColorMatrix` to `ImageDescriptor`.
- Implemented `CSSPropertySVGFilterSWTHandler` in `org.eclipse.e4.ui.css.swt`
to handle the new property.
- Modified `CSSSWTImageHelper` to apply the color matrix when an SVG is
loaded if a filter color is set on the widget.
- Updated image converters to pass the `Widget` context, enabling the
retrieval of widget-specific CSS data.
- Registered the property handler for `Control`, `ToolItem`, and `CTabItem`.
Summary of ChangesHello @vogella, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the theming capabilities within Eclipse by introducing CSS color filtering for SVG images. It provides core infrastructure for applying color matrices to image descriptors and migrates various example plugins to use SVG icons, demonstrating the new dynamic styling possibilities. Additionally, a substantial portion of the test suite has been updated to JUnit 5, modernizing the testing framework. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for colorizing SVG icons via a new CSS property, -eclipse-svg-filter. The implementation involves new handlers in the CSS engine, additions to JFace for image manipulation using color matrices, and updates to various example plugins to use SVG icons. The core logic is well-implemented, but I have identified a couple of areas for improvement regarding CSS property value formatting and the robustness of the new ColorMatrixImageDescriptor.
Additionally, a significant portion of this PR is dedicated to migrating tests from JUnit 4 to JUnit 5, which is a valuable maintenance effort.
| if (widget != null) { | ||
| Object data = widget.getData(CSSSWTConstants.CSS_SVG_FILTER_COLOR); | ||
| if (data != null) { | ||
| return "color " + data.toString(); //$NON-NLS-1$ |
There was a problem hiding this comment.
The toString() method of an RGB object returns a string representation like RGB {r, g, b}, which is not a valid CSS color value. This will likely cause parsing errors when the CSS engine attempts to use this retrieved value. The property value should be formatted as a standard CSS color, such as rgb(r, g, b) or a hex string.
| return "color " + data.toString(); //$NON-NLS-1$ | |
| return "color rgb(" + ((RGB) data).red + ", " + ((RGB) data).green + ", " + ((RGB) data).blue + ")"; //$NON-NLS-1$ |
| for (int y = 0; y < result.height; y++) { | ||
| for (int x = 0; x < result.width; x++) { | ||
| int alpha = result.getAlpha(x, y); | ||
| float a = alpha / 255f; | ||
| float na = m[15] * 0 + m[16] * 0 + m[17] * 0 + m[18] * a + m[19]; // Simplified | ||
| int ina = Math.min(255, Math.max(0, Math.round(na * 255))); | ||
| result.setAlpha(x, y, ina); | ||
| } | ||
| } |
There was a problem hiding this comment.
The alpha channel calculation for indexed palette images is simplified and assumes that the R, G, and B components for the alpha calculation are 0. This is only correct if the matrix elements m[15], m[16], and m[17] are 0. While this holds true for the colorization matrix used in this PR, it makes the ColorMatrixImageDescriptor incorrect for more generic color matrices that might affect alpha based on color components.
A more robust implementation would use the original pixel's color components to calculate the new alpha value.
for (int y = 0; y < result.height; y++) {
for (int x = 0; x < result.width; x++) {
int pixel = data.getPixel(x, y);
RGB rgb = data.palette.getRGBs()[pixel];
float r = rgb.red / 255f;
float g = rgb.green / 255f;
float b = rgb.blue / 255f;
int alpha = data.getAlpha(x, y);
float a = alpha / 255f;
float na = m[15] * r + m[16] * g + m[17] * b + m[18] * a + m[19];
int ina = Math.min(255, Math.max(0, Math.round(na * 255)));
result.setAlpha(x, y, ina);
}
}|
What exactly is the use case of these changes? Are you referring to this issue? The mentioned issue is about designing the icons so that they can be dynamically recolored if e.g. a custom theme should be used in the future. If the icon has some more metadata about its colors e.g. base-color, key-element-color the replacement is easy. This PR seems to address something else, which can also be useful but I need a little more explanation about the problem you are trying to solve and how we can test it. Why do you change so many icons to svgs in this PR and why are there ImageDescriptors doing pixel manipulations on PNGs? An algorithm for applying color changes should adjust the colors in the SVG in some way and then just rasterize it with the tools we have. |
No description provided.