diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc index dcae8f199..ac60e960a 100644 --- a/src/hb-ot-tag.cc +++ b/src/hb-ot-tag.cc @@ -651,6 +651,14 @@ hb_ot_tag_from_language (hb_language_t language) return HB_TAG('Z','H','S',' '); } + s = strchr (lang_str, '-'); + if (!s) + s = lang_str + strlen (lang_str); + if (s - lang_str == 3) { + /* Assume it's ISO-639-3 and upper-case and use it. */ + return hb_tag_from_string (lang_str, s - lang_str) & ~0x20202000; + } + return HB_OT_TAG_DEFAULT_LANGUAGE; } diff --git a/test/test-ot-tag.c b/test/test-ot-tag.c index a00799d06..81b667840 100644 --- a/test/test-ot-tag.c +++ b/test/test-ot-tag.c @@ -213,12 +213,17 @@ test_ot_tag_language (void) test_tag_from_language ("dflt", "asdf-asdf-wer-x-hbot-zxc"); + test_tag_from_language ("dflt", "xy"); + test_tag_from_language ("XYZ", "xyz"); /* Unknown ISO 639-3 */ + test_tag_from_language ("XYZ", "xyz-qw"); /* Unknown ISO 639-3 */ + /* Test that x-hbot overrides the base language */ test_tag_from_language ("ABC", "fa-x-hbotabc-zxc"); test_tag_from_language ("ABC", "fa-ir-x-hbotabc-zxc"); test_tag_from_language ("ABC", "zh-x-hbotabc-zxc"); test_tag_from_language ("ABC", "zh-cn-x-hbotabc-zxc"); test_tag_from_language ("ABC", "zh-xy-x-hbotabc-zxc"); + test_tag_from_language ("ABC", "xyz-xy-x-hbotabc-zxc"); } int