GNOME Bugzilla – Bug 120256
GtkTextView doesn't honour justification without wrapping
Last modified: 2011-02-04 16:16:03 UTC
If GTK_WORD_WRAP is not used CENTER and RIGHT justification doesn't work. Compile and run the attached test case, the right justification of text won't work. Uncomment the line that sets GTK_WORD_WRAP, compile and run again, justification works fine now. How can I workaround this problem or there is something wrong in my code ?
Created attachment 19349 [details] Testcase
Well justification is with respect to other lines of text, so if you only have one line of text, left/center/right justification are all the same thing. That may be the issue. Or there could be a bug. ;-) Try with multiple lines.
Well, I just added multiple lines by changing the line that set the text to: gtk_text_buffer_set_text (buffer, "This text should be rigt alignment.\n This text should be rigt alignment.\n This text should be rigt alignment.\n", -1); The bug is still there. Futher, imagine an user who want to use textview to display (one-line or multiple, doesn't matter) some arabic/hebrew text. He would call gtk_widget_set_direction() but likely he would not touch the justification. The widget would have a wrong RTL layout (text aligment on the left instead of on the right) unless word wrap is set. So, for having the correct RTL layout the user needs to set word wrap. IMHO this is just a bug.
Yes, this may be broken. I guess if there's no width set on the PangoLayout maybe the textview needs to do the justification manually or something. Would have to investigate. Unrelated, are you sure you need to call gtk_widget_set_direction()? GTK should be defaulting all widgets to the proper direction for the current locale. (And also automatically flipping the justification to match widget direction.)
In SWT we set the default direction to LTR, then for each individual widget we call gtk_widget_set_direction() and whatever is need to give the correct RTL layout. Several GTK widgets only calling gtk_widget_set_direction() is not enough. Some widgets, like GtkCombo, are *very* hard to give the correct RTL layout. I know that part of this trouble is because we set default direction to LTR, other part is because GTK does not do all the work when the RTL flag is set (i.e. scrollbars still need to place manually on the left side).
Trying to make up for deficencies in GTK+'s RTL layout flipping will very likely just cause your program to break with future versions of GTK+ where we fix the problems.
What if you have lines wider than the screen width? Do they extend the wrap width? May also be some interaction with bug 118543, which is about better bidi support for the text widget.
*** Bug 124825 has been marked as a duplicate of this bug. ***
I put in a pretty simple change that seems to get justification working for GTK_WRAP_NONE. Sat Mar 13 18:13:13 2004 Owen Taylor <otaylor@redhat.com> * gtk/gtktextlayout.c (gtk_text_layout_get_line_display): When not wrapping, do the offset of the line for justification ourselves. (#120256, Felipe Heidrich) Let's hope it doens't break anything... ;-) It turns out that you want to justify to the widest line, since that's what you need for RTL text - you want everything lined up at the right column when you scroll all the way to the right. Handling of the horizontal scrollbar isn't really right for RTL paragraphs, but I'm pretty positive there is a different bug about that.