mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-04 21:12:47 -05:00
Refactor the GTK drawing system to do both GDK and Cairo.
We're going to have to use Cairo in the GTK3 port, because that's all GTK3 supports; but we still need old-style GDK for GTK1 support, and also for performance reasons in GTK2 (see below). Hence, this change completely restructures GTK PuTTY's drawing code so that there's a central 'drawing context' structure which contains a type code indicating GDK or Cairo, and then either some GDK gubbins or some Cairo gubbins as appropriate; all actual drawing is abstracted through a set of routines which test the type code in that structure and do one thing or another. And because the type code is tested at run time, both sets of drawing primitives can be compiled in at once, and where possible, they will be. X server-side bitmap fonts are still supported in the Cairo world, but because Cairo drawing is entirely client-side, they have to work by cheekily downloading each glyph bitmap from the server when it's first needed, and building up a client-side cache of 'cairo_surface_t's containing the bitmaps with which we then draw on the window. This technique works, but it's rather slow; hence, even in GTK2, we keep the GDK drawing back end compiled in, and switch over to it when the main selected font is a bitmap one. One visible effect of the new Cairo routines is in the double-width and double-height text you can get by sending ESC # 3, ESC # 4 and ESC # 6 escape sequences. In GDK, that's always been done by a really horrible process of manually scaling the bitmap, server-side, column by column and row by row, causing each pixel to be exactly doubled or quadrupled. But in Cairo, we can just set a transformation matrix, and then that takes effect _before_ the scalable fonts are rendered - so the results are visibly nicer, and use all the available resolution. (Sadly, if you're using a server-side bitmap font as your primary one, then the GDK backend will be selected for all drawing in the terminal as a whole - so in that situation, even fallback characters absent from the primary font and rendered by Pango will get the old GDK scaling treatment. It's only if your main font is scalable, so that the Cairo backend is selected, that DW/DH characters will come out looking nice.)
This commit is contained in:
@ -7,6 +7,28 @@
|
||||
#ifndef PUTTY_GTKFONT_H
|
||||
#define PUTTY_GTKFONT_H
|
||||
|
||||
/*
|
||||
* We support two entirely different drawing systems: the old
|
||||
* GDK1/GDK2 one which works on server-side X drawables, and the
|
||||
* new-style Cairo one. GTK1 only supports GDK drawing; GTK3 only
|
||||
* supports Cairo; GTK2 supports both, but deprecates GTK, so we only
|
||||
* enable it if we aren't trying on purpose to compile without the
|
||||
* deprecated functions.
|
||||
*
|
||||
* Our different font classes may prefer different drawing systems: X
|
||||
* server-side fonts are a lot faster to draw with GDK, but for
|
||||
* everything else we prefer Cairo, on general grounds of modernness
|
||||
* and also in particular because its matrix-based scaling system
|
||||
* gives much nicer results for double-width and double-height text
|
||||
* when a scalable font is in use.
|
||||
*/
|
||||
#if !GTK_CHECK_VERSION(3,0,0) && !defined GDK_DISABLE_DEPRECATED
|
||||
#define DRAW_TEXT_GDK
|
||||
#endif
|
||||
#if GTK_CHECK_VERSION(2,8,0)
|
||||
#define DRAW_TEXT_CAIRO
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Exports from gtkfont.c.
|
||||
*/
|
||||
@ -36,15 +58,67 @@ typedef struct unifont {
|
||||
* fallback font to cope with missing glyphs.
|
||||
*/
|
||||
int want_fallback;
|
||||
|
||||
/*
|
||||
* Preferred drawing API to use when this class of font is active.
|
||||
* (See the enum below, in unifont_drawctx.)
|
||||
*/
|
||||
int preferred_drawtype;
|
||||
} unifont;
|
||||
|
||||
/* A default drawtype, for the case where no font exists to make the
|
||||
* decision with. */
|
||||
#ifdef DRAW_TEXT_CAIRO
|
||||
#define DRAW_DEFAULT_CAIRO
|
||||
#define DRAWTYPE_DEFAULT DRAWTYPE_CAIRO
|
||||
#elif defined DRAW_TEXT_GDK
|
||||
#define DRAW_DEFAULT_GDK
|
||||
#define DRAWTYPE_DEFAULT DRAWTYPE_GDK
|
||||
#else
|
||||
#error No drawtype available at all
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Drawing context passed in to unifont_draw_text, which contains
|
||||
* everything required to know where and how to draw the requested
|
||||
* text.
|
||||
*/
|
||||
typedef struct unifont_drawctx {
|
||||
enum {
|
||||
#ifdef DRAW_TEXT_GDK
|
||||
DRAWTYPE_GDK,
|
||||
#endif
|
||||
#ifdef DRAW_TEXT_CAIRO
|
||||
DRAWTYPE_CAIRO,
|
||||
#endif
|
||||
DRAWTYPE_NTYPES
|
||||
} type;
|
||||
union {
|
||||
#ifdef DRAW_TEXT_GDK
|
||||
struct {
|
||||
GdkDrawable *target;
|
||||
GdkGC *gc;
|
||||
} gdk;
|
||||
#endif
|
||||
#ifdef DRAW_TEXT_CAIRO
|
||||
struct {
|
||||
/* Need an actual widget, in order to backtrack to its X
|
||||
* screen number when creating server-side pixmaps */
|
||||
GtkWidget *widget;
|
||||
cairo_t *cr;
|
||||
cairo_matrix_t origmatrix;
|
||||
} cairo;
|
||||
#endif
|
||||
} u;
|
||||
} unifont_drawctx;
|
||||
|
||||
unifont *unifont_create(GtkWidget *widget, const char *name,
|
||||
int wide, int bold,
|
||||
int shadowoffset, int shadowalways);
|
||||
void unifont_destroy(unifont *font);
|
||||
void unifont_draw_text(GdkDrawable *target, GdkGC *gc, unifont *font,
|
||||
int x, int y, const wchar_t *string, int len,
|
||||
int wide, int bold, int cellwidth);
|
||||
void unifont_draw_text(unifont_drawctx *ctx, unifont *font,
|
||||
int x, int y, const wchar_t *string, int len,
|
||||
int wide, int bold, int cellwidth);
|
||||
|
||||
/*
|
||||
* This function behaves exactly like the low-level unifont_create,
|
||||
|
Reference in New Issue
Block a user