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
37HB_BEGIN_DECLS
38
39
40typedef struct hb_font_t hb_font_t;
41
42
43/*
44 * hb_font_funcs_t
45 */
46
47typedef struct hb_font_funcs_t hb_font_funcs_t;
48
49HB_EXTERN hb_font_funcs_t *
50hb_font_funcs_create (void);
51
52HB_EXTERN hb_font_funcs_t *
53hb_font_funcs_get_empty (void);
54
55HB_EXTERN hb_font_funcs_t *
56hb_font_funcs_reference (hb_font_funcs_t *ffuncs);
57
58HB_EXTERN void
59hb_font_funcs_destroy (hb_font_funcs_t *ffuncs);
60
61HB_EXTERN hb_bool_t
62hb_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
69HB_EXTERN void *
70hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
71 hb_user_data_key_t *key);
72
73
74HB_EXTERN void
75hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs);
76
77HB_EXTERN hb_bool_t
78hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs);
79
80
81/* font and glyph extents */
82
83/* Note that typically ascender is positive and descender negative in coordinate systems that grow up. */
84typedef struct hb_font_extents_t
85{
86 hb_position_t ascender; /* typographic ascender. */
87 hb_position_t descender; /* typographic descender. */
88 hb_position_t line_gap; /* suggested line spacing gap. */
89 /*< private >*/
90 hb_position_t reserved9;
91 hb_position_t reserved8;
92 hb_position_t reserved7;
93 hb_position_t reserved6;
94 hb_position_t reserved5;
95 hb_position_t reserved4;
96 hb_position_t reserved3;
97 hb_position_t reserved2;
98 hb_position_t reserved1;
99} hb_font_extents_t;
100
101/* Note that height is negative in coordinate systems that grow up. */
102typedef struct hb_glyph_extents_t
103{
104 hb_position_t x_bearing; /* left side of glyph from origin. */
105 hb_position_t y_bearing; /* top side of glyph from origin. */
106 hb_position_t width; /* distance from left to right side. */
107 hb_position_t height; /* distance from top to bottom side. */
108} hb_glyph_extents_t;
109
110/* func types */
111
112typedef hb_bool_t (*hb_font_get_font_extents_func_t) (hb_font_t *font, void *font_data,
113 hb_font_extents_t *extents,
114 void *user_data);
115typedef hb_font_get_font_extents_func_t hb_font_get_font_h_extents_func_t;
116typedef hb_font_get_font_extents_func_t hb_font_get_font_v_extents_func_t;
117
118
119typedef hb_bool_t (*hb_font_get_nominal_glyph_func_t) (hb_font_t *font, void *font_data,
120 hb_codepoint_t unicode,
121 hb_codepoint_t *glyph,
122 void *user_data);
123typedef hb_bool_t (*hb_font_get_variation_glyph_func_t) (hb_font_t *font, void *font_data,
124 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
125 hb_codepoint_t *glyph,
126 void *user_data);
127
128typedef unsigned int (*hb_font_get_nominal_glyphs_func_t) (hb_font_t *font, void *font_data,
129 unsigned int count,
130 const hb_codepoint_t *first_unicode,
131 unsigned int unicode_stride,
132 hb_codepoint_t *first_glyph,
133 unsigned int glyph_stride,
134 void *user_data);
135
136
137typedef hb_position_t (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void *font_data,
138 hb_codepoint_t glyph,
139 void *user_data);
140typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_h_advance_func_t;
141typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_v_advance_func_t;
142
143typedef void (*hb_font_get_glyph_advances_func_t) (hb_font_t* font, void* font_data,
144 unsigned int count,
145 const hb_codepoint_t *first_glyph,
146 unsigned glyph_stride,
147 hb_position_t *first_advance,
148 unsigned advance_stride,
149 void *user_data);
150typedef hb_font_get_glyph_advances_func_t hb_font_get_glyph_h_advances_func_t;
151typedef hb_font_get_glyph_advances_func_t hb_font_get_glyph_v_advances_func_t;
152
153typedef hb_bool_t (*hb_font_get_glyph_origin_func_t) (hb_font_t *font, void *font_data,
154 hb_codepoint_t glyph,
155 hb_position_t *x, hb_position_t *y,
156 void *user_data);
157typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_h_origin_func_t;
158typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_v_origin_func_t;
159
160
161typedef hb_bool_t (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, void *font_data,
162 hb_codepoint_t glyph,
163 hb_glyph_extents_t *extents,
164 void *user_data);
165typedef hb_bool_t (*hb_font_get_glyph_contour_point_func_t) (hb_font_t *font, void *font_data,
166 hb_codepoint_t glyph, unsigned int point_index,
167 hb_position_t *x, hb_position_t *y,
168 void *user_data);
169
170
171typedef hb_bool_t (*hb_font_get_glyph_name_func_t) (hb_font_t *font, void *font_data,
172 hb_codepoint_t glyph,
173 char *name, unsigned int size,
174 void *user_data);
175typedef hb_bool_t (*hb_font_get_glyph_from_name_func_t) (hb_font_t *font, void *font_data,
176 const char *name, int len, /* -1 means nul-terminated */
177 hb_codepoint_t *glyph,
178 void *user_data);
179
180
181/* func setters */
182
183/**
184 * hb_font_funcs_set_font_h_extents_func:
185 * @ffuncs: font functions.
186 * @func: (closure user_data) (destroy destroy) (scope notified):
187 * @user_data:
188 * @destroy:
189 *
190 *
191 *
192 * Since: 1.1.2
193 **/
194HB_EXTERN void
195hb_font_funcs_set_font_h_extents_func (hb_font_funcs_t *ffuncs,
196 hb_font_get_font_h_extents_func_t func,
197 void *user_data, hb_destroy_func_t destroy);
198
199/**
200 * hb_font_funcs_set_font_v_extents_func:
201 * @ffuncs: font functions.
202 * @func: (closure user_data) (destroy destroy) (scope notified):
203 * @user_data:
204 * @destroy:
205 *
206 *
207 *
208 * Since: 1.1.2
209 **/
210HB_EXTERN void
211hb_font_funcs_set_font_v_extents_func (hb_font_funcs_t *ffuncs,
212 hb_font_get_font_v_extents_func_t func,
213 void *user_data, hb_destroy_func_t destroy);
214
215/**
216 * hb_font_funcs_set_nominal_glyph_func:
217 * @ffuncs: font functions.
218 * @func: (closure user_data) (destroy destroy) (scope notified):
219 * @user_data:
220 * @destroy:
221 *
222 *
223 *
224 * Since: 1.2.3
225 **/
226HB_EXTERN void
227hb_font_funcs_set_nominal_glyph_func (hb_font_funcs_t *ffuncs,
228 hb_font_get_nominal_glyph_func_t func,
229 void *user_data, hb_destroy_func_t destroy);
230
231/**
232 * hb_font_funcs_set_nominal_glyphs_func:
233 * @ffuncs: font functions.
234 * @func: (closure user_data) (destroy destroy) (scope notified):
235 * @user_data:
236 * @destroy:
237 *
238 *
239 *
240 * Since: 2.0.0
241 **/
242HB_EXTERN void
243hb_font_funcs_set_nominal_glyphs_func (hb_font_funcs_t *ffuncs,
244 hb_font_get_nominal_glyphs_func_t func,
245 void *user_data, hb_destroy_func_t destroy);
246
247/**
248 * hb_font_funcs_set_variation_glyph_func:
249 * @ffuncs: font functions.
250 * @func: (closure user_data) (destroy destroy) (scope notified):
251 * @user_data:
252 * @destroy:
253 *
254 *
255 *
256 * Since: 1.2.3
257 **/
258HB_EXTERN void
259hb_font_funcs_set_variation_glyph_func (hb_font_funcs_t *ffuncs,
260 hb_font_get_variation_glyph_func_t func,
261 void *user_data, hb_destroy_func_t destroy);
262
263/**
264 * hb_font_funcs_set_glyph_h_advance_func:
265 * @ffuncs: font functions.
266 * @func: (closure user_data) (destroy destroy) (scope notified):
267 * @user_data:
268 * @destroy:
269 *
270 *
271 *
272 * Since: 0.9.2
273 **/
274HB_EXTERN void
275hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs,
276 hb_font_get_glyph_h_advance_func_t func,
277 void *user_data, hb_destroy_func_t destroy);
278
279/**
280 * hb_font_funcs_set_glyph_v_advance_func:
281 * @ffuncs: font functions.
282 * @func: (closure user_data) (destroy destroy) (scope notified):
283 * @user_data:
284 * @destroy:
285 *
286 *
287 *
288 * Since: 0.9.2
289 **/
290HB_EXTERN void
291hb_font_funcs_set_glyph_v_advance_func (hb_font_funcs_t *ffuncs,
292 hb_font_get_glyph_v_advance_func_t func,
293 void *user_data, hb_destroy_func_t destroy);
294
295/**
296 * hb_font_funcs_set_glyph_h_advances_func:
297 * @ffuncs: font functions.
298 * @func: (closure user_data) (destroy destroy) (scope notified):
299 * @user_data:
300 * @destroy:
301 *
302 *
303 *
304 * Since: 1.8.6
305 **/
306HB_EXTERN void
307hb_font_funcs_set_glyph_h_advances_func (hb_font_funcs_t *ffuncs,
308 hb_font_get_glyph_h_advances_func_t func,
309 void *user_data, hb_destroy_func_t destroy);
310
311/**
312 * hb_font_funcs_set_glyph_v_advances_func:
313 * @ffuncs: font functions.
314 * @func: (closure user_data) (destroy destroy) (scope notified):
315 * @user_data:
316 * @destroy:
317 *
318 *
319 *
320 * Since: 1.8.6
321 **/
322HB_EXTERN void
323hb_font_funcs_set_glyph_v_advances_func (hb_font_funcs_t *ffuncs,
324 hb_font_get_glyph_v_advances_func_t func,
325 void *user_data, hb_destroy_func_t destroy);
326
327/**
328 * hb_font_funcs_set_glyph_h_origin_func:
329 * @ffuncs: font functions.
330 * @func: (closure user_data) (destroy destroy) (scope notified):
331 * @user_data:
332 * @destroy:
333 *
334 *
335 *
336 * Since: 0.9.2
337 **/
338HB_EXTERN void
339hb_font_funcs_set_glyph_h_origin_func (hb_font_funcs_t *ffuncs,
340 hb_font_get_glyph_h_origin_func_t func,
341 void *user_data, hb_destroy_func_t destroy);
342
343/**
344 * hb_font_funcs_set_glyph_v_origin_func:
345 * @ffuncs: font functions.
346 * @func: (closure user_data) (destroy destroy) (scope notified):
347 * @user_data:
348 * @destroy:
349 *
350 *
351 *
352 * Since: 0.9.2
353 **/
354HB_EXTERN void
355hb_font_funcs_set_glyph_v_origin_func (hb_font_funcs_t *ffuncs,
356 hb_font_get_glyph_v_origin_func_t func,
357 void *user_data, hb_destroy_func_t destroy);
358
359/**
360 * hb_font_funcs_set_glyph_extents_func:
361 * @ffuncs: font functions.
362 * @func: (closure user_data) (destroy destroy) (scope notified):
363 * @user_data:
364 * @destroy:
365 *
366 *
367 *
368 * Since: 0.9.2
369 **/
370HB_EXTERN void
371hb_font_funcs_set_glyph_extents_func (hb_font_funcs_t *ffuncs,
372 hb_font_get_glyph_extents_func_t func,
373 void *user_data, hb_destroy_func_t destroy);
374
375/**
376 * hb_font_funcs_set_glyph_contour_point_func:
377 * @ffuncs: font functions.
378 * @func: (closure user_data) (destroy destroy) (scope notified):
379 * @user_data:
380 * @destroy:
381 *
382 *
383 *
384 * Since: 0.9.2
385 **/
386HB_EXTERN void
387hb_font_funcs_set_glyph_contour_point_func (hb_font_funcs_t *ffuncs,
388 hb_font_get_glyph_contour_point_func_t func,
389 void *user_data, hb_destroy_func_t destroy);
390
391/**
392 * hb_font_funcs_set_glyph_name_func:
393 * @ffuncs: font functions.
394 * @func: (closure user_data) (destroy destroy) (scope notified):
395 * @user_data:
396 * @destroy:
397 *
398 *
399 *
400 * Since: 0.9.2
401 **/
402HB_EXTERN void
403hb_font_funcs_set_glyph_name_func (hb_font_funcs_t *ffuncs,
404 hb_font_get_glyph_name_func_t func,
405 void *user_data, hb_destroy_func_t destroy);
406
407/**
408 * hb_font_funcs_set_glyph_from_name_func:
409 * @ffuncs: font functions.
410 * @func: (closure user_data) (destroy destroy) (scope notified):
411 * @user_data:
412 * @destroy:
413 *
414 *
415 *
416 * Since: 0.9.2
417 **/
418HB_EXTERN void
419hb_font_funcs_set_glyph_from_name_func (hb_font_funcs_t *ffuncs,
420 hb_font_get_glyph_from_name_func_t func,
421 void *user_data, hb_destroy_func_t destroy);
422
423/* func dispatch */
424
425HB_EXTERN hb_bool_t
426hb_font_get_h_extents (hb_font_t *font,
427 hb_font_extents_t *extents);
428HB_EXTERN hb_bool_t
429hb_font_get_v_extents (hb_font_t *font,
430 hb_font_extents_t *extents);
431
432HB_EXTERN hb_bool_t
433hb_font_get_nominal_glyph (hb_font_t *font,
434 hb_codepoint_t unicode,
435 hb_codepoint_t *glyph);
436HB_EXTERN hb_bool_t
437hb_font_get_variation_glyph (hb_font_t *font,
438 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
439 hb_codepoint_t *glyph);
440
441HB_EXTERN hb_position_t
442hb_font_get_glyph_h_advance (hb_font_t *font,
443 hb_codepoint_t glyph);
444HB_EXTERN hb_position_t
445hb_font_get_glyph_v_advance (hb_font_t *font,
446 hb_codepoint_t glyph);
447
448HB_EXTERN void
449hb_font_get_glyph_h_advances (hb_font_t* font,
450 unsigned int count,
451 const hb_codepoint_t *first_glyph,
452 unsigned glyph_stride,
453 hb_position_t *first_advance,
454 unsigned advance_stride);
455HB_EXTERN void
456hb_font_get_glyph_v_advances (hb_font_t* font,
457 unsigned int count,
458 const hb_codepoint_t *first_glyph,
459 unsigned glyph_stride,
460 hb_position_t *first_advance,
461 unsigned advance_stride);
462
463HB_EXTERN hb_bool_t
464hb_font_get_glyph_h_origin (hb_font_t *font,
465 hb_codepoint_t glyph,
466 hb_position_t *x, hb_position_t *y);
467HB_EXTERN hb_bool_t
468hb_font_get_glyph_v_origin (hb_font_t *font,
469 hb_codepoint_t glyph,
470 hb_position_t *x, hb_position_t *y);
471
472HB_EXTERN hb_bool_t
473hb_font_get_glyph_extents (hb_font_t *font,
474 hb_codepoint_t glyph,
475 hb_glyph_extents_t *extents);
476
477HB_EXTERN hb_bool_t
478hb_font_get_glyph_contour_point (hb_font_t *font,
479 hb_codepoint_t glyph, unsigned int point_index,
480 hb_position_t *x, hb_position_t *y);
481
482HB_EXTERN hb_bool_t
483hb_font_get_glyph_name (hb_font_t *font,
484 hb_codepoint_t glyph,
485 char *name, unsigned int size);
486HB_EXTERN hb_bool_t
487hb_font_get_glyph_from_name (hb_font_t *font,
488 const char *name, int len, /* -1 means nul-terminated */
489 hb_codepoint_t *glyph);
490
491
492/* high-level funcs, with fallback */
493
494/* Calls either hb_font_get_nominal_glyph() if variation_selector is 0,
495 * otherwise calls hb_font_get_variation_glyph(). */
496HB_EXTERN hb_bool_t
497hb_font_get_glyph (hb_font_t *font,
498 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
499 hb_codepoint_t *glyph);
500
501HB_EXTERN void
502hb_font_get_extents_for_direction (hb_font_t *font,
503 hb_direction_t direction,
504 hb_font_extents_t *extents);
505HB_EXTERN void
506hb_font_get_glyph_advance_for_direction (hb_font_t *font,
507 hb_codepoint_t glyph,
508 hb_direction_t direction,
509 hb_position_t *x, hb_position_t *y);
510HB_EXTERN void
511hb_font_get_glyph_advances_for_direction (hb_font_t* font,
512 hb_direction_t direction,
513 unsigned int count,
514 const hb_codepoint_t *first_glyph,
515 unsigned glyph_stride,
516 hb_position_t *first_advance,
517 unsigned advance_stride);
518HB_EXTERN void
519hb_font_get_glyph_origin_for_direction (hb_font_t *font,
520 hb_codepoint_t glyph,
521 hb_direction_t direction,
522 hb_position_t *x, hb_position_t *y);
523HB_EXTERN void
524hb_font_add_glyph_origin_for_direction (hb_font_t *font,
525 hb_codepoint_t glyph,
526 hb_direction_t direction,
527 hb_position_t *x, hb_position_t *y);
528HB_EXTERN void
529hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
530 hb_codepoint_t glyph,
531 hb_direction_t direction,
532 hb_position_t *x, hb_position_t *y);
533
534HB_EXTERN hb_bool_t
535hb_font_get_glyph_extents_for_origin (hb_font_t *font,
536 hb_codepoint_t glyph,
537 hb_direction_t direction,
538 hb_glyph_extents_t *extents);
539
540HB_EXTERN hb_bool_t
541hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
542 hb_codepoint_t glyph, unsigned int point_index,
543 hb_direction_t direction,
544 hb_position_t *x, hb_position_t *y);
545
546/* Generates gidDDD if glyph has no name. */
547HB_EXTERN void
548hb_font_glyph_to_string (hb_font_t *font,
549 hb_codepoint_t glyph,
550 char *s, unsigned int size);
551/* Parses gidDDD and uniUUUU strings automatically. */
552HB_EXTERN hb_bool_t
553hb_font_glyph_from_string (hb_font_t *font,
554 const char *s, int len, /* -1 means nul-terminated */
555 hb_codepoint_t *glyph);
556
557
558/*
559 * hb_font_t
560 */
561
562/* Fonts are very light-weight objects */
563
564HB_EXTERN hb_font_t *
565hb_font_create (hb_face_t *face);
566
567HB_EXTERN hb_font_t *
568hb_font_create_sub_font (hb_font_t *parent);
569
570HB_EXTERN hb_font_t *
571hb_font_get_empty (void);
572
573HB_EXTERN hb_font_t *
574hb_font_reference (hb_font_t *font);
575
576HB_EXTERN void
577hb_font_destroy (hb_font_t *font);
578
579HB_EXTERN hb_bool_t
580hb_font_set_user_data (hb_font_t *font,
581 hb_user_data_key_t *key,
582 void * data,
583 hb_destroy_func_t destroy,
584 hb_bool_t replace);
585
586
587HB_EXTERN void *
588hb_font_get_user_data (hb_font_t *font,
589 hb_user_data_key_t *key);
590
591HB_EXTERN void
592hb_font_make_immutable (hb_font_t *font);
593
594HB_EXTERN hb_bool_t
595hb_font_is_immutable (hb_font_t *font);
596
597HB_EXTERN void
598hb_font_set_parent (hb_font_t *font,
599 hb_font_t *parent);
600
601HB_EXTERN hb_font_t *
602hb_font_get_parent (hb_font_t *font);
603
604HB_EXTERN void
605hb_font_set_face (hb_font_t *font,
606 hb_face_t *face);
607
608HB_EXTERN hb_face_t *
609hb_font_get_face (hb_font_t *font);
610
611
612HB_EXTERN void
613hb_font_set_funcs (hb_font_t *font,
614 hb_font_funcs_t *klass,
615 void *font_data,
616 hb_destroy_func_t destroy);
617
618/* Be *very* careful with this function! */
619HB_EXTERN void
620hb_font_set_funcs_data (hb_font_t *font,
621 void *font_data,
622 hb_destroy_func_t destroy);
623
624
625HB_EXTERN void
626hb_font_set_scale (hb_font_t *font,
627 int x_scale,
628 int y_scale);
629
630HB_EXTERN void
631hb_font_get_scale (hb_font_t *font,
632 int *x_scale,
633 int *y_scale);
634
635/*
636 * A zero value means "no hinting in that direction"
637 */
638HB_EXTERN void
639hb_font_set_ppem (hb_font_t *font,
640 unsigned int x_ppem,
641 unsigned int y_ppem);
642
643HB_EXTERN void
644hb_font_get_ppem (hb_font_t *font,
645 unsigned int *x_ppem,
646 unsigned int *y_ppem);
647
648/*
649 * Point size per EM. Used for optical-sizing in CoreText.
650 * A value of zero means "not set".
651 */
652HB_EXTERN void
653hb_font_set_ptem (hb_font_t *font, float ptem);
654
655HB_EXTERN float
656hb_font_get_ptem (hb_font_t *font);
657
658HB_EXTERN void
659hb_font_set_variations (hb_font_t *font,
660 const hb_variation_t *variations,
661 unsigned int variations_length);
662
663HB_EXTERN void
664hb_font_set_var_coords_design (hb_font_t *font,
665 const float *coords,
666 unsigned int coords_length);
667
668HB_EXTERN void
669hb_font_set_var_coords_normalized (hb_font_t *font,
670 const int *coords, /* 2.14 normalized */
671 unsigned int coords_length);
672
673HB_EXTERN const int *
674hb_font_get_var_coords_normalized (hb_font_t *font,
675 unsigned int *length);
676
677HB_END_DECLS
678
679#endif /* HB_FONT_H */
680