summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2018-11-11 21:32:01 -0500
committerBehdad Esfahbod <behdad@behdad.org>2018-11-11 21:54:10 -0500
commitf521a28b4aad1566664cf14d70a911728ee0b962 (patch)
tree66e880962af321e354ad2c8e4085e93414b4f81c
parentfabb01210433ce1c6d5f630bc270f82a8a4a4014 (diff)
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.
-rw-r--r--src/hb-coretext.cc45
-rw-r--r--src/hb-directwrite.cc21
-rw-r--r--src/hb-fallback-shape.cc22
-rw-r--r--src/hb-graphite2.cc22
-rw-r--r--src/hb-ot-shape.cc99
-rw-r--r--src/hb-ot-shape.hh21
-rw-r--r--src/hb-shape-plan.cc22
-rw-r--r--src/hb-shape-plan.hh3
-rw-r--r--src/hb-uniscribe.cc22
9 files changed, 70 insertions, 207 deletions
diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 7509b8a3..3cedb5b2 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -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
*/
@@ -1205,28 +1182,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
*/
diff --git a/src/hb-directwrite.cc b/src/hb-directwrite.cc
index cc8f6cc0..b34ae601 100644
--- a/src/hb-directwrite.cc
+++ b/src/hb-directwrite.cc
@@ -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
diff --git a/src/hb-fallback-shape.cc b/src/hb-fallback-shape.cc
index ccfeba4b..40f8dad2 100644
--- a/src/hb-fallback-shape.cc
+++ b/src/hb-fallback-shape.cc
@@ -69,28 +69,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
*/
diff --git a/src/hb-graphite2.cc b/src/hb-graphite2.cc
index 38c2cd81..8dce8170 100644
--- a/src/hb-graphite2.cc
+++ b/src/hb-graphite2.cc
@@ -221,28 +221,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
*/
diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index 92a4b53a..44cf3907 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -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[] =
@@ -292,54 +334,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);
}
diff --git a/src/hb-ot-shape.hh b/src/hb-ot-shape.hh
index 655e28d6..049830a6 100644
--- a/src/hb-ot-shape.hh
+++ b/src/hb-ot-shape.hh
@@ -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. */
diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc
index ebf0e9f5..5579ded7 100644
--- a/src/hb-shape-plan.cc
+++ b/src/hb-shape-plan.cc
@@ -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
diff --git a/src/hb-shape-plan.hh b/src/hb-shape-plan.hh
index 891b9957..eaa84fd4 100644
--- a/src/hb-shape-plan.hh
+++ b/src/hb-shape-plan.hh
@@ -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 \
diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc
index 76da20df..dc82d6b7 100644
--- a/src/hb-uniscribe.cc
+++ b/src/hb-uniscribe.cc
@@ -601,28 +601,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
*/