From cfe9882610489e1b917e09a74dfbf6bbba2e4a57 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 27 Jul 2012 03:06:30 -0400 Subject: [PATCH] Add hb_ot_layout_ensure() and hb_uniscribe_font_ensure() --- src/hb-ot-layout.cc | 7 +++++++ src/hb-ot-layout.h | 6 ++++++ src/hb-shape-plan.cc | 22 ++-------------------- src/hb-shaper-private.hh | 18 ++++++++++++++++++ src/hb-uniscribe.cc | 11 +++++++++++ src/hb-uniscribe.h | 4 ++++ 6 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index dff3673f6..eb39c657c 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -38,6 +38,13 @@ #include +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 cf178b761..af234789d 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -42,6 +42,12 @@ HB_BEGIN_DECLS #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 1820f61a8..b0a893799 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 @@ hb_shape_plan_plan (hb_shape_plan_t *shape_plan, #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 @@ hb_shape_plan_execute (hb_shape_plan *shape_plan, #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 e50d86985..186318da0 100644 --- a/src/hb-shaper-private.hh +++ b/src/hb-shaper-private.hh @@ -86,5 +86,23 @@ struct hb_shaper_data_t { 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 4368f6824..7d06a6b0b 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -56,6 +56,17 @@ DWORD GetFontData( */ +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 bb99f3987..2758dab4d 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);