diff --git a/src/gen-tag-table.py b/src/gen-tag-table.py index b87183604..7e15c08c5 100755 --- a/src/gen-tag-table.py +++ b/src/gen-tag-table.py @@ -944,6 +944,8 @@ def same_tag (bcp_47_tag, ot_tags): return len (bcp_47_tag) == 3 and len (ot_tags) == 1 and bcp_47_tag == ot_tags[0].lower () for language_len in (2, 3): + if language_len == 3: + print ('#ifndef HB_NO_LANGUAGE_LONG') print ('static const LangTag ot_languages%d[] = {' % language_len) for language, tags in sorted (ot.from_bcp_47.items ()): if language == '' or '-' in language: @@ -971,6 +973,8 @@ for language_len in (2, 3): write ('%s%s' % (name if len (name) > len (ot_name) else ot_name, scope)) print (' */') print ('};') + if language_len == 3: + print ('#endif') print () print ('/**') @@ -987,7 +991,7 @@ print (' * Converts a multi-subtag BCP 47 language tag to language tags.') print (' *') print (' * Return value: Whether any language systems were retrieved.') print (' **/') -print ('static bool') +print ('static inline bool') print ('hb_ot_tags_from_complex_language (const char *lang_str,') print ('\t\t\t\t const char *limit,') print ('\t\t\t\t unsigned int *count /* IN/OUT */,') @@ -1130,7 +1134,7 @@ print (' *') print (' * Return value: The #hb_language_t corresponding to the BCP 47 language tag,') print (' * or #HB_LANGUAGE_INVALID if @tag is not ambiguous.') print (' **/') -print ('static hb_language_t') +print ('static inline hb_language_t') print ('hb_ot_ambiguous_tag_to_language (hb_tag_t tag)') print ('{') print (' switch (tag)') diff --git a/src/hb-config.hh b/src/hb-config.hh index a42687acf..2578231d2 100644 --- a/src/hb-config.hh +++ b/src/hb-config.hh @@ -64,6 +64,7 @@ #define HB_NO_FACE_COLLECT_UNICODES #define HB_NO_GETENV #define HB_NO_HINTING +#define HB_NO_LANGUAGE_LONG #define HB_NO_LANGUAGE_PRIVATE_SUBTAG #define HB_NO_LAYOUT_FEATURE_PARAMS #define HB_NO_LAYOUT_COLLECT_GLYPHS diff --git a/src/hb-ot-tag-table.hh b/src/hb-ot-tag-table.hh index b242fba2d..9394b90ee 100644 --- a/src/hb-ot-tag-table.hh +++ b/src/hb-ot-tag-table.hh @@ -219,6 +219,7 @@ static const LangTag ot_languages2[] = { {HB_TAG('z','u',' ',' '), HB_TAG('Z','U','L',' ')}, /* Zulu */ }; +#ifndef HB_NO_LANGUAGE_LONG static const LangTag ot_languages3[] = { {HB_TAG('a','a','e',' '), HB_TAG('S','Q','I',' ')}, /* Arbëreshë Albanian -> Albanian */ {HB_TAG('a','a','o',' '), HB_TAG('A','R','A',' ')}, /* Algerian Saharan Arabic -> Arabic */ @@ -1621,6 +1622,7 @@ static const LangTag ot_languages3[] = { /*{HB_TAG('z','z','a',' '), HB_TAG('Z','Z','A',' ')},*/ /* Zazaki [macrolanguage] */ {HB_TAG('z','z','j',' '), HB_TAG('Z','H','A',' ')}, /* Zuojiang Zhuang -> Zhuang */ }; +#endif /** * hb_ot_tags_from_complex_language: @@ -1636,7 +1638,7 @@ static const LangTag ot_languages3[] = { * * Return value: Whether any language systems were retrieved. **/ -static bool +static inline bool hb_ot_tags_from_complex_language (const char *lang_str, const char *limit, unsigned int *count /* IN/OUT */, @@ -2818,7 +2820,7 @@ out: * Return value: The #hb_language_t corresponding to the BCP 47 language tag, * or #HB_LANGUAGE_INVALID if @tag is not ambiguous. **/ -static hb_language_t +static inline hb_language_t hb_ot_ambiguous_tag_to_language (hb_tag_t tag) { switch (tag) diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc index 31ce1a1e2..ce5cdce98 100644 --- a/src/hb-ot-tag.cc +++ b/src/hb-ot-tag.cc @@ -263,15 +263,19 @@ hb_ot_tags_from_language (const char *lang_str, unsigned int *count, hb_tag_t *tags) { - const char *s; +#ifndef HB_NO_LANGUAGE_LONG /* Check for matches of multiple subtags. */ if (hb_ot_tags_from_complex_language (lang_str, limit, count, tags)) return; +#endif /* Find a language matching in the first component. */ - s = strchr (lang_str, '-'); +#ifndef HB_NO_LANGUAGE_LONG + const char *s; s = strchr (lang_str, '-'); +#endif { +#ifndef HB_NO_LANGUAGE_LONG if (s && limit - lang_str >= 6) { const char *extlang_end = strchr (s + 1, '-'); @@ -280,6 +284,7 @@ hb_ot_tags_from_language (const char *lang_str, ISALPHA (s[1])) lang_str = s + 1; } +#endif const LangTag *ot_languages = nullptr; unsigned ot_languages_len = 0; const char *dash = strchr (lang_str, '-'); @@ -289,11 +294,13 @@ hb_ot_tags_from_language (const char *lang_str, ot_languages = ot_languages2; ot_languages_len = ARRAY_LENGTH (ot_languages2); } +#ifndef HB_NO_LANGUAGE_LONG else if (first_len == 3) { ot_languages = ot_languages3; ot_languages_len = ARRAY_LENGTH (ot_languages3); } +#endif hb_tag_t lang_tag = hb_tag_from_string (lang_str, first_len); @@ -320,6 +327,7 @@ hb_ot_tags_from_language (const char *lang_str, } } +#ifndef HB_NO_LANGUAGE_LONG if (!s) s = lang_str + strlen (lang_str); if (s - lang_str == 3) { @@ -328,6 +336,7 @@ hb_ot_tags_from_language (const char *lang_str, *count = 1; return; } +#endif *count = 0; } @@ -472,11 +481,13 @@ hb_ot_tag_to_language (hb_tag_t tag) if (tag == HB_OT_TAG_DEFAULT_LANGUAGE) return nullptr; +#ifndef HB_NO_LANGUAGE_LONG { hb_language_t disambiguated_tag = hb_ot_ambiguous_tag_to_language (tag); if (disambiguated_tag != HB_LANGUAGE_INVALID) return disambiguated_tag; } +#endif char buf[4]; for (i = 0; i < ARRAY_LENGTH (ot_languages2); i++) @@ -485,12 +496,14 @@ hb_ot_tag_to_language (hb_tag_t tag) hb_tag_to_string (ot_languages2[i].language, buf); return hb_language_from_string (buf, 2); } +#ifndef HB_NO_LANGUAGE_LONG for (i = 0; i < ARRAY_LENGTH (ot_languages3); i++) if (ot_languages3[i].tag == tag) { hb_tag_to_string (ot_languages3[i].language, buf); return hb_language_from_string (buf, 3); } +#endif /* Return a custom language in the form of "x-hbot-AABBCCDD". * If it's three letters long, also guess it's ISO 639-3 and lower-case and @@ -596,6 +609,7 @@ test_langs_sorted () abort(); } } +#ifndef HB_NO_LANGUAGE_LONG for (unsigned int i = 1; i < ARRAY_LENGTH (ot_languages3); i++) { int c = ot_languages3[i].cmp (&ot_languages3[i - 1]); @@ -606,6 +620,7 @@ test_langs_sorted () abort(); } } +#endif } int