Skip to content

Support relative font sizes and px in the CSS engine - #4315

Open
vogella wants to merge 1 commit into
eclipse-platform:masterfrom
vogella:css-relative-font-sizes
Open

Support relative font sizes and px in the CSS engine#4315
vogella wants to merge 1 commit into
eclipse-platform:masterfrom
vogella:css-relative-font-sizes

Conversation

@vogella

@vogella vogella commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

The CSS engine now understands em, %, larger and smaller for font-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.

px was 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 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 too, a relative size on a FontDefinition scales the registered font instead of replacing it, and docs/CSS.md documents the supported values.

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Test Results

   858 files  ±  0     858 suites  ±0   1h 6m 33s ⏱️ + 26m 5s
 8 305 tests + 26   8 062 ✅ + 26  243 💤 ± 0  0 ❌ ±0 
20 784 runs  +209  20 114 ✅ +176  670 💤 +33  0 ❌ ±0 

Results for commit f8c7a09. ± Comparison against base commit 9560649.

♻️ This comment has been updated with latest results.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 corrected px sizing.
  • 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-1092 and CSSResourcesHelpers.java:79-81). Two widgets with the same family/style and font-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, oldFontData is definition.getValue(), and the scaled result is immediately written back with setValue. Reapplying the same larger, 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
vogella force-pushed the css-relative-font-sizes branch from 4f2e821 to 4be0e5d Compare September 4, 2026 11:50
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
vogella force-pushed the css-relative-font-sizes branch from 4be0e5d to f8c7a09 Compare September 4, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants