Embed hb_ot_shape_plan_t into hb_shape_plan_t

No other shaper will need shape_plan_data, by definition.  So, remove
abstraction layer and always create hb_ot_shape_plan_t as part of
hb_shape_plan_t.
This commit is contained in:
Behdad Esfahbod 2018-11-11 21:32:01 -05:00
parent fabb012104
commit f521a28b4a
9 changed files with 70 additions and 207 deletions

View File

@ -372,29 +372,6 @@ hb_coretext_font_get_ct_font (hb_font_t *font)
}
/*
* shaper shape_plan data
*/
struct hb_coretext_shape_plan_data_t {};
hb_coretext_shape_plan_data_t *
_hb_coretext_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED,
const hb_feature_t *user_features HB_UNUSED,
unsigned int num_user_features HB_UNUSED,
const int *coords HB_UNUSED,
unsigned int num_coords HB_UNUSED)
{
return (hb_coretext_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
}
void
_hb_coretext_shaper_shape_plan_data_destroy (hb_coretext_shape_plan_data_t *data HB_UNUSED)
{
}
/*
* shaper
*/
@ -1204,28 +1181,6 @@ _hb_coretext_aat_shaper_font_data_destroy (hb_coretext_aat_font_data_t *data HB_
}
/*
* shaper shape_plan data
*/
struct hb_coretext_aat_shape_plan_data_t {};
hb_coretext_aat_shape_plan_data_t *
_hb_coretext_aat_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED,
const hb_feature_t *user_features HB_UNUSED,
unsigned int num_user_features HB_UNUSED,
const int *coords HB_UNUSED,
unsigned int num_coords HB_UNUSED)
{
return (hb_coretext_aat_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
}
void
_hb_coretext_aat_shaper_shape_plan_data_destroy (hb_coretext_aat_shape_plan_data_t *data HB_UNUSED)
{
}
/*
* shaper
*/

View File

@ -256,27 +256,6 @@ _hb_directwrite_shaper_font_data_destroy (hb_directwrite_font_data_t *data)
}
/*
* shaper shape_plan data
*/
struct hb_directwrite_shape_plan_data_t {};
hb_directwrite_shape_plan_data_t *
_hb_directwrite_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED,
const hb_feature_t *user_features HB_UNUSED,
unsigned int num_user_features HB_UNUSED,
const int *coords HB_UNUSED,
unsigned int num_coords HB_UNUSED)
{
return (hb_directwrite_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
}
void
_hb_directwrite_shaper_shape_plan_data_destroy (hb_directwrite_shape_plan_data_t *data HB_UNUSED)
{
}
// Most of TextAnalysis is originally written by Bas Schouten for Mozilla project
// but now is relicensed to MIT for HarfBuzz use
class TextAnalysis

View File

@ -68,28 +68,6 @@ _hb_fallback_shaper_font_data_destroy (hb_fallback_font_data_t *data HB_UNUSED)
}
/*
* shaper shape_plan data
*/
struct hb_fallback_shape_plan_data_t {};
hb_fallback_shape_plan_data_t *
_hb_fallback_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED,
const hb_feature_t *user_features HB_UNUSED,
unsigned int num_user_features HB_UNUSED,
const int *coords HB_UNUSED,
unsigned int num_coords HB_UNUSED)
{
return (hb_fallback_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
}
void
_hb_fallback_shaper_shape_plan_data_destroy (hb_fallback_shape_plan_data_t *data HB_UNUSED)
{
}
/*
* shaper
*/

View File

@ -220,28 +220,6 @@ hb_graphite2_font_get_gr_font (hb_font_t *font HB_UNUSED)
}
/*
* shaper shape_plan data
*/
struct hb_graphite2_shape_plan_data_t {};
hb_graphite2_shape_plan_data_t *
_hb_graphite2_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED,
const hb_feature_t *user_features HB_UNUSED,
unsigned int num_user_features HB_UNUSED,
const int *coords HB_UNUSED,
unsigned int num_coords HB_UNUSED)
{
return (hb_graphite2_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
}
void
_hb_graphite2_shaper_shape_plan_data_destroy (hb_graphite2_shape_plan_data_t *data HB_UNUSED)
{
}
/*
* shaper
*/

View File

@ -27,7 +27,6 @@
*/
#define HB_SHAPER ot
#define hb_ot_shape_plan_data_t hb_ot_shape_plan_t
#include "hb-shaper-impl.hh"
#include "hb-ot-shape.hh"
@ -52,6 +51,12 @@
**/
static void
hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
const hb_segment_properties_t *props,
const hb_feature_t *user_features,
unsigned int num_user_features);
static bool
_hb_apply_morx (hb_face_t *face)
{
@ -89,7 +94,7 @@ hb_ot_shape_planner_t::compile (hb_ot_shape_plan_t &plan,
plan.dnom_mask = plan.map.get_1_mask (HB_TAG ('d','n','o','m'));
plan.has_frac = plan.frac_mask || (plan.numr_mask && plan.dnom_mask);
plan.rtlm_mask = plan.map.get_1_mask (HB_TAG ('r','t','l','m'));
hb_tag_t kern_tag = HB_DIRECTION_IS_HORIZONTAL (plan.props.direction) ?
hb_tag_t kern_tag = HB_DIRECTION_IS_HORIZONTAL (props.direction) ?
HB_TAG ('k','e','r','n') : HB_TAG ('v','k','r','n');
plan.kern_mask = plan.map.get_mask (kern_tag);
plan.trak_mask = plan.map.get_mask (HB_TAG ('t','r','a','k'));
@ -142,6 +147,43 @@ hb_ot_shape_planner_t::compile (hb_ot_shape_plan_t &plan,
plan.apply_trak = plan.requested_tracking && hb_aat_layout_has_tracking (face);
}
bool
hb_ot_shape_plan_t::init0 (hb_shape_plan_t *shape_plan,
const hb_feature_t *user_features,
unsigned int num_user_features,
const int *coords,
unsigned int num_coords)
{
map.init ();
aat_map.init ();
hb_ot_shape_planner_t planner (shape_plan);
hb_ot_shape_collect_features (&planner, &shape_plan->props,
user_features, num_user_features);
planner.compile (*this, coords, num_coords);
if (shaper->data_create)
{
data = shaper->data_create (this);
if (unlikely (!data))
return false;
}
return true;
}
void
hb_ot_shape_plan_t::fini (void)
{
if (shaper->data_destroy)
shaper->data_destroy (const_cast<void *> (data));
map.fini ();
aat_map.fini ();
}
static const hb_ot_map_feature_t
common_features[] =
@ -291,54 +333,6 @@ _hb_ot_shaper_font_data_destroy (hb_ot_font_data_t *data HB_UNUSED)
}
/*
* shaper shape_plan data
*/
hb_ot_shape_plan_data_t *
_hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan,
const hb_feature_t *user_features,
unsigned int num_user_features,
const int *coords,
unsigned int num_coords)
{
hb_ot_shape_plan_t *plan = (hb_ot_shape_plan_t *) calloc (1, sizeof (hb_ot_shape_plan_t));
if (unlikely (!plan))
return nullptr;
plan->init ();
hb_ot_shape_planner_t planner (shape_plan);
hb_ot_shape_collect_features (&planner, &shape_plan->props,
user_features, num_user_features);
planner.compile (*plan, coords, num_coords);
if (plan->shaper->data_create) {
plan->data = plan->shaper->data_create (plan);
if (unlikely (!plan->data))
{
free (plan);
return nullptr;
}
}
return plan;
}
void
_hb_ot_shaper_shape_plan_data_destroy (hb_ot_shape_plan_data_t *plan)
{
if (plan->shaper->data_destroy)
plan->shaper->data_destroy (const_cast<void *> (plan->data));
plan->fini ();
free (plan);
}
/*
* shaper
*/
@ -978,7 +972,7 @@ _hb_ot_shape (hb_shape_plan_t *shape_plan,
const hb_feature_t *features,
unsigned int num_features)
{
hb_ot_shape_context_t c = {HB_SHAPER_DATA_GET (shape_plan), font, font->face, buffer, features, num_features};
hb_ot_shape_context_t c = {&shape_plan->ot, font, font->face, buffer, features, num_features};
hb_ot_shape_internal (&c);
return true;
@ -995,8 +989,7 @@ hb_ot_shape_plan_collect_lookups (hb_shape_plan_t *shape_plan,
hb_tag_t table_tag,
hb_set_t *lookup_indexes /* OUT */)
{
/* XXX Does the first part always succeed? */
HB_SHAPER_DATA_GET (shape_plan)->collect_lookups (table_tag, lookup_indexes);
shape_plan->ot.collect_lookups (table_tag, lookup_indexes);
}

View File

@ -31,8 +31,6 @@
#include "hb-ot-map.hh"
#include "hb-aat-map.hh"
#include "hb-shape-plan.hh"
struct hb_ot_shape_plan_t
@ -75,18 +73,17 @@ struct hb_ot_shape_plan_t
inline void substitute (hb_font_t *font, hb_buffer_t *buffer) const { map.substitute (this, font, buffer); }
inline void position (hb_font_t *font, hb_buffer_t *buffer) const { map.position (this, font, buffer); }
void init (void)
{
memset (this, 0, sizeof (*this));
map.init ();
aat_map.init ();
}
void fini (void) {
map.fini ();
aat_map.fini ();
}
HB_INTERNAL bool init0 (hb_shape_plan_t *shape_plan,
const hb_feature_t *user_features,
unsigned int num_user_features,
const int *coords,
unsigned int num_coords);
HB_INTERNAL void fini (void);
};
struct hb_shape_plan_t;
struct hb_ot_shape_planner_t
{
/* In the order that they are filled in. */

View File

@ -64,10 +64,6 @@ hb_shape_plan_plan (hb_shape_plan_t *shape_plan,
HB_STMT_START { \
if (hb_##shaper##_shaper_face_data_ensure (shape_plan->face_unsafe)) \
{ \
HB_SHAPER_DATA (shaper, shape_plan).set_relaxed ( \
HB_SHAPER_DATA_CREATE_FUNC (shaper, shape_plan) (shape_plan, \
user_features, num_user_features, \
coords, num_coords)); \
shape_plan->shaper_func = _hb_##shaper##_shape; \
shape_plan->shaper_name = #shaper; \
return; \
@ -188,6 +184,17 @@ hb_shape_plan_create2 (hb_face_t *face,
coords, num_coords,
shaper_list);
if (unlikely (!shape_plan->ot.init0 (shape_plan,
user_features,
num_user_features,
coords,
num_coords)))
{
free (coords);
free (features);
return hb_shape_plan_get_empty ();
}
return shape_plan;
}
@ -235,9 +242,7 @@ 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
shape_plan->ot.fini ();
free (shape_plan->user_features);
free (shape_plan->coords);
@ -329,8 +334,7 @@ hb_shape_plan_execute (hb_shape_plan_t *shape_plan,
#define HB_SHAPER_EXECUTE(shaper) \
HB_STMT_START { \
return HB_SHAPER_DATA (shaper, shape_plan).get () && \
hb_##shaper##_shaper_font_data_ensure (font) && \
return hb_##shaper##_shaper_font_data_ensure (font) && \
_hb_##shaper##_shape (shape_plan, font, buffer, features, num_features); \
} HB_STMT_END

View File

@ -29,6 +29,7 @@
#include "hb.hh"
#include "hb-shaper.hh"
#include "hb-ot-shape.hh"
struct hb_shape_plan_t
@ -48,7 +49,7 @@ struct hb_shape_plan_t
int *coords;
unsigned int num_coords;
struct hb_shaper_data_t shaper_data;
hb_ot_shape_plan_t ot;
};
#define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS \

View File

@ -600,28 +600,6 @@ hb_uniscribe_font_get_hfont (hb_font_t *font)
}
/*
* shaper shape_plan data
*/
struct hb_uniscribe_shape_plan_data_t {};
hb_uniscribe_shape_plan_data_t *
_hb_uniscribe_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED,
const hb_feature_t *user_features HB_UNUSED,
unsigned int num_user_features HB_UNUSED,
const int *coords HB_UNUSED,
unsigned int num_coords HB_UNUSED)
{
return (hb_uniscribe_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
}
void
_hb_uniscribe_shaper_shape_plan_data_destroy (hb_uniscribe_shape_plan_data_t *data HB_UNUSED)
{
}
/*
* shaper
*/