After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 83058 - Arabic shaping mistaken with accelerated keys
Arabic shaping mistaken with accelerated keys
Status: RESOLVED FIXED
Product: pango
Classification: Platform
Component: general
unspecified
Other Linux
: Normal major
: 1.2.0
Assigned To: Owen Taylor
Owen Taylor
: 157019 (view as bug list)
Depends on:
Blocks: 83080
 
 
Reported: 2002-05-26 15:53 UTC by Isam Bayazidi
Modified: 2005-07-22 19:12 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
A first patch (10.29 KB, patch)
2002-08-21 00:13 UTC, Roozbeh Pournader
none Details | Review
Image of underlines not breaking Arabic text (7.69 KB, image/png)
2002-11-18 07:20 UTC, Owen Taylor
  Details
pango-glyph-item.c [new file] (6.31 KB, text/plain)
2002-11-18 07:23 UTC, Owen Taylor
  Details
pango-glyph-item.h [new file] (1.51 KB, text/plain)
2002-11-18 07:24 UTC, Owen Taylor
  Details
Remaining diffs (11.70 KB, patch)
2002-11-18 07:27 UTC, Owen Taylor
none Details | Review

Description Isam Bayazidi 2002-05-26 15:53:12 UTC
When Using the Arabic translated interface for ANY Gnome2 application, the
acclerated key in the menu item (the one used with ALT to fast jump), which
apeares underlined, is not connected to the rest of the word. for example
the menu item "Ma_laf" (file) does not look like a proper word due to the
seperation in the word becuase of the acclerated key. The underlined letter
is not connected before and after as it should. This cause major
readability issue for Arabic interface.
Comment 1 Luis Villa 2002-05-29 06:00:59 UTC
I'd love to mark this up but given other i18n issues and the gtk
team's workload this is not a release blocker. Sorry; I wish it had
been reported earlier.
Comment 2 Isam Bayazidi 2002-05-29 10:18:36 UTC
Too bad this is an Gnome Blocker for Arabic language ..  Luis Villa, are 
you stating your opnion or you have a role in the GTK development and 
what you said is a statement  ? 
I am currently the Gnome Translation coordinator for Arabic, and the 
Arabic team reached 48% in 3 weeks.. it seems that the Arabic 
translation would be called off until this is fixed.. 
Comment 3 Owen Taylor 2002-05-29 15:35:33 UTC
This is a *really* hard bug to fix; the trouble is that
a different attribute is set on the underline character,
and Pango shapes each attributed section separately.
(attributes within words weren't really planned for.)

There are three ways I can think of fixing it:

 - Don't use Pango attributes for the underline characters
   but draw them separetely.

 - Do some sort of trick to merge adjacent runs with
   attributes "that don't affect the shaping"
   (color, underline)

 - Change the Pango engine interface to pass, along with the text
   of the run being shaped, some characters of context.

None of these is at all easy to do, and certainly won't
happen before the Pango-1.2 timescale.

I'd suggest that to the Arabic Team, they may need to
omit underline accelerators from the menu items for
now .... I understand this is highly unsatisfacotary
but it's the best I can suggest at the moment.
Comment 4 Roozbeh Pournader 2002-08-20 12:18:56 UTC
Owen, I was wondering how hard is it to tackle this. Do you recommend
waiting until Pango 1.2 or you think one like me can try his hand on it?
If the latter, which of your three suggestions should be easier?
Comment 5 Owen Taylor 2002-08-20 21:02:47 UTC
Well, waiting for pango-1.2 won't do much good by itself :-)

Thinking about it:

 Solution #3 doesn't work becuase the underline could fall
 on half of a ligature pair.

 Solution #2 is possibly right but would require extensive
 changes to Pango. What I think you'd need to do is add: 
  
   pango_glyph_string_extents_with_attrs (PangoGlyphString *glyphs,
                                          PangoAttrList    *extra_attrs,
                                          ...)

   And a variants of pango_x_render()/pango_xft_render() that took 
   an extra list of attrs as well.

  So, when Pango got a string, it would separate it into 
  "shape relevant" and "shape irrelevant" attributes, and
  pass the first set to the shaper, and pass the second set
  as "extra attrs" when getting the extents/rendering.
  
 Solution #1 is probably the most feasible in the short term, 
 since it could be done entirely within GtkLabel, though it 
 wouldn't be  *easy* to do so.

 What I'd do to implement #1 is first just forget about trying
 to adjust the spacing between lines to fit in underlines
 on multiline labels. This makes it just a rendering problem,
 not a layout problem. Multiline labels with underlined characters
 are going to be very rare.

 Then all you have to do is:
 
 a) Add a constant two pixels to the requisition of the label
    to put in space for the character
  
 b) Identifiy the position of the character on the screen
    by iterating through the PangoLayout and draw a line under  
    it.


Comment 6 Roozbeh Pournader 2002-08-21 00:13:05 UTC
Created attachment 10608 [details] [review]
A first patch
Comment 7 Roozbeh Pournader 2002-08-21 00:20:04 UTC
Attached a first hack to solve this. It has problems with ligatures
across boundaries, but works otherwise. It also fixes the subword
coloring bug.
Comment 8 Mohammed Elzubeir 2002-08-21 00:25:21 UTC
Finally! We've all been waiting for this ;) If it doesn't break
anything (outside of Arabic-based scripts) please please incorporate.
Translated interfaces are simply undesirable.
Comment 9 Christian Fredrik Kalager Schaller 2002-10-10 18:22:58 UTC
Roozbeh Pournader are you still working on this? I heard you and Owen
had discussing 
how the patch needed to be and you where working on an improved
version, but that seems to be a while ago? 
Comment 10 Kjartan Maraas 2002-10-27 15:09:15 UTC
Anything happening here? Should I replace the PATCH_NEEDED keyword
with PATCH?
Comment 11 Owen Taylor 2002-11-18 07:19:27 UTC
I had some time today and decided to see if I could fix
this one.

Approach I took was to add two functions:


/**
 * pango_attr_list_filter:
 * @list: a #PangoAttrList
 * @types: an array of #PangoAttrType
 * @n_types: number of elements in @type
 *
 * Given a PangoAttrList and a set of types, remove any elements
 * from @list of those types, and insert them into a new list.
 *
 * Return value: a newly allocated %PangoAttrList or %NULL if
 *  no attributes of the given types were found.
 **/
PangoAttrList *
pango_attr_list_filter (PangoAttrList *list,
                        PangoAttrType *types,
                        int            n_types);

/**
 * pango_glyph_item_apply_attrs:
 * @glyph_item: a shaped item
 * @text: text that @list applies to
 * @list: a #PangoAttrList
 *
 * Splits a shaped item (PangoGlyphItem) into multiple items based
 * on an attribute list. The idea is that if you have attributes
 * that don't affect shaping, such as color or underline, to avoid
 * affecting shaping, you filter them out (pango_attr_list_filter()),
 * apply the shaping process and then reapply them to the result using
 * this function.
 *
 * This function takes ownership of @glyph_item; it will be reused
 * as one of the elements in the list.
 *
 * Return value: a list of glyph items resulting from splitting
 *   @glyph_item. Free the elements using pango_glyph_item_free(),
 *   the list using g_slist_free().
 **/
GSList *
pango_glyph_item_apply_attrs (PangoGlyphItem   *glyph_item,
                              const char       *text,
                              PangoAttrList    *list);

So PangoLayout can remove the troublesome attributes, do it's
shaping, then add them back in.
Comment 12 Owen Taylor 2002-11-18 07:20:38 UTC
Created attachment 12366 [details]
Image of underlines not breaking Arabic text
Comment 13 Owen Taylor 2002-11-18 07:23:03 UTC
(Yes, the underlines are ugly on such large text...)

One somewhat problematical issue was what to do with "clusters"
such as the lam-alef ligature in the screenshot. What I decided
to do was to simply say that if the attribute applied to the
first character in the cluster, it applied to the entire cluster.

So, though only the lam of the lam-alef is logically underlined,
the underline extends across the entire ligature. (This is 
different than the GTK+ selection behavior where we actually
draw the selection selecting half of the ligature.)
Comment 14 Owen Taylor 2002-11-18 07:23:46 UTC
Created attachment 12367 [details]
pango-glyph-item.c [new file]
Comment 15 Owen Taylor 2002-11-18 07:24:04 UTC
Created attachment 12368 [details]
pango-glyph-item.h [new file]
Comment 16 Owen Taylor 2002-11-18 07:27:24 UTC
Created attachment 12369 [details] [review]
Remaining diffs
Comment 17 Owen Taylor 2002-11-18 07:29:44 UTC
Note that there are some references to pango-script[-table].[ch]
in the above patch that would need to be removed after applying;
they are part of another change I was working on my local tree.

The main remaining thing that needs doing here is:

 a) Test the patch a bunch in practice
 b) Think about writing some automated test cases, especially
    for pango_glyph_item_apply_attrs() which is a bit tricky.
Comment 18 Hicham Amaoui 2002-11-21 19:18:08 UTC
Just tried this patch. It works well for arabic, but it breaks latin
text. I made a screenshot here
http://amaoui.free.fr/misc/images/accels.jpeg

Tried on pango-1.1.1 that comes with RH 8.0
Comment 19 Owen Taylor 2002-11-21 20:31:38 UTC
Yeah, I fixed that after posting the patch - there is

  if (ltr)
    g_slist_reverse (result);

At the and of pango-glyph-item.c should be:

  if (ltr)
    result = g_slist_reverse (result);
Comment 20 Hicham Amaoui 2002-11-23 00:21:58 UTC
Works great now
http://amaoui.free.fr/gnome2/images/accels.png

Thanks a lot Owen
Comment 21 Owen Taylor 2002-12-03 06:31:09 UTC
Sun Nov 17 23:28:26 2002  Owen Taylor  <otaylor@redhat.com>

        * pango/pango-glyph-item.[ch] pango/pango-layout.h:
        Rename PangoLayoutRun to PangoGlyphItem (with a
        typedef for compat), add pango_glyph_item_split(),
        pango_glyph_item_apply_attrs().

        * pango/pango-attributes.[ch]: Add
        pango_attr_list_filter(), pango_attr_iterator_get_attrs().

        * pango/pango-layout.c: Remove attributes that don't
        affect shaping before shaping, shape and then add
        them back. Fixes the infamous "underscores break
        arabic shaping" bug (#83058)
Comment 22 Behdad Esfahbod 2005-07-22 19:12:31 UTC
*** Bug 157019 has been marked as a duplicate of this bug. ***