| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 HB_FONT_FUNC_IMPLEMENT (glyph_name) \ | 54 HB_FONT_FUNC_IMPLEMENT (glyph_name) \ |
| 55 HB_FONT_FUNC_IMPLEMENT (glyph_from_name) \ | 55 HB_FONT_FUNC_IMPLEMENT (glyph_from_name) \ |
| 56 /* ^--- Add new callbacks here */ | 56 /* ^--- Add new callbacks here */ |
| 57 | 57 |
| 58 struct hb_font_funcs_t { | 58 struct hb_font_funcs_t { |
| 59 hb_object_header_t header; | 59 hb_object_header_t header; |
| 60 ASSERT_POD (); | 60 ASSERT_POD (); |
| 61 | 61 |
| 62 hb_bool_t immutable; | 62 hb_bool_t immutable; |
| 63 | 63 |
| 64 /* Don't access these directly. Call hb_font_get_*() instead. */ | |
| 65 | |
| 66 struct { | |
| 67 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_func_t name; | |
| 68 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS | |
| 69 #undef HB_FONT_FUNC_IMPLEMENT | |
| 70 } get; | |
| 71 | |
| 72 struct { | 64 struct { |
| 73 #define HB_FONT_FUNC_IMPLEMENT(name) void *name; | 65 #define HB_FONT_FUNC_IMPLEMENT(name) void *name; |
| 74 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS | 66 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
| 75 #undef HB_FONT_FUNC_IMPLEMENT | 67 #undef HB_FONT_FUNC_IMPLEMENT |
| 76 } user_data; | 68 } user_data; |
| 77 | 69 |
| 78 struct { | 70 struct { |
| 79 #define HB_FONT_FUNC_IMPLEMENT(name) hb_destroy_func_t name; | 71 #define HB_FONT_FUNC_IMPLEMENT(name) hb_destroy_func_t name; |
| 80 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS | 72 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
| 81 #undef HB_FONT_FUNC_IMPLEMENT | 73 #undef HB_FONT_FUNC_IMPLEMENT |
| 82 } destroy; | 74 } destroy; |
| 75 |
| 76 /* Don't access these directly. Call font->get_*() instead. */ |
| 77 union get_t { |
| 78 struct get_funcs_t { |
| 79 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_func_t name; |
| 80 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
| 81 #undef HB_FONT_FUNC_IMPLEMENT |
| 82 } f; |
| 83 void (*array[]) (void); |
| 84 } get; |
| 83 }; | 85 }; |
| 84 | 86 |
| 85 | 87 |
| 86 | 88 |
| 87 /* | 89 /* |
| 88 * hb_font_t | 90 * hb_font_t |
| 89 */ | 91 */ |
| 90 | 92 |
| 91 struct hb_font_t { | 93 struct hb_font_t { |
| 92 hb_object_header_t header; | 94 hb_object_header_t header; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 *y = parent_scale_y_distance (*y); | 139 *y = parent_scale_y_distance (*y); |
| 138 } | 140 } |
| 139 inline void parent_scale_position (hb_position_t *x, hb_position_t *y) { | 141 inline void parent_scale_position (hb_position_t *x, hb_position_t *y) { |
| 140 *x = parent_scale_x_position (*x); | 142 *x = parent_scale_x_position (*x); |
| 141 *y = parent_scale_y_position (*y); | 143 *y = parent_scale_y_position (*y); |
| 142 } | 144 } |
| 143 | 145 |
| 144 | 146 |
| 145 /* Public getters */ | 147 /* Public getters */ |
| 146 | 148 |
| 149 HB_INTERNAL bool has_func (unsigned int i); |
| 150 |
| 151 /* has_* ... */ |
| 152 #define HB_FONT_FUNC_IMPLEMENT(name) \ |
| 153 bool \ |
| 154 has_##name##_func (void) \ |
| 155 { \ |
| 156 hb_font_funcs_t *funcs = this->klass; \ |
| 157 unsigned int i = offsetof (hb_font_funcs_t::get_t::get_funcs_t, name) / size
of (funcs->get.array[0]); \ |
| 158 return has_func (i); \ |
| 159 } |
| 160 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
| 161 #undef HB_FONT_FUNC_IMPLEMENT |
| 162 |
| 147 inline hb_bool_t has_glyph (hb_codepoint_t unicode) | 163 inline hb_bool_t has_glyph (hb_codepoint_t unicode) |
| 148 { | 164 { |
| 149 hb_codepoint_t glyph; | 165 hb_codepoint_t glyph; |
| 150 return get_glyph (unicode, 0, &glyph); | 166 return get_glyph (unicode, 0, &glyph); |
| 151 } | 167 } |
| 152 | 168 |
| 153 inline hb_bool_t get_glyph (hb_codepoint_t unicode, hb_codepoint_t variation_s
elector, | 169 inline hb_bool_t get_glyph (hb_codepoint_t unicode, hb_codepoint_t variation_s
elector, |
| 154 hb_codepoint_t *glyph) | 170 hb_codepoint_t *glyph) |
| 155 { | 171 { |
| 156 *glyph = 0; | 172 *glyph = 0; |
| 157 return klass->get.glyph (this, user_data, | 173 return klass->get.f.glyph (this, user_data, |
| 158 » » » unicode, variation_selector, glyph, | 174 » » » unicode, variation_selector, glyph, |
| 159 » » » klass->user_data.glyph); | 175 » » » klass->user_data.glyph); |
| 160 } | 176 } |
| 161 | 177 |
| 162 inline hb_position_t get_glyph_h_advance (hb_codepoint_t glyph) | 178 inline hb_position_t get_glyph_h_advance (hb_codepoint_t glyph) |
| 163 { | 179 { |
| 164 return klass->get.glyph_h_advance (this, user_data, | 180 return klass->get.f.glyph_h_advance (this, user_data, |
| 165 » » » » glyph, | 181 » » » » » glyph, |
| 166 » » » » klass->user_data.glyph_h_advance); | 182 » » » » » klass->user_data.glyph_h_advance); |
| 167 } | 183 } |
| 168 | 184 |
| 169 inline hb_position_t get_glyph_v_advance (hb_codepoint_t glyph) | 185 inline hb_position_t get_glyph_v_advance (hb_codepoint_t glyph) |
| 170 { | 186 { |
| 171 return klass->get.glyph_v_advance (this, user_data, | 187 return klass->get.f.glyph_v_advance (this, user_data, |
| 172 » » » » glyph, | 188 » » » » » glyph, |
| 173 » » » » klass->user_data.glyph_v_advance); | 189 » » » » » klass->user_data.glyph_v_advance); |
| 174 } | 190 } |
| 175 | 191 |
| 176 inline hb_bool_t get_glyph_h_origin (hb_codepoint_t glyph, | 192 inline hb_bool_t get_glyph_h_origin (hb_codepoint_t glyph, |
| 177 hb_position_t *x, hb_position_t *y) | 193 hb_position_t *x, hb_position_t *y) |
| 178 { | 194 { |
| 179 *x = *y = 0; | 195 *x = *y = 0; |
| 180 return klass->get.glyph_h_origin (this, user_data, | 196 return klass->get.f.glyph_h_origin (this, user_data, |
| 181 » » » » glyph, x, y, | 197 » » » » » glyph, x, y, |
| 182 » » » » klass->user_data.glyph_h_origin); | 198 » » » » » klass->user_data.glyph_h_origin); |
| 183 } | 199 } |
| 184 | 200 |
| 185 inline hb_bool_t get_glyph_v_origin (hb_codepoint_t glyph, | 201 inline hb_bool_t get_glyph_v_origin (hb_codepoint_t glyph, |
| 186 hb_position_t *x, hb_position_t *y) | 202 hb_position_t *x, hb_position_t *y) |
| 187 { | 203 { |
| 188 *x = *y = 0; | 204 *x = *y = 0; |
| 189 return klass->get.glyph_v_origin (this, user_data, | 205 return klass->get.f.glyph_v_origin (this, user_data, |
| 190 » » » » glyph, x, y, | 206 » » » » » glyph, x, y, |
| 191 » » » » klass->user_data.glyph_v_origin); | 207 » » » » » klass->user_data.glyph_v_origin); |
| 192 } | 208 } |
| 193 | 209 |
| 194 inline hb_position_t get_glyph_h_kerning (hb_codepoint_t left_glyph, hb_codepo
int_t right_glyph) | 210 inline hb_position_t get_glyph_h_kerning (hb_codepoint_t left_glyph, hb_codepo
int_t right_glyph) |
| 195 { | 211 { |
| 196 return klass->get.glyph_h_kerning (this, user_data, | 212 return klass->get.f.glyph_h_kerning (this, user_data, |
| 197 » » » » left_glyph, right_glyph, | 213 » » » » » left_glyph, right_glyph, |
| 198 » » » » klass->user_data.glyph_h_kerning); | 214 » » » » » klass->user_data.glyph_h_kerning); |
| 199 } | 215 } |
| 200 | 216 |
| 201 inline hb_position_t get_glyph_v_kerning (hb_codepoint_t top_glyph, hb_codepoi
nt_t bottom_glyph) | 217 inline hb_position_t get_glyph_v_kerning (hb_codepoint_t top_glyph, hb_codepoi
nt_t bottom_glyph) |
| 202 { | 218 { |
| 203 return klass->get.glyph_v_kerning (this, user_data, | 219 return klass->get.f.glyph_v_kerning (this, user_data, |
| 204 » » » » top_glyph, bottom_glyph, | 220 » » » » » top_glyph, bottom_glyph, |
| 205 » » » » klass->user_data.glyph_v_kerning); | 221 » » » » » klass->user_data.glyph_v_kerning); |
| 206 } | 222 } |
| 207 | 223 |
| 208 inline hb_bool_t get_glyph_extents (hb_codepoint_t glyph, | 224 inline hb_bool_t get_glyph_extents (hb_codepoint_t glyph, |
| 209 hb_glyph_extents_t *extents) | 225 hb_glyph_extents_t *extents) |
| 210 { | 226 { |
| 211 memset (extents, 0, sizeof (*extents)); | 227 memset (extents, 0, sizeof (*extents)); |
| 212 return klass->get.glyph_extents (this, user_data, | 228 return klass->get.f.glyph_extents (this, user_data, |
| 213 » » » » glyph, | 229 » » » » glyph, |
| 214 » » » » extents, | 230 » » » » extents, |
| 215 » » » » klass->user_data.glyph_extents); | 231 » » » » klass->user_data.glyph_extents); |
| 216 } | 232 } |
| 217 | 233 |
| 218 inline hb_bool_t get_glyph_contour_point (hb_codepoint_t glyph, unsigned int p
oint_index, | 234 inline hb_bool_t get_glyph_contour_point (hb_codepoint_t glyph, unsigned int p
oint_index, |
| 219 hb_position_t *x, hb_position_t *y) | 235 hb_position_t *x, hb_position_t *y) |
| 220 { | 236 { |
| 221 *x = *y = 0; | 237 *x = *y = 0; |
| 222 return klass->get.glyph_contour_point (this, user_data, | 238 return klass->get.f.glyph_contour_point (this, user_data, |
| 223 » » » » » glyph, point_index, | 239 » » » » » glyph, point_index, |
| 224 » » » » » x, y, | 240 » » » » » x, y, |
| 225 » » » » » klass->user_data.glyph_contour_point)
; | 241 » » » » » klass->user_data.glyph_contour_poin
t); |
| 226 } | 242 } |
| 227 | 243 |
| 228 inline hb_bool_t get_glyph_name (hb_codepoint_t glyph, | 244 inline hb_bool_t get_glyph_name (hb_codepoint_t glyph, |
| 229 char *name, unsigned int size) | 245 char *name, unsigned int size) |
| 230 { | 246 { |
| 231 if (size) *name = '\0'; | 247 if (size) *name = '\0'; |
| 232 return klass->get.glyph_name (this, user_data, | 248 return klass->get.f.glyph_name (this, user_data, |
| 233 » » » » glyph, | 249 » » » » glyph, |
| 234 » » » » name, size, | 250 » » » » name, size, |
| 235 » » » » klass->user_data.glyph_name); | 251 » » » » klass->user_data.glyph_name); |
| 236 } | 252 } |
| 237 | 253 |
| 238 inline hb_bool_t get_glyph_from_name (const char *name, int len, /* -1 means n
ul-terminated */ | 254 inline hb_bool_t get_glyph_from_name (const char *name, int len, /* -1 means n
ul-terminated */ |
| 239 hb_codepoint_t *glyph) | 255 hb_codepoint_t *glyph) |
| 240 { | 256 { |
| 241 *glyph = 0; | 257 *glyph = 0; |
| 242 if (len == -1) len = strlen (name); | 258 if (len == -1) len = strlen (name); |
| 243 return klass->get.glyph_from_name (this, user_data, | 259 return klass->get.f.glyph_from_name (this, user_data, |
| 244 » » » » name, len, | 260 » » » » » name, len, |
| 245 » » » » glyph, | 261 » » » » » glyph, |
| 246 » » » » klass->user_data.glyph_from_name); | 262 » » » » » klass->user_data.glyph_from_name); |
| 247 } | 263 } |
| 248 | 264 |
| 249 | 265 |
| 250 /* A bit higher-level, and with fallback */ | 266 /* A bit higher-level, and with fallback */ |
| 251 | 267 |
| 252 inline void get_glyph_advance_for_direction (hb_codepoint_t glyph, | 268 inline void get_glyph_advance_for_direction (hb_codepoint_t glyph, |
| 253 hb_direction_t direction, | 269 hb_direction_t direction, |
| 254 hb_position_t *x, hb_position_t *
y) | 270 hb_position_t *x, hb_position_t *
y) |
| 255 { | 271 { |
| 256 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { | 272 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 if (!get_glyph_v_origin (glyph, x, y) && | 307 if (!get_glyph_v_origin (glyph, x, y) && |
| 292 get_glyph_h_origin (glyph, x, y)) | 308 get_glyph_h_origin (glyph, x, y)) |
| 293 { | 309 { |
| 294 hb_position_t dx, dy; | 310 hb_position_t dx, dy; |
| 295 guess_v_origin_minus_h_origin (glyph, &dx, &dy); | 311 guess_v_origin_minus_h_origin (glyph, &dx, &dy); |
| 296 *x += dx; *y += dy; | 312 *x += dx; *y += dy; |
| 297 } | 313 } |
| 298 } | 314 } |
| 299 } | 315 } |
| 300 | 316 |
| 317 inline void add_glyph_h_origin (hb_codepoint_t glyph, |
| 318 hb_position_t *x, hb_position_t *y) |
| 319 { |
| 320 hb_position_t origin_x, origin_y; |
| 321 |
| 322 get_glyph_h_origin (glyph, &origin_x, &origin_y); |
| 323 |
| 324 *x += origin_x; |
| 325 *y += origin_y; |
| 326 } |
| 327 inline void add_glyph_v_origin (hb_codepoint_t glyph, |
| 328 hb_position_t *x, hb_position_t *y) |
| 329 { |
| 330 hb_position_t origin_x, origin_y; |
| 331 |
| 332 get_glyph_v_origin (glyph, &origin_x, &origin_y); |
| 333 |
| 334 *x += origin_x; |
| 335 *y += origin_y; |
| 336 } |
| 301 inline void add_glyph_origin_for_direction (hb_codepoint_t glyph, | 337 inline void add_glyph_origin_for_direction (hb_codepoint_t glyph, |
| 302 hb_direction_t direction, | 338 hb_direction_t direction, |
| 303 hb_position_t *x, hb_position_t *y
) | 339 hb_position_t *x, hb_position_t *y
) |
| 304 { | 340 { |
| 305 hb_position_t origin_x, origin_y; | 341 hb_position_t origin_x, origin_y; |
| 306 | 342 |
| 307 get_glyph_origin_for_direction (glyph, direction, &origin_x, &origin_y); | 343 get_glyph_origin_for_direction (glyph, direction, &origin_x, &origin_y); |
| 308 | 344 |
| 309 *x += origin_x; | 345 *x += origin_x; |
| 310 *y += origin_y; | 346 *y += origin_y; |
| 311 } | 347 } |
| 312 | 348 |
| 349 inline void subtract_glyph_h_origin (hb_codepoint_t glyph, |
| 350 hb_position_t *x, hb_position_t *y) |
| 351 { |
| 352 hb_position_t origin_x, origin_y; |
| 353 |
| 354 get_glyph_h_origin (glyph, &origin_x, &origin_y); |
| 355 |
| 356 *x -= origin_x; |
| 357 *y -= origin_y; |
| 358 } |
| 359 inline void subtract_glyph_v_origin (hb_codepoint_t glyph, |
| 360 hb_position_t *x, hb_position_t *y) |
| 361 { |
| 362 hb_position_t origin_x, origin_y; |
| 363 |
| 364 get_glyph_v_origin (glyph, &origin_x, &origin_y); |
| 365 |
| 366 *x -= origin_x; |
| 367 *y -= origin_y; |
| 368 } |
| 313 inline void subtract_glyph_origin_for_direction (hb_codepoint_t glyph, | 369 inline void subtract_glyph_origin_for_direction (hb_codepoint_t glyph, |
| 314 hb_direction_t direction, | 370 hb_direction_t direction, |
| 315 hb_position_t *x, hb_position
_t *y) | 371 hb_position_t *x, hb_position
_t *y) |
| 316 { | 372 { |
| 317 hb_position_t origin_x, origin_y; | 373 hb_position_t origin_x, origin_y; |
| 318 | 374 |
| 319 get_glyph_origin_for_direction (glyph, direction, &origin_x, &origin_y); | 375 get_glyph_origin_for_direction (glyph, direction, &origin_x, &origin_y); |
| 320 | 376 |
| 321 *x -= origin_x; | 377 *x -= origin_x; |
| 322 *y -= origin_y; | 378 *y -= origin_y; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 }; | 462 }; |
| 407 | 463 |
| 408 #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS | 464 #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS |
| 409 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font); | 465 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font); |
| 410 #include "hb-shaper-list.hh" | 466 #include "hb-shaper-list.hh" |
| 411 #undef HB_SHAPER_IMPLEMENT | 467 #undef HB_SHAPER_IMPLEMENT |
| 412 #undef HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS | 468 #undef HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS |
| 413 | 469 |
| 414 | 470 |
| 415 #endif /* HB_FONT_PRIVATE_HH */ | 471 #endif /* HB_FONT_PRIVATE_HH */ |
| OLD | NEW |