Implement nil font functions
[framework/uifw/harfbuzz.git] / src / hb-font.h
1 /*
2  * Copyright (C) 2009  Red Hat, Inc.
3  *
4  *  This is part of HarfBuzz, an OpenType Layout engine 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 typedef struct _hb_face_t hb_face_t;
36 typedef struct _hb_font_t hb_font_t;
37
38 /*
39  * hb_face_t
40  */
41
42 hb_face_t *
43 hb_face_create_for_data (hb_blob_t    *blob,
44                          unsigned int  index);
45
46 typedef hb_blob_t * (*hb_get_table_func_t)  (hb_tag_t tag, void *user_data);
47
48 /* calls destroy() when not needing user_data anymore */
49 hb_face_t *
50 hb_face_create_for_tables (hb_get_table_func_t  get_table,
51                            hb_destroy_func_t    destroy,
52                            void                *user_data);
53
54 hb_face_t *
55 hb_face_reference (hb_face_t *face);
56
57 unsigned int
58 hb_face_get_reference_count (hb_face_t *face);
59
60 void
61 hb_face_destroy (hb_face_t *face);
62
63 hb_blob_t *
64 hb_face_get_table (hb_face_t *face,
65                    hb_tag_t   tag);
66
67
68 /*
69  * hb_font_funcs_t
70  */
71
72 typedef struct _hb_font_funcs_t hb_font_funcs_t;
73
74 hb_font_funcs_t *
75 hb_font_funcs_create (void);
76
77 hb_font_funcs_t *
78 hb_font_funcs_reference (hb_font_funcs_t *ffuncs);
79
80 unsigned int
81 hb_font_funcs_get_reference_count (hb_font_funcs_t *ffuncs);
82
83 void
84 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs);
85
86 hb_font_funcs_t *
87 hb_font_funcs_copy (hb_font_funcs_t *ffuncs);
88
89 void
90 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs);
91
92
93 /* funcs */
94
95 typedef struct _hb_glyph_metrics_t
96 {
97     hb_position_t x_pos;
98     hb_position_t y_pos;
99     hb_position_t x_advance;
100     hb_position_t y_advance;
101     hb_position_t width;
102     hb_position_t height;
103 } hb_glyph_metrics_t;
104
105 typedef hb_codepoint_t (*hb_font_get_glyph_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
106                                                     hb_codepoint_t unicode, hb_codepoint_t variant_selector);
107 typedef hb_bool_t (*hb_font_get_contour_point_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
108                                                        unsigned int point_index,
109                                                        hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y);
110 typedef void (*hb_font_get_glyph_metrics_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
111                                                   hb_codepoint_t glyph, hb_glyph_metrics_t *metrics);
112 typedef hb_position_t (*hb_font_get_kerning_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
113                                                      hb_codepoint_t first_glyph, hb_codepoint_t second_glyph);
114
115
116 void
117 hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
118                               hb_font_get_glyph_func_t glyph_func);
119
120 void
121 hb_font_funcs_set_contour_point_func (hb_font_funcs_t *ffuncs,
122                                       hb_font_get_contour_point_func_t contour_point_func);
123
124 void
125 hb_font_funcs_set_glyph_metrics_func (hb_font_funcs_t *ffuncs,
126                                       hb_font_get_glyph_metrics_func_t glyph_metrics_func);
127
128 void
129 hb_font_funcs_set_kerning_func (hb_font_funcs_t *ffuncs,
130                                 hb_font_get_kerning_func_t kerning_func);
131
132
133 /*
134  * hb_font_t
135  */
136
137 /* Fonts are very light-weight objects */
138
139 hb_font_t *
140 hb_font_create (void);
141
142 hb_font_t *
143 hb_font_reference (hb_font_t *font);
144
145 unsigned int
146 hb_font_get_reference_count (hb_font_t *font);
147
148 void
149 hb_font_destroy (hb_font_t *font);
150
151 void
152 hb_font_set_funcs (hb_font_t         *font,
153                    hb_font_funcs_t   *klass,
154                    hb_destroy_func_t  destroy,
155                    void              *user_data);
156
157 hb_font_funcs_t *
158 hb_font_get_funcs (hb_font_t       *font);
159
160
161 /*
162  * XXX
163  * should we decompose this to units_per_EM and font-size?
164  * units_per_EM setting then can go into the face, or better,
165  * read from the 'head' table.
166  *
167  * Then we either need size+shape like freetype does, or a full
168  * matrix.
169  */
170 void
171 hb_font_set_scale (hb_font_t *font,
172                    hb_16dot16_t x_scale,
173                    hb_16dot16_t y_scale);
174
175 /*
176  * A zero value means "no hinting in that direction"
177  */
178 void
179 hb_font_set_ppem (hb_font_t *font,
180                   unsigned int x_ppem,
181                   unsigned int y_ppem);
182
183
184 HB_END_DECLS
185
186 #endif /* HB_FONT_H */