Skip to content

[Win32] Ensure GC.textExtent/stringExtent returns large enough results#3101

Merged
fedejeanne merged 1 commit into
eclipse-platform:masterfrom
vi-eclipse:issue-platform-2295
Mar 3, 2026
Merged

[Win32] Ensure GC.textExtent/stringExtent returns large enough results#3101
fedejeanne merged 1 commit into
eclipse-platform:masterfrom
vi-eclipse:issue-platform-2295

Conversation

@HeikoKlare
Copy link
Copy Markdown
Contributor

The GC.textExtent()/stringExtent() operations return values in logical SWT points. On Windows, this involves a conversion from the actual pixel values according to the current zoom factor. This conversion includes a rounding to integer values which can lead to a value that is slightly smaller than the actual pixel value. The expectation of consumers is, however, that the result effectively represents the size of a bounding box, i.e., that the whole string fully fits into a rectangle of the returned size.

To ensure that the results of GC.textExtent()/stringExtent() are always large enough so that the text fits into an accordingly sized rectangle on every zoom, this change adapts the performed rounding operations to always round up the values. This makes the behavior consistent to rounding behavior of the Control.computeSize() methods with a similar semantics.

Contributes to eclipse-platform/eclipse.platform#2295

Example

The effects of the wrong rounding can be seen in Platform's Terminal implementation. Each character is drawn on its own in a grid according to the individual character size. And the calculated size for each character and thus the grid cells can become slightly too low on zooms != 100%, resulting in cut-off characters:
image

With this change, the resulting characters will have sufficient space:
image

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 27, 2026

Test Results (win32)

   34 files     34 suites   6m 29s ⏱️
4 650 tests 4 577 ✅ 73 💤 0 ❌
1 184 runs  1 160 ✅ 24 💤 0 ❌

Results for commit 785dba0.

♻️ This comment has been updated with latest results.

The GC.textExtent()/stringExtent() operations return values in logical
SWT points. On Windows, this involves a conversion from the actual pixel
values according to the current zoom factor. This conversion includes a
rounding to integer values which can lead to a value that is slightly
smaller than the actual pixel value. The expectation of consumers is,
however, that the result effectively represents the size of a bounding
box, i.e., that the whole string fully fits into a rectangle of the
returned size.

To ensure that the results of GC.textExtent()/stringExtent() are always
large enough so that the text fits into an accordingly sized rectangle
on every zoom, this change adapts the performed rounding operations to
always round up the values. This makes the behavior consistent to
rounding behavior of the Control.computeSize() methods with a similar
semantics.

Contributes to
eclipse-platform/eclipse.platform#2295
@HeikoKlare HeikoKlare force-pushed the issue-platform-2295 branch from d5980e5 to 785dba0 Compare March 2, 2026 13:39
@HeikoKlare HeikoKlare requested a review from fedejeanne March 2, 2026 14:36
@fedejeanne fedejeanne merged commit e3542b4 into eclipse-platform:master Mar 3, 2026
17 checks passed
@fedejeanne fedejeanne deleted the issue-platform-2295 branch March 3, 2026 08:04
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