hb-shape-plan.cc 15.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * Copyright © 2012  Google, Inc.
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * 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.
 *
 * Google Author(s): Behdad Esfahbod
 */

27 28 29 30 31
#include "hb.hh"
#include "hb-shape-plan.hh"
#include "hb-shaper.hh"
#include "hb-font.hh"
#include "hb-buffer.hh"
32

B
Behdad Esfahbod 已提交
33

B
Behdad Esfahbod 已提交
34 35
/**
 * SECTION:hb-shape-plan
36
 * @title: hb_shape_plan_t
B
Behdad Esfahbod 已提交
37 38 39 40 41 42 43 44 45 46
 * @short_description: Object representing a shaping plan
 * @include: hb.h
 *
 * Shape plans are not used for shaping directly, but can be access to query
 * certain information about how shaping will perform given a set of input
 * parameters (script, language, direction, features, etc.)
 * Most client would not need to deal with shape plans directly.
 **/


B
Behdad Esfahbod 已提交
47
static void
B
Behdad Esfahbod 已提交
48 49 50
hb_shape_plan_plan (hb_shape_plan_t    *shape_plan,
		    const hb_feature_t *user_features,
		    unsigned int        num_user_features,
B
Behdad Esfahbod 已提交
51 52
		    const int          *coords,
		    unsigned int        num_coords,
B
Behdad Esfahbod 已提交
53 54
		    const char * const *shaper_list)
{
B
Behdad Esfahbod 已提交
55
  DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan,
B
Behdad Esfahbod 已提交
56
		  "num_features=%d num_coords=%d shaper_list=%p",
B
Behdad Esfahbod 已提交
57
		  num_user_features,
B
Behdad Esfahbod 已提交
58
		  num_coords,
B
Behdad Esfahbod 已提交
59 60
		  shaper_list);

B
Behdad Esfahbod 已提交
61 62 63 64
  const hb_shaper_pair_t *shapers = _hb_shapers_get ();

#define HB_SHAPER_PLAN(shaper) \
	HB_STMT_START { \
65 66 67 68
	  if (hb_##shaper##_shaper_face_data_ensure (shape_plan->face_unsafe)) \
	  { \
	    /* XXX-MT-bug What happened to *ensure*ing this?!!!! */ \
	    HB_SHAPER_DATA (shaper, shape_plan).set_relaxed ( \
B
Behdad Esfahbod 已提交
69 70
	      HB_SHAPER_DATA_CREATE_FUNC (shaper, shape_plan) (shape_plan, \
							       user_features, num_user_features, \
71
							       coords, num_coords)); \
72
	    shape_plan->shaper_func = _hb_##shaper##_shape; \
73
	    shape_plan->shaper_name = #shaper; \
74
	    return; \
B
Behdad Esfahbod 已提交
75 76 77 78 79
	  } \
	} HB_STMT_END

  if (likely (!shaper_list)) {
    for (unsigned int i = 0; i < HB_SHAPERS_COUNT; i++)
80
      if (false)
B
Behdad Esfahbod 已提交
81 82 83 84 85 86 87 88
	;
#define HB_SHAPER_IMPLEMENT(shaper) \
      else if (shapers[i].func == _hb_##shaper##_shape) \
	HB_SHAPER_PLAN (shaper);
#include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT
  } else {
    for (; *shaper_list; shaper_list++)
89
      if (false)
B
Behdad Esfahbod 已提交
90 91 92 93 94 95 96 97 98 99 100
	;
#define HB_SHAPER_IMPLEMENT(shaper) \
      else if (0 == strcmp (*shaper_list, #shaper)) \
	HB_SHAPER_PLAN (shaper);
#include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT
  }

#undef HB_SHAPER_PLAN
}

101 102 103 104 105

/*
 * hb_shape_plan_t
 */

106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
DEFINE_NULL_INSTANCE (hb_shape_plan_t) =
{
  HB_OBJECT_HEADER_STATIC,

  true, /* default_shaper_list */
  nullptr, /* face */
  HB_SEGMENT_PROPERTIES_DEFAULT, /* props */

  nullptr, /* shaper_func */
  nullptr, /* shaper_name */

  nullptr, /* user_features */
  0,    /* num_user_featurs */

  nullptr, /* coords */
  0,    /* num_coords */

  {
124
#define HB_SHAPER_IMPLEMENT(shaper) HB_ATOMIC_PTR_INIT (HB_SHAPER_DATA_INVALID),
125 126
#include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT
127
  },
128 129 130
};


131
/**
132
 * hb_shape_plan_create: (Xconstructor)
133 134 135 136 137 138 139 140 141 142
 * @face: 
 * @props: 
 * @user_features: (array length=num_user_features):
 * @num_user_features: 
 * @shaper_list: (array zero-terminated=1):
 *
 * 
 *
 * Return value: (transfer full):
 *
S
Sascha Brawer 已提交
143
 * Since: 0.9.7
144
 **/
145 146 147 148 149 150
hb_shape_plan_t *
hb_shape_plan_create (hb_face_t                     *face,
		      const hb_segment_properties_t *props,
		      const hb_feature_t            *user_features,
		      unsigned int                   num_user_features,
		      const char * const            *shaper_list)
B
Behdad Esfahbod 已提交
151 152 153
{
  return hb_shape_plan_create2 (face, props,
				user_features, num_user_features,
B
Behdad Esfahbod 已提交
154
				nullptr, 0,
B
Behdad Esfahbod 已提交
155 156 157 158 159 160 161 162 163 164 165
				shaper_list);
}

hb_shape_plan_t *
hb_shape_plan_create2 (hb_face_t                     *face,
		       const hb_segment_properties_t *props,
		       const hb_feature_t            *user_features,
		       unsigned int                   num_user_features,
		       const int                     *orig_coords,
		       unsigned int                   num_coords,
		       const char * const            *shaper_list)
166
{
B
Behdad Esfahbod 已提交
167
  DEBUG_MSG_FUNC (SHAPE_PLAN, nullptr,
B
Behdad Esfahbod 已提交
168
		  "face=%p num_features=%d num_coords=%d shaper_list=%p",
169
		  face,
B
Behdad Esfahbod 已提交
170
		  num_user_features,
B
Behdad Esfahbod 已提交
171
		  num_coords,
B
Behdad Esfahbod 已提交
172 173
		  shaper_list);

174
  hb_shape_plan_t *shape_plan;
B
Behdad Esfahbod 已提交
175 176
  hb_feature_t *features = nullptr;
  int *coords = nullptr;
177 178 179

  if (unlikely (!face))
    face = hb_face_get_empty ();
B
Behdad Esfahbod 已提交
180
  if (unlikely (!props))
181
    return hb_shape_plan_get_empty ();
182
  if (num_user_features && !(features = (hb_feature_t *) calloc (num_user_features, sizeof (hb_feature_t))))
183
    return hb_shape_plan_get_empty ();
B
Behdad Esfahbod 已提交
184 185 186 187 188 189 190 191
  if (num_coords && !(coords = (int *) calloc (num_coords, sizeof (int))))
  {
    free (features);
    return hb_shape_plan_get_empty ();
  }
  if (!(shape_plan = hb_object_create<hb_shape_plan_t> ()))
  {
    free (coords);
192 193 194
    free (features);
    return hb_shape_plan_get_empty ();
  }
195

B
Behdad Esfahbod 已提交
196 197
  assert (props->direction != HB_DIRECTION_INVALID);

198
  hb_face_make_immutable (face);
199
  shape_plan->default_shaper_list = !shaper_list;
200
  shape_plan->face_unsafe = face;
B
Behdad Esfahbod 已提交
201
  shape_plan->props = *props;
202 203 204 205
  shape_plan->num_user_features = num_user_features;
  shape_plan->user_features = features;
  if (num_user_features)
    memcpy (features, user_features, num_user_features * sizeof (hb_feature_t));
B
Behdad Esfahbod 已提交
206 207 208 209
  shape_plan->num_coords = num_coords;
  shape_plan->coords = coords;
  if (num_coords)
    memcpy (coords, orig_coords, num_coords * sizeof (int));
210

B
Behdad Esfahbod 已提交
211 212 213 214
  hb_shape_plan_plan (shape_plan,
		      user_features, num_user_features,
		      coords, num_coords,
		      shaper_list);
B
Minor  
Behdad Esfahbod 已提交
215

216 217 218
  return shape_plan;
}

219 220 221 222 223 224 225
/**
 * hb_shape_plan_get_empty:
 *
 * 
 *
 * Return value: (transfer full):
 *
S
Sascha Brawer 已提交
226
 * Since: 0.9.7
227
 **/
228 229 230
hb_shape_plan_t *
hb_shape_plan_get_empty (void)
{
231
  return const_cast<hb_shape_plan_t *> (&Null(hb_shape_plan_t));
232 233
}

234 235 236 237 238 239 240 241
/**
 * hb_shape_plan_reference: (skip)
 * @shape_plan: a shape plan.
 *
 * 
 *
 * Return value: (transfer full):
 *
S
Sascha Brawer 已提交
242
 * Since: 0.9.7
243
 **/
244 245 246 247 248 249
hb_shape_plan_t *
hb_shape_plan_reference (hb_shape_plan_t *shape_plan)
{
  return hb_object_reference (shape_plan);
}

250 251 252 253 254 255
/**
 * hb_shape_plan_destroy: (skip)
 * @shape_plan: a shape plan.
 *
 * 
 *
S
Sascha Brawer 已提交
256
 * Since: 0.9.7
257
 **/
258 259 260 261 262 263 264 265 266
void
hb_shape_plan_destroy (hb_shape_plan_t *shape_plan)
{
  if (!hb_object_destroy (shape_plan)) return;

#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, shape_plan);
#include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT

267
  free (shape_plan->user_features);
B
Behdad Esfahbod 已提交
268
  free (shape_plan->coords);
B
Behdad Esfahbod 已提交
269

270 271
  free (shape_plan);
}
B
Behdad Esfahbod 已提交
272

273 274 275 276 277 278 279 280 281 282 283 284
/**
 * hb_shape_plan_set_user_data: (skip)
 * @shape_plan: a shape plan.
 * @key: 
 * @data: 
 * @destroy: 
 * @replace: 
 *
 * 
 *
 * Return value: 
 *
S
Sascha Brawer 已提交
285
 * Since: 0.9.7
286
 **/
287 288 289 290 291 292 293 294 295 296
hb_bool_t
hb_shape_plan_set_user_data (hb_shape_plan_t    *shape_plan,
			     hb_user_data_key_t *key,
			     void *              data,
			     hb_destroy_func_t   destroy,
			     hb_bool_t           replace)
{
  return hb_object_set_user_data (shape_plan, key, data, destroy, replace);
}

297 298 299 300 301 302 303 304 305
/**
 * hb_shape_plan_get_user_data: (skip)
 * @shape_plan: a shape plan.
 * @key: 
 *
 * 
 *
 * Return value: (transfer none):
 *
S
Sascha Brawer 已提交
306
 * Since: 0.9.7
307
 **/
308 309 310 311 312 313 314
void *
hb_shape_plan_get_user_data (hb_shape_plan_t    *shape_plan,
			     hb_user_data_key_t *key)
{
  return hb_object_get_user_data (shape_plan, key);
}

B
Behdad Esfahbod 已提交
315

316 317 318 319 320 321 322 323 324 325 326 327
/**
 * hb_shape_plan_execute:
 * @shape_plan: a shape plan.
 * @font: a font.
 * @buffer: a buffer.
 * @features: (array length=num_features):
 * @num_features: 
 *
 * 
 *
 * Return value: 
 *
S
Sascha Brawer 已提交
328
 * Since: 0.9.7
329
 **/
B
Behdad Esfahbod 已提交
330
hb_bool_t
331
hb_shape_plan_execute (hb_shape_plan_t    *shape_plan,
B
Behdad Esfahbod 已提交
332 333 334 335 336
		       hb_font_t          *font,
		       hb_buffer_t        *buffer,
		       const hb_feature_t *features,
		       unsigned int        num_features)
{
B
Behdad Esfahbod 已提交
337
  DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan,
338
		  "num_features=%d shaper_func=%p, shaper_name=%s",
B
Behdad Esfahbod 已提交
339
		  num_features,
340 341
		  shape_plan->shaper_func,
		  shape_plan->shaper_name);
B
Behdad Esfahbod 已提交
342

343 344 345 346 347 348 349
  if (unlikely (!buffer->len))
    return true;

  assert (!hb_object_is_inert (buffer));
  assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE);

  if (unlikely (hb_object_is_inert (shape_plan)))
B
Behdad Esfahbod 已提交
350 351
    return false;

352
  assert (shape_plan->face_unsafe == font->face);
353 354
  assert (hb_segment_properties_equal (&shape_plan->props, &buffer->props));

B
Behdad Esfahbod 已提交
355 356
#define HB_SHAPER_EXECUTE(shaper) \
	HB_STMT_START { \
357
	  return HB_SHAPER_DATA (shaper, shape_plan).get () && \
358 359
		 hb_##shaper##_shaper_font_data_ensure (font) && \
		 _hb_##shaper##_shape (shape_plan, font, buffer, features, num_features); \
B
Behdad Esfahbod 已提交
360 361
	} HB_STMT_END

362
  if (false)
B
Behdad Esfahbod 已提交
363
    ;
B
Behdad Esfahbod 已提交
364
#define HB_SHAPER_IMPLEMENT(shaper) \
B
Behdad Esfahbod 已提交
365 366
  else if (shape_plan->shaper_func == _hb_##shaper##_shape) \
    HB_SHAPER_EXECUTE (shaper);
B
Behdad Esfahbod 已提交
367 368 369 370 371 372 373
#include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT

#undef HB_SHAPER_EXECUTE

  return false;
}
B
Behdad Esfahbod 已提交
374 375 376 377 378 379 380


/*
 * caching
 */

#if 0
B
Behdad Esfahbod 已提交
381
static unsigned int
B
Behdad Esfahbod 已提交
382 383 384
hb_shape_plan_hash (const hb_shape_plan_t *shape_plan)
{
  return hb_segment_properties_hash (&shape_plan->props) +
B
Behdad Esfahbod 已提交
385
	 shape_plan->default_shaper_list ? 0 : (intptr_t) shape_plan->shaper_func;
B
Behdad Esfahbod 已提交
386 387 388
}
#endif

389 390 391 392 393
/* User-feature caching is currently somewhat dumb:
 * it only finds matches where the feature array is identical,
 * not cases where the feature lists would be compatible for plan purposes
 * but have different ranges, for example.
 */
B
Behdad Esfahbod 已提交
394 395 396 397
struct hb_shape_plan_proposal_t
{
  const hb_segment_properties_t  props;
  const char * const            *shaper_list;
398 399
  const hb_feature_t            *user_features;
  unsigned int                   num_user_features;
B
Behdad Esfahbod 已提交
400 401
  const int                     *coords;
  unsigned int                   num_coords;
B
Behdad Esfahbod 已提交
402 403 404
  hb_shape_func_t               *shaper_func;
};

405 406 407 408
static inline hb_bool_t
hb_shape_plan_user_features_match (const hb_shape_plan_t          *shape_plan,
				   const hb_shape_plan_proposal_t *proposal)
{
B
Behdad Esfahbod 已提交
409 410
  if (proposal->num_user_features != shape_plan->num_user_features)
    return false;
411 412 413 414
  for (unsigned int i = 0, n = proposal->num_user_features; i < n; i++)
    if (proposal->user_features[i].tag   != shape_plan->user_features[i].tag   ||
        proposal->user_features[i].value != shape_plan->user_features[i].value ||
        proposal->user_features[i].start != shape_plan->user_features[i].start ||
B
Behdad Esfahbod 已提交
415 416 417 418 419 420 421 422 423 424 425 426 427 428
        proposal->user_features[i].end   != shape_plan->user_features[i].end)
      return false;
  return true;
}

static inline hb_bool_t
hb_shape_plan_coords_match (const hb_shape_plan_t          *shape_plan,
			    const hb_shape_plan_proposal_t *proposal)
{
  if (proposal->num_coords != shape_plan->num_coords)
    return false;
  for (unsigned int i = 0, n = proposal->num_coords; i < n; i++)
    if (proposal->coords[i] != shape_plan->coords[i])
      return false;
429 430 431
  return true;
}

B
Behdad Esfahbod 已提交
432 433 434 435 436
static hb_bool_t
hb_shape_plan_matches (const hb_shape_plan_t          *shape_plan,
		       const hb_shape_plan_proposal_t *proposal)
{
  return hb_segment_properties_equal (&shape_plan->props, &proposal->props) &&
437
	 hb_shape_plan_user_features_match (shape_plan, proposal) &&
B
Behdad Esfahbod 已提交
438
	 hb_shape_plan_coords_match (shape_plan, proposal) &&
439
	 ((shape_plan->default_shaper_list && !proposal->shaper_list) ||
B
Behdad Esfahbod 已提交
440 441 442
	  (shape_plan->shaper_func == proposal->shaper_func));
}

443 444 445 446
static inline hb_bool_t
hb_non_global_user_features_present (const hb_feature_t *user_features,
				     unsigned int        num_user_features)
{
447
  while (num_user_features) {
448 449
    if (user_features->start != 0 || user_features->end != (unsigned int) -1)
      return true;
450 451 452
    num_user_features--;
    user_features++;
  }
453 454 455
  return false;
}

B
Behdad Esfahbod 已提交
456
static inline hb_bool_t
457
hb_coords_present (const int *coords HB_UNUSED,
B
Behdad Esfahbod 已提交
458 459 460 461 462
		   unsigned int num_coords)
{
  return num_coords != 0;
}

463 464 465 466 467 468 469 470 471 472 473 474
/**
 * hb_shape_plan_create_cached:
 * @face: 
 * @props: 
 * @user_features: (array length=num_user_features):
 * @num_user_features: 
 * @shaper_list: (array zero-terminated=1):
 *
 * 
 *
 * Return value: (transfer full):
 *
S
Sascha Brawer 已提交
475
 * Since: 0.9.7
476
 **/
B
Behdad Esfahbod 已提交
477 478 479 480 481 482
hb_shape_plan_t *
hb_shape_plan_create_cached (hb_face_t                     *face,
			     const hb_segment_properties_t *props,
			     const hb_feature_t            *user_features,
			     unsigned int                   num_user_features,
			     const char * const            *shaper_list)
B
Behdad Esfahbod 已提交
483 484 485
{
  return hb_shape_plan_create_cached2 (face, props,
				       user_features, num_user_features,
B
Behdad Esfahbod 已提交
486
				       nullptr, 0,
B
Behdad Esfahbod 已提交
487 488 489 490 491 492 493 494 495 496 497
				       shaper_list);
}

hb_shape_plan_t *
hb_shape_plan_create_cached2 (hb_face_t                     *face,
			      const hb_segment_properties_t *props,
			      const hb_feature_t            *user_features,
			      unsigned int                   num_user_features,
			      const int                     *coords,
			      unsigned int                   num_coords,
			      const char * const            *shaper_list)
B
Behdad Esfahbod 已提交
498
{
B
Behdad Esfahbod 已提交
499
  DEBUG_MSG_FUNC (SHAPE_PLAN, nullptr,
500 501
		  "face=%p num_features=%d shaper_list=%p",
		  face,
B
Behdad Esfahbod 已提交
502 503 504
		  num_user_features,
		  shaper_list);

B
Behdad Esfahbod 已提交
505 506 507
  hb_shape_plan_proposal_t proposal = {
    *props,
    shaper_list,
508 509
    user_features,
    num_user_features,
B
Behdad Esfahbod 已提交
510
    nullptr
B
Behdad Esfahbod 已提交
511 512 513
  };

  if (shaper_list) {
B
Behdad Esfahbod 已提交
514 515
    /* Choose shaper.  Adapted from hb_shape_plan_plan().
     * Must choose shaper exactly the same way as that function. */
B
Behdad Esfahbod 已提交
516
    for (const char * const *shaper_item = shaper_list; *shaper_item; shaper_item++)
517
      if (false)
B
Behdad Esfahbod 已提交
518 519
	;
#define HB_SHAPER_IMPLEMENT(shaper) \
B
Behdad Esfahbod 已提交
520 521 522 523 524 525
      else if (0 == strcmp (*shaper_item, #shaper) && \
	       hb_##shaper##_shaper_face_data_ensure (face)) \
      { \
	proposal.shaper_func = _hb_##shaper##_shape; \
	break; \
      }
B
Behdad Esfahbod 已提交
526 527 528
#include "hb-shaper-list.hh"
#undef HB_SHAPER_IMPLEMENT

B
Behdad Esfahbod 已提交
529
    if (unlikely (!proposal.shaper_func))
B
Behdad Esfahbod 已提交
530 531 532 533 534
      return hb_shape_plan_get_empty ();
  }


retry:
535
  hb_face_t::plan_node_t *cached_plan_nodes = face->shape_plans.get ();
B
Behdad Esfahbod 已提交
536

537 538 539 540 541 542 543 544
  /* Don't look for plan in the cache if there were variation coordinates XXX Fix me. */
  if (!hb_coords_present (coords, num_coords))
    for (hb_face_t::plan_node_t *node = cached_plan_nodes; node; node = node->next)
      if (hb_shape_plan_matches (node->shape_plan, &proposal))
      {
        DEBUG_MSG_FUNC (SHAPE_PLAN, node->shape_plan, "fulfilled from cache");
        return hb_shape_plan_reference (node->shape_plan);
      }
B
Behdad Esfahbod 已提交
545

546
  /* Not found. */
B
Behdad Esfahbod 已提交
547 548 549 550
  hb_shape_plan_t *shape_plan = hb_shape_plan_create2 (face, props,
						       user_features, num_user_features,
						       coords, num_coords,
						       shaper_list);
B
Behdad Esfahbod 已提交
551

B
Behdad Esfahbod 已提交
552 553 554 555
  /* Don't add to the cache if face is inert. */
  if (unlikely (hb_object_is_inert (face)))
    return shape_plan;

556 557 558
  /* Don't add the plan to the cache if there were user features with non-global ranges */
  if (hb_non_global_user_features_present (user_features, num_user_features))
    return shape_plan;
B
Behdad Esfahbod 已提交
559 560 561
  /* Don't add the plan to the cache if there were variation coordinates XXX Fix me. */
  if (hb_coords_present (coords, num_coords))
    return shape_plan;
562

B
Behdad Esfahbod 已提交
563 564 565 566 567 568 569
  hb_face_t::plan_node_t *node = (hb_face_t::plan_node_t *) calloc (1, sizeof (hb_face_t::plan_node_t));
  if (unlikely (!node))
    return shape_plan;

  node->shape_plan = shape_plan;
  node->next = cached_plan_nodes;

570 571
  if (unlikely (!face->shape_plans.cmpexch (cached_plan_nodes, node)))
  {
B
Behdad Esfahbod 已提交
572 573 574 575
    hb_shape_plan_destroy (shape_plan);
    free (node);
    goto retry;
  }
576
  DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan, "inserted into cache");
B
Behdad Esfahbod 已提交
577 578 579

  return hb_shape_plan_reference (shape_plan);
}
580

581 582 583 584 585 586 587 588
/**
 * hb_shape_plan_get_shaper:
 * @shape_plan: a shape plan.
 *
 * 
 *
 * Return value: (transfer none):
 *
S
Sascha Brawer 已提交
589
 * Since: 0.9.7
590
 **/
591 592 593
const char *
hb_shape_plan_get_shaper (hb_shape_plan_t *shape_plan)
{
B
Behdad Esfahbod 已提交
594
  return shape_plan->shaper_name;
595
}