diff --git a/.build.yml b/.build.yml index c68821c..5950b6b 100644 --- a/.build.yml +++ b/.build.yml @@ -4,6 +4,7 @@ packages: - wayland - wayland-protocols - cairo + - pango - libxkbcommon sources: - https://github.com/emerison/slurp diff --git a/meson.build b/meson.build index 6b28156..1bef39a 100644 --- a/meson.build +++ b/meson.build @@ -12,6 +12,7 @@ add_project_arguments('-Wno-unused-parameter', language: 'c') cc = meson.get_compiler('c') cairo = dependency('cairo') +pangocairo = dependency('pangocairo') realtime = cc.find_library('rt') wayland_client = dependency('wayland-client') wayland_cursor = dependency('wayland-cursor') @@ -30,6 +31,7 @@ executable( ], dependencies: [ cairo, + pangocairo, realtime, wayland_client, wayland_cursor, diff --git a/render.c b/render.c index d91f8a3..062c228 100644 --- a/render.c +++ b/render.c @@ -1,6 +1,6 @@ #include +#include #include -#include #include "pool-buffer.h" #include "render.h" @@ -71,18 +71,23 @@ void render(struct slurp_output *output) { cairo_stroke(cairo); if (state->display_dimensions) { - cairo_select_font_face(cairo, state->font_family, - CAIRO_FONT_SLANT_NORMAL, - CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size(cairo, 14); set_source_u32(cairo, state->colors.border); // buffer of 12 can hold selections up to 99999x99999 char dimensions[12]; - snprintf(dimensions, sizeof(dimensions), "%ix%i", - b.width, b.height); - cairo_move_to(cairo, b.x + b.width + 10, - b.y + b.height + 20); - cairo_show_text(cairo, dimensions); + snprintf(dimensions, sizeof(dimensions), "%ix%i", b.width, b.height); + + PangoLayout *layout = pango_cairo_create_layout (cairo); + PangoFontDescription *desc = pango_font_description_new(); + pango_font_description_set_family_static(desc, state->font_family); + pango_font_description_set_size(desc, 11 * PANGO_SCALE); + pango_font_description_set_style(desc, PANGO_STYLE_NORMAL); + pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL); + pango_layout_set_font_description (layout, desc); + pango_font_description_free (desc); + + cairo_move_to(cairo, b.x + b.width + 12, b.y + b.height + 8); + pango_layout_set_text (layout, dimensions, -1); + pango_cairo_show_layout (cairo, layout); } } }