7273db43edaf542ef9d6e969fa2d8408e7d5100e
[platform/upstream/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_H_IN
28 #error "Include <hb.h> instead."
29 #endif
30
31 #ifndef HB_FONT_H
32 #define HB_FONT_H
33
34 #include "hb-common.h"
35 #include "hb-face.h"
36
37 HB_BEGIN_DECLS
38
39
40 typedef struct hb_font_t hb_font_t;
41
42
43 /*
44  * hb_font_funcs_t
45  */
46
47 typedef struct hb_font_funcs_t hb_font_funcs_t;
48
49 hb_font_funcs_t *
50 hb_font_funcs_create (void);
51
52 hb_font_funcs_t *
53 hb_font_funcs_get_empty (void);
54
55 hb_font_funcs_t *
56 hb_font_funcs_reference (hb_font_funcs_t *ffuncs);
57
58 void
59 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs);
60
61 hb_bool_t
62 hb_font_funcs_set_user_data (hb_font_funcs_t    *ffuncs,
63                              hb_user_data_key_t *key,
64                              void *              data,
65                              hb_destroy_func_t   destroy,
66                              hb_bool_t           replace);
67
68
69 void *
70 hb_font_funcs_get_user_data (hb_font_funcs_t    *ffuncs,
71                              hb_user_data_key_t *key);
72
73
74 void
75 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs);
76
77 hb_bool_t
78 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs);
79
80
81 /* glyph extents */
82
83 typedef struct hb_glyph_extents_t
84 {
85   hb_position_t x_bearing;
86   hb_position_t y_bearing;
87   hb_position_t width;
88   hb_position_t height;
89 } hb_glyph_extents_t;
90
91
92 /* func types */
93
94 typedef hb_bool_t (*hb_font_get_glyph_func_t) (hb_font_t *font, void *font_data,
95                                                hb_codepoint_t unicode, hb_codepoint_t variation_selector,
96                                                hb_codepoint_t *glyph,
97                                                void *user_data);
98
99
100 typedef hb_position_t (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void *font_data,
101                                                            hb_codepoint_t glyph,
102                                                            void *user_data);
103 typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_h_advance_func_t;
104 typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_v_advance_func_t;
105
106 typedef hb_bool_t (*hb_font_get_glyph_origin_func_t) (hb_font_t *font, void *font_data,
107                                                       hb_codepoint_t glyph,
108                                                       hb_position_t *x, hb_position_t *y,
109                                                       void *user_data);
110 typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_h_origin_func_t;
111 typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_v_origin_func_t;
112
113 typedef hb_position_t (*hb_font_get_glyph_kerning_func_t) (hb_font_t *font, void *font_data,
114                                                            hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
115                                                            void *user_data);
116 typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_h_kerning_func_t;
117 typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_v_kerning_func_t;
118
119
120 typedef hb_bool_t (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, void *font_data,
121                                                        hb_codepoint_t glyph,
122                                                        hb_glyph_extents_t *extents,
123                                                        void *user_data);
124 typedef hb_bool_t (*hb_font_get_glyph_contour_point_func_t) (hb_font_t *font, void *font_data,
125                                                              hb_codepoint_t glyph, unsigned int point_index,
126                                                              hb_position_t *x, hb_position_t *y,
127                                                              void *user_data);
128
129
130 typedef hb_bool_t (*hb_font_get_glyph_name_func_t) (hb_font_t *font, void *font_data,
131                                                     hb_codepoint_t glyph,
132                                                     char *name, unsigned int size,
133                                                     void *user_data);
134 typedef hb_bool_t (*hb_font_get_glyph_from_name_func_t) (hb_font_t *font, void *font_data,
135                                                          const char *name, int len, /* -1 means nul-terminated */
136                                                          hb_codepoint_t *glyph,
137                                                          void *user_data);
138
139
140 /* func setters */
141
142 /**
143  * hb_font_funcs_set_glyph_func:
144  * @ffuncs: font functions.
145  * @func: (closure user_data) (destroy destroy) (scope notified):
146  * @user_data:
147  * @destroy:
148  *
149  * 
150  *
151  * Since: 1.0
152  **/
153 void
154 hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
155                               hb_font_get_glyph_func_t func,
156                               void *user_data, hb_destroy_func_t destroy);
157
158 /**
159  * hb_font_funcs_set_glyph_h_advance_func:
160  * @ffuncs: font functions.
161  * @func: (closure user_data) (destroy destroy) (scope notified):
162  * @user_data:
163  * @destroy:
164  *
165  * 
166  *
167  * Since: 1.0
168  **/
169 void
170 hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs,
171                                         hb_font_get_glyph_h_advance_func_t func,
172                                         void *user_data, hb_destroy_func_t destroy);
173
174 /**
175  * hb_font_funcs_set_glyph_v_advance_func:
176  * @ffuncs: font functions.
177  * @func: (closure user_data) (destroy destroy) (scope notified):
178  * @user_data:
179  * @destroy:
180  *
181  * 
182  *
183  * Since: 1.0
184  **/
185 void
186 hb_font_funcs_set_glyph_v_advance_func (hb_font_funcs_t *ffuncs,
187                                         hb_font_get_glyph_v_advance_func_t func,
188                                         void *user_data, hb_destroy_func_t destroy);
189
190 /**
191  * hb_font_funcs_set_glyph_h_origin_func:
192  * @ffuncs: font functions.
193  * @func: (closure user_data) (destroy destroy) (scope notified):
194  * @user_data:
195  * @destroy:
196  *
197  * 
198  *
199  * Since: 1.0
200  **/
201 void
202 hb_font_funcs_set_glyph_h_origin_func (hb_font_funcs_t *ffuncs,
203                                        hb_font_get_glyph_h_origin_func_t func,
204                                        void *user_data, hb_destroy_func_t destroy);
205
206 /**
207  * hb_font_funcs_set_glyph_v_origin_func:
208  * @ffuncs: font functions.
209  * @func: (closure user_data) (destroy destroy) (scope notified):
210  * @user_data:
211  * @destroy:
212  *
213  * 
214  *
215  * Since: 1.0
216  **/
217 void
218 hb_font_funcs_set_glyph_v_origin_func (hb_font_funcs_t *ffuncs,
219                                        hb_font_get_glyph_v_origin_func_t func,
220                                        void *user_data, hb_destroy_func_t destroy);
221
222 /**
223  * hb_font_funcs_set_glyph_h_kerning_func:
224  * @ffuncs: font functions.
225  * @func: (closure user_data) (destroy destroy) (scope notified):
226  * @user_data:
227  * @destroy:
228  *
229  * 
230  *
231  * Since: 1.0
232  **/
233 void
234 hb_font_funcs_set_glyph_h_kerning_func (hb_font_funcs_t *ffuncs,
235                                         hb_font_get_glyph_h_kerning_func_t func,
236                                         void *user_data, hb_destroy_func_t destroy);
237
238 /**
239  * hb_font_funcs_set_glyph_v_kerning_func:
240  * @ffuncs: font functions.
241  * @func: (closure user_data) (destroy destroy) (scope notified):
242  * @user_data:
243  * @destroy:
244  *
245  * 
246  *
247  * Since: 1.0
248  **/
249 void
250 hb_font_funcs_set_glyph_v_kerning_func (hb_font_funcs_t *ffuncs,
251                                         hb_font_get_glyph_v_kerning_func_t func,
252                                         void *user_data, hb_destroy_func_t destroy);
253
254 /**
255  * hb_font_funcs_set_glyph_extents_func:
256  * @ffuncs: font functions.
257  * @func: (closure user_data) (destroy destroy) (scope notified):
258  * @user_data:
259  * @destroy:
260  *
261  * 
262  *
263  * Since: 1.0
264  **/
265 void
266 hb_font_funcs_set_glyph_extents_func (hb_font_funcs_t *ffuncs,
267                                       hb_font_get_glyph_extents_func_t func,
268                                       void *user_data, hb_destroy_func_t destroy);
269
270 /**
271  * hb_font_funcs_set_glyph_contour_point_func:
272  * @ffuncs: font functions.
273  * @func: (closure user_data) (destroy destroy) (scope notified):
274  * @user_data:
275  * @destroy:
276  *
277  * 
278  *
279  * Since: 1.0
280  **/
281 void
282 hb_font_funcs_set_glyph_contour_point_func (hb_font_funcs_t *ffuncs,
283                                             hb_font_get_glyph_contour_point_func_t func,
284                                             void *user_data, hb_destroy_func_t destroy);
285
286 /**
287  * hb_font_funcs_set_glyph_name_func:
288  * @ffuncs: font functions.
289  * @func: (closure user_data) (destroy destroy) (scope notified):
290  * @user_data:
291  * @destroy:
292  *
293  * 
294  *
295  * Since: 1.0
296  **/
297 void
298 hb_font_funcs_set_glyph_name_func (hb_font_funcs_t *ffuncs,
299                                    hb_font_get_glyph_name_func_t func,
300                                    void *user_data, hb_destroy_func_t destroy);
301
302 /**
303  * hb_font_funcs_set_glyph_from_name_func:
304  * @ffuncs: font functions.
305  * @func: (closure user_data) (destroy destroy) (scope notified):
306  * @user_data:
307  * @destroy:
308  *
309  * 
310  *
311  * Since: 1.0
312  **/
313 void
314 hb_font_funcs_set_glyph_from_name_func (hb_font_funcs_t *ffuncs,
315                                         hb_font_get_glyph_from_name_func_t func,
316                                         void *user_data, hb_destroy_func_t destroy);
317
318
319 /* func dispatch */
320
321 hb_bool_t
322 hb_font_get_glyph (hb_font_t *font,
323                    hb_codepoint_t unicode, hb_codepoint_t variation_selector,
324                    hb_codepoint_t *glyph);
325
326 hb_position_t
327 hb_font_get_glyph_h_advance (hb_font_t *font,
328                              hb_codepoint_t glyph);
329 hb_position_t
330 hb_font_get_glyph_v_advance (hb_font_t *font,
331                              hb_codepoint_t glyph);
332
333 hb_bool_t
334 hb_font_get_glyph_h_origin (hb_font_t *font,
335                             hb_codepoint_t glyph,
336                             hb_position_t *x, hb_position_t *y);
337 hb_bool_t
338 hb_font_get_glyph_v_origin (hb_font_t *font,
339                             hb_codepoint_t glyph,
340                             hb_position_t *x, hb_position_t *y);
341
342 hb_position_t
343 hb_font_get_glyph_h_kerning (hb_font_t *font,
344                              hb_codepoint_t left_glyph, hb_codepoint_t right_glyph);
345 hb_position_t
346 hb_font_get_glyph_v_kerning (hb_font_t *font,
347                              hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph);
348
349 hb_bool_t
350 hb_font_get_glyph_extents (hb_font_t *font,
351                            hb_codepoint_t glyph,
352                            hb_glyph_extents_t *extents);
353
354 hb_bool_t
355 hb_font_get_glyph_contour_point (hb_font_t *font,
356                                  hb_codepoint_t glyph, unsigned int point_index,
357                                  hb_position_t *x, hb_position_t *y);
358
359 hb_bool_t
360 hb_font_get_glyph_name (hb_font_t *font,
361                         hb_codepoint_t glyph,
362                         char *name, unsigned int size);
363 hb_bool_t
364 hb_font_get_glyph_from_name (hb_font_t *font,
365                              const char *name, int len, /* -1 means nul-terminated */
366                              hb_codepoint_t *glyph);
367
368
369 /* high-level funcs, with fallback */
370
371 void
372 hb_font_get_glyph_advance_for_direction (hb_font_t *font,
373                                          hb_codepoint_t glyph,
374                                          hb_direction_t direction,
375                                          hb_position_t *x, hb_position_t *y);
376 void
377 hb_font_get_glyph_origin_for_direction (hb_font_t *font,
378                                         hb_codepoint_t glyph,
379                                         hb_direction_t direction,
380                                         hb_position_t *x, hb_position_t *y);
381 void
382 hb_font_add_glyph_origin_for_direction (hb_font_t *font,
383                                         hb_codepoint_t glyph,
384                                         hb_direction_t direction,
385                                         hb_position_t *x, hb_position_t *y);
386 void
387 hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
388                                              hb_codepoint_t glyph,
389                                              hb_direction_t direction,
390                                              hb_position_t *x, hb_position_t *y);
391
392 void
393 hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
394                                          hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
395                                          hb_direction_t direction,
396                                          hb_position_t *x, hb_position_t *y);
397
398 hb_bool_t
399 hb_font_get_glyph_extents_for_origin (hb_font_t *font,
400                                       hb_codepoint_t glyph,
401                                       hb_direction_t direction,
402                                       hb_glyph_extents_t *extents);
403
404 hb_bool_t
405 hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
406                                             hb_codepoint_t glyph, unsigned int point_index,
407                                             hb_direction_t direction,
408                                             hb_position_t *x, hb_position_t *y);
409
410 /* Generates gidDDD if glyph has no name. */
411 void
412 hb_font_glyph_to_string (hb_font_t *font,
413                          hb_codepoint_t glyph,
414                          char *s, unsigned int size);
415 /* Parses gidDDD and uniUUUU strings automatically. */
416 hb_bool_t
417 hb_font_glyph_from_string (hb_font_t *font,
418                            const char *s, int len, /* -1 means nul-terminated */
419                            hb_codepoint_t *glyph);
420
421
422 /*
423  * hb_font_t
424  */
425
426 /* Fonts are very light-weight objects */
427
428 hb_font_t *
429 hb_font_create (hb_face_t *face);
430
431 hb_font_t *
432 hb_font_create_sub_font (hb_font_t *parent);
433
434 hb_font_t *
435 hb_font_get_empty (void);
436
437 hb_font_t *
438 hb_font_reference (hb_font_t *font);
439
440 void
441 hb_font_destroy (hb_font_t *font);
442
443 hb_bool_t
444 hb_font_set_user_data (hb_font_t          *font,
445                        hb_user_data_key_t *key,
446                        void *              data,
447                        hb_destroy_func_t   destroy,
448                        hb_bool_t           replace);
449
450
451 void *
452 hb_font_get_user_data (hb_font_t          *font,
453                        hb_user_data_key_t *key);
454
455 void
456 hb_font_make_immutable (hb_font_t *font);
457
458 hb_bool_t
459 hb_font_is_immutable (hb_font_t *font);
460
461 hb_font_t *
462 hb_font_get_parent (hb_font_t *font);
463
464 hb_face_t *
465 hb_font_get_face (hb_font_t *font);
466
467
468 void
469 hb_font_set_funcs (hb_font_t         *font,
470                    hb_font_funcs_t   *klass,
471                    void              *font_data,
472                    hb_destroy_func_t  destroy);
473
474 /* Be *very* careful with this function! */
475 void
476 hb_font_set_funcs_data (hb_font_t         *font,
477                         void              *font_data,
478                         hb_destroy_func_t  destroy);
479
480
481 void
482 hb_font_set_scale (hb_font_t *font,
483                    int x_scale,
484                    int y_scale);
485
486 void
487 hb_font_get_scale (hb_font_t *font,
488                    int *x_scale,
489                    int *y_scale);
490
491 /*
492  * A zero value means "no hinting in that direction"
493  */
494 void
495 hb_font_set_ppem (hb_font_t *font,
496                   unsigned int x_ppem,
497                   unsigned int y_ppem);
498
499 void
500 hb_font_get_ppem (hb_font_t *font,
501                   unsigned int *x_ppem,
502                   unsigned int *y_ppem);
503
504
505 HB_END_DECLS
506
507 #endif /* HB_FONT_H */