[HarfBuzz] harfbuzz-ng: Branch 'master'

Behdad Esfahbod behdad at kemper.freedesktop.org
Thu May 5 21:06:29 PDT 2011


 src/hb-common.cc   |   21 +++++++++++++++++++++
 src/hb-common.h    |    3 +++
 src/hb-shape.cc    |    2 +-
 test/test-common.c |    5 +++++
 4 files changed, 30 insertions(+), 1 deletion(-)

New commits:
commit 34fb5521a5fbb6b95ceff4bbac42a62628bc9f31
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri May 6 00:04:28 2011 -0400

    [API] Add hb_language_get_default()
    
    It uses locale information to detect default language.  It's used by
    hb_shape() whenever language is not set on the buffer.
    
    Not sure how to properly test it in the test suite.  Tested by observing
    that with DejaVu Sans we select the proper local glyph version for U+431
    under Serbian locale.  See http://www.pango.org/ScriptGallery

diff --git a/src/hb-common.cc b/src/hb-common.cc
index 49f3eb8..a223edb 100644
--- a/src/hb-common.cc
+++ b/src/hb-common.cc
@@ -33,6 +33,8 @@
 #include "hb-mutex-private.hh"
 #include "hb-object-private.hh"
 
+#include <locale.h>
+
 HB_BEGIN_DECLS
 
 
@@ -179,6 +181,25 @@ hb_language_to_string (hb_language_t language)
   return language->s;
 }
 
+hb_language_t
+hb_language_get_default (void)
+{
+  static hb_language_t default_language;
+
+  if (!default_language) {
+    /* This block is not quite threadsafe, but is not as bad as
+     * it looks since it's idempotent.  As long as pointer ops
+     * are atomic, we are safe. */
+
+    /* I hear that setlocale() doesn't honor env vars on Windows,
+     * but for now we ignore that. */
+
+    default_language = hb_language_from_string (setlocale (LC_CTYPE, NULL));
+  }
+
+  return default_language;
+}
+
 
 /* hb_script_t */
 
diff --git a/src/hb-common.h b/src/hb-common.h
index 64109da..9546b21 100644
--- a/src/hb-common.h
+++ b/src/hb-common.h
@@ -113,6 +113,9 @@ hb_language_from_string (const char *str);
 const char *
 hb_language_to_string (hb_language_t language);
 
+hb_language_t
+hb_language_get_default (void);
+
 
 /* hb_unicode_general_category_t */
 
diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index cc711ea..fccb81e 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -81,7 +81,7 @@ hb_shape (hb_font_t          *font,
   /* If language is not set, use default language from locale */
   if (buffer->props.language == NULL) {
     /* TODO get_default_for_script? using $LANGUAGE */
-    //buffer->props.language = hb_language_get_default ();
+    buffer->props.language = hb_language_get_default ();
   }
 
   hb_shape_internal (font, buffer, features, num_features);
diff --git a/test/test-common.c b/test/test-common.c
index c2b4e1c..c1e3175 100644
--- a/test/test-common.c
+++ b/test/test-common.c
@@ -169,6 +169,11 @@ test_types_language (void)
 
   g_assert (NULL == hb_language_from_string (NULL));
   g_assert (NULL == hb_language_from_string (""));
+
+  /* Not sure how to test this better.  Setting env vars
+   * here doesn't sound like the right approach, and I'm
+   * not sure that it even works. */
+  g_assert (NULL != hb_language_get_default ());
 }
 
 int



More information about the HarfBuzz mailing list