266b74a8366332272fd0472999dd7ab9dba4403c
[profile/ivi/org.tizen.video-player.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 /* Returns NULL if not found */
65 hb_blob_t *
66 hb_face_get_table (hb_face_t *face,
67                    hb_tag_t   tag);
68
69
70 /*
71  * hb_font_funcs_t
72  */
73
74 typedef struct _hb_font_funcs_t hb_font_funcs_t;
75
76 hb_font_funcs_t *
77 hb_font_funcs_create (void);
78
79 hb_font_funcs_t *
80 hb_font_funcs_reference (hb_font_funcs_t *ffuncs);
81
82 unsigned int
83 hb_font_funcs_get_reference_count (hb_font_funcs_t *ffuncs);
84
85 void
86 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs);
87
88 hb_font_funcs_t *
89 hb_font_funcs_copy (hb_font_funcs_t *ffuncs);
90
91 void
92 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs);
93
94 hb_bool_t
95 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs);
96
97 /* funcs */
98
99 typedef struct _hb_glyph_metrics_t
100 {
101     hb_position_t x_advance;
102     hb_position_t y_advance;
103     hb_position_t x_offset;
104     hb_position_t y_offset;
105     hb_position_t width;
106     hb_position_t height;
107 } hb_glyph_metrics_t;
108
109 typedef hb_codepoint_t (*hb_font_get_glyph_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
110                                                     hb_codepoint_t unicode, hb_codepoint_t variation_selector);
111 typedef hb_bool_t (*hb_font_get_contour_point_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
112                                                        unsigned int point_index,
113                                                        hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y);
114 typedef void (*hb_font_get_glyph_metrics_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
115                                                   hb_codepoint_t glyph, hb_glyph_metrics_t *metrics);
116 typedef hb_position_t (*hb_font_get_kerning_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
117                                                      hb_codepoint_t first_glyph, hb_codepoint_t second_glyph);
118
119
120 void
121 hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
122                               hb_font_get_glyph_func_t glyph_func);
123
124 void
125 hb_font_funcs_set_contour_point_func (hb_font_funcs_t *ffuncs,
126                                       hb_font_get_contour_point_func_t contour_point_func);
127
128 void
129 hb_font_funcs_set_glyph_metrics_func (hb_font_funcs_t *ffuncs,
130                                       hb_font_get_glyph_metrics_func_t glyph_metrics_func);
131
132 void
133 hb_font_funcs_set_kerning_func (hb_font_funcs_t *ffuncs,
134                                 hb_font_get_kerning_func_t kerning_func);
135
136
137 /* These never return NULL.  Return fallback defaults instead. */
138
139 hb_font_get_glyph_func_t
140 hb_font_funcs_get_glyph_func (hb_font_funcs_t *ffuncs);
141
142 hb_font_get_contour_point_func_t
143 hb_font_funcs_get_contour_point_func (hb_font_funcs_t *ffuncs);
144
145 hb_font_get_glyph_metrics_func_t
146 hb_font_funcs_get_glyph_metrics_func (hb_font_funcs_t *ffuncs);
147
148 hb_font_get_kerning_func_t
149 hb_font_funcs_get_kerning_func (hb_font_funcs_t *ffuncs);
150
151
152 hb_codepoint_t
153 hb_font_get_glyph (hb_font_t *font, hb_face_t *face,
154                    hb_codepoint_t unicode, hb_codepoint_t variation_selector);
155
156 hb_bool_t
157 hb_font_get_contour_point (hb_font_t *font, hb_face_t *face,
158                            unsigned int point_index,
159                            hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y);
160
161 void
162 hb_font_get_glyph_metrics (hb_font_t *font, hb_face_t *face,
163                            hb_codepoint_t glyph, hb_glyph_metrics_t *metrics);
164
165 hb_position_t
166 hb_font_get_kerning (hb_font_t *font, hb_face_t *face,
167                      hb_codepoint_t first_glyph, hb_codepoint_t second_glyph);
168
169
170 /*
171  * hb_font_t
172  */
173
174 /* Fonts are very light-weight objects */
175
176 hb_font_t *
177 hb_font_create (void);
178
179 hb_font_t *
180 hb_font_reference (hb_font_t *font);
181
182 unsigned int
183 hb_font_get_reference_count (hb_font_t *font);
184
185 void
186 hb_font_destroy (hb_font_t *font);
187
188 void
189 hb_font_set_funcs (hb_font_t         *font,
190                    hb_font_funcs_t   *klass,
191                    hb_destroy_func_t  destroy,
192                    void              *user_data);
193
194 /* Returns what was set and unsets it, but doesn't destroy(user_data).
195  * This is useful for wrapping / chaining font_funcs_t's.
196  *
197  * The client is responsible for:
198  *
199  *   - Take ownership of the reference on the returned klass
200  *   - Calling "destroy(user_data)" exactly once if returned destroy func
201  *     is not NULL and the returned info is not needed anymore.
202  */
203 void
204 hb_font_unset_funcs (hb_font_t          *font,
205                      hb_font_funcs_t   **klass,
206                      hb_destroy_func_t  *destroy,
207                      void              **user_data);
208
209
210 /*
211  * We should add support for full matrices.
212  */
213 void
214 hb_font_set_scale (hb_font_t *font,
215                    unsigned int x_scale,
216                    unsigned int y_scale);
217
218 void
219 hb_font_get_scale (hb_font_t *font,
220                    unsigned int *x_scale,
221                    unsigned int *y_scale);
222
223 /*
224  * A zero value means "no hinting in that direction"
225  */
226 void
227 hb_font_set_ppem (hb_font_t *font,
228                   unsigned int x_ppem,
229                   unsigned int y_ppem);
230
231 void
232 hb_font_get_ppem (hb_font_t *font,
233                   unsigned int *x_ppem,
234                   unsigned int *y_ppem);
235
236
237 HB_END_DECLS
238
239 #endif /* HB_FONT_H */