[Win32] TextLayout.getBounds() calculates incorrect width on monitors with non 100% scaling
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Start by tracing TextLayout.getBounds() and TextLayout.setWidth() in SWT's Windows implementation, using the supplied standalone snippet to reproduce the issue at different monitor scaling levels. Compare the returned bounds and wrapping behavior under disabled and enabled autoscaling, including after moving the window between monitors. Done means the width from getBounds() keeps the text unwrapped in the reported Windows scenarios without breaking autoscaling behavior.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
TextLayout.getBounds() method returns bad width on monitors with non 100% scaling. The code that I expect to work correctly is the following:
textLayout.setWidth(textLayout.getBounds().width)
When doing this I expect the text of the TextLayout to not wrap. But with certain font sizes and on monitors with non 100% scaling the text wraps. I've initially suspected fractional scaling values like 125%, but testing with 200% shows that the problem is present there too. I've tried to adjust the width by 1px and even by 2px, but it looks like this is not just an off by 1 error.
Note that I am testing this with 2 autoscale modes for the control:
- AutoscaleMode.DISABLED - the text is wrapped incorrectly
- AutoscaleMode.ENABLED - the text is correct initially, but broken when window is moved from to another monitor, for example from one with 125% to one with 100% scaling
To Reproduce
A standalone SWT snippet to reproduce the behavior:
package org.eclipse.swt.snippets;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.AutoscalingMode;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class TextLayoutBoundsBug {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
shell.setText("TextLayoutBoundsBug");
shell.setAutoscalingMode(AutoscalingMode.DISABLED);
shell.setSize(1000, 1000);
Font font = shell.getFont();
FontData fontData = font.getFontData()[0];
createTextLayoutAt(shell, 10, 10, fontData, 42, "Reset", 0);
createTextLayoutAt(shell, 10, 80, fontData, 41, "Reset", 0);
createTextLayoutAt(shell, 210, 10, fontData, 42, "Download", 1);
createTextLayoutAt(shell, 210, 80, fontData, 41, "Download", 1);
createTextLayoutAt(shell, 510, 10, fontData, 42, "Download & Reset", 2);
createTextLayoutAt(shell, 510, 80, fontData, 41, "Download & Reset", 2);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private static TextLayout createTextLayoutAt(Control parent, int x, int y, FontData fontData, int fontHeight,
String text,
int widthCorrection) {
Font derivedFont = new Font(parent.getDisplay(),
new FontData(fontData.getName(), fontHeight, fontData.getStyle()));
TextLayout textLayout = new TextLayout(parent.getDisplay());
textLayout.setFont(derivedFont);
textLayout.setText(text);
textLayout.setWidth(textLayout.getBounds().width + widthCorrection);
parent.addListener(SWT.Paint, event -> {
textLayout.draw(event.gc, x, y);
});
return textLayout;
}
}
Screenshots
- AutoscalingMode.DISABLED, 125% scaling. Text is wrapping:
- AutoscalingMode.ENABLED, 125% scaling. Text looks correct:
Then moved to monitor with 100% scaling. Text is wrapping again:
Exactly the same problem can be seen with 200% scaling so I am not including additional screenshots.
Environment:
- Select the platform(s) on which the behavior is seen:
-
- All OS
-
- Windows
-
- Linux
-
- macOS
I've tested this also on Linux with 200% scaling and it worked correctly. Didn't test macOS.
- Ngôn ngữ chính
- Java
- Star
- 202
- Fork
- 206
- Merge trung bình
- 1 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 109
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của eclipse-platform/eclipse.platform.swt
-
[Win32] Table tooltip indexes cell font with subitem -1Có thể đã có người làm @fdesbiens đã nhận 15 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
eclipse-platform/eclipse.platform.swt#3752 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
eclipse-platform/eclipse.platform.swt#3546 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
eclipse-platform/eclipse.platform.swt#3428 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 75/100
eclipse-platform/eclipse.platform.swt#3336 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Cocoa] NPE in Text.shouldChangeTextInRange_replacementString when the press-and-hold accent menu inserts textCó thể đã có người làm @Jm6CnDDXBwFTakS đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 25/100
eclipse-platform/eclipse.platform.swt#3819 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của eclipse-platform/eclipse.platform.swt
Issue tương tự
-
Type: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
MCP add-on: JSON responses with non-ASCII characters are truncated (wrong Content-Length)Có thể đã có người làm @dhanushbs10 đã nhận hôm nay. Đang mởadd-on bug in:mcp
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
vaadin-map
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
vaadin/flow-components#10586 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
WeReadInstaller writes the launcher database on the main thread at handover (Activity pause timeout)Đang mởbug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
wpilibsuite/SystemcoreTesting#446 ·
Maintainer thường phản hồi trong vòng 1 ngày