GC.textExtent() ignores requested font family and measures wider text in headless (Xvfb/GTK) vs. a real win32 display
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Start with the attached TextExtentTest.java and reproduce the reported measurements using the Linux SWT jar under xvfb-run, then compare the attached linux_headless_output.txt and windows_output.txt. Trace GC.textExtent() through the GTK measurement path, checking why the requested font names produce identical results; done means the cause is identified and the behavior is covered by an appropriate regression test or documented limitation.
索引モデルが issue の本文から書いたものです。
説明
Title: GC.textExtent() ignores requested font family and measures wider text in headless (Xvfb/GTK) vs. a real win32 display
Summary
Using a minimal, standalone SWT snippet (no Eclipse RCP application, no GEF/draw2d — pure org.eclipse.swt.graphics.GC#textExtent()), the same font name/size/text produces different measured extents when run headless on Linux under Xvfb (GTK) vs. on a real Windows display (win32).
Two distinct problems are visible in the data:
- Font family name has no effect on measurement in the headless/GTK case. Requesting
"Segoe UI","DejaVu Sans", and"Sans"(all at 9pt) produces byte-identical width/height for every test string under Xvfb/GTK — even thoughSegoe UI(a physically installed TTF, verified viafc-match/fc-listoutside this test) is a genuinely different typeface fromDejaVu Sans. On win32, the three names produce measurably different results, as expected (Segoe UI differs from the DejaVu Sans/Sans fallback). - Headless/GTK measurements are systematically wider than the win32 equivalent for the same font size, by roughly 6%–33% depending on the string (see table below). This causes downstream layout problems in any Eclipse RCP application that pre-computes fixed pixel geometry from text measured headlessly and expects it to match what was authored/measured on a real (typically Windows) display — e.g. GEF/draw2d figures with fixed bounds, as used by Archi (
archimatetool/archi) for diagram rendering.
Environment
- SWT jar (Linux):
org.eclipse.swt.gtk.linux.x86_64_3.134.0.v20260515-1429.jar - SWT jar (Windows):
org.eclipse.swt.win32.win32.x86_64_3.126.0.v20240528-0813.jar
(version mismatch between the two — noted as a caveat below, but the within-platform font-name-has-no-effect finding on Linux is version-independent) - Linux: Docker container, Xvfb virtual display (
xvfb-run -a ...), JRE 21 - Windows: normal desktop session, real display, JRE (same major version)
- Font
Segoe UIverified present on the Linux side (fc-match "Segoe UI"correctly resolves tosegoeui.ttf, confirmed viafc-list)
Reproduction
Minimal snippet (attached in full below) does, per font name in {"Segoe UI", "DejaVu Sans", "Sans"}:
Display display = new Display();
Image dummy = new Image(display, 10, 10);
GC gc = new GC(dummy);
Font font = new Font(display, fontName, 9, SWT.NORMAL);
gc.setFont(font);
Point extent = gc.textExtent(text);
System.out.println(fontName + " -> " + extent.x + "x" + extent.y + " for: " + text);
Run headless:
xvfb-run -a java -cp ".:$SWT_JAR" TextExtentTest
Run on Windows desktop (real display, no Xvfb):
java -cp ".;<swt.jar>" TextExtentTest
Results
All measurements at 9pt. width in pixels as returned by GC.textExtent().
| Text | Linux/Xvfb/GTK (all 3 font names identical) | Windows/win32, Segoe UI |
Windows/win32, DejaVu Sans/Sans |
Linux vs Windows Segoe UI |
|---|---|---|---|---|
Компонент |
70 | 62 | 63 | +12.9% |
финансово-экономического |
174 | 160 | 159 | +8.75% |
ОООС «Ванильный Бюджет» (новая версия) |
277 | 243 | 255 | +14.0% |
топик 20 \nзапрос на формирование УГПП по |
215 | 193 | 200 | +11.4% |
192.168.231.150 \ngoogle.com |
112 | 84 | 96 | +33.3% |
Hello World |
67 | 63 | 64 | +6.3% |
AAAAAAAAAAAAAAAAAAAA (20×A) |
179 | 160 | 140 | +11.9% |
Note on the Linux side: all three requested font names produced these exact same numbers, row for row — i.e. the "Segoe UI" column, "DejaVu Sans" column, and "Sans" column values on Linux are one and the same, whereas on Windows they genuinely differ per font.
Why this matters
Any application that measures/lays out text headlessly (CI pipelines, automated report/diagram generation, etc.) using SWT GC.textExtent() and expects that layout to match what a user sees/authored on a real (typically Windows) desktop will get incorrect, generally too-wide-but-not-reliably-scaled text metrics, and — separately — will get no differentiation at all between different font families in the headless/GTK case. We hit this in practice via Archi (archimatetool/archi) generating HTML diagram reports headlessly in a CI/Docker pipeline: text overflows figure boundaries that were sized correctly on Windows desktop, and no combination of installing/selecting fonts on the Linux side changed the outcome — which this snippet now explains: the font selection wasn't taking effect on the measurement path at all.
Caveats
- The two SWT jar versions compared (3.134.0 Linux vs 3.126.0 Windows) are not identical, so version drift could contribute to the magnitude of the width difference. However, the font-name-has-no-effect-on-Linux finding is internally consistent within the single Linux run (three different names, one identical result) and doesn't depend on cross-version comparison at all.
fc-match/fc-listoutside this JVM confirmSegoe UIis present and correctly resolvable at the fontconfig level — so the lack of differentiation appears to be happening either in SWT's GTK backend itself, or in how it (or possibly Pango/Cairo under Xvfb) selects a font for measurement, not in fontconfig/system-level font registration.
Attached
TextExtentTest.java(full source, self-contained, no dependencies beyond the platform SWT jar)- Raw output:
linux_headless_output.txt,windows_output.txt
Happy to run further variations (different SWT versions on both sides, real X11 display on Linux instead of Xvfb, etc.) if that would help narrow this down further.
- 主要言語
- Java
- スター
- 202
- フォーク
- 206
- 平均マージ
- 23時間 40分
- マージ済み PR(30日)
- 103
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
eclipse-platform/eclipse.platform.swt のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
eclipse-platform/eclipse.platform.swt#3761 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Win32] Table tooltip indexes cell font with subitem -1対応中かも @fdesbiens が 6 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
eclipse-platform/eclipse.platform.swt#3752 ·
メンテナーはふだん 1 日以内に返信
-
`SWT_AWT.initFrame` takes `(long, String)` in Java; the GTK native declares no `className` and the Cocoa native types it `const char *`対応中かも @GreenFuze が 14 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
eclipse-platform/eclipse.platform.swt#3665 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
eclipse-platform/eclipse.platform.swt#3546 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
eclipse-platform/eclipse.platform.swt#3428 ·
メンテナーはふだん 1 日以内に返信
eclipse-platform/eclipse.platform.swt の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
Type/Improvement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
ballerina-platform/static-code-analysis-tool#140 ·
メンテナーはふだん 1 日以内に返信
-
ready-for-triage triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
RedHatInsights/notifications-backend#5080 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
protobuf
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
FasterXML/jackson-dataformats-binary#874 ·
メンテナーはふだん 1 日以内に返信