Bug 442831 - TextLayout.getLineBounds returns incorrect values for right to left text
Summary: TextLayout.getLineBounds returns incorrect values for right to left text
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.3.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.9 M3   Edit
Assignee: Xi Yan CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2014-08-28 15:41 EDT by Jim Mayer CLA
Modified: 2018-08-23 08:56 EDT (History)
2 users (show)

See Also:


Attachments
Program that illustrates the problem. (1.66 KB, application/zip)
2014-08-28 15:41 EDT, Jim Mayer CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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.