OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2009 Red Hat, Inc. | 2 * Copyright © 2009 Red Hat, Inc. |
3 * Copyright © 2011 Google, Inc. | 3 * Copyright © 2011 Google, Inc. |
4 * | 4 * |
5 * This is part of HarfBuzz, a text shaping library. | 5 * This is part of HarfBuzz, a text shaping library. |
6 * | 6 * |
7 * Permission is hereby granted, without written agreement and without | 7 * Permission is hereby granted, without written agreement and without |
8 * license or royalty fees, to use, copy, modify, and distribute this | 8 * license or royalty fees, to use, copy, modify, and distribute this |
9 * software and its documentation for any purpose, provided that the | 9 * software and its documentation for any purpose, provided that the |
10 * above copyright notice and the following two paragraphs appear in | 10 * above copyright notice and the following two paragraphs appear in |
(...skipping 15 matching lines...) Expand all Loading... |
26 * Google Author(s): Behdad Esfahbod | 26 * Google Author(s): Behdad Esfahbod |
27 */ | 27 */ |
28 | 28 |
29 #ifndef HB_FONT_PRIVATE_HH | 29 #ifndef HB_FONT_PRIVATE_HH |
30 #define HB_FONT_PRIVATE_HH | 30 #define HB_FONT_PRIVATE_HH |
31 | 31 |
32 #include "hb-private.hh" | 32 #include "hb-private.hh" |
33 | 33 |
34 #include "hb-font.h" | 34 #include "hb-font.h" |
35 #include "hb-object-private.hh" | 35 #include "hb-object-private.hh" |
| 36 #include "hb-face-private.hh" |
36 #include "hb-shaper-private.hh" | 37 #include "hb-shaper-private.hh" |
37 #include "hb-shape-plan-private.hh" | |
38 | 38 |
39 | 39 |
40 | 40 |
41 /* | 41 /* |
42 * hb_font_funcs_t | 42 * hb_font_funcs_t |
43 */ | 43 */ |
44 | 44 |
45 #define HB_FONT_FUNCS_IMPLEMENT_CALLBACKS \ | 45 #define HB_FONT_FUNCS_IMPLEMENT_CALLBACKS \ |
46 HB_FONT_FUNC_IMPLEMENT (glyph) \ | 46 HB_FONT_FUNC_IMPLEMENT (glyph) \ |
47 HB_FONT_FUNC_IMPLEMENT (glyph_h_advance) \ | 47 HB_FONT_FUNC_IMPLEMENT (glyph_h_advance) \ |
(...skipping 29 matching lines...) Expand all Loading... |
77 } user_data; | 77 } user_data; |
78 | 78 |
79 struct { | 79 struct { |
80 #define HB_FONT_FUNC_IMPLEMENT(name) hb_destroy_func_t name; | 80 #define HB_FONT_FUNC_IMPLEMENT(name) hb_destroy_func_t name; |
81 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS | 81 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
82 #undef HB_FONT_FUNC_IMPLEMENT | 82 #undef HB_FONT_FUNC_IMPLEMENT |
83 } destroy; | 83 } destroy; |
84 }; | 84 }; |
85 | 85 |
86 | 86 |
87 /* | |
88 * hb_face_t | |
89 */ | |
90 | |
91 struct hb_face_t { | |
92 hb_object_header_t header; | |
93 ASSERT_POD (); | |
94 | |
95 hb_bool_t immutable; | |
96 | |
97 hb_reference_table_func_t reference_table_func; | |
98 void *user_data; | |
99 hb_destroy_func_t destroy; | |
100 | |
101 unsigned int index; | |
102 mutable unsigned int upem; | |
103 mutable unsigned int num_glyphs; | |
104 | |
105 struct hb_shaper_data_t shaper_data; | |
106 | |
107 struct plan_node_t { | |
108 hb_shape_plan_t *shape_plan; | |
109 plan_node_t *next; | |
110 } *shape_plans; | |
111 | |
112 | |
113 inline hb_blob_t *reference_table (hb_tag_t tag) const | |
114 { | |
115 hb_blob_t *blob; | |
116 | |
117 if (unlikely (!this || !reference_table_func)) | |
118 return hb_blob_get_empty (); | |
119 | |
120 blob = reference_table_func (/*XXX*/const_cast<hb_face_t *> (this), tag, use
r_data); | |
121 if (unlikely (!blob)) | |
122 return hb_blob_get_empty (); | |
123 | |
124 return blob; | |
125 } | |
126 | |
127 inline unsigned int get_upem (void) const | |
128 { | |
129 if (unlikely (!upem)) | |
130 load_upem (); | |
131 return upem; | |
132 } | |
133 | |
134 inline unsigned int get_num_glyphs (void) const | |
135 { | |
136 if (unlikely (num_glyphs == (unsigned int) -1)) | |
137 load_num_glyphs (); | |
138 return num_glyphs; | |
139 } | |
140 | |
141 private: | |
142 HB_INTERNAL void load_upem (void) const; | |
143 HB_INTERNAL void load_num_glyphs (void) const; | |
144 }; | |
145 | |
146 #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS | |
147 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, face); | |
148 #include "hb-shaper-list.hh" | |
149 #undef HB_SHAPER_IMPLEMENT | |
150 #undef HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS | |
151 | |
152 | 87 |
153 /* | 88 /* |
154 * hb_font_t | 89 * hb_font_t |
155 */ | 90 */ |
156 | 91 |
157 struct hb_font_t { | 92 struct hb_font_t { |
158 hb_object_header_t header; | 93 hb_object_header_t header; |
159 ASSERT_POD (); | 94 ASSERT_POD (); |
160 | 95 |
161 hb_bool_t immutable; | 96 hb_bool_t immutable; |
(...skipping 14 matching lines...) Expand all Loading... |
176 struct hb_shaper_data_t shaper_data; | 111 struct hb_shaper_data_t shaper_data; |
177 | 112 |
178 | 113 |
179 /* Convert from font-space to user-space */ | 114 /* Convert from font-space to user-space */ |
180 inline hb_position_t em_scale_x (int16_t v) { return em_scale (v, this->x_scal
e); } | 115 inline hb_position_t em_scale_x (int16_t v) { return em_scale (v, this->x_scal
e); } |
181 inline hb_position_t em_scale_y (int16_t v) { return em_scale (v, this->y_scal
e); } | 116 inline hb_position_t em_scale_y (int16_t v) { return em_scale (v, this->y_scal
e); } |
182 | 117 |
183 /* Convert from parent-font user-space to our user-space */ | 118 /* Convert from parent-font user-space to our user-space */ |
184 inline hb_position_t parent_scale_x_distance (hb_position_t v) { | 119 inline hb_position_t parent_scale_x_distance (hb_position_t v) { |
185 if (unlikely (parent && parent->x_scale != x_scale)) | 120 if (unlikely (parent && parent->x_scale != x_scale)) |
186 return v * (int64_t) this->x_scale / this->parent->x_scale; | 121 return (hb_position_t) (v * (int64_t) this->x_scale / this->parent->x_scal
e); |
187 return v; | 122 return v; |
188 } | 123 } |
189 inline hb_position_t parent_scale_y_distance (hb_position_t v) { | 124 inline hb_position_t parent_scale_y_distance (hb_position_t v) { |
190 if (unlikely (parent && parent->y_scale != y_scale)) | 125 if (unlikely (parent && parent->y_scale != y_scale)) |
191 return v * (int64_t) this->y_scale / this->parent->y_scale; | 126 return (hb_position_t) (v * (int64_t) this->y_scale / this->parent->y_scal
e); |
192 return v; | 127 return v; |
193 } | 128 } |
194 inline hb_position_t parent_scale_x_position (hb_position_t v) { | 129 inline hb_position_t parent_scale_x_position (hb_position_t v) { |
195 return parent_scale_x_distance (v); | 130 return parent_scale_x_distance (v); |
196 } | 131 } |
197 inline hb_position_t parent_scale_y_position (hb_position_t v) { | 132 inline hb_position_t parent_scale_y_position (hb_position_t v) { |
198 return parent_scale_y_distance (v); | 133 return parent_scale_y_distance (v); |
199 } | 134 } |
200 | 135 |
201 inline void parent_scale_distance (hb_position_t *x, hb_position_t *y) { | 136 inline void parent_scale_distance (hb_position_t *x, hb_position_t *y) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 klass->user_data.glyph_v_origin); | 186 klass->user_data.glyph_v_origin); |
252 } | 187 } |
253 | 188 |
254 inline hb_position_t get_glyph_h_kerning (hb_codepoint_t left_glyph, hb_codepo
int_t right_glyph) | 189 inline hb_position_t get_glyph_h_kerning (hb_codepoint_t left_glyph, hb_codepo
int_t right_glyph) |
255 { | 190 { |
256 return klass->get.glyph_h_kerning (this, user_data, | 191 return klass->get.glyph_h_kerning (this, user_data, |
257 left_glyph, right_glyph, | 192 left_glyph, right_glyph, |
258 klass->user_data.glyph_h_kerning); | 193 klass->user_data.glyph_h_kerning); |
259 } | 194 } |
260 | 195 |
261 inline hb_position_t get_glyph_v_kerning (hb_codepoint_t left_glyph, hb_codepo
int_t right_glyph) | 196 inline hb_position_t get_glyph_v_kerning (hb_codepoint_t top_glyph, hb_codepoi
nt_t bottom_glyph) |
262 { | 197 { |
263 return klass->get.glyph_v_kerning (this, user_data, | 198 return klass->get.glyph_v_kerning (this, user_data, |
264 » » » » left_glyph, right_glyph, | 199 » » » » top_glyph, bottom_glyph, |
265 klass->user_data.glyph_v_kerning); | 200 klass->user_data.glyph_v_kerning); |
266 } | 201 } |
267 | 202 |
268 inline hb_bool_t get_glyph_extents (hb_codepoint_t glyph, | 203 inline hb_bool_t get_glyph_extents (hb_codepoint_t glyph, |
269 hb_glyph_extents_t *extents) | 204 hb_glyph_extents_t *extents) |
270 { | 205 { |
271 memset (extents, 0, sizeof (*extents)); | 206 memset (extents, 0, sizeof (*extents)); |
272 return klass->get.glyph_extents (this, user_data, | 207 return klass->get.glyph_extents (this, user_data, |
273 glyph, | 208 glyph, |
274 extents, | 209 extents, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 *x = get_glyph_h_advance (glyph) / 2; | 264 *x = get_glyph_h_advance (glyph) / 2; |
330 | 265 |
331 /* TODO use font_metics.ascent */ | 266 /* TODO use font_metics.ascent */ |
332 *y = y_scale; | 267 *y = y_scale; |
333 } | 268 } |
334 | 269 |
335 inline void get_glyph_origin_for_direction (hb_codepoint_t glyph, | 270 inline void get_glyph_origin_for_direction (hb_codepoint_t glyph, |
336 hb_direction_t direction, | 271 hb_direction_t direction, |
337 hb_position_t *x, hb_position_t *y
) | 272 hb_position_t *x, hb_position_t *y
) |
338 { | 273 { |
339 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { | 274 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) |
340 hb_bool_t ret = get_glyph_h_origin (glyph, x, y); | 275 { |
341 if (!ret && (ret = get_glyph_v_origin (glyph, x, y))) { | 276 if (!get_glyph_h_origin (glyph, x, y) && |
| 277 » get_glyph_v_origin (glyph, x, y)) |
| 278 { |
342 hb_position_t dx, dy; | 279 hb_position_t dx, dy; |
343 guess_v_origin_minus_h_origin (glyph, &dx, &dy); | 280 guess_v_origin_minus_h_origin (glyph, &dx, &dy); |
344 *x -= dx; *y -= dy; | 281 *x -= dx; *y -= dy; |
345 } | 282 } |
346 } else { | 283 } |
347 hb_bool_t ret = get_glyph_v_origin (glyph, x, y); | 284 else |
348 if (!ret && (ret = get_glyph_h_origin (glyph, x, y))) { | 285 { |
| 286 if (!get_glyph_v_origin (glyph, x, y) && |
| 287 » get_glyph_h_origin (glyph, x, y)) |
| 288 { |
349 hb_position_t dx, dy; | 289 hb_position_t dx, dy; |
350 guess_v_origin_minus_h_origin (glyph, &dx, &dy); | 290 guess_v_origin_minus_h_origin (glyph, &dx, &dy); |
351 *x += dx; *y += dy; | 291 *x += dx; *y += dy; |
352 } | 292 } |
353 } | 293 } |
354 } | 294 } |
355 | 295 |
356 inline void add_glyph_origin_for_direction (hb_codepoint_t glyph, | 296 inline void add_glyph_origin_for_direction (hb_codepoint_t glyph, |
357 hb_direction_t direction, | 297 hb_direction_t direction, |
358 hb_position_t *x, hb_position_t *y
) | 298 hb_position_t *x, hb_position_t *y
) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 return ret; | 354 return ret; |
415 } | 355 } |
416 | 356 |
417 /* Generates gidDDD if glyph has no name. */ | 357 /* Generates gidDDD if glyph has no name. */ |
418 inline void | 358 inline void |
419 glyph_to_string (hb_codepoint_t glyph, | 359 glyph_to_string (hb_codepoint_t glyph, |
420 char *s, unsigned int size) | 360 char *s, unsigned int size) |
421 { | 361 { |
422 if (get_glyph_name (glyph, s, size)) return; | 362 if (get_glyph_name (glyph, s, size)) return; |
423 | 363 |
424 snprintf (s, size, "gid%u", glyph); | 364 if (size && snprintf (s, size, "gid%u", glyph) < 0) |
| 365 *s = '\0'; |
425 } | 366 } |
426 | 367 |
427 /* Parses gidDDD and uniUUUU strings automatically. */ | 368 /* Parses gidDDD and uniUUUU strings automatically. */ |
428 inline hb_bool_t | 369 inline hb_bool_t |
429 glyph_from_string (const char *s, int len, /* -1 means nul-terminated */ | 370 glyph_from_string (const char *s, int len, /* -1 means nul-terminated */ |
430 hb_codepoint_t *glyph) | 371 hb_codepoint_t *glyph) |
431 { | 372 { |
432 if (get_glyph_from_name (s, len, glyph)) return true; | 373 if (get_glyph_from_name (s, len, glyph)) return true; |
433 | 374 |
434 if (len == -1) len = strlen (s); | 375 if (len == -1) len = strlen (s); |
(...skipping 14 matching lines...) Expand all Loading... |
449 if (0 == strncmp (s, "uni", 3) && | 390 if (0 == strncmp (s, "uni", 3) && |
450 hb_codepoint_parse (s + 3, len - 3, 16, &unichar) && | 391 hb_codepoint_parse (s + 3, len - 3, 16, &unichar) && |
451 get_glyph (unichar, 0, glyph)) | 392 get_glyph (unichar, 0, glyph)) |
452 return true; | 393 return true; |
453 } | 394 } |
454 | 395 |
455 return false; | 396 return false; |
456 } | 397 } |
457 | 398 |
458 private: | 399 private: |
459 inline hb_position_t em_scale (int16_t v, int scale) { return v * (int64_t) sc
ale / hb_face_get_upem (this->face); } | 400 inline hb_position_t em_scale (int16_t v, int scale) { return (hb_position_t)
(v * (int64_t) scale / face->get_upem ()); } |
460 }; | 401 }; |
461 | 402 |
462 #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS | 403 #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS |
463 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font); | 404 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font); |
464 #include "hb-shaper-list.hh" | 405 #include "hb-shaper-list.hh" |
465 #undef HB_SHAPER_IMPLEMENT | 406 #undef HB_SHAPER_IMPLEMENT |
466 #undef HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS | 407 #undef HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS |
467 | 408 |
468 | 409 |
469 #endif /* HB_FONT_PRIVATE_HH */ | 410 #endif /* HB_FONT_PRIVATE_HH */ |
OLD | NEW |