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
33 * Exports from gtkfont.c.
35 struct unifont_vtable; /* contents internal to gtkfont.c */
36 typedef struct unifont {
37 const struct unifont_vtable *vt;
39 * `Non-static data members' of the `class', accessible to
44 * public_charset is the charset used when the user asks for
45 * `Use font encoding'.
50 * Font dimensions needed by clients.
52 int width, height, ascent, descent;
55 * Indicates whether this font is capable of handling all glyphs
56 * (Pango fonts can do this because Pango automatically supplies
57 * missing glyphs from other fonts), or whether it would like a
58 * fallback font to cope with missing glyphs.
63 * Preferred drawing API to use when this class of font is active.
64 * (See the enum below, in unifont_drawctx.)
66 int preferred_drawtype;
69 /* A default drawtype, for the case where no font exists to make the
71 #ifdef DRAW_TEXT_CAIRO
72 #define DRAW_DEFAULT_CAIRO
73 #define DRAWTYPE_DEFAULT DRAWTYPE_CAIRO
74 #elif defined DRAW_TEXT_GDK
75 #define DRAW_DEFAULT_GDK
76 #define DRAWTYPE_DEFAULT DRAWTYPE_GDK
78 #error No drawtype available at all
82 * Drawing context passed in to unifont_draw_text, which contains
83 * everything required to know where and how to draw the requested
86 typedef struct unifont_drawctx {
91 #ifdef DRAW_TEXT_CAIRO
103 #ifdef DRAW_TEXT_CAIRO
105 /* Need an actual widget, in order to backtrack to its X
106 * screen number when creating server-side pixmaps */
109 cairo_matrix_t origmatrix;
115 unifont *unifont_create(GtkWidget *widget, const char *name,
117 int shadowoffset, int shadowalways);
118 void unifont_destroy(unifont *font);
119 void unifont_draw_text(unifont_drawctx *ctx, unifont *font,
120 int x, int y, const wchar_t *string, int len,
121 int wide, int bold, int cellwidth);
124 * This function behaves exactly like the low-level unifont_create,
125 * except that as well as the requested font it also allocates (if
126 * necessary) a fallback font for filling in replacement glyphs.
128 * Return value is usable with unifont_destroy and unifont_draw_text
129 * as if it were an ordinary unifont.
131 unifont *multifont_create(GtkWidget *widget, const char *name,
133 int shadowoffset, int shadowalways);
136 * Unified font selector dialog. I can't be bothered to do a
137 * proper GTK subclassing today, so this will just be an ordinary
138 * data structure with some useful members.
140 * (Of course, these aren't the only members; this structure is
141 * contained within a bigger one which holds data visible only to
142 * the implementation.)
144 typedef struct unifontsel {
145 void *user_data; /* settable by the user */
147 GtkWidget *ok_button, *cancel_button;
150 unifontsel *unifontsel_new(const char *wintitle);
151 void unifontsel_destroy(unifontsel *fontsel);
152 void unifontsel_set_name(unifontsel *fontsel, const char *fontname);
153 char *unifontsel_get_name(unifontsel *fontsel);
155 #endif /* PUTTY_GTKFONT_H */