hb-font.cc 34.6 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 1160

  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;

1161 1162
  /* TODO: copy variation coordinates. */

1163 1164 1165
  return font;
}

1166 1167 1168 1169 1170 1171 1172
/**
 * hb_font_get_empty:
 *
 * 
 *
 * Return value: (transfer full)
 *
1173
 * Since: 0.9.2
1174
 **/
1175 1176 1177
hb_font_t *
hb_font_get_empty (void)
{
1178 1179 1180
  static const hb_font_t _hb_font_nil = {
    HB_OBJECT_HEADER_STATIC,

1181
    true, /* immutable */
1182 1183 1184 1185

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

1186 1187
    1000, /* x_scale */
    1000, /* y_scale */
1188 1189 1190 1191

    0, /* x_ppem */
    0, /* y_ppem */

1192
    0, /* num_coords */
1193
    NULL, /* coords */
1194

1195 1196
    const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
    NULL, /* user_data */
1197 1198 1199 1200 1201 1202 1203
    NULL, /* destroy */

    {
#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
#include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT
    }
1204 1205 1206
  };

  return const_cast<hb_font_t *> (&_hb_font_nil);
1207 1208
}

1209 1210 1211 1212 1213 1214 1215 1216
/**
 * hb_font_reference: (skip)
 * @font: a font.
 *
 * 
 *
 * Return value: (transfer full): 
 *
1217
 * Since: 0.9.2
1218
 **/
1219 1220 1221
hb_font_t *
hb_font_reference (hb_font_t *font)
{
1222
  return hb_object_reference (font);
1223 1224
}

1225 1226 1227 1228 1229 1230
/**
 * hb_font_destroy: (skip)
 * @font: a font.
 *
 * 
 *
1231
 * Since: 0.9.2
1232
 **/
1233 1234 1235
void
hb_font_destroy (hb_font_t *font)
{
1236
  if (!hb_object_destroy (font)) return;
1237

1238 1239 1240 1241 1242 1243 1244
#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);

1245
  hb_font_destroy (font->parent);
1246
  hb_face_destroy (font->face);
B
Behdad Esfahbod 已提交
1247
  hb_font_funcs_destroy (font->klass);
1248

B
Behdad Esfahbod 已提交
1249
  free (font->coords);
1250

1251 1252 1253
  free (font);
}

1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
/**
 * hb_font_set_user_data: (skip)
 * @font: a font.
 * @key: 
 * @data: 
 * @destroy: 
 * @replace: 
 *
 * 
 *
 * Return value: 
 *
1266
 * Since: 0.9.2
1267
 **/
1268 1269 1270 1271
hb_bool_t
hb_font_set_user_data (hb_font_t          *font,
		       hb_user_data_key_t *key,
		       void *              data,
1272 1273
		       hb_destroy_func_t   destroy,
		       hb_bool_t           replace)
1274
{
1275
  return hb_object_set_user_data (font, key, data, destroy, replace);
1276 1277
}

1278 1279 1280 1281 1282 1283 1284 1285 1286
/**
 * hb_font_get_user_data: (skip)
 * @font: a font.
 * @key: 
 *
 * 
 *
 * Return value: (transfer none): 
 *
1287
 * Since: 0.9.2
1288
 **/
1289 1290 1291 1292 1293 1294 1295
void *
hb_font_get_user_data (hb_font_t          *font,
		       hb_user_data_key_t *key)
{
  return hb_object_get_user_data (font, key);
}

1296 1297 1298 1299 1300 1301
/**
 * hb_font_make_immutable:
 * @font: a font.
 *
 * 
 *
1302
 * Since: 0.9.2
1303
 **/
1304 1305 1306
void
hb_font_make_immutable (hb_font_t *font)
{
1307
  if (unlikely (hb_object_is_inert (font)))
1308 1309
    return;

1310 1311 1312
  if (font->parent)
    hb_font_make_immutable (font->parent);

1313 1314 1315
  font->immutable = true;
}

1316 1317 1318 1319 1320 1321 1322 1323
/**
 * hb_font_is_immutable:
 * @font: a font.
 *
 * 
 *
 * Return value: 
 *
1324
 * Since: 0.9.2
1325
 **/
1326 1327 1328 1329 1330 1331
hb_bool_t
hb_font_is_immutable (hb_font_t *font)
{
  return font->immutable;
}

B
Behdad Esfahbod 已提交
1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357
/**
 * 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);
}

1358 1359 1360 1361 1362 1363 1364 1365
/**
 * hb_font_get_parent:
 * @font: a font.
 *
 * 
 *
 * Return value: (transfer none): 
 *
1366
 * Since: 0.9.2
1367
 **/
1368 1369 1370 1371 1372
hb_font_t *
hb_font_get_parent (hb_font_t *font)
{
  return font->parent;
}
1373

1374 1375 1376 1377 1378 1379 1380 1381
/**
 * hb_font_get_face:
 * @font: a font.
 *
 * 
 *
 * Return value: (transfer none): 
 *
S
Sascha Brawer 已提交
1382
 * Since: 0.9.2
1383
 **/
1384 1385 1386 1387 1388 1389 1390
hb_face_t *
hb_font_get_face (hb_font_t *font)
{
  return font->face;
}


1391 1392 1393
/**
 * hb_font_set_funcs:
 * @font: a font.
1394
 * @klass: (closure font_data) (destroy destroy) (scope notified):
1395
 * @font_data: 
1396 1397 1398 1399
 * @destroy: 
 *
 * 
 *
S
Sascha Brawer 已提交
1400
 * Since: 0.9.2
1401
 **/
B
Behdad Esfahbod 已提交
1402
void
B
Behdad Esfahbod 已提交
1403 1404
hb_font_set_funcs (hb_font_t         *font,
		   hb_font_funcs_t   *klass,
1405
		   void              *font_data,
1406
		   hb_destroy_func_t  destroy)
1407
{
B
Behdad Esfahbod 已提交
1408 1409
  if (font->immutable) {
    if (destroy)
1410
      destroy (font_data);
B
Behdad Esfahbod 已提交
1411
    return;
B
Behdad Esfahbod 已提交
1412
  }
1413

B
Behdad Esfahbod 已提交
1414 1415 1416
  if (font->destroy)
    font->destroy (font->user_data);

B
Behdad Esfahbod 已提交
1417
  if (!klass)
1418
    klass = hb_font_funcs_get_empty ();
B
Behdad Esfahbod 已提交
1419

B
Behdad Esfahbod 已提交
1420 1421 1422
  hb_font_funcs_reference (klass);
  hb_font_funcs_destroy (font->klass);
  font->klass = klass;
1423
  font->user_data = font_data;
1424
  font->destroy = destroy;
1425 1426
}

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

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

1452
  font->user_data = font_data;
1453 1454 1455
  font->destroy = destroy;
}

B
Behdad Esfahbod 已提交
1456

1457 1458 1459 1460 1461 1462 1463 1464
/**
 * hb_font_set_scale:
 * @font: a font.
 * @x_scale: 
 * @y_scale: 
 *
 * 
 *
1465
 * Since: 0.9.2
1466
 **/
1467 1468
void
hb_font_set_scale (hb_font_t *font,
1469 1470
		   int x_scale,
		   int y_scale)
1471
{
1472
  if (font->immutable)
1473 1474 1475 1476 1477 1478
    return;

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

1479 1480 1481 1482 1483 1484 1485 1486
/**
 * hb_font_get_scale:
 * @font: a font.
 * @x_scale: (out): 
 * @y_scale: (out): 
 *
 * 
 *
1487
 * Since: 0.9.2
1488
 **/
B
Behdad Esfahbod 已提交
1489 1490
void
hb_font_get_scale (hb_font_t *font,
1491 1492
		   int *x_scale,
		   int *y_scale)
B
Behdad Esfahbod 已提交
1493 1494 1495 1496 1497
{
  if (x_scale) *x_scale = font->x_scale;
  if (y_scale) *y_scale = font->y_scale;
}

1498 1499 1500 1501 1502 1503 1504 1505
/**
 * hb_font_set_ppem:
 * @font: a font.
 * @x_ppem: 
 * @y_ppem: 
 *
 * 
 *
1506
 * Since: 0.9.2
1507
 **/
1508 1509 1510 1511 1512
void
hb_font_set_ppem (hb_font_t *font,
		  unsigned int x_ppem,
		  unsigned int y_ppem)
{
1513
  if (font->immutable)
1514 1515 1516 1517 1518 1519
    return;

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

1520 1521 1522 1523 1524 1525 1526 1527
/**
 * hb_font_get_ppem:
 * @font: a font.
 * @x_ppem: (out): 
 * @y_ppem: (out): 
 *
 * 
 *
1528
 * Since: 0.9.2
1529
 **/
B
Behdad Esfahbod 已提交
1530 1531 1532 1533 1534 1535 1536 1537
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;
}
1538

1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
/*
 * Variations
 */

void
hb_font_set_var_coords_design (hb_font_t *font,
			       float *coords,
			       unsigned int coords_length)
{
  int normalized[coords_length]; // XXX Remove variable-length array use...

  hb_face_t *face = font->face;
  for (unsigned int i = 0; i < coords_length; i++)
    normalized[i] = hb_ot_var_normalize_axis_value (face, i, coords[i]);

  hb_font_set_var_coords_normalized (font, normalized, coords_length);
}
1556

1557 1558
void
hb_font_set_var_coords_normalized (hb_font_t *font,
1559
				   int *coords, /* 2.14 normalized */
1560 1561 1562 1563 1564
				   unsigned int coords_length)
{
  if (font->immutable)
    return;

1565 1566
  int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : NULL;
  if (unlikely (coords_length && !copy))
1567 1568
    return;

1569 1570 1571
  if (coords_length)
    memcpy (copy, coords, coords_length * sizeof (coords[0]));

1572 1573
  free (font->coords);

1574
  font->coords = copy;
1575 1576 1577
  font->num_coords = coords_length;
}

1578 1579 1580 1581 1582
int *
hb_font_get_var_coords_normalized (hb_font_t *font,
				   unsigned int *length)
{
  if (length)
1583
    *length = font->num_coords;
1584 1585 1586 1587

  return font->coords;
}

1588

1589 1590
#ifndef HB_DISABLE_DEPRECATED

1591 1592 1593 1594 1595 1596 1597 1598
/*
 * Deprecated get_glyph_func():
 */

struct hb_trampoline_closure_t
{
  void *user_data;
  hb_destroy_func_t destroy;
1599
  unsigned int ref_count;
1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623
};

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;
1624
  trampoline->closure.ref_count = 1;
1625 1626 1627 1628 1629
  trampoline->func = func;

  return trampoline;
}

1630 1631 1632 1633 1634 1635
static void
trampoline_reference (hb_trampoline_closure_t *closure)
{
  closure->ref_count++;
}

1636 1637 1638 1639
static void
trampoline_destroy (void *user_data)
{
  hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
1640 1641 1642 1643

  if (--closure->ref_count)
    return;

1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694
  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);
1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709
  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,
1710 1711 1712
					  trampoline,
					  trampoline_destroy);
}
1713 1714

#endif /* HB_DISABLE_DEPRECATED */