summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>2022-01-08 11:49:17 -0500
committerCorentin Noël <tintou@noel.tf>2022-06-22 07:22:17 +0000
commitefd617958e26849ee2c518159f875a7f493f8b24 (patch)
treeea0cfe4b2f7ac8de82c771e2e89c268bfcd01d56
parentaee49af900b2df48a95dcd7dc8c5dffcbc90d059 (diff)
downloadlibgnomekbd-efd617958e26849ee2c518159f875a7f493f8b24.tar.gz
Invert alignment for RTL symbols to place them correctly
https://docs.gtk.org/Pango/method.Layout.set_auto_dir.html says: > When the auto-computed direction of a paragraph differs from the > base direction of the context, the interpretation of > PANGO_ALIGN_LEFT and PANGO_ALIGN_RIGHT are swapped. Now that symbols are placed based using alignment, we don't want RTL symbols placed on the wrong side of the key rendering. To do this, we invert the alignment for RTL symbols. Closes: #8
-rw-r--r--libgnomekbd/gkbd-keyboard-drawing.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/libgnomekbd/gkbd-keyboard-drawing.c b/libgnomekbd/gkbd-keyboard-drawing.c
index 199199b..932644a 100644
--- a/libgnomekbd/gkbd-keyboard-drawing.c
+++ b/libgnomekbd/gkbd-keyboard-drawing.c
@@ -931,6 +931,7 @@ draw_key_label_helper (GkbdKeyboardDrawingRenderContext * context,
{
gint label_x, label_y, label_max_width, ycell;
PangoAlignment align;
+ PangoDirection dir;
if (keysym == 0)
return;
@@ -947,20 +948,26 @@ draw_key_label_helper (GkbdKeyboardDrawingRenderContext * context,
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:
+ 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:
+ 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) *