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_font_funcs_t *
  50 hb_font_funcs_create (void);
  51 
  52 hb_font_funcs_t *
  53 hb_font_funcs_get_empty (void);
  54 
  55 hb_font_funcs_t *
  56 hb_font_funcs_reference (hb_font_funcs_t *ffuncs);
  57 
  58 void
  59 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs);
  60 
  61 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 void *
  70 hb_font_funcs_get_user_data (hb_font_funcs_t    *ffuncs,
  71                              hb_user_data_key_t *key);
  72 
  73 
  74 void
  75 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs);
  76 
  77 hb_bool_t
  78 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs);
  79 
  80 
  81 /* glyph extents */
  82 
  83 /* Note that height is negative in coordinate systems that grow up. */
  84 typedef struct hb_glyph_extents_t
  85 {
  86   hb_position_t x_bearing; /* left side of glyph from origin. */
  87   hb_position_t y_bearing; /* top side of glyph from origin. */
  88   hb_position_t width; /* distance from left to right side. */
  89   hb_position_t height; /* distance from top to bottom side. */
  90 } hb_glyph_extents_t;
  91 
  92 
  93 /* func types */
  94 
  95 typedef hb_bool_t (*hb_font_get_glyph_func_t) (hb_font_t *font, void *font_data,
  96                                                hb_codepoint_t unicode, hb_codepoint_t variation_selector,
  97                                                hb_codepoint_t *glyph,
  98                                                void *user_data);
  99 
 100 
 101 typedef hb_position_t (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void *font_data,
 102                                                            hb_codepoint_t glyph,
 103                                                            void *user_data);
 104 typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_h_advance_func_t;
 105 typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_v_advance_func_t;
 106 
 107 typedef hb_bool_t (*hb_font_get_glyph_origin_func_t) (hb_font_t *font, void *font_data,
 108                                                       hb_codepoint_t glyph,
 109                                                       hb_position_t *x, hb_position_t *y,
 110                                                       void *user_data);
 111 typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_h_origin_func_t;
 112 typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_v_origin_func_t;
 113 
 114 typedef hb_position_t (*hb_font_get_glyph_kerning_func_t) (hb_font_t *font, void *font_data,
 115                                                            hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
 116                                                            void *user_data);
 117 typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_h_kerning_func_t;
 118 typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_v_kerning_func_t;
 119 
 120 
 121 typedef hb_bool_t (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, void *font_data,
 122                                                        hb_codepoint_t glyph,
 123                                                        hb_glyph_extents_t *extents,
 124                                                        void *user_data);
 125 typedef hb_bool_t (*hb_font_get_glyph_contour_point_func_t) (hb_font_t *font, void *font_data,
 126                                                              hb_codepoint_t glyph, unsigned int point_index,
 127                                                              hb_position_t *x, hb_position_t *y,
 128                                                              void *user_data);
 129 
 130 
 131 typedef hb_bool_t (*hb_font_get_glyph_name_func_t) (hb_font_t *font, void *font_data,
 132                                                     hb_codepoint_t glyph,
 133                                                     char *name, unsigned int size,
 134                                                     void *user_data);
 135 typedef hb_bool_t (*hb_font_get_glyph_from_name_func_t) (hb_font_t *font, void *font_data,
 136                                                          const char *name, int len, /* -1 means nul-terminated */
 137                                                          hb_codepoint_t *glyph,
 138                                                          void *user_data);
 139 
 140 
 141 /* func setters */
 142 
 143 /**
 144  * hb_font_funcs_set_glyph_func:
 145  * @ffuncs: font functions.
 146  * @func: (closure user_data) (destroy destroy) (scope notified):
 147  * @user_data:
 148  * @destroy:
 149  *
 150  *
 151  *
 152  * Since: 0.9.2
 153  **/
 154 void
 155 hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
 156                               hb_font_get_glyph_func_t func,
 157                               void *user_data, hb_destroy_func_t destroy);
 158 
 159 /**
 160  * hb_font_funcs_set_glyph_h_advance_func:
 161  * @ffuncs: font functions.
 162  * @func: (closure user_data) (destroy destroy) (scope notified):
 163  * @user_data:
 164  * @destroy:
 165  *
 166  *
 167  *
 168  * Since: 0.9.2
 169  **/
 170 void
 171 hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs,
 172                                         hb_font_get_glyph_h_advance_func_t func,
 173                                         void *user_data, hb_destroy_func_t destroy);
 174 
 175 /**
 176  * hb_font_funcs_set_glyph_v_advance_func:
 177  * @ffuncs: font functions.
 178  * @func: (closure user_data) (destroy destroy) (scope notified):
 179  * @user_data:
 180  * @destroy:
 181  *
 182  *
 183  *
 184  * Since: 0.9.2
 185  **/
 186 void
 187 hb_font_funcs_set_glyph_v_advance_func (hb_font_funcs_t *ffuncs,
 188                                         hb_font_get_glyph_v_advance_func_t func,
 189                                         void *user_data, hb_destroy_func_t destroy);
 190 
 191 /**
 192  * hb_font_funcs_set_glyph_h_origin_func:
 193  * @ffuncs: font functions.
 194  * @func: (closure user_data) (destroy destroy) (scope notified):
 195  * @user_data:
 196  * @destroy:
 197  *
 198  *
 199  *
 200  * Since: 0.9.2
 201  **/
 202 void
 203 hb_font_funcs_set_glyph_h_origin_func (hb_font_funcs_t *ffuncs,
 204                                        hb_font_get_glyph_h_origin_func_t func,
 205                                        void *user_data, hb_destroy_func_t destroy);
 206 
 207 /**
 208  * hb_font_funcs_set_glyph_v_origin_func:
 209  * @ffuncs: font functions.
 210  * @func: (closure user_data) (destroy destroy) (scope notified):
 211  * @user_data:
 212  * @destroy:
 213  *
 214  *
 215  *
 216  * Since: 0.9.2
 217  **/
 218 void
 219 hb_font_funcs_set_glyph_v_origin_func (hb_font_funcs_t *ffuncs,
 220                                        hb_font_get_glyph_v_origin_func_t func,
 221                                        void *user_data, hb_destroy_func_t destroy);
 222 
 223 /**
 224  * hb_font_funcs_set_glyph_h_kerning_func:
 225  * @ffuncs: font functions.
 226  * @func: (closure user_data) (destroy destroy) (scope notified):
 227  * @user_data:
 228  * @destroy:
 229  *
 230  *
 231  *
 232  * Since: 0.9.2
 233  **/
 234 void
 235 hb_font_funcs_set_glyph_h_kerning_func (hb_font_funcs_t *ffuncs,
 236                                         hb_font_get_glyph_h_kerning_func_t func,
 237                                         void *user_data, hb_destroy_func_t destroy);
 238 
 239 /**
 240  * hb_font_funcs_set_glyph_v_kerning_func:
 241  * @ffuncs: font functions.
 242  * @func: (closure user_data) (destroy destroy) (scope notified):
 243  * @user_data:
 244  * @destroy:
 245  *
 246  *
 247  *
 248  * Since: 0.9.2
 249  **/
 250 void
 251 hb_font_funcs_set_glyph_v_kerning_func (hb_font_funcs_t *ffuncs,
 252                                         hb_font_get_glyph_v_kerning_func_t func,
 253                                         void *user_data, hb_destroy_func_t destroy);
 254 
 255 /**
 256  * hb_font_funcs_set_glyph_extents_func:
 257  * @ffuncs: font functions.
 258  * @func: (closure user_data) (destroy destroy) (scope notified):
 259  * @user_data:
 260  * @destroy:
 261  *
 262  *
 263  *
 264  * Since: 0.9.2
 265  **/
 266 void
 267 hb_font_funcs_set_glyph_extents_func (hb_font_funcs_t *ffuncs,
 268                                       hb_font_get_glyph_extents_func_t func,
 269                                       void *user_data, hb_destroy_func_t destroy);
 270 
 271 /**
 272  * hb_font_funcs_set_glyph_contour_point_func:
 273  * @ffuncs: font functions.
 274  * @func: (closure user_data) (destroy destroy) (scope notified):
 275  * @user_data:
 276  * @destroy:
 277  *
 278  *
 279  *
 280  * Since: 0.9.2
 281  **/
 282 void
 283 hb_font_funcs_set_glyph_contour_point_func (hb_font_funcs_t *ffuncs,
 284                                             hb_font_get_glyph_contour_point_func_t func,
 285                                             void *user_data, hb_destroy_func_t destroy);
 286 
 287 /**
 288  * hb_font_funcs_set_glyph_name_func:
 289  * @ffuncs: font functions.
 290  * @func: (closure user_data) (destroy destroy) (scope notified):
 291  * @user_data:
 292  * @destroy:
 293  *
 294  *
 295  *
 296  * Since: 0.9.2
 297  **/
 298 void
 299 hb_font_funcs_set_glyph_name_func (hb_font_funcs_t *ffuncs,
 300                                    hb_font_get_glyph_name_func_t func,
 301                                    void *user_data, hb_destroy_func_t destroy);
 302 
 303 /**
 304  * hb_font_funcs_set_glyph_from_name_func:
 305  * @ffuncs: font functions.
 306  * @func: (closure user_data) (destroy destroy) (scope notified):
 307  * @user_data:
 308  * @destroy:
 309  *
 310  *
 311  *
 312  * Since: 0.9.2
 313  **/
 314 void
 315 hb_font_funcs_set_glyph_from_name_func (hb_font_funcs_t *ffuncs,
 316                                         hb_font_get_glyph_from_name_func_t func,
 317                                         void *user_data, hb_destroy_func_t destroy);
 318 
 319 
 320 /* func dispatch */
 321 
 322 hb_bool_t
 323 hb_font_get_glyph (hb_font_t *font,
 324                    hb_codepoint_t unicode, hb_codepoint_t variation_selector,
 325                    hb_codepoint_t *glyph);
 326 
 327 hb_position_t
 328 hb_font_get_glyph_h_advance (hb_font_t *font,
 329                              hb_codepoint_t glyph);
 330 hb_position_t
 331 hb_font_get_glyph_v_advance (hb_font_t *font,
 332                              hb_codepoint_t glyph);
 333 
 334 hb_bool_t
 335 hb_font_get_glyph_h_origin (hb_font_t *font,
 336                             hb_codepoint_t glyph,
 337                             hb_position_t *x, hb_position_t *y);
 338 hb_bool_t
 339 hb_font_get_glyph_v_origin (hb_font_t *font,
 340                             hb_codepoint_t glyph,
 341                             hb_position_t *x, hb_position_t *y);
 342 
 343 hb_position_t
 344 hb_font_get_glyph_h_kerning (hb_font_t *font,
 345                              hb_codepoint_t left_glyph, hb_codepoint_t right_glyph);
 346 hb_position_t
 347 hb_font_get_glyph_v_kerning (hb_font_t *font,
 348                              hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph);
 349 
 350 hb_bool_t
 351 hb_font_get_glyph_extents (hb_font_t *font,
 352                            hb_codepoint_t glyph,
 353                            hb_glyph_extents_t *extents);
 354 
 355 hb_bool_t
 356 hb_font_get_glyph_contour_point (hb_font_t *font,
 357                                  hb_codepoint_t glyph, unsigned int point_index,
 358                                  hb_position_t *x, hb_position_t *y);
 359 
 360 hb_bool_t
 361 hb_font_get_glyph_name (hb_font_t *font,
 362                         hb_codepoint_t glyph,
 363                         char *name, unsigned int size);
 364 hb_bool_t
 365 hb_font_get_glyph_from_name (hb_font_t *font,
 366                              const char *name, int len, /* -1 means nul-terminated */
 367                              hb_codepoint_t *glyph);
 368 
 369 
 370 /* high-level funcs, with fallback */
 371 
 372 void
 373 hb_font_get_glyph_advance_for_direction (hb_font_t *font,
 374                                          hb_codepoint_t glyph,
 375                                          hb_direction_t direction,
 376                                          hb_position_t *x, hb_position_t *y);
 377 void
 378 hb_font_get_glyph_origin_for_direction (hb_font_t *font,
 379                                         hb_codepoint_t glyph,
 380                                         hb_direction_t direction,
 381                                         hb_position_t *x, hb_position_t *y);
 382 void
 383 hb_font_add_glyph_origin_for_direction (hb_font_t *font,
 384                                         hb_codepoint_t glyph,
 385                                         hb_direction_t direction,
 386                                         hb_position_t *x, hb_position_t *y);
 387 void
 388 hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
 389                                              hb_codepoint_t glyph,
 390                                              hb_direction_t direction,
 391                                              hb_position_t *x, hb_position_t *y);
 392 
 393 void
 394 hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
 395                                          hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
 396                                          hb_direction_t direction,
 397                                          hb_position_t *x, hb_position_t *y);
 398 
 399 hb_bool_t
 400 hb_font_get_glyph_extents_for_origin (hb_font_t *font,
 401                                       hb_codepoint_t glyph,
 402                                       hb_direction_t direction,
 403                                       hb_glyph_extents_t *extents);
 404 
 405 hb_bool_t
 406 hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
 407                                             hb_codepoint_t glyph, unsigned int point_index,
 408                                             hb_direction_t direction,
 409                                             hb_position_t *x, hb_position_t *y);
 410 
 411 /* Generates gidDDD if glyph has no name. */
 412 void
 413 hb_font_glyph_to_string (hb_font_t *font,
 414                          hb_codepoint_t glyph,
 415                          char *s, unsigned int size);
 416 /* Parses gidDDD and uniUUUU strings automatically. */
 417 hb_bool_t
 418 hb_font_glyph_from_string (hb_font_t *font,
 419                            const char *s, int len, /* -1 means nul-terminated */
 420                            hb_codepoint_t *glyph);
 421 
 422 
 423 /*
 424  * hb_font_t
 425  */
 426 
 427 /* Fonts are very light-weight objects */
 428 
 429 hb_font_t *
 430 hb_font_create (hb_face_t *face);
 431 
 432 hb_font_t *
 433 hb_font_create_sub_font (hb_font_t *parent);
 434 
 435 hb_font_t *
 436 hb_font_get_empty (void);
 437 
 438 hb_font_t *
 439 hb_font_reference (hb_font_t *font);
 440 
 441 void
 442 hb_font_destroy (hb_font_t *font);
 443 
 444 hb_bool_t
 445 hb_font_set_user_data (hb_font_t          *font,
 446                        hb_user_data_key_t *key,
 447                        void *              data,
 448                        hb_destroy_func_t   destroy,
 449                        hb_bool_t           replace);
 450 
 451 
 452 void *
 453 hb_font_get_user_data (hb_font_t          *font,
 454                        hb_user_data_key_t *key);
 455 
 456 void
 457 hb_font_make_immutable (hb_font_t *font);
 458 
 459 hb_bool_t
 460 hb_font_is_immutable (hb_font_t *font);
 461 
 462 void
 463 hb_font_set_parent (hb_font_t *font,
 464                     hb_font_t *parent);
 465 
 466 hb_font_t *
 467 hb_font_get_parent (hb_font_t *font);
 468 
 469 hb_face_t *
 470 hb_font_get_face (hb_font_t *font);
 471 
 472 
 473 void
 474 hb_font_set_funcs (hb_font_t         *font,
 475                    hb_font_funcs_t   *klass,
 476                    void              *font_data,
 477                    hb_destroy_func_t  destroy);
 478 
 479 /* Be *very* careful with this function! */
 480 void
 481 hb_font_set_funcs_data (hb_font_t         *font,
 482                         void              *font_data,
 483                         hb_destroy_func_t  destroy);
 484 
 485 
 486 void
 487 hb_font_set_scale (hb_font_t *font,
 488                    int x_scale,
 489                    int y_scale);
 490 
 491 void
 492 hb_font_get_scale (hb_font_t *font,
 493                    int *x_scale,
 494                    int *y_scale);
 495 
 496 /*
 497  * A zero value means "no hinting in that direction"
 498  */
 499 void
 500 hb_font_set_ppem (hb_font_t *font,
 501                   unsigned int x_ppem,
 502                   unsigned int y_ppem);
 503 
 504 void
 505 hb_font_get_ppem (hb_font_t *font,
 506                   unsigned int *x_ppem,
 507                   unsigned int *y_ppem);
 508 
 509 
 510 HB_END_DECLS
 511 
 512 #endif /* HB_FONT_H */