[GTK][X11] Drawing on an image is shifted with DPI scaling
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- java, linux
- 領域
- desktop-dev
調査の方向性
Start by running the supplied Java reproduction with GDK_BACKEND=x11 and GDK_SCALE=2, then read the SWT Image and GC drawing APIs and trace their Linux/X11 DPI handling. Compare the repainted image with the original; done means the drawing is correctly aligned at scaled DPI, with only the red rectangle added.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
Drawing on an Image object using a GC is shifted by a significant amount when run on X11 with DPI scaling.
To Reproduce
The following program executed on Linux with either full X11 session or in wayland with Xwayland.
To reproduce:
- Set the GDK_BACKEND=x11 and GDK_SCALE=2 environment variable. The latter was not required on my system, the OS-level scaling was automatically detected and applied with the same result as setting the environment variable.
- Start the program.
package test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class Test
{
private static Image repaint( Image source )
{
Rectangle bounds = source.getBounds();
Image newImage = new Image( source.getDevice(), bounds.width, bounds.height );
GC gc = new GC( newImage );
gc.setAntialias( SWT.ON );
gc.setInterpolation( SWT.HIGH );
int offset = 0;
// offset = bounds.height * ( DPIUtil.getDeviceZoom() - 100 ) / 200;
gc.drawImage( source, 0, 0, bounds.width, bounds.height, 0, offset, bounds.width, bounds.height );
gc.setForeground( new Color( source.getDevice(), 0xff, 00, 00 ) );
gc.drawRectangle( 0, offset, bounds.width - 1, bounds.height - 1 );
gc.dispose();
return newImage;
}
public static void main( String[] args )
{
Display dpy = new Display();
ImageData imageData = new ImageData( 256, 256, 24, new PaletteData( 0xff0000, 0x00ff00, 0x0000ff ) );
for ( int i = 0; i < 256; ++i ) {
for ( int j = i % 16; j < 256 - i % 16; ++j ) {
imageData.setPixel( i, j, ( i << 8 ) + j );
}
}
Image image = new Image( dpy, imageData );
Shell shell = new Shell( dpy );
shell.setText( "SWT " + SWT.getVersion() );
Label label1 = new Label( shell, SWT.NONE );
Label label2 = new Label( shell, SWT.NONE );
label1.setSize( image.getBounds().width, image.getBounds().height );
label1.setImage( image );
image = repaint( image );
label2.setBounds( label1.getBounds().width, 0, image.getBounds().width, image.getBounds().height );
label2.setImage( image );
shell.setSize( label1.getBounds().width + label2.getBounds().width,
Math.max( label1.getBounds().height, label2.getBounds().height ) );
shell.open();
while ( !shell.isDisposed() ) {
if ( !dpy.readAndDispatch() ) {
dpy.sleep();
}
}
dpy.dispose();
}
}
Expected behavior
The re-painted image on the right side should look the same as the one on the left (except for the added red rectangle).
Screenshots
Environment:
- Select the platform(s) on which the behavior is seen:
-
- All OS
-
- Windows
-
- Linux
-
- macOS
-
Additional OS info (e.g. OS version, Linux Desktop, etc)
Observed on Kubuntu 24.04 and 26.04 on both Xwayland and native X11 server -
JRE/JDK version
java-25-openjdk-amd64
Version since
The last version which shows the expected behavior is 4.7.3a:
In SWT 4.8 - 4.16 the image is smaller and shifted vertically:
In SWT 4.17 and newer it is not smaller but it is shifted by the amount relative to the DPI scaling:
Workaround (or) Additional context
I was able to workaround the issue in SWT 4.17 and later by shifting the drawing coordinates by amount proportional to the UI scaling (visible in the code snippet as a commented-out line). The workaround works for different scaling values between 1 and 5. SWT 4.8 - 4.16 would likely require a different shift value(s).
- 主要言語
- Java
- スター
- 202
- フォーク
- 206
- 平均マージ
- 14時間 7分
- マージ済み PR(30日)
- 103
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
eclipse-platform/eclipse.platform.swt のほかの issue
-
`SWT_AWT.initFrame` takes `(long, String)` in Java; the GTK native declares no `className` and the Cocoa native types it `const char *`対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 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 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 75/100
eclipse-platform/eclipse.platform.swt#3336 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
eclipse-platform/eclipse.platform.swt#3718 ·
メンテナーはふだん 1 日以内に返信
eclipse-platform/eclipse.platform.swt の issue をすべて見る
似ている issue
-
`timer` rule rejects dates the engine accepts対応中かも @MFA-G が今日担当しました。 オープンbug ready
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
camunda/bpmnlint-plugin-camunda-compat#281 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
status: waiting-for-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
AOT compilation fails for derived delete queries returning Set対応中かも @ryujungkyun が今日担当しました。 オープンstatus: waiting-for-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
spring-projects/spring-data-jpa#4387 ·
メンテナーはふだん 3 日以内に返信