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 *metrics,
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
128
129typedef hb_position_t (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void *font_data,
130 hb_codepoint_t glyph,
131 void *user_data);
132typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_h_advance_func_t;
133typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_v_advance_func_t;
134
135typedef hb_bool_t (*hb_font_get_glyph_origin_func_t) (hb_font_t *font, void *font_data,
136 hb_codepoint_t glyph,
137 hb_position_t *x, hb_position_t *y,
138 void *user_data);
139typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_h_origin_func_t;
140typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_v_origin_func_t;
141
142typedef hb_position_t (*hb_font_get_glyph_kerning_func_t) (hb_font_t *font, void *font_data,
143 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
144 void *user_data);
145typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_h_kerning_func_t;
146typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_v_kerning_func_t;
147
148
149typedef hb_bool_t (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, void *font_data,
150 hb_codepoint_t glyph,
151 hb_glyph_extents_t *extents,
152 void *user_data);
153typedef hb_bool_t (*hb_font_get_glyph_contour_point_func_t) (hb_font_t *font, void *font_data,
154 hb_codepoint_t glyph, unsigned int point_index,
155 hb_position_t *x, hb_position_t *y,
156 void *user_data);
157
158
159typedef hb_bool_t (*hb_font_get_glyph_name_func_t) (hb_font_t *font, void *font_data,
160 hb_codepoint_t glyph,
161 char *name, unsigned int size,
162 void *user_data);
163typedef hb_bool_t (*hb_font_get_glyph_from_name_func_t) (hb_font_t *font, void *font_data,
164 const char *name, int len, /* -1 means nul-terminated */
165 hb_codepoint_t *glyph,
166 void *user_data);
167
168
169/* func setters */
170
171/**
172 * hb_font_funcs_set_font_h_extents_func:
173 * @ffuncs: font functions.
174 * @func: (closure user_data) (destroy destroy) (scope notified):
175 * @user_data:
176 * @destroy:
177 *
178 *
179 *
180 * Since: 1.1.2
181 **/
182HB_EXTERN void
183hb_font_funcs_set_font_h_extents_func (hb_font_funcs_t *ffuncs,
184 hb_font_get_font_h_extents_func_t func,
185 void *user_data, hb_destroy_func_t destroy);
186
187/**
188 * hb_font_funcs_set_font_v_extents_func:
189 * @ffuncs: font functions.
190 * @func: (closure user_data) (destroy destroy) (scope notified):
191 * @user_data:
192 * @destroy:
193 *
194 *
195 *
196 * Since: 1.1.2
197 **/
198HB_EXTERN void
199hb_font_funcs_set_font_v_extents_func (hb_font_funcs_t *ffuncs,
200 hb_font_get_font_v_extents_func_t func,
201 void *user_data, hb_destroy_func_t destroy);
202
203/**
204 * hb_font_funcs_set_nominal_glyph_func:
205 * @ffuncs: font functions.
206 * @func: (closure user_data) (destroy destroy) (scope notified):
207 * @user_data:
208 * @destroy:
209 *
210 *
211 *
212 * Since: 1.2.3
213 **/
214HB_EXTERN void
215hb_font_funcs_set_nominal_glyph_func (hb_font_funcs_t *ffuncs,
216 hb_font_get_nominal_glyph_func_t func,
217 void *user_data, hb_destroy_func_t destroy);
218
219/**
220 * hb_font_funcs_set_variation_glyph_func:
221 * @ffuncs: font functions.
222 * @func: (closure user_data) (destroy destroy) (scope notified):
223 * @user_data:
224 * @destroy:
225 *
226 *
227 *
228 * Since: 1.2.3
229 **/
230HB_EXTERN void
231hb_font_funcs_set_variation_glyph_func (hb_font_funcs_t *ffuncs,
232 hb_font_get_variation_glyph_func_t func,
233 void *user_data, hb_destroy_func_t destroy);
234
235/**
236 * hb_font_funcs_set_glyph_h_advance_func:
237 * @ffuncs: font functions.
238 * @func: (closure user_data) (destroy destroy) (scope notified):
239 * @user_data:
240 * @destroy:
241 *
242 *
243 *
244 * Since: 0.9.2
245 **/
246HB_EXTERN void
247hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs,
248 hb_font_get_glyph_h_advance_func_t func,
249 void *user_data, hb_destroy_func_t destroy);
250
251/**
252 * hb_font_funcs_set_glyph_v_advance_func:
253 * @ffuncs: font functions.
254 * @func: (closure user_data) (destroy destroy) (scope notified):
255 * @user_data:
256 * @destroy:
257 *
258 *
259 *
260 * Since: 0.9.2
261 **/
262HB_EXTERN void
263hb_font_funcs_set_glyph_v_advance_func (hb_font_funcs_t *ffuncs,
264 hb_font_get_glyph_v_advance_func_t func,
265 void *user_data, hb_destroy_func_t destroy);
266
267/**
268 * hb_font_funcs_set_glyph_h_origin_func:
269 * @ffuncs: font functions.
270 * @func: (closure user_data) (destroy destroy) (scope notified):
271 * @user_data:
272 * @destroy:
273 *
274 *
275 *
276 * Since: 0.9.2
277 **/
278HB_EXTERN void
279hb_font_funcs_set_glyph_h_origin_func (hb_font_funcs_t *ffuncs,
280 hb_font_get_glyph_h_origin_func_t func,
281 void *user_data, hb_destroy_func_t destroy);
282
283/**
284 * hb_font_funcs_set_glyph_v_origin_func:
285 * @ffuncs: font functions.
286 * @func: (closure user_data) (destroy destroy) (scope notified):
287 * @user_data:
288 * @destroy:
289 *
290 *
291 *
292 * Since: 0.9.2
293 **/
294HB_EXTERN void
295hb_font_funcs_set_glyph_v_origin_func (hb_font_funcs_t *ffuncs,
296 hb_font_get_glyph_v_origin_func_t func,
297 void *user_data, hb_destroy_func_t destroy);
298
299/**
300 * hb_font_funcs_set_glyph_h_kerning_func:
301 * @ffuncs: font functions.
302 * @func: (closure user_data) (destroy destroy) (scope notified):
303 * @user_data:
304 * @destroy:
305 *
306 *
307 *
308 * Since: 0.9.2
309 **/
310HB_EXTERN void
311hb_font_funcs_set_glyph_h_kerning_func (hb_font_funcs_t *ffuncs,
312 hb_font_get_glyph_h_kerning_func_t func,
313 void *user_data, hb_destroy_func_t destroy);
314
315/**
316 * hb_font_funcs_set_glyph_v_kerning_func:
317 * @ffuncs: font functions.
318 * @func: (closure user_data) (destroy destroy) (scope notified):
319 * @user_data:
320 * @destroy:
321 *
322 *
323 *
324 * Since: 0.9.2
325 **/
326HB_EXTERN void
327hb_font_funcs_set_glyph_v_kerning_func (hb_font_funcs_t *ffuncs,
328 hb_font_get_glyph_v_kerning_func_t func,
329 void *user_data, hb_destroy_func_t destroy);
330
331/**
332 * hb_font_funcs_set_glyph_extents_func:
333 * @ffuncs: font functions.
334 * @func: (closure user_data) (destroy destroy) (scope notified):
335 * @user_data:
336 * @destroy:
337 *
338 *
339 *
340 * Since: 0.9.2
341 **/
342HB_EXTERN void
343hb_font_funcs_set_glyph_extents_func (hb_font_funcs_t *ffuncs,
344 hb_font_get_glyph_extents_func_t func,
345 void *user_data, hb_destroy_func_t destroy);
346
347/**
348 * hb_font_funcs_set_glyph_contour_point_func:
349 * @ffuncs: font functions.
350 * @func: (closure user_data) (destroy destroy) (scope notified):
351 * @user_data:
352 * @destroy:
353 *
354 *
355 *
356 * Since: 0.9.2
357 **/
358HB_EXTERN void
359hb_font_funcs_set_glyph_contour_point_func (hb_font_funcs_t *ffuncs,
360 hb_font_get_glyph_contour_point_func_t func,
361 void *user_data, hb_destroy_func_t destroy);
362
363/**
364 * hb_font_funcs_set_glyph_name_func:
365 * @ffuncs: font functions.
366 * @func: (closure user_data) (destroy destroy) (scope notified):
367 * @user_data:
368 * @destroy:
369 *
370 *
371 *
372 * Since: 0.9.2
373 **/
374HB_EXTERN void
375hb_font_funcs_set_glyph_name_func (hb_font_funcs_t *ffuncs,
376 hb_font_get_glyph_name_func_t func,
377 void *user_data, hb_destroy_func_t destroy);
378
379/**
380 * hb_font_funcs_set_glyph_from_name_func:
381 * @ffuncs: font functions.
382 * @func: (closure user_data) (destroy destroy) (scope notified):
383 * @user_data:
384 * @destroy:
385 *
386 *
387 *
388 * Since: 0.9.2
389 **/
390HB_EXTERN void
391hb_font_funcs_set_glyph_from_name_func (hb_font_funcs_t *ffuncs,
392 hb_font_get_glyph_from_name_func_t func,
393 void *user_data, hb_destroy_func_t destroy);
394
395/* func dispatch */
396
397HB_EXTERN hb_bool_t
398hb_font_get_h_extents (hb_font_t *font,
399 hb_font_extents_t *extents);
400HB_EXTERN hb_bool_t
401hb_font_get_v_extents (hb_font_t *font,
402 hb_font_extents_t *extents);
403
404HB_EXTERN hb_bool_t
405hb_font_get_nominal_glyph (hb_font_t *font,
406 hb_codepoint_t unicode,
407 hb_codepoint_t *glyph);
408HB_EXTERN hb_bool_t
409hb_font_get_variation_glyph (hb_font_t *font,
410 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
411 hb_codepoint_t *glyph);
412
413HB_EXTERN hb_position_t
414hb_font_get_glyph_h_advance (hb_font_t *font,
415 hb_codepoint_t glyph);
416HB_EXTERN hb_position_t
417hb_font_get_glyph_v_advance (hb_font_t *font,
418 hb_codepoint_t glyph);
419
420HB_EXTERN hb_bool_t
421hb_font_get_glyph_h_origin (hb_font_t *font,
422 hb_codepoint_t glyph,
423 hb_position_t *x, hb_position_t *y);
424HB_EXTERN hb_bool_t
425hb_font_get_glyph_v_origin (hb_font_t *font,
426 hb_codepoint_t glyph,
427 hb_position_t *x, hb_position_t *y);
428
429HB_EXTERN hb_position_t
430hb_font_get_glyph_h_kerning (hb_font_t *font,
431 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph);
432HB_EXTERN hb_position_t
433hb_font_get_glyph_v_kerning (hb_font_t *font,
434 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph);
435
436HB_EXTERN hb_bool_t
437hb_font_get_glyph_extents (hb_font_t *font,
438 hb_codepoint_t glyph,
439 hb_glyph_extents_t *extents);
440
441HB_EXTERN hb_bool_t
442hb_font_get_glyph_contour_point (hb_font_t *font,
443 hb_codepoint_t glyph, unsigned int point_index,
444 hb_position_t *x, hb_position_t *y);
445
446HB_EXTERN hb_bool_t
447hb_font_get_glyph_name (hb_font_t *font,
448 hb_codepoint_t glyph,
449 char *name, unsigned int size);
450HB_EXTERN hb_bool_t
451hb_font_get_glyph_from_name (hb_font_t *font,
452 const char *name, int len, /* -1 means nul-terminated */
453 hb_codepoint_t *glyph);
454
455
456/* high-level funcs, with fallback */
457
458/* Calls either hb_font_get_nominal_glyph() if variation_selector is 0,
459 * otherwise callse hb_font_get_variation_glyph(). */
460HB_EXTERN hb_bool_t
461hb_font_get_glyph (hb_font_t *font,
462 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
463 hb_codepoint_t *glyph);
464
465HB_EXTERN void
466hb_font_get_extents_for_direction (hb_font_t *font,
467 hb_direction_t direction,
468 hb_font_extents_t *extents);
469HB_EXTERN void
470hb_font_get_glyph_advance_for_direction (hb_font_t *font,
471 hb_codepoint_t glyph,
472 hb_direction_t direction,
473 hb_position_t *x, hb_position_t *y);
474HB_EXTERN void
475hb_font_get_glyph_origin_for_direction (hb_font_t *font,
476 hb_codepoint_t glyph,
477 hb_direction_t direction,
478 hb_position_t *x, hb_position_t *y);
479HB_EXTERN void
480hb_font_add_glyph_origin_for_direction (hb_font_t *font,
481 hb_codepoint_t glyph,
482 hb_direction_t direction,
483 hb_position_t *x, hb_position_t *y);
484HB_EXTERN void
485hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
486 hb_codepoint_t glyph,
487 hb_direction_t direction,
488 hb_position_t *x, hb_position_t *y);
489
490HB_EXTERN void
491hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
492 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
493 hb_direction_t direction,
494 hb_position_t *x, hb_position_t *y);
495
496HB_EXTERN hb_bool_t
497hb_font_get_glyph_extents_for_origin (hb_font_t *font,
498 hb_codepoint_t glyph,
499 hb_direction_t direction,
500 hb_glyph_extents_t *extents);
501
502HB_EXTERN hb_bool_t
503hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
504 hb_codepoint_t glyph, unsigned int point_index,
505 hb_direction_t direction,
506 hb_position_t *x, hb_position_t *y);
507
508/* Generates gidDDD if glyph has no name. */
509HB_EXTERN void
510hb_font_glyph_to_string (hb_font_t *font,
511 hb_codepoint_t glyph,
512 char *s, unsigned int size);
513/* Parses gidDDD and uniUUUU strings automatically. */
514HB_EXTERN hb_bool_t
515hb_font_glyph_from_string (hb_font_t *font,
516 const char *s, int len, /* -1 means nul-terminated */
517 hb_codepoint_t *glyph);
518
519
520/*
521 * hb_font_t
522 */
523
524/* Fonts are very light-weight objects */
525
526HB_EXTERN hb_font_t *
527hb_font_create (hb_face_t *face);
528
529HB_EXTERN hb_font_t *
530hb_font_create_sub_font (hb_font_t *parent);
531
532HB_EXTERN hb_font_t *
533hb_font_get_empty (void);
534
535HB_EXTERN hb_font_t *
536hb_font_reference (hb_font_t *font);
537
538HB_EXTERN void
539hb_font_destroy (hb_font_t *font);
540
541HB_EXTERN hb_bool_t
542hb_font_set_user_data (hb_font_t *font,
543 hb_user_data_key_t *key,
544 void * data,
545 hb_destroy_func_t destroy,
546 hb_bool_t replace);
547
548
549HB_EXTERN void *
550hb_font_get_user_data (hb_font_t *font,
551 hb_user_data_key_t *key);
552
553HB_EXTERN void
554hb_font_make_immutable (hb_font_t *font);
555
556HB_EXTERN hb_bool_t
557hb_font_is_immutable (hb_font_t *font);
558
559HB_EXTERN void
560hb_font_set_parent (hb_font_t *font,
561 hb_font_t *parent);
562
563HB_EXTERN hb_font_t *
564hb_font_get_parent (hb_font_t *font);
565
566HB_EXTERN hb_face_t *
567hb_font_get_face (hb_font_t *font);
568
569
570HB_EXTERN void
571hb_font_set_funcs (hb_font_t *font,
572 hb_font_funcs_t *klass,
573 void *font_data,
574 hb_destroy_func_t destroy);
575
576/* Be *very* careful with this function! */
577HB_EXTERN void
578hb_font_set_funcs_data (hb_font_t *font,
579 void *font_data,
580 hb_destroy_func_t destroy);
581
582
583HB_EXTERN void
584hb_font_set_scale (hb_font_t *font,
585 int x_scale,
586 int y_scale);
587
588HB_EXTERN void
589hb_font_get_scale (hb_font_t *font,
590 int *x_scale,
591 int *y_scale);
592
593/*
594 * A zero value means "no hinting in that direction"
595 */
596HB_EXTERN void
597hb_font_set_ppem (hb_font_t *font,
598 unsigned int x_ppem,
599 unsigned int y_ppem);
600
601HB_EXTERN void
602hb_font_get_ppem (hb_font_t *font,
603 unsigned int *x_ppem,
604 unsigned int *y_ppem);
605
606
607HB_END_DECLS
608
609#endif /* HB_FONT_H */
610