changeset 54232 | 7c11a7cc7c1d |
parent 50826 | f5b95be8b6e2 |
54231:e4813eded7cb | 54232:7c11a7cc7c1d |
---|---|
24 * |
24 * |
25 * Red Hat Author(s): Behdad Esfahbod |
25 * Red Hat Author(s): Behdad Esfahbod |
26 * Google Author(s): Behdad Esfahbod |
26 * Google Author(s): Behdad Esfahbod |
27 */ |
27 */ |
28 |
28 |
29 #include "hb-private.hh" |
29 #include "hb.hh" |
30 |
30 |
31 #include "hb-font-private.hh" |
31 #include "hb-font.hh" |
32 #include "hb-machinery.hh" |
|
33 |
|
34 #include "hb-ot.h" |
|
35 |
|
36 |
|
37 /** |
|
38 * SECTION:hb-font |
|
39 * @title: hb-font |
|
40 * @short_description: Font objects |
|
41 * @include: hb.h |
|
42 * |
|
43 * Font objects represent a font face at a certain size and other |
|
44 * parameters (pixels per EM, points per EM, variation settings.) |
|
45 * Fonts are created from font faces, and are used as input to |
|
46 * hb_shape() among other things. |
|
47 **/ |
|
32 |
48 |
33 |
49 |
34 /* |
50 /* |
35 * hb_font_funcs_t |
51 * hb_font_funcs_t |
36 */ |
52 */ |
37 |
53 |
38 static hb_bool_t |
54 static hb_bool_t |
39 hb_font_get_font_h_extents_nil (hb_font_t *font HB_UNUSED, |
55 hb_font_get_font_h_extents_nil (hb_font_t *font HB_UNUSED, |
40 void *font_data HB_UNUSED, |
56 void *font_data HB_UNUSED, |
41 hb_font_extents_t *metrics, |
57 hb_font_extents_t *extents, |
42 void *user_data HB_UNUSED) |
58 void *user_data HB_UNUSED) |
43 { |
59 { |
44 memset (metrics, 0, sizeof (*metrics)); |
60 memset (extents, 0, sizeof (*extents)); |
45 return false; |
61 return false; |
46 } |
62 } |
47 static hb_bool_t |
63 static hb_bool_t |
48 hb_font_get_font_h_extents_parent (hb_font_t *font, |
64 hb_font_get_font_h_extents_default (hb_font_t *font, |
49 void *font_data HB_UNUSED, |
65 void *font_data HB_UNUSED, |
50 hb_font_extents_t *metrics, |
66 hb_font_extents_t *extents, |
51 void *user_data HB_UNUSED) |
67 void *user_data HB_UNUSED) |
52 { |
68 { |
53 hb_bool_t ret = font->parent->get_font_h_extents (metrics); |
69 hb_bool_t ret = font->parent->get_font_h_extents (extents); |
54 if (ret) { |
70 if (ret) { |
55 metrics->ascender = font->parent_scale_y_distance (metrics->ascender); |
71 extents->ascender = font->parent_scale_y_distance (extents->ascender); |
56 metrics->descender = font->parent_scale_y_distance (metrics->descender); |
72 extents->descender = font->parent_scale_y_distance (extents->descender); |
57 metrics->line_gap = font->parent_scale_y_distance (metrics->line_gap); |
73 extents->line_gap = font->parent_scale_y_distance (extents->line_gap); |
58 } |
74 } |
59 return ret; |
75 return ret; |
60 } |
76 } |
61 |
77 |
62 static hb_bool_t |
78 static hb_bool_t |
63 hb_font_get_font_v_extents_nil (hb_font_t *font HB_UNUSED, |
79 hb_font_get_font_v_extents_nil (hb_font_t *font HB_UNUSED, |
64 void *font_data HB_UNUSED, |
80 void *font_data HB_UNUSED, |
65 hb_font_extents_t *metrics, |
81 hb_font_extents_t *extents, |
66 void *user_data HB_UNUSED) |
82 void *user_data HB_UNUSED) |
67 { |
83 { |
68 memset (metrics, 0, sizeof (*metrics)); |
84 memset (extents, 0, sizeof (*extents)); |
69 return false; |
85 return false; |
70 } |
86 } |
71 static hb_bool_t |
87 static hb_bool_t |
72 hb_font_get_font_v_extents_parent (hb_font_t *font, |
88 hb_font_get_font_v_extents_default (hb_font_t *font, |
73 void *font_data HB_UNUSED, |
89 void *font_data HB_UNUSED, |
74 hb_font_extents_t *metrics, |
90 hb_font_extents_t *extents, |
75 void *user_data HB_UNUSED) |
91 void *user_data HB_UNUSED) |
76 { |
92 { |
77 hb_bool_t ret = font->parent->get_font_v_extents (metrics); |
93 hb_bool_t ret = font->parent->get_font_v_extents (extents); |
78 if (ret) { |
94 if (ret) { |
79 metrics->ascender = font->parent_scale_x_distance (metrics->ascender); |
95 extents->ascender = font->parent_scale_x_distance (extents->ascender); |
80 metrics->descender = font->parent_scale_x_distance (metrics->descender); |
96 extents->descender = font->parent_scale_x_distance (extents->descender); |
81 metrics->line_gap = font->parent_scale_x_distance (metrics->line_gap); |
97 extents->line_gap = font->parent_scale_x_distance (extents->line_gap); |
82 } |
98 } |
83 return ret; |
99 return ret; |
84 } |
100 } |
85 |
101 |
86 static hb_bool_t |
102 static hb_bool_t |
87 hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED, |
103 hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED, |
88 void *font_data HB_UNUSED, |
104 void *font_data HB_UNUSED, |
89 hb_codepoint_t unicode, |
105 hb_codepoint_t unicode HB_UNUSED, |
90 hb_codepoint_t *glyph, |
106 hb_codepoint_t *glyph, |
91 void *user_data HB_UNUSED) |
107 void *user_data HB_UNUSED) |
92 { |
108 { |
93 *glyph = 0; |
109 *glyph = 0; |
94 return false; |
110 return false; |
95 } |
111 } |
96 static hb_bool_t |
112 static hb_bool_t |
97 hb_font_get_nominal_glyph_parent (hb_font_t *font, |
113 hb_font_get_nominal_glyph_default (hb_font_t *font, |
98 void *font_data HB_UNUSED, |
114 void *font_data HB_UNUSED, |
99 hb_codepoint_t unicode, |
115 hb_codepoint_t unicode, |
100 hb_codepoint_t *glyph, |
116 hb_codepoint_t *glyph, |
101 void *user_data HB_UNUSED) |
117 void *user_data HB_UNUSED) |
102 { |
118 { |
119 if (font->has_nominal_glyphs_func_set ()) |
|
120 { |
|
121 return font->get_nominal_glyphs (1, &unicode, 0, glyph, 0); |
|
122 } |
|
103 return font->parent->get_nominal_glyph (unicode, glyph); |
123 return font->parent->get_nominal_glyph (unicode, glyph); |
124 } |
|
125 |
|
126 #define hb_font_get_nominal_glyphs_nil hb_font_get_nominal_glyphs_default |
|
127 static unsigned int |
|
128 hb_font_get_nominal_glyphs_default (hb_font_t *font, |
|
129 void *font_data HB_UNUSED, |
|
130 unsigned int count, |
|
131 const hb_codepoint_t *first_unicode, |
|
132 unsigned int unicode_stride, |
|
133 hb_codepoint_t *first_glyph, |
|
134 unsigned int glyph_stride, |
|
135 void *user_data HB_UNUSED) |
|
136 { |
|
137 if (font->has_nominal_glyph_func_set ()) |
|
138 { |
|
139 for (unsigned int i = 0; i < count; i++) |
|
140 { |
|
141 if (!font->get_nominal_glyph (*first_unicode, first_glyph)) |
|
142 return i; |
|
143 |
|
144 first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride); |
|
145 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride); |
|
146 } |
|
147 return count; |
|
148 } |
|
149 |
|
150 return font->parent->get_nominal_glyphs (count, |
|
151 first_unicode, unicode_stride, |
|
152 first_glyph, glyph_stride); |
|
104 } |
153 } |
105 |
154 |
106 static hb_bool_t |
155 static hb_bool_t |
107 hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED, |
156 hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED, |
108 void *font_data HB_UNUSED, |
157 void *font_data HB_UNUSED, |
109 hb_codepoint_t unicode, |
158 hb_codepoint_t unicode HB_UNUSED, |
110 hb_codepoint_t variation_selector, |
159 hb_codepoint_t variation_selector HB_UNUSED, |
111 hb_codepoint_t *glyph, |
160 hb_codepoint_t *glyph, |
112 void *user_data HB_UNUSED) |
161 void *user_data HB_UNUSED) |
113 { |
162 { |
114 *glyph = 0; |
163 *glyph = 0; |
115 return false; |
164 return false; |
116 } |
165 } |
117 static hb_bool_t |
166 static hb_bool_t |
118 hb_font_get_variation_glyph_parent (hb_font_t *font, |
167 hb_font_get_variation_glyph_default (hb_font_t *font, |
119 void *font_data HB_UNUSED, |
168 void *font_data HB_UNUSED, |
120 hb_codepoint_t unicode, |
169 hb_codepoint_t unicode, |
121 hb_codepoint_t variation_selector, |
170 hb_codepoint_t variation_selector, |
122 hb_codepoint_t *glyph, |
171 hb_codepoint_t *glyph, |
123 void *user_data HB_UNUSED) |
172 void *user_data HB_UNUSED) |
124 { |
173 { |
125 return font->parent->get_variation_glyph (unicode, variation_selector, glyph); |
174 return font->parent->get_variation_glyph (unicode, variation_selector, glyph); |
126 } |
175 } |
127 |
176 |
128 |
177 |
129 static hb_position_t |
178 static hb_position_t |
130 hb_font_get_glyph_h_advance_nil (hb_font_t *font, |
179 hb_font_get_glyph_h_advance_nil (hb_font_t *font, |
131 void *font_data HB_UNUSED, |
180 void *font_data HB_UNUSED, |
132 hb_codepoint_t glyph, |
181 hb_codepoint_t glyph HB_UNUSED, |
133 void *user_data HB_UNUSED) |
182 void *user_data HB_UNUSED) |
134 { |
183 { |
135 return font->x_scale; |
184 return font->x_scale; |
136 } |
185 } |
137 static hb_position_t |
186 static hb_position_t |
138 hb_font_get_glyph_h_advance_parent (hb_font_t *font, |
187 hb_font_get_glyph_h_advance_default (hb_font_t *font, |
139 void *font_data HB_UNUSED, |
188 void *font_data HB_UNUSED, |
140 hb_codepoint_t glyph, |
189 hb_codepoint_t glyph, |
141 void *user_data HB_UNUSED) |
190 void *user_data HB_UNUSED) |
142 { |
191 { |
192 if (font->has_glyph_h_advances_func_set ()) |
|
193 { |
|
194 hb_position_t ret; |
|
195 font->get_glyph_h_advances (1, &glyph, 0, &ret, 0); |
|
196 return ret; |
|
197 } |
|
143 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph)); |
198 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph)); |
144 } |
199 } |
145 |
200 |
146 static hb_position_t |
201 static hb_position_t |
147 hb_font_get_glyph_v_advance_nil (hb_font_t *font, |
202 hb_font_get_glyph_v_advance_nil (hb_font_t *font, |
148 void *font_data HB_UNUSED, |
203 void *font_data HB_UNUSED, |
149 hb_codepoint_t glyph, |
204 hb_codepoint_t glyph HB_UNUSED, |
150 void *user_data HB_UNUSED) |
205 void *user_data HB_UNUSED) |
151 { |
206 { |
152 /* TODO use font_extents.ascender+descender */ |
207 /* TODO use font_extents.ascender+descender */ |
153 return font->y_scale; |
208 return font->y_scale; |
154 } |
209 } |
155 static hb_position_t |
210 static hb_position_t |
156 hb_font_get_glyph_v_advance_parent (hb_font_t *font, |
211 hb_font_get_glyph_v_advance_default (hb_font_t *font, |
157 void *font_data HB_UNUSED, |
212 void *font_data HB_UNUSED, |
158 hb_codepoint_t glyph, |
213 hb_codepoint_t glyph, |
159 void *user_data HB_UNUSED) |
214 void *user_data HB_UNUSED) |
160 { |
215 { |
216 if (font->has_glyph_v_advances_func_set ()) |
|
217 { |
|
218 hb_position_t ret; |
|
219 font->get_glyph_v_advances (1, &glyph, 0, &ret, 0); |
|
220 return ret; |
|
221 } |
|
161 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph)); |
222 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph)); |
223 } |
|
224 |
|
225 #define hb_font_get_glyph_h_advances_nil hb_font_get_glyph_h_advances_default |
|
226 static void |
|
227 hb_font_get_glyph_h_advances_default (hb_font_t* font, |
|
228 void* font_data HB_UNUSED, |
|
229 unsigned int count, |
|
230 const hb_codepoint_t *first_glyph, |
|
231 unsigned int glyph_stride, |
|
232 hb_position_t *first_advance, |
|
233 unsigned int advance_stride, |
|
234 void *user_data HB_UNUSED) |
|
235 { |
|
236 if (font->has_glyph_h_advance_func_set ()) |
|
237 { |
|
238 for (unsigned int i = 0; i < count; i++) |
|
239 { |
|
240 *first_advance = font->get_glyph_h_advance (*first_glyph); |
|
241 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride); |
|
242 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride); |
|
243 } |
|
244 return; |
|
245 } |
|
246 |
|
247 font->parent->get_glyph_h_advances (count, |
|
248 first_glyph, glyph_stride, |
|
249 first_advance, advance_stride); |
|
250 for (unsigned int i = 0; i < count; i++) |
|
251 { |
|
252 *first_advance = font->parent_scale_x_distance (*first_advance); |
|
253 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride); |
|
254 } |
|
255 } |
|
256 |
|
257 #define hb_font_get_glyph_v_advances_nil hb_font_get_glyph_v_advances_default |
|
258 static void |
|
259 hb_font_get_glyph_v_advances_default (hb_font_t* font, |
|
260 void* font_data HB_UNUSED, |
|
261 unsigned int count, |
|
262 const hb_codepoint_t *first_glyph, |
|
263 unsigned int glyph_stride, |
|
264 hb_position_t *first_advance, |
|
265 unsigned int advance_stride, |
|
266 void *user_data HB_UNUSED) |
|
267 { |
|
268 if (font->has_glyph_v_advance_func_set ()) |
|
269 { |
|
270 for (unsigned int i = 0; i < count; i++) |
|
271 { |
|
272 *first_advance = font->get_glyph_v_advance (*first_glyph); |
|
273 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride); |
|
274 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride); |
|
275 } |
|
276 return; |
|
277 } |
|
278 |
|
279 font->parent->get_glyph_v_advances (count, |
|
280 first_glyph, glyph_stride, |
|
281 first_advance, advance_stride); |
|
282 for (unsigned int i = 0; i < count; i++) |
|
283 { |
|
284 *first_advance = font->parent_scale_y_distance (*first_advance); |
|
285 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride); |
|
286 } |
|
162 } |
287 } |
163 |
288 |
164 static hb_bool_t |
289 static hb_bool_t |
165 hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED, |
290 hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED, |
166 void *font_data HB_UNUSED, |
291 void *font_data HB_UNUSED, |
167 hb_codepoint_t glyph, |
292 hb_codepoint_t glyph HB_UNUSED, |
168 hb_position_t *x, |
293 hb_position_t *x, |
169 hb_position_t *y, |
294 hb_position_t *y, |
170 void *user_data HB_UNUSED) |
295 void *user_data HB_UNUSED) |
171 { |
296 { |
172 *x = *y = 0; |
297 *x = *y = 0; |
173 return true; |
298 return true; |
174 } |
299 } |
175 static hb_bool_t |
300 static hb_bool_t |
176 hb_font_get_glyph_h_origin_parent (hb_font_t *font, |
301 hb_font_get_glyph_h_origin_default (hb_font_t *font, |
177 void *font_data HB_UNUSED, |
302 void *font_data HB_UNUSED, |
178 hb_codepoint_t glyph, |
303 hb_codepoint_t glyph, |
179 hb_position_t *x, |
304 hb_position_t *x, |
180 hb_position_t *y, |
305 hb_position_t *y, |
181 void *user_data HB_UNUSED) |
306 void *user_data HB_UNUSED) |
182 { |
307 { |
183 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y); |
308 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y); |
184 if (ret) |
309 if (ret) |
185 font->parent_scale_position (x, y); |
310 font->parent_scale_position (x, y); |
186 return ret; |
311 return ret; |
187 } |
312 } |
188 |
313 |
189 static hb_bool_t |
314 static hb_bool_t |
190 hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED, |
315 hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED, |
191 void *font_data HB_UNUSED, |
316 void *font_data HB_UNUSED, |
192 hb_codepoint_t glyph, |
317 hb_codepoint_t glyph HB_UNUSED, |
193 hb_position_t *x, |
318 hb_position_t *x, |
194 hb_position_t *y, |
319 hb_position_t *y, |
195 void *user_data HB_UNUSED) |
320 void *user_data HB_UNUSED) |
196 { |
321 { |
197 *x = *y = 0; |
322 *x = *y = 0; |
198 return false; |
323 return false; |
199 } |
324 } |
200 static hb_bool_t |
325 static hb_bool_t |
201 hb_font_get_glyph_v_origin_parent (hb_font_t *font, |
326 hb_font_get_glyph_v_origin_default (hb_font_t *font, |
202 void *font_data HB_UNUSED, |
327 void *font_data HB_UNUSED, |
203 hb_codepoint_t glyph, |
328 hb_codepoint_t glyph, |
204 hb_position_t *x, |
329 hb_position_t *x, |
205 hb_position_t *y, |
330 hb_position_t *y, |
206 void *user_data HB_UNUSED) |
331 void *user_data HB_UNUSED) |
207 { |
332 { |
208 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y); |
333 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y); |
209 if (ret) |
334 if (ret) |
210 font->parent_scale_position (x, y); |
335 font->parent_scale_position (x, y); |
211 return ret; |
336 return ret; |
212 } |
337 } |
213 |
338 |
214 static hb_position_t |
339 static hb_position_t |
215 hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED, |
340 hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED, |
216 void *font_data HB_UNUSED, |
341 void *font_data HB_UNUSED, |
217 hb_codepoint_t left_glyph, |
342 hb_codepoint_t left_glyph HB_UNUSED, |
218 hb_codepoint_t right_glyph, |
343 hb_codepoint_t right_glyph HB_UNUSED, |
219 void *user_data HB_UNUSED) |
344 void *user_data HB_UNUSED) |
220 { |
345 { |
221 return 0; |
346 return 0; |
222 } |
347 } |
223 static hb_position_t |
348 static hb_position_t |
224 hb_font_get_glyph_h_kerning_parent (hb_font_t *font, |
349 hb_font_get_glyph_h_kerning_default (hb_font_t *font, |
225 void *font_data HB_UNUSED, |
350 void *font_data HB_UNUSED, |
226 hb_codepoint_t left_glyph, |
351 hb_codepoint_t left_glyph, |
227 hb_codepoint_t right_glyph, |
352 hb_codepoint_t right_glyph, |
228 void *user_data HB_UNUSED) |
353 void *user_data HB_UNUSED) |
229 { |
354 { |
230 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph)); |
355 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph)); |
231 } |
356 } |
232 |
357 |
233 static hb_position_t |
358 static hb_position_t |
234 hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED, |
359 hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED, |
235 void *font_data HB_UNUSED, |
360 void *font_data HB_UNUSED, |
236 hb_codepoint_t top_glyph, |
361 hb_codepoint_t top_glyph HB_UNUSED, |
237 hb_codepoint_t bottom_glyph, |
362 hb_codepoint_t bottom_glyph HB_UNUSED, |
238 void *user_data HB_UNUSED) |
363 void *user_data HB_UNUSED) |
239 { |
364 { |
240 return 0; |
365 return 0; |
241 } |
366 } |
242 static hb_position_t |
367 static hb_position_t |
243 hb_font_get_glyph_v_kerning_parent (hb_font_t *font, |
368 hb_font_get_glyph_v_kerning_default (hb_font_t *font, |
244 void *font_data HB_UNUSED, |
369 void *font_data HB_UNUSED, |
245 hb_codepoint_t top_glyph, |
370 hb_codepoint_t top_glyph, |
246 hb_codepoint_t bottom_glyph, |
371 hb_codepoint_t bottom_glyph, |
247 void *user_data HB_UNUSED) |
372 void *user_data HB_UNUSED) |
248 { |
373 { |
249 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph)); |
374 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph)); |
250 } |
375 } |
251 |
376 |
252 static hb_bool_t |
377 static hb_bool_t |
253 hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED, |
378 hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED, |
254 void *font_data HB_UNUSED, |
379 void *font_data HB_UNUSED, |
255 hb_codepoint_t glyph, |
380 hb_codepoint_t glyph HB_UNUSED, |
256 hb_glyph_extents_t *extents, |
381 hb_glyph_extents_t *extents, |
257 void *user_data HB_UNUSED) |
382 void *user_data HB_UNUSED) |
258 { |
383 { |
259 memset (extents, 0, sizeof (*extents)); |
384 memset (extents, 0, sizeof (*extents)); |
260 return false; |
385 return false; |
261 } |
386 } |
262 static hb_bool_t |
387 static hb_bool_t |
263 hb_font_get_glyph_extents_parent (hb_font_t *font, |
388 hb_font_get_glyph_extents_default (hb_font_t *font, |
264 void *font_data HB_UNUSED, |
389 void *font_data HB_UNUSED, |
265 hb_codepoint_t glyph, |
390 hb_codepoint_t glyph, |
266 hb_glyph_extents_t *extents, |
391 hb_glyph_extents_t *extents, |
267 void *user_data HB_UNUSED) |
392 void *user_data HB_UNUSED) |
268 { |
393 { |
269 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents); |
394 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents); |
270 if (ret) { |
395 if (ret) { |
271 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing); |
396 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing); |
272 font->parent_scale_distance (&extents->width, &extents->height); |
397 font->parent_scale_distance (&extents->width, &extents->height); |
275 } |
400 } |
276 |
401 |
277 static hb_bool_t |
402 static hb_bool_t |
278 hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED, |
403 hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED, |
279 void *font_data HB_UNUSED, |
404 void *font_data HB_UNUSED, |
280 hb_codepoint_t glyph, |
405 hb_codepoint_t glyph HB_UNUSED, |
281 unsigned int point_index, |
406 unsigned int point_index HB_UNUSED, |
282 hb_position_t *x, |
407 hb_position_t *x, |
283 hb_position_t *y, |
408 hb_position_t *y, |
284 void *user_data HB_UNUSED) |
409 void *user_data HB_UNUSED) |
285 { |
410 { |
286 *x = *y = 0; |
411 *x = *y = 0; |
287 return false; |
412 return false; |
288 } |
413 } |
289 static hb_bool_t |
414 static hb_bool_t |
290 hb_font_get_glyph_contour_point_parent (hb_font_t *font, |
415 hb_font_get_glyph_contour_point_default (hb_font_t *font, |
291 void *font_data HB_UNUSED, |
416 void *font_data HB_UNUSED, |
292 hb_codepoint_t glyph, |
417 hb_codepoint_t glyph, |
293 unsigned int point_index, |
418 unsigned int point_index, |
294 hb_position_t *x, |
419 hb_position_t *x, |
295 hb_position_t *y, |
420 hb_position_t *y, |
296 void *user_data HB_UNUSED) |
421 void *user_data HB_UNUSED) |
297 { |
422 { |
298 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y); |
423 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y); |
299 if (ret) |
424 if (ret) |
300 font->parent_scale_position (x, y); |
425 font->parent_scale_position (x, y); |
301 return ret; |
426 return ret; |
302 } |
427 } |
303 |
428 |
304 static hb_bool_t |
429 static hb_bool_t |
305 hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED, |
430 hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED, |
306 void *font_data HB_UNUSED, |
431 void *font_data HB_UNUSED, |
307 hb_codepoint_t glyph, |
432 hb_codepoint_t glyph HB_UNUSED, |
308 char *name, unsigned int size, |
433 char *name, unsigned int size, |
309 void *user_data HB_UNUSED) |
434 void *user_data HB_UNUSED) |
310 { |
435 { |
311 if (size) *name = '\0'; |
436 if (size) *name = '\0'; |
312 return false; |
437 return false; |
313 } |
438 } |
314 static hb_bool_t |
439 static hb_bool_t |
315 hb_font_get_glyph_name_parent (hb_font_t *font, |
440 hb_font_get_glyph_name_default (hb_font_t *font, |
316 void *font_data HB_UNUSED, |
441 void *font_data HB_UNUSED, |
317 hb_codepoint_t glyph, |
442 hb_codepoint_t glyph, |
318 char *name, unsigned int size, |
443 char *name, unsigned int size, |
319 void *user_data HB_UNUSED) |
444 void *user_data HB_UNUSED) |
320 { |
445 { |
321 return font->parent->get_glyph_name (glyph, name, size); |
446 return font->parent->get_glyph_name (glyph, name, size); |
322 } |
447 } |
323 |
448 |
324 static hb_bool_t |
449 static hb_bool_t |
325 hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED, |
450 hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED, |
326 void *font_data HB_UNUSED, |
451 void *font_data HB_UNUSED, |
327 const char *name, int len, /* -1 means nul-terminated */ |
452 const char *name HB_UNUSED, |
453 int len HB_UNUSED, /* -1 means nul-terminated */ |
|
328 hb_codepoint_t *glyph, |
454 hb_codepoint_t *glyph, |
329 void *user_data HB_UNUSED) |
455 void *user_data HB_UNUSED) |
330 { |
456 { |
331 *glyph = 0; |
457 *glyph = 0; |
332 return false; |
458 return false; |
333 } |
459 } |
334 static hb_bool_t |
460 static hb_bool_t |
335 hb_font_get_glyph_from_name_parent (hb_font_t *font, |
461 hb_font_get_glyph_from_name_default (hb_font_t *font, |
336 void *font_data HB_UNUSED, |
462 void *font_data HB_UNUSED, |
337 const char *name, int len, /* -1 means nul-terminated */ |
463 const char *name, int len, /* -1 means nul-terminated */ |
338 hb_codepoint_t *glyph, |
464 hb_codepoint_t *glyph, |
339 void *user_data HB_UNUSED) |
465 void *user_data HB_UNUSED) |
340 { |
466 { |
341 return font->parent->get_glyph_from_name (name, len, glyph); |
467 return font->parent->get_glyph_from_name (name, len, glyph); |
342 } |
468 } |
343 |
469 |
344 static const hb_font_funcs_t _hb_font_funcs_nil = { |
470 DEFINE_NULL_INSTANCE (hb_font_funcs_t) = |
471 { |
|
345 HB_OBJECT_HEADER_STATIC, |
472 HB_OBJECT_HEADER_STATIC, |
346 |
|
347 true, /* immutable */ |
|
348 |
473 |
349 { |
474 { |
350 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr, |
475 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr, |
351 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
476 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
352 #undef HB_FONT_FUNC_IMPLEMENT |
477 #undef HB_FONT_FUNC_IMPLEMENT |
362 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
487 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
363 #undef HB_FONT_FUNC_IMPLEMENT |
488 #undef HB_FONT_FUNC_IMPLEMENT |
364 } |
489 } |
365 } |
490 } |
366 }; |
491 }; |
367 static const hb_font_funcs_t _hb_font_funcs_parent = { |
492 |
493 static const hb_font_funcs_t _hb_font_funcs_default = { |
|
368 HB_OBJECT_HEADER_STATIC, |
494 HB_OBJECT_HEADER_STATIC, |
369 |
|
370 true, /* immutable */ |
|
371 |
495 |
372 { |
496 { |
373 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr, |
497 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr, |
374 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
498 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
375 #undef HB_FONT_FUNC_IMPLEMENT |
499 #undef HB_FONT_FUNC_IMPLEMENT |
379 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
503 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
380 #undef HB_FONT_FUNC_IMPLEMENT |
504 #undef HB_FONT_FUNC_IMPLEMENT |
381 }, |
505 }, |
382 { |
506 { |
383 { |
507 { |
384 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_parent, |
508 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_default, |
385 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
509 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
386 #undef HB_FONT_FUNC_IMPLEMENT |
510 #undef HB_FONT_FUNC_IMPLEMENT |
387 } |
511 } |
388 } |
512 } |
389 }; |
513 }; |
397 * Return value: (transfer full): |
521 * Return value: (transfer full): |
398 * |
522 * |
399 * Since: 0.9.2 |
523 * Since: 0.9.2 |
400 **/ |
524 **/ |
401 hb_font_funcs_t * |
525 hb_font_funcs_t * |
402 hb_font_funcs_create (void) |
526 hb_font_funcs_create () |
403 { |
527 { |
404 hb_font_funcs_t *ffuncs; |
528 hb_font_funcs_t *ffuncs; |
405 |
529 |
406 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ())) |
530 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ())) |
407 return hb_font_funcs_get_empty (); |
531 return hb_font_funcs_get_empty (); |
408 |
532 |
409 ffuncs->get = _hb_font_funcs_parent.get; |
533 ffuncs->get = _hb_font_funcs_default.get; |
410 |
534 |
411 return ffuncs; |
535 return ffuncs; |
412 } |
536 } |
413 |
537 |
414 /** |
538 /** |
419 * Return value: (transfer full): |
543 * Return value: (transfer full): |
420 * |
544 * |
421 * Since: 0.9.2 |
545 * Since: 0.9.2 |
422 **/ |
546 **/ |
423 hb_font_funcs_t * |
547 hb_font_funcs_t * |
424 hb_font_funcs_get_empty (void) |
548 hb_font_funcs_get_empty () |
425 { |
549 { |
426 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_parent); |
550 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_default); |
427 } |
551 } |
428 |
552 |
429 /** |
553 /** |
430 * hb_font_funcs_reference: (skip) |
554 * hb_font_funcs_reference: (skip) |
431 * @ffuncs: font functions. |
555 * @ffuncs: font functions. |
515 * Since: 0.9.2 |
639 * Since: 0.9.2 |
516 **/ |
640 **/ |
517 void |
641 void |
518 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs) |
642 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs) |
519 { |
643 { |
520 if (unlikely (hb_object_is_inert (ffuncs))) |
644 if (hb_object_is_immutable (ffuncs)) |
521 return; |
645 return; |
522 |
646 |
523 ffuncs->immutable = true; |
647 hb_object_make_immutable (ffuncs); |
524 } |
648 } |
525 |
649 |
526 /** |
650 /** |
527 * hb_font_funcs_is_immutable: |
651 * hb_font_funcs_is_immutable: |
528 * @ffuncs: font functions. |
652 * @ffuncs: font functions. |
534 * Since: 0.9.2 |
658 * Since: 0.9.2 |
535 **/ |
659 **/ |
536 hb_bool_t |
660 hb_bool_t |
537 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs) |
661 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs) |
538 { |
662 { |
539 return ffuncs->immutable; |
663 return hb_object_is_immutable (ffuncs); |
540 } |
664 } |
541 |
665 |
542 |
666 |
543 #define HB_FONT_FUNC_IMPLEMENT(name) \ |
667 #define HB_FONT_FUNC_IMPLEMENT(name) \ |
544 \ |
668 \ |
546 hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \ |
670 hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \ |
547 hb_font_get_##name##_func_t func, \ |
671 hb_font_get_##name##_func_t func, \ |
548 void *user_data, \ |
672 void *user_data, \ |
549 hb_destroy_func_t destroy) \ |
673 hb_destroy_func_t destroy) \ |
550 { \ |
674 { \ |
551 if (ffuncs->immutable) { \ |
675 if (hb_object_is_immutable (ffuncs)) { \ |
552 if (destroy) \ |
676 if (destroy) \ |
553 destroy (user_data); \ |
677 destroy (user_data); \ |
554 return; \ |
678 return; \ |
555 } \ |
679 } \ |
556 \ |
680 \ |
560 if (func) { \ |
684 if (func) { \ |
561 ffuncs->get.f.name = func; \ |
685 ffuncs->get.f.name = func; \ |
562 ffuncs->user_data.name = user_data; \ |
686 ffuncs->user_data.name = user_data; \ |
563 ffuncs->destroy.name = destroy; \ |
687 ffuncs->destroy.name = destroy; \ |
564 } else { \ |
688 } else { \ |
565 ffuncs->get.f.name = hb_font_get_##name##_parent; \ |
689 ffuncs->get.f.name = hb_font_get_##name##_default; \ |
566 ffuncs->user_data.name = nullptr; \ |
690 ffuncs->user_data.name = nullptr; \ |
567 ffuncs->destroy.name = nullptr; \ |
691 ffuncs->destroy.name = nullptr; \ |
568 } \ |
692 } \ |
569 } |
693 } |
570 |
694 |
571 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
695 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
572 #undef HB_FONT_FUNC_IMPLEMENT |
696 #undef HB_FONT_FUNC_IMPLEMENT |
573 |
697 |
574 bool |
698 bool |
699 hb_font_t::has_func_set (unsigned int i) |
|
700 { |
|
701 return this->klass->get.array[i] != _hb_font_funcs_default.get.array[i]; |
|
702 } |
|
703 |
|
704 bool |
|
575 hb_font_t::has_func (unsigned int i) |
705 hb_font_t::has_func (unsigned int i) |
576 { |
706 { |
577 if (parent && parent != hb_font_get_empty () && parent->has_func (i)) |
707 return has_func_set (i) || |
578 return true; |
708 (parent && parent != &_hb_Null_hb_font_t && parent->has_func (i)); |
579 return this->klass->get.array[i] != _hb_font_funcs_parent.get.array[i]; |
|
580 } |
709 } |
581 |
710 |
582 /* Public getters */ |
711 /* Public getters */ |
583 |
712 |
584 /** |
713 /** |
716 { |
845 { |
717 return font->get_glyph_v_advance (glyph); |
846 return font->get_glyph_v_advance (glyph); |
718 } |
847 } |
719 |
848 |
720 /** |
849 /** |
850 * hb_font_get_glyph_h_advances: |
|
851 * @font: a font. |
|
852 * |
|
853 * |
|
854 * |
|
855 * Since: 1.8.6 |
|
856 **/ |
|
857 void |
|
858 hb_font_get_glyph_h_advances (hb_font_t* font, |
|
859 unsigned int count, |
|
860 const hb_codepoint_t *first_glyph, |
|
861 unsigned glyph_stride, |
|
862 hb_position_t *first_advance, |
|
863 unsigned advance_stride) |
|
864 { |
|
865 font->get_glyph_h_advances (count, first_glyph, glyph_stride, first_advance, advance_stride); |
|
866 } |
|
867 /** |
|
868 * hb_font_get_glyph_v_advances: |
|
869 * @font: a font. |
|
870 * |
|
871 * |
|
872 * |
|
873 * Since: 1.8.6 |
|
874 **/ |
|
875 void |
|
876 hb_font_get_glyph_v_advances (hb_font_t* font, |
|
877 unsigned int count, |
|
878 const hb_codepoint_t *first_glyph, |
|
879 unsigned glyph_stride, |
|
880 hb_position_t *first_advance, |
|
881 unsigned advance_stride) |
|
882 { |
|
883 font->get_glyph_v_advances (count, first_glyph, glyph_stride, first_advance, advance_stride); |
|
884 } |
|
885 |
|
886 /** |
|
721 * hb_font_get_glyph_h_origin: |
887 * hb_font_get_glyph_h_origin: |
722 * @font: a font. |
888 * @font: a font. |
723 * @glyph: |
889 * @glyph: |
724 * @x: (out): |
890 * @x: (out): |
725 * @y: (out): |
891 * @y: (out): |
768 * |
934 * |
769 * |
935 * |
770 * Return value: |
936 * Return value: |
771 * |
937 * |
772 * Since: 0.9.2 |
938 * Since: 0.9.2 |
939 * Deprecated: 2.0.0 |
|
773 **/ |
940 **/ |
774 hb_position_t |
941 hb_position_t |
775 hb_font_get_glyph_h_kerning (hb_font_t *font, |
942 hb_font_get_glyph_h_kerning (hb_font_t *font, |
776 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph) |
943 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph) |
777 { |
944 { |
787 * |
954 * |
788 * |
955 * |
789 * Return value: |
956 * Return value: |
790 * |
957 * |
791 * Since: 0.9.2 |
958 * Since: 0.9.2 |
959 * Deprecated: 2.0.0 |
|
792 **/ |
960 **/ |
793 hb_position_t |
961 hb_position_t |
794 hb_font_get_glyph_v_kerning (hb_font_t *font, |
962 hb_font_get_glyph_v_kerning (hb_font_t *font, |
795 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph) |
963 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph) |
796 { |
964 { |
886 |
1054 |
887 /** |
1055 /** |
888 * hb_font_get_extents_for_direction: |
1056 * hb_font_get_extents_for_direction: |
889 * @font: a font. |
1057 * @font: a font. |
890 * @direction: |
1058 * @direction: |
891 * @extents: |
1059 * @extents: (out): |
892 * |
1060 * |
893 * |
1061 * |
894 * |
1062 * |
895 * Since: 1.1.3 |
1063 * Since: 1.1.3 |
896 **/ |
1064 **/ |
918 hb_codepoint_t glyph, |
1086 hb_codepoint_t glyph, |
919 hb_direction_t direction, |
1087 hb_direction_t direction, |
920 hb_position_t *x, hb_position_t *y) |
1088 hb_position_t *x, hb_position_t *y) |
921 { |
1089 { |
922 return font->get_glyph_advance_for_direction (glyph, direction, x, y); |
1090 return font->get_glyph_advance_for_direction (glyph, direction, x, y); |
1091 } |
|
1092 /** |
|
1093 * hb_font_get_glyph_advances_for_direction: |
|
1094 * @font: a font. |
|
1095 * @direction: |
|
1096 * |
|
1097 * |
|
1098 * |
|
1099 * Since: 1.8.6 |
|
1100 **/ |
|
1101 HB_EXTERN void |
|
1102 hb_font_get_glyph_advances_for_direction (hb_font_t* font, |
|
1103 hb_direction_t direction, |
|
1104 unsigned int count, |
|
1105 const hb_codepoint_t *first_glyph, |
|
1106 unsigned glyph_stride, |
|
1107 hb_position_t *first_advance, |
|
1108 unsigned advance_stride) |
|
1109 { |
|
1110 font->get_glyph_advances_for_direction (direction, count, first_glyph, glyph_stride, first_advance, advance_stride); |
|
923 } |
1111 } |
924 |
1112 |
925 /** |
1113 /** |
926 * hb_font_get_glyph_origin_for_direction: |
1114 * hb_font_get_glyph_origin_for_direction: |
927 * @font: a font. |
1115 * @font: a font. |
995 * @y: (out): |
1183 * @y: (out): |
996 * |
1184 * |
997 * |
1185 * |
998 * |
1186 * |
999 * Since: 0.9.2 |
1187 * Since: 0.9.2 |
1188 * Deprecated: 2.0.0 |
|
1000 **/ |
1189 **/ |
1001 void |
1190 void |
1002 hb_font_get_glyph_kerning_for_direction (hb_font_t *font, |
1191 hb_font_get_glyph_kerning_for_direction (hb_font_t *font, |
1003 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, |
1192 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, |
1004 hb_direction_t direction, |
1193 hb_direction_t direction, |
1098 |
1287 |
1099 /* |
1288 /* |
1100 * hb_font_t |
1289 * hb_font_t |
1101 */ |
1290 */ |
1102 |
1291 |
1103 /** |
1292 DEFINE_NULL_INSTANCE (hb_font_t) = |
1104 * hb_font_create: (Xconstructor) |
1293 { |
1105 * @face: a face. |
1294 HB_OBJECT_HEADER_STATIC, |
1106 * |
1295 |
1107 * |
1296 nullptr, /* parent */ |
1108 * |
1297 const_cast<hb_face_t *> (&_hb_Null_hb_face_t), |
1109 * Return value: (transfer full): |
1298 |
1110 * |
1299 1000, /* x_scale */ |
1111 * Since: 0.9.2 |
1300 1000, /* y_scale */ |
1112 **/ |
1301 |
1113 hb_font_t * |
1302 0, /* x_ppem */ |
1114 hb_font_create (hb_face_t *face) |
1303 0, /* y_ppem */ |
1304 0, /* ptem */ |
|
1305 |
|
1306 0, /* num_coords */ |
|
1307 nullptr, /* coords */ |
|
1308 |
|
1309 const_cast<hb_font_funcs_t *> (&_hb_Null_hb_font_funcs_t), |
|
1310 |
|
1311 /* Zero for the rest is fine. */ |
|
1312 }; |
|
1313 |
|
1314 |
|
1315 static hb_font_t * |
|
1316 _hb_font_create (hb_face_t *face) |
|
1115 { |
1317 { |
1116 hb_font_t *font; |
1318 hb_font_t *font; |
1117 |
1319 |
1118 if (unlikely (!face)) |
1320 if (unlikely (!face)) |
1119 face = hb_face_get_empty (); |
1321 face = hb_face_get_empty (); |
1122 |
1324 |
1123 hb_face_make_immutable (face); |
1325 hb_face_make_immutable (face); |
1124 font->parent = hb_font_get_empty (); |
1326 font->parent = hb_font_get_empty (); |
1125 font->face = hb_face_reference (face); |
1327 font->face = hb_face_reference (face); |
1126 font->klass = hb_font_funcs_get_empty (); |
1328 font->klass = hb_font_funcs_get_empty (); |
1127 |
1329 font->data.init0 (font); |
1128 font->x_scale = font->y_scale = hb_face_get_upem (face); |
1330 font->x_scale = font->y_scale = hb_face_get_upem (face); |
1331 |
|
1332 return font; |
|
1333 } |
|
1334 |
|
1335 /** |
|
1336 * hb_font_create: (Xconstructor) |
|
1337 * @face: a face. |
|
1338 * |
|
1339 * |
|
1340 * |
|
1341 * Return value: (transfer full): |
|
1342 * |
|
1343 * Since: 0.9.2 |
|
1344 **/ |
|
1345 hb_font_t * |
|
1346 hb_font_create (hb_face_t *face) |
|
1347 { |
|
1348 hb_font_t *font = _hb_font_create (face); |
|
1349 |
|
1350 /* Install our in-house, very lightweight, funcs. */ |
|
1351 hb_ot_font_set_funcs (font); |
|
1129 |
1352 |
1130 return font; |
1353 return font; |
1131 } |
1354 } |
1132 |
1355 |
1133 /** |
1356 /** |
1144 hb_font_create_sub_font (hb_font_t *parent) |
1367 hb_font_create_sub_font (hb_font_t *parent) |
1145 { |
1368 { |
1146 if (unlikely (!parent)) |
1369 if (unlikely (!parent)) |
1147 parent = hb_font_get_empty (); |
1370 parent = hb_font_get_empty (); |
1148 |
1371 |
1149 hb_font_t *font = hb_font_create (parent->face); |
1372 hb_font_t *font = _hb_font_create (parent->face); |
1150 |
1373 |
1151 if (unlikely (hb_object_is_inert (font))) |
1374 if (unlikely (hb_object_is_immutable (font))) |
1152 return font; |
1375 return font; |
1153 |
1376 |
1154 font->parent = hb_font_reference (parent); |
1377 font->parent = hb_font_reference (parent); |
1155 |
1378 |
1156 font->x_scale = parent->x_scale; |
1379 font->x_scale = parent->x_scale; |
1183 * Return value: (transfer full) |
1406 * Return value: (transfer full) |
1184 * |
1407 * |
1185 * Since: 0.9.2 |
1408 * Since: 0.9.2 |
1186 **/ |
1409 **/ |
1187 hb_font_t * |
1410 hb_font_t * |
1188 hb_font_get_empty (void) |
1411 hb_font_get_empty () |
1189 { |
1412 { |
1190 static const hb_font_t _hb_font_nil = { |
1413 return const_cast<hb_font_t *> (&Null(hb_font_t)); |
1191 HB_OBJECT_HEADER_STATIC, |
|
1192 |
|
1193 true, /* immutable */ |
|
1194 |
|
1195 nullptr, /* parent */ |
|
1196 const_cast<hb_face_t *> (&_hb_face_nil), |
|
1197 |
|
1198 1000, /* x_scale */ |
|
1199 1000, /* y_scale */ |
|
1200 |
|
1201 0, /* x_ppem */ |
|
1202 0, /* y_ppem */ |
|
1203 0, /* ptem */ |
|
1204 |
|
1205 0, /* num_coords */ |
|
1206 nullptr, /* coords */ |
|
1207 |
|
1208 const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */ |
|
1209 nullptr, /* user_data */ |
|
1210 nullptr, /* destroy */ |
|
1211 |
|
1212 { |
|
1213 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, |
|
1214 #include "hb-shaper-list.hh" |
|
1215 #undef HB_SHAPER_IMPLEMENT |
|
1216 } |
|
1217 }; |
|
1218 |
|
1219 return const_cast<hb_font_t *> (&_hb_font_nil); |
|
1220 } |
1414 } |
1221 |
1415 |
1222 /** |
1416 /** |
1223 * hb_font_reference: (skip) |
1417 * hb_font_reference: (skip) |
1224 * @font: a font. |
1418 * @font: a font. |
1246 void |
1440 void |
1247 hb_font_destroy (hb_font_t *font) |
1441 hb_font_destroy (hb_font_t *font) |
1248 { |
1442 { |
1249 if (!hb_object_destroy (font)) return; |
1443 if (!hb_object_destroy (font)) return; |
1250 |
1444 |
1251 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font); |
1445 font->data.fini (); |
1252 #include "hb-shaper-list.hh" |
|
1253 #undef HB_SHAPER_IMPLEMENT |
|
1254 |
1446 |
1255 if (font->destroy) |
1447 if (font->destroy) |
1256 font->destroy (font->user_data); |
1448 font->destroy (font->user_data); |
1257 |
1449 |
1258 hb_font_destroy (font->parent); |
1450 hb_font_destroy (font->parent); |
1315 * Since: 0.9.2 |
1507 * Since: 0.9.2 |
1316 **/ |
1508 **/ |
1317 void |
1509 void |
1318 hb_font_make_immutable (hb_font_t *font) |
1510 hb_font_make_immutable (hb_font_t *font) |
1319 { |
1511 { |
1320 if (unlikely (hb_object_is_inert (font))) |
1512 if (hb_object_is_immutable (font)) |
1321 return; |
1513 return; |
1322 |
1514 |
1323 if (font->parent) |
1515 if (font->parent) |
1324 hb_font_make_immutable (font->parent); |
1516 hb_font_make_immutable (font->parent); |
1325 |
1517 |
1326 font->immutable = true; |
1518 hb_object_make_immutable (font); |
1327 } |
1519 } |
1328 |
1520 |
1329 /** |
1521 /** |
1330 * hb_font_is_immutable: |
1522 * hb_font_is_immutable: |
1331 * @font: a font. |
1523 * @font: a font. |
1337 * Since: 0.9.2 |
1529 * Since: 0.9.2 |
1338 **/ |
1530 **/ |
1339 hb_bool_t |
1531 hb_bool_t |
1340 hb_font_is_immutable (hb_font_t *font) |
1532 hb_font_is_immutable (hb_font_t *font) |
1341 { |
1533 { |
1342 return font->immutable; |
1534 return hb_object_is_immutable (font); |
1343 } |
1535 } |
1344 |
1536 |
1345 /** |
1537 /** |
1346 * hb_font_set_parent: |
1538 * hb_font_set_parent: |
1347 * @font: a font. |
1539 * @font: a font. |
1353 **/ |
1545 **/ |
1354 void |
1546 void |
1355 hb_font_set_parent (hb_font_t *font, |
1547 hb_font_set_parent (hb_font_t *font, |
1356 hb_font_t *parent) |
1548 hb_font_t *parent) |
1357 { |
1549 { |
1358 if (font->immutable) |
1550 if (hb_object_is_immutable (font)) |
1359 return; |
1551 return; |
1360 |
1552 |
1361 if (!parent) |
1553 if (!parent) |
1362 parent = hb_font_get_empty (); |
1554 parent = hb_font_get_empty (); |
1363 |
1555 |
1395 **/ |
1587 **/ |
1396 void |
1588 void |
1397 hb_font_set_face (hb_font_t *font, |
1589 hb_font_set_face (hb_font_t *font, |
1398 hb_face_t *face) |
1590 hb_face_t *face) |
1399 { |
1591 { |
1400 if (font->immutable) |
1592 if (hb_object_is_immutable (font)) |
1401 return; |
1593 return; |
1402 |
1594 |
1403 if (unlikely (!face)) |
1595 if (unlikely (!face)) |
1404 face = hb_face_get_empty (); |
1596 face = hb_face_get_empty (); |
1405 |
1597 |
1442 hb_font_set_funcs (hb_font_t *font, |
1634 hb_font_set_funcs (hb_font_t *font, |
1443 hb_font_funcs_t *klass, |
1635 hb_font_funcs_t *klass, |
1444 void *font_data, |
1636 void *font_data, |
1445 hb_destroy_func_t destroy) |
1637 hb_destroy_func_t destroy) |
1446 { |
1638 { |
1447 if (font->immutable) { |
1639 if (hb_object_is_immutable (font)) |
1640 { |
|
1448 if (destroy) |
1641 if (destroy) |
1449 destroy (font_data); |
1642 destroy (font_data); |
1450 return; |
1643 return; |
1451 } |
1644 } |
1452 |
1645 |
1477 hb_font_set_funcs_data (hb_font_t *font, |
1670 hb_font_set_funcs_data (hb_font_t *font, |
1478 void *font_data, |
1671 void *font_data, |
1479 hb_destroy_func_t destroy) |
1672 hb_destroy_func_t destroy) |
1480 { |
1673 { |
1481 /* Destroy user_data? */ |
1674 /* Destroy user_data? */ |
1482 if (font->immutable) { |
1675 if (hb_object_is_immutable (font)) |
1676 { |
|
1483 if (destroy) |
1677 if (destroy) |
1484 destroy (font_data); |
1678 destroy (font_data); |
1485 return; |
1679 return; |
1486 } |
1680 } |
1487 |
1681 |
1506 void |
1700 void |
1507 hb_font_set_scale (hb_font_t *font, |
1701 hb_font_set_scale (hb_font_t *font, |
1508 int x_scale, |
1702 int x_scale, |
1509 int y_scale) |
1703 int y_scale) |
1510 { |
1704 { |
1511 if (font->immutable) |
1705 if (hb_object_is_immutable (font)) |
1512 return; |
1706 return; |
1513 |
1707 |
1514 font->x_scale = x_scale; |
1708 font->x_scale = x_scale; |
1515 font->y_scale = y_scale; |
1709 font->y_scale = y_scale; |
1516 } |
1710 } |
1547 void |
1741 void |
1548 hb_font_set_ppem (hb_font_t *font, |
1742 hb_font_set_ppem (hb_font_t *font, |
1549 unsigned int x_ppem, |
1743 unsigned int x_ppem, |
1550 unsigned int y_ppem) |
1744 unsigned int y_ppem) |
1551 { |
1745 { |
1552 if (font->immutable) |
1746 if (hb_object_is_immutable (font)) |
1553 return; |
1747 return; |
1554 |
1748 |
1555 font->x_ppem = x_ppem; |
1749 font->x_ppem = x_ppem; |
1556 font->y_ppem = y_ppem; |
1750 font->y_ppem = y_ppem; |
1557 } |
1751 } |
1576 } |
1770 } |
1577 |
1771 |
1578 /** |
1772 /** |
1579 * hb_font_set_ptem: |
1773 * hb_font_set_ptem: |
1580 * @font: a font. |
1774 * @font: a font. |
1581 * @ptem: |
1775 * @ptem: font size in points. |
1582 * |
1776 * |
1583 * Sets "point size" of the font. |
1777 * Sets "point size" of the font. Set to 0 to unset. |
1778 * |
|
1779 * There are 72 points in an inch. |
|
1584 * |
1780 * |
1585 * Since: 1.6.0 |
1781 * Since: 1.6.0 |
1586 **/ |
1782 **/ |
1587 void |
1783 void |
1588 hb_font_set_ptem (hb_font_t *font, float ptem) |
1784 hb_font_set_ptem (hb_font_t *font, float ptem) |
1589 { |
1785 { |
1590 if (font->immutable) |
1786 if (hb_object_is_immutable (font)) |
1591 return; |
1787 return; |
1592 |
1788 |
1593 font->ptem = ptem; |
1789 font->ptem = ptem; |
1594 } |
1790 } |
1595 |
1791 |
1632 void |
1828 void |
1633 hb_font_set_variations (hb_font_t *font, |
1829 hb_font_set_variations (hb_font_t *font, |
1634 const hb_variation_t *variations, |
1830 const hb_variation_t *variations, |
1635 unsigned int variations_length) |
1831 unsigned int variations_length) |
1636 { |
1832 { |
1637 if (font->immutable) |
1833 if (hb_object_is_immutable (font)) |
1638 return; |
1834 return; |
1639 |
1835 |
1640 if (!variations_length) |
1836 if (!variations_length) |
1641 { |
1837 { |
1642 hb_font_set_var_coords_normalized (font, nullptr, 0); |
1838 hb_font_set_var_coords_normalized (font, nullptr, 0); |
1663 void |
1859 void |
1664 hb_font_set_var_coords_design (hb_font_t *font, |
1860 hb_font_set_var_coords_design (hb_font_t *font, |
1665 const float *coords, |
1861 const float *coords, |
1666 unsigned int coords_length) |
1862 unsigned int coords_length) |
1667 { |
1863 { |
1668 if (font->immutable) |
1864 if (hb_object_is_immutable (font)) |
1669 return; |
1865 return; |
1670 |
1866 |
1671 int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : nullptr; |
1867 int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : nullptr; |
1672 if (unlikely (coords_length && !normalized)) |
1868 if (unlikely (coords_length && !normalized)) |
1673 return; |
1869 return; |
1684 void |
1880 void |
1685 hb_font_set_var_coords_normalized (hb_font_t *font, |
1881 hb_font_set_var_coords_normalized (hb_font_t *font, |
1686 const int *coords, /* 2.14 normalized */ |
1882 const int *coords, /* 2.14 normalized */ |
1687 unsigned int coords_length) |
1883 unsigned int coords_length) |
1688 { |
1884 { |
1689 if (font->immutable) |
1885 if (hb_object_is_immutable (font)) |
1690 return; |
1886 return; |
1691 |
1887 |
1692 int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : nullptr; |
1888 int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : nullptr; |
1693 if (unlikely (coords_length && !copy)) |
1889 if (unlikely (coords_length && !copy)) |
1694 return; |
1890 return; |
1715 *length = font->num_coords; |
1911 *length = font->num_coords; |
1716 |
1912 |
1717 return font->coords; |
1913 return font->coords; |
1718 } |
1914 } |
1719 |
1915 |
1720 |
|
1721 #ifndef HB_DISABLE_DEPRECATED |
|
1722 |
1916 |
1723 /* |
1917 /* |
1724 * Deprecated get_glyph_func(): |
1918 * Deprecated get_glyph_func(): |
1725 */ |
1919 */ |
1726 |
1920 |
1804 } |
1998 } |
1805 |
1999 |
1806 /** |
2000 /** |
1807 * hb_font_funcs_set_glyph_func: |
2001 * hb_font_funcs_set_glyph_func: |
1808 * @ffuncs: font functions. |
2002 * @ffuncs: font functions. |
1809 * @func: (closure user_data) (destroy destroy) (scope notified): |
2003 * @func: (closure user_data) (destroy destroy) (scope notified): callback function. |
1810 * @user_data: |
2004 * @user_data: data to pass to @func. |
1811 * @destroy: |
2005 * @destroy: function to call when @user_data is not needed anymore. |
1812 * |
2006 * |
1813 * Deprecated. Use hb_font_funcs_set_nominal_glyph_func() and |
2007 * Deprecated. Use hb_font_funcs_set_nominal_glyph_func() and |
1814 * hb_font_funcs_set_variation_glyph_func() instead. |
2008 * hb_font_funcs_set_variation_glyph_func() instead. |
1815 * |
2009 * |
1816 * Since: 0.9.2 |
2010 * Since: 0.9.2 |
1840 hb_font_funcs_set_variation_glyph_func (ffuncs, |
2034 hb_font_funcs_set_variation_glyph_func (ffuncs, |
1841 hb_font_get_variation_glyph_trampoline, |
2035 hb_font_get_variation_glyph_trampoline, |
1842 trampoline, |
2036 trampoline, |
1843 trampoline_destroy); |
2037 trampoline_destroy); |
1844 } |
2038 } |
1845 |
|
1846 #endif /* HB_DISABLE_DEPRECATED */ |