Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 442831

Summary: TextLayout.getLineBounds returns incorrect values for right to left text
Product: [Eclipse Project] Platform Reporter: Jim Mayer <jim>
Component: SWTAssignee: Xi Yan <xixiyan>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: ericwill, xixiyan
Version: 4.3.2Keywords: triaged
Target Milestone: 4.9 M3   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/127589
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=23d65c30e28bf3ac50666f5d621156cd02248454
Whiteboard:
Attachments:
Description Flags
Program that illustrates the problem. none

Description Jim Mayer CLA 2014-08-28 15:41:48 EDT
Created attachment 246513 [details]
Program that illustrates the problem.

The method "Rectangle getLineBounds(int lineIndex) on TextLayout is supposed to return the bounding box for the given line of text.  It works correctly when the orientation is set to SWT.LEFT_TO_RIGHT.  When the orientation is set to SWT.RIGHT_TO_LEFT, however, the returned bounding box is flipped from the displayed text for SWT.LEFT or SWT.RIGHT alignment.

I have attached a sample program that exhibits the problem.  It renders text using a TextLayout and draws a rectangle on the bounds of each line.  There is a check box that flips the LEFT_TO_RIGHT/RIGHT_TO_LEFT setting.

To repeat, compile and run the program then select the "RTL" check box.  Notice that the bounding box for each line has the wrong alignment.

I believe that the problem is in the getLineBounds method itself.  Removing the following lines from that method appears to fix the problem:

	if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) {
		x = width() - x - width;
	}

Jim Mayer
Comment 1 Xi Yan CLA 2018-08-16 17:11:34 EDT
I can reproduce the issue on SWT master as of today.
Comment 2 Eclipse Genie CLA 2018-08-17 10:26:48 EDT
New Gerrit change created: https://git.eclipse.org/r/127589
Comment 4 Eric Williams CLA 2018-08-20 14:51:28 EDT
(In reply to Eclipse Genie from comment #3)
> Gerrit change https://git.eclipse.org/r/127589 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=23d65c30e28bf3ac50666f5d621156cd02248454

Patch is in master, thanks Xi.
Comment 5 Eric Williams CLA 2018-08-23 08:56:58 EDT
Verified in I20180821-2000.