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

Bug 41474

Summary: GTK-BIDI: RTL support in Text
Product: [Eclipse Project] Platform Reporter: Semion Chichelnitsky <semion>
Component: SWTAssignee: Bogdan Gheorghe <gheorghe>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: baochlin, eclipse.felipe, ericwill, Lina.Kemmel, matial, peter, salexb, wajnberg, yanghang
Version: 3.0Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Linux-GTK   
Whiteboard: stalebug
Bug Depends on:    
Bug Blocks: 207245, 333624    

Description Semion Chichelnitsky CLA 2003-08-13 08:43:27 EDT
RTL-oriented multiline Text with wrap mode "WRAP_NONE" can't be aligned 
properly. This mode can be used only in case, when text is trail-aligned. In 
other cases we need use WRAP_WORD mode:
.......
if ((style & SWT.WRAP) != 0)
   OS.gtk_text_view_set_wrap_mode(handle,OS.GTK_WRAP_WORD);
else if((style & SWT.RIGHT_TO_LEFT) != 0 && (style & SWT.TRAIL) == 0)   //bidi
   OS.gtk_text_view_set_wrap_mode(handle,OS.GTK_WRAP_WORD);             //bidi 
.......
Comment 1 Felipe Heidrich CLA 2003-08-18 16:47:19 EDT
It means: you need to force word wrap in order to get the trail alignment on a
RTL multi-line text widget ?

We have this same problem for LTR, see Bug#37530 comment #5, in there we decide
not to fix the problem. We should do the same here.

Comment 2 Semion Chichelnitsky CLA 2003-08-19 05:08:35 EDT
Yes, problem has the same reason, but in case of rtl multiline Text we need to 
solve it. Take into consideration, that here we need to get leading (default) 
alignment properly, and it is more important, that correct wrapping mode. What 
we suggest here is the following: rtl-oriented Text should be always in 
WRAP_WORD mode excluding the case, when it has explicitly assigned trail 
alignment. 
Comment 3 Felipe Heidrich CLA 2003-08-19 11:17:09 EDT
I've filed a bug against GTK for this:
http://bugzilla.gnome.org/show_bug.cgi?id=120256
It might be something else we can do to fix this.

According to bug#37530 I found no fix for right alignment for the single line 
text widget, is this a bug on Bidi as well ?

Comment 4 Felipe Heidrich CLA 2003-08-19 12:09:37 EDT
Works fine for GtkEntry (Single-line text).

Comment 5 Semion Chichelnitsky CLA 2003-08-19 12:17:53 EDT
Right alignment or trail alignment? Single line SWT Text doesn't have problem 
with leading (default) alignment, but it's content currently can't be aligned 
to trailing edge of widget (it isn't bidi problem).
Comment 6 Felipe Heidrich CLA 2003-09-08 14:58:45 EDT
there are some GTK-Bugs we could contribute to have this problem fixed:
http://bugzilla.gnome.org/show_bug.cgi?id=59799
http://bugzilla.gnome.org/show_bug.cgi?id=120256
http://bugzilla.gnome.org/show_bug.cgi?id=118543
Comment 7 Felipe Heidrich CLA 2005-02-28 12:36:43 EST
Semion, this bug is fixed in GTK (the problem about forcing WRAP).
The thing is: the alignment is correct on BIDI when the text in the widget is
RTL. In Gtk widgets the paragraph level depends on the first wrong character in
the text, when the paragraph is set to one it changes the alignment left->rigth,
and the other way around too.

I'm not sure we can (or should) change the native behaviour of the widget.
What do you think ?
Comment 8 Lina Kemmel CLA 2010-12-27 09:20:46 EST
(In reply to comment #7)
> In Gtk widgets the paragraph level depends on the first strong character in
> the text, when the paragraph is set to one it changes the alignment left->rigth,
> and the other way around too.

It seems that nowadays proper alignment can be set irrespective of the first strong character of the content.

And for Text, it is actually set upon widget creation (gtk_entry_set_alignment / gtk_text_view_set_justification for single/multi -line widget respectively).

So the original problem reported here seems to be fixed (when using GTK of an appropriate level).

However, we still need to override the "auto_dir" behavior when Text#setOrientation is called (i.e. when setting a strong base direction explicitly). - But this is a subject for another bugzilla entry.
Comment 9 Felipe Heidrich CLA 2011-01-10 12:38:22 EST
The basic problem is still there:
Text mirrors or not based on the content.

public static void main(String[] args) {
	Display display = new Display();
	Shell shell = new Shell( display , SWT.SHELL_TRIM | SWT.RIGHT_TO_LEFT);
	shell.setLayout(new GridLayout(1, false));
	Text text = new Text(shell, SWT.SINGLE);
	text.setText("hellow world.");
	text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	Label label = new Label(shell, SWT.NONE);
	label.setText("hellow world.");
	label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	shell.setSize(400, 200);
	shell.open();
	while( !shell.isDisposed() ) {
		if( !display.readAndDispatch() )
			display.sleep();
	}
	display.dispose();
}

See the alignment for the text and the label differ.
Comment 10 Lina Kemmel CLA 2011-01-12 08:51:13 EST
Felipe,
However, OS.gtk_entry_set_alignment and OS.gtk_text_view_set_justification now seem to work properly, so Text can be aligned as needed (if the alignment is set explicitly) without the need to force wrap mode.

The following snippet (with SWT.RIGHT style added for Text) causes the Text to be aligned to the right:

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell( display , SWT.SHELL_TRIM | SWT.RIGHT_TO_LEFT);
    shell.setLayout(new GridLayout(1, false));
    Text text = new Text(shell, SWT.SINGLE | SWT.RIGHT);
    text.setText("hellow world.");
    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Label label = new Label(shell, SWT.NONE);
    label.setText("hellow world.");
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    shell.setSize(400, 200);
    shell.open();
    while( !shell.isDisposed() ) {
        if( !display.readAndDispatch() )
            display.sleep();
    }
    display.dispose();
}
____________________________

As for base text direction, this is a separate problem which AFAICS can be only overcome by using control characters..
Comment 11 Felipe Heidrich CLA 2011-01-12 15:47:00 EST
Fixing the alignment but not fixing the base text direction does not make sense to me.
We could look into what it takes to force GTK to use the base text direction we need. If that fails, in a worse cas scenario, add the control characters ourselves so that windows and gtk have the same behaviour. This fix would conflict with the fix for 230854.

Other option is to say this is a platform difference and don't do anything about it (we just have to documented it).
Comment 12 Felipe Heidrich CLA 2011-01-18 15:25:41 EST
*** Bug 333130 has been marked as a duplicate of this bug. ***
Comment 13 Felipe Heidrich CLA 2011-01-18 15:36:32 EST
Some cases that are still broken on GTK:

Label + WRAP
Text depends on the text content
On Windows all the controls in this snippet are right-aligned
public static void main(String[] args) {
	Display display = new Display();
	Shell shell = new Shell(display, SWT.DIALOG_TRIM|SWT.RIGHT_TO_LEFT);
	shell.setSize(500, 375);
	shell.setLayout(new GridLayout());

	Label l0 = new Label(shell, SWT.NULL);
	l0.setText("\u0646\u0635 \u0627\u0644\u062A\u0631\u0634\u064A\u062D");
	l0.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 0, 0));

	Label l1 = new Label(shell, SWT.WRAP);
	l1.setText("\u0646\u0635 \u0627\u0644\u062A\u0631\u0634\u064A\u062D");
	l1.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 0, 0));
	
	Label l2 = new Label(shell, SWT.NULL);
	l2.setText("a \u0646\u0635 \u0627\u0644\u062A\u0631\u0634\u064A\u062D");
	l2.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 0, 0));
	
	Label l3 = new Label(shell, SWT.WRAP);
	l3.setText("a \u0646\u0635 \u0627\u0644\u062A\u0631\u0634\u064A\u062D");
	l3.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 0, 0));

	
	Text t0 = new Text(shell, SWT.SINGLE);
	t0.setText("\u0646\u0635 \u0627\u0644\u062A\u0631\u0634\u064A\u062D");
	t0.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 0, 0));
	
	Text t1 = new Text(shell, SWT.SINGLE | SWT.WRAP);
	t1.setText("\u0646\u0635 \u0627\u0644\u062A\u0631\u0634\u064A\u062D");
	t1.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 0, 0));

	Text t2 = new Text(shell, SWT.SINGLE);
	t2.setText("a \u0646\u0635 \u0627\u0644\u062A\u0631\u0634\u064A\u062D");
	t2.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 0, 0));
	
	Text t3 = new Text(shell, SWT.SINGLE | SWT.WRAP);
	t3.setText("a \u0646\u0635 \u0627\u0644\u062A\u0631\u0634\u064A\u062D");
	t3.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 0, 0));
	
	
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
Comment 14 Lina Kemmel CLA 2011-01-18 18:14:01 EST
(In reply to comment #11)
> We could look into what it takes to force GTK to use the base text direction 
> we need. If that fails, in a worse cas scenario, add the control characters
> ourselves so that windows and gtk have the same behaviour. This fix would
> conflict with the fix for 230854.

I think there is no conflict with 230854 if we delegate base direction support to application. Then an application would do the following:

.....
text.addSegmentListener(new SegmentListener() {
	public void lineGetSegments(SegmentEvent event) {
		event.segments = new int[] { 0 };
	});
That will cause bidi marks to be prepended to a Text: LRM for a Text with SWT.LEFT_TO_RIGHT orientation and RLM - for a Text with SWT.RIGHT_TO_LEFT orientation. As LRM and RLM have strong directionality, GTK will provide RTL base direction when the text starts with RLM, and LTR - when it starts with the LRM character.
As a result, both alignment and base direction will be appropriate.
Comment 15 Lina Kemmel CLA 2011-01-18 18:44:27 EST
Better, we can merge "external" and "internal" segments (which would be easy as the latter is always a single default segment at position 0).
Comment 16 Lina Kemmel CLA 2011-01-18 19:18:10 EST
(In reply to comment #13)
> Some cases that are still broken on GTK:
> Label + WRAP
> Text depends on the text content
> On Windows all the controls in this snippet are right-aligned
Yes, but the default alignment can be overridden if specified explicitly Previously, as I understand it, one couldn't apply non-default alignment in the WRAP_NONE mode at all.
Felipe, I believe that was fixed in the course of 
https://bugzilla.gnome.org/show_bug.cgi?id=120256
that you opened.
Comment 17 Eric Williams CLA 2018-11-30 15:16:00 EST
*** Bug 465094 has been marked as a duplicate of this bug. ***
Comment 18 Eclipse Genie CLA 2020-11-20 03:37:12 EST
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.