all repos — tint2 @ c76f0567469abd7bac9f3e6bb55b1784e75e3480

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

Fix markup drawing when font shadow enabled (fixes issue #709)
Chris Lee @klee93
commit

c76f0567469abd7bac9f3e6bb55b1784e75e3480

parent

cacd4b8dadd892226a53ef79e9034a16f85ec469

M ChangeLogChangeLog

@@ -1,6 +1,7 @@

-2018-12-26 master +2018-12-31 master - Fix spacing around icons in executor without text in vertical panels (issue #716) - Fix Bug: Clock Only Updates Every Minute With Format %s (issue #724) +- Fix markup drawing when font shadow enabled (issue #709) 2018-08-05 16.6.1 - Fix packaging regression for debian (issue #715)
M src/button/button.csrc/button/button.c

@@ -478,7 +478,7 @@ c,

button->frontend->textx, button->frontend->texty, &button->backend->font_color, - panel_config.font_shadow); + panel_config.font_shadow ? layout : NULL); g_object_unref(layout); g_object_unref(context);
M src/execplugin/execplugin.csrc/execplugin/execplugin.c

@@ -491,6 +491,18 @@ schedule_redraw(&execp->area);

return resized; } +PangoLayout *create_execp_text_layout(Execp *execp, PangoContext *context) +{ + PangoLayout *layout = pango_layout_new(context); + pango_layout_set_font_description(layout, execp->backend->font_desc); + pango_layout_set_width(layout, (execp->frontend->textw + TINT2_PANGO_SLACK) * PANGO_SCALE); + pango_layout_set_height(layout, (execp->frontend->texth + TINT2_PANGO_SLACK) * PANGO_SCALE); + pango_layout_set_alignment(layout, execp->backend->centered ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT); + pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); + pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); + return layout; +} + void draw_execp(void *obj, cairo_t *c) { Execp *execp = (Execp *)obj;

@@ -498,7 +510,8 @@ Panel *panel = (Panel *)execp->area.panel;

PangoContext *context = pango_cairo_create_context(c); pango_cairo_context_set_resolution(context, 96 * panel->scale); - PangoLayout *layout = pango_layout_new(context); + PangoLayout *layout = create_execp_text_layout(execp, context); + PangoLayout *shadow_layout = NULL; if (execp->backend->has_icon && execp->backend->icon) { imlib_context_set_image(execp->backend->icon);

@@ -507,16 +520,18 @@ render_image(execp->area.pix, execp->frontend->iconx, execp->frontend->icony);

} // draw layout - pango_layout_set_font_description(layout, execp->backend->font_desc); - pango_layout_set_width(layout, (execp->frontend->textw + TINT2_PANGO_SLACK) * PANGO_SCALE); - pango_layout_set_height(layout, (execp->frontend->texth + TINT2_PANGO_SLACK) * PANGO_SCALE); - pango_layout_set_alignment(layout, execp->backend->centered ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT); - pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); - pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); - if (!execp->backend->has_markup) + if (!execp->backend->has_markup) { pango_layout_set_text(layout, execp->backend->text, strlen(execp->backend->text)); - else + } else { pango_layout_set_markup(layout, execp->backend->text, strlen(execp->backend->text)); + if (panel_config.font_shadow) { + shadow_layout = create_execp_text_layout(execp, context); + if (!layout_set_markup_strip_colors(shadow_layout, execp->backend->text)) { + g_object_unref(shadow_layout); + shadow_layout = NULL; + } + } + } pango_cairo_update_layout(c, layout); draw_text(layout,

@@ -524,7 +539,7 @@ c,

execp->frontend->textx, execp->frontend->texty, &execp->backend->font_color, - panel_config.font_shadow); + shadow_layout); g_object_unref(layout); g_object_unref(context);
M src/taskbar/task.csrc/taskbar/task.c

@@ -497,7 +497,7 @@ pango_layout_get_pixel_size(layout, &task->_text_width, &task->_text_height);

task->_text_posy = (panel->g_task.area.height - task->_text_height) / 2.0; Color *config_text = &panel->g_task.font[task->current_state]; - draw_text(layout, c, panel->g_task.text_posx, task->_text_posy, config_text, panel->font_shadow); + draw_text(layout, c, panel->g_task.text_posx, task->_text_posy, config_text, panel->font_shadow ? layout : NULL); g_object_unref(layout); g_object_unref(context);
M src/taskbar/taskbarname.csrc/taskbar/taskbarname.c

@@ -215,7 +215,7 @@

cairo_set_source_rgba(c, config_text->rgb[0], config_text->rgb[1], config_text->rgb[2], config_text->alpha); pango_cairo_update_layout(c, layout); - draw_text(layout, c, 0, taskbar_name->posy, config_text, ((Panel *)taskbar_name->area.panel)->font_shadow); + draw_text(layout, c, 0, taskbar_name->posy, config_text, ((Panel *)taskbar_name->area.panel)->font_shadow ? layout : NULL); g_object_unref(layout); g_object_unref(context);
M src/util/area.csrc/util/area.c

@@ -1084,7 +1084,7 @@ if (line1 && line1[0]) {

pango_layout_set_font_description(layout, line1_font_desc); pango_layout_set_text(layout, line1, strlen(line1)); pango_cairo_update_layout(c, layout); - draw_text(layout, c, (area->width - inner_w) / 2, line1_posy, color, ((Panel *)area->panel)->font_shadow); + draw_text(layout, c, (area->width - inner_w) / 2, line1_posy, color, ((Panel *)area->panel)->font_shadow ? layout : NULL); } if (line2 && line2[0]) {

@@ -1092,7 +1092,7 @@ pango_layout_set_font_description(layout, line2_font_desc);

pango_layout_set_indent(layout, 0); pango_layout_set_text(layout, line2, strlen(line2)); pango_cairo_update_layout(c, layout); - draw_text(layout, c, (area->width - inner_w) / 2, line2_posy, color, ((Panel *)area->panel)->font_shadow); + draw_text(layout, c, (area->width - inner_w) / 2, line2_posy, color, ((Panel *)area->panel)->font_shadow ? layout : NULL); } g_object_unref(layout);
M src/util/common.csrc/util/common.c

@@ -724,27 +724,60 @@ XFreePixmap(server.display, mask);

XFreePixmap(server.display, pixmap); } -void draw_text(PangoLayout *layout, cairo_t *c, int posx, int posy, Color *color, int font_shadow) +gboolean is_color_attribute(PangoAttribute *attr, gpointer user_data) +{ + return attr->klass->type == PANGO_ATTR_FOREGROUND || + attr->klass->type == PANGO_ATTR_BACKGROUND || + attr->klass->type == PANGO_ATTR_UNDERLINE_COLOR || + attr->klass->type == PANGO_ATTR_STRIKETHROUGH_COLOR || + attr->klass->type == PANGO_ATTR_FOREGROUND_ALPHA || + attr->klass->type == PANGO_ATTR_BACKGROUND_ALPHA; +} + +gboolean layout_set_markup_strip_colors(PangoLayout *layout, const char *markup) +{ + PangoAttrList *attrs = NULL; + char *text = NULL; + GError *error = NULL; + if (!pango_parse_markup(markup, -1, 0, &attrs, &text, NULL, &error)) { + g_error_free(error); + return FALSE; + } + + pango_layout_set_text(layout, text, -1); + g_free(text); + + pango_attr_list_filter(attrs, is_color_attribute, NULL); + pango_layout_set_attributes(layout, attrs); + pango_attr_list_unref(attrs); + return TRUE; +} + +void draw_shadow(cairo_t *c, int posx, int posy, PangoLayout *shadow_layout) { - if (font_shadow) { - const int shadow_size = 3; - const double shadow_edge_alpha = 0.0; - int i, j; - for (i = -shadow_size; i <= shadow_size; i++) { - for (j = -shadow_size; j <= shadow_size; j++) { - cairo_set_source_rgba(c, - 0.0, - 0.0, - 0.0, - 1.0 - - (1.0 - shadow_edge_alpha) * - sqrt((i * i + j * j) / (double)(shadow_size * shadow_size))); - pango_cairo_update_layout(c, layout); - cairo_move_to(c, posx + i, posy + j); - pango_cairo_show_layout(c, layout); - } + const int shadow_size = 3; + const double shadow_edge_alpha = 0.0; + int i, j; + for (i = -shadow_size; i <= shadow_size; i++) { + for (j = -shadow_size; j <= shadow_size; j++) { + cairo_set_source_rgba(c, + 0.0, + 0.0, + 0.0, + 1.0 - + (1.0 - shadow_edge_alpha) * + sqrt((i * i + j * j) / (double)(shadow_size * shadow_size))); + pango_cairo_update_layout(c, shadow_layout); + cairo_move_to(c, posx + i, posy + j); + pango_cairo_show_layout(c, shadow_layout); } } +} + +void draw_text(PangoLayout *layout, cairo_t *c, int posx, int posy, Color *color, PangoLayout *shadow_layout) +{ + if (shadow_layout) + draw_shadow(c, posx, posy, shadow_layout); cairo_set_source_rgba(c, color->rgb[0], color->rgb[1], color->rgb[2], color->alpha); pango_cairo_update_layout(c, layout); cairo_move_to(c, posx, posy);
M src/util/common.hsrc/util/common.h

@@ -126,7 +126,8 @@ PangoAlignment alignment,

gboolean markup, double scale); -void draw_text(PangoLayout *layout, cairo_t *c, int posx, int posy, Color *color, int font_shadow); +gboolean layout_set_markup_strip_colors(PangoLayout *layout, const char *markup); +void draw_text(PangoLayout *layout, cairo_t *c, int posx, int posy, Color *color, PangoLayout *shadow_layout); // Draws a rounded rectangle void draw_rect(cairo_t *c, double x, double y, double w, double h, double r);