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

Behdad Esfahbod behdad at kemper.freedesktop.org
Fri Aug 5 16:59:14 PDT 2011


 src/check-header-guards.sh  |    1 
 src/hb-common.cc            |    8 +++---
 src/hb-open-type-private.hh |   10 +++----
 src/hb-shape.cc             |   58 +++++++++++++++++++++++++++++++++-----------
 src/hb-shape.h              |    3 ++
 src/hb-view.cc              |    2 -
 test/Makefile.am            |    2 +
 test/test-c.c               |    8 ++++++
 test/test-shape.c           |   15 +++++++++++
 9 files changed, 83 insertions(+), 24 deletions(-)

New commits:
commit 9da554504e30a326fc57b28cdb0e57108bfa9555
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Aug 5 19:48:49 2011 -0400

    Add hb_shape_list_shapers()

diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index 9e4469d..78c39dd 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -66,8 +66,16 @@ static struct static_shaper_list_t
   {
     char *env = getenv ("HB_SHAPER_LIST");
     shaper_list = NULL;
-    if (!env || !*env)
+    if (!env || !*env) {
+    fallback:
+      ASSERT_STATIC ((ARRAY_LENGTH (shapers) + 1) * sizeof (*shaper_list) <= sizeof (static_buffer));
+      shaper_list = (const char **) static_buffer;
+      unsigned int i;
+      for (i = 0; i < ARRAY_LENGTH (shapers); i++)
+        shaper_list[i] = shapers[i].name;
+      shaper_list[i] = NULL;
       return;
+    }
 
     unsigned int count = 3; /* initial, fallback, null */
     for (const char *p = env; (p == strchr (p, ',')) && p++; )
@@ -76,7 +84,7 @@ static struct static_shaper_list_t
     unsigned int len = strlen (env);
 
     if (count > 100 || len > 1000)
-      return;
+      goto fallback;
 
     len += count * sizeof (*shaper_list) + 1;
     char *buffer = len < sizeof (static_buffer) ? static_buffer : (char *) malloc (len);
@@ -100,7 +108,13 @@ static struct static_shaper_list_t
 
   const char **shaper_list;
   char static_buffer[32];
-} env_shaper_list;
+} static_shaper_list;
+
+const char **
+hb_shape_list_shapers (void)
+{
+  return static_shaper_list.shaper_list;
+}
 
 hb_bool_t
 hb_shape_full (hb_font_t           *font,
@@ -111,7 +125,7 @@ hb_shape_full (hb_font_t           *font,
 	       const char         **shaper_list)
 {
   if (likely (!shaper_list))
-    shaper_list = env_shaper_list.shaper_list;
+    shaper_list = static_shaper_list.shaper_list;
 
   if (likely (!shaper_list)) {
     for (unsigned int i = 0; i < ARRAY_LENGTH (shapers); i++)
diff --git a/src/hb-shape.h b/src/hb-shape.h
index 75818dc..18b35ae 100644
--- a/src/hb-shape.h
+++ b/src/hb-shape.h
@@ -56,6 +56,9 @@ hb_shape_full (hb_font_t           *font,
 	       const char          *shaper_options,
 	       const char         **shaper_list);
 
+const char **
+hb_shape_list_shapers (void);
+
 
 HB_END_DECLS
 
diff --git a/test/Makefile.am b/test/Makefile.am
index 0fbc689..18f36df 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -25,9 +25,11 @@ TEST_PROGS = \
 	test-version \
 	$(NULL)
 
+if HAVE_OT
 TEST_PROGS += \
 	test-ot-tag \
 	$(NULL)
+endif
 
 # Tests for header compilation
 TEST_PROGS += \
diff --git a/test/test-c.c b/test/test-c.c
index 543fa7b..e72db27 100644
--- a/test/test-c.c
+++ b/test/test-c.c
@@ -43,6 +43,14 @@
 #include <hb-ft.h>
 #endif
 
+#if HAVE_OT
+#include <hb-ot.h>
+#endif
+
+#if HAVE_UNISCRIBE
+#include <hb-uniscribe.h>
+#endif
+
 int
 main (int argc, char **argv)
 {
diff --git a/test/test-shape.c b/test/test-shape.c
index 5a41f0c..6d30824 100644
--- a/test/test-shape.c
+++ b/test/test-shape.c
@@ -138,6 +138,18 @@ test_shape (void)
   hb_font_destroy (font);
 }
 
+static void
+test_shape_list (void)
+{
+  const char **shapers = hb_shape_list_shapers ();
+
+  unsigned int i;
+  for (i = 0; shapers[i]; i++)
+    ;
+
+  g_assert_cmpint (i, >, 1);
+  g_assert (!strcmp (shapers[i - 1], "fallback"));
+}
 
 int
 main (int argc, char **argv)
@@ -145,6 +157,9 @@ main (int argc, char **argv)
   hb_test_init (&argc, &argv);
 
   hb_test_add (test_shape);
+  /* TODO test fallback shaper */
+  /* TODO test shaper_full */
+  hb_test_add (test_shape_list);
 
   return hb_test_run();
 }
commit d7bf473ef222ab420456ff155ffaa09bacb3a394
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Aug 5 18:18:21 2011 -0400

    Minor

diff --git a/src/check-header-guards.sh b/src/check-header-guards.sh
index 212b803..dc1893c 100755
--- a/src/check-header-guards.sh
+++ b/src/check-header-guards.sh
@@ -10,7 +10,6 @@ test "x$HBHEADERS" = x && HBHEADERS=`find . -maxdepth 1 -name 'hb*.h'`
 test "x$HBSOURCES" = x && HBSOURCES=`find . -maxdepth 1 -name 'hb-*.cc' -or -name 'hb-*.hh'`
 
 
-echo  $srcdir
 for x in $HBHEADERS $HBSOURCES; do
 	test -f "$srcdir/$x" && x="$srcdir/$x"
 	echo "$x" | grep '[^h]$' -q && continue;
diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index a6f1389..ae44ed7 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -338,12 +338,12 @@ struct Sanitizer
  */
 
 
-template <typename Type, int Bytes> class BEInt;
+template <typename Type, int Bytes> struct BEInt;
 
 /* LONGTERMTODO: On machines allowing unaligned access, we can make the
  * following tighter by using byteswap instructions on ints directly. */
 template <typename Type>
-class BEInt<Type, 2>
+struct BEInt<Type, 2>
 {
   public:
   inline void set (Type i) { hb_be_uint16_put (v,i); }
@@ -353,7 +353,7 @@ class BEInt<Type, 2>
   private: uint8_t v[2];
 };
 template <typename Type>
-class BEInt<Type, 4>
+struct BEInt<Type, 4>
 {
   public:
   inline void set (Type i) { hb_be_uint32_put (v,i); }
@@ -691,8 +691,8 @@ struct SortedArrayOf : ArrayOf<Type> {
 
   template <typename SearchType>
   inline int search (const SearchType &x) const {
-    class Cmp {
-      public: static int cmp (const SearchType *a, const Type *b) { return b->cmp (*a); }
+    struct Cmp {
+      static int cmp (const SearchType *a, const Type *b) { return b->cmp (*a); }
     };
     const Type *p = (const Type *) bsearch (&x, this->array, this->len, sizeof (this->array[0]), (hb_compare_func_t) Cmp::cmp);
     return p ? p - this->array : -1;
commit c62a8f10f3b9a4ac3ac6b686464ac734ebfa2f7f
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Aug 5 18:02:30 2011 -0400

    Free all static memory upon exit

diff --git a/src/hb-common.cc b/src/hb-common.cc
index f2347d5..afbe941 100644
--- a/src/hb-common.cc
+++ b/src/hb-common.cc
@@ -161,8 +161,10 @@ struct hb_language_item_t {
   void finish (void) { free (lang); }
 };
 
-static hb_static_mutex_t langs_lock;
-static hb_lockable_set_t<hb_language_item_t, hb_static_mutex_t> langs;
+static struct hb_static_lang_set_t : hb_lockable_set_t<hb_language_item_t, hb_static_mutex_t> {
+  ~hb_static_lang_set_t (void) { this->finish (lock); }
+  hb_static_mutex_t lock;
+} langs;
 
 hb_language_t
 hb_language_from_string (const char *str)
@@ -170,7 +172,7 @@ hb_language_from_string (const char *str)
   if (!str || !*str)
     return HB_LANGUAGE_INVALID;
 
-  hb_language_item_t *item = langs.find_or_insert (str, langs_lock);
+  hb_language_item_t *item = langs.find_or_insert (str, langs.lock);
 
   return likely (item) ? item->lang : HB_LANGUAGE_INVALID;
 }
diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index 986dd70..9e4469d 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -60,8 +60,8 @@ static const struct hb_shaper_pair_t {
 };
 #undef HB_SHAPER_IMPLEMENT
 
-static class static_shaper_list_t {
-  public:
+static struct static_shaper_list_t
+{
   static_shaper_list_t (void)
   {
     char *env = getenv ("HB_SHAPER_LIST");
commit c4d63ef744f79701458ab7af2055afb87ffe8de3
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Aug 5 17:54:25 2011 -0400

    Fix env parsing code
    
    Also changed the separator to comma instead of colon.

diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index 18dc6c1..986dd70 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -62,28 +62,44 @@ static const struct hb_shaper_pair_t {
 
 static class static_shaper_list_t {
   public:
-  static_shaper_list_t (void) {
+  static_shaper_list_t (void)
+  {
     char *env = getenv ("HB_SHAPER_LIST");
     shaper_list = NULL;
     if (!env || !*env)
       return;
+
     unsigned int count = 3; /* initial, fallback, null */
-    for (const char *p = env; (p == strchr (p, ':')) && p++; )
+    for (const char *p = env; (p == strchr (p, ',')) && p++; )
       count++;
-    if (count <= ARRAY_LENGTH (static_shaper_list))
-      shaper_list = static_shaper_list;
-    else
-      shaper_list = (const char **) malloc (count * sizeof (shaper_list[0]));
+
+    unsigned int len = strlen (env);
+
+    if (count > 100 || len > 1000)
+      return;
+
+    len += count * sizeof (*shaper_list) + 1;
+    char *buffer = len < sizeof (static_buffer) ? static_buffer : (char *) malloc (len);
+    shaper_list = (const char **) buffer;
+    buffer += count * sizeof (*shaper_list);
+    len -= count * sizeof (*shaper_list);
+    strncpy (buffer, env, len);
 
     count = 0;
-    shaper_list[count++] = env;
-    for (char *p = env; (p == strchr (p, ':')) && (*p = '\0', TRUE) && p++; )
+    shaper_list[count++] = buffer;
+    for (char *p = buffer; (p == strchr (p, ',')) && (*p = '\0', TRUE) && p++; )
       shaper_list[count++] = p;
     shaper_list[count++] = "fallback";
     shaper_list[count] = NULL;
   }
+  ~static_shaper_list_t (void)
+  {
+    if ((char *) shaper_list != static_buffer)
+      free (shaper_list);
+  }
+
   const char **shaper_list;
-  const char *static_shaper_list[10];
+  char static_buffer[32];
 } env_shaper_list;
 
 hb_bool_t
commit 3931837bebd79c5eb1bd5b24ff12e2c8e7d3f24c
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Aug 5 17:22:19 2011 -0400

    Change hb_shape() API back to what it was, add hb_shape_full()
    
    I disliked changing hb_shape() API, and disliked the fact that it was
    returning a bool now.  So, reverted.  Added new API for the extra
    functionality.

diff --git a/src/hb-view.cc b/src/hb-view.cc
index 67070ef..dc3fc47 100644
--- a/src/hb-view.cc
+++ b/src/hb-view.cc
@@ -370,7 +370,7 @@ _hb_cr_text_glyphs (cairo_t *cr,
     len = strlen (utf8);
   hb_buffer_add_utf8 (hb_buffer, utf8, len, 0, len);
 
-  hb_shape (hb_font, hb_buffer, features, num_features, NULL, NULL);
+  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);



More information about the HarfBuzz mailing list