hb-font.cc 33.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 32
#include "hb-ot-layout-private.hh"

33
#include "hb-font-private.hh"
34
#include "hb-open-file-private.hh"
35
#include "hb-ot-head-table.hh"
B
Behdad Esfahbod 已提交
36
#include "hb-ot-maxp-table.hh"
37

B
Behdad Esfahbod 已提交
38 39
#include <string.h>

B
Behdad Esfahbod 已提交
40

41
/*
B
Behdad Esfahbod 已提交
42
 * hb_font_funcs_t
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 86 87 88 89 90 91 92
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;
}

93
static hb_bool_t
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
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)
120 121
{
  *glyph = 0;
122
  return false;
123
}
124
static hb_bool_t
125 126 127 128 129 130
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)
131
{
132
  return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
133
}
134

135

136
static hb_position_t
137
hb_font_get_glyph_h_advance_nil (hb_font_t *font HB_UNUSED,
138 139 140
				 void *font_data HB_UNUSED,
				 hb_codepoint_t glyph,
				 void *user_data HB_UNUSED)
141
{
142
  return font->x_scale;
143
}
144 145 146 147 148 149 150 151
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 已提交
152

153
static hb_position_t
154
hb_font_get_glyph_v_advance_nil (hb_font_t *font HB_UNUSED,
155 156 157
				 void *font_data HB_UNUSED,
				 hb_codepoint_t glyph,
				 void *user_data HB_UNUSED)
158
{
B
Behdad Esfahbod 已提交
159
  /* TODO use font_extents.ascender+descender */
160
  return font->y_scale;
161
}
162 163 164 165 166 167 168 169
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));
}
170

B
Behdad Esfahbod 已提交
171
static hb_bool_t
172
hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
B
Behdad Esfahbod 已提交
173 174
				void *font_data HB_UNUSED,
				hb_codepoint_t glyph,
B
Behdad Esfahbod 已提交
175 176
				hb_position_t *x,
				hb_position_t *y,
B
Behdad Esfahbod 已提交
177 178
				void *user_data HB_UNUSED)
{
B
Behdad Esfahbod 已提交
179
  *x = *y = 0;
180
  return true;
B
Behdad Esfahbod 已提交
181
}
182 183 184 185 186 187 188 189 190 191 192 193 194
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 已提交
195

196
static hb_bool_t
197
hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
198 199
				void *font_data HB_UNUSED,
				hb_codepoint_t glyph,
B
Behdad Esfahbod 已提交
200 201
				hb_position_t *x,
				hb_position_t *y,
202 203
				void *user_data HB_UNUSED)
{
B
Behdad Esfahbod 已提交
204
  *x = *y = 0;
205
  return false;
206
}
207 208 209 210 211 212 213 214 215 216 217 218 219
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;
}
220

221
static hb_position_t
222
hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
B
Behdad Esfahbod 已提交
223 224 225 226
				 void *font_data HB_UNUSED,
				 hb_codepoint_t left_glyph,
				 hb_codepoint_t right_glyph,
				 void *user_data HB_UNUSED)
227
{
228
  return 0;
229
}
230 231 232 233 234 235 236 237 238
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));
}
239

240
static hb_position_t
241
hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
B
Behdad Esfahbod 已提交
242 243 244 245
				 void *font_data HB_UNUSED,
				 hb_codepoint_t top_glyph,
				 hb_codepoint_t bottom_glyph,
				 void *user_data HB_UNUSED)
246
{
247
  return 0;
248
}
249 250 251 252 253 254 255 256 257
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 已提交
258

259
static hb_bool_t
260
hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
261
			       void *font_data HB_UNUSED,
262 263
			       hb_codepoint_t glyph,
			       hb_glyph_extents_t *extents,
264
			       void *user_data HB_UNUSED)
265
{
266
  memset (extents, 0, sizeof (*extents));
267
  return false;
268
}
269 270 271 272 273 274 275 276 277 278 279 280 281 282
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;
}
283

284
static hb_bool_t
285
hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,
B
Behdad Esfahbod 已提交
286 287 288 289 290 291
				     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)
292
{
293
  *x = *y = 0;
294
  return false;
295
}
296 297 298 299 300 301 302 303 304 305 306 307 308 309
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 已提交
310

311
static hb_bool_t
312
hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,
313 314 315 316 317
			    void *font_data HB_UNUSED,
			    hb_codepoint_t glyph,
			    char *name, unsigned int size,
			    void *user_data HB_UNUSED)
{
318
  if (size) *name = '\0';
319
  return false;
320
}
321 322 323 324 325 326 327 328 329
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);
}
330 331

static hb_bool_t
332
hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,
333 334 335 336 337 338
				 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;
339
  return false;
340
}
341 342 343 344 345 346 347 348 349
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);
}
350

351
static const hb_font_funcs_t _hb_font_funcs_nil = {
352 353
  HB_OBJECT_HEADER_STATIC,

354
  true, /* immutable */
355

356 357 358 359 360 361 362 363 364 365
  {
#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
  },
366
  {
367
    {
368
#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
369
      HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
370
#undef HB_FONT_FUNC_IMPLEMENT
371
    }
372
  }
373
};
374 375 376 377 378
static const hb_font_funcs_t _hb_font_funcs_parent = {
  HB_OBJECT_HEADER_STATIC,

  true, /* immutable */

379 380 381 382 383 384 385 386 387 388
  {
#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
  },
389
  {
390
    {
391
#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_parent,
392
      HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
393
#undef HB_FONT_FUNC_IMPLEMENT
394
    }
395 396
  }
};
397

B
Behdad Esfahbod 已提交
398

399
/**
400
 * hb_font_funcs_create: (Xconstructor)
401 402 403 404 405
 *
 * 
 *
 * Return value: (transfer full): 
 *
406
 * Since: 0.9.2
407
 **/
B
Behdad Esfahbod 已提交
408 409
hb_font_funcs_t *
hb_font_funcs_create (void)
410
{
B
Behdad Esfahbod 已提交
411
  hb_font_funcs_t *ffuncs;
412

413
  if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
414
    return hb_font_funcs_get_empty ();
415

416
  ffuncs->get = _hb_font_funcs_parent.get;
417

B
Behdad Esfahbod 已提交
418
  return ffuncs;
419 420
}

421 422 423 424 425 426 427
/**
 * hb_font_funcs_get_empty:
 *
 * 
 *
 * Return value: (transfer full): 
 *
428
 * Since: 0.9.2
429
 **/
430 431 432
hb_font_funcs_t *
hb_font_funcs_get_empty (void)
{
433
  return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_parent);
434 435
}

436 437 438 439 440 441 442 443
/**
 * hb_font_funcs_reference: (skip)
 * @ffuncs: font functions.
 *
 * 
 *
 * Return value: 
 *
444
 * Since: 0.9.2
445
 **/
B
Behdad Esfahbod 已提交
446 447
hb_font_funcs_t *
hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
448
{
449
  return hb_object_reference (ffuncs);
450 451
}

452 453 454 455 456 457
/**
 * hb_font_funcs_destroy: (skip)
 * @ffuncs: font functions.
 *
 * 
 *
458
 * Since: 0.9.2
459
 **/
460
void
B
Behdad Esfahbod 已提交
461
hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
462
{
463
  if (!hb_object_destroy (ffuncs)) return;
464

B
Behdad Esfahbod 已提交
465 466
#define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
  ffuncs->destroy.name (ffuncs->user_data.name);
467 468
  HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
#undef HB_FONT_FUNC_IMPLEMENT
469

B
Behdad Esfahbod 已提交
470
  free (ffuncs);
471 472
}

473 474 475 476 477 478 479 480 481 482 483 484
/**
 * hb_font_funcs_set_user_data: (skip)
 * @ffuncs: font functions.
 * @key: 
 * @data: 
 * @destroy: 
 * @replace: 
 *
 * 
 *
 * Return value: 
 *
485
 * Since: 0.9.2
486
 **/
487 488 489 490
hb_bool_t
hb_font_funcs_set_user_data (hb_font_funcs_t    *ffuncs,
			     hb_user_data_key_t *key,
			     void *              data,
491 492
			     hb_destroy_func_t   destroy,
			     hb_bool_t           replace)
493
{
494
  return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
495 496
}

497 498 499 500 501 502 503 504 505
/**
 * hb_font_funcs_get_user_data: (skip)
 * @ffuncs: font functions.
 * @key: 
 *
 * 
 *
 * Return value: (transfer none): 
 *
506
 * Since: 0.9.2
507
 **/
508 509 510 511 512 513 514 515
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);
}


516 517 518 519 520 521
/**
 * hb_font_funcs_make_immutable:
 * @ffuncs: font functions.
 *
 * 
 *
522
 * Since: 0.9.2
523
 **/
524 525 526
void
hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
{
527
  if (unlikely (hb_object_is_inert (ffuncs)))
528 529
    return;

530
  ffuncs->immutable = true;
B
Behdad Esfahbod 已提交
531 532
}

533 534 535 536 537 538 539 540
/**
 * hb_font_funcs_is_immutable:
 * @ffuncs: font functions.
 *
 * 
 *
 * Return value: 
 *
541
 * Since: 0.9.2
542
 **/
B
Behdad Esfahbod 已提交
543 544 545
hb_bool_t
hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
{
B
Behdad Esfahbod 已提交
546
  return ffuncs->immutable;
547 548
}

549

550
#define HB_FONT_FUNC_IMPLEMENT(name) \
551 552 553 554 555 556 557
                                                                         \
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 已提交
558 559 560
  if (ffuncs->immutable) {                                               \
    if (destroy)                                                         \
      destroy (user_data);                                               \
561
    return;                                                              \
B
Behdad Esfahbod 已提交
562
  }                                                                      \
563 564 565 566 567
                                                                         \
  if (ffuncs->destroy.name)                                              \
    ffuncs->destroy.name (ffuncs->user_data.name);                       \
                                                                         \
  if (func) {                                                            \
568
    ffuncs->get.f.name = func;                                           \
569 570 571
    ffuncs->user_data.name = user_data;                                  \
    ffuncs->destroy.name = destroy;                                      \
  } else {                                                               \
572
    ffuncs->get.f.name = hb_font_get_##name##_parent;                    \
573 574 575
    ffuncs->user_data.name = NULL;                                       \
    ffuncs->destroy.name = NULL;                                         \
  }                                                                      \
B
Behdad Esfahbod 已提交
576 577
}

578 579 580
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
#undef HB_FONT_FUNC_IMPLEMENT

581 582 583 584 585 586 587
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];
}
588

B
Behdad Esfahbod 已提交
589 590
/* Public getters */

591 592 593 594 595 596 597 598 599
/**
 * hb_font_get_h_extents:
 * @font: a font.
 * @extents: (out):
 *
 *
 *
 * Return value:
 *
B
Behdad Esfahbod 已提交
600
 * Since: 1.1.3
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
 **/
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 已提交
618
 * Since: 1.1.3
619 620 621 622 623 624 625 626
 **/
hb_bool_t
hb_font_get_v_extents (hb_font_t *font,
		       hb_font_extents_t *extents)
{
  return font->get_font_v_extents (extents);
}

627 628 629 630 631 632 633 634 635 636 637
/**
 * hb_font_get_glyph:
 * @font: a font.
 * @unicode: 
 * @variation_selector: 
 * @glyph: (out): 
 *
 * 
 *
 * Return value: 
 *
638
 * Since: 0.9.2
639
 **/
640 641 642 643 644
hb_bool_t
hb_font_get_glyph (hb_font_t *font,
		   hb_codepoint_t unicode, hb_codepoint_t variation_selector,
		   hb_codepoint_t *glyph)
{
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 682 683 684 685 686 687 688
  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);
689 690
}

691 692 693 694 695 696 697 698 699
/**
 * hb_font_get_glyph_h_advance:
 * @font: a font.
 * @glyph: 
 *
 * 
 *
 * Return value: 
 *
700
 * Since: 0.9.2
701
 **/
702
hb_position_t
703
hb_font_get_glyph_h_advance (hb_font_t *font,
704
			     hb_codepoint_t glyph)
705
{
B
Behdad Esfahbod 已提交
706
  return font->get_glyph_h_advance (glyph);
707 708
}

709 710 711 712 713 714 715 716 717
/**
 * hb_font_get_glyph_v_advance:
 * @font: a font.
 * @glyph: 
 *
 * 
 *
 * Return value: 
 *
718
 * Since: 0.9.2
719
 **/
720
hb_position_t
721
hb_font_get_glyph_v_advance (hb_font_t *font,
722
			     hb_codepoint_t glyph)
723
{
B
Behdad Esfahbod 已提交
724
  return font->get_glyph_v_advance (glyph);
725 726
}

727 728 729 730 731 732 733 734 735 736 737
/**
 * hb_font_get_glyph_h_origin:
 * @font: a font.
 * @glyph: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
 * Return value: 
 *
738
 * Since: 0.9.2
739
 **/
B
Behdad Esfahbod 已提交
740 741 742
hb_bool_t
hb_font_get_glyph_h_origin (hb_font_t *font,
			    hb_codepoint_t glyph,
B
Behdad Esfahbod 已提交
743
			    hb_position_t *x, hb_position_t *y)
B
Behdad Esfahbod 已提交
744
{
B
Behdad Esfahbod 已提交
745
  return font->get_glyph_h_origin (glyph, x, y);
B
Behdad Esfahbod 已提交
746 747
}

748 749 750 751 752 753 754 755 756 757 758
/**
 * hb_font_get_glyph_v_origin:
 * @font: a font.
 * @glyph: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
 * Return value: 
 *
759
 * Since: 0.9.2
760
 **/
761 762 763
hb_bool_t
hb_font_get_glyph_v_origin (hb_font_t *font,
			    hb_codepoint_t glyph,
B
Behdad Esfahbod 已提交
764
			    hb_position_t *x, hb_position_t *y)
765
{
B
Behdad Esfahbod 已提交
766
  return font->get_glyph_v_origin (glyph, x, y);
767 768
}

769 770 771 772 773 774 775 776 777 778
/**
 * hb_font_get_glyph_h_kerning:
 * @font: a font.
 * @left_glyph: 
 * @right_glyph: 
 *
 * 
 *
 * Return value: 
 *
779
 * Since: 0.9.2
780
 **/
781
hb_position_t
B
Behdad Esfahbod 已提交
782
hb_font_get_glyph_h_kerning (hb_font_t *font,
783
			     hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
784
{
B
Behdad Esfahbod 已提交
785
  return font->get_glyph_h_kerning (left_glyph, right_glyph);
786
}
B
Behdad Esfahbod 已提交
787

788 789 790 791 792 793 794 795 796 797
/**
 * hb_font_get_glyph_v_kerning:
 * @font: a font.
 * @top_glyph: 
 * @bottom_glyph: 
 *
 * 
 *
 * Return value: 
 *
798
 * Since: 0.9.2
799
 **/
800
hb_position_t
B
Behdad Esfahbod 已提交
801
hb_font_get_glyph_v_kerning (hb_font_t *font,
802
			     hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph)
803
{
804
  return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
805
}
B
Behdad Esfahbod 已提交
806

807 808 809 810 811 812 813 814 815 816
/**
 * hb_font_get_glyph_extents:
 * @font: a font.
 * @glyph: 
 * @extents: (out): 
 *
 * 
 *
 * Return value: 
 *
817
 * Since: 0.9.2
818
 **/
819 820 821 822 823
hb_bool_t
hb_font_get_glyph_extents (hb_font_t *font,
			   hb_codepoint_t glyph,
			   hb_glyph_extents_t *extents)
{
B
Behdad Esfahbod 已提交
824
  return font->get_glyph_extents (glyph, extents);
825
}
826

827 828 829 830 831 832 833 834 835 836 837 838
/**
 * hb_font_get_glyph_contour_point:
 * @font: a font.
 * @glyph: 
 * @point_index: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
 * Return value: 
 *
839
 * Since: 0.9.2
840
 **/
841
hb_bool_t
B
Behdad Esfahbod 已提交
842 843 844
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 已提交
845
{
B
Behdad Esfahbod 已提交
846
  return font->get_glyph_contour_point (glyph, point_index, x, y);
B
Behdad Esfahbod 已提交
847 848
}

849 850 851 852 853 854 855 856 857 858 859
/**
 * hb_font_get_glyph_name:
 * @font: a font.
 * @glyph: 
 * @name: (array length=size): 
 * @size: 
 *
 * 
 *
 * Return value: 
 *
S
Sascha Brawer 已提交
860
 * Since: 0.9.2
861
 **/
862 863 864 865 866
hb_bool_t
hb_font_get_glyph_name (hb_font_t *font,
			hb_codepoint_t glyph,
			char *name, unsigned int size)
{
867
  return font->get_glyph_name (glyph, name, size);
868 869
}

870 871 872 873 874 875 876 877 878 879 880
/**
 * hb_font_get_glyph_from_name:
 * @font: a font.
 * @name: (array length=len): 
 * @len: 
 * @glyph: (out): 
 *
 * 
 *
 * Return value: 
 *
S
Sascha Brawer 已提交
881
 * Since: 0.9.2
882
 **/
883 884 885 886 887
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 已提交
888
  return font->get_glyph_from_name (name, len, glyph);
889 890
}

891 892 893

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

894 895 896 897 898 899 900 901
/**
 * hb_font_get_extents_for_direction:
 * @font: a font.
 * @direction:
 * @extents:
 *
 *
 *
B
Behdad Esfahbod 已提交
902
 * Since: 1.1.3
903 904 905 906 907 908 909 910
 **/
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);
}
911 912 913 914 915 916 917 918 919 920
/**
 * hb_font_get_glyph_advance_for_direction:
 * @font: a font.
 * @glyph: 
 * @direction: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
921
 * Since: 0.9.2
922
 **/
923
void
924 925 926
hb_font_get_glyph_advance_for_direction (hb_font_t *font,
					 hb_codepoint_t glyph,
					 hb_direction_t direction,
B
Behdad Esfahbod 已提交
927
					 hb_position_t *x, hb_position_t *y)
928
{
B
Behdad Esfahbod 已提交
929
  return font->get_glyph_advance_for_direction (glyph, direction, x, y);
930 931
}

932 933 934 935 936 937 938 939 940 941
/**
 * hb_font_get_glyph_origin_for_direction:
 * @font: a font.
 * @glyph: 
 * @direction: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
942
 * Since: 0.9.2
943
 **/
944
void
B
Behdad Esfahbod 已提交
945 946 947
hb_font_get_glyph_origin_for_direction (hb_font_t *font,
					hb_codepoint_t glyph,
					hb_direction_t direction,
B
Behdad Esfahbod 已提交
948
					hb_position_t *x, hb_position_t *y)
B
Behdad Esfahbod 已提交
949
{
B
Behdad Esfahbod 已提交
950
  return font->get_glyph_origin_for_direction (glyph, direction, x, y);
B
Behdad Esfahbod 已提交
951 952
}

953 954 955 956 957 958 959 960 961 962
/**
 * hb_font_add_glyph_origin_for_direction:
 * @font: a font.
 * @glyph: 
 * @direction: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
963
 * Since: 0.9.2
964
 **/
B
Behdad Esfahbod 已提交
965 966 967 968 969 970
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 已提交
971
  return font->add_glyph_origin_for_direction (glyph, direction, x, y);
B
Behdad Esfahbod 已提交
972 973
}

974 975 976 977 978 979 980 981 982 983
/**
 * hb_font_subtract_glyph_origin_for_direction:
 * @font: a font.
 * @glyph: 
 * @direction: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
984
 * Since: 0.9.2
985
 **/
B
Behdad Esfahbod 已提交
986 987 988 989 990 991
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 已提交
992
  return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
B
Behdad Esfahbod 已提交
993 994
}

995 996 997 998 999 1000 1001 1002 1003 1004 1005
/**
 * hb_font_get_glyph_kerning_for_direction:
 * @font: a font.
 * @first_glyph: 
 * @second_glyph: 
 * @direction: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
1006
 * Since: 0.9.2
1007
 **/
B
Behdad Esfahbod 已提交
1008 1009 1010 1011
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 已提交
1012
					 hb_position_t *x, hb_position_t *y)
1013
{
B
Behdad Esfahbod 已提交
1014
  return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
1015 1016
}

1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
/**
 * hb_font_get_glyph_extents_for_origin:
 * @font: a font.
 * @glyph: 
 * @direction: 
 * @extents: (out): 
 *
 * 
 *
 * Return value: 
 *
1028
 * Since: 0.9.2
1029
 **/
1030 1031 1032 1033 1034
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 已提交
1035
{
B
Behdad Esfahbod 已提交
1036
  return font->get_glyph_extents_for_origin (glyph, direction, extents);
B
Behdad Esfahbod 已提交
1037 1038
}

1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
/**
 * hb_font_get_glyph_contour_point_for_origin:
 * @font: a font.
 * @glyph: 
 * @point_index: 
 * @direction: 
 * @x: (out): 
 * @y: (out): 
 *
 * 
 *
 * Return value: 
 *
1052
 * Since: 0.9.2
1053
 **/
1054
hb_bool_t
1055 1056 1057 1058
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 已提交
1059
{
B
Behdad Esfahbod 已提交
1060
  return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
B
Behdad Esfahbod 已提交
1061 1062
}

1063
/* Generates gidDDD if glyph has no name. */
1064 1065 1066 1067 1068 1069 1070 1071 1072
/**
 * hb_font_glyph_to_string:
 * @font: a font.
 * @glyph: 
 * @s: (array length=size): 
 * @size: 
 *
 * 
 *
S
Sascha Brawer 已提交
1073
 * Since: 0.9.2
1074
 **/
1075 1076 1077 1078 1079 1080 1081 1082 1083
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. */
1084 1085 1086
/**
 * hb_font_glyph_from_string:
 * @font: a font.
1087
 * @s: (array length=len) (element-type uint8_t): 
1088 1089 1090 1091 1092 1093 1094
 * @len: 
 * @glyph: (out): 
 *
 * 
 *
 * Return value: 
 *
S
Sascha Brawer 已提交
1095
 * Since: 0.9.2
1096
 **/
1097 1098 1099 1100 1101 1102 1103 1104
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);
}

1105

1106 1107 1108 1109
/*
 * hb_font_t
 */

1110
/**
1111
 * hb_font_create: (Xconstructor)
1112 1113 1114 1115 1116 1117
 * @face: a face.
 *
 * 
 *
 * Return value: (transfer full): 
 *
1118
 * Since: 0.9.2
1119
 **/
1120
hb_font_t *
1121
hb_font_create (hb_face_t *face)
1122 1123 1124
{
  hb_font_t *font;

1125
  if (unlikely (!face))
1126
    face = hb_face_get_empty ();
1127
  if (!(font = hb_object_create<hb_font_t> ()))
1128
    return hb_font_get_empty ();
1129

1130
  hb_face_make_immutable (face);
1131
  font->parent = hb_font_get_empty ();
1132
  font->face = hb_face_reference (face);
1133
  font->klass = hb_font_funcs_get_empty ();
B
Behdad Esfahbod 已提交
1134

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

1137 1138 1139
  return font;
}

1140 1141 1142 1143 1144 1145 1146 1147
/**
 * hb_font_create_sub_font:
 * @parent: parent font.
 *
 * 
 *
 * Return value: (transfer full): 
 *
1148
 * Since: 0.9.2
1149
 **/
1150 1151 1152 1153
hb_font_t *
hb_font_create_sub_font (hb_font_t *parent)
{
  if (unlikely (!parent))
B
Behdad Esfahbod 已提交
1154
    parent = hb_font_get_empty ();
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170

  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;

  return font;
}

1171 1172 1173 1174 1175 1176 1177
/**
 * hb_font_get_empty:
 *
 * 
 *
 * Return value: (transfer full)
 *
1178
 * Since: 0.9.2
1179
 **/
1180 1181 1182
hb_font_t *
hb_font_get_empty (void)
{
1183 1184 1185
  static const hb_font_t _hb_font_nil = {
    HB_OBJECT_HEADER_STATIC,

1186
    true, /* immutable */
1187 1188 1189 1190

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

1191 1192
    1000, /* x_scale */
    1000, /* y_scale */
1193 1194 1195 1196 1197 1198

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

    const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
    NULL, /* user_data */
1199 1200 1201 1202 1203 1204 1205
    NULL, /* destroy */

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

  return const_cast<hb_font_t *> (&_hb_font_nil);
1209 1210
}

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

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

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

1247
  hb_font_destroy (font->parent);
1248
  hb_face_destroy (font->face);
B
Behdad Esfahbod 已提交
1249
  hb_font_funcs_destroy (font->klass);
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
#ifndef HB_DISABLE_DEPRECATED

1542 1543 1544 1545 1546 1547 1548 1549
/*
 * Deprecated get_glyph_func():
 */

struct hb_trampoline_closure_t
{
  void *user_data;
  hb_destroy_func_t destroy;
1550
  unsigned int ref_count;
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574
};

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;
1575
  trampoline->closure.ref_count = 1;
1576 1577 1578 1579 1580
  trampoline->func = func;

  return trampoline;
}

1581 1582 1583 1584 1585 1586
static void
trampoline_reference (hb_trampoline_closure_t *closure)
{
  closure->ref_count++;
}

1587 1588 1589 1590
static void
trampoline_destroy (void *user_data)
{
  hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
1591 1592 1593 1594

  if (--closure->ref_count)
    return;

1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645
  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);
1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660
  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,
1661 1662 1663
					  trampoline,
					  trampoline_destroy);
}
1664 1665

#endif /* HB_DISABLE_DEPRECATED */