| Summary: | [Graphics] TextLayout#getOffset() isn't correct with RTL text | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Felipe Heidrich <eclipse.felipe> |
| Component: | SWT | Assignee: | Platform-SWT-Inbox <platform-swt-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | Felipe Heidrich <eclipse.felipe> |
| Severity: | normal | ||
| Priority: | P3 | CC: | jim |
| Version: | 3.1 | Keywords: | triaged |
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | stalebug | ||
This problem makes hard to fix StyledText#getOffsetLinePoint(int,int,int)
int getOffsetAtPoint(int x, int y, int lineIndex) {
TextLayout layout = renderer.getTextLayout(lineIndex);
x += horizontalScrollOffset - leftMargin;
int[] trailing = new int[1];
int offsetInLine = layout.getOffset(x, y, trailing);
int index = layout.getLineIndex(offsetInLine);
int[] offsets = layout.getLineOffsets();
if (offsetInLine == offsets[index] && trailing[0] == 0) {
caretAlignment = OFFSET_LEADING;
} else {
offsetInLine += trailing[0];
String line = content.getLine(lineIndex);
int lineEnd;
if (offsetInLine == line.length()) {
lineEnd = offsetInLine;
} else {
index = layout.getLineIndex(offsetInLine);
lineEnd = offsets[index];
}
if (offsetInLine == lineEnd) {
caretAlignment = PREVIOUS_OFFSET_TRAILING;
} else {
caretAlignment = OFFSET_LEADING;
if (trailing[0] != 0) {
int level;
int offset = offsetInLine - trailing[0];
while (offset > 0 && Character.isDigit(line.charAt(offset))) offset--;
if (offset == 0 && Character.isDigit(line.charAt(offset))) {
level = isMirrored() ? 1 : 0;
} else {
level = layout.getLevel(offset) & 0x1;
}
int trailingLevel = layout.getLevel(offsetInLine) & 0x1;
if ((level ^ trailingLevel) != 0) {
caretAlignment = PREVIOUS_OFFSET_TRAILING;
}
}
}
}
renderer.disposeTextLayout(layout);
return offsetInLine + content.getOffsetAtLine(lineIndex);
}
Your bug has been moved to triage, visit http://www.eclipse.org/swt/triage.php for more info. This issue looks like it could be related to a bug report I just filed on getLineBounds. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=442831 This is a one-off bulk update. (The last one in the triage migration). Moving bugs from swt-triaged@eclipse to platform-swt-inbox@eclipse.org and adding "triaged" keyword as per new triage process: https://wiki.eclipse.org/SWT/Devel/Triage See Bug 518478 for details. Tag for notification/mail filters: @TriageBulkUpdate This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |
when a line L wraps is impossible to tell from the result of getOffset if the click happened on the left of line L or on the right of line L + 1. Here the test case and its result: public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event event) { TextLayout layout = new TextLayout(event.display); layout.setText ("English wraps"); layout.setWidth(layout.getBounds().width - 2); layout.draw(event.gc, 10, 10); int[] trailing = new int [1]; int[] lineOffsets; int offset; offset = layout.getOffset(0, 0, trailing); System.out.print("English text, line offsets: "); lineOffsets = layout.getLineOffsets(); for (int i = 0; i < lineOffsets.length; i++) { System.out.print(lineOffsets[i] + " "); } System.out.println(); System.out.println("offset:" + offset + " trailing:" + trailing[0]); offset = layout.getOffset(layout.getLineBounds(0).width + 2, 0, trailing); System.out.println("offset:" + offset + " trailing:" + trailing[0]); offset = layout.getOffset(0, layout.getLineBounds(0).height + 2, trailing); System.out.println("offset:" + offset + " trailing:" + trailing[0]); offset = layout.getOffset(layout.getLineBounds(0).width + 2, layout.getLineBounds(0).height + 2, trailing); System.out.println("offset:" + offset + " trailing:" + trailing[0]); layout.dispose(); layout = new TextLayout(event.display); layout.setText ("\u0623\u0639\u0644\u0646\u062A \u0648\u0632\u0627\u0631\u0629"); layout.setWidth(layout.getBounds().width - 2); layout.draw(event.gc, 10, 70); System.out.print("Arabic text, line offsets: "); lineOffsets = layout.getLineOffsets(); for (int i = 0; i < lineOffsets.length; i++) { System.out.print(lineOffsets[i] + " "); } System.out.println(); offset = layout.getOffset(0, 0, trailing); System.out.println("offset:" + offset + " trailing:" + trailing[0]); offset = layout.getOffset(layout.getLineBounds(0).width + 2, 0, trailing); System.out.println("offset:" + offset + " trailing:" + trailing[0]); offset = layout.getOffset(0, layout.getLineBounds(0).height + 2, trailing); System.out.println("offset:" + offset + " trailing:" + trailing[0]); offset = layout.getOffset(layout.getLineBounds(0).width + 2, layout.getLineBounds(0).height + 2, trailing); System.out.println("offset:" + offset + " trailing:" + trailing[0]); layout.dispose(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose (); } ---- English text, line offsets: 0 8 13 offset:0 trailing:0 offset:7 trailing:1 offset:8 trailing:0 offset:12 trailing:1 Arabic text, line offsets: 0 6 11 offset:6 trailing:0 offset:0 trailing:0 offset:11 trailing:0 offset:6 trailing:0