]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - unix/gtkfont.h
Merge tag '0.66'
[PuTTY.git] / unix / gtkfont.h
1 /*
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).
5  */
6
7 #ifndef PUTTY_GTKFONT_H
8 #define PUTTY_GTKFONT_H
9
10 /*
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.
17  *
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.
24  */
25 #if !GTK_CHECK_VERSION(3,0,0) && !defined GDK_DISABLE_DEPRECATED
26 #define DRAW_TEXT_GDK
27 #endif
28 #if GTK_CHECK_VERSION(2,8,0)
29 #define DRAW_TEXT_CAIRO
30 #endif
31
32 #if GTK_CHECK_VERSION(3,0,0) || defined GDK_DISABLE_DEPRECATED
33 /*
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.
42  *
43  * However, GTK is deprecating the use of server-side pixmaps, so we
44  * have to disable this mode under some circumstances.
45  */
46 #define NO_BACKING_PIXMAPS
47 #endif
48
49 /*
50  * Exports from gtkfont.c.
51  */
52 struct unifont_vtable;                 /* contents internal to gtkfont.c */
53 typedef struct unifont {
54     const struct unifont_vtable *vt;
55     /*
56      * `Non-static data members' of the `class', accessible to
57      * external code.
58      */
59
60     /*
61      * public_charset is the charset used when the user asks for
62      * `Use font encoding'.
63      */
64     int public_charset;
65
66     /*
67      * Font dimensions needed by clients.
68      */
69     int width, height, ascent, descent;
70
71     /*
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.
76      */
77     int want_fallback;
78
79     /*
80      * Preferred drawing API to use when this class of font is active.
81      * (See the enum below, in unifont_drawctx.)
82      */
83     int preferred_drawtype;
84 } unifont;
85
86 /* A default drawtype, for the case where no font exists to make the
87  * decision with. */
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
94 #else
95 #error No drawtype available at all
96 #endif
97
98 /*
99  * Drawing context passed in to unifont_draw_text, which contains
100  * everything required to know where and how to draw the requested
101  * text.
102  */
103 typedef struct unifont_drawctx {
104     enum {
105 #ifdef DRAW_TEXT_GDK
106         DRAWTYPE_GDK,
107 #endif
108 #ifdef DRAW_TEXT_CAIRO
109         DRAWTYPE_CAIRO,
110 #endif
111         DRAWTYPE_NTYPES
112     } type;
113     union {
114 #ifdef DRAW_TEXT_GDK
115         struct {
116             GdkDrawable *target;
117             GdkGC *gc;
118         } gdk;
119 #endif
120 #ifdef DRAW_TEXT_CAIRO
121         struct {
122             /* Need an actual widget, in order to backtrack to its X
123              * screen number when creating server-side pixmaps */
124             GtkWidget *widget;
125             cairo_t *cr;
126             cairo_matrix_t origmatrix;
127         } cairo;
128 #endif
129     } u;
130 } unifont_drawctx;
131
132 unifont *unifont_create(GtkWidget *widget, const char *name,
133                         int wide, int bold,
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);
145
146 /*
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.
150  *
151  * Return value is usable with unifont_destroy and unifont_draw_text
152  * as if it were an ordinary unifont.
153  */
154 unifont *multifont_create(GtkWidget *widget, const char *name,
155                           int wide, int bold,
156                           int shadowoffset, int shadowalways);
157
158 /*
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.
162  * 
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.)
166  */
167 typedef struct unifontsel {
168     void *user_data;                   /* settable by the user */
169     GtkWindow *window;
170     GtkWidget *ok_button, *cancel_button;
171 } unifontsel;
172
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);
177
178 #endif /* PUTTY_GTKFONT_H */