Include FT_FREETYPE_H.
[m17n/m17n-lib.git] / src / font.h
1 /* font.h -- header file for the font module.
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 _M17N_FONT_H_
24 #define _M17N_FONT_H_
25
26 /** Type of font stored in MFont->property[MFONT_TYPE].  */
27
28 enum MFontType
29   {
30     /** Fonts supproted by a window system natively.  On X Window
31         System, it is an X font.  */
32     MFONT_TYPE_WIN,
33
34     /** Fonts supported by FreeType library.  */
35     MFONT_TYPE_FT,
36
37     /** anchor */
38     MFONT_TYPE_MAX
39   };
40
41
42 enum MFontProperty
43   {
44     /* The order of MFONT_FOUNDRY to MFONT_ADSTYLE must be the same as
45        enum MFaceProperty.  */
46     MFONT_FOUNDRY,
47     MFONT_FAMILY,
48     MFONT_WEIGHT,
49     MFONT_STYLE,
50     MFONT_STRETCH,
51     MFONT_ADSTYLE,
52     MFONT_REGISTRY,
53     MFONT_SIZE,
54     MFONT_RESY,
55     MFONT_TYPE,
56     /* anchor */
57     MFONT_PROPERTY_MAX
58   };
59
60 /** Information about a font.  This structure is used in three ways:
61     FONT-OBJ, FONT-OPENED, and FONT-SPEC.  
62
63     FONT-OBJ: To store information of an existing font.  Instances
64     appear only in <font_list> of MDisplay.
65
66     FONT-OPENED: To store information of an opened font.  Instances
67     appear only in <opend_list> of MDisplay.
68
69     FONT-SPEC: To store specifications of a font.  Instances appear
70     only in <spec_list> of MFontset.  */
71
72 struct MFont
73 {
74   /** Numeric value of each font property.  Also used as an index to
75       the table @c mfont__property_table to get the actual name of the
76       property.
77
78       For FONT-OBJ, FONT-OPENED: The value is greater than zero.
79
80       For FONT-SPEC: The value is equal to or greater than zero.  Zero
81       means that the correponding property is not specified (i.e. wild
82       card).
83
84       <property>[MFONT_SIZE] is the size of the font in 1/10 pixels.
85
86       For FONT-OBJ: If the value is 0, the font is scalable or
87       auto-scaled.
88
89       For FONT-OPENED: The actual size of opened font.
90
91       <prperty>[MFONT_RESY] is the designed resolution of the font in
92       DPI, or zero.  Zero means that the font is scalable.
93
94       For the time being, we mention only Y-resolution (resy) and
95       assume that resx is always equal to resy.  */
96   unsigned short property[MFONT_PROPERTY_MAX];
97 };
98
99 typedef struct
100 {
101   int size, inc, used;
102   MSymbol property;
103   MSymbol *names;
104 } MFontPropertyTable;
105
106 extern MFontPropertyTable mfont__property_table[MFONT_REGISTRY + 1];
107
108 /** Return the symbol of the Nth font property of FONT.  */
109 #define FONT_PROPERTY(font, n)  \
110   mfont__property_table[(n)].names[(font)->property[(n)]]
111
112 typedef struct MFontEncoding MFontEncoding;
113
114 struct MRealizedFont
115 {
116   /* Frame on which the font is realized.  */
117   MFrame *frame;
118
119   /* Font spec used to find the font.  */
120   MFont spec;
121
122   /* Font spec requested by a face.  */
123   MFont request;
124
125   /* The found font.  */
126   MFont font;
127
128   /* How well <font> matches with <request>.  */
129   int score;
130
131   MFontDriver *driver;
132
133   /* Font Layout Table for the font.  */
134   MSymbol layouter;
135
136   /* 0: not yet tried to open
137      -1: failed to open
138      1: succeessfully opened.  */
139   int status;
140
141   /* Extra information set by <driver>->select or <driver>->open.  If
142      non-NULL, it must be a pointer to a managed object.  */
143   void *info;
144
145   short ascent, descent;
146
147   MFontEncoding *encoding;
148 };
149
150 /** Structure to hold a list of fonts of each registry.  */
151
152 typedef struct
153 {
154   MSymbol tag;
155   int nfonts;
156   MFont *fonts;
157 } MFontList;
158
159
160 struct MFontDriver
161 {
162   /** Return a font best matching with SPEC.  */
163   MRealizedFont *(*select) (MFrame *frame, MFont *spec, MFont *request,
164                             int limitted_size);
165
166   /** Open a font specified by RFONT.  */
167   int (*open) (MRealizedFont *rfont);
168
169   /** Close a font specified by RFONT.   */
170   void (*close) (MRealizedFont *rfont);
171
172   /** Set metrics of glyphs in GSTRING from FROM to TO.  */
173   void (*find_metric) (MRealizedFont *rfont, MGlyphString *gstring,
174                        int from, int to);
175
176   /** Encode C into the glyph code the font.  CODE is a code point of
177       C in rfont->encoder->encoding_charset.  If the font has no glyph
178       for C, return MCHAR_INVALID_CODE.  */
179   unsigned (*encode_char) (MRealizedFont *rfont, int c, unsigned code);
180
181   /** Draw glyphs from FROM to TO (exclusive) on window WIN of FRAME
182       at coordinate (X, Y) relative to WIN.  */
183   void (*render) (MDrawWindow win, int x, int y,
184                   MGlyphString *gstring, MGlyph *from, MGlyph *to,
185                   int reverse, MDrawRegion region);
186 };
187
188 /** Initialize the members of FONT.  */
189
190 #define MFONT_INIT(font) memset ((font), 0, sizeof (MFont))
191
192
193 extern MFontDriver *mfont__driver_list[MFONT_TYPE_MAX];
194
195 extern MSymbol Mlayouter;
196
197 extern int mfont__flt_init ();
198
199 extern void mfont__flt_fini ();
200
201 #ifdef HAVE_FREETYPE
202 #include <ft2build.h>
203 #include FT_FREETYPE_H
204
205 extern int mfont__ft_init ();
206
207 extern void mfont__ft_fini ();
208
209 extern int mfont__ft_drive_otf (MGlyphString *gstring, int from, int to,
210                                 MRealizedFont *rfont,
211                                 MSymbol script, MSymbol langsys,
212                                 MSymbol gsub_features, MSymbol gpos_features);
213 extern int mfont__ft_decode_otf (MGlyph *g);
214
215 #endif /* HAVE_FREETYPE */
216
217 extern void mfont__free_realized (MRealizedFont *rfont);
218
219 extern int mfont__match_p (MFont *font, MFont *spec, int prop);
220
221 extern int mfont__score (MFont *font, MFont *spec, MFont *request,
222                          int limitted_size);
223
224 extern void mfont__set_spec_from_face (MFont *spec, MFace *face);
225
226 extern MSymbol mfont__set_spec_from_plist (MFont *spec, MPlist *plist);
227
228 extern void mfont__resize (MFont *spec, MFont *request);
229
230 extern int mfont__encodable_p (MRealizedFont *rfont, MSymbol layouter_name,
231                                int c);
232
233 extern unsigned mfont__encode_char (MRealizedFont *rfont, int c);
234
235 extern MRealizedFont *mfont__select (MFrame *frame, MFont *spec,
236                                      MFont *request, int limitted_size,
237                                      MSymbol layouter);
238
239 extern int mfont__open (MRealizedFont *rfont);
240
241 extern void mfont__close (MRealizedFont *rfont);
242
243 extern void mfont__get_metric (MGlyphString *gstring, int from, int to);
244
245 extern void mfont__set_property (MFont *font, enum MFontProperty key,
246                                  MSymbol val);
247
248 extern int mfont__split_name (char *name, int *property_idx,
249                               unsigned short *point, unsigned short *resy);
250
251 extern void mfont__set_spec (MFont *font,
252                              MSymbol attrs[MFONT_PROPERTY_MAX],
253                              unsigned short size, unsigned short resy);
254
255 extern unsigned mfont__flt_encode_char (MSymbol layouter_name, int c);
256
257 extern int mfont__flt_run (MGlyphString *gstring, int from, int to,
258                            MRealizedFace *rface);
259
260 #endif /* _M17N_FONT_H_ */