hb-font.cc 37.0 KB
Newer Older
1
/*
B
Behdad Esfahbod 已提交
2
 * Copyright © 2009  Red Hat, Inc.
3
 * Copyright © 2012  Google, Inc.
4
 *
B
Behdad Esfahbod 已提交
5
 *  This is part of HarfBuzz, a text shaping library.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Red Hat Author(s): Behdad Esfahbod
26
 * Google Author(s): Behdad Esfahbod
27 28
 */

29
#include "hb-private.hh"
30

31
#include "hb-font-private.hh"
B
Behdad Esfahbod 已提交
32

B
Behdad Esfahbod 已提交
33

34
/*
B
Behdad Esfahbod 已提交
35
 * hb_font_funcs_t
36 37
 */

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
static hb_bool_t
hb_font_get_font_h_extents_nil (hb_font_t *font,
				void *font_data HB_UNUSED,
				hb_font_extents_t *metrics,
				void *user_data HB_UNUSED)
{
  memset (metrics, 0, sizeof (*metrics));
  return false;
}
static hb_bool_t
hb_font_get_font_h_extents_parent (hb_font_t *font,
				   void *font_data HB_UNUSED,
				   hb_font_extents_t *metrics,
				   void *user_data HB_UNUSED)
{
  hb_bool_t ret = font->parent->get_font_h_extents (metrics);
  if (ret) {
    metrics->ascender = font->parent_scale_y_distance (metrics->ascender);
    metrics->descender = font->parent_scale_y_distance (metrics->descender);
    metrics->line_gap = font->parent_scale_y_distance (metrics->line_gap);
  }
  return ret;
}

static hb_bool_t
hb_font_get_font_v_extents_nil (hb_font_t *font,
				void *font_data HB_UNUSED,
				hb_font_extents_t *metrics,
				void *user_data HB_UNUSED)
{
  memset (metrics, 0, sizeof (*metrics));
  return false;
}
static hb_bool_t
hb_font_get_font_v_extents_parent (hb_font_t *font,
				   void *font_data HB_UNUSED,
				   hb_font_extents_t *metrics,
				   void *user_data HB_UNUSED)
{
  hb_bool_t ret = font->parent->get_font_v_extents (metrics);
  if (ret) {
    metrics->ascender = font->parent_scale_x_distance (metrics->ascender);
    metrics->descender = font->parent_scale_x_distance (metrics->descender);
    metrics->line_gap = font->parent_scale_x_distance (metrics->line_gap);
  }
  return ret;
}

86
static hb_bool_t
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED,
			       void *font_data HB_UNUSED,
			       hb_codepoint_t unicode,
			       hb_codepoint_t *glyph,
			       void *user_data HB_UNUSED)
{
  *glyph = 0;
  return false;
}
static hb_bool_t
hb_font_get_nominal_glyph_parent (hb_font_t *font,
				  void *font_data HB_UNUSED,
				  hb_codepoint_t unicode,
				  hb_codepoint_t *glyph,
				  void *user_data HB_UNUSED)
{
  return font->parent->get_nominal_glyph (unicode, glyph);
}

static hb_bool_t
hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED,
				 void *font_data HB_UNUSED,
				 hb_codepoint_t unicode,
				 hb_codepoint_t variation_selector,
				 hb_codepoint_t *glyph,
				 void *user_data HB_UNUSED)
113 114
{
  *glyph = 0;
115
  return false;
116
}
117
static hb_bool_t
118 119 120 121 122 123
hb_font_get_variation_glyph_parent (hb_font_t *font,
				    void *font_data HB_UNUSED,
				    hb_codepoint_t unicode,
				    hb_codepoint_t variation_selector,
				    hb_codepoint_t *glyph,
				    void *user_data HB_UNUSED)
124
{
125
  return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
126
}
127

128

129
static hb_position_t
130
hb_font_get_glyph_h_advance_nil (hb_font_t *font HB_UNUSED,
131 132 133
				 void *font_data HB_UNUSED,
				 hb_codepoint_t glyph,
				 void *user_data HB_UNUSED)
134
{
135
  return font->x_scale;
136
}
137 138 139 140 141 142 143 144
static hb_position_t
hb_font_get_glyph_h_advance_parent (hb_font_t *font,
				    void *font_data HB_UNUSED,
				    hb_codepoint_t glyph,
				    void *user_data HB_UNUSED)
{
  return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
}
B
Behdad Esfahbod 已提交
145

146
static hb_position_t
147
hb_font_get_glyph_v_advance_nil (hb_font_t *font HB_UNUSED,
148 149 150
				 void *font_data HB_UNUSED,
				 hb_codepoint_t glyph,
				 void *user_data HB_UNUSED)
151
{
B
Behdad Esfahbod 已提交
152
  /* TODO use font_extents.ascender+descender */
153
  return font->y_scale;
154
}
155 156 157 158 159 160 161 162
static hb_position_t
hb_font_get_glyph_v_advance_parent (hb_font_t *font,
				    void *font_data HB_UNUSED,
				    hb_codepoint_t glyph,
				    void *user_data HB_UNUSED)
{
  return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
}
163

B
Behdad Esfahbod 已提交
164
static hb_bool_t
165
hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
B
Behdad Esfahbod 已提交
166 167
				void *font_data HB_UNUSED,
				hb_codepoint_t glyph,
B
Behdad Esfahbod 已提交
168 169
				hb_position_t *x,
				hb_position_t *y,
B
Behdad Esfahbod 已提交
170 171
				void *user_data HB_UNUSED)
{
B
Behdad Esfahbod 已提交
172
  *x = *y = 0;
173
  return true;
B
Behdad Esfahbod 已提交
174
}
175 176 177 178 179 180 181 182 183 184 185 186 187
static hb_bool_t
hb_font_get_glyph_h_origin_parent (hb_font_t *font,
				   void *font_data HB_UNUSED,
				   hb_codepoint_t glyph,
				   hb_position_t *x,
				   hb_position_t *y,
				   void *user_data HB_UNUSED)
{
  hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
  if (ret)
    font->parent_scale_position (x, y);
  return ret;
}
B
Behdad Esfahbod 已提交
188

189
static hb_bool_t
190
hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
191 192
				void *font_data HB_UNUSED,
				hb_codepoint_t glyph,
B
Behdad Esfahbod 已提交
193 194
				hb_position_t *x,
				hb_position_t *y,
195 196
				void *user_data HB_UNUSED)
{
B
Behdad Esfahbod 已提交
197
  *x = *y = 0;
198
  return false;
199
}
200 201 202 203 204 205 206 207 208 209 210 211 212
static hb_bool_t
hb_font_get_glyph_v_origin_parent (hb_font_t *font,
				   void *font_data HB_UNUSED,
				   hb_codepoint_t glyph,
				   hb_position_t *x,
				   hb_position_t *y,
				   void *user_data HB_UNUSED)
{
  hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
  if (ret)
    font->parent_scale_position (x, y);
  return ret;
}
213

214
static hb_position_t
215
hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
B
Behdad Esfahbod 已提交
216 217 218 219
				 void *font_data HB_UNUSED,
				 hb_codepoint_t left_glyph,
				 hb_codepoint_t right_glyph,
				 void *user_data HB_UNUSED)
220
{
221
  return 0;
222
}
223 224 225 226 227 228 229 230 231
static hb_position_t
hb_font_get_glyph_h_kerning_parent (hb_font_t *font,
				    void *font_data HB_UNUSED,
				    hb_codepoint_t left_glyph,
				    hb_codepoint_t right_glyph,
				    void *user_data HB_UNUSED)
{
  return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
}
232

233
static hb_position_t
234
hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
B
Behdad Esfahbod 已提交
235 236 237 238
				 void *font_data HB_UNUSED,
				 hb_codepoint_t top_glyph,
				 hb_codepoint_t bottom_glyph,
				 void *user_data HB_UNUSED)
239
{
240
  return 0;
241
}
242 243 244 245 246 247 248 249 250
static hb_position_t
hb_font_get_glyph_v_kerning_parent (hb_font_t *font,
				    void *font_data HB_UNUSED,
				    hb_codepoint_t top_glyph,
				    hb_codepoint_t bottom_glyph,
				    void *user_data HB_UNUSED)
{
  return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
}
B
Behdad Esfahbod 已提交
251

252
static hb_bool_t
253
hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
254
			       void *font_data HB_UNUSED,
255 256
			       hb_codepoint_t glyph,
			       hb_glyph_extents_t *extents,
257
			       void *user_data HB_UNUSED)
258
{
259
  memset (extents, 0, sizeof (*extents));
260
  return false;
261
}
262 263 264 265 266 267 268 269 270 271 272 273 274 275
static hb_bool_t
hb_font_get_glyph_extents_parent (hb_font_t *font,
				  void *font_data HB_UNUSED,
				  hb_codepoint_t glyph,
				  hb_glyph_extents_t *extents,
				  void *user_data HB_UNUSED)
{
  hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
  if (ret) {
    font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
    font->parent_scale_distance (&extents->width, &extents->height);
  }
  return ret;
}
276

277
static hb_bool_t
278
hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,
B
Behdad Esfahbod 已提交
279 280 281 282 283 284
				     void *font_data HB_UNUSED,
				     hb_codepoint_t glyph,
				     unsigned int point_index,
				     hb_position_t *x,
				     hb_position_t *y,
				     void *user_data HB_UNUSED)
285
{
286
  *x = *y = 0;
287
  return false;
288
}
289 290 291 292 293 294 295 296 297 298 299 300 301 302
static hb_bool_t
hb_font_get_glyph_contour_point_parent (hb_font_t *font,
					void *font_data HB_UNUSED,
					hb_codepoint_t glyph,
					unsigned int point_index,
					hb_position_t *x,
					hb_position_t *y,
					void *user_data HB_UNUSED)
{
  hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
  if (ret)
    font->parent_scale_position (x, y);
  return ret;
}
B
Behdad Esfahbod 已提交
303

304
static hb_bool_t
305
hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,
306 307 308 309 310
			    void *font_data HB_UNUSED,
			    hb_codepoint_t glyph,
			    char *name, unsigned int size,
			    void *user_data HB_UNUSED)
{
311
  if (size) *name = '\0';
312
  return false;
313
}
314 315 316 317 318 319 320 321 322
static hb_bool_t
hb_font_get_glyph_name_parent (hb_font_t *font,
			       void *font_data HB_UNUSED,
			       hb_codepoint_t glyph,
			       char *name, unsigned int size,
			       void *user_data HB_UNUSED)
{
  return font->parent->get_glyph_name (glyph, name, size);
}
323 324

static hb_bool_t
325
hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,
326 327 328 329 330 331
				 void *font_data HB_UNUSED,
				 const char *name, int len, /* -1 means nul-terminated */
				 hb_codepoint_t *glyph,
				 void *user_data HB_UNUSED)
{
  *glyph = 0;
332
  return false;
333
}
334 335 336 337 338 339 340 341 342
static hb_bool_t
hb_font_get_glyph_from_name_parent (hb_font_t *font,
				    void *font_data HB_UNUSED,
				    const char *name, int len, /* -1 means nul-terminated */
				    hb_codepoint_t *glyph,
				    void *user_data HB_UNUSED)
{
  return font->parent->get_glyph_from_name (name, len, glyph);
}
343

344
static const hb_font_funcs_t _hb_font_funcs_nil = {
345 346
  HB_OBJECT_HEADER_STATIC,

347
  true, /* immutable */
348

349 350 351 352 353 354 355 356 357 358
  {
#define HB_FONT_FUNC_IMPLEMENT(name) NULL,
    HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
#undef HB_FONT_FUNC_IMPLEMENT
  },
  {
#define HB_FONT_FUNC_IMPLEMENT(name) NULL,
    HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
#undef HB_FONT_FUNC_IMPLEMENT
  },
359
  {
360
    {
361
#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
362
      HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
363
#undef HB_FONT_FUNC_IMPLEMENT
364
    }
365
  }
366
};
367 368 369 370 371
static const hb_font_funcs_t _hb_font_funcs_parent = {
  HB_OBJECT_HEADER_STATIC,

  true, /* immutable */

372 373 374 375 376 377 378 379 380 381
  {
#define HB_FONT_FUNC_IMPLEMENT(name) NULL,
    HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
#undef HB_FONT_FUNC_IMPLEMENT
  },
  {
#define HB_FONT_FUNC_IMPLEMENT(name) NULL,
    HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
#undef HB_FONT_FUNC_IMPLEMENT
  },
382
  {
383
    {
384
#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_parent,
385
      HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
386
#undef HB_FONT_FUNC_IMPLEMENT
387
    }
388 389
  }
};
390

B
Behdad Esfahbod 已提交
391

392
/**
393
 * hb_font_funcs_create: (Xconstructor)
394 395 396 397 398
 *
 * 
 *
 * Return value: (transfer full): 
 *
399
 * Since: 0.9.2
400
 **/
B
Behdad Esfahbod 已提交
401 402
hb_font_funcs_t *
hb_font_funcs_create (void)
403
{
B
Behdad Esfahbod 已提交
404
  hb_font_funcs_t *ffuncs;
405

406
  if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
407
    return hb_font_funcs_get_empty ();
408

409
  ffuncs->get = _hb_font_funcs_parent.get;
410

B
Behdad Esfahbod 已提交
411
  return ffuncs;
412 413
}

414 415 416 417 418 419 420
/**
 * hb_font_funcs_get_empty:
 *
 * 
 *
 * Return value: (transfer full): 
 *
421
 * Since: 0.9.2
422
 **/
423 424 425
hb_font_funcs_t *
hb_font_funcs_get_empty (void)
{
426
  return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_parent);
427 428
}

429 430 431 432 433 434 435 436
/**
 * hb_font_funcs_reference: (skip)
 * @ffuncs: font functions.
 *
 * 
 *
 * Return value: 
 *
437
 * Since: 0.9.2
438
 **/
B
Behdad Esfahbod 已提交
439 440
hb_font_funcs_t *
hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
441
{
442
  return hb_object_reference (ffuncs);
443 444
}

445 446 447 448 449 450
/**
 * hb_font_funcs_destroy: (skip)
 * @ffuncs: font functions.
 *
 * 
 *
451
 * Since: 0.9.2
452
 **/
453
void
B
Behdad Esfahbod 已提交
454
hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
455
{
456
  if (!hb_object_destroy (ffuncs)) return;
457

B
Behdad Esfahbod 已提交
458 459
#define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
  ffuncs->destroy.name (ffuncs->user_data.name);
460 461
  HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
#undef HB_FONT_FUNC_IMPLEMENT
462

B
Behdad Esfahbod 已提交
463
  free (ffuncs);
464 465
}

466 467 468 469 470 471 472 473 474 475 476 477
/**
 * hb_font_funcs_set_user_data: (skip)
 * @ffuncs: font functions.
 * @key: 
 * @data: 
 * @destroy: 
 * @replace: 
 *
 * 
 *
 * Return value: 
 *
478
 * Since: 0.9.2
479
 **/
480 481 482 483
hb_bool_t
hb_font_funcs_set_user_data (hb_font_funcs_t    *ffuncs,
			     hb_user_data_key_t *key,
			     void *              data,
484 485
			     hb_destroy_func_t   destroy,
			     hb_bool_t           replace)
486
{
487
  return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
488 489
}

490 491 492 493 494 495 496 497 498
/**
 * hb_font_funcs_get_user_data: (skip)
 * @ffuncs: font functions.
 * @key: 
 *
 * 
 *
 * Return value: (transfer none): 
 *
499
 * Since: 0.9.2
500
 **/
501 502 503 504 505 506 507 508
void *
hb_font_funcs_get_user_data (hb_font_funcs_t    *ffuncs,
			     hb_user_data_key_t *key)
{
  return hb_object_get_user_data (ffuncs, key);
}


509 510 511 512 513 514
/**
 * hb_font_funcs_make_immutable:
 * @ffuncs: font functions.
 *
 * 
 *
515
 * Since: 0.9.2
516
 **/
517 518 519
void
hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
{
520
  if (unlikely (hb_object_is_inert (ffuncs)))
521 522
    return;

523
  ffuncs->immutable = true;
B
Behdad Esfahbod 已提交
524 525
}

526 527 528 529 530 531 532 533
/**
 * hb_font_funcs_is_immutable:
 * @ffuncs: font functions.
 *
 * 
 *
 * Return value: 
 *
534
 * Since: 0.9.2
535
 **/
B
Behdad Esfahbod 已提交
536 537 538
hb_bool_t
hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
{
B
Behdad Esfahbod 已提交
539
  return ffuncs->immutable;
540 541
}

542

543
#define HB_FONT_FUNC_IMPLEMENT(name) \
544 545 546 547 548 549 550
                                                                         \
void                                                                     \
hb_font_funcs_set_##name##_func (hb_font_funcs_t             *ffuncs,    \
                                 hb_font_get_##name##_func_t  func,      \
                                 void                        *user_data, \
                                 hb_destroy_func_t            destroy)   \
{                                                                        \
B
Behdad Esfahbod 已提交
551 552 553
  if (ffuncs->immutable) {                                               \
    if (destroy)                                                         \
      destroy (user_data);                                               \
554
    return;                                                              \
B
Behdad Esfahbod 已提交
555
  }                                                                      \
556 557 558 559 560
                                                                         \
  if (ffuncs->destroy.name)                                              \
    ffuncs->destroy.name (ffuncs->user_data.name);                       \
                                                                         \
  if (func) {                                                            \
561
    ffuncs->get.f.name = func;                                           \
562 563 564
    ffuncs->user_data.name = user_data;                                  \
    ffuncs->destroy.name = destroy;                                      \
  } else {                                                               \
565
    ffuncs->get.f.name = hb_font_get_##name##_parent;                    \
566 567 568
    ffuncs->user_data.name = NULL;                                       \
    ffuncs->destroy.name = NULL;                                         \
  }                                                                      \
B
Behdad Esfahbod 已提交
569 570
}

571 572 573
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
#undef HB_FONT_FUNC_IMPLEMENT

574 575 576 577 578 579 580
bool
hb_font_t::has_func (unsigned int i)
{
  if (parent && parent != hb_font_get_empty () && parent->has_func (i))
    return true;
  return this->klass->get.array[i] != _hb_font_funcs_parent.get.array[i];
}
581

B
Behdad Esfahbod 已提交
582 583
/* Public getters */

584 585 586 587 588 589 590 591 592
/**
 * hb_font_get_h_extents:
 * @font: a font.
 * @extents: (out):
 *
 *
 *
 * Return value:
 *
B
Behdad Esfahbod 已提交
593
 * Since: 1.1.3
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
 **/
hb_bool_t
hb_font_get_h_extents (hb_font_t *font,
		       hb_font_extents_t *extents)
{
  return font->get_font_h_extents (extents);
}

/**
 * hb_font_get_v_extents:
 * @font: a font.
 * @extents: (out):
 *
 *
 *
 * Return value:
 *
B
Behdad Esfahbod 已提交
611
 * Since: 1.1.3
612 613 614 615 616 617 618 619
 **/
hb_bool_t
hb_font_get_v_extents (hb_font_t *font,
		       hb_font_extents_t *extents)
{
  return font->get_font_v_extents (extents);
}

620 621 622 623 624 625 626 627 628 629 630
/**
 * hb_font_get_glyph:
 * @font: a font.
 * @unicode: 
 * @variation_selector: 
 * @glyph: (out): 
 *
 * 
 *
 * Return value: 
 *
631
 * Since: 0.9.2
632
 **/
633 634 635 636 637
hb_bool_t
hb_font_get_glyph (hb_font_t *font,
		   hb_codepoint_t unicode, hb_codepoint_t variation_selector,
		   hb_codepoint_t *glyph)
{
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
  if (unlikely (variation_selector))
    return font->get_variation_glyph (unicode, variation_selector, glyph);
  return font->get_nominal_glyph (unicode, glyph);
}

/**
 * hb_font_get_nominal_glyph:
 * @font: a font.
 * @unicode: 
 * @glyph: (out): 
 *
 * 
 *
 * Return value: 
 *
 * Since: 1.2.3
 **/
hb_bool_t
hb_font_get_nominal_glyph (hb_font_t *font,
			   hb_codepoint_t unicode,
			   hb_codepoint_t *glyph)
{
  return font->get_nominal_glyph (unicode, glyph);
}

/**
 * hb_font_get_variation_glyph:
 * @font: a font.
 * @unicode: 
 * @variation_selector: 
 * @glyph: (out): 
 *
 * 
 *
 * Return value: 
 *
 * Since: 1.2.3
 **/
hb_bool_t
hb_font_get_variation_glyph (hb_font_t *font,
			     hb_codepoint_t unicode, hb_codepoint_t variation_selector,
			     hb_codepoint_t *glyph)
{
  return font->get_variation_glyph (unicode, variation_selector, glyph);
682 683
}

684 685 686 687 688 689 690 691 692
/**
 * hb_font_get_glyph_h_advance:
 * @font: a font.
 * @glyph: 
 *
 * 
 *
 * Return value: 
 *
693
 * Since: 0.9.2
694
 **/
695
hb_position_t
696
hb_font_get_glyph_h_advance (hb_font_t *font,
697
			     hb_codepoint_t glyph)
698
{
B
Behdad Esfahbod 已提交
699
  return font->get_glyph_h_advance (glyph);
700 701
}

702 703 704 705 706 707 708 709 710
/**
 * hb_font_get_glyph_v_advance:
 * @font: a font.
 * @glyph: 
 *
 * 
 *
 * Return value: 
 *
711
 * Since: 0.9.2
712
 **/
713
hb_position_t
714
hb_font_get_glyph_v_advance (hb_font_t *font,
715
			     hb_codepoint_t glyph)
716
{
B
Behdad Esfahbod 已提交
717
  return font->get_glyph_v_advance (glyph);
718 719
}

720 721 722 723 724 725 726 727 728 729 730
/**
 * hb_font_get_glyph_h_origin:
 * @font: a font.
 * @glyph: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
 * Return value: 
 *
731
 * Since: 0.9.2
732
 **/
B
Behdad Esfahbod 已提交
733 734 735
hb_bool_t
hb_font_get_glyph_h_origin (hb_font_t *font,
			    hb_codepoint_t glyph,
B
Behdad Esfahbod 已提交
736
			    hb_position_t *x, hb_position_t *y)
B
Behdad Esfahbod 已提交
737
{
B
Behdad Esfahbod 已提交
738
  return font->get_glyph_h_origin (glyph, x, y);
B
Behdad Esfahbod 已提交
739 740
}

741 742 743 744 745 746 747 748 749 750 751
/**
 * hb_font_get_glyph_v_origin:
 * @font: a font.
 * @glyph: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
 * Return value: 
 *
752
 * Since: 0.9.2
753
 **/
754 755 756
hb_bool_t
hb_font_get_glyph_v_origin (hb_font_t *font,
			    hb_codepoint_t glyph,
B
Behdad Esfahbod 已提交
757
			    hb_position_t *x, hb_position_t *y)
758
{
B
Behdad Esfahbod 已提交
759
  return font->get_glyph_v_origin (glyph, x, y);
760 761
}

762 763 764 765 766 767 768 769 770 771
/**
 * hb_font_get_glyph_h_kerning:
 * @font: a font.
 * @left_glyph: 
 * @right_glyph: 
 *
 * 
 *
 * Return value: 
 *
772
 * Since: 0.9.2
773
 **/
774
hb_position_t
B
Behdad Esfahbod 已提交
775
hb_font_get_glyph_h_kerning (hb_font_t *font,
776
			     hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
777
{
B
Behdad Esfahbod 已提交
778
  return font->get_glyph_h_kerning (left_glyph, right_glyph);
779
}
B
Behdad Esfahbod 已提交
780

781 782 783 784 785 786 787 788 789 790
/**
 * hb_font_get_glyph_v_kerning:
 * @font: a font.
 * @top_glyph: 
 * @bottom_glyph: 
 *
 * 
 *
 * Return value: 
 *
791
 * Since: 0.9.2
792
 **/
793
hb_position_t
B
Behdad Esfahbod 已提交
794
hb_font_get_glyph_v_kerning (hb_font_t *font,
795
			     hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph)
796
{
797
  return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
798
}
B
Behdad Esfahbod 已提交
799

800 801 802 803 804 805 806 807 808 809
/**
 * hb_font_get_glyph_extents:
 * @font: a font.
 * @glyph: 
 * @extents: (out): 
 *
 * 
 *
 * Return value: 
 *
810
 * Since: 0.9.2
811
 **/
812 813 814 815 816
hb_bool_t
hb_font_get_glyph_extents (hb_font_t *font,
			   hb_codepoint_t glyph,
			   hb_glyph_extents_t *extents)
{
B
Behdad Esfahbod 已提交
817
  return font->get_glyph_extents (glyph, extents);
818
}
819

820 821 822 823 824 825 826 827 828 829 830 831
/**
 * hb_font_get_glyph_contour_point:
 * @font: a font.
 * @glyph: 
 * @point_index: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
 * Return value: 
 *
832
 * Since: 0.9.2
833
 **/
834
hb_bool_t
B
Behdad Esfahbod 已提交
835 836 837
hb_font_get_glyph_contour_point (hb_font_t *font,
				 hb_codepoint_t glyph, unsigned int point_index,
				 hb_position_t *x, hb_position_t *y)
B
Behdad Esfahbod 已提交
838
{
B
Behdad Esfahbod 已提交
839
  return font->get_glyph_contour_point (glyph, point_index, x, y);
B
Behdad Esfahbod 已提交
840 841
}

842 843 844 845 846 847 848 849 850 851 852
/**
 * hb_font_get_glyph_name:
 * @font: a font.
 * @glyph: 
 * @name: (array length=size): 
 * @size: 
 *
 * 
 *
 * Return value: 
 *
S
Sascha Brawer 已提交
853
 * Since: 0.9.2
854
 **/
855 856 857 858 859
hb_bool_t
hb_font_get_glyph_name (hb_font_t *font,
			hb_codepoint_t glyph,
			char *name, unsigned int size)
{
860
  return font->get_glyph_name (glyph, name, size);
861 862
}

863 864 865 866 867 868 869 870 871 872 873
/**
 * hb_font_get_glyph_from_name:
 * @font: a font.
 * @name: (array length=len): 
 * @len: 
 * @glyph: (out): 
 *
 * 
 *
 * Return value: 
 *
S
Sascha Brawer 已提交
874
 * Since: 0.9.2
875
 **/
876 877 878 879 880
hb_bool_t
hb_font_get_glyph_from_name (hb_font_t *font,
			     const char *name, int len, /* -1 means nul-terminated */
			     hb_codepoint_t *glyph)
{
B
Behdad Esfahbod 已提交
881
  return font->get_glyph_from_name (name, len, glyph);
882 883
}

884 885 886

/* A bit higher-level, and with fallback */

887 888 889 890 891 892 893 894
/**
 * hb_font_get_extents_for_direction:
 * @font: a font.
 * @direction:
 * @extents:
 *
 *
 *
B
Behdad Esfahbod 已提交
895
 * Since: 1.1.3
896 897 898 899 900 901 902 903
 **/
void
hb_font_get_extents_for_direction (hb_font_t *font,
				   hb_direction_t direction,
				   hb_font_extents_t *extents)
{
  return font->get_extents_for_direction (direction, extents);
}
904 905 906 907 908 909 910 911 912 913
/**
 * hb_font_get_glyph_advance_for_direction:
 * @font: a font.
 * @glyph: 
 * @direction: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
914
 * Since: 0.9.2
915
 **/
916
void
917 918 919
hb_font_get_glyph_advance_for_direction (hb_font_t *font,
					 hb_codepoint_t glyph,
					 hb_direction_t direction,
B
Behdad Esfahbod 已提交
920
					 hb_position_t *x, hb_position_t *y)
921
{
B
Behdad Esfahbod 已提交
922
  return font->get_glyph_advance_for_direction (glyph, direction, x, y);
923 924
}

925 926 927 928 929 930 931 932 933 934
/**
 * hb_font_get_glyph_origin_for_direction:
 * @font: a font.
 * @glyph: 
 * @direction: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
935
 * Since: 0.9.2
936
 **/
937
void
B
Behdad Esfahbod 已提交
938 939 940
hb_font_get_glyph_origin_for_direction (hb_font_t *font,
					hb_codepoint_t glyph,
					hb_direction_t direction,
B
Behdad Esfahbod 已提交
941
					hb_position_t *x, hb_position_t *y)
B
Behdad Esfahbod 已提交
942
{
B
Behdad Esfahbod 已提交
943
  return font->get_glyph_origin_for_direction (glyph, direction, x, y);
B
Behdad Esfahbod 已提交
944 945
}

946 947 948 949 950 951 952 953 954 955
/**
 * hb_font_add_glyph_origin_for_direction:
 * @font: a font.
 * @glyph: 
 * @direction: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
956
 * Since: 0.9.2
957
 **/
B
Behdad Esfahbod 已提交
958 959 960 961 962 963
void
hb_font_add_glyph_origin_for_direction (hb_font_t *font,
					hb_codepoint_t glyph,
					hb_direction_t direction,
					hb_position_t *x, hb_position_t *y)
{
B
Behdad Esfahbod 已提交
964
  return font->add_glyph_origin_for_direction (glyph, direction, x, y);
B
Behdad Esfahbod 已提交
965 966
}

967 968 969 970 971 972 973 974 975 976
/**
 * hb_font_subtract_glyph_origin_for_direction:
 * @font: a font.
 * @glyph: 
 * @direction: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
977
 * Since: 0.9.2
978
 **/
B
Behdad Esfahbod 已提交
979 980 981 982 983 984
void
hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
					     hb_codepoint_t glyph,
					     hb_direction_t direction,
					     hb_position_t *x, hb_position_t *y)
{
B
Behdad Esfahbod 已提交
985
  return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
B
Behdad Esfahbod 已提交
986 987
}

988 989 990 991 992 993 994 995 996 997 998
/**
 * hb_font_get_glyph_kerning_for_direction:
 * @font: a font.
 * @first_glyph: 
 * @second_glyph: 
 * @direction: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
999
 * Since: 0.9.2
1000
 **/
B
Behdad Esfahbod 已提交
1001 1002 1003 1004
void
hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
					 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
					 hb_direction_t direction,
B
Behdad Esfahbod 已提交
1005
					 hb_position_t *x, hb_position_t *y)
1006
{
B
Behdad Esfahbod 已提交
1007
  return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
1008 1009
}

1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
/**
 * hb_font_get_glyph_extents_for_origin:
 * @font: a font.
 * @glyph: 
 * @direction: 
 * @extents: (out): 
 *
 * 
 *
 * Return value: 
 *
1021
 * Since: 0.9.2
1022
 **/
1023 1024 1025 1026 1027
hb_bool_t
hb_font_get_glyph_extents_for_origin (hb_font_t *font,
				      hb_codepoint_t glyph,
				      hb_direction_t direction,
				      hb_glyph_extents_t *extents)
B
Behdad Esfahbod 已提交
1028
{
B
Behdad Esfahbod 已提交
1029
  return font->get_glyph_extents_for_origin (glyph, direction, extents);
B
Behdad Esfahbod 已提交
1030 1031
}

1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
/**
 * hb_font_get_glyph_contour_point_for_origin:
 * @font: a font.
 * @glyph: 
 * @point_index: 
 * @direction: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
 * Return value: 
 *
1045
 * Since: 0.9.2
1046
 **/
1047
hb_bool_t
1048 1049 1050 1051
hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
					    hb_codepoint_t glyph, unsigned int point_index,
					    hb_direction_t direction,
					    hb_position_t *x, hb_position_t *y)
B
Behdad Esfahbod 已提交
1052
{
B
Behdad Esfahbod 已提交
1053
  return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
B
Behdad Esfahbod 已提交
1054 1055
}

1056
/* Generates gidDDD if glyph has no name. */
1057 1058 1059 1060 1061 1062 1063 1064 1065
/**
 * hb_font_glyph_to_string:
 * @font: a font.
 * @glyph: 
 * @s: (array length=size): 
 * @size: 
 *
 * 
 *
S
Sascha Brawer 已提交
1066
 * Since: 0.9.2
1067
 **/
1068 1069 1070 1071 1072 1073 1074 1075 1076
void
hb_font_glyph_to_string (hb_font_t *font,
			 hb_codepoint_t glyph,
			 char *s, unsigned int size)
{
  font->glyph_to_string (glyph, s, size);
}

/* Parses gidDDD and uniUUUU strings automatically. */
1077 1078 1079
/**
 * hb_font_glyph_from_string:
 * @font: a font.
1080
 * @s: (array length=len) (element-type uint8_t): 
1081 1082 1083 1084 1085 1086 1087
 * @len: 
 * @glyph: (out): 
 *
 * 
 *
 * Return value: 
 *
S
Sascha Brawer 已提交
1088
 * Since: 0.9.2
1089
 **/
1090 1091 1092 1093 1094 1095 1096 1097
hb_bool_t
hb_font_glyph_from_string (hb_font_t *font,
			   const char *s, int len, /* -1 means nul-terminated */
			   hb_codepoint_t *glyph)
{
  return font->glyph_from_string (s, len, glyph);
}

1098

1099 1100 1101 1102
/*
 * hb_font_t
 */

1103
/**
1104
 * hb_font_create: (Xconstructor)
1105 1106 1107 1108 1109 1110
 * @face: a face.
 *
 * 
 *
 * Return value: (transfer full): 
 *
1111
 * Since: 0.9.2
1112
 **/
1113
hb_font_t *
1114
hb_font_create (hb_face_t *face)
1115 1116 1117
{
  hb_font_t *font;

1118
  if (unlikely (!face))
1119
    face = hb_face_get_empty ();
1120
  if (!(font = hb_object_create<hb_font_t> ()))
1121
    return hb_font_get_empty ();
1122

1123
  hb_face_make_immutable (face);
1124
  font->parent = hb_font_get_empty ();
1125
  font->face = hb_face_reference (face);
1126
  font->klass = hb_font_funcs_get_empty ();
B
Behdad Esfahbod 已提交
1127

B
Behdad Esfahbod 已提交
1128 1129
  font->x_scale = font->y_scale = hb_face_get_upem (face);

1130 1131 1132
  return font;
}

1133 1134 1135 1136 1137 1138 1139 1140
/**
 * hb_font_create_sub_font:
 * @parent: parent font.
 *
 * 
 *
 * Return value: (transfer full): 
 *
1141
 * Since: 0.9.2
1142
 **/
1143 1144 1145 1146
hb_font_t *
hb_font_create_sub_font (hb_font_t *parent)
{
  if (unlikely (!parent))
B
Behdad Esfahbod 已提交
1147
    parent = hb_font_get_empty ();
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159

  hb_font_t *font = hb_font_create (parent->face);

  if (unlikely (hb_object_is_inert (font)))
    return font;

  font->parent = hb_font_reference (parent);

  font->x_scale = parent->x_scale;
  font->y_scale = parent->y_scale;
  font->x_ppem = parent->x_ppem;
  font->y_ppem = parent->y_ppem;
1160
  font->ptem = parent->ptem;
1161

B
Behdad Esfahbod 已提交
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
  font->num_coords = parent->num_coords;
  if (!font->num_coords)
    font->coords = NULL;
  else
  {
    unsigned int size = parent->num_coords * sizeof (parent->coords[0]);
    font->coords = (int *) malloc (size);
    if (unlikely (!font->coords))
      font->num_coords = 0;
    else
      memcpy (font->coords, parent->coords, size);
  }
1174

1175 1176 1177
  return font;
}

1178 1179 1180 1181 1182 1183 1184
/**
 * hb_font_get_empty:
 *
 * 
 *
 * Return value: (transfer full)
 *
1185
 * Since: 0.9.2
1186
 **/
1187 1188 1189
hb_font_t *
hb_font_get_empty (void)
{
1190 1191 1192
  static const hb_font_t _hb_font_nil = {
    HB_OBJECT_HEADER_STATIC,

1193
    true, /* immutable */
1194 1195 1196 1197

    NULL, /* parent */
    const_cast<hb_face_t *> (&_hb_face_nil),

1198 1199
    1000, /* x_scale */
    1000, /* y_scale */
1200 1201 1202

    0, /* x_ppem */
    0, /* y_ppem */
1203
    0, /* ptem */
1204

1205
    0, /* num_coords */
1206
    NULL, /* coords */
1207

1208 1209
    const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
    NULL, /* user_data */
1210 1211 1212 1213 1214 1215 1216
    NULL, /* destroy */

    {
#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
#include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT
    }
1217 1218 1219
  };

  return const_cast<hb_font_t *> (&_hb_font_nil);
1220 1221
}

1222 1223 1224 1225 1226 1227 1228 1229
/**
 * hb_font_reference: (skip)
 * @font: a font.
 *
 * 
 *
 * Return value: (transfer full): 
 *
1230
 * Since: 0.9.2
1231
 **/
1232 1233 1234
hb_font_t *
hb_font_reference (hb_font_t *font)
{
1235
  return hb_object_reference (font);
1236 1237
}

1238 1239 1240 1241 1242 1243
/**
 * hb_font_destroy: (skip)
 * @font: a font.
 *
 * 
 *
1244
 * Since: 0.9.2
1245
 **/
1246 1247 1248
void
hb_font_destroy (hb_font_t *font)
{
1249
  if (!hb_object_destroy (font)) return;
1250

1251 1252 1253 1254 1255 1256 1257
#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font);
#include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT

  if (font->destroy)
    font->destroy (font->user_data);

1258
  hb_font_destroy (font->parent);
1259
  hb_face_destroy (font->face);
B
Behdad Esfahbod 已提交
1260
  hb_font_funcs_destroy (font->klass);
1261

B
Behdad Esfahbod 已提交
1262
  free (font->coords);
1263

1264 1265 1266
  free (font);
}

1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
/**
 * hb_font_set_user_data: (skip)
 * @font: a font.
 * @key: 
 * @data: 
 * @destroy: 
 * @replace: 
 *
 * 
 *
 * Return value: 
 *
1279
 * Since: 0.9.2
1280
 **/
1281 1282 1283 1284
hb_bool_t
hb_font_set_user_data (hb_font_t          *font,
		       hb_user_data_key_t *key,
		       void *              data,
1285 1286
		       hb_destroy_func_t   destroy,
		       hb_bool_t           replace)
1287
{
1288
  return hb_object_set_user_data (font, key, data, destroy, replace);
1289 1290
}

1291 1292 1293 1294 1295 1296 1297 1298 1299
/**
 * hb_font_get_user_data: (skip)
 * @font: a font.
 * @key: 
 *
 * 
 *
 * Return value: (transfer none): 
 *
1300
 * Since: 0.9.2
1301
 **/
1302 1303 1304 1305 1306 1307 1308
void *
hb_font_get_user_data (hb_font_t          *font,
		       hb_user_data_key_t *key)
{
  return hb_object_get_user_data (font, key);
}

1309 1310 1311 1312 1313 1314
/**
 * hb_font_make_immutable:
 * @font: a font.
 *
 * 
 *
1315
 * Since: 0.9.2
1316
 **/
1317 1318 1319
void
hb_font_make_immutable (hb_font_t *font)
{
1320
  if (unlikely (hb_object_is_inert (font)))
1321 1322
    return;

1323 1324 1325
  if (font->parent)
    hb_font_make_immutable (font->parent);

1326 1327 1328
  font->immutable = true;
}

1329 1330 1331 1332 1333 1334 1335 1336
/**
 * hb_font_is_immutable:
 * @font: a font.
 *
 * 
 *
 * Return value: 
 *
1337
 * Since: 0.9.2
1338
 **/
1339 1340 1341 1342 1343 1344
hb_bool_t
hb_font_is_immutable (hb_font_t *font)
{
  return font->immutable;
}

B
Behdad Esfahbod 已提交
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370
/**
 * hb_font_set_parent:
 * @font: a font.
 * @parent: new parent.
 *
 * Sets parent font of @font.
 *
 * Since: 1.0.5
 **/
void
hb_font_set_parent (hb_font_t *font,
		    hb_font_t *parent)
{
  if (font->immutable)
    return;

  if (!parent)
    parent = hb_font_get_empty ();

  hb_font_t *old = font->parent;

  font->parent = hb_font_reference (parent);

  hb_font_destroy (old);
}

1371 1372 1373 1374 1375 1376 1377 1378
/**
 * hb_font_get_parent:
 * @font: a font.
 *
 * 
 *
 * Return value: (transfer none): 
 *
1379
 * Since: 0.9.2
1380
 **/
1381 1382 1383 1384 1385
hb_font_t *
hb_font_get_parent (hb_font_t *font)
{
  return font->parent;
}
1386

B
Behdad Esfahbod 已提交
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412
/**
 * hb_font_set_face:
 * @font: a font.
 * @face: new face.
 *
 * Sets font-face of @font.
 *
 * Since: 1.4.3
 **/
void
hb_font_set_face (hb_font_t *font,
		  hb_face_t *face)
{
  if (font->immutable)
    return;

  if (unlikely (!face))
    face = hb_face_get_empty ();

  hb_face_t *old = font->face;

  font->face = hb_face_reference (face);

  hb_face_destroy (old);
}

1413 1414 1415 1416 1417 1418 1419 1420
/**
 * hb_font_get_face:
 * @font: a font.
 *
 * 
 *
 * Return value: (transfer none): 
 *
S
Sascha Brawer 已提交
1421
 * Since: 0.9.2
1422
 **/
1423 1424 1425 1426 1427 1428 1429
hb_face_t *
hb_font_get_face (hb_font_t *font)
{
  return font->face;
}


1430 1431 1432
/**
 * hb_font_set_funcs:
 * @font: a font.
1433
 * @klass: (closure font_data) (destroy destroy) (scope notified):
1434
 * @font_data: 
1435 1436 1437 1438
 * @destroy: 
 *
 * 
 *
S
Sascha Brawer 已提交
1439
 * Since: 0.9.2
1440
 **/
B
Behdad Esfahbod 已提交
1441
void
B
Behdad Esfahbod 已提交
1442 1443
hb_font_set_funcs (hb_font_t         *font,
		   hb_font_funcs_t   *klass,
1444
		   void              *font_data,
1445
		   hb_destroy_func_t  destroy)
1446
{
B
Behdad Esfahbod 已提交
1447 1448
  if (font->immutable) {
    if (destroy)
1449
      destroy (font_data);
B
Behdad Esfahbod 已提交
1450
    return;
B
Behdad Esfahbod 已提交
1451
  }
1452

B
Behdad Esfahbod 已提交
1453 1454 1455
  if (font->destroy)
    font->destroy (font->user_data);

B
Behdad Esfahbod 已提交
1456
  if (!klass)
1457
    klass = hb_font_funcs_get_empty ();
B
Behdad Esfahbod 已提交
1458

B
Behdad Esfahbod 已提交
1459 1460 1461
  hb_font_funcs_reference (klass);
  hb_font_funcs_destroy (font->klass);
  font->klass = klass;
1462
  font->user_data = font_data;
1463
  font->destroy = destroy;
1464 1465
}

1466 1467 1468
/**
 * hb_font_set_funcs_data:
 * @font: a font.
1469
 * @font_data: (destroy destroy) (scope notified):
1470 1471 1472 1473
 * @destroy: 
 *
 * 
 *
S
Sascha Brawer 已提交
1474
 * Since: 0.9.2
1475
 **/
1476 1477
void
hb_font_set_funcs_data (hb_font_t         *font,
1478
		        void              *font_data,
1479 1480
		        hb_destroy_func_t  destroy)
{
B
Behdad Esfahbod 已提交
1481 1482 1483
  /* Destroy user_data? */
  if (font->immutable) {
    if (destroy)
1484
      destroy (font_data);
1485
    return;
B
Behdad Esfahbod 已提交
1486
  }
1487 1488 1489 1490

  if (font->destroy)
    font->destroy (font->user_data);

1491
  font->user_data = font_data;
1492 1493 1494
  font->destroy = destroy;
}

B
Behdad Esfahbod 已提交
1495

1496 1497 1498 1499 1500 1501 1502 1503
/**
 * hb_font_set_scale:
 * @font: a font.
 * @x_scale: 
 * @y_scale: 
 *
 * 
 *
1504
 * Since: 0.9.2
1505
 **/
1506 1507
void
hb_font_set_scale (hb_font_t *font,
1508 1509
		   int x_scale,
		   int y_scale)
1510
{
1511
  if (font->immutable)
1512 1513 1514 1515 1516 1517
    return;

  font->x_scale = x_scale;
  font->y_scale = y_scale;
}

1518 1519 1520 1521 1522 1523 1524 1525
/**
 * hb_font_get_scale:
 * @font: a font.
 * @x_scale: (out): 
 * @y_scale: (out): 
 *
 * 
 *
1526
 * Since: 0.9.2
1527
 **/
B
Behdad Esfahbod 已提交
1528 1529
void
hb_font_get_scale (hb_font_t *font,
1530 1531
		   int *x_scale,
		   int *y_scale)
B
Behdad Esfahbod 已提交
1532 1533 1534 1535 1536
{
  if (x_scale) *x_scale = font->x_scale;
  if (y_scale) *y_scale = font->y_scale;
}

1537 1538 1539 1540 1541 1542 1543 1544
/**
 * hb_font_set_ppem:
 * @font: a font.
 * @x_ppem: 
 * @y_ppem: 
 *
 * 
 *
1545
 * Since: 0.9.2
1546
 **/
1547 1548 1549 1550 1551
void
hb_font_set_ppem (hb_font_t *font,
		  unsigned int x_ppem,
		  unsigned int y_ppem)
{
1552
  if (font->immutable)
1553 1554 1555 1556 1557 1558
    return;

  font->x_ppem = x_ppem;
  font->y_ppem = y_ppem;
}

1559 1560 1561 1562 1563 1564 1565 1566
/**
 * hb_font_get_ppem:
 * @font: a font.
 * @x_ppem: (out): 
 * @y_ppem: (out): 
 *
 * 
 *
1567
 * Since: 0.9.2
1568
 **/
B
Behdad Esfahbod 已提交
1569 1570 1571 1572 1573 1574 1575 1576
void
hb_font_get_ppem (hb_font_t *font,
		  unsigned int *x_ppem,
		  unsigned int *y_ppem)
{
  if (x_ppem) *x_ppem = font->x_ppem;
  if (y_ppem) *y_ppem = font->y_ppem;
}
1577

1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599
/**
 * hb_font_set_ptem:
 * @font: a font.
 * @ptem: 
 *
 * Sets "point size" of the font.
 *
 * Since: 1.6.0
 **/
void
hb_font_set_ptem (hb_font_t *font, float ptem)
{
  if (font->immutable)
    return;

  font->ptem = ptem;
}

/**
 * hb_font_get_ptem:
 * @font: a font.
 *
1600
 * Gets the "point size" of the font.  A value of 0 means unset.
1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611
 *
 * Return value: Point size.
 *
 * Since: 0.9.2
 **/
float
hb_font_get_ptem (hb_font_t *font)
{
  return font->ptem;
}

1612 1613 1614 1615
/*
 * Variations
 */

1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626
static void
_hb_font_adopt_var_coords_normalized (hb_font_t *font,
				      int *coords, /* 2.14 normalized */
				      unsigned int coords_length)
{
  free (font->coords);

  font->coords = coords;
  font->num_coords = coords_length;
}

1627 1628 1629 1630 1631
/**
 * hb_font_set_variations:
 *
 * Since: 1.4.2
 */
1632
void
1633 1634 1635
hb_font_set_variations (hb_font_t *font,
			const hb_variation_t *variations,
			unsigned int variations_length)
1636 1637 1638 1639
{
  if (font->immutable)
    return;

1640
  if (!variations_length)
1641 1642 1643 1644 1645
  {
    hb_font_set_var_coords_normalized (font, NULL, 0);
    return;
  }

1646
  unsigned int coords_length = hb_ot_var_get_axis_count (font->face);
1647

1648 1649
  int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : NULL;
  if (unlikely (coords_length && !normalized))
1650
    return;
1651

1652 1653 1654
  hb_ot_var_normalize_variations (font->face,
				  variations, variations_length,
				  normalized, coords_length);
1655
  _hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
1656 1657
}

1658 1659 1660 1661 1662
/**
 * hb_font_set_var_coords_design:
 *
 * Since: 1.4.2
 */
1663 1664
void
hb_font_set_var_coords_design (hb_font_t *font,
1665
			       const float *coords,
1666 1667
			       unsigned int coords_length)
{
1668 1669 1670
  if (font->immutable)
    return;

1671 1672 1673
  int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : NULL;
  if (unlikely (coords_length && !normalized))
    return;
1674

1675
  hb_ot_var_normalize_coords (font->face, coords_length, coords, normalized);
1676
  _hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
1677
}
1678

1679 1680 1681 1682 1683
/**
 * hb_font_set_var_coords_normalized:
 *
 * Since: 1.4.2
 */
1684 1685
void
hb_font_set_var_coords_normalized (hb_font_t *font,
1686
				   const int *coords, /* 2.14 normalized */
1687 1688 1689 1690 1691
				   unsigned int coords_length)
{
  if (font->immutable)
    return;

1692 1693
  int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : NULL;
  if (unlikely (coords_length && !copy))
1694 1695
    return;

1696 1697 1698
  if (coords_length)
    memcpy (copy, coords, coords_length * sizeof (coords[0]));

1699
  _hb_font_adopt_var_coords_normalized (font, copy, coords_length);
1700 1701
}

1702
/**
B
Behdad Esfahbod 已提交
1703
 * hb_font_get_var_coords_normalized:
1704
 *
B
Minor  
Behdad Esfahbod 已提交
1705 1706 1707
 * Return value is valid as long as variation coordinates of the font
 * are not modified.
 *
1708 1709
 * Since: 1.4.2
 */
B
Minor  
Behdad Esfahbod 已提交
1710
const int *
1711 1712 1713 1714
hb_font_get_var_coords_normalized (hb_font_t *font,
				   unsigned int *length)
{
  if (length)
1715
    *length = font->num_coords;
1716 1717 1718 1719

  return font->coords;
}

1720

1721 1722
#ifndef HB_DISABLE_DEPRECATED

1723 1724 1725 1726 1727 1728 1729 1730
/*
 * Deprecated get_glyph_func():
 */

struct hb_trampoline_closure_t
{
  void *user_data;
  hb_destroy_func_t destroy;
1731
  unsigned int ref_count;
1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755
};

template <typename FuncType>
struct hb_trampoline_t
{
  hb_trampoline_closure_t closure; /* Must be first. */
  FuncType func;
};

template <typename FuncType>
static hb_trampoline_t<FuncType> *
trampoline_create (FuncType           func,
		   void              *user_data,
		   hb_destroy_func_t  destroy)
{
  typedef hb_trampoline_t<FuncType> trampoline_t;

  trampoline_t *trampoline = (trampoline_t *) calloc (1, sizeof (trampoline_t));

  if (unlikely (!trampoline))
    return NULL;

  trampoline->closure.user_data = user_data;
  trampoline->closure.destroy = destroy;
1756
  trampoline->closure.ref_count = 1;
1757 1758 1759 1760 1761
  trampoline->func = func;

  return trampoline;
}

1762 1763 1764 1765 1766 1767
static void
trampoline_reference (hb_trampoline_closure_t *closure)
{
  closure->ref_count++;
}

1768 1769 1770 1771
static void
trampoline_destroy (void *user_data)
{
  hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
1772 1773 1774 1775

  if (--closure->ref_count)
    return;

1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826
  if (closure->destroy)
    closure->destroy (closure->user_data);
  free (closure);
}

typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;

static hb_bool_t
hb_font_get_nominal_glyph_trampoline (hb_font_t *font,
				      void *font_data,
				      hb_codepoint_t unicode,
				      hb_codepoint_t *glyph,
				      void *user_data)
{
  hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
  return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);
}

static hb_bool_t
hb_font_get_variation_glyph_trampoline (hb_font_t *font,
					void *font_data,
					hb_codepoint_t unicode,
					hb_codepoint_t variation_selector,
					hb_codepoint_t *glyph,
					void *user_data)
{
  hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
  return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data);
}

/**
 * hb_font_funcs_set_glyph_func:
 * @ffuncs: font functions.
 * @func: (closure user_data) (destroy destroy) (scope notified):
 * @user_data:
 * @destroy:
 *
 * Deprecated.  Use hb_font_funcs_set_nominal_glyph_func() and
 * hb_font_funcs_set_variation_glyph_func() instead.
 *
 * Since: 0.9.2
 * Deprecated: 1.2.3
 **/
void
hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
			      hb_font_get_glyph_func_t func,
			      void *user_data, hb_destroy_func_t destroy)
{
  hb_font_get_glyph_trampoline_t *trampoline;

  trampoline = trampoline_create (func, user_data, destroy);
1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841
  if (unlikely (!trampoline))
  {
    if (destroy)
      destroy (user_data);
    return;
  }

  hb_font_funcs_set_nominal_glyph_func (ffuncs,
					hb_font_get_nominal_glyph_trampoline,
					trampoline,
					trampoline_destroy);

  trampoline_reference (&trampoline->closure);
  hb_font_funcs_set_variation_glyph_func (ffuncs,
					  hb_font_get_variation_glyph_trampoline,
1842 1843 1844
					  trampoline,
					  trampoline_destroy);
}
1845 1846

#endif /* HB_DISABLE_DEPRECATED */