From 738d096a06822e63b3894bd817ecb90e5fb94f73 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 2 Sep 2011 13:31:19 -0400 Subject: [PATCH] Pass through unknown ISO 639-3 language tags to OpenType engine In hb_ot_tag_from_language(), if first component of an unknown language is three letters long, use it directly as OpenType language tag (after case conversion and padding). --- src/hb-ot-tag.cc | 8 ++++++++ test/test-ot-tag.c | 5 +++++ 2 files changed, 13 insertions(+) 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