[HarfBuzz] harfbuzz-ng: Branch 'master' - 6 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Mon May 2 21:20:23 PDT 2011


 src/hb-blob.cc                   |   13 ++++-----
 src/hb-common.cc                 |   54 +++++++++++++++++++++++++++++++++++++++
 src/hb-font-private.hh           |    2 +
 src/hb-font.cc                   |   48 ++++++++++++++++++++--------------
 src/hb-font.h                    |   26 ++++++++++--------
 src/hb-ft.cc                     |    7 -----
 src/hb-ot-layout-gdef-private.hh |    2 -
 src/hb-ot-layout-gpos-private.hh |    2 -
 src/hb-ot-layout.cc              |   10 ++-----
 src/hb-ot-layout.h               |    2 -
 src/hb-ot-map-private.hh         |    2 -
 src/hb-ot-shape.cc               |   23 +++++++---------
 src/hb-ot-shape.h                |    1 
 src/hb-private.hh                |   48 +++++++++++++++++++++++++---------
 src/hb-shape.cc                  |   18 +------------
 src/hb-shape.h                   |    1 
 src/hb-view.cc                   |    4 --
 test/test-object.c               |    7 +++--
 18 files changed, 168 insertions(+), 102 deletions(-)

New commits:
commit d4141a44b97377a65e6d2a3e03b3709307af38c1
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue May 3 00:19:18 2011 -0400

    [blob] Implement sub_blob() in terms of create()
    
    Fixes problem with uninitialized sub_blob->mutex among other things.
    
    Reported by Bradley Grainger.

diff --git a/src/hb-blob.cc b/src/hb-blob.cc
index bcbfa34..8d6d746 100644
--- a/src/hb-blob.cc
+++ b/src/hb-blob.cc
@@ -127,16 +127,14 @@ hb_blob_create_sub_blob (hb_blob_t    *parent,
 
   pdata = hb_blob_lock (parent);
 
-  blob->data = pdata + offset;
-  blob->length = MIN (length, parent->length - offset);
-
   hb_mutex_lock (parent->lock);
-  blob->mode = parent->mode;
+  blob = hb_blob_create (pdata + offset,
+			 MIN (length, parent->length - offset),
+			 parent->mode,
+			 hb_blob_reference (parent),
+			 (hb_destroy_func_t) _hb_blob_unlock_and_destroy);
   hb_mutex_unlock (parent->lock);
 
-  blob->user_data = hb_blob_reference (parent);
-  blob->destroy = (hb_destroy_func_t) _hb_blob_unlock_and_destroy;
-
   return blob;
 }
 
commit fc52e9e44c2fe84d63f18dc0098720830f0b467d
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue May 3 00:09:16 2011 -0400

    Implement win32 thread-safety stuff
    
    Patch from Bradley Grainger.

diff --git a/src/hb-common.cc b/src/hb-common.cc
index b75146d..2f5e89b 100644
--- a/src/hb-common.cc
+++ b/src/hb-common.cc
@@ -263,4 +263,58 @@ 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-private.hh b/src/hb-private.hh
index a45fece..cac434a 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -243,13 +243,31 @@ typedef GStaticMutex hb_mutex_t;
 #else
 
 #ifdef _MSC_VER
-#define _HB__STR2__(x) #x
-#define _HB__STR1__(x) _HB__STR2__(x)
-#define _HB__LOC__ __FILE__ "("_HB__STR1__(__LINE__)") : Warning Msg: "
-#pragma message(_HB__LOC__"Could not find any system to define platform macros, library will NOT be thread-safe")
+
+#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"
-#endif
 
 typedef volatile int hb_atomic_int_t;
 #define hb_atomic_int_fetch_and_add(AI, V)	((AI) += (V), (AI) - (V))
@@ -266,6 +284,8 @@ typedef volatile int hb_mutex_t;
 
 #endif
 
+#endif
+
 
 HB_END_DECLS
 
commit f55272ecde857c116f97a3195f3abd1df3be4b86
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon May 2 20:57:28 2011 -0400

    Add hb_mutex_free() and use it
    
    Based on patch by Bradley Grainger.

diff --git a/src/hb-blob.cc b/src/hb-blob.cc
index db12758..bcbfa34 100644
--- a/src/hb-blob.cc
+++ b/src/hb-blob.cc
@@ -158,6 +158,7 @@ hb_blob_destroy (hb_blob_t *blob)
   if (!hb_object_destroy (blob)) return;
 
   _hb_blob_destroy_user_data (blob);
+  hb_mutex_free (blob->lock);
 
   free (blob);
 }
diff --git a/src/hb-private.hh b/src/hb-private.hh
index 445f602..a45fece 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -234,10 +234,11 @@ typedef volatile int hb_atomic_int_t;
 
 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_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
 
@@ -257,10 +258,11 @@ typedef volatile int hb_atomic_int_t;
 
 typedef volatile int hb_mutex_t;
 #define HB_MUTEX_INIT				0
-#define hb_mutex_init(M)			HB_STMT_START { (M) = 0; } HB_STMT_END
-#define hb_mutex_lock(M)			HB_STMT_START { (M) = 1; } HB_STMT_END
+#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)			HB_STMT_START { (M) = 0; } HB_STMT_END
+#define hb_mutex_unlock(M)			((void) ((M) = 0))
+#define hb_mutex_free(M)			((void) ((M) = 2))
 
 #endif
 
commit 8d5186484b28b5f629b523e067d7d5166eec557a
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon May 2 20:52:21 2011 -0400

    Cosmetic

diff --git a/src/hb-private.hh b/src/hb-private.hh
index 02fc099..445f602 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -253,7 +253,7 @@ typedef GStaticMutex hb_mutex_t;
 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)		HB_STMT_START { (AI) = (V); } HB_STMT_END
+#define hb_atomic_int_set(AI, V)		((void) ((AI) = (V)))
 
 typedef volatile int hb_mutex_t;
 #define HB_MUTEX_INIT				0
commit 72657e4ce757dcb055a8db7291b68f96f0d34bfb
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon May 2 20:46:32 2011 -0400

    [API] Make hb_font_create() take a face and reference it

diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh
index b028d5f..9e1ee51 100644
--- a/src/hb-font-private.hh
+++ b/src/hb-font-private.hh
@@ -83,6 +83,8 @@ struct _hb_face_t {
 struct _hb_font_t {
   hb_object_header_t header;
 
+  hb_face_t *face;
+
   unsigned int x_scale;
   unsigned int y_scale;
 
diff --git a/src/hb-font.cc b/src/hb-font.cc
index 2de3950..1242375 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -43,7 +43,6 @@ HB_BEGIN_DECLS
 
 static hb_codepoint_t
 hb_font_get_glyph_nil (hb_font_t *font HB_UNUSED,
-		       hb_face_t *face HB_UNUSED,
 		       const void *user_data HB_UNUSED,
 		       hb_codepoint_t unicode HB_UNUSED,
 		       hb_codepoint_t variation_selector HB_UNUSED)
@@ -51,7 +50,6 @@ hb_font_get_glyph_nil (hb_font_t *font HB_UNUSED,
 
 static void
 hb_font_get_glyph_advance_nil (hb_font_t *font HB_UNUSED,
-			       hb_face_t *face HB_UNUSED,
 			       const void *user_data HB_UNUSED,
 			       hb_codepoint_t glyph HB_UNUSED,
 			       hb_position_t *x_advance HB_UNUSED,
@@ -60,7 +58,6 @@ hb_font_get_glyph_advance_nil (hb_font_t *font HB_UNUSED,
 
 static void
 hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
-			       hb_face_t *face HB_UNUSED,
 			       const void *user_data HB_UNUSED,
 			       hb_codepoint_t glyph HB_UNUSED,
 			       hb_glyph_extents_t *extents HB_UNUSED)
@@ -68,7 +65,6 @@ hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
 
 static hb_bool_t
 hb_font_get_contour_point_nil (hb_font_t *font HB_UNUSED,
-			       hb_face_t *face HB_UNUSED,
 			       const void *user_data HB_UNUSED,
 			       unsigned int point_index HB_UNUSED,
 			       hb_codepoint_t glyph HB_UNUSED,
@@ -78,7 +74,6 @@ hb_font_get_contour_point_nil (hb_font_t *font HB_UNUSED,
 
 static hb_position_t
 hb_font_get_kerning_nil (hb_font_t *font HB_UNUSED,
-			 hb_face_t *face HB_UNUSED,
 			 const void *user_data HB_UNUSED,
 			 hb_codepoint_t first_glyph HB_UNUSED,
 			 hb_codepoint_t second_glyph HB_UNUSED)
@@ -241,48 +236,48 @@ hb_font_funcs_get_kerning_func (hb_font_funcs_t *ffuncs)
 
 
 hb_codepoint_t
-hb_font_get_glyph (hb_font_t *font, hb_face_t *face,
+hb_font_get_glyph (hb_font_t *font,
 		   hb_codepoint_t unicode, hb_codepoint_t variation_selector)
 {
-  return font->klass->v.get_glyph (font, face, font->user_data,
+  return font->klass->v.get_glyph (font, font->user_data,
 				   unicode, variation_selector);
 }
 
 void
-hb_font_get_glyph_advance (hb_font_t *font, hb_face_t *face,
+hb_font_get_glyph_advance (hb_font_t *font,
 			   hb_codepoint_t glyph,
 			   hb_position_t *x_advance, hb_position_t *y_advance)
 {
   *x_advance = *y_advance = 0;
-  return font->klass->v.get_glyph_advance (font, face, font->user_data,
+  return font->klass->v.get_glyph_advance (font, font->user_data,
 					   glyph, x_advance, y_advance);
 }
 
 void
-hb_font_get_glyph_extents (hb_font_t *font, hb_face_t *face,
+hb_font_get_glyph_extents (hb_font_t *font,
 			   hb_codepoint_t glyph, hb_glyph_extents_t *extents)
 {
   memset (extents, 0, sizeof (*extents));
-  return font->klass->v.get_glyph_extents (font, face, font->user_data,
+  return font->klass->v.get_glyph_extents (font, font->user_data,
 					   glyph, extents);
 }
 
 hb_bool_t
-hb_font_get_contour_point (hb_font_t *font, hb_face_t *face,
+hb_font_get_contour_point (hb_font_t *font,
 			   unsigned int point_index,
 			   hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y)
 {
   *x = 0; *y = 0;
-  return font->klass->v.get_contour_point (font, face, font->user_data,
+  return font->klass->v.get_contour_point (font, font->user_data,
 					   point_index,
 					   glyph, x, y);
 }
 
 hb_position_t
-hb_font_get_kerning (hb_font_t *font, hb_face_t *face,
+hb_font_get_kerning (hb_font_t *font,
 		     hb_codepoint_t first_glyph, hb_codepoint_t second_glyph)
 {
-  return font->klass->v.get_kerning (font, face, font->user_data,
+  return font->klass->v.get_kerning (font, font->user_data,
 				     first_glyph, second_glyph);
 }
 
@@ -462,6 +457,8 @@ hb_face_get_upem (hb_face_t *face)
 static hb_font_t _hb_font_nil = {
   HB_OBJECT_HEADER_STATIC,
 
+  &_hb_face_nil,
+
   0, /* x_scale */
   0, /* y_scale */
 
@@ -474,13 +471,18 @@ static hb_font_t _hb_font_nil = {
 };
 
 hb_font_t *
-hb_font_create (void)
+hb_font_create (hb_face_t *face)
 {
   hb_font_t *font;
 
+  if (unlikely (!face))
+    face = &_hb_face_nil;
+  if (unlikely (hb_object_is_inert (face)))
+    return &_hb_font_nil;
   if (!(font = hb_object_create<hb_font_t> ()))
     return &_hb_font_nil;
 
+  font->face = hb_face_reference (face);
   font->klass = &_hb_font_funcs_nil;
 
   return font;
@@ -497,6 +499,7 @@ hb_font_destroy (hb_font_t *font)
 {
   if (!hb_object_destroy (font)) return;
 
+  hb_face_destroy (font->face);
   hb_font_funcs_destroy (font->klass);
   if (font->destroy)
     font->destroy (font->user_data);
@@ -521,6 +524,13 @@ hb_font_get_user_data (hb_font_t          *font,
 }
 
 
+hb_face_t *
+hb_font_get_face (hb_font_t *font)
+{
+  return font->face;
+}
+
+
 void
 hb_font_set_funcs (hb_font_t         *font,
 		   hb_font_funcs_t   *klass,
diff --git a/src/hb-font.h b/src/hb-font.h
index c26ab01..e8e344d 100644
--- a/src/hb-font.h
+++ b/src/hb-font.h
@@ -121,18 +121,18 @@ typedef struct _hb_glyph_extents_t
     hb_position_t height;
 } hb_glyph_extents_t;
 
-typedef hb_codepoint_t (*hb_font_get_glyph_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
+typedef hb_codepoint_t (*hb_font_get_glyph_func_t) (hb_font_t *font, const void *user_data,
 						    hb_codepoint_t unicode, hb_codepoint_t variation_selector);
-typedef void (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
+typedef void (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, const void *user_data,
 						  hb_codepoint_t glyph,
 						  hb_position_t *x_advance, hb_position_t *y_advance);
-typedef void (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
+typedef void (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, const void *user_data,
 						  hb_codepoint_t glyph,
 						  hb_glyph_extents_t *extents);
-typedef hb_bool_t (*hb_font_get_contour_point_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
+typedef hb_bool_t (*hb_font_get_contour_point_func_t) (hb_font_t *font, const void *user_data,
 						       unsigned int point_index, hb_codepoint_t glyph,
 						       hb_position_t *x, hb_position_t *y);
-typedef hb_position_t (*hb_font_get_kerning_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
+typedef hb_position_t (*hb_font_get_kerning_func_t) (hb_font_t *font, const void *user_data,
 						     hb_codepoint_t first_glyph, hb_codepoint_t second_glyph);
 
 
@@ -176,26 +176,26 @@ hb_font_funcs_get_kerning_func (hb_font_funcs_t *ffuncs);
 
 
 hb_codepoint_t
-hb_font_get_glyph (hb_font_t *font, hb_face_t *face,
+hb_font_get_glyph (hb_font_t *font,
 		   hb_codepoint_t unicode, hb_codepoint_t variation_selector);
 
 void
-hb_font_get_glyph_advance (hb_font_t *font, hb_face_t *face,
+hb_font_get_glyph_advance (hb_font_t *font,
 			   hb_codepoint_t glyph,
 			   hb_position_t *x_advance, hb_position_t *y_advance);
 
 void
-hb_font_get_glyph_extents (hb_font_t *font, hb_face_t *face,
+hb_font_get_glyph_extents (hb_font_t *font,
 			   hb_codepoint_t glyph,
 			   hb_glyph_extents_t *extents);
 
 hb_bool_t
-hb_font_get_contour_point (hb_font_t *font, hb_face_t *face,
+hb_font_get_contour_point (hb_font_t *font,
 			   unsigned int point_index, hb_codepoint_t glyph,
 			   hb_position_t *x, hb_position_t *y);
 
 hb_position_t
-hb_font_get_kerning (hb_font_t *font, hb_face_t *face,
+hb_font_get_kerning (hb_font_t *font,
 		     hb_codepoint_t first_glyph, hb_codepoint_t second_glyph);
 
 
@@ -206,7 +206,7 @@ hb_font_get_kerning (hb_font_t *font, hb_face_t *face,
 /* Fonts are very light-weight objects */
 
 hb_font_t *
-hb_font_create (void);
+hb_font_create (hb_face_t *face);
 
 hb_font_t *
 hb_font_reference (hb_font_t *font);
@@ -226,6 +226,10 @@ hb_font_get_user_data (hb_font_t          *font,
 		       hb_user_data_key_t *key);
 
 
+hb_face_t *
+hb_font_get_face (hb_font_t *font);
+
+
 void
 hb_font_set_funcs (hb_font_t         *font,
 		   hb_font_funcs_t   *klass,
diff --git a/src/hb-ft.cc b/src/hb-ft.cc
index 4afcd6c..e4e77f5 100644
--- a/src/hb-ft.cc
+++ b/src/hb-ft.cc
@@ -38,7 +38,6 @@ HB_BEGIN_DECLS
 
 static hb_codepoint_t
 hb_ft_get_glyph (hb_font_t *font HB_UNUSED,
-		 hb_face_t *face HB_UNUSED,
 		 const void *user_data,
 		 hb_codepoint_t unicode,
 		 hb_codepoint_t variation_selector)
@@ -58,7 +57,6 @@ hb_ft_get_glyph (hb_font_t *font HB_UNUSED,
 
 static void
 hb_ft_get_glyph_advance (hb_font_t *font HB_UNUSED,
-			 hb_face_t *face HB_UNUSED,
 			 const void *user_data,
 			 hb_codepoint_t glyph,
 			 hb_position_t *x_advance,
@@ -78,7 +76,6 @@ hb_ft_get_glyph_advance (hb_font_t *font HB_UNUSED,
 
 static void
 hb_ft_get_glyph_extents (hb_font_t *font HB_UNUSED,
-			 hb_face_t *face HB_UNUSED,
 			 const void *user_data,
 			 hb_codepoint_t glyph,
 			 hb_glyph_extents_t *extents)
@@ -100,7 +97,6 @@ hb_ft_get_glyph_extents (hb_font_t *font HB_UNUSED,
 
 static hb_bool_t
 hb_ft_get_contour_point (hb_font_t *font HB_UNUSED,
-			 hb_face_t *face HB_UNUSED,
 			 const void *user_data,
 			 unsigned int point_index,
 			 hb_codepoint_t glyph,
@@ -129,7 +125,6 @@ hb_ft_get_contour_point (hb_font_t *font HB_UNUSED,
 
 static hb_position_t
 hb_ft_get_kerning (hb_font_t *font HB_UNUSED,
-		   hb_face_t *face HB_UNUSED,
 		   const void *user_data,
 		   hb_codepoint_t first_glyph,
 		   hb_codepoint_t second_glyph)
@@ -244,7 +239,7 @@ hb_ft_font_create (FT_Face           ft_face,
 {
   hb_font_t *font;
 
-  font = hb_font_create ();
+  font = hb_font_create (hb_ft_face_create_cached (ft_face));
   hb_font_set_funcs (font,
 		     hb_ft_get_font_funcs (),
 		     ft_face, destroy);
diff --git a/src/hb-ot-layout-gdef-private.hh b/src/hb-ot-layout-gdef-private.hh
index 4d4ad93..010f819 100644
--- a/src/hb-ot-layout-gdef-private.hh
+++ b/src/hb-ot-layout-gdef-private.hh
@@ -121,7 +121,7 @@ struct CaretValueFormat2
   inline int get_caret_value (hb_ot_layout_context_t *c, hb_direction_t direction, hb_codepoint_t glyph_id) const
   {
     hb_position_t x, y;
-    if (hb_font_get_contour_point (c->font, c->face, caretValuePoint, glyph_id, &x, &y))
+    if (hb_font_get_contour_point (c->font, caretValuePoint, glyph_id, &x, &y))
       return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y;
     else
       return 0;
diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh
index 9d1f3be..1e277ce 100644
--- a/src/hb-ot-layout-gpos-private.hh
+++ b/src/hb-ot-layout-gpos-private.hh
@@ -243,7 +243,7 @@ struct AnchorFormat2
       hb_bool_t ret = false;
 
       if (x_ppem || y_ppem)
-	ret = hb_font_get_contour_point (layout->font, layout->face, anchorPoint, glyph_id, &cx, &cy);
+	ret = hb_font_get_contour_point (layout->font, anchorPoint, glyph_id, &cx, &cy);
       *x = x_ppem && ret ? cx : layout->scale_x (xCoordinate);
       *y = y_ppem && ret ? cy : layout->scale_y (yCoordinate);
   }
diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc
index e79f945..03a9455 100644
--- a/src/hb-ot-layout.cc
+++ b/src/hb-ot-layout.cc
@@ -193,7 +193,6 @@ hb_ot_layout_get_attach_points (hb_face_t      *face,
 
 unsigned int
 hb_ot_layout_get_ligature_carets (hb_font_t      *font,
-				  hb_face_t      *face,
 				  hb_direction_t  direction,
 				  hb_codepoint_t  glyph,
 				  unsigned int    start_offset,
@@ -202,8 +201,8 @@ hb_ot_layout_get_ligature_carets (hb_font_t      *font,
 {
   hb_ot_layout_context_t c;
   c.font = font;
-  c.face = face;
-  return _get_gdef (face).get_lig_carets (&c, direction, glyph, start_offset, caret_count, caret_array);
+  c.face = font->face;
+  return _get_gdef (c.face).get_lig_carets (&c, direction, glyph, start_offset, caret_count, caret_array);
 }
 
 /*
@@ -470,15 +469,14 @@ hb_ot_layout_position_start (hb_buffer_t  *buffer)
 
 hb_bool_t
 hb_ot_layout_position_lookup   (hb_font_t    *font,
-				hb_face_t    *face,
 				hb_buffer_t  *buffer,
 				unsigned int  lookup_index,
 				hb_mask_t     mask)
 {
   hb_ot_layout_context_t c;
   c.font = font;
-  c.face = face;
-  return _get_gpos (face).position_lookup (&c, buffer, lookup_index, mask);
+  c.face = font->face;
+  return _get_gpos (c.face).position_lookup (&c, buffer, lookup_index, mask);
 }
 
 void
diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h
index 9e58510..a6dbc61 100644
--- a/src/hb-ot-layout.h
+++ b/src/hb-ot-layout.h
@@ -59,7 +59,6 @@ hb_ot_layout_get_attach_points (hb_face_t      *face,
 /* Ligature caret positions */
 unsigned int
 hb_ot_layout_get_ligature_carets (hb_font_t      *font,
-				  hb_face_t      *face,
 				  hb_direction_t  direction,
 				  hb_codepoint_t  glyph,
 				  unsigned int    start_offset,
@@ -185,7 +184,6 @@ hb_ot_layout_position_start (hb_buffer_t  *buffer);
 
 hb_bool_t
 hb_ot_layout_position_lookup (hb_font_t    *font,
-			      hb_face_t    *face,
 			      hb_buffer_t  *buffer,
 			      unsigned int  lookup_index,
 			      hb_mask_t     mask);
diff --git a/src/hb-ot-map-private.hh b/src/hb-ot-map-private.hh
index 6296187..e0fe51b 100644
--- a/src/hb-ot-map-private.hh
+++ b/src/hb-ot-map-private.hh
@@ -121,7 +121,7 @@ struct hb_ot_map_t {
 
   inline void position (hb_font_t *font, hb_face_t *face, hb_buffer_t *buffer) const {
     for (unsigned int i = 0; i < lookup_count[1]; i++)
-      hb_ot_layout_position_lookup (font, face, buffer, lookup_maps[1][i].index, lookup_maps[1][i].mask);
+      hb_ot_layout_position_lookup (font, buffer, lookup_maps[1][i].index, lookup_maps[1][i].mask);
   }
 
   private:
diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index d6bfd65..e01f372 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -29,6 +29,8 @@
 #include "hb-ot-shape-private.hh"
 #include "hb-ot-shape-complex-private.hh"
 
+#include "hb-font-private.hh"
+
 HB_BEGIN_DECLS
 
 
@@ -209,7 +211,6 @@ hb_mirror_chars (hb_ot_shape_context_t *c)
 
 static void
 hb_map_glyphs (hb_font_t    *font,
-	       hb_face_t    *face,
 	       hb_buffer_t  *buffer)
 {
   if (unlikely (!buffer->len))
@@ -219,21 +220,21 @@ hb_map_glyphs (hb_font_t    *font,
   unsigned int count = buffer->len - 1;
   for (buffer->i = 0; buffer->i < count;) {
     if (unlikely (is_variation_selector (buffer->info[buffer->i + 1].codepoint))) {
-      buffer->replace_glyph (hb_font_get_glyph (font, face, buffer->info[buffer->i].codepoint, buffer->info[buffer->i + 1].codepoint));
+      buffer->replace_glyph (hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, buffer->info[buffer->i + 1].codepoint));
       buffer->i++;
     } else {
-      buffer->replace_glyph (hb_font_get_glyph (font, face, buffer->info[buffer->i].codepoint, 0));
+      buffer->replace_glyph (hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, 0));
     }
   }
   if (likely (buffer->i < buffer->len))
-    buffer->replace_glyph (hb_font_get_glyph (font, face, buffer->info[buffer->i].codepoint, 0));
+    buffer->replace_glyph (hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, 0));
   buffer->swap ();
 }
 
 static void
 hb_substitute_default (hb_ot_shape_context_t *c)
 {
-  hb_map_glyphs (c->font, c->face, c->buffer);
+  hb_map_glyphs (c->font, c->buffer);
 }
 
 static void
@@ -252,7 +253,7 @@ hb_position_default (hb_ot_shape_context_t *c)
 
   unsigned int count = c->buffer->len;
   for (unsigned int i = 0; i < count; i++) {
-    hb_font_get_glyph_advance (c->font, c->face, c->buffer->info[i].codepoint,
+    hb_font_get_glyph_advance (c->font, c->buffer->info[i].codepoint,
 			       &c->buffer->pos[i].x_advance,
 			       &c->buffer->pos[i].y_advance);
   }
@@ -271,7 +272,7 @@ hb_truetype_kern (hb_ot_shape_context_t *c)
   unsigned int count = c->buffer->len;
   for (unsigned int i = 1; i < count; i++) {
     hb_position_t kern, kern1, kern2;
-    kern = hb_font_get_kerning (c->font, c->face, c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint);
+    kern = hb_font_get_kerning (c->font, c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint);
     kern1 = kern >> 1;
     kern2 = kern - kern1;
     c->buffer->pos[i - 1].x_advance += kern1;
@@ -355,26 +356,24 @@ hb_ot_shape_plan_internal (hb_ot_shape_plan_t       *plan,
 void
 hb_ot_shape_execute (hb_ot_shape_plan_t *plan,
 		     hb_font_t          *font,
-		     hb_face_t          *face,
 		     hb_buffer_t        *buffer,
 		     const hb_feature_t *user_features,
 		     unsigned int        num_user_features)
 {
-  hb_ot_shape_context_t c = {plan, font, face, buffer, user_features, num_user_features};
+  hb_ot_shape_context_t c = {plan, font, font->face, buffer, user_features, num_user_features};
   hb_ot_shape_execute_internal (&c);
 }
 
 void
 hb_ot_shape (hb_font_t          *font,
-	     hb_face_t          *face,
 	     hb_buffer_t        *buffer,
 	     const hb_feature_t *features,
 	     unsigned int        num_features)
 {
   hb_ot_shape_plan_t plan;
 
-  hb_ot_shape_plan_internal (&plan, face, &buffer->props, features, num_features);
-  hb_ot_shape_execute (&plan, font, face, buffer, features, num_features);
+  hb_ot_shape_plan_internal (&plan, font->face, &buffer->props, features, num_features);
+  hb_ot_shape_execute (&plan, font, buffer, features, num_features);
 }
 
 
diff --git a/src/hb-ot-shape.h b/src/hb-ot-shape.h
index d6a3dc7..70a8172 100644
--- a/src/hb-ot-shape.h
+++ b/src/hb-ot-shape.h
@@ -35,7 +35,6 @@ HB_BEGIN_DECLS
 
 void
 hb_ot_shape (hb_font_t          *font,
-	     hb_face_t          *face,
 	     hb_buffer_t        *buffer,
 	     const hb_feature_t *features,
 	     unsigned int        num_features);
diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index 94b9118..cc711ea 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -41,29 +41,15 @@ HB_BEGIN_DECLS
 
 static void
 hb_shape_internal (hb_font_t          *font,
-		   hb_face_t          *face,
 		   hb_buffer_t        *buffer,
 		   const hb_feature_t *features,
 		   unsigned int        num_features)
 {
-#if 0 && defined(HAVE_GRAPHITE)
-  hb_blob_t *silf_blob;
-  silf_blob = hb_face_reference_table (face, HB_GRAPHITE_TAG_Silf);
-  if (hb_blob_get_length(silf_blob))
-  {
-    hb_graphite_shape(font, face, buffer, features, num_features);
-    hb_blob_destroy(silf_blob);
-    return;
-  }
-  hb_blob_destroy(silf_blob);
-#endif
-
-  hb_ot_shape (font, face, buffer, features, num_features);
+  hb_ot_shape (font, buffer, features, num_features);
 }
 
 void
 hb_shape (hb_font_t          *font,
-	  hb_face_t          *face,
 	  hb_buffer_t        *buffer,
 	  const hb_feature_t *features,
 	  unsigned int        num_features)
@@ -98,7 +84,7 @@ hb_shape (hb_font_t          *font,
     //buffer->props.language = hb_language_get_default ();
   }
 
-  hb_shape_internal (font, face, buffer, features, num_features);
+  hb_shape_internal (font, buffer, features, num_features);
 
   buffer->props = orig_props;
 }
diff --git a/src/hb-shape.h b/src/hb-shape.h
index 2c6755a..39383af 100644
--- a/src/hb-shape.h
+++ b/src/hb-shape.h
@@ -43,7 +43,6 @@ typedef struct _hb_feature_t {
 
 void
 hb_shape (hb_font_t          *font,
-	  hb_face_t          *face,
 	  hb_buffer_t        *buffer,
 	  const hb_feature_t *features,
 	  unsigned int        num_features);
diff --git a/src/hb-view.cc b/src/hb-view.cc
index 7d936dd..fac4109 100644
--- a/src/hb-view.cc
+++ b/src/hb-view.cc
@@ -344,7 +344,6 @@ _hb_cr_text_glyphs (cairo_t *cr,
 {
   cairo_scaled_font_t *scaled_font = cairo_get_scaled_font (cr);
   FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
-  hb_face_t *hb_face = hb_ft_face_create_cached (ft_face);
   hb_font_t *hb_font = hb_ft_font_create (ft_face, NULL);
   hb_buffer_t *hb_buffer;
   cairo_glyph_t *cairo_glyphs;
@@ -366,7 +365,7 @@ _hb_cr_text_glyphs (cairo_t *cr,
     len = strlen (text);
   hb_buffer_add_utf8 (hb_buffer, text, len, 0, len);
 
-  hb_shape (hb_font, hb_face, hb_buffer, features, num_features);
+  hb_shape (hb_font, hb_buffer, features, num_features);
 
   num_glyphs = hb_buffer_get_length (hb_buffer);
   hb_glyph = hb_buffer_get_glyph_infos (hb_buffer, NULL);
@@ -386,7 +385,6 @@ _hb_cr_text_glyphs (cairo_t *cr,
   cairo_glyphs[i].x = x * (1./64);
   hb_buffer_destroy (hb_buffer);
   hb_font_destroy (hb_font);
-  hb_face_destroy (hb_face);
   cairo_ft_scaled_font_unlock_face (scaled_font);
 
   if (pnum_glyphs)
diff --git a/test/test-object.c b/test/test-object.c
index 0fbabd8..297aa29 100644
--- a/test/test-object.c
+++ b/test/test-object.c
@@ -74,12 +74,15 @@ create_face_inert (void)
 static void *
 create_font (void)
 {
-  return hb_font_create ();
+  hb_face_t *face = (hb_face_t *) create_face ();
+  hb_font_t *font = hb_font_create (face);
+  hb_face_destroy (face);
+  return font;
 }
 static void *
 create_font_inert (void)
 {
-  return NULL;
+  return hb_font_create (create_face_inert ());
 }
 
 static void *
commit cec6611c5ce84d69d910bf7e9ec1fdd594398f9f
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon May 2 20:18:58 2011 -0400

    Protect NULL in a couple places

diff --git a/src/hb-font.cc b/src/hb-font.cc
index 91dde45..2de3950 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -312,7 +312,7 @@ hb_face_create_for_tables (hb_get_table_func_t  get_table,
 {
   hb_face_t *face;
 
-  if (!(face = hb_object_create<hb_face_t> ())) {
+  if (!get_table || !(face = hb_object_create<hb_face_t> ())) {
     if (destroy)
       destroy (user_data);
     return &_hb_face_nil;
@@ -379,7 +379,7 @@ hb_face_t *
 hb_face_create_for_data (hb_blob_t    *blob,
 			 unsigned int  index)
 {
-  if (unlikely (hb_object_is_inert (blob)))
+  if (unlikely (!blob || hb_object_is_inert (blob)))
     return &_hb_face_nil;
 
   hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (Sanitizer<OpenTypeFontFile>::sanitize (hb_blob_reference (blob)), index);
@@ -434,7 +434,7 @@ hb_face_get_user_data (hb_face_t          *face,
 
 hb_blob_t *
 hb_face_reference_table (hb_face_t *face,
-		   hb_tag_t   tag)
+			 hb_tag_t   tag)
 {
   hb_blob_t *blob;
 



More information about the HarfBuzz mailing list