Imported Upstream version 3.4.0
[platform/upstream/harfbuzz.git] / src / hb-ot-tag.cc
index 7ec91c5..f50be97 100644 (file)
@@ -41,6 +41,7 @@ hb_ot_old_tag_from_script (hb_script_t script)
   switch ((hb_tag_t) script)
   {
     case HB_SCRIPT_INVALID:            return HB_OT_TAG_DEFAULT_SCRIPT;
+    case HB_SCRIPT_MATH:               return HB_OT_TAG_MATH_SCRIPT;
 
     /* KATAKANA and HIRAGANA both map to 'kana' */
     case HB_SCRIPT_HIRAGANA:           return HB_TAG('k','a','n','a');
@@ -63,6 +64,8 @@ hb_ot_old_tag_to_script (hb_tag_t tag)
 {
   if (unlikely (tag == HB_OT_TAG_DEFAULT_SCRIPT))
     return HB_SCRIPT_INVALID;
+  if (unlikely (tag == HB_OT_TAG_MATH_SCRIPT))
+    return HB_SCRIPT_MATH;
 
   /* This side of the conversion is fully algorithmic. */
 
@@ -164,6 +167,15 @@ hb_ot_all_tags_from_script (hb_script_t   script,
   *count = i;
 }
 
+/**
+ * hb_ot_tag_to_script:
+ * @tag: a script tag
+ *
+ * Converts a script tag to an #hb_script_t.
+ *
+ * Return value: The #hb_script_t corresponding to @tag.
+ *
+ **/
 hb_script_t
 hb_ot_tag_to_script (hb_tag_t tag)
 {
@@ -280,6 +292,7 @@ hb_ot_tags_from_language (const char   *lang_str,
       for (i = 0;
           i < *count &&
           tag_idx + i < ARRAY_LENGTH (ot_languages) &&
+          ot_languages[tag_idx + i].tag != HB_TAG_NONE &&
           0 == strcmp (ot_languages[tag_idx + i].language, ot_languages[tag_idx].language);
           i++)
        tags[i] = ot_languages[tag_idx + i].tag;
@@ -350,13 +363,13 @@ parse_private_use_subtag (const char     *private_use_subtag,
  * hb_ot_tags_from_script_and_language:
  * @script: an #hb_script_t to convert.
  * @language: an #hb_language_t to convert.
- * @script_count: (allow-none): maximum number of script tags to retrieve (IN)
+ * @script_count: (inout) (optional): maximum number of script tags to retrieve (IN)
  * and actual number of script tags retrieved (OUT)
- * @script_tags: (out) (allow-none): array of size at least @script_count to store the
+ * @script_tags: (out) (optional): array of size at least @script_count to store the
  * script tag results
- * @language_count: (allow-none): maximum number of language tags to retrieve
+ * @language_count: (inout) (optional): maximum number of language tags to retrieve
  * (IN) and actual number of language tags retrieved (OUT)
- * @language_tags: (out) (allow-none): array of size at least @language_count to store
+ * @language_tags: (out) (optional): array of size at least @language_count to store
  * the language tag results
  *
  * Converts an #hb_script_t and an #hb_language_t to script and language tags.
@@ -423,10 +436,12 @@ hb_ot_tags_from_script_and_language (hb_script_t   script,
 
 /**
  * hb_ot_tag_to_language:
+ * @tag: an language tag
  *
+ * Converts a language tag to an #hb_language_t.
  *
- *
- * Return value: (transfer none):
+ * Return value: (transfer none) (nullable):
+ * The #hb_language_t corresponding to @tag.
  *
  * Since: 0.9.2
  **/
@@ -477,9 +492,9 @@ hb_ot_tag_to_language (hb_tag_t tag)
  * hb_ot_tags_to_script_and_language:
  * @script_tag: a script tag
  * @language_tag: a language tag
- * @script: (allow-none): the #hb_script_t corresponding to @script_tag (OUT).
- * @language: (allow-none): the #hb_language_t corresponding to @script_tag and
- * @language_tag (OUT).
+ * @script: (out) (optional): the #hb_script_t corresponding to @script_tag.
+ * @language: (out) (optional): the #hb_language_t corresponding to @script_tag and
+ * @language_tag.
  *
  * Converts a script tag and a language tag to an #hb_script_t and an
  * #hb_language_t.
@@ -510,7 +525,7 @@ hb_ot_tags_to_script_and_language (hb_tag_t       script_tag,
       unsigned char *buf;
       const char *lang_str = hb_language_to_string (*language);
       size_t len = strlen (lang_str);
-      buf = (unsigned char *) malloc (len + 16);
+      buf = (unsigned char *) hb_malloc (len + 16);
       if (unlikely (!buf))
       {
        *language = nullptr;
@@ -532,7 +547,7 @@ hb_ot_tags_to_script_and_language (hb_tag_t       script_tag,
        for (shift = 28; shift >= 0; shift -= 4)
          buf[len++] = TOHEX (script_tag >> shift);
        *language = hb_language_from_string ((char *) buf, len);
-       free (buf);
+       hb_free (buf);
       }
     }
   }