Handle the case of _M17N_H_ being defined.
[m17n/m17n-lib.git] / src / m17n-flt.h
1 /* m17n-flt.h -- header file for the FLT API of the m17n library.
2    Copyright (C) 2007
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., 51 Franklin Street, Fifth Floor,
21    02111-1307, USA.  */
22
23 #ifndef _M17N_FLT_H_
24 #define _M17N_FLT_H_
25
26 #ifndef _M17N_CORE_H_
27 #include <m17n-core.h>
28 #endif
29
30 M17N_BEGIN_HEADER
31
32 #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
33
34 extern void m17n_init_flt (int);
35 #undef M17N_INIT
36 #ifdef _M17N_H_
37 #define M17N_INIT() m17n_init_flt (1)
38 #else  /* not _M17N_H_ */
39 #define M17N_INIT() m17n_init_flt (0)
40 #endif  /* not _M17N_H_ */
41
42 extern void m17n_fini_flt (int);
43 #undef M17N_FINI
44 #ifdef _M17N_H_
45 #define M17N_FINI() m17n_fini_flt (1)
46 #else  /* not _M17N_H_ */
47 #define M17N_FINI() m17n_fini_flt (0)
48 #endif  /* not _M17N_H_ */
49
50 #endif
51
52 /***en @defgroup m17nFLT FLT API */
53 /***ja @defgroup m17nFLT FLT API */
54 /*=*/
55
56 /*** @addtogroup m17nFLT */
57 /*** @{ */
58 /*=*/
59
60 /***en
61     @brief Type of information about a glyph.
62
63     The type #MFLTGlyph is the structure that contains information
64     about a glyph.  */
65
66 typedef struct _MFLTGlyph MFLTGlyph;
67
68 struct _MFLTGlyph
69 {
70   /***en @brief Character code (Unicode) of the glyph.  This is the sole
71       member to be set before calling the functions mflt_find () and
72       mflt_run ().  */
73   int c;
74   /***en Glyph-id of the font of the glyph.  */
75   unsigned int code;
76   /***en Glyph indices indicating the start of the original glyphs.  */
77   int from;
78   /***en Glyph indices indicating the end of the original glyphs.  */
79   int to;
80   /***en Advance width for horizontal layout expressed in 26.6
81       fractional pixel format.  */
82   int xadv;
83   /***en Advance height for vertical layout expressed in 26.6
84       fractional pixel format.  */
85   int yadv;
86   /***en Ink metrics of the glyph expressed in 26.6 fractional pixel
87       format.  */
88   int ascent, descent, lbearing, rbearing;
89   /***en Horizontal and vertical adjustments for the glyph positioning
90       expressed in 26.6 fractional pixel format.  */
91   int xoff, yoff;
92   /***en Flag to tell if the member <code> is already encoded into a
93       glyph ID of a font.  */
94   unsigned encoded : 1;
95   /***en Flag to tell if the metrics of the glyph (members <xadv> thru
96       <rbearing>) are already calculated.  */
97   unsigned measured : 1;
98   /***en Flag to tell if the metrics of the glyph is adjusted,
99       i.e. <xadv> or <yadv> is different from the normal size, or
100       <xoff> or <yoff> is nonzero.  */
101   unsigned adjusted : 1;
102   /***en For m17n-lib's internal use only.  */
103   unsigned internal : 30;
104
105   /* Arbitrary data can follow.  */
106 };
107
108 /*=*/
109
110 /***en
111     @brief Type of information about a glyph position adjustment.
112
113     The type #MFLTGlyphAdjustment is the structure to store
114     information about a glyph metrics/position adjustment.  It is
115     given to the callback function #drive_otf of #MFLTFont.  */
116
117 typedef struct _MFLTGlyphAdjustment MFLTGlyphAdjustment;
118
119 struct _MFLTGlyphAdjustment
120 {
121   /***en Adjustments for advance width for horizontal layout and
122       advance height for vertical layout expressed in 26.6 fractional
123       pixel format.  */
124   int xadv, yadv;
125   /***en Horizontal and vertical adjustments for a glyph positioning
126       expressed in 26.6 fractional pixel format.  */
127   int xoff, yoff;
128   /***en Number of glyphs to go back for drawing a glyph.  */
129   short back;
130   /***en If nonzero, the member <xadv> and <yadv> are absolute, i.e.,
131       they should not be added to a glyph's origianl advance width and
132       height.  */
133   unsigned advance_is_absolute : 1;
134   /***en Should be set to 1 iff at least one of the other members has
135       a nonzero value.  */
136   unsigned set : 1;
137 };
138
139 /***en
140     @brief Type of information about a glyph sequence.
141
142     The type #MFLTGlyphString is the structure that contains
143     information about a sequence of glyphs.  */
144
145 typedef struct _MFLTGlyphString MFLTGlyphString;
146
147 struct _MFLTGlyphString
148 {
149   /***en The actual byte size of elements of the array pointed by the
150       member #glyphs.  It must be equal to or greater than "sizeof
151       (MFLTGlyph)".  */
152   int glyph_size;
153   /***en Array of glyphs.  */
154   MFLTGlyph *glyphs;
155   /***en How many elements are allocated in #glyphs.  */
156   int allocated;
157   /***en How many elements in #glyphs are in use.  */
158   int used;
159   /***en Flag to tell if the glyphs should be drawn from right-to-left
160       or not.  */
161   unsigned int r2l;
162 };
163
164 /***en
165     @brief Type of specification of GSUB and GPOS OpenType tables.
166
167     The type #MFLTOtfSpec is the structure that contains information
168     about GSUB and GPOS features of a specific script and language
169     system to be applied to a glyph sequence.  */
170
171 typedef struct _MFLTOtfSpec MFLTOtfSpec;
172
173 struct _MFLTOtfSpec
174 {
175   /***en Unique symbol representing the spec.  This is the same as the
176       #OTF-SPEC of the FLT.  */
177   MSymbol sym;
178
179   /***en Tags for script and language system.  */
180   unsigned int script, langsys;
181
182   /***en Array of GSUB (1st element) and GPOS (2nd element) features.
183       Each array is terminated by 0.  If an element is 0xFFFFFFFF,
184       apply the previous features in that order, and apply all the
185       other features except those appearing in the following elements.
186       It may be NULL if there's no feature.  */
187   unsigned int *features[2];
188 };
189
190 /***en
191     @brief Type of font to be used by the FLT driver.
192
193     The type #MFLTFont is the structure that contains information
194     about a font used by the FLT driver.  */
195
196 typedef struct _MFLTFont MFLTFont;
197
198 struct _MFLTFont
199 {
200   /***en Family name of the font.  It may be #Mnil if the family name
201      is not important in finding a Font Layout Table suitable for the
202      font (for instance, in the case that the font is an OpenType
203      font).  */
204   MSymbol family;
205
206   /***en Horizontal and vertical font sizes in pixel per EM.  */
207   int x_ppem, y_ppem;
208
209   /***en Callback function to get glyph IDs for glyphs between FROM
210      (inclusive) and TO (exclusive) of GSTRING.  If <encoded> member
211      of a glyph is zero, the <code> member of the glyph is a character
212      code.  The function must convert it to the glyph ID of FONT.  */
213   int (*get_glyph_id) (MFLTFont *font, MFLTGlyphString *gstring,
214                        int from, int to);
215
216   /*** Callback function to get metrics of glyphs between FROM
217      (inclusive) and TO (exclusive) of GSTRING.  If <measured> member
218      of a glyph is zero, the function must set members <xadv>, <yadv>,
219      <ascent>, <descent>, <lbearing>, and <rbearing> of the glyph.  */
220   int (*get_metrics) (MFLTFont *font, MFLTGlyphString *gstring,
221                      int from, int to);
222
223   /***en Callback function to check if the font has OpenType GSUB/GPOS
224      features for a specific script/language.  The function must
225      return 1 if the font satisfy SPEC, else return 0.  It must be
226      NULL if the font doesn't have OpenType tables.  */
227   int (*check_otf) (MFLTFont *font, MFLTOtfSpec *spec);
228
229   /*** Callback function to apply OpenType features in SPEC to glyphs
230      between FROM (inclusive) and TO (exclusive) of IN.  The resulting
231      glyphs should be appended to the tail of OUT.  If OUT doesn't
232      have a room to store all resulting glyphs, it must return -2.
233      It must be NULL if the font doesn't have OpenType tables.  */
234   int (*drive_otf) (MFLTFont *font, MFLTOtfSpec *spec,
235                     MFLTGlyphString *in, int from, int to,
236                     MFLTGlyphString *out, MFLTGlyphAdjustment *adjustment);
237
238   /***en For m17n-lib's internal use only.  It should be initialized
239       to NULL.  */
240   void *internal;
241 };
242
243 /***en
244     @brief Type of FLT (Font Layout Table).
245
246     The type #MFLT is for a FLT object.  Its internal structure is
247     concealed from application program.  */
248
249 typedef struct _MFLT MFLT;
250
251 extern MFLT *mflt_get (MSymbol name);
252
253 extern MFLT *mflt_find (int c, MFLTFont *font);
254
255 extern const char *mflt_name (MFLT *flt);
256
257 extern MCharTable *mflt_coverage (MFLT *flt);
258
259 extern int mflt_run (MFLTGlyphString *gstring, int from, int to,
260                      MFLTFont *font, MFLT *flt);
261
262 /*=*/
263 /*** @} */
264
265 M17N_END_HEADER
266
267 #endif /* _M17N_FLT_H_ */
268
269 /*
270   Local Variables:
271   coding: euc-japan
272   End:
273 */