Control: retitle 994092 gkbd-capplet: keyboard layout display garbled for RTL (e.g., Hebrew and Arabic) layouts Control: forwarded 994092 https://gitlab.gnome.org/GNOME/libgnomekbd/-/issues/8 Control: tags 994092 + patch
On Sat 2021-09-11 16:01:58 +0100, Toni Mueller wrote: > I have added Hebrew keyboard layouts and then tried to see the layout > via gkbd-keyboard-display. For Hebrew layouts - I tried 'Hebrew' and > 'Hebrew (Bibilical)', the display is a bit garbled, showing dotted > circles instead of the glyphs, although I have installed every font > containing Hebrew that I could find, using 'apt'. Using the Hebrew > script in eg. LibreOffice Writer is perfectly possible, it's just this > program that does not tell me what the keyboard layout actually is. I ran into the same problem with Arabic layouts. I reported it upstream at the URL above, and the attached patch (also forwarded upstream at https://gitlab.gnome.org/GNOME/libgnomekbd/-/merge_requests/9) solves the problem. --dkg
diff --git a/libgnomekbd/gkbd-keyboard-drawing.c b/libgnomekbd/gkbd-keyboard-drawing.c index da526d2..b5888ee 100644 --- a/libgnomekbd/gkbd-keyboard-drawing.c +++ b/libgnomekbd/gkbd-keyboard-drawing.c @@ -666,12 +666,13 @@ set_markup (GkbdKeyboardDrawingRenderContext * context, gchar * txt) } } -static void +static PangoDirection set_key_label_in_layout (GkbdKeyboardDrawingRenderContext * context, guint keyval) { gchar buf[5]; gunichar uc; + PangoDirection dir = PANGO_DIRECTION_LTR; switch (keyval) { case GDK_KEY_Scroll_Lock: @@ -825,6 +826,7 @@ set_key_label_in_layout (GkbdKeyboardDrawingRenderContext * context, default: uc = gdk_keyval_to_unicode (keyval); if (uc != 0 && g_unichar_isgraph (uc)) { + dir = pango_unichar_direction (uc); buf[g_unichar_to_utf8 (uc, buf)] = '\0'; set_markup (context, buf); } else { @@ -846,6 +848,7 @@ set_key_label_in_layout (GkbdKeyboardDrawingRenderContext * context, set_markup (context, ""); } } + return dir; } @@ -927,6 +930,8 @@ draw_key_label_helper (GkbdKeyboardDrawingRenderContext * context, gboolean is_pressed) { gint label_x, label_y, label_max_width, ycell; + PangoAlignment align; + PangoDirection dir; if (keysym == 0) return; @@ -935,46 +940,36 @@ draw_key_label_helper (GkbdKeyboardDrawingRenderContext * context, (unsigned) keysym, (char) keysym, (int) glp); #endif + ycell = ((glp == GKBD_KEYBOARD_DRAWING_POS_BOTTOMLEFT) || + (glp == GKBD_KEYBOARD_DRAWING_POS_BOTTOMRIGHT)); + rotate_coordinate (x, y, x + padding, + y + padding + (height - + 2 * padding) * + ycell * 4 / 7, angle, &label_x, + &label_y); + label_max_width = PANGO_SCALE * (width - 2 * padding); + dir = set_key_label_in_layout (context, keysym); + switch (glp) { case GKBD_KEYBOARD_DRAWING_POS_TOPLEFT: case GKBD_KEYBOARD_DRAWING_POS_BOTTOMLEFT: - { - ycell = - glp == GKBD_KEYBOARD_DRAWING_POS_BOTTOMLEFT; - - rotate_coordinate (x, y, x + padding, - y + padding + (height - - 2 * padding) * - ycell * 4 / 7, angle, &label_x, - &label_y); - label_max_width = - PANGO_SCALE * (width - 2 * padding); - break; - } + if (dir == PANGO_DIRECTION_RTL) + align = PANGO_ALIGN_RIGHT; + else + align = PANGO_ALIGN_LEFT; + break; case GKBD_KEYBOARD_DRAWING_POS_TOPRIGHT: case GKBD_KEYBOARD_DRAWING_POS_BOTTOMRIGHT: - { - ycell = - glp == GKBD_KEYBOARD_DRAWING_POS_BOTTOMRIGHT; - - rotate_coordinate (x, y, - x + padding + (width - - 2 * padding) * - 4 / 7, - y + padding + (height - - 2 * padding) * - ycell * 4 / 7, angle, &label_x, - &label_y); - label_max_width = - PANGO_SCALE * ((width - 2 * padding) - - (width - 2 * padding) * 4 / 7); - break; - } + if (dir == PANGO_DIRECTION_RTL) + align = PANGO_ALIGN_LEFT; + else + align = PANGO_ALIGN_RIGHT; + break; default: return; } - set_key_label_in_layout (context, keysym); pango_layout_set_width (context->layout, label_max_width); + pango_layout_set_alignment (context->layout, align); label_y -= (pango_layout_get_line_count (context->layout) - 1) * (pango_font_description_get_size (context->font_desc) / PANGO_SCALE);
signature.asc
Description: PGP signature