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

Behdad Esfahbod behdad at kemper.freedesktop.org
Wed Apr 27 06:38:48 PDT 2011


 src/hb-buffer.cc            |    6 +++---
 src/hb-glib.cc              |    5 +++--
 src/hb-icu.cc               |    5 +++--
 src/hb-object-private.hh    |    1 +
 src/hb-open-type-private.hh |    4 ++--
 src/hb-private.hh           |   30 +++++++++++++++++++++---------
 src/hb-unicode-private.hh   |   11 +++++++++++
 src/hb-unicode.cc           |    7 +++++++
 src/hb-unicode.h            |    8 ++++++++
 src/hb-view.c               |   13 ++++++-------
 test/test-unicode.c         |   11 ++++++++++-
 11 files changed, 75 insertions(+), 26 deletions(-)

New commits:
commit 65e0063eae2f3adb25315b8bd7b0e7757aa960f3
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Apr 27 09:33:58 2011 -0400

    Make buffer size growth start from 32 instead of 8

diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc
index 7cf5adc..5468270 100644
--- a/src/hb-buffer.cc
+++ b/src/hb-buffer.cc
@@ -78,7 +78,7 @@ _hb_buffer_enlarge (hb_buffer_t *buffer, unsigned int size)
   separate_out = buffer->out_info != buffer->info;
 
   while (size > new_allocated)
-    new_allocated += (new_allocated >> 1) + 8;
+    new_allocated += (new_allocated >> 1) + 32;
 
   ASSERT_STATIC (sizeof (buffer->info[0]) == sizeof (buffer->pos[0]));
   bool overflows = new_allocated >= ((unsigned int) -1) / sizeof (buffer->info[0]);
commit d4bee9f813bb299b1c4aab7c33d588be2a7d354b
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Apr 27 09:24:37 2011 -0400

    [API] Add hb_unicode_funcs_get_default()

diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc
index cf46671..7cf5adc 100644
--- a/src/hb-buffer.cc
+++ b/src/hb-buffer.cc
@@ -37,7 +37,7 @@ HB_BEGIN_DECLS
 static hb_buffer_t _hb_buffer_nil = {
   HB_OBJECT_HEADER_STATIC,
 
-  &_hb_unicode_funcs_nil,  /* unicode */
+  &_hb_unicode_funcs_default,
   {
     HB_DIRECTION_INVALID,
     HB_SCRIPT_INVALID,
@@ -173,7 +173,7 @@ hb_buffer_set_unicode_funcs (hb_buffer_t        *buffer,
 			     hb_unicode_funcs_t *unicode)
 {
   if (!unicode)
-    unicode = &_hb_unicode_funcs_nil;
+    unicode = &_hb_unicode_funcs_default;
 
   hb_unicode_funcs_reference (unicode);
   hb_unicode_funcs_destroy (buffer->unicode);
diff --git a/src/hb-glib.cc b/src/hb-glib.cc
index 32cefa2..2bce1f9 100644
--- a/src/hb-glib.cc
+++ b/src/hb-glib.cc
@@ -220,7 +220,8 @@ hb_glib_get_script (hb_unicode_funcs_t *ufuncs,
   return hb_glib_script_to_script (g_unichar_get_script (unicode));
 }
 
-static hb_unicode_funcs_t glib_ufuncs = {
+extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_glib;
+hb_unicode_funcs_t _hb_glib_unicode_funcs = {
   HB_OBJECT_HEADER_STATIC,
 
   NULL, /* parent */
@@ -237,7 +238,7 @@ static hb_unicode_funcs_t glib_ufuncs = {
 hb_unicode_funcs_t *
 hb_glib_get_unicode_funcs (void)
 {
-  return &glib_ufuncs;
+  return &_hb_glib_unicode_funcs;
 }
 
 
diff --git a/src/hb-icu.cc b/src/hb-icu.cc
index 2abd140..52645fd 100644
--- a/src/hb-icu.cc
+++ b/src/hb-icu.cc
@@ -160,7 +160,8 @@ hb_icu_get_script (hb_unicode_funcs_t *ufuncs,
   return hb_icu_script_to_script (scriptCode);
 }
 
-static hb_unicode_funcs_t icu_ufuncs = {
+extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_icu;
+hb_unicode_funcs_t _hb_icu_unicode_funcs = {
   HB_OBJECT_HEADER_STATIC,
 
   NULL, /* parent */
@@ -177,7 +178,7 @@ static hb_unicode_funcs_t icu_ufuncs = {
 hb_unicode_funcs_t *
 hb_icu_get_unicode_funcs (void)
 {
-  return &icu_ufuncs;
+  return &_hb_icu_unicode_funcs;
 }
 
 
diff --git a/src/hb-unicode-private.hh b/src/hb-unicode-private.hh
index 16836a0..8337e42 100644
--- a/src/hb-unicode-private.hh
+++ b/src/hb-unicode-private.hh
@@ -90,7 +90,18 @@ struct _hb_unicode_funcs_t {
   } destroy;
 };
 
+
+#if HAVE_GLIB
+extern HB_INTERNAL hb_unicode_funcs_t _hb_glib_unicode_funcs;
+#define _hb_unicode_funcs_default _hb_glib_unicode_funcs
+#elif HAVE_ICU
+extern HB_INTERNAL hb_unicode_funcs_t _hb_icu_unicode_funcs;
+#define _hb_unicode_funcs_default _hb_icu_unicode_funcs
+#else
 extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_nil;
+#define _hb_unicode_funcs_default _hb_unicode_funcs_nil
+#endif
+
 
 
 HB_END_DECLS
diff --git a/src/hb-unicode.cc b/src/hb-unicode.cc
index ed0dc10..b756461 100644
--- a/src/hb-unicode.cc
+++ b/src/hb-unicode.cc
@@ -80,6 +80,7 @@ hb_unicode_get_script_nil (hb_unicode_funcs_t *ufuncs    HB_UNUSED,
 }
 
 
+extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_nil;
 hb_unicode_funcs_t _hb_unicode_funcs_nil = {
   HB_OBJECT_HEADER_STATIC,
 
@@ -96,6 +97,12 @@ hb_unicode_funcs_t _hb_unicode_funcs_nil = {
 
 
 hb_unicode_funcs_t *
+hb_unicode_funcs_get_default (void)
+{
+  return &_hb_unicode_funcs_default;
+}
+
+hb_unicode_funcs_t *
 hb_unicode_funcs_create (hb_unicode_funcs_t *parent)
 {
   hb_unicode_funcs_t *ufuncs;
diff --git a/src/hb-unicode.h b/src/hb-unicode.h
index 47a78d4..d558c22 100644
--- a/src/hb-unicode.h
+++ b/src/hb-unicode.h
@@ -42,6 +42,14 @@ HB_BEGIN_DECLS
 
 typedef struct _hb_unicode_funcs_t hb_unicode_funcs_t;
 
+
+/*
+ * just give me the best implementation you've got there.
+ */
+hb_unicode_funcs_t *
+hb_unicode_funcs_get_default (void);
+
+
 hb_unicode_funcs_t *
 hb_unicode_funcs_create (hb_unicode_funcs_t *parent_funcs);
 
diff --git a/src/hb-view.c b/src/hb-view.c
index ed2d515..783c559 100644
--- a/src/hb-view.c
+++ b/src/hb-view.c
@@ -37,7 +37,7 @@
 #include <math.h>
 #include <locale.h>
 
-#include <hb-glib.h>
+#include <glib.h>
 
 #include <cairo-ft.h>
 #include <hb-ft.h>
@@ -348,18 +348,17 @@ _hb_cr_text_glyphs (cairo_t *cr,
   unsigned int num_glyphs, i;
   hb_position_t x;
 
-  if (len < 0)
-    len = strlen (text);
-  hb_buffer = hb_buffer_create (len);
+  hb_buffer = hb_buffer_create (0);
 
-  hb_buffer_set_unicode_funcs (hb_buffer, hb_glib_get_unicode_funcs ());
-
-  hb_buffer_add_utf8 (hb_buffer, text, len, 0, len);
   if (script)
     hb_buffer_set_script (hb_buffer, hb_script_from_string (script));
   if (language)
     hb_buffer_set_language (hb_buffer, hb_language_from_string (language));
 
+  if (len < 0)
+    len = strlen (text);
+  hb_buffer_add_utf8 (hb_buffer, text, len, 0, len);
+
   hb_shape (hb_font, hb_face, hb_buffer, features, num_features);
 
   num_glyphs = hb_buffer_get_length (hb_buffer);
diff --git a/test/test-unicode.c b/test/test-unicode.c
index 324fa1f..c696341 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -46,6 +46,14 @@ test_glib (void)
   g_assert_cmpint (hb_unicode_get_script (uf, 'd'), ==, HB_SCRIPT_LATIN);
 }
 
+static void
+test_default (void)
+{
+  hb_unicode_funcs_t *uf = hb_unicode_funcs_get_default ();
+
+  g_assert_cmpint (hb_unicode_get_script (uf, 'd'), ==, HB_SCRIPT_LATIN);
+}
+
 static gboolean freed0, freed1;
 static int unique_pointer0[1];
 static int unique_pointer1[1];
@@ -191,12 +199,13 @@ main (int argc, char **argv)
 
   g_test_add_func ("/unicode/nil", test_nil);
   g_test_add_func ("/unicode/glib", test_glib);
+  g_test_add_func ("/unicode/default", test_default);
   g_test_add_func ("/unicode/custom", test_custom);
   g_test_add_func ("/unicode/subclassing/nil", test_subclassing_nil);
   g_test_add_func ("/unicode/subclassing/glib", test_subclassing_glib);
   g_test_add_func ("/unicode/subclassing/deep", test_subclassing_deep);
 
-  /* XXX test all methods for their defaults and various (glib, icu) implementations. */
+  /* XXX test all methods for their defaults and various (glib, icu, default) implementations. */
   /* XXX test glib & icu two-way script conversion */
 
   return g_test_run ();
commit 153142dac8dd9abaf164bb88af07c600c17fc3a1
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Apr 27 01:49:03 2011 -0400

    Replace simple macros with inline functions for better type safety
    
    Now that we use C++ for all source code, lets benefit from it!
    
    The hb_be_int16/32_get/put/eq() macros grow code size if replaced with
    inline functions, so leave them as is.

diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index 0f1021b..5810cc3 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -371,7 +371,7 @@ class BEInt<Type, 2>
   public:
   inline void set (Type i) { hb_be_uint16_put (v,i); }
   inline operator Type (void) const { return hb_be_uint16_get (v); }
-  inline bool operator == (const BEInt<Type, 2>& o) const { return hb_be_uint16_cmp (v, o.v); }
+  inline bool operator == (const BEInt<Type, 2>& o) const { return hb_be_uint16_eq (v, o.v); }
   inline bool operator != (const BEInt<Type, 2>& o) const { return !(*this == o); }
   private: uint8_t v[2];
 };
@@ -381,7 +381,7 @@ class BEInt<Type, 4>
   public:
   inline void set (Type i) { hb_be_uint32_put (v,i); }
   inline operator Type (void) const { return hb_be_uint32_get (v); }
-  inline bool operator == (const BEInt<Type, 4>& o) const { return hb_be_uint32_cmp (v, o.v); }
+  inline bool operator == (const BEInt<Type, 4>& o) const { return hb_be_uint32_eq (v, o.v); }
   inline bool operator != (const BEInt<Type, 4>& o) const { return !(*this == o); }
   private: uint8_t v[4];
 };
diff --git a/src/hb-private.hh b/src/hb-private.hh
index d299029..fc06e70 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -64,11 +64,15 @@ HB_BEGIN_DECLS
 
 /* Basics */
 
+HB_END_DECLS
+
 #undef MIN
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
+template <typename Type> static inline Type MIN (const Type &a, const Type &b) { return a < b ? a : b; }
 
 #undef MAX
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
+template <typename Type> static inline Type MAX (const Type &a, const Type &b) { return a > b ? a : b; }
+
+HB_BEGIN_DECLS
 
 #undef  ARRAY_LENGTH
 #define ARRAY_LENGTH(__array) ((signed int) (sizeof (__array) / sizeof (__array[0])))
@@ -275,23 +279,31 @@ typedef struct {
 
 /* Big-endian handling */
 
-#define hb_be_uint16(v)		((uint16_t) ((((const uint8_t *)&(v))[0] << 8) + (((const uint8_t *)&(v))[1])))
+static inline uint16_t hb_be_uint16 (const uint16_t v)
+{
+  const uint8_t *V = (const uint8_t *) &v;
+  return (uint16_t) (V[0] << 8) + V[1];
+}
 
 #define hb_be_uint16_put(v,V)	HB_STMT_START { v[0] = (V>>8); v[1] = (V); } HB_STMT_END
 #define hb_be_uint16_get(v)	(uint16_t) ((v[0] << 8) + v[1])
-#define hb_be_uint16_cmp(a,b)	(a[0] == b[0] && a[1] == b[1])
+#define hb_be_uint16_eq(a,b)	(a[0] == b[0] && a[1] == b[1])
 
 #define hb_be_uint32_put(v,V)	HB_STMT_START { v[0] = (V>>24); v[1] = (V>>16); v[2] = (V>>8); v[3] = (V); } HB_STMT_END
 #define hb_be_uint32_get(v)	(uint32_t) ((v[0] << 24) + (v[1] << 16) + (v[2] << 8) + v[3])
-#define hb_be_uint32_cmp(a,b)	(a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3])
+#define hb_be_uint32_eq(a,b)	(a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3])
 
 
 /* ASCII tag/character handling */
 
-#define ISALPHA(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z'))
-#define ISALNUM(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z') || ((c) >= '0' && (c) <= '9'))
-#define TOUPPER(c) (((c) >= 'a' && (c) <= 'z') ? (c) - 'a' + 'A' : (c))
-#define TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c))
+static inline unsigned char ISALPHA (unsigned char c)
+{ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); }
+static inline unsigned char ISALNUM (unsigned char c)
+{ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); }
+static inline unsigned char TOUPPER (unsigned char c)
+{ return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; }
+static inline unsigned char TOLOWER (unsigned char c)
+{ return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; }
 
 #define HB_TAG_CHAR4(s)   (HB_TAG(((const char *) s)[0], \
 				  ((const char *) s)[1], \
commit 40a9b8154f929947f4693bf90c64301afa407c3f
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Apr 27 01:48:56 2011 -0400

    Add TODO item

diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh
index ff66d1d..8142bd4 100644
--- a/src/hb-object-private.hh
+++ b/src/hb-object-private.hh
@@ -113,6 +113,7 @@ HB_BEGIN_DECLS
 
 /* Object allocation and lifecycle manamgement macros */
 
+/* XXX Trace objects.  Got removed in refactoring */
 #define HB_TRACE_OBJECT(obj) hb_object_trace (obj)
 #define HB_OBJECT_DO_CREATE(Type, obj) likely (obj = hb_object_create<Type> ())
 #define HB_OBJECT_IS_INERT(obj) hb_object_is_inert (obj)



More information about the HarfBuzz mailing list