2012-07-26 23:34:25 +02:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2017-11-03 21:57:30 +01:00
|
|
|
#include "hb-private.hh"
|
|
|
|
#include "hb-debug.hh"
|
2012-07-26 23:34:25 +02:00
|
|
|
#include "hb-shape-plan-private.hh"
|
2012-07-27 05:46:53 +02:00
|
|
|
#include "hb-shaper-private.hh"
|
2012-07-26 23:34:25 +02:00
|
|
|
#include "hb-font-private.hh"
|
2013-02-15 13:46:57 +01:00
|
|
|
#include "hb-buffer-private.hh"
|
2012-07-26 23:34:25 +02:00
|
|
|
|
2014-08-12 22:49:18 +02:00
|
|
|
|
2012-08-08 23:44:19 +02:00
|
|
|
static void
|
2012-07-27 05:46:53 +02:00
|
|
|
hb_shape_plan_plan (hb_shape_plan_t *shape_plan,
|
|
|
|
const hb_feature_t *user_features,
|
|
|
|
unsigned int num_user_features,
|
2016-09-10 12:57:24 +02:00
|
|
|
const int *coords,
|
|
|
|
unsigned int num_coords,
|
2012-07-27 05:46:53 +02:00
|
|
|
const char * const *shaper_list)
|
|
|
|
{
|
2014-08-12 22:49:18 +02:00
|
|
|
DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan,
|
2016-09-10 12:57:24 +02:00
|
|
|
"num_features=%d num_coords=%d shaper_list=%p",
|
2014-08-12 22:49:18 +02:00
|
|
|
num_user_features,
|
2016-09-10 12:57:24 +02:00
|
|
|
num_coords,
|
2014-08-12 22:49:18 +02:00
|
|
|
shaper_list);
|
|
|
|
|
2012-07-27 05:46:53 +02:00
|
|
|
const hb_shaper_pair_t *shapers = _hb_shapers_get ();
|
|
|
|
|
|
|
|
#define HB_SHAPER_PLAN(shaper) \
|
|
|
|
HB_STMT_START { \
|
2013-12-02 11:57:27 +01:00
|
|
|
if (hb_##shaper##_shaper_face_data_ensure (shape_plan->face_unsafe)) { \
|
2012-07-27 09:12:23 +02:00
|
|
|
HB_SHAPER_DATA (shaper, shape_plan) = \
|
2016-09-10 12:57:24 +02:00
|
|
|
HB_SHAPER_DATA_CREATE_FUNC (shaper, shape_plan) (shape_plan, \
|
|
|
|
user_features, num_user_features, \
|
|
|
|
coords, num_coords); \
|
2012-07-27 09:12:23 +02:00
|
|
|
shape_plan->shaper_func = _hb_##shaper##_shape; \
|
2012-11-16 22:23:37 +01:00
|
|
|
shape_plan->shaper_name = #shaper; \
|
2012-07-27 09:12:23 +02:00
|
|
|
return; \
|
2012-07-27 05:46:53 +02:00
|
|
|
} \
|
|
|
|
} HB_STMT_END
|
|
|
|
|
|
|
|
if (likely (!shaper_list)) {
|
|
|
|
for (unsigned int i = 0; i < HB_SHAPERS_COUNT; i++)
|
|
|
|
if (0)
|
|
|
|
;
|
|
|
|
#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++)
|
|
|
|
if (0)
|
|
|
|
;
|
|
|
|
#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
|
|
|
|
}
|
|
|
|
|
2012-07-26 23:34:25 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* hb_shape_plan_t
|
|
|
|
*/
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
2013-09-12 23:14:33 +02:00
|
|
|
* hb_shape_plan_create: (Xconstructor)
|
2013-09-06 21:40:22 +02:00
|
|
|
* @face:
|
|
|
|
* @props:
|
|
|
|
* @user_features: (array length=num_user_features):
|
|
|
|
* @num_user_features:
|
|
|
|
* @shaper_list: (array zero-terminated=1):
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Return value: (transfer full):
|
|
|
|
*
|
2015-06-01 13:22:01 +02:00
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
**/
|
2012-07-26 23:34:25 +02:00
|
|
|
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)
|
2016-09-10 12:57:24 +02:00
|
|
|
{
|
|
|
|
return hb_shape_plan_create2 (face, props,
|
|
|
|
user_features, num_user_features,
|
2017-10-15 12:11:08 +02:00
|
|
|
nullptr, 0,
|
2016-09-10 12:57:24 +02:00
|
|
|
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)
|
2012-07-26 23:34:25 +02:00
|
|
|
{
|
2017-10-15 12:11:08 +02:00
|
|
|
DEBUG_MSG_FUNC (SHAPE_PLAN, nullptr,
|
2016-09-10 12:57:24 +02:00
|
|
|
"face=%p num_features=%d num_coords=%d shaper_list=%p",
|
2014-08-12 23:14:36 +02:00
|
|
|
face,
|
2014-08-12 22:49:18 +02:00
|
|
|
num_user_features,
|
2016-09-10 12:57:24 +02:00
|
|
|
num_coords,
|
2014-08-12 22:49:18 +02:00
|
|
|
shaper_list);
|
|
|
|
|
2012-07-26 23:34:25 +02:00
|
|
|
hb_shape_plan_t *shape_plan;
|
2017-10-15 12:11:08 +02:00
|
|
|
hb_feature_t *features = nullptr;
|
|
|
|
int *coords = nullptr;
|
2012-07-26 23:34:25 +02:00
|
|
|
|
|
|
|
if (unlikely (!face))
|
|
|
|
face = hb_face_get_empty ();
|
2014-08-06 21:36:41 +02:00
|
|
|
if (unlikely (!props))
|
2012-07-26 23:34:25 +02:00
|
|
|
return hb_shape_plan_get_empty ();
|
2015-10-02 09:02:29 +02:00
|
|
|
if (num_user_features && !(features = (hb_feature_t *) calloc (num_user_features, sizeof (hb_feature_t))))
|
2012-07-26 23:34:25 +02:00
|
|
|
return hb_shape_plan_get_empty ();
|
2016-09-10 12:57:24 +02:00
|
|
|
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);
|
2013-12-02 11:22:00 +01:00
|
|
|
free (features);
|
|
|
|
return hb_shape_plan_get_empty ();
|
|
|
|
}
|
2012-07-26 23:34:25 +02:00
|
|
|
|
2014-06-03 23:57:00 +02:00
|
|
|
assert (props->direction != HB_DIRECTION_INVALID);
|
|
|
|
|
2012-07-26 23:34:25 +02:00
|
|
|
hb_face_make_immutable (face);
|
2017-08-10 02:09:21 +02:00
|
|
|
shape_plan->default_shaper_list = !shaper_list;
|
2013-12-02 11:57:27 +01:00
|
|
|
shape_plan->face_unsafe = face;
|
2012-07-27 05:46:53 +02:00
|
|
|
shape_plan->props = *props;
|
2013-12-02 11:22:00 +01:00
|
|
|
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));
|
2016-09-10 12:57:24 +02:00
|
|
|
shape_plan->num_coords = num_coords;
|
|
|
|
shape_plan->coords = coords;
|
|
|
|
if (num_coords)
|
|
|
|
memcpy (coords, orig_coords, num_coords * sizeof (int));
|
2012-07-26 23:34:25 +02:00
|
|
|
|
2016-09-10 12:57:24 +02:00
|
|
|
hb_shape_plan_plan (shape_plan,
|
|
|
|
user_features, num_user_features,
|
|
|
|
coords, num_coords,
|
|
|
|
shaper_list);
|
2012-07-27 04:05:39 +02:00
|
|
|
|
2012-07-26 23:34:25 +02:00
|
|
|
return shape_plan;
|
|
|
|
}
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_get_empty:
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Return value: (transfer full):
|
|
|
|
*
|
2015-06-01 13:22:01 +02:00
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
**/
|
2012-07-26 23:34:25 +02:00
|
|
|
hb_shape_plan_t *
|
|
|
|
hb_shape_plan_get_empty (void)
|
|
|
|
{
|
|
|
|
static const hb_shape_plan_t _hb_shape_plan_nil = {
|
|
|
|
HB_OBJECT_HEADER_STATIC,
|
2012-07-27 08:12:28 +02:00
|
|
|
|
2012-07-30 03:35:22 +02:00
|
|
|
true, /* default_shaper_list */
|
2017-10-15 12:11:08 +02:00
|
|
|
nullptr, /* face */
|
2012-11-16 03:39:46 +01:00
|
|
|
HB_SEGMENT_PROPERTIES_DEFAULT, /* props */
|
2012-07-27 08:12:28 +02:00
|
|
|
|
2017-10-15 12:11:08 +02:00
|
|
|
nullptr, /* shaper_func */
|
|
|
|
nullptr, /* shaper_name */
|
2012-07-27 08:12:28 +02:00
|
|
|
|
2017-10-15 12:11:08 +02:00
|
|
|
nullptr, /* user_features */
|
2013-12-02 11:22:00 +01:00
|
|
|
0, /* num_user_featurs */
|
|
|
|
|
2017-10-15 12:11:08 +02:00
|
|
|
nullptr, /* coords */
|
2016-09-10 12:57:24 +02:00
|
|
|
0, /* num_coords */
|
|
|
|
|
2012-07-27 08:12:28 +02:00
|
|
|
{
|
|
|
|
#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
|
|
|
|
#include "hb-shaper-list.hh"
|
|
|
|
#undef HB_SHAPER_IMPLEMENT
|
|
|
|
}
|
2012-07-26 23:34:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return const_cast<hb_shape_plan_t *> (&_hb_shape_plan_nil);
|
|
|
|
}
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_reference: (skip)
|
|
|
|
* @shape_plan: a shape plan.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Return value: (transfer full):
|
|
|
|
*
|
2015-06-01 13:22:01 +02:00
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
**/
|
2012-07-26 23:34:25 +02:00
|
|
|
hb_shape_plan_t *
|
|
|
|
hb_shape_plan_reference (hb_shape_plan_t *shape_plan)
|
|
|
|
{
|
|
|
|
return hb_object_reference (shape_plan);
|
|
|
|
}
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_destroy: (skip)
|
|
|
|
* @shape_plan: a shape plan.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
2015-06-01 13:22:01 +02:00
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
**/
|
2012-07-26 23:34:25 +02:00
|
|
|
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
|
|
|
|
|
2013-12-02 11:22:00 +01:00
|
|
|
free (shape_plan->user_features);
|
2016-09-10 12:57:24 +02:00
|
|
|
free (shape_plan->coords);
|
2012-08-04 03:21:13 +02:00
|
|
|
|
2012-07-26 23:34:25 +02:00
|
|
|
free (shape_plan);
|
|
|
|
}
|
2012-07-27 07:13:53 +02:00
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_set_user_data: (skip)
|
|
|
|
* @shape_plan: a shape plan.
|
|
|
|
* @key:
|
|
|
|
* @data:
|
|
|
|
* @destroy:
|
|
|
|
* @replace:
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*
|
2015-06-01 13:22:01 +02:00
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
**/
|
2012-11-16 03:39:46 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_get_user_data: (skip)
|
|
|
|
* @shape_plan: a shape plan.
|
|
|
|
* @key:
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Return value: (transfer none):
|
|
|
|
*
|
2015-06-01 13:22:01 +02:00
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
**/
|
2012-11-16 03:39:46 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-07-27 07:13:53 +02:00
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_execute:
|
|
|
|
* @shape_plan: a shape plan.
|
|
|
|
* @font: a font.
|
|
|
|
* @buffer: a buffer.
|
|
|
|
* @features: (array length=num_features):
|
|
|
|
* @num_features:
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*
|
2015-06-01 13:22:01 +02:00
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
**/
|
2012-07-27 07:13:53 +02:00
|
|
|
hb_bool_t
|
2012-11-16 03:39:46 +01:00
|
|
|
hb_shape_plan_execute (hb_shape_plan_t *shape_plan,
|
2012-07-27 07:13:53 +02:00
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer,
|
|
|
|
const hb_feature_t *features,
|
|
|
|
unsigned int num_features)
|
|
|
|
{
|
2014-08-12 22:49:18 +02:00
|
|
|
DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan,
|
2016-08-27 15:38:42 +02:00
|
|
|
"num_features=%d shaper_func=%p, shaper_name=%s",
|
2014-08-12 22:49:18 +02:00
|
|
|
num_features,
|
2016-08-27 15:38:42 +02:00
|
|
|
shape_plan->shaper_func,
|
|
|
|
shape_plan->shaper_name);
|
2014-08-12 22:49:18 +02:00
|
|
|
|
2015-10-02 08:25:52 +02:00
|
|
|
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)))
|
2012-07-27 07:13:53 +02:00
|
|
|
return false;
|
|
|
|
|
2013-12-02 11:57:27 +01:00
|
|
|
assert (shape_plan->face_unsafe == font->face);
|
2013-02-15 13:46:57 +01:00
|
|
|
assert (hb_segment_properties_equal (&shape_plan->props, &buffer->props));
|
|
|
|
|
2012-07-27 07:13:53 +02:00
|
|
|
#define HB_SHAPER_EXECUTE(shaper) \
|
|
|
|
HB_STMT_START { \
|
2012-07-27 09:12:23 +02:00
|
|
|
return HB_SHAPER_DATA (shaper, shape_plan) && \
|
|
|
|
hb_##shaper##_shaper_font_data_ensure (font) && \
|
|
|
|
_hb_##shaper##_shape (shape_plan, font, buffer, features, num_features); \
|
2012-07-27 07:13:53 +02:00
|
|
|
} HB_STMT_END
|
|
|
|
|
2012-07-27 08:49:39 +02:00
|
|
|
if (0)
|
|
|
|
;
|
2012-07-27 07:13:53 +02:00
|
|
|
#define HB_SHAPER_IMPLEMENT(shaper) \
|
2012-07-27 08:49:39 +02:00
|
|
|
else if (shape_plan->shaper_func == _hb_##shaper##_shape) \
|
|
|
|
HB_SHAPER_EXECUTE (shaper);
|
2012-07-27 07:13:53 +02:00
|
|
|
#include "hb-shaper-list.hh"
|
|
|
|
#undef HB_SHAPER_IMPLEMENT
|
|
|
|
|
|
|
|
#undef HB_SHAPER_EXECUTE
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-27 10:02:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* caching
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if 0
|
2012-08-08 20:26:36 +02:00
|
|
|
static unsigned int
|
2012-07-27 10:02:38 +02:00
|
|
|
hb_shape_plan_hash (const hb_shape_plan_t *shape_plan)
|
|
|
|
{
|
|
|
|
return hb_segment_properties_hash (&shape_plan->props) +
|
2012-08-08 20:26:36 +02:00
|
|
|
shape_plan->default_shaper_list ? 0 : (intptr_t) shape_plan->shaper_func;
|
2012-07-27 10:02:38 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-02 11:22:00 +01:00
|
|
|
/* 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.
|
|
|
|
*/
|
2012-07-27 10:02:38 +02:00
|
|
|
struct hb_shape_plan_proposal_t
|
|
|
|
{
|
|
|
|
const hb_segment_properties_t props;
|
|
|
|
const char * const *shaper_list;
|
2013-12-02 11:22:00 +01:00
|
|
|
const hb_feature_t *user_features;
|
|
|
|
unsigned int num_user_features;
|
2016-09-10 12:57:24 +02:00
|
|
|
const int *coords;
|
|
|
|
unsigned int num_coords;
|
2012-07-27 10:02:38 +02:00
|
|
|
hb_shape_func_t *shaper_func;
|
|
|
|
};
|
|
|
|
|
2013-12-02 11:22:00 +01:00
|
|
|
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)
|
|
|
|
{
|
2016-09-10 12:57:24 +02:00
|
|
|
if (proposal->num_user_features != shape_plan->num_user_features)
|
|
|
|
return false;
|
2013-12-02 11:22:00 +01:00
|
|
|
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 ||
|
2016-09-10 12:57:24 +02:00
|
|
|
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;
|
2013-12-02 11:22:00 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-27 10:02:38 +02:00
|
|
|
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) &&
|
2013-12-02 11:22:00 +01:00
|
|
|
hb_shape_plan_user_features_match (shape_plan, proposal) &&
|
2016-09-10 12:57:24 +02:00
|
|
|
hb_shape_plan_coords_match (shape_plan, proposal) &&
|
2017-08-10 02:09:21 +02:00
|
|
|
((shape_plan->default_shaper_list && !proposal->shaper_list) ||
|
2012-07-27 10:02:38 +02:00
|
|
|
(shape_plan->shaper_func == proposal->shaper_func));
|
|
|
|
}
|
|
|
|
|
2013-12-02 11:22:00 +01:00
|
|
|
static inline hb_bool_t
|
|
|
|
hb_non_global_user_features_present (const hb_feature_t *user_features,
|
|
|
|
unsigned int num_user_features)
|
|
|
|
{
|
2017-04-18 08:25:24 +02:00
|
|
|
while (num_user_features) {
|
2013-12-02 11:22:00 +01:00
|
|
|
if (user_features->start != 0 || user_features->end != (unsigned int) -1)
|
|
|
|
return true;
|
2017-04-18 08:25:24 +02:00
|
|
|
num_user_features--;
|
|
|
|
user_features++;
|
|
|
|
}
|
2013-12-02 11:22:00 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-10 12:57:24 +02:00
|
|
|
static inline hb_bool_t
|
|
|
|
hb_coords_present (const int *coords,
|
|
|
|
unsigned int num_coords)
|
|
|
|
{
|
|
|
|
return num_coords != 0;
|
|
|
|
}
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
|
|
|
* 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):
|
|
|
|
*
|
2015-06-01 13:22:01 +02:00
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
**/
|
2012-07-27 10:02:38 +02:00
|
|
|
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)
|
2016-09-10 12:57:24 +02:00
|
|
|
{
|
|
|
|
return hb_shape_plan_create_cached2 (face, props,
|
|
|
|
user_features, num_user_features,
|
2017-10-15 12:11:08 +02:00
|
|
|
nullptr, 0,
|
2016-09-10 12:57:24 +02:00
|
|
|
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)
|
2012-07-27 10:02:38 +02:00
|
|
|
{
|
2017-10-15 12:11:08 +02:00
|
|
|
DEBUG_MSG_FUNC (SHAPE_PLAN, nullptr,
|
2014-08-12 23:14:36 +02:00
|
|
|
"face=%p num_features=%d shaper_list=%p",
|
|
|
|
face,
|
2014-08-12 22:49:18 +02:00
|
|
|
num_user_features,
|
|
|
|
shaper_list);
|
|
|
|
|
2012-07-27 10:02:38 +02:00
|
|
|
hb_shape_plan_proposal_t proposal = {
|
|
|
|
*props,
|
|
|
|
shaper_list,
|
2013-12-02 11:22:00 +01:00
|
|
|
user_features,
|
|
|
|
num_user_features,
|
2017-10-15 12:11:08 +02:00
|
|
|
nullptr
|
2012-07-27 10:02:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (shaper_list) {
|
2014-08-12 23:03:27 +02:00
|
|
|
/* Choose shaper. Adapted from hb_shape_plan_plan().
|
|
|
|
* Must choose shaper exactly the same way as that function. */
|
2012-07-27 10:02:38 +02:00
|
|
|
for (const char * const *shaper_item = shaper_list; *shaper_item; shaper_item++)
|
|
|
|
if (0)
|
|
|
|
;
|
|
|
|
#define HB_SHAPER_IMPLEMENT(shaper) \
|
2014-08-12 23:03:27 +02:00
|
|
|
else if (0 == strcmp (*shaper_item, #shaper) && \
|
|
|
|
hb_##shaper##_shaper_face_data_ensure (face)) \
|
|
|
|
{ \
|
|
|
|
proposal.shaper_func = _hb_##shaper##_shape; \
|
|
|
|
break; \
|
|
|
|
}
|
2012-07-27 10:02:38 +02:00
|
|
|
#include "hb-shaper-list.hh"
|
|
|
|
#undef HB_SHAPER_IMPLEMENT
|
|
|
|
|
2014-08-12 23:15:09 +02:00
|
|
|
if (unlikely (!proposal.shaper_func))
|
2012-07-27 10:02:38 +02:00
|
|
|
return hb_shape_plan_get_empty ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
retry:
|
|
|
|
hb_face_t::plan_node_t *cached_plan_nodes = (hb_face_t::plan_node_t *) hb_atomic_ptr_get (&face->shape_plans);
|
|
|
|
|
2017-10-02 14:08:49 +02:00
|
|
|
/* 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);
|
|
|
|
}
|
2012-07-27 10:02:38 +02:00
|
|
|
|
2017-10-02 14:08:49 +02:00
|
|
|
/* Not found. */
|
2016-09-10 12:57:24 +02:00
|
|
|
hb_shape_plan_t *shape_plan = hb_shape_plan_create2 (face, props,
|
|
|
|
user_features, num_user_features,
|
|
|
|
coords, num_coords,
|
|
|
|
shaper_list);
|
2012-07-27 10:02:38 +02:00
|
|
|
|
2014-08-06 21:36:41 +02:00
|
|
|
/* Don't add to the cache if face is inert. */
|
|
|
|
if (unlikely (hb_object_is_inert (face)))
|
|
|
|
return shape_plan;
|
|
|
|
|
2013-12-02 11:22:00 +01:00
|
|
|
/* 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;
|
2016-09-10 12:57:24 +02:00
|
|
|
/* 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;
|
2013-12-02 11:22:00 +01:00
|
|
|
|
2012-07-27 10:02:38 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
if (!hb_atomic_ptr_cmpexch (&face->shape_plans, cached_plan_nodes, node)) {
|
|
|
|
hb_shape_plan_destroy (shape_plan);
|
|
|
|
free (node);
|
|
|
|
goto retry;
|
|
|
|
}
|
2014-08-12 23:14:36 +02:00
|
|
|
DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan, "inserted into cache");
|
2012-07-27 10:02:38 +02:00
|
|
|
|
|
|
|
return hb_shape_plan_reference (shape_plan);
|
|
|
|
}
|
2012-11-16 22:23:37 +01:00
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_get_shaper:
|
|
|
|
* @shape_plan: a shape plan.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Return value: (transfer none):
|
|
|
|
*
|
2015-06-01 13:22:01 +02:00
|
|
|
* Since: 0.9.7
|
2013-09-06 21:40:22 +02:00
|
|
|
**/
|
2012-11-16 22:23:37 +01:00
|
|
|
const char *
|
|
|
|
hb_shape_plan_get_shaper (hb_shape_plan_t *shape_plan)
|
|
|
|
{
|
2012-11-22 20:15:08 +01:00
|
|
|
return shape_plan->shaper_name;
|
2012-11-16 22:23:37 +01:00
|
|
|
}
|