[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 @@
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 */