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