From 83a32e9b4cb5d4cf15769f2a397bdb464b84000d Mon Sep 17 00:00:00 2001 From: v44r Date: Mon, 28 Jan 2019 13:14:44 +0100 Subject: Fix vertical alignment of text. --- lib/renderers/cairo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/renderers/cairo.h b/lib/renderers/cairo.h index 307b9c2..d0f2dca 100644 --- a/lib/renderers/cairo.h +++ b/lib/renderers/cairo.h @@ -140,13 +140,13 @@ bm_cairo_draw_line(struct cairo *cairo, struct cairo_paint *paint, struct cairo_ cairo_fill(cairo->cr); cairo_set_source_rgba(cairo->cr, paint->fg.r, paint->fg.b, paint->fg.g, paint->fg.a); - cairo_move_to(cairo->cr, paint->box.lx + paint->pos.x, paint->pos.y + paint->box.ty); + cairo_move_to(cairo->cr, paint->box.lx + paint->pos.x, paint->pos.y); pango_cairo_show_layout(cairo->cr, layout); g_object_unref(layout); result->x_advance = width + paint->box.rx; - result->height = height + paint->box.by; + result->height = height + paint->box.by + paint->box.ty; return true; } -- cgit v1.2.3-70-g09d2 From 6e34c3a9235fe7564b3c18c9e01ecae5e84a56b7 Mon Sep 17 00:00:00 2001 From: v44r Date: Mon, 28 Jan 2019 14:53:16 +0100 Subject: Fix extra space below last item in vertical mode. --- lib/renderers/cairo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/renderers/cairo.h b/lib/renderers/cairo.h index d0f2dca..4bea81c 100644 --- a/lib/renderers/cairo.h +++ b/lib/renderers/cairo.h @@ -246,7 +246,7 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma } posy += (spacing_y ? spacing_y : result.height); - out_result->height = posy + 2; + out_result->height = posy; out_result->displayed++; } -- cgit v1.2.3-70-g09d2 From d3c43973c8fe04e625b1ae62696954d3abb65699 Mon Sep 17 00:00:00 2001 From: v44r Date: Tue, 29 Jan 2019 18:16:37 +0100 Subject: Limit line height to that of ASCII chars --- lib/renderers/cairo.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/renderers/cairo.h b/lib/renderers/cairo.h index 4bea81c..a299bc5 100644 --- a/lib/renderers/cairo.h +++ b/lib/renderers/cairo.h @@ -103,7 +103,7 @@ bm_pango_get_text_extents(struct cairo *cairo, struct cairo_paint *paint, struct PangoRectangle rect; PangoLayout *layout = bm_pango_get_layout(cairo, paint, buffer); - pango_layout_get_pixel_extents(layout, &rect, NULL); + pango_layout_get_pixel_extents(layout, NULL, &rect); g_object_unref(layout); result->x_advance = rect.x + rect.width; @@ -130,13 +130,13 @@ bm_cairo_draw_line(struct cairo *cairo, struct cairo_paint *paint, struct cairo_ int width, height; pango_layout_get_pixel_size(layout, &width, &height); - int base = pango_layout_get_baseline(layout) / PANGO_SCALE; + height = paint->box.h > 0 ? paint->box.h : height; cairo_set_source_rgba(cairo->cr, paint->bg.r, paint->bg.b, paint->bg.g, paint->bg.a); cairo_rectangle(cairo->cr, paint->pos.x - paint->box.lx, paint->pos.y - paint->box.ty, (paint->box.w > 0 ? paint->box.w : width) + paint->box.rx + paint->box.lx, - (paint->box.h > 0 ? paint->box.h : height) + paint->box.by + paint->box.ty); + height + paint->box.by + paint->box.ty); cairo_fill(cairo->cr); cairo_set_source_rgba(cairo->cr, paint->fg.r, paint->fg.b, paint->fg.g, paint->fg.a); @@ -178,13 +178,18 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma struct cairo_result result; memset(&result, 0, sizeof(result)); + int ascii_height; + bm_pango_get_text_extents(cairo, &paint, &result, "!\"#$%%&'()*+,-./0123456789:;<=>?@ABCD" + "EFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"); + ascii_height = result.height; + memset(&result, 0, sizeof(result)); uint32_t title_x = 0; if (menu->title) { bm_cairo_color_from_menu_color(menu, BM_COLOR_TITLE_FG, &paint.fg); bm_cairo_color_from_menu_color(menu, BM_COLOR_TITLE_BG, &paint.bg); paint.pos = (struct pos){ result.x_advance, 2 }; - paint.box = (struct box){ 4, 8, 2, 2, 0, 0 }; + paint.box = (struct box){ 4, 8, 2, 2, 0, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, "%s", menu->title); title_x = result.x_advance; } @@ -192,7 +197,7 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_FG, &paint.fg); bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_BG, &paint.bg); paint.pos = (struct pos){ (menu->title ? 2 : 0) + result.x_advance, 2 }; - paint.box = (struct box){ (menu->title ? 2 : 4), 0, 2, 2, width - paint.pos.x, 0 }; + paint.box = (struct box){ (menu->title ? 2 : 4), 0, 2, 2, width - paint.pos.x, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, "%s", (menu->filter ? menu->filter : "")); const uint32_t titleh = result.height; out_result->height = titleh; @@ -237,11 +242,11 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma if (menu->prefix && highlighted) { paint.pos = (struct pos){ 0, 2 + posy }; - paint.box = (struct box){ 4 + spacing_x, 0, 2, 2, width - paint.pos.x, 0 }; + paint.box = (struct box){ 4 + spacing_x, 0, 2, 2, width - paint.pos.x, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, "%s %s", menu->prefix, (items[i]->text ? items[i]->text : "")); } else { paint.pos = (struct pos){ 0, 2 + posy }; - paint.box = (struct box){ 4 + spacing_x + prefix_x, 0, 2, 2, width - paint.pos.x, 0 }; + paint.box = (struct box){ 4 + spacing_x + prefix_x, 0, 2, 2, width - paint.pos.x, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, "%s", (items[i]->text ? items[i]->text : "")); } @@ -273,7 +278,7 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma if (menu->wrap || menu->index > 0) { paint.pos = (struct pos){ cl, 2 }; - paint.box = (struct box){ 1, 2, 2, 2, 0, 0 }; + paint.box = (struct box){ 1, 2, 2, 2, 0, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, "<"); cl += result.x_advance + 1; } @@ -293,7 +298,7 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma } paint.pos = (struct pos){ cl, 2 }; - paint.box = (struct box){ 2, 4, 2, 2, 0, 0 }; + paint.box = (struct box){ 2, 4, 2, 2, 0, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, "%s", (items[i]->text ? items[i]->text : "")); cl += result.x_advance + 2; out_result->displayed += (cl < width); @@ -305,7 +310,7 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_BG, &paint.bg); bm_pango_get_text_extents(cairo, &paint, &result, ">"); paint.pos = (struct pos){ width - result.x_advance - 2, 2 }; - paint.box = (struct box){ 1, 2, 2, 2, 0, 0 }; + paint.box = (struct box){ 1, 2, 2, 2, 0, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, ">"); } } -- cgit v1.2.3-70-g09d2 From 3916772cec1942b884516fc9293fd2b6927a1a38 Mon Sep 17 00:00:00 2001 From: v44r Date: Tue, 29 Jan 2019 19:30:45 +0100 Subject: Fix baseline when mixing ASCII and CJK characters --- lib/renderers/cairo.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/renderers/cairo.h b/lib/renderers/cairo.h index a299bc5..cdb477d 100644 --- a/lib/renderers/cairo.h +++ b/lib/renderers/cairo.h @@ -22,6 +22,7 @@ struct cairo_paint { struct cairo_color fg; struct cairo_color bg; const char *font; + int32_t baseline; struct box { int32_t lx, rx; // left/right offset (pos.x - lx, box.w + rx) @@ -37,6 +38,7 @@ struct cairo_paint { struct cairo_result { uint32_t x_advance; uint32_t height; + uint32_t baseline; }; struct cairo_paint_result { @@ -104,10 +106,12 @@ bm_pango_get_text_extents(struct cairo *cairo, struct cairo_paint *paint, struct PangoRectangle rect; PangoLayout *layout = bm_pango_get_layout(cairo, paint, buffer); pango_layout_get_pixel_extents(layout, NULL, &rect); + int baseline = pango_layout_get_baseline(layout) / PANGO_SCALE; g_object_unref(layout); result->x_advance = rect.x + rect.width; result->height = rect.height; + result->baseline = baseline; return true; } @@ -131,6 +135,7 @@ bm_cairo_draw_line(struct cairo *cairo, struct cairo_paint *paint, struct cairo_ int width, height; pango_layout_get_pixel_size(layout, &width, &height); height = paint->box.h > 0 ? paint->box.h : height; + int base = pango_layout_get_baseline(layout) / PANGO_SCALE; cairo_set_source_rgba(cairo->cr, paint->bg.r, paint->bg.b, paint->bg.g, paint->bg.a); cairo_rectangle(cairo->cr, @@ -140,7 +145,7 @@ bm_cairo_draw_line(struct cairo *cairo, struct cairo_paint *paint, struct cairo_ cairo_fill(cairo->cr); cairo_set_source_rgba(cairo->cr, paint->fg.r, paint->fg.b, paint->fg.g, paint->fg.a); - cairo_move_to(cairo->cr, paint->box.lx + paint->pos.x, paint->pos.y); + cairo_move_to(cairo->cr, paint->box.lx + paint->pos.x, paint->pos.y - base + paint->baseline); pango_cairo_show_layout(cairo->cr, layout); g_object_unref(layout); @@ -182,6 +187,7 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma bm_pango_get_text_extents(cairo, &paint, &result, "!\"#$%%&'()*+,-./0123456789:;<=>?@ABCD" "EFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"); ascii_height = result.height; + paint.baseline = result.baseline; memset(&result, 0, sizeof(result)); uint32_t title_x = 0; -- cgit v1.2.3-70-g09d2