2 * Header file for gtkfont.c. Has to be separate from unix.h
3 * because it depends on GTK data types, hence can't be included
4 * from cross-platform code (which doesn't go near GTK).
7 #ifndef PUTTY_GTKFONT_H
8 #define PUTTY_GTKFONT_H
11 * We support two entirely different drawing systems: the old
12 * GDK1/GDK2 one which works on server-side X drawables, and the
13 * new-style Cairo one. GTK1 only supports GDK drawing; GTK3 only
14 * supports Cairo; GTK2 supports both, but deprecates GTK, so we only
15 * enable it if we aren't trying on purpose to compile without the
16 * deprecated functions.
18 * Our different font classes may prefer different drawing systems: X
19 * server-side fonts are a lot faster to draw with GDK, but for
20 * everything else we prefer Cairo, on general grounds of modernness
21 * and also in particular because its matrix-based scaling system
22 * gives much nicer results for double-width and double-height text
23 * when a scalable font is in use.
25 #if !GTK_CHECK_VERSION(3,0,0) && !defined GDK_DISABLE_DEPRECATED
28 #if GTK_CHECK_VERSION(2,8,0)
29 #define DRAW_TEXT_CAIRO
32 #if GTK_CHECK_VERSION(3,0,0) || defined GDK_DISABLE_DEPRECATED
34 * Where the facility is available, we prefer to render text on to a
35 * persistent server-side pixmap, and redraw windows by simply
36 * blitting rectangles of that pixmap into them as needed. This is
37 * better for performance since we avoid expensive font rendering
38 * calls where possible, and it's particularly good over a non-local X
39 * connection because the response to an expose event can now be a
40 * very simple rectangle-copy operation rather than a lot of fiddly
41 * drawing or bitmap transfer.
43 * However, GTK is deprecating the use of server-side pixmaps, so we
44 * have to disable this mode under some circumstances.
46 #define NO_BACKING_PIXMAPS
50 * Exports from gtkfont.c.
52 struct unifont_vtable; /* contents internal to gtkfont.c */
53 typedef struct unifont {
54 const struct unifont_vtable *vt;
56 * `Non-static data members' of the `class', accessible to
61 * public_charset is the charset used when the user asks for
62 * `Use font encoding'.
67 * Font dimensions needed by clients.
69 int width, height, ascent, descent;
72 * Indicates whether this font is capable of handling all glyphs
73 * (Pango fonts can do this because Pango automatically supplies
74 * missing glyphs from other fonts), or whether it would like a
75 * fallback font to cope with missing glyphs.
80 * Preferred drawing API to use when this class of font is active.
81 * (See the enum below, in unifont_drawctx.)
83 int preferred_drawtype;
86 /* A default drawtype, for the case where no font exists to make the
88 #ifdef DRAW_TEXT_CAIRO
89 #define DRAW_DEFAULT_CAIRO
90 #define DRAWTYPE_DEFAULT DRAWTYPE_CAIRO
91 #elif defined DRAW_TEXT_GDK
92 #define DRAW_DEFAULT_GDK
93 #define DRAWTYPE_DEFAULT DRAWTYPE_GDK
95 #error No drawtype available at all
99 * Drawing context passed in to unifont_draw_text, which contains
100 * everything required to know where and how to draw the requested
103 typedef struct unifont_drawctx {
108 #ifdef DRAW_TEXT_CAIRO
120 #ifdef DRAW_TEXT_CAIRO
122 /* Need an actual widget, in order to backtrack to its X
123 * screen number when creating server-side pixmaps */
126 cairo_matrix_t origmatrix;
132 unifont *unifont_create(GtkWidget *widget, const char *name,
134 int shadowoffset, int shadowalways);
135 void unifont_destroy(unifont *font);
136 void unifont_draw_text(unifont_drawctx *ctx, unifont *font,
137 int x, int y, const wchar_t *string, int len,
138 int wide, int bold, int cellwidth);
139 /* Same as unifont_draw_text, but expects 'string' to contain one
140 * normal char plus combining chars, and overdraws them all in the
141 * same character cell. */
142 void unifont_draw_combining(unifont_drawctx *ctx, unifont *font,
143 int x, int y, const wchar_t *string, int len,
144 int wide, int bold, int cellwidth);
147 * This function behaves exactly like the low-level unifont_create,
148 * except that as well as the requested font it also allocates (if
149 * necessary) a fallback font for filling in replacement glyphs.
151 * Return value is usable with unifont_destroy and unifont_draw_text
152 * as if it were an ordinary unifont.
154 unifont *multifont_create(GtkWidget *widget, const char *name,
156 int shadowoffset, int shadowalways);
159 * Unified font selector dialog. I can't be bothered to do a
160 * proper GTK subclassing today, so this will just be an ordinary
161 * data structure with some useful members.
163 * (Of course, these aren't the only members; this structure is
164 * contained within a bigger one which holds data visible only to
165 * the implementation.)
167 typedef struct unifontsel {
168 void *user_data; /* settable by the user */
170 GtkWidget *ok_button, *cancel_button;
173 unifontsel *unifontsel_new(const char *wintitle);
174 void unifontsel_destroy(unifontsel *fontsel);
175 void unifontsel_set_name(unifontsel *fontsel, const char *fontname);
176 char *unifontsel_get_name(unifontsel *fontsel);
178 #endif /* PUTTY_GTKFONT_H */