Support relative font sizes and px in the CSS engine - #4315
Open
vogella wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Relative sizing compounds on reapply, and shorthand keyword classification is incorrect.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds relative font sizing and correct CSS pixel-to-point conversion to the SWT CSS engine.
Changes:
- Supports
em,%,larger,smaller, and correctedpxsizing. - Extends shorthand parsing, tests, documentation, and examples.
- Updates existing fixtures to use explicit point sizes.
File summaries
| File | Review |
|---|---|
tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ShellTest.java |
Updates fixtures to explicit point units. |
tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/LabelTest.java |
Tests new size forms and shorthand behavior. |
tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CTabFolderTest.java |
Updates fixtures to explicit point units. |
tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/ButtonTest.java |
Updates fixtures to explicit point units. |
tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelperTest.java |
Tests conversion and relative sizing. |
examples/org.eclipse.e4.demo.cssbridge/css/common.css |
Preserves example sizing with pt. |
docs/CSS.md |
Documents supported font-size values. |
bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelper.java |
Moderate: Relative sizes compound during style reapplication instead of using the inherited baseline. |
bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2FontHelper.java |
Moderate: Shorthand parsing misclassifies quoted and mixed-case larger/smaller values. |
Review details
Suppressed comments (2)
bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelper.java:220
- Relative sizes make font conversion depend on
oldFontData, but the engine caches converted fonts by the CSS properties alone (CSSEngineImpl.java:1083-1092andCSSResourcesHelpers.java:79-81). Two widgets with the same family/style andfont-size: 200%but inherited heights of 10 and 20 therefore share the first cached font instead of resolving to 20 and 40. Include the inherited height in the cache identity for relative sizes, or bypass caching for these context-dependent conversions.
case EM -> scaleFontHeight(numeric.value(), oldFontData);
case PERCENT -> scaleFontHeight(numeric.value() / 100, oldFontData);
bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelper.java:241
- When called from
CSSPropertyFontDefinitionHandler,oldFontDataisdefinition.getValue(), and the scaled result is immediately written back withsetValue. Reapplying the samelarger,smaller,em, or%rule therefore scales the previous override again (for example, 10pt becomes 12pt and then 14pt), rather than consistently scaling the registered baseline. Preserve and use the unstyled definition value as the relative-size base.
private static OptionalInt scaleFontHeight(double factor, FontData oldFontData) {
if (oldFontData == null) {
return OptionalInt.empty();
}
return OptionalInt.of(toFontHeight(oldFontData.getHeight() * factor));
- Files reviewed: 9/9 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
vogella
force-pushed
the
css-relative-font-sizes
branch
from
September 4, 2026 11:50
4f2e821 to
4be0e5d
Compare
font-size now understands em, %, larger and smaller. Relative values are resolved against the font the element had before it was styled, which is recorded in its CSS element context, so a theme can ask for a slightly larger font without overriding the size the user configured and restyling does not scale an already scaled font. They are resolved before the font is converted, because converted fonts are cached by their CSS values alone and "larger" means a different font for every element it applies to. px was accepted before but read as a point size. It is now converted with 1px = 0.75pt, as a CSS pixel is 1/96 inch and an SWT font height is 1/72 inch. Style sheets that relied on the old reading render smaller and have to state pt, as the cssbridge example now does. Unitless values and any other unit keep being read as points. The font shorthand accepts the new forms, taking larger and smaller as keywords only unquoted and regardless of case, and a relative size on a FontDefinition scales the registered font instead of replacing it. Assisted-by: multiple AI agents and layers of automated tooling 🤖
vogella
force-pushed
the
css-relative-font-sizes
branch
from
September 4, 2026 13:26
4be0e5d to
f8c7a09
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The CSS engine now understands
em,%,largerandsmallerforfont-size, resolved against the font the widget inherited. A theme can therefore ask for a slightly larger font without overriding the size the user configured, which was not expressible before.pxwas accepted already but silently read as a point size. It is now converted with 1px = 0.75pt, matching the CSS definition of a pixel as 1/96 inch against SWT's 1/72 inch font height. Style sheets that relied on the old reading render smaller and have to statept, as the cssbridge example now does. Unitless values and any other unit keep being read as points.The
fontshorthand accepts the new forms too, a relative size on aFontDefinitionscales the registered font instead of replacing it, anddocs/CSS.mddocuments the supported values.