From 01043ce4fc90cee578a00872a64fd69e4bb7203a Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sat, 26 Apr 2025 14:26:02 +0100 Subject: [PATCH] GTK: simpler text scaling under Cairo Rather than constructing a transformation matrix piece by piece (with very branchy code), draw_stretch_before now just calls cairo_translate() and cairo_scale() with values that are almost-obviously correct. Also, rather than stashing and restoring the transformation matrix ourselves, it seems simpler to use cairo_save() and cairo_restore(). That requires that draw_stretch_before() and draw_stretch_after() be called strictly in pairs, but they are so that's OK. --- unix/unifont.h | 1 - unix/window.c | 37 ++++++------------------------------- 2 files changed, 6 insertions(+), 32 deletions(-) diff --git a/unix/unifont.h b/unix/unifont.h index c0f01121..6e22c257 100644 --- a/unix/unifont.h +++ b/unix/unifont.h @@ -124,7 +124,6 @@ typedef struct unifont_drawctx { * screen number when creating server-side pixmaps */ GtkWidget *widget; cairo_t *cr; - cairo_matrix_t origmatrix; #if GTK_CHECK_VERSION(3,22,0) GdkWindow *gdkwin; GdkDrawingContext *drawctx; diff --git a/unix/window.c b/unix/window.c index 6029a9f4..66da32fa 100644 --- a/unix/window.c +++ b/unix/window.c @@ -918,8 +918,6 @@ static gboolean area_configured( #ifdef DRAW_TEXT_CAIRO static void cairo_setup_draw_ctx(GtkFrontend *inst) { - cairo_get_matrix(inst->uctx.u.cairo.cr, - &inst->uctx.u.cairo.origmatrix); cairo_set_line_width(inst->uctx.u.cairo.cr, 1.0); cairo_set_line_cap(inst->uctx.u.cairo.cr, CAIRO_LINE_CAP_SQUARE); cairo_set_line_join(inst->uctx.u.cairo.cr, CAIRO_LINE_JOIN_MITER); @@ -3808,31 +3806,10 @@ static void draw_stretch_before(GtkFrontend *inst, int x, int y, { #ifdef DRAW_TEXT_CAIRO if (inst->uctx.type == DRAWTYPE_CAIRO) { - cairo_matrix_t matrix; - - matrix.xy = 0; - matrix.yx = 0; - - if (wdouble) { - matrix.xx = 2; - matrix.x0 = -x; - } else { - matrix.xx = 1; - matrix.x0 = 0; - } - - if (hdouble) { - matrix.yy = 2; - if (hbothalf) { - matrix.y0 = -(y+h); - } else { - matrix.y0 = -y; - } - } else { - matrix.yy = 1; - matrix.y0 = 0; - } - cairo_transform(inst->uctx.u.cairo.cr, &matrix); + cairo_save(inst->uctx.u.cairo.cr); + cairo_translate(inst->uctx.u.cairo.cr, + -x * wdouble, -y * hdouble - h * hbothalf); + cairo_scale(inst->uctx.u.cairo.cr, 1 + wdouble, 1 + hdouble); } #endif } @@ -3887,10 +3864,8 @@ static void draw_stretch_after(GtkFrontend *inst, int x, int y, #endif #endif /* DRAW_TEXT_GDK */ #ifdef DRAW_TEXT_CAIRO - if (inst->uctx.type == DRAWTYPE_CAIRO) { - cairo_set_matrix(inst->uctx.u.cairo.cr, - &inst->uctx.u.cairo.origmatrix); - } + if (inst->uctx.type == DRAWTYPE_CAIRO) + cairo_restore(inst->uctx.u.cairo.cr); #endif }