Reduce LangTag from 3 language system tags to 1

This commit is contained in:
David Corbett 2019-04-16 10:04:45 -04:00 committed by Behdad Esfahbod
parent 155e92f259
commit 1ce11b4437
3 changed files with 1053 additions and 1060 deletions

View File

@ -895,20 +895,11 @@ def language_name_intersection (a, b):
def get_matching_language_name (intersection, candidates):
return next (iter (c for c in candidates if not intersection.isdisjoint (get_variant_set (c))))
maximum_tags = 0
for language, tags in sorted (ot.from_bcp_47.items ()):
if language == '' or '-' in language:
continue
print (' {\"%s\",\t{' % language, end='')
maximum_tags = max (maximum_tags, len (tags))
tag_count = len (tags)
for i, tag in enumerate (tags, start=1):
if i > 1:
print ('\t\t ', end='')
print (hb_tag (tag), end='')
if i == tag_count:
print ('}}', end='')
print (',\t/* ', end='')
print (' {\"%s\",\t%s},\t/* ' % (language, hb_tag (tag)), end='')
bcp_47_name = bcp_47.names.get (language, '')
bcp_47_name_candidates = bcp_47_name.split ('\n')
intersection = language_name_intersection (bcp_47_name, ot.names[tag])
@ -923,8 +914,6 @@ for language, tags in sorted (ot.from_bcp_47.items ()):
print ('};')
print ()
print ('static_assert (HB_OT_MAX_TAGS_PER_LANGUAGE == %iu, "");' % maximum_tags)
print ()
print ('/**')
print (' * hb_ot_tags_from_complex_language:')

File diff suppressed because it is too large Load Diff

View File

@ -198,7 +198,7 @@ lang_matches (const char *lang_str, const char *spec)
struct LangTag
{
char language[4];
hb_tag_t tags[HB_OT_MAX_TAGS_PER_LANGUAGE];
hb_tag_t tag;
int cmp (const char *a) const
{
@ -246,6 +246,7 @@ hb_ot_tags_from_language (const char *lang_str,
hb_tag_t *tags)
{
const char *s;
unsigned int tag_idx;
/* Check for matches of multiple subtags. */
if (hb_ot_tags_from_complex_language (lang_str, limit, count, tags))
@ -254,7 +255,6 @@ hb_ot_tags_from_language (const char *lang_str,
/* Find a language matching in the first component. */
s = strchr (lang_str, '-');
{
const LangTag *lang_tag;
if (s && limit - lang_str >= 6)
{
const char *extlang_end = strchr (s + 1, '-');
@ -263,12 +263,18 @@ hb_ot_tags_from_language (const char *lang_str,
ISALPHA (s[1]))
lang_str = s + 1;
}
lang_tag = hb_sorted_array (ot_languages).bsearch (lang_str);
if (lang_tag)
if (hb_sorted_array (ot_languages).bfind (lang_str, &tag_idx))
{
unsigned int i;
for (i = 0; i < *count && lang_tag->tags[i] != HB_TAG_NONE; i++)
tags[i] = lang_tag->tags[i];
while (tag_idx != 0 &&
0 == strcmp (ot_languages[tag_idx].language, ot_languages[tag_idx - 1].language))
tag_idx--;
for (i = 0;
i < *count &&
tag_idx + i < ARRAY_LENGTH (ot_languages) &&
0 == strcmp (ot_languages[tag_idx + i].language, ot_languages[tag_idx].language);
i++)
tags[i] = ot_languages[tag_idx + i].tag;
*count = i;
return;
}
@ -417,7 +423,7 @@ hb_ot_tag_to_language (hb_tag_t tag)
}
for (i = 0; i < ARRAY_LENGTH (ot_languages); i++)
if (ot_languages[i].tags[0] == tag)
if (ot_languages[i].tag == tag)
return hb_language_from_string (ot_languages[i].language, -1);
/* Else return a custom language in the form of "x-hbotABCD" */
@ -506,7 +512,7 @@ test_langs_sorted ()
for (unsigned int i = 1; i < ARRAY_LENGTH (ot_languages); i++)
{
int c = ot_languages[i].cmp (&ot_languages[i - 1]);
if (c >= 0)
if (c > 0)
{
fprintf (stderr, "ot_languages not sorted at index %d: %s %d %s\n",
i, ot_languages[i-1].language, c, ot_languages[i].language);