[gimp] libgimpwidgets: fix label vertical alignment of GimpSpinScale.



commit c3cc859a886a0c54539dffdc7cb5fc0ab332b0d7
Author: Jehan <jehan girinstud io>
Date:   Tue Apr 26 22:57:51 2022 +0200

    libgimpwidgets: fix label vertical alignment of GimpSpinScale.
    
    Let's not try to align anymore the label text with the value (numbers
    inside the GtkEntry) text. Our previous offset computation was wrong
    anyway, but even correctly aligning the text, there could be cases where
    the label's actual font was bigger than the number's font.
    
    I had the case with GIMP set in Korean. The number text was 11-pixel
    high but the Hangul text on 16 pixels in plug-ins using a GimpSpinScale,
    most likely because the font used for numbers didn't have Hangul glyphs.
    So we ended up with very ugly scale title on the bottom of the widget,
    even out of the progress area. Instead, we just make sure that the label
    is exactly in the vertical middle of the widget, disregarding the entry
    layout's offset.

 libgimpwidgets/gimpspinscale.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/libgimpwidgets/gimpspinscale.c b/libgimpwidgets/gimpspinscale.c
index f296e6fb2b..99c61902a7 100644
--- a/libgimpwidgets/gimpspinscale.c
+++ b/libgimpwidgets/gimpspinscale.c
@@ -462,7 +462,14 @@ gimp_spin_scale_draw (GtkWidget *widget,
       cairo_clip (cr);
       cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
 
-      cairo_move_to (cr, layout_offset_x, text_area.y + layout_offset_y);
+      /* Center the label on the widget text area. Do not necessarily
+       * try to align the label with the number characters in the entry
+       * layout, because the size might actually be different, in
+       * particular when the label's actual font ends up different
+       * (typically when displaying non-Western languages).
+       */
+      cairo_move_to (cr, layout_offset_x,
+                     text_area.y - ink.y + text_area.height / 2 - ink.height / 2);
       gdk_cairo_set_source_rgba (cr, &text_color);
       pango_cairo_show_layout (cr, private->layout);
 
@@ -472,7 +479,8 @@ gimp_spin_scale_draw (GtkWidget *widget,
                        progress_width, progress_height);
       cairo_clip (cr);
 
-      cairo_move_to (cr, layout_offset_x, text_area.y + layout_offset_y);
+      cairo_move_to (cr, layout_offset_x,
+                     text_area.y - ink.y + text_area.height / 2 - ink.height / 2);
       gdk_cairo_set_source_rgba (cr, &bar_text_color);
       pango_cairo_show_layout (cr, private->layout);
     }


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