(Mfont): Delete extern.
[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   /** The default ascent and descent of a line.  It is ascent and
58       descent of ASCII font of the default face.  */
59   int ascent, descent;
60
61   /** Initialized to 0 and incremented on each modification of a face
62       on which one of the realized faces is based.  */
63   unsigned tick;
64
65   /** Pointer to device dependent information associated with the
66       frame.  */
67   void *device;
68
69   /** The following members are set by "device_open" function of a
70       device dependent library.  */
71
72   /** Logical OR of enum MDeviceType.  */
73   int device_type;
74
75   /** Correction of functions to manipulate the device.  */
76   MDeviceDriver *driver;
77
78   /** List of font drivers.  */
79   MPlist *font_driver_list;
80
81   /** List of realized fonts.  */
82   MPlist *realized_font_list;
83
84   /** List of realized faces.  */
85   MPlist *realized_face_list;
86
87   /** List of realized fontsets.  */
88   MPlist *realized_fontset_list;
89 };
90
91 #define M_CHECK_WRITABLE(frame, err, ret)                       \
92   do {                                                          \
93     if (! ((frame)->device_type & MDEVICE_SUPPORT_OUTPUT))      \
94       MERROR ((err), (ret));                                    \
95   } while (0)
96
97 #define M_CHECK_READABLE(frame, err, ret)                       \
98   do {                                                          \
99     if (! ((frame)->device_type & MDEVICE_SUPPORT_INPUT))       \
100       MERROR ((err), (ret));                                    \
101   } while (0)
102
103 enum glyph_type
104   {
105     GLYPH_CHAR,
106     GLYPH_SPACE,
107     GLYPH_PAD,
108     GLYPH_BOX,
109     GLYPH_ANCHOR,
110     GLYPH_TYPE_MAX
111   };
112
113 typedef struct
114 {
115   MSymbol script;
116   MSymbol langsys;
117   MSymbol gsub_features;
118   MSymbol gpos_features;
119 } FontLayoutCmdOTF;
120
121 typedef struct
122 {
123   int pos, to;
124   int c;
125   unsigned code;
126   MSymbol category;
127   MRealizedFace *rface;
128   short width, ascent, descent, lbearing, rbearing;
129   short xoff, yoff;
130 #ifdef HAVE_OTF
131   FontLayoutCmdOTF *otf_cmd;
132 #endif
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_type type : 3;
139   int combining_code;
140 } MGlyph;
141
142 struct MGlyphString
143 {
144   M17NObject head;
145
146   MFrame *frame;
147   int tick;
148
149   int size, inc, used;
150   MGlyph *glyphs;
151   MText *mt;
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   /* Members to keep temporary data while layouting.  */
159   short sub_width, sub_lbearing, sub_rbearing;
160
161   /* Copied for <control>.anti_alias but never set if the frame's
162      depth is less than 8.  */
163   unsigned anti_alias : 1;
164
165   MDrawControl control;
166
167   MDrawRegion region;
168
169   struct MGlyphString *next, *top;
170 };
171
172 #define MGLYPH(idx)     \
173   (gstring->glyphs + ((idx) >= 0 ? (idx) : (gstring->used + (idx))))
174
175 #define GLYPH_INDEX(g)  \
176   ((g) - gstring->glyphs)
177
178 #define INIT_GLYPH(g)   \
179   (memset (&(g), 0, sizeof (g)))
180
181 #define APPEND_GLYPH(gstring, g)        \
182   MLIST_APPEND1 ((gstring), glyphs, (g), MERROR_DRAW)
183
184 #define INSERT_GLYPH(gstring, at, g)                            \
185   do {                                                          \
186     MLIST_INSERT1 ((gstring), glyphs, (at), 1, MERROR_DRAW);    \
187     (gstring)->glyphs[at] = g;                                  \
188   } while (0)
189
190 #define DELETE_GLYPH(gstring, at)               \
191   do {                                          \
192     MLIST_DELETE1 (gstring, glyphs, at, 1);     \
193   } while (0)
194
195 #define REPLACE_GLYPHS(gstring, from, to, len)                            \
196   do {                                                                    \
197     int newlen = (gstring)->used - (from);                                \
198     int diff = newlen - (len);                                            \
199                                                                           \
200     if (diff < 0)                                                         \
201       MLIST_DELETE1 (gstring, glyphs, (to) + newlen, -diff);              \
202     else if (diff > 0)                                                    \
203       MLIST_INSERT1 ((gstring), glyphs, (to) + (len), diff, MERROR_DRAW); \
204     memmove ((gstring)->glyphs + to, (gstring)->glyphs + (from + diff),   \
205              (sizeof (MGlyph)) * newlen);                                 \
206     (gstring)->used -= newlen;                                            \
207   } while (0)
208
209 #define MAKE_COMBINING_CODE(base_y, base_x, add_y, add_x, off_y, off_x) \
210   (((off_y) << 16)                                                      \
211    | ((off_x) << 8)                                                     \
212    | ((base_x) << 6)                                                    \
213    | ((base_y) << 4)                                                    \
214    | ((add_x) << 2)                                                     \
215    | (add_y))
216
217 #define COMBINING_CODE_OFF_Y(code) (((code) >> 16) & 0xFF)
218 #define COMBINING_CODE_OFF_X(code) (((code) >> 8) & 0xFF)
219 #define COMBINING_CODE_BASE_X(code) (((code) >> 6) & 0x3)
220 #define COMBINING_CODE_BASE_Y(code) (((code) >> 4) & 0x3)
221 #define COMBINING_CODE_ADD_X(code) (((code) >> 2) & 0x3)
222 #define COMBINING_CODE_ADD_Y(code) ((code) & 0x3)
223
224 #define MAKE_COMBINING_CODE_BY_CLASS(class) (0x1000000 | class)
225
226 #define COMBINING_BY_CLASS_P(code) ((code) & 0x1000000)
227
228 #define COMBINING_CODE_CLASS(code) ((code) & 0xFFFFFF)
229
230 typedef struct MGlyphString MGlyphString;
231
232 typedef struct MFontDriver MFontDriver;
233
234 typedef struct
235 {
236   short x, y;
237 } MDrawPoint;
238
239 struct MDeviceDriver
240 {
241   void (*close) (MFrame *frame);
242   void *(*get_prop) (MFrame *frame, MSymbol key);
243   void (*realize_face) (MRealizedFace *rface);
244   void (*free_realized_face) (MRealizedFace *rface);
245   void (*fill_space) (MFrame *frame, MDrawWindow win,
246                       MRealizedFace *rface, int reverse,
247                       int x, int y, int width, int height,
248                       MDrawRegion region);
249   void (*draw_empty_boxes) (MDrawWindow win, int x, int y,
250                             MGlyphString *gstring,
251                             MGlyph *from, MGlyph *to,
252                             int reverse, MDrawRegion region);
253   void (*draw_hline) (MFrame *frame, MDrawWindow win,
254                       MGlyphString *gstring,
255                       MRealizedFace *rface, int reverse,
256                       int x, int y, int width, MDrawRegion region);
257   void (*draw_box) (MFrame *frame, MDrawWindow win,
258                     MGlyphString *gstring,
259                     MGlyph *g, int x, int y, int width,
260                     MDrawRegion region);
261
262   void (*draw_points) (MFrame *frame, MDrawWindow win,
263                        MRealizedFace *rface,
264                        int intensity, MDrawPoint *points, int num,
265                        MDrawRegion region);
266   MDrawRegion (*region_from_rect) (MDrawMetric *rect);
267   void (*union_rect_with_region) (MDrawRegion region, MDrawMetric *rect);
268   void (*intersect_region) (MDrawRegion region1, MDrawRegion region2);
269   void (*region_add_rect) (MDrawRegion region, MDrawMetric *rect);
270   void (*region_to_rect) (MDrawRegion region, MDrawMetric *rect);
271   void (*free_region) (MDrawRegion region);
272   void (*dump_region) (MDrawRegion region);
273   MDrawWindow (*create_window) (MFrame *frame, MDrawWindow parent);
274   void (*destroy_window) (MFrame *frame, MDrawWindow win);
275   void (*map_window) (MFrame *frame, MDrawWindow win);
276   void (*unmap_window) (MFrame *frame, MDrawWindow win);
277   void (*window_geometry) (MFrame *frame, MDrawWindow win,
278                            MDrawWindow parent, MDrawMetric *geometry);
279   void (*adjust_window) (MFrame *frame, MDrawWindow win,
280                          MDrawMetric *current, MDrawMetric *new);
281   MSymbol (*parse_event) (MFrame *frame, void *arg, int *modifiers);
282 };
283
284 extern MSymbol Mx;
285 extern MSymbol Mgd;
286 extern MSymbol Mfreetype;
287
288 extern int mfont__init ();
289 extern void mfont__fini ();
290
291 extern int mface__init ();
292 extern void mface__fini ();
293
294 extern int mdraw__init ();
295 extern void mdraw__fini ();
296
297 extern int mfont__fontset_init ();
298 extern void mfont__fontset_fini ();
299
300 extern int minput__win_init ();
301 extern void minput__win_fini ();
302
303 #endif /* _M_INTERNAL_GUI_H */