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
|
|
|
|
*/
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb.hh"
|
|
|
|
#include "hb-shape-plan.hh"
|
|
|
|
#include "hb-shaper.hh"
|
|
|
|
#include "hb-font.hh"
|
|
|
|
#include "hb-buffer.hh"
|
2012-07-26 23:34:25 +02:00
|
|
|
|
2014-08-12 22:49:18 +02:00
|
|
|
|
2018-10-27 13:07:33 +02:00
|
|
|
/**
|
|
|
|
* SECTION:hb-shape-plan
|
2018-10-28 16:23:36 +01:00
|
|
|
* @title: hb-shape-plan
|
2018-10-27 13:07:33 +02:00
|
|
|
* @short_description: Object representing a shaping plan
|
|
|
|
* @include: hb.h
|
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Shape plans are an internal mechanism. Each plan contains state
|
|
|
|
* describing how HarfBuzz will shape a particular text segment, based on
|
|
|
|
* the combination of segment properties and the capabilities in the
|
|
|
|
* font face in use.
|
|
|
|
*
|
|
|
|
* Shape plans are not used for shaping directly, but can be queried to
|
|
|
|
* access certain information about how shaping will perform, given a set
|
|
|
|
* of specific input parameters (script, language, direction, features,
|
|
|
|
* etc.).
|
|
|
|
*
|
|
|
|
* Most client programs will not need to deal with shape plans directly.
|
2018-10-27 13:07:33 +02:00
|
|
|
**/
|
|
|
|
|
|
|
|
|
2018-11-12 23:49:15 +01:00
|
|
|
/*
|
|
|
|
* hb_shape_plan_key_t
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool
|
|
|
|
hb_shape_plan_key_t::init (bool copy,
|
|
|
|
hb_face_t *face,
|
|
|
|
const hb_segment_properties_t *props,
|
|
|
|
const hb_feature_t *user_features,
|
|
|
|
unsigned int num_user_features,
|
2018-11-13 00:48:10 +01:00
|
|
|
const int *coords,
|
2018-11-12 23:49:15 +01:00
|
|
|
unsigned int num_coords,
|
|
|
|
const char * const *shaper_list)
|
2012-07-27 05:46:53 +02:00
|
|
|
{
|
2018-11-12 23:49:15 +01:00
|
|
|
hb_feature_t *features = nullptr;
|
2021-07-08 18:58:50 +02:00
|
|
|
if (copy && num_user_features && !(features = (hb_feature_t *) hb_calloc (num_user_features, sizeof (hb_feature_t))))
|
2018-11-12 23:49:15 +01:00
|
|
|
goto bail;
|
|
|
|
|
|
|
|
this->props = *props;
|
|
|
|
this->num_user_features = num_user_features;
|
|
|
|
this->user_features = copy ? features : user_features;
|
|
|
|
if (copy && num_user_features)
|
2018-11-13 01:26:01 +01:00
|
|
|
{
|
2018-11-12 23:49:15 +01:00
|
|
|
memcpy (features, user_features, num_user_features * sizeof (hb_feature_t));
|
2018-11-13 01:26:01 +01:00
|
|
|
/* Make start/end uniform to easier catch bugs. */
|
|
|
|
for (unsigned int i = 0; i < num_user_features; i++)
|
|
|
|
{
|
|
|
|
if (features[0].start != HB_FEATURE_GLOBAL_START)
|
|
|
|
features[0].start = 1;
|
|
|
|
if (features[0].end != HB_FEATURE_GLOBAL_END)
|
|
|
|
features[0].end = 2;
|
|
|
|
}
|
|
|
|
}
|
2018-11-12 23:49:15 +01:00
|
|
|
this->shaper_func = nullptr;
|
|
|
|
this->shaper_name = nullptr;
|
2019-06-26 22:21:03 +02:00
|
|
|
#ifndef HB_NO_OT_SHAPE
|
2018-11-13 00:48:10 +01:00
|
|
|
this->ot.init (face, coords, num_coords);
|
2019-06-26 22:21:03 +02:00
|
|
|
#endif
|
2018-11-12 23:49:15 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Choose shaper.
|
|
|
|
*/
|
|
|
|
|
2012-07-27 05:46:53 +02:00
|
|
|
#define HB_SHAPER_PLAN(shaper) \
|
|
|
|
HB_STMT_START { \
|
2018-11-16 08:29:13 +01:00
|
|
|
if (face->data.shaper) \
|
2018-08-09 09:22:37 +02:00
|
|
|
{ \
|
2018-11-12 23:49:15 +01:00
|
|
|
this->shaper_func = _hb_##shaper##_shape; \
|
|
|
|
this->shaper_name = #shaper; \
|
|
|
|
return true; \
|
2012-07-27 05:46:53 +02:00
|
|
|
} \
|
|
|
|
} HB_STMT_END
|
|
|
|
|
2018-11-12 23:19:45 +01:00
|
|
|
if (unlikely (shaper_list))
|
|
|
|
{
|
2012-07-27 05:46:53 +02:00
|
|
|
for (; *shaper_list; shaper_list++)
|
2018-10-18 17:18:42 +02:00
|
|
|
if (false)
|
2012-07-27 05:46:53 +02:00
|
|
|
;
|
|
|
|
#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
|
|
|
|
}
|
2018-11-12 23:49:15 +01:00
|
|
|
else
|
|
|
|
{
|
2022-07-13 20:46:36 +02:00
|
|
|
const HB_UNUSED hb_shaper_entry_t *shapers = _hb_shapers_get ();
|
2018-11-12 23:49:15 +01:00
|
|
|
for (unsigned int i = 0; i < HB_SHAPERS_COUNT; i++)
|
|
|
|
if (false)
|
|
|
|
;
|
2018-11-12 23:19:45 +01:00
|
|
|
#define HB_SHAPER_IMPLEMENT(shaper) \
|
2018-11-12 23:49:15 +01:00
|
|
|
else if (shapers[i].func == _hb_##shaper##_shape) \
|
|
|
|
HB_SHAPER_PLAN (shaper);
|
2018-11-12 23:19:45 +01:00
|
|
|
#include "hb-shaper-list.hh"
|
|
|
|
#undef HB_SHAPER_IMPLEMENT
|
2018-11-12 23:49:15 +01:00
|
|
|
}
|
2012-07-27 05:46:53 +02:00
|
|
|
#undef HB_SHAPER_PLAN
|
2018-11-12 23:49:15 +01:00
|
|
|
|
|
|
|
bail:
|
2021-07-08 18:58:50 +02:00
|
|
|
::hb_free (features);
|
2018-11-12 23:49:15 +01:00
|
|
|
return false;
|
2012-07-27 05:46:53 +02:00
|
|
|
}
|
|
|
|
|
2018-11-13 01:26:01 +01:00
|
|
|
bool
|
|
|
|
hb_shape_plan_key_t::user_features_match (const hb_shape_plan_key_t *other)
|
|
|
|
{
|
|
|
|
if (this->num_user_features != other->num_user_features)
|
|
|
|
return false;
|
|
|
|
for (unsigned int i = 0; i < num_user_features; i++)
|
|
|
|
{
|
|
|
|
if (this->user_features[i].tag != other->user_features[i].tag ||
|
|
|
|
this->user_features[i].value != other->user_features[i].value ||
|
|
|
|
(this->user_features[i].start == HB_FEATURE_GLOBAL_START &&
|
|
|
|
this->user_features[i].end == HB_FEATURE_GLOBAL_END) !=
|
|
|
|
(other->user_features[i].start == HB_FEATURE_GLOBAL_START &&
|
|
|
|
other->user_features[i].end == HB_FEATURE_GLOBAL_END))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
hb_shape_plan_key_t::equal (const hb_shape_plan_key_t *other)
|
|
|
|
{
|
|
|
|
return hb_segment_properties_equal (&this->props, &other->props) &&
|
|
|
|
this->user_features_match (other) &&
|
2019-06-26 22:21:03 +02:00
|
|
|
#ifndef HB_NO_OT_SHAPE
|
2018-11-13 01:26:01 +01:00
|
|
|
this->ot.equal (&other->ot) &&
|
2019-06-26 22:21:03 +02:00
|
|
|
#endif
|
2018-11-13 01:26:01 +01:00
|
|
|
this->shaper_func == other->shaper_func;
|
|
|
|
}
|
|
|
|
|
2012-07-26 23:34:25 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* hb_shape_plan_t
|
|
|
|
*/
|
|
|
|
|
2018-08-06 15:17:48 +02:00
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
2022-06-05 08:55:35 +02:00
|
|
|
* hb_shape_plan_create:
|
2019-04-22 20:17:40 +02:00
|
|
|
* @face: #hb_face_t to use
|
|
|
|
* @props: The #hb_segment_properties_t of the segment
|
|
|
|
* @user_features: (array length=num_user_features): The list of user-selected features
|
|
|
|
* @num_user_features: The number of user-selected features
|
|
|
|
* @shaper_list: (array zero-terminated=1): List of shapers to try
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Constructs a shaping plan for a combination of @face, @user_features, @props,
|
|
|
|
* and @shaper_list.
|
2019-08-24 15:27:14 +02:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Return value: (transfer full): The shaping plan
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
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);
|
|
|
|
}
|
|
|
|
|
2019-04-22 20:17:40 +02:00
|
|
|
/**
|
2022-06-05 08:55:35 +02:00
|
|
|
* hb_shape_plan_create2:
|
2019-04-22 20:17:40 +02:00
|
|
|
* @face: #hb_face_t to use
|
|
|
|
* @props: The #hb_segment_properties_t of the segment
|
|
|
|
* @user_features: (array length=num_user_features): The list of user-selected features
|
|
|
|
* @num_user_features: The number of user-selected features
|
|
|
|
* @coords: (array length=num_coords): The list of variation-space coordinates
|
|
|
|
* @num_coords: The number of variation-space coordinates
|
|
|
|
* @shaper_list: (array zero-terminated=1): List of shapers to try
|
|
|
|
*
|
|
|
|
* The variable-font version of #hb_shape_plan_create.
|
|
|
|
* Constructs a shaping plan for a combination of @face, @user_features, @props,
|
|
|
|
* and @shaper_list, plus the variation-space coordinates @coords.
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): The shaping plan
|
|
|
|
*
|
|
|
|
* Since: 1.4.0
|
|
|
|
**/
|
2016-09-10 12:57:24 +02:00
|
|
|
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,
|
2018-11-12 23:49:15 +01:00
|
|
|
const int *coords,
|
2016-09-10 12:57:24 +02:00
|
|
|
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);
|
|
|
|
|
2022-05-31 16:20:56 +02:00
|
|
|
if (unlikely (props->direction == HB_DIRECTION_INVALID))
|
|
|
|
return hb_shape_plan_get_empty ();
|
2018-11-12 23:19:45 +01:00
|
|
|
|
2012-07-26 23:34:25 +02:00
|
|
|
hb_shape_plan_t *shape_plan;
|
|
|
|
|
2014-08-06 21:36:41 +02:00
|
|
|
if (unlikely (!props))
|
2018-11-12 04:03:15 +01:00
|
|
|
goto bail;
|
2016-09-10 12:57:24 +02:00
|
|
|
if (!(shape_plan = hb_object_create<hb_shape_plan_t> ()))
|
2018-11-12 04:03:15 +01:00
|
|
|
goto bail;
|
2012-07-26 23:34:25 +02:00
|
|
|
|
2018-11-12 04:03:15 +01:00
|
|
|
if (unlikely (!face))
|
|
|
|
face = hb_face_get_empty ();
|
2012-07-26 23:34:25 +02:00
|
|
|
hb_face_make_immutable (face);
|
2013-12-02 11:57:27 +01:00
|
|
|
shape_plan->face_unsafe = face;
|
2018-11-12 23:19:45 +01:00
|
|
|
|
2018-11-12 23:49:15 +01:00
|
|
|
if (unlikely (!shape_plan->key.init (true,
|
|
|
|
face,
|
|
|
|
props,
|
|
|
|
user_features,
|
|
|
|
num_user_features,
|
|
|
|
coords,
|
|
|
|
num_coords,
|
|
|
|
shaper_list)))
|
|
|
|
goto bail2;
|
2019-06-26 22:21:03 +02:00
|
|
|
#ifndef HB_NO_OT_SHAPE
|
2018-11-13 00:05:02 +01:00
|
|
|
if (unlikely (!shape_plan->ot.init0 (face, &shape_plan->key)))
|
2018-11-12 23:49:15 +01:00
|
|
|
goto bail3;
|
2019-06-26 22:21:03 +02:00
|
|
|
#endif
|
2018-11-12 03:32:01 +01:00
|
|
|
|
2012-07-26 23:34:25 +02:00
|
|
|
return shape_plan;
|
2018-11-12 04:03:15 +01:00
|
|
|
|
2019-06-26 22:21:03 +02:00
|
|
|
#ifndef HB_NO_OT_SHAPE
|
2018-11-12 23:49:15 +01:00
|
|
|
bail3:
|
2019-06-26 22:21:03 +02:00
|
|
|
#endif
|
2021-07-08 18:53:45 +02:00
|
|
|
shape_plan->key.fini ();
|
2018-11-12 23:49:15 +01:00
|
|
|
bail2:
|
2021-07-08 18:58:50 +02:00
|
|
|
hb_free (shape_plan);
|
2018-11-12 04:03:15 +01:00
|
|
|
bail:
|
|
|
|
return hb_shape_plan_get_empty ();
|
2012-07-26 23:34:25 +02:00
|
|
|
}
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_get_empty:
|
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Fetches the singleton empty shaping plan.
|
2019-08-24 15:27:14 +02:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Return value: (transfer full): The empty shaping plan
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
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 *
|
2018-12-17 19:01:01 +01:00
|
|
|
hb_shape_plan_get_empty ()
|
2012-07-26 23:34:25 +02:00
|
|
|
{
|
2020-04-20 11:42:45 +02:00
|
|
|
return const_cast<hb_shape_plan_t *> (&Null (hb_shape_plan_t));
|
2012-07-26 23:34:25 +02:00
|
|
|
}
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_reference: (skip)
|
2019-04-22 20:17:40 +02:00
|
|
|
* @shape_plan: A shaping plan
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Increases the reference count on the given shaping plan.
|
2019-08-24 15:27:14 +02:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Return value: (transfer full): @shape_plan
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
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)
|
2019-04-22 20:17:40 +02:00
|
|
|
* @shape_plan: A shaping plan
|
2019-08-24 15:27:14 +02:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Decreases the reference count on the given shaping plan. When the
|
|
|
|
* reference count reaches zero, the shaping plan is destroyed,
|
|
|
|
* freeing all memory.
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
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;
|
|
|
|
|
2021-07-08 18:58:50 +02:00
|
|
|
hb_free (shape_plan);
|
2012-07-26 23:34:25 +02:00
|
|
|
}
|
2012-07-27 07:13:53 +02:00
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_set_user_data: (skip)
|
2019-04-22 20:17:40 +02:00
|
|
|
* @shape_plan: A shaping plan
|
|
|
|
* @key: The user-data key to set
|
|
|
|
* @data: A pointer to the user data
|
2020-12-30 23:19:29 +01:00
|
|
|
* @destroy: (nullable): A callback to call when @data is not needed anymore
|
2019-04-22 20:17:40 +02:00
|
|
|
* @replace: Whether to replace an existing data with the same key
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Attaches a user-data key/data pair to the given shaping plan.
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
2022-06-30 08:43:57 +02:00
|
|
|
* Return value: `true` if success, `false` otherwise.
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
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)
|
2019-04-22 20:17:40 +02:00
|
|
|
* @shape_plan: A shaping plan
|
|
|
|
* @key: The user-data key to query
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Fetches the user data associated with the specified key,
|
|
|
|
* attached to the specified shaping plan.
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Return value: (transfer none): A pointer to the user data
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
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 *
|
2022-07-25 18:45:55 +02:00
|
|
|
hb_shape_plan_get_user_data (const hb_shape_plan_t *shape_plan,
|
|
|
|
hb_user_data_key_t *key)
|
2012-11-16 03:39:46 +01:00
|
|
|
{
|
|
|
|
return hb_object_get_user_data (shape_plan, key);
|
|
|
|
}
|
|
|
|
|
2018-11-12 23:50:30 +01:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_get_shaper:
|
2019-04-22 20:17:40 +02:00
|
|
|
* @shape_plan: A shaping plan
|
2018-11-12 23:50:30 +01:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Fetches the shaper from a given shaping plan.
|
2019-08-24 15:27:14 +02:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Return value: (transfer none): The shaper
|
2018-11-12 23:50:30 +01:00
|
|
|
*
|
|
|
|
* Since: 0.9.7
|
|
|
|
**/
|
|
|
|
const char *
|
|
|
|
hb_shape_plan_get_shaper (hb_shape_plan_t *shape_plan)
|
|
|
|
{
|
|
|
|
return shape_plan->key.shaper_name;
|
|
|
|
}
|
|
|
|
|
2012-07-27 07:13:53 +02:00
|
|
|
|
2020-09-16 20:48:30 +02:00
|
|
|
static bool
|
|
|
|
_hb_shape_plan_execute_internal (hb_shape_plan_t *shape_plan,
|
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer,
|
|
|
|
const hb_feature_t *features,
|
|
|
|
unsigned int num_features)
|
2012-07-27 07:13:53 +02:00
|
|
|
{
|
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,
|
2018-11-12 23:19:45 +01:00
|
|
|
shape_plan->key.shaper_func,
|
|
|
|
shape_plan->key.shaper_name);
|
2014-08-12 22:49:18 +02:00
|
|
|
|
2015-10-02 08:25:52 +02:00
|
|
|
if (unlikely (!buffer->len))
|
|
|
|
return true;
|
|
|
|
|
2018-11-03 20:03:06 +01:00
|
|
|
assert (!hb_object_is_immutable (buffer));
|
2020-10-15 10:02:04 +02:00
|
|
|
|
|
|
|
buffer->assert_unicode ();
|
2015-10-02 08:25:52 +02:00
|
|
|
|
2021-08-17 04:13:58 +02:00
|
|
|
if (unlikely (!hb_object_is_valid (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);
|
2018-11-12 23:19:45 +01:00
|
|
|
assert (hb_segment_properties_equal (&shape_plan->key.props, &buffer->props));
|
2013-02-15 13:46:57 +01:00
|
|
|
|
2012-07-27 07:13:53 +02:00
|
|
|
#define HB_SHAPER_EXECUTE(shaper) \
|
|
|
|
HB_STMT_START { \
|
2018-11-16 08:29:13 +01:00
|
|
|
return font->data.shaper && \
|
2012-07-27 09:12:23 +02:00
|
|
|
_hb_##shaper##_shape (shape_plan, font, buffer, features, num_features); \
|
2012-07-27 07:13:53 +02:00
|
|
|
} HB_STMT_END
|
|
|
|
|
2018-10-18 17:18:42 +02:00
|
|
|
if (false)
|
2012-07-27 08:49:39 +02:00
|
|
|
;
|
2012-07-27 07:13:53 +02:00
|
|
|
#define HB_SHAPER_IMPLEMENT(shaper) \
|
2018-11-12 23:19:45 +01:00
|
|
|
else if (shape_plan->key.shaper_func == _hb_##shaper##_shape) \
|
2012-07-27 08:49:39 +02:00
|
|
|
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;
|
|
|
|
}
|
2020-09-16 20:48:30 +02:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_execute:
|
2019-04-22 20:17:40 +02:00
|
|
|
* @shape_plan: A shaping plan
|
|
|
|
* @font: The #hb_font_t to use
|
|
|
|
* @buffer: The #hb_buffer_t to work upon
|
|
|
|
* @features: (array length=num_features): Features to enable
|
|
|
|
* @num_features: The number of features to enable
|
2020-09-16 20:48:30 +02:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Executes the given shaping plan on the specified buffer, using
|
|
|
|
* the given @font and @features.
|
2020-09-16 20:48:30 +02:00
|
|
|
*
|
2022-06-30 08:43:57 +02:00
|
|
|
* Return value: `true` if success, `false` otherwise.
|
2020-09-16 20:48:30 +02:00
|
|
|
*
|
|
|
|
* Since: 0.9.7
|
|
|
|
**/
|
|
|
|
hb_bool_t
|
|
|
|
hb_shape_plan_execute (hb_shape_plan_t *shape_plan,
|
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer,
|
|
|
|
const hb_feature_t *features,
|
|
|
|
unsigned int num_features)
|
|
|
|
{
|
|
|
|
bool ret = _hb_shape_plan_execute_internal (shape_plan, font, buffer,
|
|
|
|
features, num_features);
|
|
|
|
|
|
|
|
if (ret && buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE)
|
|
|
|
buffer->content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2012-07-27 10:02:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2018-11-12 23:49:15 +01:00
|
|
|
* Caching
|
2012-07-27 10:02:38 +02:00
|
|
|
*/
|
|
|
|
|
2013-09-06 21:40:22 +02:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_create_cached:
|
2019-04-22 20:17:40 +02:00
|
|
|
* @face: #hb_face_t to use
|
|
|
|
* @props: The #hb_segment_properties_t of the segment
|
|
|
|
* @user_features: (array length=num_user_features): The list of user-selected features
|
|
|
|
* @num_user_features: The number of user-selected features
|
|
|
|
* @shaper_list: (array zero-terminated=1): List of shapers to try
|
2019-08-24 15:27:14 +02:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Creates a cached shaping plan suitable for reuse, for a combination
|
|
|
|
* of @face, @user_features, @props, and @shaper_list.
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
2019-04-22 20:17:40 +02:00
|
|
|
* Return value: (transfer full): The shaping plan
|
2013-09-06 21:40:22 +02:00
|
|
|
*
|
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);
|
|
|
|
}
|
|
|
|
|
2019-04-22 20:17:40 +02:00
|
|
|
/**
|
|
|
|
* hb_shape_plan_create_cached2:
|
|
|
|
* @face: #hb_face_t to use
|
|
|
|
* @props: The #hb_segment_properties_t of the segment
|
|
|
|
* @user_features: (array length=num_user_features): The list of user-selected features
|
|
|
|
* @num_user_features: The number of user-selected features
|
|
|
|
* @coords: (array length=num_coords): The list of variation-space coordinates
|
|
|
|
* @num_coords: The number of variation-space coordinates
|
|
|
|
* @shaper_list: (array zero-terminated=1): List of shapers to try
|
|
|
|
*
|
|
|
|
* The variable-font version of #hb_shape_plan_create_cached.
|
|
|
|
* Creates a cached shaping plan suitable for reuse, for a combination
|
|
|
|
* of @face, @user_features, @props, and @shaper_list, plus the
|
|
|
|
* variation-space coordinates @coords.
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): The shaping plan
|
|
|
|
*
|
|
|
|
* Since: 1.4.0
|
|
|
|
**/
|
2016-09-10 12:57:24 +02:00
|
|
|
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
|
|
|
retry:
|
2018-11-05 19:23:54 +01:00
|
|
|
hb_face_t::plan_node_t *cached_plan_nodes = face->shape_plans;
|
2012-07-27 10:02:38 +02:00
|
|
|
|
2021-08-17 04:13:58 +02:00
|
|
|
bool dont_cache = !hb_object_is_valid (face);
|
2018-11-12 23:27:34 +01:00
|
|
|
|
2018-11-13 01:26:01 +01:00
|
|
|
if (likely (!dont_cache))
|
2018-11-13 00:18:20 +01:00
|
|
|
{
|
|
|
|
hb_shape_plan_key_t key;
|
|
|
|
if (!key.init (false,
|
|
|
|
face,
|
|
|
|
props,
|
|
|
|
user_features,
|
|
|
|
num_user_features,
|
|
|
|
coords,
|
|
|
|
num_coords,
|
|
|
|
shaper_list))
|
|
|
|
return hb_shape_plan_get_empty ();
|
|
|
|
|
2017-10-02 14:08:49 +02:00
|
|
|
for (hb_face_t::plan_node_t *node = cached_plan_nodes; node; node = node->next)
|
2018-11-13 00:48:10 +01:00
|
|
|
if (node->shape_plan->key.equal (&key))
|
2017-10-02 14:08:49 +02:00
|
|
|
{
|
2019-08-24 15:27:14 +02:00
|
|
|
DEBUG_MSG_FUNC (SHAPE_PLAN, node->shape_plan, "fulfilled from cache");
|
|
|
|
return hb_shape_plan_reference (node->shape_plan);
|
2017-10-02 14:08:49 +02:00
|
|
|
}
|
2018-11-13 00:18:20 +01:00
|
|
|
}
|
2012-07-27 10:02:38 +02:00
|
|
|
|
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
|
|
|
|
2018-11-13 01:26:01 +01:00
|
|
|
if (unlikely (dont_cache))
|
2016-09-10 12:57:24 +02:00
|
|
|
return shape_plan;
|
2013-12-02 11:22:00 +01:00
|
|
|
|
2021-07-08 18:58:50 +02:00
|
|
|
hb_face_t::plan_node_t *node = (hb_face_t::plan_node_t *) hb_calloc (1, sizeof (hb_face_t::plan_node_t));
|
2012-07-27 10:02:38 +02:00
|
|
|
if (unlikely (!node))
|
|
|
|
return shape_plan;
|
|
|
|
|
|
|
|
node->shape_plan = shape_plan;
|
|
|
|
node->next = cached_plan_nodes;
|
|
|
|
|
2018-08-09 09:22:37 +02:00
|
|
|
if (unlikely (!face->shape_plans.cmpexch (cached_plan_nodes, node)))
|
|
|
|
{
|
2012-07-27 10:02:38 +02:00
|
|
|
hb_shape_plan_destroy (shape_plan);
|
2021-07-08 18:58:50 +02:00
|
|
|
hb_free (node);
|
2012-07-27 10:02:38 +02:00
|
|
|
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);
|
|
|
|
}
|