Willow Barraco: 1 POC: Move dependency from pangocairo to cairo alone 6 files changed, 43 insertions(+), 26 deletions(-)
I'll just give another chance cause I think this is worth it. This would strip lot of dependencies. I'll see if I can solve the issues your reported.
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~mil/sxmo-devel/patches/44886/mbox | git am -3Learn more about email & git
Signed-off-by: Willow Barraco <contact@willowbarraco.fr> --- Makefile | 2 +- config.def.h | 3 ++- drw.c | 24 +++++++++++++----------- drw.h | 7 ++++--- keyboard.c | 1 + main.c | 32 ++++++++++++++++++++++---------- 6 files changed, 43 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 1d8b276..8baff48 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ BIN=${NAME}-${LAYOUT} SRC=. MAN1 = ${NAME}.1 -PKGS = wayland-client xkbcommon pangocairo +PKGS = wayland-client xkbcommon cairo WVKBD_SOURCES += $(wildcard $(SRC)/*.c) WVKBD_HEADERS += $(wildcard $(SRC)/*.h) diff --git a/config.def.h b/config.def.h index 6f73943..1e1eefa 100644 --- a/config.def.h +++ b/config.def.h @@ -1,7 +1,8 @@ #ifndef config_def_h_INCLUDED #define config_def_h_INCLUDED -static const char *default_font = "Sans 14"; +static char *default_font_family = "Sans"; +static double default_font_size = 14; static const int transparency = 255; struct clr_scheme scheme = { diff --git a/drw.c b/drw.c index 83b4db3..9a0e740 100644 --- a/drw.c +++ b/drw.c @@ -40,16 +40,17 @@ drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y, color.bgra[0] / (double)255, color.bgra[3] / (double)255); cairo_move_to(d->cairo, x + w / 2, y + h / 2); - pango_layout_set_text(d->layout, label, -1); - pango_layout_set_width(d->layout, (w - (b * 2)) * PANGO_SCALE); - pango_layout_set_height(d->layout, (h - (b * 2)) * PANGO_SCALE); + cairo_text_extents_t extents; + cairo_text_extents(d->cairo, label, &extents); - int width, height; - pango_layout_get_pixel_size(d->layout, &width, &height); + if (extents.x_bearing < 0) + cairo_rel_move_to(d->cairo, -extents.x_bearing, 0); + if (extents.y_bearing < 0) + cairo_rel_move_to(d->cairo, 0, -extents.y_bearing); - cairo_rel_move_to(d->cairo, -width / 2, -height / 2); + cairo_rel_move_to(d->cairo, -extents.width / 2, -extents.height / 2); + cairo_show_text(d->cairo, label); - pango_cairo_show_layout(d->cairo, d->layout); cairo_restore(d->cairo); } @@ -133,10 +134,11 @@ setup_buffer(struct drwsurf *drwsurf) drwsurf->cairo = cairo_create(s); cairo_scale(drwsurf->cairo, drwsurf->scale, drwsurf->scale); cairo_set_antialias(drwsurf->cairo, CAIRO_ANTIALIAS_NONE); - drwsurf->layout = pango_cairo_create_layout(drwsurf->cairo); - pango_layout_set_font_description(drwsurf->layout, - drwsurf->ctx->font_description); - pango_layout_set_auto_dir(drwsurf->layout, false); + + cairo_select_font_face(drwsurf->cairo, drwsurf->ctx->font_family, + CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size(drwsurf->cairo, drwsurf->ctx->font_size); + cairo_save(drwsurf->cairo); return 0; diff --git a/drw.h b/drw.h index 2e5c919..e245a5e 100644 --- a/drw.h +++ b/drw.h @@ -1,12 +1,14 @@ #ifndef __DRW_H #define __DRW_H -#include <pango/pangocairo.h> +#include <cairo.h> +#include <stdlib.h> #include <stdbool.h> struct drw { struct wl_shm *shm; - PangoFontDescription *font_description; + char *font_family; + double font_size; }; struct drwsurf { uint32_t width, height, size; @@ -19,7 +21,6 @@ struct drwsurf { unsigned char *pool_data; cairo_t *cairo; - PangoLayout *layout; }; struct kbd; diff --git a/keyboard.c b/keyboard.c index 9b29367..0e2411d 100644 --- a/keyboard.c +++ b/keyboard.c @@ -6,6 +6,7 @@ #include "keyboard.h" #include "drw.h" #include "os-compatibility.h" +#include <string.h> #define MAX_LAYERS 25 diff --git a/main.c b/main.c index 66ead9d..a62c05c 100644 --- a/main.c +++ b/main.c @@ -14,6 +14,8 @@ #include <wayland-client-protocol.h> #include <wayland-client.h> #include <wchar.h> +#include <errno.h> +#include <signal.h> #include "keyboard.h" #include "config.h" @@ -625,7 +627,8 @@ usage(char *argv0) " -O - Print intersected keys to standard output\n"); fprintf(stderr, " -H [int] - Height in pixels\n"); fprintf(stderr, " -L [int] - Landscape height in pixels\n"); - fprintf(stderr, " --fn [font] - Set font (e.g: DejaVu Sans 20)\n"); + fprintf(stderr, " --fn [font] - Set font name (e.g: DejaVu Sans)\n"); + fprintf(stderr, " --fs [size] - Set font size (e.g: 20)\n"); fprintf(stderr, " --hidden - Start hidden (send SIGUSR2 to show)\n"); fprintf( stderr, @@ -746,7 +749,8 @@ main(int argc, char **argv) { /* parse command line arguments */ char *layer_names_list = NULL, *landscape_layer_names_list = NULL; - const char *fc_font_pattern = NULL; + char *fc_font_family = NULL; + double fc_font_size = 0; height = normal_height = KBD_PIXEL_HEIGHT; landscape_height = KBD_PIXEL_LANDSCAPE_HEIGHT; @@ -885,7 +889,13 @@ main(int argc, char **argv) usage(argv[0]); exit(1); } - fc_font_pattern = estrdup(argv[++i]); + fc_font_family= estrdup(argv[++i]); + } else if ((!strcmp(argv[i], "-fs")) || (!strcmp(argv[i], "--fs"))) { + if (i >= argc - 1) { + usage(argv[0]); + exit(1); + } + fc_font_size= atof(argv[++i]); } else if (!strcmp(argv[i], "-o")) { keyboard.print = true; } else if (!strcmp(argv[i], "-O")) { @@ -913,9 +923,11 @@ main(int argc, char **argv) keyboard.scheme1.high.bgra[3] = alpha; } - if (!fc_font_pattern) { - fc_font_pattern = default_font; - } + if (!fc_font_family) + fc_font_family = default_font_family; + + if (!fc_font_size) + fc_font_size = default_font_size; display = wl_display_connect(NULL); if (display == NULL) { @@ -959,8 +971,8 @@ main(int argc, char **argv) kbd_init(&keyboard, (struct layout *)&layouts, layer_names_list, landscape_layer_names_list); - draw_ctx.font_description = - pango_font_description_from_string(fc_font_pattern); + draw_ctx.font_family = fc_font_family; + draw_ctx.font_size = fc_font_size; if (!hidden) show(); @@ -1014,8 +1026,8 @@ main(int argc, char **argv) } } - if (fc_font_pattern != default_font) { - free((void *)fc_font_pattern); + if (fc_font_family != default_font_family) { + free((void *)fc_font_family); } return 0; -- 2.42.0
I don't think we can do without pango, as I understand it it handles the more complex aspects of font rendering. With your patch applied I notice the following problems: * Some missing glyphs in the font * Arabic letters are no properly rendered right-to-left and they are no longer properly joined (see the index layout) * Emojis no longer render in colour, I'm getting simpler ones from the base font. I think the default fontconfig way of handling fonts is not used? Also, the --fn parameter used to allow both the fontname and the fontsize. We should retain some backward compatibility even if we introduce seperate font size (--fs) parameter. So all in all, I don't think this is worth pursuing.
Rejected!