]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - unix/gtkfont.h
b56640c5b7bdefc976729a9e9f9751fc3ca3c2c5
[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 /*
33  * Exports from gtkfont.c.
34  */
35 struct unifont_vtable;                 /* contents internal to gtkfont.c */
36 typedef struct unifont {
37     const struct unifont_vtable *vt;
38     /*
39      * `Non-static data members' of the `class', accessible to
40      * external code.
41      */
42
43     /*
44      * public_charset is the charset used when the user asks for
45      * `Use font encoding'.
46      */
47     int public_charset;
48
49     /*
50      * Font dimensions needed by clients.
51      */
52     int width, height, ascent, descent;
53
54     /*
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.
59      */
60     int want_fallback;
61
62     /*
63      * Preferred drawing API to use when this class of font is active.
64      * (See the enum below, in unifont_drawctx.)
65      */
66     int preferred_drawtype;
67 } unifont;
68
69 /* A default drawtype, for the case where no font exists to make the
70  * decision with. */
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
77 #else
78 #error No drawtype available at all
79 #endif
80
81 /*
82  * Drawing context passed in to unifont_draw_text, which contains
83  * everything required to know where and how to draw the requested
84  * text.
85  */
86 typedef struct unifont_drawctx {
87     enum {
88 #ifdef DRAW_TEXT_GDK
89         DRAWTYPE_GDK,
90 #endif
91 #ifdef DRAW_TEXT_CAIRO
92         DRAWTYPE_CAIRO,
93 #endif
94         DRAWTYPE_NTYPES
95     } type;
96     union {
97 #ifdef DRAW_TEXT_GDK
98         struct {
99             GdkDrawable *target;
100             GdkGC *gc;
101         } gdk;
102 #endif
103 #ifdef DRAW_TEXT_CAIRO
104         struct {
105             /* Need an actual widget, in order to backtrack to its X
106              * screen number when creating server-side pixmaps */
107             GtkWidget *widget;
108             cairo_t *cr;
109             cairo_matrix_t origmatrix;
110         } cairo;
111 #endif
112     } u;
113 } unifont_drawctx;
114
115 unifont *unifont_create(GtkWidget *widget, const char *name,
116                         int wide, int bold,
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);
122
123 /*
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.
127  *
128  * Return value is usable with unifont_destroy and unifont_draw_text
129  * as if it were an ordinary unifont.
130  */
131 unifont *multifont_create(GtkWidget *widget, const char *name,
132                           int wide, int bold,
133                           int shadowoffset, int shadowalways);
134
135 /*
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.
139  * 
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.)
143  */
144 typedef struct unifontsel {
145     void *user_data;                   /* settable by the user */
146     GtkWindow *window;
147     GtkWidget *ok_button, *cancel_button;
148 } unifontsel;
149
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);
154
155 #endif /* PUTTY_GTKFONT_H */