[HarfBuzz] harfbuzz: Branch 'master' - 3 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Thu Jul 10 16:23:22 PDT 2014


 src/hb-ot-tag.cc       |   44 ++++++++++++++++++++++----------------------
 test/api/test-ot-tag.c |   10 +++++++---
 2 files changed, 29 insertions(+), 25 deletions(-)

New commits:
commit 6334495ac1ee0a86228e67794b7a41ee91146f3b
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu Jul 10 19:22:07 2014 -0400

    Use zh-Hans / zh-Hant when converting OT language tag to hb_language_t

diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc
index 07ae310..89cc1e2 100644
--- a/src/hb-ot-tag.cc
+++ b/src/hb-ot-tag.cc
@@ -880,18 +880,9 @@ hb_ot_tag_to_language (hb_tag_t tag)
   if ((tag & 0xFFFF0000)  == 0x5A480000) {
     switch (tag) {
       case HB_TAG('Z','H','H',' '): return hb_language_from_string ("zh-hk", -1); /* Hong Kong */
-      default: {
-        /* Encode the tag... */
-	unsigned char buf[14] = "zh-x-hbot";
-	buf[9] = tag >> 24;
-	buf[10] = (tag >> 16) & 0xFF;
-	buf[11] = (tag >> 8) & 0xFF;
-	buf[12] = tag & 0xFF;
-	if (buf[12] == 0x20)
-	  buf[12] = '\0';
-	buf[13] = '\0';
-	return hb_language_from_string ((char *) buf, -1);
-      }
+      case HB_TAG('Z','H','S',' '): return hb_language_from_string ("zh-Hans", -1); /* Simplified */
+      case HB_TAG('Z','H','T',' '): return hb_language_from_string ("zh-Hant", -1); /* Traditional */
+      default: break; /* Fall through */
     }
   }
 
diff --git a/test/api/test-ot-tag.c b/test/api/test-ot-tag.c
index 6529017..b667c7d 100644
--- a/test/api/test-ot-tag.c
+++ b/test/api/test-ot-tag.c
@@ -207,9 +207,9 @@ test_ot_tag_language (void)
   test_tag_from_language ("ZHS", "zh"); /* Chinese */
   test_tag_from_language ("ZHS", "zh-xx");
 
-  test_tag_to_language ("ZHS", "zh-x-hbotzhs");
-  test_tag_to_language ("ZHT", "zh-x-hbotzht");
-  test_tag_to_language ("ZHP", "zh-x-hbotzhp");
+  test_tag_to_language ("ZHS", "zh-Hans");
+  test_tag_to_language ("ZHT", "zh-Hant");
+  test_tag_to_language ("ZHP", "x-hbotzhp");
 
   test_language_two_way ("ABC", "x-hbotabc");
   test_tag_from_language ("ABC", "asdf-asdf-wer-x-hbotabc-zxc");
commit f381e320df795a9d73ac81499f8ed8c311bcb2f0
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu Jul 10 19:20:35 2014 -0400

    Fix lang matching logic
    
    Previous code was broken logically, but harmless.

diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc
index 5dd005f..07ae310 100644
--- a/src/hb-ot-tag.cc
+++ b/src/hb-ot-tag.cc
@@ -845,7 +845,7 @@ hb_ot_tag_from_language (hb_language_t language)
     {
       const LangTagLong *lang_tag;
       lang_tag = &ot_languages_zh[i];
-      if (lang_matches (lang_tag->language, lang_str))
+      if (lang_matches (lang_str, lang_tag->language))
 	return lang_tag->tag;
     }
 
diff --git a/test/api/test-ot-tag.c b/test/api/test-ot-tag.c
index 1897180..6529017 100644
--- a/test/api/test-ot-tag.c
+++ b/test/api/test-ot-tag.c
@@ -195,6 +195,7 @@ test_ot_tag_language (void)
 
   test_language_two_way ("ZHH", "zh-hk"); /* Chinese (Hong Kong) */
 
+  test_tag_from_language ("ZHS", "zh"); /* Chinese */
   test_tag_from_language ("ZHS", "zh-cn"); /* Chinese (China) */
   test_tag_from_language ("ZHS", "zh-sg"); /* Chinese (Singapore) */
   test_tag_from_language ("ZHT", "zh-mo"); /* Chinese (Macao) */
commit ee5350d667f3a9644667202597694581f2cf657d
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu Jul 10 19:06:45 2014 -0400

    Accept BCP 47 zh-Hans / zh-Hant language tags

diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc
index 5594ef5..5dd005f 100644
--- a/src/hb-ot-tag.cc
+++ b/src/hb-ot-tag.cc
@@ -156,7 +156,7 @@ hb_ot_tag_to_script (hb_tag_t tag)
 /* hb_language_t */
 
 typedef struct {
-  char language[6];
+  char language[4];
   hb_tag_t tag;
 } LangTag;
 
@@ -763,12 +763,18 @@ static const LangTag ot_languages[] = {
 /*{"??",	HB_TAG('Z','H','P',' ')},*/	/* Chinese Phonetic */
 };
 
-static const LangTag ot_languages_zh[] = {
+typedef struct {
+  char language[8];
+  hb_tag_t tag;
+} LangTagLong;
+static const LangTagLong ot_languages_zh[] = {
   {"zh-cn",	HB_TAG('Z','H','S',' ')},	/* Chinese (China) */
   {"zh-hk",	HB_TAG('Z','H','H',' ')},	/* Chinese (Hong Kong) */
   {"zh-mo",	HB_TAG('Z','H','T',' ')},	/* Chinese (Macao) */
   {"zh-sg",	HB_TAG('Z','H','S',' ')},	/* Chinese (Singapore) */
-  {"zh-tw",	HB_TAG('Z','H','T',' ')} 	/* Chinese (Taiwan) */
+  {"zh-tw",	HB_TAG('Z','H','T',' ')},	/* Chinese (Taiwan) */
+  {"zh-hans",	HB_TAG('Z','H','S',' ')},	/* Chinese (Simplified) */
+  {"zh-hant",	HB_TAG('Z','H','T',' ')},	/* Chinese (Traditional) */
 };
 
 static int
@@ -800,7 +806,6 @@ hb_tag_t
 hb_ot_tag_from_language (hb_language_t language)
 {
   const char *lang_str, *s;
-  const LangTag *lang_tag;
 
   if (language == HB_LANGUAGE_INVALID)
     return HB_OT_TAG_DEFAULT_LANGUAGE;
@@ -822,11 +827,14 @@ hb_ot_tag_from_language (hb_language_t language)
   }
 
   /* Find a language matching in the first component */
-  lang_tag = (LangTag *) bsearch (lang_str, ot_languages,
-				  ARRAY_LENGTH (ot_languages), sizeof (LangTag),
-				  (hb_compare_func_t) lang_compare_first_component);
-  if (lang_tag)
-    return lang_tag->tag;
+  {
+    const LangTag *lang_tag;
+    lang_tag = (LangTag *) bsearch (lang_str, ot_languages,
+				    ARRAY_LENGTH (ot_languages), sizeof (LangTag),
+				    (hb_compare_func_t) lang_compare_first_component);
+    if (lang_tag)
+      return lang_tag->tag;
+  }
 
   /* Otherwise, check the Chinese ones */
   if (0 == lang_compare_first_component (lang_str, "zh"))
@@ -835,6 +843,7 @@ hb_ot_tag_from_language (hb_language_t language)
 
     for (i = 0; i < ARRAY_LENGTH (ot_languages_zh); i++)
     {
+      const LangTagLong *lang_tag;
       lang_tag = &ot_languages_zh[i];
       if (lang_matches (lang_tag->language, lang_str))
 	return lang_tag->tag;
diff --git a/test/api/test-ot-tag.c b/test/api/test-ot-tag.c
index 79e2bbf..1897180 100644
--- a/test/api/test-ot-tag.c
+++ b/test/api/test-ot-tag.c
@@ -199,6 +199,9 @@ test_ot_tag_language (void)
   test_tag_from_language ("ZHS", "zh-sg"); /* Chinese (Singapore) */
   test_tag_from_language ("ZHT", "zh-mo"); /* Chinese (Macao) */
   test_tag_from_language ("ZHT", "zh-tw"); /* Chinese (Taiwan) */
+  test_tag_from_language ("ZHS", "zh-Hans"); /* Chinese (Simplified) */
+  test_tag_from_language ("ZHT", "zh-Hant"); /* Chinese (Traditional) */
+  test_tag_from_language ("ZHS", "zh-xx"); /* Chinese (Other) */
 
   test_tag_from_language ("ZHS", "zh"); /* Chinese */
   test_tag_from_language ("ZHS", "zh-xx");


More information about the HarfBuzz mailing list