Include FT_FREETYPE_H.
[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 typedef struct MWDevice MWDevice;
27
28 extern MSymbol Mfont;
29
30 typedef struct MRealizedFont MRealizedFont;
31 typedef struct MRealizedFace MRealizedFace;
32 typedef struct MRealizedFontset MRealizedFontset;
33
34 /** Information about a frame.  */
35
36 struct MFrame
37 {
38   M17NObject control;
39
40   /** Pointer to a window-system dependent device object associated
41       with the frame.  */
42   MWDevice *device;
43
44   MSymbol foreground, background, videomode;
45
46   MFont *font;
47
48   /** The default face of the frame.  */
49   MFace *face;
50
51   /** The default realized face of the frame.  */
52   MRealizedFace *rface;
53
54   /** The default width of one-char space.  It is a width of SPACE
55       character of the default face.  */
56   int space_width;
57
58   /** The default ascent and descent of a line.  It is ascent and
59       descent of ASCII font of the default face.  */
60   int ascent, descent;
61
62   /** The following three members are set by mwin__open_device ().  */
63
64   /** List of realized fonts.  */
65   MPlist *realized_font_list;
66
67   /** List of realized faces.  */
68   MPlist *realized_face_list;
69
70   /** List of realized fontsets.  */
71   MPlist *realized_fontset_list;
72 };
73
74 enum glyph_type
75   {
76     GLYPH_CHAR,
77     GLYPH_SPACE,
78     GLYPH_PAD,
79     GLYPH_BOX,
80     GLYPH_ANCHOR,
81     GLYPH_TYPE_MAX
82   };
83
84 typedef struct
85 {
86   int pos, to;
87   int c;
88   unsigned code;
89   MSymbol category;
90   MRealizedFace *rface;
91   short width, ascent, descent, lbearing, rbearing;
92   short xoff, yoff;
93   unsigned enabled : 1;
94   unsigned left_padding : 1;
95   unsigned right_padding : 1;
96   unsigned otf_encoded : 1;
97   unsigned bidi_level : 6;
98   enum glyph_type type : 3;
99   int combining_code;
100 } MGlyph;
101
102 struct MGlyphString
103 {
104   M17NObject head;
105
106   int size, inc, used;
107   MGlyph *glyphs;
108   MText *mt;
109   int from, to;
110   short width, height, ascent, descent;
111   short physical_ascent, physical_descent, lbearing, rbearing;
112   short text_ascent, text_descent, line_ascent, line_descent;
113   int indent, width_limit;
114
115   /* Members to keep temporary data while layouting.  */
116   short sub_width, sub_lbearing, sub_rbearing;
117
118   /* Copied for <control>.anti_alias but never set if the frame's
119      depth is less than 8.  */
120   unsigned anti_alias : 1;
121
122   MDrawControl control;
123
124   MDrawRegion region;
125
126   struct MGlyphString *next, *top;
127 };
128
129 #define MGLYPH(idx)     \
130   (gstring->glyphs + ((idx) >= 0 ? (idx) : (gstring->used + (idx))))
131
132 #define GLYPH_INDEX(g)  \
133   ((g) - gstring->glyphs)
134
135 #define INIT_GLYPH(g)   \
136   (memset (&(g), 0, sizeof (g)))
137
138 #define APPEND_GLYPH(gstring, g)        \
139   MLIST_APPEND1 ((gstring), glyphs, (g), MERROR_DRAW)
140
141 #define INSERT_GLYPH(gstring, at, g)                            \
142   do {                                                          \
143     MLIST_INSERT1 ((gstring), glyphs, (at), 1, MERROR_DRAW);    \
144     (gstring)->glyphs[at] = g;                                  \
145   } while (0)
146
147 #define DELETE_GLYPH(gstring, at)               \
148   do {                                          \
149     MLIST_DELETE1 (gstring, glyphs, at, 1);     \
150   } while (0)
151
152 #define REPLACE_GLYPHS(gstring, from, to, len)                            \
153   do {                                                                    \
154     int newlen = (gstring)->used - (from);                                \
155     int diff = newlen - (len);                                            \
156                                                                           \
157     if (diff < 0)                                                         \
158       MLIST_DELETE1 (gstring, glyphs, (to) + newlen, -diff);              \
159     else if (diff > 0)                                                    \
160       MLIST_INSERT1 ((gstring), glyphs, (to) + (len), diff, MERROR_DRAW); \
161     memmove ((gstring)->glyphs + to, (gstring)->glyphs + (from + diff),   \
162              (sizeof (MGlyph)) * newlen);                                 \
163     (gstring)->used -= newlen;                                            \
164   } while (0)
165
166 #define MAKE_COMBINING_CODE(base_y, base_x, add_y, add_x, off_y, off_x) \
167   (((off_y) << 16)                                                      \
168    | ((off_x) << 8)                                                     \
169    | ((base_x) << 6)                                                    \
170    | ((base_y) << 4)                                                    \
171    | ((add_x) << 2)                                                     \
172    | (add_y))
173
174 #define COMBINING_CODE_OFF_Y(code) (((code) >> 16) & 0xFF)
175 #define COMBINING_CODE_OFF_X(code) (((code) >> 8) & 0xFF)
176 #define COMBINING_CODE_BASE_X(code) (((code) >> 6) & 0x3)
177 #define COMBINING_CODE_BASE_Y(code) (((code) >> 4) & 0x3)
178 #define COMBINING_CODE_ADD_X(code) (((code) >> 2) & 0x3)
179 #define COMBINING_CODE_ADD_Y(code) ((code) & 0x3)
180
181 #define MAKE_COMBINING_CODE_BY_CLASS(class) (0x1000000 | class)
182
183 #define COMBINING_BY_CLASS_P(code) ((code) & 0x1000000)
184
185 #define COMBINING_CODE_CLASS(code) ((code) & 0xFFFFFF)
186
187 typedef struct MGlyphString MGlyphString;
188
189 typedef struct MFontDriver MFontDriver;
190
191 typedef struct
192 {
193   short x, y;
194 } MDrawPoint;
195
196 extern int mfont__init ();
197 extern void mfont__fini ();
198
199 extern int mface__init ();
200 extern void mface__fini ();
201
202 extern int mdraw__init ();
203 extern void mdraw__fini ();
204
205 extern int mfont__fontset_init ();
206 extern void mfont__fontset_fini ();
207
208 extern int minput__win_init ();
209 extern void minput__win_fini ();
210
211 extern int mwin__init ();
212 extern void mwin__fini ();
213
214 extern MWDevice *mwin__open_device (MFrame *frame, MPlist *plist);
215
216 extern void mwin__close_device (MFrame *frame);
217
218 extern void *mwin__device_get_prop (MWDevice *device, MSymbol key);
219
220 extern int mwin__parse_font_name (char *name, MFont *font);
221
222 extern char *mwin__build_font_name (MFont *font);
223
224 extern void mwin__realize_face (MRealizedFace *rface);
225
226 extern void mwin__free_realized_face (MRealizedFace *rface);
227
228 extern void mwin__fill_space (MFrame *frame, MDrawWindow win,
229                               MRealizedFace *rface, int reverse,
230                               int x, int y, int width, int height,
231                               MDrawRegion region);
232
233 extern void mwin__draw_hline (MFrame *frame, MDrawWindow win,
234                               MGlyphString *gstring,
235                               MRealizedFace *rface, int reverse,
236                               int x, int y, int width, MDrawRegion region);
237
238 extern void mwin__draw_box (MFrame *frame, MDrawWindow win,
239                             MGlyphString *gstring,
240                             MGlyph *g, int x, int y, int width,
241                             MDrawRegion region);
242
243 extern void mwin__draw_points (MFrame *frame, MDrawWindow win,
244                                MRealizedFace *rface,
245                                int intensity, MDrawPoint *points, int num,
246                                MDrawRegion region);
247
248 extern MDrawRegion mwin__region_from_rect (MDrawMetric *rect);
249
250 extern void mwin__union_rect_with_region (MDrawRegion region,
251                                           MDrawMetric *rect);
252
253 extern void mwin__intersect_region (MDrawRegion region1, MDrawRegion region2);
254
255 extern void mwin__region_add_rect (MDrawRegion region, MDrawMetric *rect);
256
257 extern void mwin__region_to_rect (MDrawRegion region, MDrawMetric *rect);
258
259 extern void mwin__free_region (MDrawRegion region);
260
261 extern void mwin__verify_region (MFrame *frame, MDrawRegion region);
262
263 extern void mwin__dump_region (MDrawRegion region);
264
265 extern MDrawWindow mwin__create_window (MFrame *frame, MDrawWindow parent);
266
267 extern void mwin__destroy_window (MFrame *frame, MDrawWindow win);
268
269 #if 0
270 extern MDrawWindow mwin__event_window (void *event);
271
272 extern void mwin__print_event (void *event, char *win_name);
273 #endif
274
275 extern void mwin__map_window (MFrame *frame, MDrawWindow win);
276
277 extern void mwin__unmap_window (MFrame *frame, MDrawWindow win);
278
279 extern void mwin__window_geometry (MFrame *frame, MDrawWindow win,
280                                    MDrawWindow parent, MDrawMetric *geometry);
281
282 extern void mwin__adjust_window (MFrame *frame, MDrawWindow win,
283                                  MDrawMetric *current, MDrawMetric *new);
284
285 extern MSymbol mwin__parse_event (MFrame *frame, void *arg, int *modifiers);
286
287 #ifdef HAVE_XFT2
288
289 #include <ft2build.h>
290 #include FT_FREETYPE_H
291
292 extern void *mwin__xft_open (MFrame *frame, char *filename, int size);
293 extern void mwin__xft_close (void *xft_info);
294 extern void mwin__xft_get_metric (void *xft_info, FT_Face ft_face, MGlyph *g);
295 extern void mwin__xft_render (MDrawWindow win, int x, int y,
296                               MGlyphString *gstring, MGlyph *from, MGlyph *to,
297                               int reverse, MDrawRegion region,
298                               void *xft_info, FT_Face ft_face);
299 #endif  /* HAVE_XFT2 */
300
301 #endif /* _M_INTERNAL_GUI_H */