From 03675b152d558387079dc1bc8666eb5c924d5b22 Mon Sep 17 00:00:00 2001 From: o9000 Date: Sat, 20 Jan 2018 08:56:58 +0000 Subject: [PATCH] Match perfectly text layout and drawing parameters #693 --- src/button/button.c | 3 +++ src/execplugin/execplugin.c | 1 + src/taskbar/taskbar.c | 1 + src/taskbar/taskbarname.c | 2 ++ src/util/area.c | 2 ++ src/util/common.c | 19 ++++++++++++------- src/util/common.h | 1 + 7 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/button/button.c b/src/button/button.c index 059b060..7e1dc59 100644 --- a/src/button/button.c +++ b/src/button/button.c @@ -299,6 +299,7 @@ int button_compute_desired_size(void *obj) strlen(button->backend->text), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, + button->backend->centered ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT, FALSE, panel->scale); } else { @@ -312,6 +313,7 @@ int button_compute_desired_size(void *obj) strlen(button->backend->text), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, + button->backend->centered ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT, FALSE, panel->scale); } @@ -380,6 +382,7 @@ gboolean resize_button(void *obj) strlen(button->backend->text), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, + button->backend->centered ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT, FALSE, panel->scale); } else { diff --git a/src/execplugin/execplugin.c b/src/execplugin/execplugin.c index 5e9b252..c52c8b5 100644 --- a/src/execplugin/execplugin.c +++ b/src/execplugin/execplugin.c @@ -349,6 +349,7 @@ void execp_compute_icon_text_geometry(Execp *execp, strlen(execp->backend->text), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, + execp->backend->centered ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT, execp->backend->has_markup, panel->scale); diff --git a/src/taskbar/taskbar.c b/src/taskbar/taskbar.c index 78eb268..362b686 100644 --- a/src/taskbar/taskbar.c +++ b/src/taskbar/taskbar.c @@ -343,6 +343,7 @@ void init_taskbar_panel(void *p) 5, PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_END, + panel->g_task.centered ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT, FALSE, panel->scale); diff --git a/src/taskbar/taskbarname.c b/src/taskbar/taskbarname.c index c351b1a..dc95d85 100644 --- a/src/taskbar/taskbarname.c +++ b/src/taskbar/taskbarname.c @@ -144,6 +144,7 @@ int taskbarname_compute_desired_size(void *obj) strlen(taskbar_name->name), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, + PANGO_ALIGN_CENTER, FALSE, panel->scale); @@ -171,6 +172,7 @@ gboolean resize_taskbarname(void *obj) strlen(taskbar_name->name), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, + PANGO_ALIGN_CENTER, FALSE, panel->scale); diff --git a/src/util/area.c b/src/util/area.c index dbcbc1f..61dc4c8 100644 --- a/src/util/area.c +++ b/src/util/area.c @@ -947,6 +947,7 @@ void area_compute_text_geometry(Area *area, strlen(line1), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, + PANGO_ALIGN_CENTER, FALSE, ((Panel*)area->panel)->scale); else @@ -962,6 +963,7 @@ void area_compute_text_geometry(Area *area, strlen(line2), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, + PANGO_ALIGN_CENTER, FALSE, ((Panel*)area->panel)->scale); else diff --git a/src/util/common.c b/src/util/common.c index 37e361c..5116aa3 100644 --- a/src/util/common.c +++ b/src/util/common.c @@ -933,6 +933,7 @@ void get_text_size(const PangoFontDescription *font, int text_len, PangoWrapMode wrap, PangoEllipsizeMode ellipsis, + PangoAlignment alignment, gboolean markup, double scale) { @@ -951,6 +952,7 @@ void get_text_size(const PangoFontDescription *font, PangoLayout *layout = pango_layout_new(context); pango_layout_set_width(layout, available_width * PANGO_SCALE); pango_layout_set_height(layout, available_height * PANGO_SCALE); + pango_layout_set_alignment(layout, alignment); pango_layout_set_wrap(layout, wrap); pango_layout_set_ellipsize(layout, ellipsis); pango_layout_set_font_description(layout, font); @@ -982,38 +984,41 @@ void get_text_size2(const PangoFontDescription *font, int text_len, PangoWrapMode wrap, PangoEllipsizeMode ellipsis, + PangoAlignment alignment, gboolean markup, double scale) { - get_text_size(font, height, width, available_height, available_width, text, text_len, wrap, ellipsis, markup, scale); + get_text_size(font, height, width, available_height, available_width, text, text_len, wrap, ellipsis, alignment, markup, scale); // We do multiple passes, because pango sucks int actual_height, actual_width, overflow = 0; while (true) { - get_text_size(font, &actual_height, &actual_width, *height, *width, text, text_len, wrap, ellipsis, markup, scale); + get_text_size(font, &actual_height, &actual_width, *height, *width, text, text_len, wrap, ellipsis, alignment, markup, scale); if (actual_height <= *height) break; - if (*width >= available_width + 50) + if (*width >= available_width) break; overflow = 1; - fprintf(stderr, "tint2: text overflows, recomputing: available %dx%d, computed %dx%d, actual %dx%d\n", + fprintf(stderr, "tint2: text overflows, recomputing: available %dx%d, computed %dx%d, actual %dx%d: %s\n", available_width, available_height, *width, *height, actual_width, - actual_height); + actual_height, + text); (*width)++; } if (overflow) { *height = actual_height; - fprintf(stderr, "tint2: text final size computed as: available %dx%d, computed %dx%d, actual %dx%d\n", + fprintf(stderr, "tint2: text final size computed as: available %dx%d, computed %dx%d, actual %dx%d: %s\n", available_width, available_height, *width, *height, actual_width, - actual_height); + actual_height, + text); } } diff --git a/src/util/common.h b/src/util/common.h index a06fcd6..a9454b6 100644 --- a/src/util/common.h +++ b/src/util/common.h @@ -122,6 +122,7 @@ void get_text_size2(const PangoFontDescription *font, int text_len, PangoWrapMode wrap, PangoEllipsizeMode ellipsis, + PangoAlignment alignment, gboolean markup, double scale);