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.
This commit is contained in:
Jehan 2022-04-26 22:57:51 +02:00
parent ba6ec46178
commit c3cc859a88
1 changed files with 10 additions and 2 deletions

View File

@ -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);
}