bb53f8fec639a8c2f06f4d1ff752bc1dc904c025
[framework/uifw/harfbuzz.git] / src / hb-font.h
1 /*
2  * Copyright © 2009  Red Hat, Inc.
3  *
4  *  This is part of HarfBuzz, a text shaping library.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that the
9  * above copyright notice and the following two paragraphs appear in
10  * all copies of this software.
11  *
12  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16  * DAMAGE.
17  *
18  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  *
24  * Red Hat Author(s): Behdad Esfahbod
25  */
26
27 #ifndef HB_FONT_H
28 #define HB_FONT_H
29
30 #include "hb-common.h"
31 #include "hb-blob.h"
32
33 HB_BEGIN_DECLS
34
35
36 typedef struct _hb_face_t hb_face_t;
37 typedef struct _hb_font_t hb_font_t;
38
39 /*
40  * hb_face_t
41  */
42
43 hb_face_t *
44 hb_face_create (hb_blob_t    *blob,
45                 unsigned int  index);
46
47 typedef hb_blob_t * (*hb_get_table_func_t)  (hb_tag_t tag, void *user_data);
48
49 /* calls destroy() when not needing user_data anymore */
50 hb_face_t *
51 hb_face_create_for_tables (hb_get_table_func_t  get_table,
52                            void                *user_data,
53                            hb_destroy_func_t    destroy);
54
55 hb_face_t *
56 hb_face_get_empty (void);
57
58 hb_face_t *
59 hb_face_reference (hb_face_t *face);
60
61 void
62 hb_face_destroy (hb_face_t *face);
63
64 hb_bool_t
65 hb_face_set_user_data (hb_face_t          *face,
66                        hb_user_data_key_t *key,
67                        void *              data,
68                        hb_destroy_func_t   destroy);
69
70
71 void *
72 hb_face_get_user_data (hb_face_t          *face,
73                        hb_user_data_key_t *key);
74
75
76 hb_blob_t *
77 hb_face_reference_table (hb_face_t *face,
78                          hb_tag_t   tag);
79
80 unsigned int
81 hb_face_get_upem (hb_face_t *face);
82
83
84 /*
85  * hb_font_funcs_t
86  */
87
88 typedef struct _hb_font_funcs_t hb_font_funcs_t;
89
90 hb_font_funcs_t *
91 hb_font_funcs_create (void);
92
93 hb_font_funcs_t *
94 hb_font_funcs_get_empty (void);
95
96 hb_font_funcs_t *
97 hb_font_funcs_reference (hb_font_funcs_t *ffuncs);
98
99 void
100 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs);
101
102 hb_bool_t
103 hb_font_funcs_set_user_data (hb_font_funcs_t    *ffuncs,
104                              hb_user_data_key_t *key,
105                              void *              data,
106                              hb_destroy_func_t   destroy);
107
108
109 void *
110 hb_font_funcs_get_user_data (hb_font_funcs_t    *ffuncs,
111                              hb_user_data_key_t *key);
112
113
114 void
115 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs);
116
117 hb_bool_t
118 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs);
119
120 /* funcs */
121
122 typedef struct _hb_glyph_extents_t
123 {
124     hb_position_t x_bearing;
125     hb_position_t y_bearing;
126     hb_position_t width;
127     hb_position_t height;
128 } hb_glyph_extents_t;
129
130
131 typedef hb_bool_t (*hb_font_get_contour_point_func_t) (hb_font_t *font, void *font_data,
132                                                        hb_codepoint_t glyph, unsigned int point_index,
133                                                        hb_position_t *x, hb_position_t *y,
134                                                        void *user_data);
135 typedef void (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void *font_data,
136                                                   hb_codepoint_t glyph,
137                                                   hb_position_t *x_advance, hb_position_t *y_advance,
138                                                   void *user_data);
139 typedef void (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, void *font_data,
140                                                   hb_codepoint_t glyph,
141                                                   hb_glyph_extents_t *extents,
142                                                   void *user_data);
143 typedef hb_codepoint_t (*hb_font_get_glyph_func_t) (hb_font_t *font, void *font_data,
144                                                     hb_codepoint_t unicode, hb_codepoint_t variation_selector,
145                                                     void *user_data);
146 typedef void (*hb_font_get_kerning_func_t) (hb_font_t *font, void *font_data,
147                                             hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
148                                             hb_position_t *x_kern, hb_position_t *y_kern,
149                                             void *user_data);
150
151
152 void
153 hb_font_funcs_set_contour_point_func (hb_font_funcs_t *ffuncs,
154                                       hb_font_get_contour_point_func_t contour_point_func,
155                                       void *user_data, hb_destroy_func_t destroy);
156
157 void
158 hb_font_funcs_set_glyph_advance_func (hb_font_funcs_t *ffuncs,
159                                       hb_font_get_glyph_advance_func_t glyph_advance_func,
160                                       void *user_data, hb_destroy_func_t destroy);
161
162 void
163 hb_font_funcs_set_glyph_extents_func (hb_font_funcs_t *ffuncs,
164                                       hb_font_get_glyph_extents_func_t glyph_extents_func,
165                                       void *user_data, hb_destroy_func_t destroy);
166
167 void
168 hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
169                               hb_font_get_glyph_func_t glyph_func,
170                               void *user_data, hb_destroy_func_t destroy);
171
172 void
173 hb_font_funcs_set_kerning_func (hb_font_funcs_t *ffuncs,
174                                 hb_font_get_kerning_func_t kerning_func,
175                                 void *user_data, hb_destroy_func_t destroy);
176
177
178 hb_bool_t
179 hb_font_get_contour_point (hb_font_t *font,
180                            hb_codepoint_t glyph, unsigned int point_index,
181                            hb_position_t *x, hb_position_t *y);
182
183 void
184 hb_font_get_glyph_advance (hb_font_t *font,
185                            hb_codepoint_t glyph,
186                            hb_position_t *x_advance, hb_position_t *y_advance);
187
188 void
189 hb_font_get_glyph_extents (hb_font_t *font,
190                            hb_codepoint_t glyph,
191                            hb_glyph_extents_t *extents);
192
193 hb_codepoint_t
194 hb_font_get_glyph (hb_font_t *font,
195                    hb_codepoint_t unicode, hb_codepoint_t variation_selector);
196
197 void
198 hb_font_get_kerning (hb_font_t *font,
199                      hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
200                      hb_position_t *x_kern, hb_position_t *y_kern);
201
202
203 /*
204  * hb_font_t
205  */
206
207 /* Fonts are very light-weight objects */
208
209 hb_font_t *
210 hb_font_create (hb_face_t *face);
211
212 hb_font_t *
213 hb_font_create_sub_font (hb_font_t *parent);
214
215 hb_font_t *
216 hb_font_get_empty (void);
217
218 hb_font_t *
219 hb_font_reference (hb_font_t *font);
220
221 void
222 hb_font_destroy (hb_font_t *font);
223
224 hb_bool_t
225 hb_font_set_user_data (hb_font_t          *font,
226                        hb_user_data_key_t *key,
227                        void *              data,
228                        hb_destroy_func_t   destroy);
229
230
231 void *
232 hb_font_get_user_data (hb_font_t          *font,
233                        hb_user_data_key_t *key);
234
235 void
236 hb_font_make_immutable (hb_font_t *font);
237
238 hb_bool_t
239 hb_font_is_immutable (hb_font_t *font);
240
241 hb_font_t *
242 hb_font_get_parent (hb_font_t *font);
243
244 hb_face_t *
245 hb_font_get_face (hb_font_t *font);
246
247
248 void
249 hb_font_set_funcs (hb_font_t         *font,
250                    hb_font_funcs_t   *klass,
251                    void              *font_data,
252                    hb_destroy_func_t  destroy);
253
254
255 /*
256  * We should add support for full matrices.
257  */
258 void
259 hb_font_set_scale (hb_font_t *font,
260                    int x_scale,
261                    int y_scale);
262
263 void
264 hb_font_get_scale (hb_font_t *font,
265                    int *x_scale,
266                    int *y_scale);
267
268 /*
269  * A zero value means "no hinting in that direction"
270  */
271 void
272 hb_font_set_ppem (hb_font_t *font,
273                   unsigned int x_ppem,
274                   unsigned int y_ppem);
275
276 void
277 hb_font_get_ppem (hb_font_t *font,
278                   unsigned int *x_ppem,
279                   unsigned int *y_ppem);
280
281
282 HB_END_DECLS
283
284 #endif /* HB_FONT_H */