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_font_funcs_t *
50hb_font_funcs_create (void);
51
52hb_font_funcs_t *
53hb_font_funcs_get_empty (void);
54
55hb_font_funcs_t *
56hb_font_funcs_reference (hb_font_funcs_t *ffuncs);
57
58void
59hb_font_funcs_destroy (hb_font_funcs_t *ffuncs);
60
61hb_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
69void *
70hb_font_funcs_get_user_data (hb_font_funcs_t    *ffuncs,
71			     hb_user_data_key_t *key);
72
73
74void
75hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs);
76
77hb_bool_t
78hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs);
79
80
81/* glyph extents */
82
83typedef 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
94typedef 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
100typedef 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);
103typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_h_advance_func_t;
104typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_v_advance_func_t;
105
106typedef 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);
110typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_h_origin_func_t;
111typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_v_origin_func_t;
112
113typedef 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);
116typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_h_kerning_func_t;
117typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_v_kerning_func_t;
118
119
120typedef 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);
124typedef 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
130typedef 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);
134typedef 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 **/
153void
154hb_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 **/
169void
170hb_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 **/
185void
186hb_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 **/
201void
202hb_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 **/
217void
218hb_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 **/
233void
234hb_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 **/
249void
250hb_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 **/
265void
266hb_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 **/
281void
282hb_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 **/
297void
298hb_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 **/
313void
314hb_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
321hb_bool_t
322hb_font_get_glyph (hb_font_t *font,
323		   hb_codepoint_t unicode, hb_codepoint_t variation_selector,
324		   hb_codepoint_t *glyph);
325
326hb_position_t
327hb_font_get_glyph_h_advance (hb_font_t *font,
328			     hb_codepoint_t glyph);
329hb_position_t
330hb_font_get_glyph_v_advance (hb_font_t *font,
331			     hb_codepoint_t glyph);
332
333hb_bool_t
334hb_font_get_glyph_h_origin (hb_font_t *font,
335			    hb_codepoint_t glyph,
336			    hb_position_t *x, hb_position_t *y);
337hb_bool_t
338hb_font_get_glyph_v_origin (hb_font_t *font,
339			    hb_codepoint_t glyph,
340			    hb_position_t *x, hb_position_t *y);
341
342hb_position_t
343hb_font_get_glyph_h_kerning (hb_font_t *font,
344			     hb_codepoint_t left_glyph, hb_codepoint_t right_glyph);
345hb_position_t
346hb_font_get_glyph_v_kerning (hb_font_t *font,
347			     hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph);
348
349hb_bool_t
350hb_font_get_glyph_extents (hb_font_t *font,
351			   hb_codepoint_t glyph,
352			   hb_glyph_extents_t *extents);
353
354hb_bool_t
355hb_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
359hb_bool_t
360hb_font_get_glyph_name (hb_font_t *font,
361			hb_codepoint_t glyph,
362			char *name, unsigned int size);
363hb_bool_t
364hb_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
371void
372hb_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);
376void
377hb_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);
381void
382hb_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);
386void
387hb_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
392void
393hb_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
398hb_bool_t
399hb_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
404hb_bool_t
405hb_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. */
411void
412hb_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. */
416hb_bool_t
417hb_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
428hb_font_t *
429hb_font_create (hb_face_t *face);
430
431hb_font_t *
432hb_font_create_sub_font (hb_font_t *parent);
433
434hb_font_t *
435hb_font_get_empty (void);
436
437hb_font_t *
438hb_font_reference (hb_font_t *font);
439
440void
441hb_font_destroy (hb_font_t *font);
442
443hb_bool_t
444hb_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
451void *
452hb_font_get_user_data (hb_font_t          *font,
453		       hb_user_data_key_t *key);
454
455void
456hb_font_make_immutable (hb_font_t *font);
457
458hb_bool_t
459hb_font_is_immutable (hb_font_t *font);
460
461hb_font_t *
462hb_font_get_parent (hb_font_t *font);
463
464hb_face_t *
465hb_font_get_face (hb_font_t *font);
466
467
468void
469hb_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! */
475void
476hb_font_set_funcs_data (hb_font_t         *font,
477		        void              *font_data,
478		        hb_destroy_func_t  destroy);
479
480
481void
482hb_font_set_scale (hb_font_t *font,
483		   int x_scale,
484		   int y_scale);
485
486void
487hb_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 */
494void
495hb_font_set_ppem (hb_font_t *font,
496		  unsigned int x_ppem,
497		  unsigned int y_ppem);
498
499void
500hb_font_get_ppem (hb_font_t *font,
501		  unsigned int *x_ppem,
502		  unsigned int *y_ppem);
503
504
505HB_END_DECLS
506
507#endif /* HB_FONT_H */
508