Add hb_ot_layout_ensure() and hb_uniscribe_font_ensure()
diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index dff3673..eb39c65 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc
@@ -38,6 +38,13 @@ #include <string.h> +HB_SHAPER_DATA_ENSURE_DECLARE(ot, face) +hb_bool_t +hb_ot_layout_ensure (hb_face_t *face) +{ + return hb_ot_shaper_face_data_ensure (face); +} + hb_ot_layout_t * _hb_ot_layout_create (hb_face_t *face)
diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index cf178b7..af23478 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h
@@ -42,6 +42,12 @@ #define HB_OT_TAG_GSUB HB_TAG('G','S','U','B') #define HB_OT_TAG_GPOS HB_TAG('G','P','O','S') + +/* Must call before all other funtions in this file. Idempotent. */ +hb_bool_t +hb_ot_layout_ensure (hb_face_t *face); + + /* * GDEF */
diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index 1820f61..b0a8937 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc
@@ -30,24 +30,6 @@ #include "hb-shaper-private.hh" #include "hb-font-private.hh" -#define HB_SHAPER_DATA_ENSURE_DECLARE(shaper, object) \ -static inline bool \ -hb_##shaper##_##object##_data_ensure (hb_##object##_t *object) \ -{\ - retry: \ - HB_SHAPER_DATA_TYPE (shaper, object) *data = (HB_SHAPER_DATA_TYPE (shaper, object) *) hb_atomic_ptr_get (&HB_SHAPER_DATA (shaper, object)); \ - if (unlikely (!data)) { \ - data = HB_SHAPER_DATA_CREATE_FUNC (shaper, object) (object); \ - if (unlikely (!data)) \ - data = (HB_SHAPER_DATA_TYPE (shaper, object) *) HB_SHAPER_DATA_INVALID; \ - if (!hb_atomic_ptr_cmpexch (&HB_SHAPER_DATA (shaper, object), NULL, data)) { \ - HB_SHAPER_DATA_DESTROY_FUNC (shaper, object) (data); \ - goto retry; \ - } \ - } \ - return data != NULL && !HB_SHAPER_DATA_IS_INVALID (data); \ -} - #define HB_SHAPER_IMPLEMENT(shaper) \ HB_SHAPER_DATA_ENSURE_DECLARE(shaper, face) \ HB_SHAPER_DATA_ENSURE_DECLARE(shaper, font) @@ -65,7 +47,7 @@ #define HB_SHAPER_PLAN(shaper) \ HB_STMT_START { \ - if (hb_##shaper##_face_data_ensure (shape_plan->face)) { \ + if (hb_##shaper##_shaper_face_data_ensure (shape_plan->face)) { \ HB_SHAPER_DATA_TYPE (shaper, shape_plan) *data= \ HB_SHAPER_DATA_CREATE_FUNC (shaper, shape_plan) (shape_plan, user_features, num_user_features); \ if (data) { \ @@ -181,7 +163,7 @@ #define HB_SHAPER_EXECUTE(shaper) \ HB_STMT_START { \ - if (hb_##shaper##_font_data_ensure (font) && \ + if (hb_##shaper##_shaper_font_data_ensure (font) && \ _hb_##shaper##_shape (shape_plan, font, buffer, features, num_features)) \ return true; \ else \
diff --git a/src/hb-shaper-private.hh b/src/hb-shaper-private.hh index e50d869..186318d 100644 --- a/src/hb-shaper-private.hh +++ b/src/hb-shaper-private.hh
@@ -86,5 +86,23 @@ object->shaper_data.shaper != HB_SHAPER_DATA_SUCCEEDED) \ HB_SHAPER_DATA_DESTROY_FUNC (shaper, object) (HB_SHAPER_DATA (shaper, object)); +#define HB_SHAPER_DATA_ENSURE_DECLARE(shaper, object) \ +static inline bool \ +hb_##shaper##_shaper_##object##_data_ensure (hb_##object##_t *object) \ +{\ + retry: \ + HB_SHAPER_DATA_TYPE (shaper, object) *data = (HB_SHAPER_DATA_TYPE (shaper, object) *) hb_atomic_ptr_get (&HB_SHAPER_DATA (shaper, object)); \ + if (unlikely (!data)) { \ + data = HB_SHAPER_DATA_CREATE_FUNC (shaper, object) (object); \ + if (unlikely (!data)) \ + data = (HB_SHAPER_DATA_TYPE (shaper, object) *) HB_SHAPER_DATA_INVALID; \ + if (!hb_atomic_ptr_cmpexch (&HB_SHAPER_DATA (shaper, object), NULL, data)) { \ + HB_SHAPER_DATA_DESTROY_FUNC (shaper, object) (data); \ + goto retry; \ + } \ + } \ + return data != NULL && !HB_SHAPER_DATA_IS_INVALID (data); \ +} + #endif /* HB_SHAPER_PRIVATE_HH */
diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index 4368f68..7d06a6b 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc
@@ -56,6 +56,17 @@ */ +HB_SHAPER_DATA_ENSURE_DECLARE(uniscribe, face) +HB_SHAPER_DATA_ENSURE_DECLARE(uniscribe, font) +hb_bool_t +hb_uniscribe_font_ensure (hb_font_t *font) +{ + hb_face_t *face = font->face; + return hb_uniscribe_shaper_face_data_ensure (face) && + hb_uniscribe_shaper_font_data_ensure (font); +} + + /* * shaper face data */
diff --git a/src/hb-uniscribe.h b/src/hb-uniscribe.h index bb99f39..2758dab 100644 --- a/src/hb-uniscribe.h +++ b/src/hb-uniscribe.h
@@ -34,6 +34,10 @@ HB_BEGIN_DECLS +/* Must call before all other funtions in this file. Idempotent. */ +hb_bool_t +hb_uniscribe_font_ensure (hb_font_t *font); + LOGFONTW * hb_uniscribe_font_get_logfontw (hb_font_t *font);