src/hb-common.cc | 54 ------------------------------------ src/hb-font.cc | 19 +++--------- src/hb-ft.cc | 7 +++- src/hb-object-private.hh | 66 ++++++++++++++++++++++++++++++++++++++++++++ src/hb-ot-layout-private.hh | 60 ++++++++++++++++++++++------------------ src/hb-ot-layout.cc | 28 ++++++++++++++++-- src/hb-private.hh | 66 -------------------------------------------- 7 files changed, 134 insertions(+), 166 deletions(-)
New commits: commit d292885893395dcb345dce1010e5c8628a715ef4 Author: Behdad Esfahbod <[email protected]> Date: Tue May 3 01:03:53 2011 -0400 [ft] Fix font->face handling Don't use _cached() diff --git a/src/hb-ft.cc b/src/hb-ft.cc index e4e77f5..9d1dbd1 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -238,11 +238,14 @@ hb_ft_font_create (FT_Face ft_face, hb_destroy_func_t destroy) { hb_font_t *font; + hb_face_t *face; - font = hb_font_create (hb_ft_face_create_cached (ft_face)); + face = hb_ft_face_create (ft_face, destroy); + font = hb_font_create (face); + hb_face_destroy (face); hb_font_set_funcs (font, hb_ft_get_font_funcs (), - ft_face, destroy); + ft_face, NULL); hb_font_set_scale (font, ((uint64_t) ft_face->size->metrics.x_scale * (uint64_t) ft_face->units_per_EM) >> 16, ((uint64_t) ft_face->size->metrics.y_scale * (uint64_t) ft_face->units_per_EM) >> 16); commit 2000179487b49e0d504ec127450dc6fcb5568cec Author: Behdad Esfahbod <[email protected]> Date: Tue May 3 00:49:06 2011 -0400 Move Win32 thread-safety stuff to hb-object-private.h The Win32 definitions for LONG, ULONG, etc conflicts with hb-open-type.h. Avoid that by making sure hb-object-private.h and hb-open-type.h are not included in the same compilation unit. diff --git a/src/hb-common.cc b/src/hb-common.cc index 2f5e89b..b75146d 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -263,58 +263,4 @@ hb_script_get_horizontal_direction (hb_script_t script) } - -/* System stuff */ - - -#ifdef _MSC_VER - -#include <Windows.h> - -hb_mutex_t -_hb_win32_mutex_create () -{ - hb_mutex_t m; - _hb_win32_mutex_init (&m); - return m; -} - -void -_hb_win32_mutex_init (hb_mutex_t *m) -{ - LPCRITICAL_SECTION lpcs = (LPCRITICAL_SECTION) calloc(1, sizeof(CRITICAL_SECTION)); - InitializeCriticalSection (lpcs); - *m = (void*) lpcs; -} - -void -_hb_win32_mutex_lock (hb_mutex_t m) -{ - EnterCriticalSection ((LPCRITICAL_SECTION) m); -} - -int -_hb_win32_mutex_trylock (hb_mutex_t m) -{ - return TryEnterCriticalSection ((LPCRITICAL_SECTION) m); -} - -void -_hb_win32_mutex_unlock (hb_mutex_t m) -{ - LeaveCriticalSection ((LPCRITICAL_SECTION) m); -} - -void -_hb_win32_mutex_free (hb_mutex_t *m) -{ - LPCRITICAL_SECTION lpcs = (LPCRITICAL_SECTION) *m; - DeleteCriticalSection (lpcs); - free(lpcs); - *m = 0; -} - -#endif - - HB_END_DECLS diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh index 47cef7e..d77b6a5 100644 --- a/src/hb-object-private.hh +++ b/src/hb-object-private.hh @@ -44,6 +44,72 @@ HB_BEGIN_DECLS #endif +/* atomic_int and mutex */ + +/* We need external help for these */ + +#ifdef HAVE_GLIB + +#include <glib.h> + +typedef volatile int hb_atomic_int_t; +#define hb_atomic_int_fetch_and_add(AI, V) g_atomic_int_exchange_and_add (&(AI), V) +#define hb_atomic_int_get(AI) g_atomic_int_get (&(AI)) +#define hb_atomic_int_set(AI, V) g_atomic_int_set (&(AI), V) + +typedef GStaticMutex hb_mutex_t; +#define HB_MUTEX_INIT G_STATIC_MUTEX_INIT +#define hb_mutex_init(M) g_static_mutex_init (&(M)) +#define hb_mutex_lock(M) g_static_mutex_lock (&(M)) +#define hb_mutex_trylock(M) g_static_mutex_trylock (&(M)) +#define hb_mutex_unlock(M) g_static_mutex_unlock (&(M)) +#define hb_mutex_free(M) g_static_mutex_free (&(M)) + +#else + +#ifdef _MSC_VER + +#include <intrin.h> + +typedef long hb_atomic_int_t; +#define hb_atomic_int_fetch_and_add(AI, V) _InterlockedExchangeAdd (&(AI), V) +#define hb_atomic_int_get(AI) (_ReadBarrier (), (AI)) +#define hb_atomic_int_set(AI, V) ((void) _InterlockedExchange (&(AI), (V))) + +#include <Windows.h> + +typedef CRITICAL_SECTION hb_mutex_t; +#define HB_MUTEX_INIT { NULL, 0, 0, NULL, NULL, 0 } +#define hb_mutex_init(M) InitializeCriticalSection (&(M)) +#define hb_mutex_lock(M) EnterCriticalSection (&(M)) +#define hb_mutex_trylock(M) TryEnterCriticalSection (&(M)) +#define hb_mutex_unlock(M) LeaveCriticalSection (&(M)) +#define hb_mutex_free(M) DeleteCriticalSection (&(M)) + +#else + +#warning "Could not find any system to define platform macros, library will NOT be thread-safe" + +typedef volatile int hb_atomic_int_t; +#define hb_atomic_int_fetch_and_add(AI, V) ((AI) += (V), (AI) - (V)) +#define hb_atomic_int_get(AI) (AI) +#define hb_atomic_int_set(AI, V) ((void) ((AI) = (V))) + +typedef volatile int hb_mutex_t; +#define HB_MUTEX_INIT 0 +#define hb_mutex_init(M) ((void) ((M) = 0)) +#define hb_mutex_lock(M) ((void) ((M) = 1)) +#define hb_mutex_trylock(M) ((M) = 1, 1) +#define hb_mutex_unlock(M) ((void) ((M) = 0)) +#define hb_mutex_free(M) ((void) ((M) = 2)) + +#endif + +#endif + + + + /* reference_count */ typedef struct { diff --git a/src/hb-private.hh b/src/hb-private.hh index cac434a..1d40d66 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -221,72 +221,6 @@ _hb_unsigned_int_mul_overflows (unsigned int count, unsigned int size) typedef int (*hb_compare_func_t) (const void *, const void *); -/* We need external help for these */ - -#ifdef HAVE_GLIB - -#include <glib.h> - -typedef volatile int hb_atomic_int_t; -#define hb_atomic_int_fetch_and_add(AI, V) g_atomic_int_exchange_and_add (&(AI), V) -#define hb_atomic_int_get(AI) g_atomic_int_get (&(AI)) -#define hb_atomic_int_set(AI, V) g_atomic_int_set (&(AI), V) - -typedef GStaticMutex hb_mutex_t; -#define HB_MUTEX_INIT G_STATIC_MUTEX_INIT -#define hb_mutex_init(M) g_static_mutex_init (&(M)) -#define hb_mutex_lock(M) g_static_mutex_lock (&(M)) -#define hb_mutex_trylock(M) g_static_mutex_trylock (&(M)) -#define hb_mutex_unlock(M) g_static_mutex_unlock (&(M)) -#define hb_mutex_free(M) g_static_mutex_free (&(M)) - -#else - -#ifdef _MSC_VER - -#include <intrin.h> - -typedef long hb_atomic_int_t; -#define hb_atomic_int_fetch_and_add(AI, V) _InterlockedExchangeAdd (&(AI), V) -#define hb_atomic_int_get(AI) (_ReadBarrier (), (AI)) -#define hb_atomic_int_set(AI, V) ((void) _InterlockedExchange (&(AI), (V))) - -typedef void * hb_mutex_t; -extern HB_INTERNAL hb_mutex_t _hb_win32_mutex_create (void); -extern HB_INTERNAL void _hb_win32_mutex_init (hb_mutex_t *m); -extern HB_INTERNAL void _hb_win32_mutex_lock (hb_mutex_t m); -extern HB_INTERNAL int _hb_win32_mutex_trylock (hb_mutex_t m); -extern HB_INTERNAL void _hb_win32_mutex_unlock (hb_mutex_t m); -extern HB_INTERNAL void _hb_win32_mutex_free (hb_mutex_t *m); -#define HB_MUTEX_INIT _hb_win32_mutex_create () -#define hb_mutex_init(M) _hb_win32_mutex_init (&(M)) -#define hb_mutex_lock(M) _hb_win32_mutex_lock ((M)) -#define hb_mutex_trylock(M) _hb_win32_mutex_trylock ((M)) -#define hb_mutex_unlock(M) _hb_win32_mutex_unlock ((M)) -#define hb_mutex_free(M) _hb_win32_mutex_free (&(M)) - -#else - -#warning "Could not find any system to define platform macros, library will NOT be thread-safe" - -typedef volatile int hb_atomic_int_t; -#define hb_atomic_int_fetch_and_add(AI, V) ((AI) += (V), (AI) - (V)) -#define hb_atomic_int_get(AI) (AI) -#define hb_atomic_int_set(AI, V) ((void) ((AI) = (V))) - -typedef volatile int hb_mutex_t; -#define HB_MUTEX_INIT 0 -#define hb_mutex_init(M) ((void) ((M) = 0)) -#define hb_mutex_lock(M) ((void) ((M) = 1)) -#define hb_mutex_trylock(M) ((M) = 1, 1) -#define hb_mutex_unlock(M) ((void) ((M) = 0)) -#define hb_mutex_free(M) ((void) ((M) = 2)) - -#endif - -#endif - - HB_END_DECLS commit 266b34418c9bbe23ccaf29cb354b58c465fa3b22 Author: Behdad Esfahbod <[email protected]> Date: Tue May 3 00:35:53 2011 -0400 Refactor to keep hb-object-private.h and hb-open-type.h separate Needed to be able to include <Windows.h> from hb-object-private.h. diff --git a/src/hb-font.cc b/src/hb-font.cc index 1242375..0a58377 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -26,12 +26,12 @@ #include "hb-private.hh" +#include "hb-ot-layout-private.hh" + #include "hb-font-private.hh" #include "hb-blob-private.hh" #include "hb-open-file-private.hh" -#include "hb-ot-layout-private.hh" - #include <string.h> HB_BEGIN_DECLS @@ -293,9 +293,6 @@ static hb_face_t _hb_face_nil = { NULL, /* user_data */ NULL, /* destroy */ - NULL, /* head_blob */ - NULL, /* head_table */ - NULL /* ot_layout */ }; @@ -317,10 +314,7 @@ hb_face_create_for_tables (hb_get_table_func_t get_table, face->user_data = user_data; face->destroy = destroy; - face->ot_layout = _hb_ot_layout_new (face); - - face->head_blob = Sanitizer<head>::sanitize (hb_face_reference_table (face, HB_OT_TAG_head)); - face->head_table = Sanitizer<head>::lock_instance (face->head_blob); + face->ot_layout = _hb_ot_layout_create (face); return face; } @@ -399,10 +393,7 @@ hb_face_destroy (hb_face_t *face) { if (!hb_object_destroy (face)) return; - _hb_ot_layout_free (face->ot_layout); - - hb_blob_unlock (face->head_blob); - hb_blob_destroy (face->head_blob); + _hb_ot_layout_destroy (face->ot_layout); if (face->destroy) face->destroy (face->user_data); @@ -446,7 +437,7 @@ hb_face_reference_table (hb_face_t *face, unsigned int hb_face_get_upem (hb_face_t *face) { - return (face->head_table ? face->head_table : &Null(head))->get_upem (); + return _hb_ot_layout_get_upem (face); } diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh index 7b72515..5870248 100644 --- a/src/hb-ot-layout-private.hh +++ b/src/hb-ot-layout-private.hh @@ -30,7 +30,6 @@ #include "hb-private.hh" #include "hb-ot-layout.h" -#include "hb-ot-head-private.hh" #include "hb-font-private.hh" #include "hb-buffer-private.hh" @@ -38,10 +37,13 @@ HB_BEGIN_DECLS +/* + * GDEF + */ + /* buffer var allocations */ #define props_cache() var1.u16[1] /* glyph_props cache */ - /* XXX cleanup */ typedef enum { HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED = 0x0001, @@ -52,6 +54,31 @@ typedef enum { } hb_ot_layout_glyph_class_t; +HB_INTERNAL unsigned int +_hb_ot_layout_get_glyph_property (hb_face_t *face, + hb_glyph_info_t *info); + +HB_INTERNAL hb_bool_t +_hb_ot_layout_check_glyph_property (hb_face_t *face, + hb_glyph_info_t *ginfo, + unsigned int lookup_props, + unsigned int *property_out); + +HB_INTERNAL hb_bool_t +_hb_ot_layout_skip_mark (hb_face_t *face, + hb_glyph_info_t *ginfo, + unsigned int lookup_props, + unsigned int *property_out); + + +/* + * head + */ + +HB_INTERNAL unsigned int +_hb_ot_layout_get_upem (hb_face_t *face); + + /* * hb_ot_layout_t */ @@ -61,10 +88,12 @@ struct hb_ot_layout_t hb_blob_t *gdef_blob; hb_blob_t *gsub_blob; hb_blob_t *gpos_blob; + hb_blob_t *head_blob; const struct GDEF *gdef; const struct GSUB *gsub; const struct GPOS *gpos; + const struct head *head; }; struct hb_ot_layout_context_t @@ -77,36 +106,15 @@ struct hb_ot_layout_context_t inline hb_position_t scale_y (int16_t v) { return scale (v, this->font->y_scale); } private: - inline hb_position_t scale (int16_t v, int scale) { return v * (int64_t) scale / this->face->head_table->get_upem (); } + inline hb_position_t scale (int16_t v, int scale) { return v * (int64_t) scale / _hb_ot_layout_get_upem (this->face); } }; HB_INTERNAL hb_ot_layout_t * -_hb_ot_layout_new (hb_face_t *face); +_hb_ot_layout_create (hb_face_t *face); HB_INTERNAL void -_hb_ot_layout_free (hb_ot_layout_t *layout); - - -/* - * GDEF - */ - -HB_INTERNAL unsigned int -_hb_ot_layout_get_glyph_property (hb_face_t *face, - hb_glyph_info_t *info); - -HB_INTERNAL hb_bool_t -_hb_ot_layout_check_glyph_property (hb_face_t *face, - hb_glyph_info_t *ginfo, - unsigned int lookup_props, - unsigned int *property_out); - -HB_INTERNAL hb_bool_t -_hb_ot_layout_skip_mark (hb_face_t *face, - hb_glyph_info_t *ginfo, - unsigned int lookup_props, - unsigned int *property_out); +_hb_ot_layout_destroy (hb_ot_layout_t *layout); HB_END_DECLS diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 03a9455..7383e9f 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -33,6 +33,7 @@ #include "hb-ot-layout-gdef-private.hh" #include "hb-ot-layout-gsub-private.hh" #include "hb-ot-layout-gpos-private.hh" +#include "hb-ot-head-private.hh" #include <stdlib.h> @@ -42,7 +43,7 @@ HB_BEGIN_DECLS hb_ot_layout_t * -_hb_ot_layout_new (hb_face_t *face) +_hb_ot_layout_create (hb_face_t *face) { /* Remove this object altogether */ hb_ot_layout_t *layout = (hb_ot_layout_t *) calloc (1, sizeof (hb_ot_layout_t)); @@ -56,19 +57,24 @@ _hb_ot_layout_new (hb_face_t *face) layout->gpos_blob = Sanitizer<GPOS>::sanitize (hb_face_reference_table (face, HB_OT_TAG_GPOS)); layout->gpos = Sanitizer<GPOS>::lock_instance (layout->gpos_blob); + layout->head_blob = Sanitizer<head>::sanitize (hb_face_reference_table (face, HB_OT_TAG_head)); + layout->head = Sanitizer<head>::lock_instance (layout->head_blob); + return layout; } void -_hb_ot_layout_free (hb_ot_layout_t *layout) +_hb_ot_layout_destroy (hb_ot_layout_t *layout) { hb_blob_unlock (layout->gdef_blob); hb_blob_unlock (layout->gsub_blob); hb_blob_unlock (layout->gpos_blob); + hb_blob_unlock (layout->head_blob); hb_blob_destroy (layout->gdef_blob); hb_blob_destroy (layout->gsub_blob); hb_blob_destroy (layout->gpos_blob); + hb_blob_destroy (layout->head_blob); free (layout); } @@ -78,18 +84,21 @@ _get_gdef (hb_face_t *face) { return likely (face->ot_layout && face->ot_layout->gdef) ? *face->ot_layout->gdef : Null(GDEF); } - static inline const GSUB& _get_gsub (hb_face_t *face) { return likely (face->ot_layout && face->ot_layout->gsub) ? *face->ot_layout->gsub : Null(GSUB); } - static inline const GPOS& _get_gpos (hb_face_t *face) { return likely (face->ot_layout && face->ot_layout->gpos) ? *face->ot_layout->gpos : Null(GPOS); } +static inline const head& +_get_head (hb_face_t *face) +{ + return likely (face->ot_layout && face->ot_layout->head) ? *face->ot_layout->head : Null(head); +} /* @@ -486,4 +495,15 @@ hb_ot_layout_position_finish (hb_buffer_t *buffer) } +/* + * head + */ + +unsigned int +_hb_ot_layout_get_upem (hb_face_t *face) +{ + return _get_head (face).get_upem (); +} + + HB_END_DECLS _______________________________________________ HarfBuzz mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/harfbuzz
