[libgnomekbd] Invert alignment for RTL symbols to place them correctly



commit efd617958e26849ee2c518159f875a7f493f8b24
Author: Daniel Kahn Gillmor <dkg fifthhorseman net>
Date:   Sat Jan 8 11:49:17 2022 -0500

    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

 libgnomekbd/gkbd-keyboard-drawing.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
---
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) *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]