(xft_render): Check xft_draw's drawable before changing
[m17n/m17n-lib.git] / src / internal-gui.h
1 /* internal-gui.h -- common header file for the internal GUI API.
2    Copyright (C) 2003, 2004
3      National Institute of Advanced Industrial Science and Technology (AIST)
4      Registration Number H15PRO112
5
6    This file is part of the m17n library.
7
8    The m17n library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public License
10    as published by the Free Software Foundation; either version 2.1 of
11    the License, or (at your option) any later version.
12
13    The m17n library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Lesser General Public License for more details.
17
18    You should have received a copy of the GNU Lesser General Public
19    License along with the m17n library; if not, write to the Free
20    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21    02111-1307, USA.  */
22
23 #ifndef _M_INTERNAL_GUI_H
24 #define _M_INTERNAL_GUI_H
25
26 enum MDeviceType
27   {
28     MDEVICE_SUPPORT_OUTPUT = 1,
29     MDEVICE_SUPPORT_INPUT = 2
30   };
31
32 typedef struct MRealizedFont MRealizedFont;
33 typedef struct MRealizedFace MRealizedFace;
34 typedef struct MRealizedFontset MRealizedFontset;
35 typedef struct MDeviceDriver MDeviceDriver;
36
37 /** Information about a frame.  */
38
39 struct MFrame
40 {
41   M17NObject control;
42
43   MSymbol foreground, background, videomode;
44
45   MFont *font;
46
47   /** The default face of the frame.  */
48   MFace *face;
49
50   /** The default realized face of the frame.  */
51   MRealizedFace *rface;
52
53   /** The default width of one-char space.  It is a width of SPACE
54       character of the default face.  */
55   int space_width;
56
57   int average_width;
58
59   /** The default ascent and descent of a line.  It is ascent and
60       descent of ASCII font of the default face.  */
61   int ascent, descent;
62
63   /** Initialized to 0 and incremented on each modification of a face
64       on which one of the realized faces is based.  */
65   unsigned tick;
66
67   /** Pointer to device dependent information associated with the
68       frame.  */
69   void *device;
70
71   /** The following members are set by "device_open" function of a
72       device dependent library.  */
73
74   /** Logical OR of enum MDeviceType.  */
75   int device_type;
76
77   /** Resolution (dots per inch) of the device.  */
78   int dpi;
79
80   /** Correction of functions to manipulate the device.  */
81   MDeviceDriver *driver;
82
83   /** List of font drivers.  */
84   MPlist *font_driver_list;
85
86   /** List of realized fonts.  */
87   MPlist *realized_font_list;
88
89   /** List of realized faces.  */
90   MPlist *realized_face_list;
91
92   /** List of realized fontsets.  */
93   MPlist *realized_fontset_list;
94 };
95
96 #define M_CHECK_WRITABLE(frame, err, ret)                       \
97   do {                                                          \
98     if (! ((frame)->device_type & MDEVICE_SUPPORT_OUTPUT))      \
99       MERROR ((err), (ret));                                    \
100   } while (0)
101
102 #define M_CHECK_READABLE(frame, err, ret)                       \
103   do {                                                          \
104     if (! ((frame)->device_type & MDEVICE_SUPPORT_INPUT))       \
105       MERROR ((err), (ret));                                    \
106   } while (0)
107
108 enum glyph_type
109   {
110     GLYPH_CHAR,
111     GLYPH_SPACE,
112     GLYPH_PAD,
113     GLYPH_BOX,
114     GLYPH_ANCHOR,
115     GLYPH_TYPE_MAX
116   };
117
118 enum glyph_category
119   {
120     GLYPH_CATEGORY_NORMAL,
121     GLYPH_CATEGORY_MODIFIER,
122     GLYPH_CATEGORY_FORMATTER
123   };
124
125 typedef struct
126 {
127   int pos, to;
128   int c;
129   unsigned code;
130   MRealizedFace *rface;
131   short width, ascent, descent, lbearing, rbearing;
132   short xoff, yoff;
133   unsigned enabled : 1;
134   unsigned left_padding : 1;
135   unsigned right_padding : 1;
136   unsigned otf_encoded : 1;
137   unsigned bidi_level : 6;
138   enum glyph_category category : 2;
139   enum glyph_type type : 3;
140   int combining_code;
141 } MGlyph;
142
143 struct MGlyphString
144 {
145   M17NObject head;
146
147   MFrame *frame;
148   int tick;
149
150   int size, inc, used;
151   MGlyph *glyphs;
152   int from, to;
153   short width, height, ascent, descent;
154   short physical_ascent, physical_descent, lbearing, rbearing;
155   short text_ascent, text_descent, line_ascent, line_descent;
156   int indent, width_limit;
157
158   /* Copied for <control>.anti_alias but never set if the frame's
159      depth is less than 8.  */
160   unsigned anti_alias : 1;
161
162   MDrawControl control;
163
164   struct MGlyphString *next, *top;
165 };
166
167 #define MGLYPH(idx)     \
168   (gstring->glyphs + ((idx) >= 0 ? (idx) : (gstring->used + (idx))))
169
170 #define GLYPH_INDEX(g)  \
171   ((g) - gstring->glyphs)
172
173 #define INIT_GLYPH(g)   \
174   (memset (&(g), 0, sizeof (g)))
175
176 #define APPEND_GLYPH(gstring, g)        \
177   MLIST_APPEND1 ((gstring), glyphs, (g), MERROR_DRAW)
178
179 #define INSERT_GLYPH(gstring, at, g)                            \
180   do {                                                          \
181     MLIST_INSERT1 ((gstring), glyphs, (at), 1, MERROR_DRAW);    \
182     (gstring)->glyphs[at] = g;                                  \
183   } while (0)
184
185 #define DELETE_GLYPH(gstring, at)               \
186   do {                                          \
187     MLIST_DELETE1 (gstring, glyphs, at, 1);     \
188   } while (0)
189
190 #define REPLACE_GLYPHS(gstring, from, to, len)                            \
191   do {                                                                    \
192     int newlen = (gstring)->used - (from);                                \
193     int diff = newlen - (len);                                            \
194                                                                           \
195     if (diff < 0)                                                         \
196       MLIST_DELETE1 (gstring, glyphs, (to) + newlen, -diff);              \
197     else if (diff > 0)                                                    \
198       MLIST_INSERT1 ((gstring), glyphs, (to) + (len), diff, MERROR_DRAW); \
199     memmove ((gstring)->glyphs + to, (gstring)->glyphs + (from + diff),   \
200              (sizeof (MGlyph)) * newlen);                                 \
201     (gstring)->used -= newlen;                                            \
202   } while (0)
203
204 #define MAKE_COMBINING_CODE(base_y, base_x, add_y, add_x, off_y, off_x) \
205   (((off_y) << 16)                                                      \
206    | ((off_x) << 8)                                                     \
207    | ((base_x) << 6)                                                    \
208    | ((base_y) << 4)                                                    \
209    | ((add_x) << 2)                                                     \
210    | (add_y))
211
212 #define COMBINING_CODE_OFF_Y(code) (((code) >> 16) & 0xFF)
213 #define COMBINING_CODE_OFF_X(code) (((code) >> 8) & 0xFF)
214 #define COMBINING_CODE_BASE_X(code) (((code) >> 6) & 0x3)
215 #define COMBINING_CODE_BASE_Y(code) (((code) >> 4) & 0x3)
216 #define COMBINING_CODE_ADD_X(code) (((code) >> 2) & 0x3)
217 #define COMBINING_CODE_ADD_Y(code) ((code) & 0x3)
218
219 #define MAKE_COMBINING_CODE_BY_CLASS(class) (0x1000000 | class)
220
221 #define COMBINING_BY_CLASS_P(code) ((code) & 0x1000000)
222
223 #define COMBINING_CODE_CLASS(code) ((code) & 0xFFFFFF)
224
225 #define MAKE_PRECOMPUTED_COMBINDING_CODE() (0x2000000)
226
227 #define COMBINING_PRECOMPUTED_P(code) ((code) & 0x2000000)
228
229 typedef struct MGlyphString MGlyphString;
230
231 typedef struct
232 {
233   short x, y;
234 } MDrawPoint;
235
236 struct MDeviceDriver
237 {
238   void (*close) (MFrame *frame);
239   void *(*get_prop) (MFrame *frame, MSymbol key);
240   void (*realize_face) (MRealizedFace *rface);
241   void (*free_realized_face) (MRealizedFace *rface);
242   void (*fill_space) (MFrame *frame, MDrawWindow win,
243                       MRealizedFace *rface, int reverse,
244                       int x, int y, int width, int height,
245                       MDrawRegion region);
246   void (*draw_empty_boxes) (MDrawWindow win, int x, int y,
247                             MGlyphString *gstring,
248                             MGlyph *from, MGlyph *to,
249                             int reverse, MDrawRegion region);
250   void (*draw_hline) (MFrame *frame, MDrawWindow win,
251                       MGlyphString *gstring,
252                       MRealizedFace *rface, int reverse,
253                       int x, int y, int width, MDrawRegion region);
254   void (*draw_box) (MFrame *frame, MDrawWindow win,
255                     MGlyphString *gstring,
256                     MGlyph *g, int x, int y, int width,
257                     MDrawRegion region);
258
259   void (*draw_points) (MFrame *frame, MDrawWindow win,
260                        MRealizedFace *rface,
261                        int intensity, MDrawPoint *points, int num,
262                        MDrawRegion region);
263   MDrawRegion (*region_from_rect) (MDrawMetric *rect);
264   void (*union_rect_with_region) (MDrawRegion region, MDrawMetric *rect);
265   void (*intersect_region) (MDrawRegion region1, MDrawRegion region2);
266   void (*region_add_rect) (MDrawRegion region, MDrawMetric *rect);
267   void (*region_to_rect) (MDrawRegion region, MDrawMetric *rect);
268   void (*free_region) (MDrawRegion region);
269   void (*dump_region) (MDrawRegion region);
270   MDrawWindow (*create_window) (MFrame *frame, MDrawWindow parent);
271   void (*destroy_window) (MFrame *frame, MDrawWindow win);
272   void (*map_window) (MFrame *frame, MDrawWindow win);
273   void (*unmap_window) (MFrame *frame, MDrawWindow win);
274   void (*window_geometry) (MFrame *frame, MDrawWindow win,
275                            MDrawWindow parent, MDrawMetric *geometry);
276   void (*adjust_window) (MFrame *frame, MDrawWindow win,
277                          MDrawMetric *current, MDrawMetric *new);
278   MSymbol (*parse_event) (MFrame *frame, void *arg, int *modifiers);
279 };
280
281 extern MSymbol Mlatin;
282
283 extern MSymbol Mgd;
284
285 extern int mfont__init ();
286 extern void mfont__fini ();
287
288 extern int mface__init ();
289 extern void mface__fini ();
290
291 extern int mdraw__init ();
292 extern void mdraw__fini ();
293
294 extern int mfont__fontset_init ();
295 extern void mfont__fontset_fini ();
296
297 extern int minput__win_init ();
298 extern void minput__win_fini ();
299
300 #endif /* _M_INTERNAL_GUI_H */