1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-05-10 06:02:10 -05:00

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.
This commit is contained in:
Ben Harris 2025-04-26 14:26:02 +01:00
parent 578ed46f34
commit 01043ce4fc
2 changed files with 6 additions and 32 deletions

View File

@ -124,7 +124,6 @@ typedef struct unifont_drawctx {
* screen number when creating server-side pixmaps */ * screen number when creating server-side pixmaps */
GtkWidget *widget; GtkWidget *widget;
cairo_t *cr; cairo_t *cr;
cairo_matrix_t origmatrix;
#if GTK_CHECK_VERSION(3,22,0) #if GTK_CHECK_VERSION(3,22,0)
GdkWindow *gdkwin; GdkWindow *gdkwin;
GdkDrawingContext *drawctx; GdkDrawingContext *drawctx;

View File

@ -918,8 +918,6 @@ static gboolean area_configured(
#ifdef DRAW_TEXT_CAIRO #ifdef DRAW_TEXT_CAIRO
static void cairo_setup_draw_ctx(GtkFrontend *inst) 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_width(inst->uctx.u.cairo.cr, 1.0);
cairo_set_line_cap(inst->uctx.u.cairo.cr, CAIRO_LINE_CAP_SQUARE); 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); 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 #ifdef DRAW_TEXT_CAIRO
if (inst->uctx.type == DRAWTYPE_CAIRO) { if (inst->uctx.type == DRAWTYPE_CAIRO) {
cairo_matrix_t matrix; cairo_save(inst->uctx.u.cairo.cr);
cairo_translate(inst->uctx.u.cairo.cr,
matrix.xy = 0; -x * wdouble, -y * hdouble - h * hbothalf);
matrix.yx = 0; cairo_scale(inst->uctx.u.cairo.cr, 1 + wdouble, 1 + hdouble);
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);
} }
#endif #endif
} }
@ -3887,10 +3864,8 @@ static void draw_stretch_after(GtkFrontend *inst, int x, int y,
#endif #endif
#endif /* DRAW_TEXT_GDK */ #endif /* DRAW_TEXT_GDK */
#ifdef DRAW_TEXT_CAIRO #ifdef DRAW_TEXT_CAIRO
if (inst->uctx.type == DRAWTYPE_CAIRO) { if (inst->uctx.type == DRAWTYPE_CAIRO)
cairo_set_matrix(inst->uctx.u.cairo.cr, cairo_restore(inst->uctx.u.cairo.cr);
&inst->uctx.u.cairo.origmatrix);
}
#endif #endif
} }