Always allocate new ligature id
[framework/uifw/harfbuzz.git] / src / hb-font.h
1 /*
2  * Copyright (C) 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_for_data (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                            hb_destroy_func_t    destroy,
53                            void                *user_data);
54
55 hb_face_t *
56 hb_face_reference (hb_face_t *face);
57
58 unsigned int
59 hb_face_get_reference_count (hb_face_t *face);
60
61 void
62 hb_face_destroy (hb_face_t *face);
63
64 /* XXX
65  *
66  * I have two major concerns about this API as it is right now:
67  *
68  *   - Jonathan Kew convinced me to make it return NULL if table not found (280af1bd),
69  *     however, that is WRONG IMO.  The API should not differentiate between a non-existing
70  *     table vs a zero-length table vs a very short table.  It only leads to implementations
71  *     that check for non-NULL and assume that they've got a usable table going on...  This
72  *     actually happened with Firefox.
73  *
74  *   - It has to be renamed to reference_table() since unlike any other _get_ API, a reference
75  *     ownership transfer happens and the user is responsible to destroy the result.
76  */
77 hb_blob_t *
78 hb_face_get_table (hb_face_t *face,
79                    hb_tag_t   tag);
80
81 unsigned int
82 hb_face_get_upem (hb_face_t *face);
83
84
85 /*
86  * hb_font_funcs_t
87  */
88
89 typedef struct _hb_font_funcs_t hb_font_funcs_t;
90
91 hb_font_funcs_t *
92 hb_font_funcs_create (void);
93
94 hb_font_funcs_t *
95 hb_font_funcs_reference (hb_font_funcs_t *ffuncs);
96
97 unsigned int
98 hb_font_funcs_get_reference_count (hb_font_funcs_t *ffuncs);
99
100 void
101 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs);
102
103 hb_font_funcs_t *
104 hb_font_funcs_copy (hb_font_funcs_t *ffuncs);
105
106 void
107 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs);
108
109 hb_bool_t
110 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs);
111
112 /* funcs */
113
114 typedef struct _hb_glyph_extents_t
115 {
116     hb_position_t x_bearing;
117     hb_position_t y_bearing;
118     hb_position_t width;
119     hb_position_t height;
120 } hb_glyph_extents_t;
121
122 typedef hb_codepoint_t (*hb_font_get_glyph_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
123                                                     hb_codepoint_t unicode, hb_codepoint_t variation_selector);
124 typedef void (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
125                                                   hb_codepoint_t glyph,
126                                                   hb_position_t *x_advance, hb_position_t *y_advance);
127 typedef void (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
128                                                   hb_codepoint_t glyph,
129                                                   hb_glyph_extents_t *metrics);
130 typedef hb_bool_t (*hb_font_get_contour_point_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
131                                                        unsigned int point_index, hb_codepoint_t glyph,
132                                                        hb_position_t *x, hb_position_t *y);
133 typedef hb_position_t (*hb_font_get_kerning_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
134                                                      hb_codepoint_t first_glyph, hb_codepoint_t second_glyph);
135
136
137 void
138 hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
139                               hb_font_get_glyph_func_t glyph_func);
140
141 void
142 hb_font_funcs_set_glyph_advance_func (hb_font_funcs_t *ffuncs,
143                                       hb_font_get_glyph_advance_func_t glyph_advance_func);
144
145 void
146 hb_font_funcs_set_glyph_extents_func (hb_font_funcs_t *ffuncs,
147                                       hb_font_get_glyph_extents_func_t glyph_extents_func);
148
149 void
150 hb_font_funcs_set_contour_point_func (hb_font_funcs_t *ffuncs,
151                                       hb_font_get_contour_point_func_t contour_point_func);
152
153 void
154 hb_font_funcs_set_kerning_func (hb_font_funcs_t *ffuncs,
155                                 hb_font_get_kerning_func_t kerning_func);
156
157
158 /* These never return NULL.  Return fallback defaults instead. */
159
160 hb_font_get_glyph_func_t
161 hb_font_funcs_get_glyph_func (hb_font_funcs_t *ffuncs);
162
163 hb_font_get_glyph_advance_func_t
164 hb_font_funcs_get_glyph_advance_func (hb_font_funcs_t *ffuncs);
165
166 hb_font_get_glyph_extents_func_t
167 hb_font_funcs_get_glyph_extents_func (hb_font_funcs_t *ffuncs);
168
169 hb_font_get_contour_point_func_t
170 hb_font_funcs_get_contour_point_func (hb_font_funcs_t *ffuncs);
171
172 hb_font_get_kerning_func_t
173 hb_font_funcs_get_kerning_func (hb_font_funcs_t *ffuncs);
174
175
176 hb_codepoint_t
177 hb_font_get_glyph (hb_font_t *font, hb_face_t *face,
178                    hb_codepoint_t unicode, hb_codepoint_t variation_selector);
179
180 void
181 hb_font_get_glyph_advance (hb_font_t *font, hb_face_t *face,
182                            hb_codepoint_t glyph,
183                            hb_position_t *x_advance, hb_position_t *y_advance);
184
185 void
186 hb_font_get_glyph_extents (hb_font_t *font, hb_face_t *face,
187                            hb_codepoint_t glyph,
188                            hb_glyph_extents_t *metrics);
189
190 hb_bool_t
191 hb_font_get_contour_point (hb_font_t *font, hb_face_t *face,
192                            unsigned int point_index, hb_codepoint_t glyph,
193                            hb_position_t *x, hb_position_t *y);
194
195 hb_position_t
196 hb_font_get_kerning (hb_font_t *font, hb_face_t *face,
197                      hb_codepoint_t first_glyph, hb_codepoint_t second_glyph);
198
199
200 /*
201  * hb_font_t
202  */
203
204 /* Fonts are very light-weight objects */
205
206 hb_font_t *
207 hb_font_create (void);
208
209 hb_font_t *
210 hb_font_reference (hb_font_t *font);
211
212 unsigned int
213 hb_font_get_reference_count (hb_font_t *font);
214
215 void
216 hb_font_destroy (hb_font_t *font);
217
218 void
219 hb_font_set_funcs (hb_font_t         *font,
220                    hb_font_funcs_t   *klass,
221                    hb_destroy_func_t  destroy,
222                    void              *user_data);
223
224 /* Returns what was set and unsets it, but doesn't destroy(user_data).
225  * This is useful for wrapping / chaining font_funcs_t's.
226  *
227  * The client is responsible for:
228  *
229  *   - Take ownership of the reference on the returned klass,
230  *
231  *   - Calling "destroy(user_data)" exactly once if returned destroy func
232  *     is not NULL and the returned info is not needed anymore.
233  */
234 void
235 hb_font_unset_funcs (hb_font_t          *font,
236                      hb_font_funcs_t   **klass,
237                      hb_destroy_func_t  *destroy,
238                      void              **user_data);
239
240
241 /*
242  * We should add support for full matrices.
243  */
244 void
245 hb_font_set_scale (hb_font_t *font,
246                    unsigned int x_scale,
247                    unsigned int y_scale);
248
249 void
250 hb_font_get_scale (hb_font_t *font,
251                    unsigned int *x_scale,
252                    unsigned int *y_scale);
253
254 /*
255  * A zero value means "no hinting in that direction"
256  */
257 void
258 hb_font_set_ppem (hb_font_t *font,
259                   unsigned int x_ppem,
260                   unsigned int y_ppem);
261
262 void
263 hb_font_get_ppem (hb_font_t *font,
264                   unsigned int *x_ppem,
265                   unsigned int *y_ppem);
266
267
268 HB_END_DECLS
269
270 #endif /* HB_FONT_H */