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