8944a9b6da13640925ec416abacfe702f13fbf70
[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 extern MSymbol Mfont;
33
34 typedef struct MRealizedFont MRealizedFont;
35 typedef struct MRealizedFace MRealizedFace;
36 typedef struct MRealizedFontset MRealizedFontset;
37 typedef struct MDeviceDriver MDeviceDriver;
38
39 /** Information about a frame.  */
40
41 struct MFrame
42 {
43   M17NObject control;
44
45   MSymbol foreground, background, videomode;
46
47   MFont *font;
48
49   /** The default face of the frame.  */
50   MFace *face;
51
52   /** The default realized face of the frame.  */
53   MRealizedFace *rface;
54
55   /** The default width of one-char space.  It is a width of SPACE
56       character of the default face.  */
57   int space_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   /** Correction of functions to manipulate the device.  */
78   MDeviceDriver *driver;
79
80   /** List of font drivers.  */
81   MPlist *font_driver_list;
82
83   /** List of realized fonts.  */
84   MPlist *realized_font_list;
85
86   /** List of realized faces.  */
87   MPlist *realized_face_list;
88
89   /** List of realized fontsets.  */
90   MPlist *realized_fontset_list;
91 };
92
93 #define M_CHECK_WRITABLE(frame, err, ret)                       \
94   do {                                                          \
95     if (! ((frame)->device_type & MDEVICE_SUPPORT_OUTPUT))      \
96       MERROR ((err), (ret));                                    \
97   } while (0)
98
99 #define M_CHECK_READABLE(frame, err, ret)                       \
100   do {                                                          \
101     if (! ((frame)->device_type & MDEVICE_SUPPORT_INPUT))       \
102       MERROR ((err), (ret));                                    \
103   } while (0)
104
105 enum glyph_type
106   {
107     GLYPH_CHAR,
108     GLYPH_SPACE,
109     GLYPH_PAD,
110     GLYPH_BOX,
111     GLYPH_ANCHOR,
112     GLYPH_TYPE_MAX
113   };
114
115 typedef struct
116 {
117   int pos, to;
118   int c;
119   unsigned code;
120   MSymbol category;
121   MRealizedFace *rface;
122   short width, ascent, descent, lbearing, rbearing;
123   short xoff, yoff;
124   unsigned enabled : 1;
125   unsigned left_padding : 1;
126   unsigned right_padding : 1;
127   unsigned otf_encoded : 1;
128   unsigned bidi_level : 6;
129   enum glyph_type type : 3;
130   int combining_code;
131 } MGlyph;
132
133 struct MGlyphString
134 {
135   M17NObject head;
136
137   MFrame *frame;
138   int tick;
139
140   int size, inc, used;
141   MGlyph *glyphs;
142   MText *mt;
143   int from, to;
144   short width, height, ascent, descent;
145   short physical_ascent, physical_descent, lbearing, rbearing;
146   short text_ascent, text_descent, line_ascent, line_descent;
147   int indent, width_limit;
148
149   /* Members to keep temporary data while layouting.  */
150   short sub_width, sub_lbearing, sub_rbearing;
151
152   /* Copied for <control>.anti_alias but never set if the frame's
153      depth is less than 8.  */
154   unsigned anti_alias : 1;
155
156   MDrawControl control;
157
158   MDrawRegion region;
159
160   struct MGlyphString *next, *top;
161 };
162
163 #define MGLYPH(idx)     \
164   (gstring->glyphs + ((idx) >= 0 ? (idx) : (gstring->used + (idx))))
165
166 #define GLYPH_INDEX(g)  \
167   ((g) - gstring->glyphs)
168
169 #define INIT_GLYPH(g)   \
170   (memset (&(g), 0, sizeof (g)))
171
172 #define APPEND_GLYPH(gstring, g)        \
173   MLIST_APPEND1 ((gstring), glyphs, (g), MERROR_DRAW)
174
175 #define INSERT_GLYPH(gstring, at, g)                            \
176   do {                                                          \
177     MLIST_INSERT1 ((gstring), glyphs, (at), 1, MERROR_DRAW);    \
178     (gstring)->glyphs[at] = g;                                  \
179   } while (0)
180
181 #define DELETE_GLYPH(gstring, at)               \
182   do {                                          \
183     MLIST_DELETE1 (gstring, glyphs, at, 1);     \
184   } while (0)
185
186 #define REPLACE_GLYPHS(gstring, from, to, len)                            \
187   do {                                                                    \
188     int newlen = (gstring)->used - (from);                                \
189     int diff = newlen - (len);                                            \
190                                                                           \
191     if (diff < 0)                                                         \
192       MLIST_DELETE1 (gstring, glyphs, (to) + newlen, -diff);              \
193     else if (diff > 0)                                                    \
194       MLIST_INSERT1 ((gstring), glyphs, (to) + (len), diff, MERROR_DRAW); \
195     memmove ((gstring)->glyphs + to, (gstring)->glyphs + (from + diff),   \
196              (sizeof (MGlyph)) * newlen);                                 \
197     (gstring)->used -= newlen;                                            \
198   } while (0)
199
200 #define MAKE_COMBINING_CODE(base_y, base_x, add_y, add_x, off_y, off_x) \
201   (((off_y) << 16)                                                      \
202    | ((off_x) << 8)                                                     \
203    | ((base_x) << 6)                                                    \
204    | ((base_y) << 4)                                                    \
205    | ((add_x) << 2)                                                     \
206    | (add_y))
207
208 #define COMBINING_CODE_OFF_Y(code) (((code) >> 16) & 0xFF)
209 #define COMBINING_CODE_OFF_X(code) (((code) >> 8) & 0xFF)
210 #define COMBINING_CODE_BASE_X(code) (((code) >> 6) & 0x3)
211 #define COMBINING_CODE_BASE_Y(code) (((code) >> 4) & 0x3)
212 #define COMBINING_CODE_ADD_X(code) (((code) >> 2) & 0x3)
213 #define COMBINING_CODE_ADD_Y(code) ((code) & 0x3)
214
215 #define MAKE_COMBINING_CODE_BY_CLASS(class) (0x1000000 | class)
216
217 #define COMBINING_BY_CLASS_P(code) ((code) & 0x1000000)
218
219 #define COMBINING_CODE_CLASS(code) ((code) & 0xFFFFFF)
220
221 typedef struct MGlyphString MGlyphString;
222
223 typedef struct MFontDriver MFontDriver;
224
225 typedef struct
226 {
227   short x, y;
228 } MDrawPoint;
229
230 extern MPlist *m17n__device_library_list;
231
232 struct MDeviceDriver
233 {
234   int initialized;
235   int (*init) ();
236   int (*fini) ();
237   int (*open) (MFrame *frame, MPlist *param);
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 Mx;
282 extern MSymbol Mgd;
283 extern MSymbol Mfreetype;
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 */