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

Bug 310054

Summary: [Widget] alignment for different language users(start with blank space char) is a mess with Tree/List
Product: [Eclipse Project] Platform Reporter: yanghang
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WORKSFORME QA Contact: Bogdan Gheorghe <gheorghe>
Severity: normal    
Priority: P3 CC: eclipse.felipe, ericwill, ipun, mukund, pinnamur, prakash, pwebster, raji, Silenio_Quarti
Version: 4.8Keywords: helpwanted, triaged
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
input
none
Picture of the tree with problem
none
Screenshot of problem in Lotus Sametime Connect
none
Multilingual tree viewer
none
sample code
none
expected result
none
compressed result none

Description yanghang CLA 2010-04-21 23:36:26 EDT
Build Identifier: 20100218-1602

My OS is Linux Suse11:

Create input for Jface treeviewer like below:

	public static UserTreeNode getInitalInput() {
		UserTreeNode root = null;
		root = new UserTreeNode( "");
		UserTreeNode n1 = new UserTreeNode( "       ±±¾©");
		UserTreeNode n2 = new UserTreeNode( "       &#1602;&#1601;&#1594;&#1593;&#1607;&#1582;&#1581;&#1605;");
		UserTreeNode n3 = new UserTreeNode( "       &#1574;&#1569;&#1572;&#1585;&#1604;&#1575;&#1609;");
		UserTreeNode n4 = new UserTreeNode( "       English");
		root.addChildren(n1);
		root.addChildren(n2);
		root.addChildren(n3);
		root.addChildren(n4);

		return root;
	}

bug:
alignment for different language users is a mess

Reproducible: Always

Steps to Reproduce:
1.create jfacetreeview
2. creat input for the tree, input different language string, and the string start with same blank space char.
3. show the tree

Bug:
alignment for different language users is a mess
Comment 1 yanghang CLA 2010-04-21 23:41:47 EDT
Created attachment 165685 [details]
input
Comment 2 Raji Akella CLA 2010-04-27 17:50:13 EDT
This is being reported as a usability issue by Lotus Sametime team.
Comment 3 Raji Akella CLA 2010-04-28 11:13:48 EDT
Should this be moved to UI category instead of SWT?
Comment 4 Felipe Heidrich CLA 2010-04-28 14:38:09 EDT
Yes, please send it back if the problem is caused by the native control.
Comment 5 Raji Akella CLA 2010-05-11 16:39:28 EDT
Requesting feedback from UI team.
Comment 6 Paul Webster CLA 2010-05-13 09:03:05 EDT
Please also attach a picture of the tree with the problem.

PW
Comment 7 Raji Akella CLA 2010-05-13 11:27:58 EDT
Created attachment 168397 [details]
Picture of the tree with problem

Adding picture as requested
Comment 8 Raji Akella CLA 2010-05-13 11:31:16 EDT
Created attachment 168398 [details]
Screenshot of problem in Lotus Sametime Connect

Hang Yang, If you have additional data please add here.
Comment 9 Prakash Rangaraj CLA 2010-05-14 00:25:27 EDT
Created attachment 168500 [details]
Multilingual tree viewer

It looks good to me.

I've used the TreeViewer created by PDE's wizard and used some strings translated by Google. Any specific steps to reproduce? Or is it a Lotus/Linux specific bug?
Comment 10 yanghang CLA 2010-05-14 01:26:48 EDT
(In reply to comment #9)
> Created an attachment (id=168500) [details]
> Multilingual tree viewer
> It looks good to me.
> I've used the TreeViewer created by PDE's wizard and used some strings
> translated by Google. Any specific steps to reproduce? Or is it a Lotus/Linux
> specific bug?

It is only reproduce on Suse11. 

Just reminder, the String includes some space char.
For example "   hello"
Comment 11 Prakash Rangaraj CLA 2010-05-14 01:41:01 EDT
(In reply to comment #10)
> It is only reproduce on Suse11. 

Possibly SWT bug? Adding Praveen to cc.

Praveen,/
    Can you quickly check whether SWT Tree on Linux has this issue?
Comment 12 Hitesh CLA 2010-05-14 02:01:00 EDT
(In reply to comment #9)
Thanks, Prakash.

Also ,Hang Yang are you using ownerdraw/stylledlabelproviders ? Could you please share information on the labelprovider code and if you have used alignment bits while setting up columns if any.
Comment 13 yanghang CLA 2010-05-14 02:30:14 EDT
Created attachment 168507 [details]
sample code

This is my sample code
Comment 14 Hitesh CLA 2010-05-14 03:34:44 EDT
(In reply to comment #13)
> Created an attachment (id=168507) [details]
> sample code
> 
> This is my sample code

Thanks for the snippet. This is not reproducible on windows either. 
(In reply to comment #11)
> (In reply to comment #10)
> > It is only reproduce on Suse11. 
> 
> Possibly SWT bug? Adding Praveen to cc.
> 
> Praveen,/
>     Can you quickly check whether SWT Tree on Linux has this issue?

Prakash is right and looks like a platform specific problem. Waiting for SWT's comment.
Comment 15 Praveen CLA 2010-05-14 04:12:13 EDT
(In reply to comment #11)
>     Can you quickly check whether SWT Tree on Linux has this issue?
Yes, I am able to reproduce the problem on my Ubuntu machine. So, it appears to me that GTK does not handle such charset strings in the right way.
However, I have noticed that the alignment happens correctly when there are no spaces before the string.
Comment 16 Praveen CLA 2010-05-14 08:07:08 EDT
After some investigation, I realized that incorrect alignment was due to the variation in the size of "space" character for different unicode chars.
For example, the space char size of chinese chars is slightly wider than the space char size of english chars. Due to this reason, the chinese chars appear as they moved towards right.
This is clearly evident when these strings are set to a Text widget :)
Comment 17 yanghang CLA 2010-05-26 03:15:53 EDT
So it is valid bug, right? 
Have workaround to avoid this?

Thanks
Comment 18 Prakash Rangaraj CLA 2010-05-26 04:05:21 EDT
This bug showed up in a unrelated query for me. Shouldn't the component of this bug be SWT instead of UI?
Comment 19 Felipe Heidrich CLA 2010-05-26 11:57:34 EDT
(In reply to comment #17)
> So it is valid bug, right? 
> Have workaround to avoid this?
> Thanks

I'm still not sure I understood the problem, can you please add a screenshot and highlight how the alignment is wrong ?

I think this problem can be a duplicate of bug 236513.
Can you also test using the latest SWT (3.6 RC2)
Comment 20 Raji Akella CLA 2010-05-26 16:23:24 EDT
Hi Felipe, I had added a couple of screenshots earlier on Hang Yang's behalf. Pls see the one from Lotus Sametime Connect.
Comment 21 yanghang CLA 2010-06-03 01:27:38 EDT
Where can I get the swt3.6 RC2?

I do not find the download on the page 
http://www.eclipse.org/swt/
Comment 22 Prakash Rangaraj CLA 2010-06-03 02:07:03 EDT
(In reply to comment #21)
> Where can I get the swt3.6 RC2?

http://download.eclipse.org/eclipse/downloads/drops/S-3.6RC2-201005201744/index.php Search for SWT binary and source
Comment 23 yanghang CLA 2010-06-03 04:32:50 EDT
run the sample code on Eclipse 3.6 RC2. still has the issue
Comment 24 Felipe Heidrich CLA 2010-06-07 10:34:35 EDT
I have seem this problem before (not sure if it was on Linux, maybe it was).
The problem is the current font does not support all the languages, so the system replaces the current font with a fallback font for the language in the item. But instead of drawing only the foreign characters with the fallback font it draws the entire string. It happens that the whitespace characters have different width in different fonts. If the system was always drawing the whitespaces with the current font and only using the fallback font to draw the foreign characters the problem wouldn't exist (IMO).

Not sure how to fix this problem.
Comment 25 Raji Akella CLA 2010-06-10 10:59:50 EDT
Any more thoughts on this one?
Comment 26 Felipe Heidrich CLA 2010-06-10 11:42:08 EDT
(In reply to comment #25)
> Any more thoughts on this one?

Just for my curiosity, why do you need to add whitespaces in the beginning of the text ?
Comment 27 yanghang CLA 2010-06-13 01:43:39 EDT
We need use different width icon in the tree.

The expected result is in image(expected result) attached.


But if we if use Labelprovider to provide these different width icons. the result is is in image(compressed result).

So we use gc.drawImage() to make the icon show correctly. to avoid overlap, we need add some space char to text
Comment 28 yanghang CLA 2010-06-13 01:45:29 EDT
Created attachment 171793 [details]
expected result
Comment 29 yanghang CLA 2010-06-13 01:45:59 EDT
Created attachment 171794 [details]
compressed result
Comment 30 Felipe Heidrich CLA 2010-06-14 09:31:45 EDT
I would not recommend using whitespace for that.


You should make all images the same width. When the actual image is smaller than max width you need to create a transparent image (or with the same background as the item) with max width and draw your image in it (easy to control the alignment). At the end, set the transparent image to the item.
I believe Eclipse uses this technique all over the place and they even have a class to help you composite images.


Other option is, keep using custom draw (like it seems you are already doing). In MeasureItem you return the width to draw all the images, paddings, and text. In EraseItem you clear the SWT.FOREGROUND flag (so SWT wont draw the text for you. In PaintItem you draw all your imges and the text.
Comment 31 Ian Pun CLA 2017-07-04 10:19:33 EDT
Bug triaged. Visit https://wiki.eclipse.org/SWT/Devel/Triage for more information.
Comment 32 Eric Williams CLA 2019-02-15 15:29:34 EST
As per comment 30.