1 /* 2 * Copyright © 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_H_IN 28 #error "Include <hb.h> instead." 29 #endif 30 31 #ifndef HB_FONT_H 32 #define HB_FONT_H 33 34 #include "hb-common.h" 35 #include "hb-face.h" 36 37 HB_BEGIN_DECLS 38 39 40 typedef struct hb_font_t hb_font_t; 41 42 43 /* 44 * hb_font_funcs_t 45 */ 46 47 typedef struct hb_font_funcs_t hb_font_funcs_t; 48 49 HB_EXTERN hb_font_funcs_t * 50 hb_font_funcs_create (void); 51 52 HB_EXTERN hb_font_funcs_t * 53 hb_font_funcs_get_empty (void); 54 55 HB_EXTERN hb_font_funcs_t * 56 hb_font_funcs_reference (hb_font_funcs_t *ffuncs); 57 58 HB_EXTERN void 59 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs); 60 61 HB_EXTERN hb_bool_t 62 hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs, 63 hb_user_data_key_t *key, 64 void * data, 65 hb_destroy_func_t destroy, 66 hb_bool_t replace); 67 68 69 HB_EXTERN void * 70 hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs, 71 hb_user_data_key_t *key); 72 73 74 HB_EXTERN void 75 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs); 76 77 HB_EXTERN hb_bool_t 78 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs); 79 80 81 /* font and glyph extents */ 82 83 /* Note that typically ascender is positive and descender negative in coordinate systems that grow up. */ 84 typedef struct hb_font_extents_t 85 { 86 hb_position_t ascender; /* typographic ascender. */ 87 hb_position_t descender; /* typographic descender. */ 88 hb_position_t line_gap; /* suggested line spacing gap. */ 89 /*< private >*/ 90 hb_position_t reserved9; 91 hb_position_t reserved8; 92 hb_position_t reserved7; 93 hb_position_t reserved6; 94 hb_position_t reserved5; 95 hb_position_t reserved4; 96 hb_position_t reserved3; 97 hb_position_t reserved2; 98 hb_position_t reserved1; 99 } hb_font_extents_t; 100 101 /* Note that height is negative in coordinate systems that grow up. */ 102 typedef struct hb_glyph_extents_t 103 { 104 hb_position_t x_bearing; /* left side of glyph from origin. */ 105 hb_position_t y_bearing; /* top side of glyph from origin. */ 106 hb_position_t width; /* distance from left to right side. */ 107 hb_position_t height; /* distance from top to bottom side. */ 108 } hb_glyph_extents_t; 109 110 /* func types */ 111 112 typedef hb_bool_t (*hb_font_get_font_extents_func_t) (hb_font_t *font, void *font_data, 113 hb_font_extents_t *metrics, 114 void *user_data); 115 typedef hb_font_get_font_extents_func_t hb_font_get_font_h_extents_func_t; 116 typedef hb_font_get_font_extents_func_t hb_font_get_font_v_extents_func_t; 117 118 119 typedef hb_bool_t (*hb_font_get_nominal_glyph_func_t) (hb_font_t *font, void *font_data, 120 hb_codepoint_t unicode, 121 hb_codepoint_t *glyph, 122 void *user_data); 123 typedef hb_bool_t (*hb_font_get_variation_glyph_func_t) (hb_font_t *font, void *font_data, 124 hb_codepoint_t unicode, hb_codepoint_t variation_selector, 125 hb_codepoint_t *glyph, 126 void *user_data); 127 128 129 typedef hb_position_t (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void *font_data, 130 hb_codepoint_t glyph, 131 void *user_data); 132 typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_h_advance_func_t; 133 typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_v_advance_func_t; 134 135 typedef hb_bool_t (*hb_font_get_glyph_origin_func_t) (hb_font_t *font, void *font_data, 136 hb_codepoint_t glyph, 137 hb_position_t *x, hb_position_t *y, 138 void *user_data); 139 typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_h_origin_func_t; 140 typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_v_origin_func_t; 141 142 typedef hb_position_t (*hb_font_get_glyph_kerning_func_t) (hb_font_t *font, void *font_data, 143 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, 144 void *user_data); 145 typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_h_kerning_func_t; 146 typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_v_kerning_func_t; 147 148 149 typedef hb_bool_t (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, void *font_data, 150 hb_codepoint_t glyph, 151 hb_glyph_extents_t *extents, 152 void *user_data); 153 typedef hb_bool_t (*hb_font_get_glyph_contour_point_func_t) (hb_font_t *font, void *font_data, 154 hb_codepoint_t glyph, unsigned int point_index, 155 hb_position_t *x, hb_position_t *y, 156 void *user_data); 157 158 159 typedef hb_bool_t (*hb_font_get_glyph_name_func_t) (hb_font_t *font, void *font_data, 160 hb_codepoint_t glyph, 161 char *name, unsigned int size, 162 void *user_data); 163 typedef hb_bool_t (*hb_font_get_glyph_from_name_func_t) (hb_font_t *font, void *font_data, 164 const char *name, int len, /* -1 means nul-terminated */ 165 hb_codepoint_t *glyph, 166 void *user_data); 167 168 169 /* func setters */ 170 171 /** 172 * hb_font_funcs_set_font_h_extents_func: 173 * @ffuncs: font functions. 174 * @func: (closure user_data) (destroy destroy) (scope notified): 175 * @user_data: 176 * @destroy: 177 * 178 * 179 * 180 * Since: 1.1.2 181 **/ 182 HB_EXTERN void 183 hb_font_funcs_set_font_h_extents_func (hb_font_funcs_t *ffuncs, 184 hb_font_get_font_h_extents_func_t func, 185 void *user_data, hb_destroy_func_t destroy); 186 187 /** 188 * hb_font_funcs_set_font_v_extents_func: 189 * @ffuncs: font functions. 190 * @func: (closure user_data) (destroy destroy) (scope notified): 191 * @user_data: 192 * @destroy: 193 * 194 * 195 * 196 * Since: 1.1.2 197 **/ 198 HB_EXTERN void 199 hb_font_funcs_set_font_v_extents_func (hb_font_funcs_t *ffuncs, 200 hb_font_get_font_v_extents_func_t func, 201 void *user_data, hb_destroy_func_t destroy); 202 203 /** 204 * hb_font_funcs_set_nominal_glyph_func: 205 * @ffuncs: font functions. 206 * @func: (closure user_data) (destroy destroy) (scope notified): 207 * @user_data: 208 * @destroy: 209 * 210 * 211 * 212 * Since: 1.2.3 213 **/ 214 HB_EXTERN void 215 hb_font_funcs_set_nominal_glyph_func (hb_font_funcs_t *ffuncs, 216 hb_font_get_nominal_glyph_func_t func, 217 void *user_data, hb_destroy_func_t destroy); 218 219 /** 220 * hb_font_funcs_set_variation_glyph_func: 221 * @ffuncs: font functions. 222 * @func: (closure user_data) (destroy destroy) (scope notified): 223 * @user_data: 224 * @destroy: 225 * 226 * 227 * 228 * Since: 1.2.3 229 **/ 230 HB_EXTERN void 231 hb_font_funcs_set_variation_glyph_func (hb_font_funcs_t *ffuncs, 232 hb_font_get_variation_glyph_func_t func, 233 void *user_data, hb_destroy_func_t destroy); 234 235 /** 236 * hb_font_funcs_set_glyph_h_advance_func: 237 * @ffuncs: font functions. 238 * @func: (closure user_data) (destroy destroy) (scope notified): 239 * @user_data: 240 * @destroy: 241 * 242 * 243 * 244 * Since: 0.9.2 245 **/ 246 HB_EXTERN void 247 hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs, 248 hb_font_get_glyph_h_advance_func_t func, 249 void *user_data, hb_destroy_func_t destroy); 250 251 /** 252 * hb_font_funcs_set_glyph_v_advance_func: 253 * @ffuncs: font functions. 254 * @func: (closure user_data) (destroy destroy) (scope notified): 255 * @user_data: 256 * @destroy: 257 * 258 * 259 * 260 * Since: 0.9.2 261 **/ 262 HB_EXTERN void 263 hb_font_funcs_set_glyph_v_advance_func (hb_font_funcs_t *ffuncs, 264 hb_font_get_glyph_v_advance_func_t func, 265 void *user_data, hb_destroy_func_t destroy); 266 267 /** 268 * hb_font_funcs_set_glyph_h_origin_func: 269 * @ffuncs: font functions. 270 * @func: (closure user_data) (destroy destroy) (scope notified): 271 * @user_data: 272 * @destroy: 273 * 274 * 275 * 276 * Since: 0.9.2 277 **/ 278 HB_EXTERN void 279 hb_font_funcs_set_glyph_h_origin_func (hb_font_funcs_t *ffuncs, 280 hb_font_get_glyph_h_origin_func_t func, 281 void *user_data, hb_destroy_func_t destroy); 282 283 /** 284 * hb_font_funcs_set_glyph_v_origin_func: 285 * @ffuncs: font functions. 286 * @func: (closure user_data) (destroy destroy) (scope notified): 287 * @user_data: 288 * @destroy: 289 * 290 * 291 * 292 * Since: 0.9.2 293 **/ 294 HB_EXTERN void 295 hb_font_funcs_set_glyph_v_origin_func (hb_font_funcs_t *ffuncs, 296 hb_font_get_glyph_v_origin_func_t func, 297 void *user_data, hb_destroy_func_t destroy); 298 299 /** 300 * hb_font_funcs_set_glyph_h_kerning_func: 301 * @ffuncs: font functions. 302 * @func: (closure user_data) (destroy destroy) (scope notified): 303 * @user_data: 304 * @destroy: 305 * 306 * 307 * 308 * Since: 0.9.2 309 **/ 310 HB_EXTERN void 311 hb_font_funcs_set_glyph_h_kerning_func (hb_font_funcs_t *ffuncs, 312 hb_font_get_glyph_h_kerning_func_t func, 313 void *user_data, hb_destroy_func_t destroy); 314 315 /** 316 * hb_font_funcs_set_glyph_v_kerning_func: 317 * @ffuncs: font functions. 318 * @func: (closure user_data) (destroy destroy) (scope notified): 319 * @user_data: 320 * @destroy: 321 * 322 * 323 * 324 * Since: 0.9.2 325 **/ 326 HB_EXTERN void 327 hb_font_funcs_set_glyph_v_kerning_func (hb_font_funcs_t *ffuncs, 328 hb_font_get_glyph_v_kerning_func_t func, 329 void *user_data, hb_destroy_func_t destroy); 330 331 /** 332 * hb_font_funcs_set_glyph_extents_func: 333 * @ffuncs: font functions. 334 * @func: (closure user_data) (destroy destroy) (scope notified): 335 * @user_data: 336 * @destroy: 337 * 338 * 339 * 340 * Since: 0.9.2 341 **/ 342 HB_EXTERN void 343 hb_font_funcs_set_glyph_extents_func (hb_font_funcs_t *ffuncs, 344 hb_font_get_glyph_extents_func_t func, 345 void *user_data, hb_destroy_func_t destroy); 346 347 /** 348 * hb_font_funcs_set_glyph_contour_point_func: 349 * @ffuncs: font functions. 350 * @func: (closure user_data) (destroy destroy) (scope notified): 351 * @user_data: 352 * @destroy: 353 * 354 * 355 * 356 * Since: 0.9.2 357 **/ 358 HB_EXTERN void 359 hb_font_funcs_set_glyph_contour_point_func (hb_font_funcs_t *ffuncs, 360 hb_font_get_glyph_contour_point_func_t func, 361 void *user_data, hb_destroy_func_t destroy); 362 363 /** 364 * hb_font_funcs_set_glyph_name_func: 365 * @ffuncs: font functions. 366 * @func: (closure user_data) (destroy destroy) (scope notified): 367 * @user_data: 368 * @destroy: 369 * 370 * 371 * 372 * Since: 0.9.2 373 **/ 374 HB_EXTERN void 375 hb_font_funcs_set_glyph_name_func (hb_font_funcs_t *ffuncs, 376 hb_font_get_glyph_name_func_t func, 377 void *user_data, hb_destroy_func_t destroy); 378 379 /** 380 * hb_font_funcs_set_glyph_from_name_func: 381 * @ffuncs: font functions. 382 * @func: (closure user_data) (destroy destroy) (scope notified): 383 * @user_data: 384 * @destroy: 385 * 386 * 387 * 388 * Since: 0.9.2 389 **/ 390 HB_EXTERN void 391 hb_font_funcs_set_glyph_from_name_func (hb_font_funcs_t *ffuncs, 392 hb_font_get_glyph_from_name_func_t func, 393 void *user_data, hb_destroy_func_t destroy); 394 395 /* func dispatch */ 396 397 HB_EXTERN hb_bool_t 398 hb_font_get_h_extents (hb_font_t *font, 399 hb_font_extents_t *extents); 400 HB_EXTERN hb_bool_t 401 hb_font_get_v_extents (hb_font_t *font, 402 hb_font_extents_t *extents); 403 404 HB_EXTERN hb_bool_t 405 hb_font_get_nominal_glyph (hb_font_t *font, 406 hb_codepoint_t unicode, 407 hb_codepoint_t *glyph); 408 HB_EXTERN hb_bool_t 409 hb_font_get_variation_glyph (hb_font_t *font, 410 hb_codepoint_t unicode, hb_codepoint_t variation_selector, 411 hb_codepoint_t *glyph); 412 413 HB_EXTERN hb_position_t 414 hb_font_get_glyph_h_advance (hb_font_t *font, 415 hb_codepoint_t glyph); 416 HB_EXTERN hb_position_t 417 hb_font_get_glyph_v_advance (hb_font_t *font, 418 hb_codepoint_t glyph); 419 420 HB_EXTERN hb_bool_t 421 hb_font_get_glyph_h_origin (hb_font_t *font, 422 hb_codepoint_t glyph, 423 hb_position_t *x, hb_position_t *y); 424 HB_EXTERN hb_bool_t 425 hb_font_get_glyph_v_origin (hb_font_t *font, 426 hb_codepoint_t glyph, 427 hb_position_t *x, hb_position_t *y); 428 429 HB_EXTERN hb_position_t 430 hb_font_get_glyph_h_kerning (hb_font_t *font, 431 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph); 432 HB_EXTERN hb_position_t 433 hb_font_get_glyph_v_kerning (hb_font_t *font, 434 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph); 435 436 HB_EXTERN hb_bool_t 437 hb_font_get_glyph_extents (hb_font_t *font, 438 hb_codepoint_t glyph, 439 hb_glyph_extents_t *extents); 440 441 HB_EXTERN hb_bool_t 442 hb_font_get_glyph_contour_point (hb_font_t *font, 443 hb_codepoint_t glyph, unsigned int point_index, 444 hb_position_t *x, hb_position_t *y); 445 446 HB_EXTERN hb_bool_t 447 hb_font_get_glyph_name (hb_font_t *font, 448 hb_codepoint_t glyph, 449 char *name, unsigned int size); 450 HB_EXTERN hb_bool_t 451 hb_font_get_glyph_from_name (hb_font_t *font, 452 const char *name, int len, /* -1 means nul-terminated */ 453 hb_codepoint_t *glyph); 454 455 456 /* high-level funcs, with fallback */ 457 458 /* Calls either hb_font_get_nominal_glyph() if variation_selector is 0, 459 * otherwise callse hb_font_get_variation_glyph(). */ 460 HB_EXTERN hb_bool_t 461 hb_font_get_glyph (hb_font_t *font, 462 hb_codepoint_t unicode, hb_codepoint_t variation_selector, 463 hb_codepoint_t *glyph); 464 465 HB_EXTERN void 466 hb_font_get_extents_for_direction (hb_font_t *font, 467 hb_direction_t direction, 468 hb_font_extents_t *extents); 469 HB_EXTERN void 470 hb_font_get_glyph_advance_for_direction (hb_font_t *font, 471 hb_codepoint_t glyph, 472 hb_direction_t direction, 473 hb_position_t *x, hb_position_t *y); 474 HB_EXTERN void 475 hb_font_get_glyph_origin_for_direction (hb_font_t *font, 476 hb_codepoint_t glyph, 477 hb_direction_t direction, 478 hb_position_t *x, hb_position_t *y); 479 HB_EXTERN void 480 hb_font_add_glyph_origin_for_direction (hb_font_t *font, 481 hb_codepoint_t glyph, 482 hb_direction_t direction, 483 hb_position_t *x, hb_position_t *y); 484 HB_EXTERN void 485 hb_font_subtract_glyph_origin_for_direction (hb_font_t *font, 486 hb_codepoint_t glyph, 487 hb_direction_t direction, 488 hb_position_t *x, hb_position_t *y); 489 490 HB_EXTERN void 491 hb_font_get_glyph_kerning_for_direction (hb_font_t *font, 492 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, 493 hb_direction_t direction, 494 hb_position_t *x, hb_position_t *y); 495 496 HB_EXTERN hb_bool_t 497 hb_font_get_glyph_extents_for_origin (hb_font_t *font, 498 hb_codepoint_t glyph, 499 hb_direction_t direction, 500 hb_glyph_extents_t *extents); 501 502 HB_EXTERN hb_bool_t 503 hb_font_get_glyph_contour_point_for_origin (hb_font_t *font, 504 hb_codepoint_t glyph, unsigned int point_index, 505 hb_direction_t direction, 506 hb_position_t *x, hb_position_t *y); 507 508 /* Generates gidDDD if glyph has no name. */ 509 HB_EXTERN void 510 hb_font_glyph_to_string (hb_font_t *font, 511 hb_codepoint_t glyph, 512 char *s, unsigned int size); 513 /* Parses gidDDD and uniUUUU strings automatically. */ 514 HB_EXTERN hb_bool_t 515 hb_font_glyph_from_string (hb_font_t *font, 516 const char *s, int len, /* -1 means nul-terminated */ 517 hb_codepoint_t *glyph); 518 519 520 /* 521 * hb_font_t 522 */ 523 524 /* Fonts are very light-weight objects */ 525 526 HB_EXTERN hb_font_t * 527 hb_font_create (hb_face_t *face); 528 529 HB_EXTERN hb_font_t * 530 hb_font_create_sub_font (hb_font_t *parent); 531 532 HB_EXTERN hb_font_t * 533 hb_font_get_empty (void); 534 535 HB_EXTERN hb_font_t * 536 hb_font_reference (hb_font_t *font); 537 538 HB_EXTERN void 539 hb_font_destroy (hb_font_t *font); 540 541 HB_EXTERN hb_bool_t 542 hb_font_set_user_data (hb_font_t *font, 543 hb_user_data_key_t *key, 544 void * data, 545 hb_destroy_func_t destroy, 546 hb_bool_t replace); 547 548 549 HB_EXTERN void * 550 hb_font_get_user_data (hb_font_t *font, 551 hb_user_data_key_t *key); 552 553 HB_EXTERN void 554 hb_font_make_immutable (hb_font_t *font); 555 556 HB_EXTERN hb_bool_t 557 hb_font_is_immutable (hb_font_t *font); 558 559 HB_EXTERN void 560 hb_font_set_parent (hb_font_t *font, 561 hb_font_t *parent); 562 563 HB_EXTERN hb_font_t * 564 hb_font_get_parent (hb_font_t *font); 565 566 HB_EXTERN hb_face_t * 567 hb_font_get_face (hb_font_t *font); 568 569 570 HB_EXTERN void 571 hb_font_set_funcs (hb_font_t *font, 572 hb_font_funcs_t *klass, 573 void *font_data, 574 hb_destroy_func_t destroy); 575 576 /* Be *very* careful with this function! */ 577 HB_EXTERN void 578 hb_font_set_funcs_data (hb_font_t *font, 579 void *font_data, 580 hb_destroy_func_t destroy); 581 582 583 HB_EXTERN void 584 hb_font_set_scale (hb_font_t *font, 585 int x_scale, 586 int y_scale); 587 588 HB_EXTERN void 589 hb_font_get_scale (hb_font_t *font, 590 int *x_scale, 591 int *y_scale); 592 593 /* 594 * A zero value means "no hinting in that direction" 595 */ 596 HB_EXTERN void 597 hb_font_set_ppem (hb_font_t *font, 598 unsigned int x_ppem, 599 unsigned int y_ppem); 600 601 HB_EXTERN void 602 hb_font_get_ppem (hb_font_t *font, 603 unsigned int *x_ppem, 604 unsigned int *y_ppem); 605 606 607 HB_END_DECLS 608 609 #endif /* HB_FONT_H */ 610