1 /*
2  * Copyright © 2009  Red Hat, Inc.
3  * Copyright © 2011  Google, Inc.
4  *
5  *  This is part of HarfBuzz, a text shaping library.
6  *
7  * Permission is hereby granted, without written agreement and without
8  * license or royalty fees, to use, copy, modify, and distribute this
9  * software and its documentation for any purpose, provided that the
10  * above copyright notice and the following two paragraphs appear in
11  * all copies of this software.
12  *
13  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17  * DAMAGE.
18  *
19  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24  *
25  * Red Hat Author(s): Behdad Esfahbod
26  * Google Author(s): Behdad Esfahbod, Roozbeh Pournader
27  */
28 
29 #include "hb-private.hh"
30 
31 #include <string.h>
32 
33 
34 
35 /* hb_script_t */
36 
37 static hb_tag_t
hb_ot_old_tag_from_script(hb_script_t script)38 hb_ot_old_tag_from_script (hb_script_t script)
39 {
40   /* This seems to be accurate as of end of 2012. */
41 
42   switch ((hb_tag_t) script) {
43     case HB_SCRIPT_INVALID:		return HB_OT_TAG_DEFAULT_SCRIPT;
44 
45     /* KATAKANA and HIRAGANA both map to 'kana' */
46     case HB_SCRIPT_HIRAGANA:		return HB_TAG('k','a','n','a');
47 
48     /* Spaces at the end are preserved, unlike ISO 15924 */
49     case HB_SCRIPT_LAO:			return HB_TAG('l','a','o',' ');
50     case HB_SCRIPT_YI:			return HB_TAG('y','i',' ',' ');
51     /* Unicode-5.0 additions */
52     case HB_SCRIPT_NKO:			return HB_TAG('n','k','o',' ');
53     /* Unicode-5.1 additions */
54     case HB_SCRIPT_VAI:			return HB_TAG('v','a','i',' ');
55     /* Unicode-5.2 additions */
56     /* Unicode-6.0 additions */
57   }
58 
59   /* Else, just change first char to lowercase and return */
60   return ((hb_tag_t) script) | 0x20000000u;
61 }
62 
63 static hb_script_t
hb_ot_old_tag_to_script(hb_tag_t tag)64 hb_ot_old_tag_to_script (hb_tag_t tag)
65 {
66   if (unlikely (tag == HB_OT_TAG_DEFAULT_SCRIPT))
67     return HB_SCRIPT_INVALID;
68 
69   /* This side of the conversion is fully algorithmic. */
70 
71   /* Any spaces at the end of the tag are replaced by repeating the last
72    * letter.  Eg 'nko ' -> 'Nkoo' */
73   if (unlikely ((tag & 0x0000FF00u) == 0x00002000u))
74     tag |= (tag >> 8) & 0x0000FF00u; /* Copy second letter to third */
75   if (unlikely ((tag & 0x000000FFu) == 0x00000020u))
76     tag |= (tag >> 8) & 0x000000FFu; /* Copy third letter to fourth */
77 
78   /* Change first char to uppercase and return */
79   return (hb_script_t) (tag & ~0x20000000u);
80 }
81 
82 static hb_tag_t
hb_ot_new_tag_from_script(hb_script_t script)83 hb_ot_new_tag_from_script (hb_script_t script)
84 {
85   switch ((hb_tag_t) script) {
86     case HB_SCRIPT_BENGALI:		return HB_TAG('b','n','g','2');
87     case HB_SCRIPT_DEVANAGARI:		return HB_TAG('d','e','v','2');
88     case HB_SCRIPT_GUJARATI:		return HB_TAG('g','j','r','2');
89     case HB_SCRIPT_GURMUKHI:		return HB_TAG('g','u','r','2');
90     case HB_SCRIPT_KANNADA:		return HB_TAG('k','n','d','2');
91     case HB_SCRIPT_MALAYALAM:		return HB_TAG('m','l','m','2');
92     case HB_SCRIPT_ORIYA:		return HB_TAG('o','r','y','2');
93     case HB_SCRIPT_TAMIL:		return HB_TAG('t','m','l','2');
94     case HB_SCRIPT_TELUGU:		return HB_TAG('t','e','l','2');
95     case HB_SCRIPT_MYANMAR:		return HB_TAG('m','y','m','2');
96   }
97 
98   return HB_OT_TAG_DEFAULT_SCRIPT;
99 }
100 
101 static hb_script_t
hb_ot_new_tag_to_script(hb_tag_t tag)102 hb_ot_new_tag_to_script (hb_tag_t tag)
103 {
104   switch (tag) {
105     case HB_TAG('b','n','g','2'):	return HB_SCRIPT_BENGALI;
106     case HB_TAG('d','e','v','2'):	return HB_SCRIPT_DEVANAGARI;
107     case HB_TAG('g','j','r','2'):	return HB_SCRIPT_GUJARATI;
108     case HB_TAG('g','u','r','2'):	return HB_SCRIPT_GURMUKHI;
109     case HB_TAG('k','n','d','2'):	return HB_SCRIPT_KANNADA;
110     case HB_TAG('m','l','m','2'):	return HB_SCRIPT_MALAYALAM;
111     case HB_TAG('o','r','y','2'):	return HB_SCRIPT_ORIYA;
112     case HB_TAG('t','m','l','2'):	return HB_SCRIPT_TAMIL;
113     case HB_TAG('t','e','l','2'):	return HB_SCRIPT_TELUGU;
114     case HB_TAG('m','y','m','2'):	return HB_SCRIPT_MYANMAR;
115   }
116 
117   return HB_SCRIPT_UNKNOWN;
118 }
119 
120 /*
121  * Complete list at:
122  * https://www.microsoft.com/typography/otspec/scripttags.htm
123  * https://www.microsoft.com/typography/otspec160/scripttagsProposed.htm
124  *
125  * Most of the script tags are the same as the ISO 15924 tag but lowercased.
126  * So we just do that, and handle the exceptional cases in a switch.
127  */
128 
129 void
hb_ot_tags_from_script(hb_script_t script,hb_tag_t * script_tag_1,hb_tag_t * script_tag_2)130 hb_ot_tags_from_script (hb_script_t  script,
131 			hb_tag_t    *script_tag_1,
132 			hb_tag_t    *script_tag_2)
133 {
134   hb_tag_t new_tag;
135 
136   *script_tag_2 = HB_OT_TAG_DEFAULT_SCRIPT;
137   *script_tag_1 = hb_ot_old_tag_from_script (script);
138 
139   new_tag = hb_ot_new_tag_from_script (script);
140   if (unlikely (new_tag != HB_OT_TAG_DEFAULT_SCRIPT)) {
141     *script_tag_2 = *script_tag_1;
142     *script_tag_1 = new_tag;
143   }
144 }
145 
146 hb_script_t
hb_ot_tag_to_script(hb_tag_t tag)147 hb_ot_tag_to_script (hb_tag_t tag)
148 {
149   if (unlikely ((tag & 0x000000FFu) == '2'))
150     return hb_ot_new_tag_to_script (tag);
151 
152   return hb_ot_old_tag_to_script (tag);
153 }
154 
155 
156 /* hb_language_t */
157 
158 typedef struct {
159   char language[4];
160   hb_tag_t tag;
161 } LangTag;
162 
163 /*
164  * Complete list at:
165  * http://www.microsoft.com/typography/otspec/languagetags.htm
166  *
167  * Generated by intersecting the OpenType language tag list from
168  * Draft OpenType 1.5 spec, with with the ISO 639-3 codes from
169  * 2008-08-04, matching on name, and finally adjusted manually.
170  *
171  * Updated on 2012-12-07 with more research into remaining codes.
172  *
173  * Updated on 2013-11-23 based on usage in SIL and Microsoft fonts,
174  * the new proposal from Microsoft, and latest ISO 639-3 names.
175  *
176  * Some items still missing.  Those are commented out at the end.
177  * Keep sorted for bsearch.
178  */
179 
180 static const LangTag ot_languages[] = {
181   {"aa",	HB_TAG('A','F','R',' ')},	/* Afar */
182   {"ab",	HB_TAG('A','B','K',' ')},	/* Abkhazian */
183   {"abq",	HB_TAG('A','B','A',' ')},	/* Abaza */
184   {"ach",	HB_TAG('A','C','H',' ')},	/* Acoli */
185   {"ada",	HB_TAG('D','N','G',' ')},	/* Dangme */
186   {"ady",	HB_TAG('A','D','Y',' ')},	/* Adyghe */
187   {"af",	HB_TAG('A','F','K',' ')},	/* Afrikaans */
188   {"aii",	HB_TAG('S','W','A',' ')},	/* Swadaya Aramaic */
189   {"aio",	HB_TAG('A','I','O',' ')},	/* Aiton */
190   {"aiw",	HB_TAG('A','R','I',' ')},	/* Aari */
191   {"ak",	HB_TAG('T','W','I',' ')},	/* Akan [macrolanguage] */
192   {"alt",	HB_TAG('A','L','T',' ')},	/* [Southern] Altai */
193   {"am",	HB_TAG('A','M','H',' ')},	/* Amharic */
194   {"amf",	HB_TAG('H','B','N',' ')},	/* Hammer-Banna */
195   {"an",	HB_TAG('A','R','G',' ')},	/* Aragonese */
196   {"ang",	HB_TAG('A','N','G',' ')},	/* Old English (ca. 450-1100) */
197   {"ar",	HB_TAG('A','R','A',' ')},	/* Arabic [macrolanguage] */
198   {"arb",	HB_TAG('A','R','A',' ')},	/* Standard Arabic */
199   {"arn",	HB_TAG('M','A','P',' ')},	/* Mapudungun */
200   {"ary",	HB_TAG('M','O','R',' ')},	/* Moroccan Arabic */
201   {"as",	HB_TAG('A','S','M',' ')},	/* Assamese */
202   {"ast",	HB_TAG('A','S','T',' ')},	/* Asturian/Asturleonese/Bable/Leonese */
203   {"ath",	HB_TAG('A','T','H',' ')},	/* Athapaskan [family] */
204   {"atv",	HB_TAG('A','L','T',' ')},	/* [Northern] Altai */
205   {"av",	HB_TAG('A','V','R',' ')},	/* Avaric */
206   {"awa",	HB_TAG('A','W','A',' ')},	/* Awadhi */
207   {"ay",	HB_TAG('A','Y','M',' ')},	/* Aymara [macrolanguage] */
208   {"az",	HB_TAG('A','Z','E',' ')},	/* Azerbaijani [macrolanguage] */
209   {"azb",	HB_TAG('A','Z','B',' ')},	/* South Azerbaijani */
210   {"azj",	HB_TAG('A','Z','E',' ')},	/* North Azerbaijani */
211   {"ba",	HB_TAG('B','S','H',' ')},	/* Bashkir */
212   {"bai",	HB_TAG('B','M','L',' ')},	/* Bamileke [family] */
213   {"bal",	HB_TAG('B','L','I',' ')},	/* Baluchi [macrolangauge] */
214   {"ban",	HB_TAG('B','A','N',' ')},	/* Balinese */
215   {"bar",	HB_TAG('B','A','R',' ')},	/* Bavarian */
216   {"bbc",	HB_TAG('B','B','C',' ')},	/* Batak Toba */
217   {"bci",	HB_TAG('B','A','U',' ')},	/* Baoulé */
218   {"bcl",	HB_TAG('B','I','K',' ')},	/* Central Bikol */
219   {"bcq",	HB_TAG('B','C','H',' ')},	/* Bench */
220   {"be",	HB_TAG('B','E','L',' ')},  	/* Belarusian */
221   {"bem",	HB_TAG('B','E','M',' ')},	/* Bemba (Zambia) */
222   {"ber",	HB_TAG('B','E','R',' ')},  	/* Berber [family] */
223   {"bfq",	HB_TAG('B','A','D',' ')},	/* Badaga */
224   {"bft",	HB_TAG('B','L','T',' ')},	/* Balti */
225   {"bfy",	HB_TAG('B','A','G',' ')},	/* Baghelkhandi */
226   {"bg",	HB_TAG('B','G','R',' ')},	/* Bulgarian */
227   {"bgc",	HB_TAG('B','G','C',' ')},	/* Haryanvi */
228   {"bgq",	HB_TAG('B','G','Q',' ')},	/* Bagri */
229   {"bhb",	HB_TAG('B','H','I',' ')},	/* Bhili */
230   {"bhk",	HB_TAG('B','I','K',' ')},	/* Albay Bicolano (retired code) */
231   {"bho",	HB_TAG('B','H','O',' ')},	/* Bhojpuri */
232   {"bi",	HB_TAG('B','I','S',' ')},	/* Bislama */
233   {"bik",	HB_TAG('B','I','K',' ')},	/* Bikol [macrolanguage] */
234   {"bin",	HB_TAG('E','D','O',' ')},	/* Bini */
235   {"bjj",	HB_TAG('B','J','J',' ')},	/* Kanauji */
236   {"bjt",	HB_TAG('B','L','N',' ')},	/* Balanta-Ganja */
237   {"bla",	HB_TAG('B','K','F',' ')},	/* Blackfoot */
238   {"ble",	HB_TAG('B','L','N',' ')},	/* Balanta-Kentohe */
239   {"blk",	HB_TAG('B','L','K',' ')},	/* Pa'O/Pa'o Karen */
240   {"bln",	HB_TAG('B','I','K',' ')},	/* Southern Catanduanes Bikol */
241   {"bm",	HB_TAG('B','M','B',' ')},	/* Bambara */
242   {"bn",	HB_TAG('B','E','N',' ')},	/* Bengali */
243   {"bo",	HB_TAG('T','I','B',' ')},	/* Tibetan */
244   {"bpy",	HB_TAG('B','P','Y',' ')},	/* Bishnupriya */
245   {"bqi",	HB_TAG('L','R','C',' ')},	/* Bakhtiari */
246   {"br",	HB_TAG('B','R','E',' ')},	/* Breton */
247   {"bra",	HB_TAG('B','R','I',' ')},	/* Braj Bhasha */
248   {"brh",	HB_TAG('B','R','H',' ')},	/* Brahui */
249   {"brx",	HB_TAG('B','R','X',' ')},	/* Bodo (India) */
250   {"bs",	HB_TAG('B','O','S',' ')},	/* Bosnian */
251   {"btb",	HB_TAG('B','T','I',' ')},	/* Beti (Cameroon) */
252   {"bto",	HB_TAG('B','I','K',' ')},	/* Rinconada Bikol */
253   {"bts",	HB_TAG('B','T','S',' ')},	/* Batak Simalungun */
254   {"bug",	HB_TAG('B','U','G',' ')},	/* Buginese */
255   {"bxr",	HB_TAG('R','B','U',' ')},	/* Russian Buriat */
256   {"byn",	HB_TAG('B','I','L',' ')},	/* Bilen */
257   {"ca",	HB_TAG('C','A','T',' ')},	/* Catalan */
258   {"cbk",	HB_TAG('C','B','K',' ')},	/* Chavacano */
259   {"ce",	HB_TAG('C','H','E',' ')},	/* Chechen */
260   {"ceb",	HB_TAG('C','E','B',' ')},	/* Cebuano */
261   {"cgg",	HB_TAG('C','G','G',' ')},	/* Chiga */
262   {"ch",	HB_TAG('C','H','A',' ')},	/* Chamorro */
263   {"cho",	HB_TAG('C','H','O',' ')},	/* Choctaw */
264   {"chp",	HB_TAG('C','H','P',' ')},	/* Chipewyan */
265   {"chr",	HB_TAG('C','H','R',' ')},	/* Cherokee */
266   {"chy",	HB_TAG('C','H','Y',' ')},	/* Cheyenne */
267   {"ckb",	HB_TAG('K','U','R',' ')},	/* Central Kurdish (Sorani) */
268   {"ckt",	HB_TAG('C','H','K',' ')},	/* Chukchi */
269   {"cop",	HB_TAG('C','O','P',' ')},	/* Coptic */
270   {"cr",	HB_TAG('C','R','E',' ')},	/* Cree */
271   {"crh",	HB_TAG('C','R','T',' ')},	/* Crimean Tatar */
272   {"crj",	HB_TAG('E','C','R',' ')},	/* [Southern] East Cree */
273   {"crl",	HB_TAG('E','C','R',' ')},	/* [Northern] East Cree */
274   {"crm",	HB_TAG('M','C','R',' ')},	/* Moose Cree */
275   {"crx",	HB_TAG('C','R','R',' ')},	/* Carrier */
276   {"cs",	HB_TAG('C','S','Y',' ')},	/* Czech */
277   {"csb",	HB_TAG('C','S','B',' ')},	/* Kashubian */
278   {"ctg",	HB_TAG('C','T','G',' ')},	/* Chittagonian */
279   {"cts",	HB_TAG('B','I','K',' ')},	/* Northern Catanduanes Bikol */
280   {"cu",	HB_TAG('C','S','L',' ')},	/* Church Slavic */
281   {"cv",	HB_TAG('C','H','U',' ')},	/* Chuvash */
282   {"cwd",	HB_TAG('D','C','R',' ')},	/* Woods Cree */
283   {"cy",	HB_TAG('W','E','L',' ')},	/* Welsh */
284   {"da",	HB_TAG('D','A','N',' ')},	/* Danish */
285   {"dap",	HB_TAG('N','I','S',' ')},	/* Nisi (India) */
286   {"dar",	HB_TAG('D','A','R',' ')},	/* Dargwa */
287   {"de",	HB_TAG('D','E','U',' ')},	/* German */
288   {"dgo",	HB_TAG('D','G','O',' ')},	/* Dogri */
289   {"dhd",	HB_TAG('M','A','W',' ')},	/* Dhundari */
290   {"din",	HB_TAG('D','N','K',' ')},	/* Dinka [macrolanguage] */
291   {"diq",	HB_TAG('D','I','Q',' ')},	/* Dimli */
292   {"dje",	HB_TAG('D','J','R',' ')},	/* Zarma */
293   {"dng",	HB_TAG('D','U','N',' ')},	/* Dungan */
294   {"doi",	HB_TAG('D','G','R',' ')},	/* Dogri [macrolanguage] */
295   {"dsb",	HB_TAG('L','S','B',' ')},	/* Lower Sorbian */
296   {"dv",	HB_TAG('D','I','V',' ')},	/* Dhivehi/Divehi/Maldivian */
297   {"dyu",	HB_TAG('J','U','L',' ')},	/* Jula */
298   {"dz",	HB_TAG('D','Z','N',' ')},	/* Dzongkha */
299   {"ee",	HB_TAG('E','W','E',' ')},	/* Ewe */
300   {"efi",	HB_TAG('E','F','I',' ')},	/* Efik */
301   {"ekk",	HB_TAG('E','T','I',' ')},	/* Standard Estonian */
302   {"el",	HB_TAG('E','L','L',' ')},	/* Modern Greek (1453-) */
303   {"emk",	HB_TAG('M','N','K',' ')},	/* Eastern Maninkakan */
304   {"en",	HB_TAG('E','N','G',' ')},	/* English */
305   {"eo",	HB_TAG('N','T','O',' ')},	/* Esperanto */
306   {"eot",	HB_TAG('B','T','I',' ')},	/* Beti (Côte d'Ivoire) */
307   {"es",	HB_TAG('E','S','P',' ')},	/* Spanish */
308   {"et",	HB_TAG('E','T','I',' ')},	/* Estonian [macrolanguage] */
309   {"eu",	HB_TAG('E','U','Q',' ')},	/* Basque */
310   {"eve",	HB_TAG('E','V','N',' ')},	/* Even */
311   {"evn",	HB_TAG('E','V','K',' ')},	/* Evenki */
312   {"fa",	HB_TAG('F','A','R',' ')},	/* Persian [macrolanguage] */
313   {"ff",	HB_TAG('F','U','L',' ')},	/* Fulah [macrolanguage] */
314   {"fi",	HB_TAG('F','I','N',' ')},	/* Finnish */
315   {"fil",	HB_TAG('P','I','L',' ')},	/* Filipino */
316   {"fj",	HB_TAG('F','J','I',' ')},	/* Fijian */
317   {"fo",	HB_TAG('F','O','S',' ')},	/* Faroese */
318   {"fon",	HB_TAG('F','O','N',' ')},	/* Fon */
319   {"fr",	HB_TAG('F','R','A',' ')},	/* French */
320   {"frc",	HB_TAG('F','R','C',' ')},	/* Cajun French */
321   {"frp",	HB_TAG('F','R','P',' ')},	/* Arpitan/Francoprovençal */
322   {"fur",	HB_TAG('F','R','L',' ')},	/* Friulian */
323   {"fuv",	HB_TAG('F','U','V',' ')},	/* Nigerian Fulfulde */
324   {"fy",	HB_TAG('F','R','I',' ')},	/* Western Frisian */
325   {"ga",	HB_TAG('I','R','I',' ')},	/* Irish */
326   {"gaa",	HB_TAG('G','A','D',' ')},	/* Ga */
327   {"gag",	HB_TAG('G','A','G',' ')},	/* Gagauz */
328   {"gbm",	HB_TAG('G','A','W',' ')},	/* Garhwali */
329   {"gd",	HB_TAG('G','A','E',' ')},	/* Scottish Gaelic */
330   {"gez",	HB_TAG('G','E','Z',' ')},	/* Ge'ez */
331   {"ggo",	HB_TAG('G','O','N',' ')},	/* Southern Gondi */
332   {"gl",	HB_TAG('G','A','L',' ')},	/* Galician */
333   {"gld",	HB_TAG('N','A','N',' ')},	/* Nanai */
334   {"glk",	HB_TAG('G','L','K',' ')},	/* Gilaki */
335   {"gn",	HB_TAG('G','U','A',' ')},	/* Guarani [macrolanguage] */
336   {"gno",	HB_TAG('G','O','N',' ')},	/* Northern Gondi */
337   {"gog",	HB_TAG('G','O','G',' ')},	/* Gogo */
338   {"gon",	HB_TAG('G','O','N',' ')},	/* Gondi [macrolanguage] */
339   {"grt",	HB_TAG('G','R','O',' ')},	/* Garo */
340   {"gru",	HB_TAG('S','O','G',' ')},	/* Sodo Gurage */
341   {"gu",	HB_TAG('G','U','J',' ')},	/* Gujarati */
342   {"guc",	HB_TAG('G','U','C',' ')},	/* Wayuu */
343   {"guk",	HB_TAG('G','M','Z',' ')},	/* Gumuz */
344 /*{"guk",	HB_TAG('G','U','K',' ')},*/	/* Gumuz (in SIL fonts) */
345   {"guz",	HB_TAG('G','U','Z',' ')},	/* Ekegusii/Gusii */
346   {"gv",	HB_TAG('M','N','X',' ')},	/* Manx */
347   {"ha",	HB_TAG('H','A','U',' ')},	/* Hausa */
348   {"har",	HB_TAG('H','R','I',' ')},	/* Harari */
349   {"haw",	HB_TAG('H','A','W',' ')},  	/* Hawaiian */
350   {"hay",	HB_TAG('H','A','Y',' ')},  	/* Haya */
351   {"haz",	HB_TAG('H','A','Z',' ')},  	/* Hazaragi */
352   {"he",	HB_TAG('I','W','R',' ')},	/* Hebrew */
353   {"hz",	HB_TAG('H','E','R',' ')},	/* Herero */
354   {"hi",	HB_TAG('H','I','N',' ')},	/* Hindi */
355   {"hil",	HB_TAG('H','I','L',' ')},	/* Hiligaynon */
356   {"hnd",	HB_TAG('H','N','D',' ')},	/* [Southern] Hindko */
357   {"hne",	HB_TAG('C','H','H',' ')},	/* Chattisgarhi */
358   {"hno",	HB_TAG('H','N','D',' ')},	/* [Northern] Hindko */
359   {"ho",	HB_TAG('H','M','O',' ')},	/* Hiri Motu */
360   {"hoc",	HB_TAG('H','O',' ',' ')},	/* Ho */
361   {"hoj",	HB_TAG('H','A','R',' ')},	/* Harauti */
362   {"hr",	HB_TAG('H','R','V',' ')},	/* Croatian */
363   {"hsb",	HB_TAG('U','S','B',' ')},	/* Upper Sorbian */
364   {"ht",	HB_TAG('H','A','I',' ')},	/* Haitian/Haitian Creole */
365   {"hu",	HB_TAG('H','U','N',' ')},	/* Hungarian */
366   {"hy",	HB_TAG('H','Y','E',' ')},	/* Armenian */
367   {"hz",	HB_TAG('H','E','R',' ')},	/* Herero */
368   {"ia",	HB_TAG('I','N','A',' ')},	/* Interlingua (International Auxiliary Language Association) */
369   {"ibb",	HB_TAG('I','B','B',' ')},	/* Ibibio */
370   {"id",	HB_TAG('I','N','D',' ')},	/* Indonesian */
371   {"ie",	HB_TAG('I','L','E',' ')},	/* Interlingue/Occidental */
372   {"ig",	HB_TAG('I','B','O',' ')},	/* Igbo */
373   {"igb",	HB_TAG('E','B','I',' ')},	/* Ebira */
374   {"ijc",	HB_TAG('I','J','O',' ')},	/* Izon */
375   {"ijo",	HB_TAG('I','J','O',' ')},	/* Ijo [family] */
376   {"ik",	HB_TAG('I','P','K',' ')},	/* Inupiaq [macrolanguage] */
377   {"ilo",	HB_TAG('I','L','O',' ')},	/* Ilokano */
378   {"inh",	HB_TAG('I','N','G',' ')},	/* Ingush */
379   {"io",	HB_TAG('I','D','O',' ')},	/* Ido */
380   {"is",	HB_TAG('I','S','L',' ')},	/* Icelandic */
381   {"it",	HB_TAG('I','T','A',' ')},	/* Italian */
382   {"iu",	HB_TAG('I','N','U',' ')},	/* Inuktitut [macrolanguage] */
383   {"ja",	HB_TAG('J','A','N',' ')},	/* Japanese */
384   {"jam",	HB_TAG('J','A','M',' ')},	/* Jamaican Creole English */
385   {"jbo",	HB_TAG('J','B','O',' ')},	/* Lojban */
386   {"jv",	HB_TAG('J','A','V',' ')},	/* Javanese */
387   {"ka",	HB_TAG('K','A','T',' ')},	/* Georgian */
388   {"kaa",	HB_TAG('K','R','K',' ')},	/* Karakalpak */
389   {"kab",	HB_TAG('K','A','B',' ')},	/* Kabyle */
390   {"kam",	HB_TAG('K','M','B',' ')},	/* Kamba (Kenya) */
391   {"kar",	HB_TAG('K','R','N',' ')},	/* Karen [family] */
392   {"kbd",	HB_TAG('K','A','B',' ')},	/* Kabardian */
393   {"kde",	HB_TAG('K','D','E',' ')},	/* Makonde */
394   {"kdr",	HB_TAG('K','R','M',' ')},	/* Karaim */
395   {"kdt",	HB_TAG('K','U','Y',' ')},	/* Kuy */
396   {"kex",	HB_TAG('K','K','N',' ')},	/* Kokni */
397   {"kfr",	HB_TAG('K','A','C',' ')},	/* Kachchi */
398   {"kfy",	HB_TAG('K','M','N',' ')},	/* Kumaoni */
399   {"kg",	HB_TAG('K','O','N',' ')},	/* Kongo [macrolanguage] */
400   {"kha",	HB_TAG('K','S','I',' ')},	/* Khasi */
401   {"khb",	HB_TAG('X','B','D',' ')},	/* Lü */
402   {"kht",	HB_TAG('K','H','N',' ')},	/* Khamti (Microsoft fonts) */
403 /*{"kht",	HB_TAG('K','H','T',' ')},*/	/* Khamti (OpenType spec and SIL fonts) */
404   {"khw",	HB_TAG('K','H','W',' ')},	/* Khowar */
405   {"ki",	HB_TAG('K','I','K',' ')},	/* Gikuyu/Kikuyu */
406   {"kj",	HB_TAG('K','U','A',' ')},	/* Kuanyama/Kwanyama */
407   {"kjh",	HB_TAG('K','H','A',' ')},	/* Khakass */
408   {"kjp",	HB_TAG('K','J','P',' ')},	/* Pwo Eastern Karen */
409   {"kk",	HB_TAG('K','A','Z',' ')},	/* Kazakh */
410   {"kl",	HB_TAG('G','R','N',' ')},	/* Kalaallisut */
411   {"kln",	HB_TAG('K','A','L',' ')},	/* Kalenjin */
412   {"km",	HB_TAG('K','H','M',' ')},	/* Central Khmer */
413   {"kmb",	HB_TAG('M','B','N',' ')},	/* Kimbundu */
414   {"kmw",	HB_TAG('K','M','O',' ')},	/* Komo (Democratic Republic of Congo) */
415   {"kn",	HB_TAG('K','A','N',' ')},	/* Kannada */
416   {"knn",	HB_TAG('K','O','K',' ')},	/* Konkani */
417   {"ko",	HB_TAG('K','O','R',' ')},	/* Korean */
418   {"koi",	HB_TAG('K','O','P',' ')},	/* Komi-Permyak */
419   {"kok",	HB_TAG('K','O','K',' ')},	/* Konkani [macrolanguage] */
420   {"kpe",	HB_TAG('K','P','L',' ')},	/* Kpelle [macrolanguage] */
421   {"kpv",	HB_TAG('K','O','Z',' ')},	/* Komi-Zyrian */
422   {"kpy",	HB_TAG('K','Y','K',' ')},	/* Koryak */
423   {"kqy",	HB_TAG('K','R','T',' ')},	/* Koorete */
424   {"kr",	HB_TAG('K','N','R',' ')},	/* Kanuri [macrolanguage] */
425   {"kri",	HB_TAG('K','R','I',' ')},	/* Krio */
426   {"krl",	HB_TAG('K','R','L',' ')},	/* Karelian */
427   {"kru",	HB_TAG('K','U','U',' ')},	/* Kurukh */
428   {"ks",	HB_TAG('K','S','H',' ')},	/* Kashmiri */
429   {"ksh",	HB_TAG('K','S','H',' ')},	/* Kölsch */
430 /*{"ksw",	HB_TAG('K','R','N',' ')},*/	/* S'gaw Karen (Microsoft fonts?) */
431   {"ksw",	HB_TAG('K','S','W',' ')},	/* S'gaw Karen (OpenType spec and SIL fonts) */
432   {"ku",	HB_TAG('K','U','R',' ')},	/* Kurdish [macrolanguage] */
433   {"kum",	HB_TAG('K','U','M',' ')},	/* Kumyk */
434   {"kv",	HB_TAG('K','O','M',' ')},	/* Komi [macrolanguage] */
435   {"kvd",	HB_TAG('K','U','I',' ')},	/* Kui (Indonesia) */
436   {"kw",	HB_TAG('C','O','R',' ')},	/* Cornish */
437   {"kxc",	HB_TAG('K','M','S',' ')},	/* Komso */
438   {"kxu",	HB_TAG('K','U','I',' ')},	/* Kui (India) */
439   {"ky",	HB_TAG('K','I','R',' ')},	/* Kirghiz/Kyrgyz */
440   {"kyu",	HB_TAG('K','Y','U',' ')},	/* Western Kayah */
441   {"la",	HB_TAG('L','A','T',' ')},	/* Latin */
442   {"lad",	HB_TAG('J','U','D',' ')},	/* Ladino */
443   {"lb",	HB_TAG('L','T','Z',' ')},	/* Luxembourgish */
444   {"lbe",	HB_TAG('L','A','K',' ')},	/* Lak */
445   {"lbj",	HB_TAG('L','D','K',' ')},	/* Ladakhi */
446   {"lez",	HB_TAG('L','E','Z',' ')},	/* Lezgi */
447   {"lg",	HB_TAG('L','U','G',' ')},	/* Ganda */
448   {"li",	HB_TAG('L','I','M',' ')},	/* Limburgan/Limburger/Limburgish */
449   {"lif",	HB_TAG('L','M','B',' ')},	/* Limbu */
450   {"lij",	HB_TAG('L','I','J',' ')},	/* Ligurian */
451   {"lis",	HB_TAG('L','I','S',' ')},	/* Lisu */
452   {"ljp",	HB_TAG('L','J','P',' ')},	/* Lampung Api */
453   {"lki",	HB_TAG('L','K','I',' ')},	/* Laki */
454   {"lld",	HB_TAG('L','A','D',' ')},	/* Ladin */
455   {"lmn",	HB_TAG('L','A','M',' ')},	/* Lambani */
456   {"lmo",	HB_TAG('L','M','O',' ')},	/* Lombard */
457   {"ln",	HB_TAG('L','I','N',' ')},	/* Lingala */
458   {"lo",	HB_TAG('L','A','O',' ')},	/* Lao */
459   {"lrc",	HB_TAG('L','R','C',' ')},	/* Northern Luri */
460   {"lt",	HB_TAG('L','T','H',' ')},	/* Lithuanian */
461   {"lu",	HB_TAG('L','U','B',' ')},	/* Luba-Katanga */
462   {"lua",	HB_TAG('L','U','B',' ')},	/* Luba-Kasai */
463   {"luo",	HB_TAG('L','U','O',' ')},	/* Luo (Kenya and Tanzania) */
464   {"lus",	HB_TAG('M','I','Z',' ')},	/* Mizo */
465   {"luy",	HB_TAG('L','U','H',' ')},	/* Luyia/Oluluyia [macrolanguage] */
466   {"luz",	HB_TAG('L','R','C',' ')},	/* Southern Luri */
467   {"lv",	HB_TAG('L','V','I',' ')},	/* Latvian */
468   {"lzz",	HB_TAG('L','A','Z',' ')},	/* Laz */
469   {"mad",	HB_TAG('M','A','D',' ')},	/* Madurese */
470   {"mag",	HB_TAG('M','A','G',' ')},	/* Magahi */
471   {"mai",	HB_TAG('M','T','H',' ')},	/* Maithili */
472   {"mak",	HB_TAG('M','K','R',' ')},	/* Makasar */
473   {"man",	HB_TAG('M','N','K',' ')},	/* Manding/Mandingo [macrolanguage] */
474   {"mdc",	HB_TAG('M','L','E',' ')},	/* Male (Papua New Guinea) */
475   {"mdf",	HB_TAG('M','O','K',' ')},	/* Moksha */
476   {"mdr",	HB_TAG('M','D','R',' ')},	/* Mandar */
477   {"mdy",	HB_TAG('M','L','E',' ')},	/* Male (Ethiopia) */
478   {"men",	HB_TAG('M','D','E',' ')},	/* Mende (Sierra Leone) */
479   {"mer",	HB_TAG('M','E','R',' ')},	/* Meru */
480   {"mfe",	HB_TAG('M','F','E',' ')},	/* Morisyen */
481   {"mg",	HB_TAG('M','L','G',' ')},	/* Malagasy [macrolanguage] */
482   {"mh",	HB_TAG('M','A','H',' ')},	/* Marshallese */
483   {"mhr",	HB_TAG('L','M','A',' ')},	/* Low Mari */
484   {"mi",	HB_TAG('M','R','I',' ')},	/* Maori */
485   {"min",	HB_TAG('M','I','N',' ')},	/* Minangkabau */
486   {"mk",	HB_TAG('M','K','D',' ')},	/* Macedonian */
487   {"mku",	HB_TAG('M','N','K',' ')},	/* Konyanka Maninka */
488   {"mkw",	HB_TAG('M','K','W',' ')},	/* Kituba (Congo) */
489   {"ml",	HB_TAG('M','L','R',' ')},	/* Malayalam */
490   {"mlq",	HB_TAG('M','N','K',' ')},	/* Western Maninkakan */
491   {"mn",	HB_TAG('M','N','G',' ')},	/* Mongolian [macrolanguage] */
492   {"mnc",	HB_TAG('M','C','H',' ')},	/* Manchu */
493   {"mni",	HB_TAG('M','N','I',' ')},	/* Manipuri */
494   {"mnk",	HB_TAG('M','N','D',' ')},	/* Mandinka */
495   {"mns",	HB_TAG('M','A','N',' ')},	/* Mansi */
496   {"mnw",	HB_TAG('M','O','N',' ')},	/* Mon */
497   {"mo",	HB_TAG('M','O','L',' ')},	/* Moldavian */
498   {"moh",	HB_TAG('M','O','H',' ')},	/* Mohawk */
499   {"mos",	HB_TAG('M','O','S',' ')},	/* Mossi */
500   {"mpe",	HB_TAG('M','A','J',' ')},	/* Majang */
501   {"mr",	HB_TAG('M','A','R',' ')},	/* Marathi */
502   {"mrj",	HB_TAG('H','M','A',' ')},	/* High Mari */
503   {"ms",	HB_TAG('M','L','Y',' ')},	/* Malay [macrolanguage] */
504   {"msc",	HB_TAG('M','N','K',' ')},	/* Sankaran Maninka */
505   {"mt",	HB_TAG('M','T','S',' ')},	/* Maltese */
506   {"mtr",	HB_TAG('M','A','W',' ')},	/* Mewari */
507   {"mus",	HB_TAG('M','U','S',' ')},	/* Creek */
508   {"mve",	HB_TAG('M','A','W',' ')},	/* Marwari (Pakistan) */
509   {"mwk",	HB_TAG('M','N','K',' ')},	/* Kita Maninkakan */
510   {"mwl",	HB_TAG('M','W','L',' ')},	/* Mirandese */
511   {"mwr",	HB_TAG('M','A','W',' ')},	/* Marwari [macrolanguage] */
512   {"mww",	HB_TAG('M','W','W',' ')},	/* Hmong Daw */
513   {"my",	HB_TAG('B','R','M',' ')},	/* Burmese */
514   {"mym",	HB_TAG('M','E','N',' ')},	/* Me'en */
515   {"myq",	HB_TAG('M','N','K',' ')},	/* Forest Maninka (retired code) */
516   {"myv",	HB_TAG('E','R','Z',' ')},	/* Erzya */
517   {"mzn",	HB_TAG('M','Z','N',' ')},	/* Mazanderani */
518   {"na",	HB_TAG('N','A','U',' ')},	/* Nauru */
519   {"nag",	HB_TAG('N','A','G',' ')},	/* Naga-Assamese */
520   {"nah",	HB_TAG('N','A','H',' ')},	/* Nahuatl [family] */
521   {"nap",	HB_TAG('N','A','P',' ')},	/* Neapolitan */
522   {"nb",	HB_TAG('N','O','R',' ')},	/* Norwegian Bokmål */
523   {"nco",	HB_TAG('S','I','B',' ')},	/* Sibe */
524   {"nd",	HB_TAG('N','D','B',' ')},	/* [North] Ndebele */
525   {"ndc",	HB_TAG('N','D','C',' ')},	/* Ndau */
526   {"nds",	HB_TAG('N','D','S',' ')},	/* Low German/Low Saxon */
527   {"ne",	HB_TAG('N','E','P',' ')},	/* Nepali */
528   {"new",	HB_TAG('N','E','W',' ')},	/* Newari */
529   {"ng",	HB_TAG('N','D','G',' ')},	/* Ndonga */
530   {"nga",	HB_TAG('N','G','A',' ')},	/* Ngabaka */
531   {"ngl",	HB_TAG('L','M','W',' ')},	/* Lomwe */
532   {"niu",	HB_TAG('N','I','U',' ')},	/* Niuean */
533   {"niv",	HB_TAG('G','I','L',' ')},	/* Gilyak */
534   {"nl",	HB_TAG('N','L','D',' ')},	/* Dutch */
535   {"nn",	HB_TAG('N','Y','N',' ')},	/* Norwegian Nynorsk */
536   {"no",	HB_TAG('N','O','R',' ')},	/* Norwegian [macrolanguage] */
537   {"nod",	HB_TAG('N','T','A',' ')},	/* Northern Thai */
538   {"noe",	HB_TAG('N','O','E',' ')},	/* Nimadi */
539   {"nog",	HB_TAG('N','O','G',' ')},	/* Nogai */
540   {"nov",	HB_TAG('N','O','V',' ')},	/* Novial */
541   {"nqo",	HB_TAG('N','K','O',' ')},	/* N'Ko */
542   {"nr",	HB_TAG('N','D','B',' ')},	/* [South] Ndebele */
543   {"nsk",	HB_TAG('N','A','S',' ')},	/* Naskapi */
544   {"nso",	HB_TAG('S','O','T',' ')},	/* [Northern] Sotho */
545   {"ny",	HB_TAG('C','H','I',' ')},	/* Chewa/Chichwa/Nyanja */
546   {"nym",	HB_TAG('N','Y','M',' ')},	/* Nyamwezi */
547   {"nyn",	HB_TAG('N','K','L',' ')},	/* Nyankole */
548   {"oc",	HB_TAG('O','C','I',' ')},	/* Occitan (post 1500) */
549   {"oj",	HB_TAG('O','J','B',' ')},	/* Ojibwa [macrolanguage] */
550   {"ojs",	HB_TAG('O','C','R',' ')},	/* Oji-Cree */
551   {"om",	HB_TAG('O','R','O',' ')},	/* Oromo [macrolanguage] */
552   {"or",	HB_TAG('O','R','I',' ')},	/* Oriya */
553   {"os",	HB_TAG('O','S','S',' ')},	/* Ossetian */
554   {"pa",	HB_TAG('P','A','N',' ')},	/* Panjabi */
555   {"pag",	HB_TAG('P','A','G',' ')},	/* Pangasinan */
556   {"pam",	HB_TAG('P','A','M',' ')},	/* Kapampangan/Pampanga */
557   {"pap",	HB_TAG('P','A','P',' ')},	/* Papiamento */
558   {"pcc",	HB_TAG('P','C','C',' ')},	/* Bouyei */
559   {"pcd",	HB_TAG('P','C','D',' ')},	/* Picard */
560   {"pce",	HB_TAG('P','L','G',' ')},	/* [Ruching] Palaung */
561   {"pdc",	HB_TAG('P','D','C',' ')},	/* Pennsylvania German */
562   {"pes",	HB_TAG('F','A','R',' ')},	/* Iranian Persian */
563   {"phk",	HB_TAG('P','H','K',' ')},	/* Phake */
564   {"pi",	HB_TAG('P','A','L',' ')},	/* Pali */
565   {"pih",	HB_TAG('P','I','H',' ')},	/* Pitcairn-Norfolk */
566   {"pl",	HB_TAG('P','L','K',' ')},	/* Polish */
567   {"pll",	HB_TAG('P','L','G',' ')},	/* [Shwe] Palaung */
568   {"plp",	HB_TAG('P','A','P',' ')},	/* Palpa */
569   {"pms",	HB_TAG('P','M','S',' ')},	/* Piemontese */
570   {"pnb",	HB_TAG('P','N','B',' ')},	/* Western Panjabi */
571   {"prs",	HB_TAG('D','R','I',' ')},	/* Afghan Persian/Dari */
572   {"ps",	HB_TAG('P','A','S',' ')},	/* Pashto/Pushto [macrolanguage] */
573   {"pt",	HB_TAG('P','T','G',' ')},	/* Portuguese */
574   {"pwo",	HB_TAG('P','W','O',' ')},	/* Pwo Western Karen */
575   {"qu",	HB_TAG('Q','U','Z',' ')},	/* Quechua [macrolanguage] */
576   {"quc",	HB_TAG('Q','U','C',' ')},	/* K'iche'/Quiché */
577   {"quz",	HB_TAG('Q','U','Z',' ')},	/* Cusco Quechua */
578   {"raj",	HB_TAG('R','A','J',' ')},	/* Rajasthani [macrolanguage] */
579   {"rbb",	HB_TAG('P','L','G',' ')},	/* Rumai Palaung */
580   {"rej",	HB_TAG('R','E','J',' ')},	/* Rejang */
581   {"ria",	HB_TAG('R','I','A',' ')},	/* Riang (India) */
582   {"ril",	HB_TAG('R','I','A',' ')},	/* Riang (Myanmar) */
583   {"rki",	HB_TAG('A','R','K',' ')},	/* Rakhine */
584   {"rm",	HB_TAG('R','M','S',' ')},	/* Romansh */
585   {"rmy",	HB_TAG('R','M','Y',' ')},	/* Vlax Romani */
586   {"rn",	HB_TAG('R','U','N',' ')},	/* Rundi */
587   {"ro",	HB_TAG('R','O','M',' ')},	/* Romanian */
588   {"rom",	HB_TAG('R','O','Y',' ')},	/* Romany [macrolanguage] */
589   {"ru",	HB_TAG('R','U','S',' ')},	/* Russian */
590   {"rue",	HB_TAG('R','S','Y',' ')},	/* Rusyn */
591   {"rup",	HB_TAG('R','U','P',' ')},	/* Aromanian/Arumanian/Macedo-Romanian */
592   {"rw",	HB_TAG('R','U','A',' ')},	/* Kinyarwanda */
593   {"rwr",	HB_TAG('M','A','W',' ')},	/* Marwari (India) */
594   {"sa",	HB_TAG('S','A','N',' ')},	/* Sanskrit */
595   {"sah",	HB_TAG('Y','A','K',' ')},	/* Yakut */
596   {"sas",	HB_TAG('S','A','S',' ')},	/* Sasak */
597   {"sat",	HB_TAG('S','A','T',' ')},	/* Santali */
598   {"sck",	HB_TAG('S','A','D',' ')},	/* Sadri */
599   {"sc",	HB_TAG('S','R','D',' ')},	/* Sardinian [macrolanguage] */
600   {"scn",	HB_TAG('S','C','N',' ')},	/* Sicilian */
601   {"sco",	HB_TAG('S','C','O',' ')},	/* Scots */
602   {"scs",	HB_TAG('S','L','A',' ')},	/* [North] Slavey */
603   {"sd",	HB_TAG('S','N','D',' ')},	/* Sindhi */
604   {"se",	HB_TAG('N','S','M',' ')},	/* Northern Sami */
605   {"seh",	HB_TAG('S','N','A',' ')},	/* Sena */
606   {"sel",	HB_TAG('S','E','L',' ')},	/* Selkup */
607   {"sg",	HB_TAG('S','G','O',' ')},	/* Sango */
608   {"sga",	HB_TAG('S','G','A',' ')},	/* Old Irish (to 900) */
609   {"sgs",	HB_TAG('S','G','S',' ')},	/* Samogitian */
610   {"sgw",	HB_TAG('C','H','G',' ')},	/* Sebat Bet Gurage */
611 /*{"sgw",	HB_TAG('S','G','W',' ')},*/	/* Sebat Bet Gurage (in SIL fonts) */
612   {"shn",	HB_TAG('S','H','N',' ')},	/* Shan */
613   {"si",	HB_TAG('S','N','H',' ')},	/* Sinhala */
614   {"sid",	HB_TAG('S','I','D',' ')},	/* Sidamo */
615   {"sjd",	HB_TAG('K','S','M',' ')},	/* Kildin Sami */
616   {"sk",	HB_TAG('S','K','Y',' ')},	/* Slovak */
617   {"skr",	HB_TAG('S','R','K',' ')},	/* Seraiki */
618   {"sl",	HB_TAG('S','L','V',' ')},	/* Slovenian */
619   {"sm",	HB_TAG('S','M','O',' ')},	/* Samoan */
620   {"sma",	HB_TAG('S','S','M',' ')},	/* Southern Sami */
621   {"smj",	HB_TAG('L','S','M',' ')},	/* Lule Sami */
622   {"smn",	HB_TAG('I','S','M',' ')},	/* Inari Sami */
623   {"sms",	HB_TAG('S','K','S',' ')},	/* Skolt Sami */
624   {"sn",	HB_TAG('S','N','A',' ')},	/* Shona */
625   {"snk",	HB_TAG('S','N','K',' ')},	/* Soninke */
626   {"so",	HB_TAG('S','M','L',' ')},	/* Somali */
627   {"sop",	HB_TAG('S','O','P',' ')},	/* Songe */
628   {"sq",	HB_TAG('S','Q','I',' ')},	/* Albanian [macrolanguage] */
629   {"sr",	HB_TAG('S','R','B',' ')},	/* Serbian */
630   {"srr",	HB_TAG('S','R','R',' ')},	/* Serer */
631   {"ss",	HB_TAG('S','W','Z',' ')},	/* Swati */
632   {"st",	HB_TAG('S','O','T',' ')},	/* [Southern] Sotho */
633   {"stq",	HB_TAG('S','T','Q',' ')},	/* Saterfriesisch */
634   {"stv",	HB_TAG('S','I','G',' ')},	/* Silt'e */
635   {"su",	HB_TAG('S','U','N',' ')},	/* Sundanese */
636   {"suk",	HB_TAG('S','U','K',' ')},	/* Sukama */
637   {"suq",	HB_TAG('S','U','R',' ')},	/* Suri */
638   {"sv",	HB_TAG('S','V','E',' ')},	/* Swedish */
639   {"sva",	HB_TAG('S','V','A',' ')},	/* Svan */
640   {"sw",	HB_TAG('S','W','K',' ')},	/* Swahili [macrolanguage] */
641   {"swb",	HB_TAG('C','M','R',' ')},	/* Comorian */
642   {"swh",	HB_TAG('S','W','K',' ')},	/* Kiswahili/Swahili */
643   {"swv",	HB_TAG('M','A','W',' ')},	/* Shekhawati */
644   {"sxu",	HB_TAG('S','X','U',' ')},	/* Upper Saxon */
645   {"syl",	HB_TAG('S','Y','L',' ')},	/* Sylheti */
646   {"syr",	HB_TAG('S','Y','R',' ')},	/* Syriac [macrolanguage] */
647   {"szl",	HB_TAG('S','Z','L',' ')},	/* Silesian */
648   {"ta",	HB_TAG('T','A','M',' ')},	/* Tamil */
649   {"tab",	HB_TAG('T','A','B',' ')},	/* Tabasaran */
650   {"tcy",	HB_TAG('T','U','L',' ')},	/* Tulu */
651   {"tdd",	HB_TAG('T','D','D',' ')},	/* Tai Nüa */
652   {"te",	HB_TAG('T','E','L',' ')},	/* Telugu */
653   {"tem",	HB_TAG('T','M','N',' ')},	/* Temne */
654   {"tet",	HB_TAG('T','E','T',' ')},	/* Tetum */
655   {"tg",	HB_TAG('T','A','J',' ')},	/* Tajik */
656   {"th",	HB_TAG('T','H','A',' ')},	/* Thai */
657   {"ti",	HB_TAG('T','G','Y',' ')},	/* Tigrinya */
658   {"tig",	HB_TAG('T','G','R',' ')},	/* Tigre */
659   {"tiv",	HB_TAG('T','I','V',' ')},	/* Tiv */
660   {"tk",	HB_TAG('T','K','M',' ')},	/* Turkmen */
661   {"tl",	HB_TAG('T','G','L',' ')},	/* Tagalog */
662   {"tmh",	HB_TAG('t','m','h',' ')},	/* Tamashek [macrolanguage] */
663   {"tn",	HB_TAG('T','N','A',' ')},	/* Tswana */
664   {"to",	HB_TAG('T','G','N',' ')},	/* Tonga (Tonga Islands) */
665   {"tpi",	HB_TAG('T','P','I',' ')},	/* Tok Pisin */
666   {"tr",	HB_TAG('T','R','K',' ')},	/* Turkish */
667   {"tru",	HB_TAG('T','U','A',' ')},	/* Turoyo Aramaic */
668   {"ts",	HB_TAG('T','S','G',' ')},	/* Tsonga */
669   {"tt",	HB_TAG('T','A','T',' ')},	/* Tatar */
670   {"tum",	HB_TAG('T','U','M',' ')},	/* Tumbuka */
671   {"tw",	HB_TAG('T','W','I',' ')},	/* Twi */
672   {"ty",	HB_TAG('T','H','T',' ')},	/* Tahitian */
673   {"tyv",	HB_TAG('T','U','V',' ')},	/* Tuvin */
674   {"tyz",	HB_TAG('T','Y','Z',' ')},	/* Tày */
675   {"tzm",	HB_TAG('T','Z','M',' ')},	/* Central Atlas Tamazight */
676   {"udm",	HB_TAG('U','D','M',' ')},	/* Udmurt */
677   {"ug",	HB_TAG('U','Y','G',' ')},	/* Uighur */
678   {"uk",	HB_TAG('U','K','R',' ')},	/* Ukrainian */
679   {"umb",	HB_TAG('U','M','B',' ')},	/* Umbundu */
680   {"unr",	HB_TAG('M','U','N',' ')},	/* Mundari */
681   {"ur",	HB_TAG('U','R','D',' ')},	/* Urdu */
682   {"uz",	HB_TAG('U','Z','B',' ')},	/* Uzbek [macrolanguage] */
683   {"uzn",	HB_TAG('U','Z','B',' ')},	/* Northern Uzbek */
684   {"uzs",	HB_TAG('U','Z','B',' ')},	/* Southern Uzbek */
685   {"ve",	HB_TAG('V','E','N',' ')},	/* Venda */
686   {"vec",	HB_TAG('V','E','C',' ')},	/* Venetian */
687   {"vls",	HB_TAG('F','L','E',' ')},	/* Vlaams */
688   {"vi",	HB_TAG('V','I','T',' ')},	/* Vietnamese */
689   {"vmw",	HB_TAG('M','A','K',' ')},	/* Makhuwa */
690   {"vo",	HB_TAG('V','O','L',' ')},	/* Volapük */
691   {"vro",	HB_TAG('V','R','O',' ')},	/* Võro */
692   {"wa",	HB_TAG('W','L','N',' ')},	/* Walloon */
693   {"war",	HB_TAG('W','A','R',' ')},	/* Waray (Philippines) */
694   {"wbm",	HB_TAG('W','A',' ',' ')},	/* Wa */
695   {"wbr",	HB_TAG('W','A','G',' ')},	/* Wagdi */
696   {"wle",	HB_TAG('S','I','G',' ')},	/* Wolane */
697   {"wry",	HB_TAG('M','A','W',' ')},	/* Merwari */
698   {"wtm",	HB_TAG('W','T','M',' ')},	/* Mewati */
699   {"wo",	HB_TAG('W','L','F',' ')},	/* Wolof */
700   {"xal",	HB_TAG('K','L','M',' ')},	/* Kalmyk */
701   {"xh",	HB_TAG('X','H','S',' ')},	/* Xhosa */
702   {"xog",	HB_TAG('X','O','G',' ')},	/* Soga */
703   {"xom",	HB_TAG('K','M','O',' ')},	/* Komo (Sudan) */
704   {"xsl",	HB_TAG('S','S','L',' ')},	/* South Slavey */
705   {"xst",	HB_TAG('S','I','G',' ')},	/* Silt'e (retired code) */
706   {"xwo",	HB_TAG('T','O','D',' ')},	/* Written Oirat (Todo) */
707   {"yao",	HB_TAG('Y','A','O',' ')},	/* Yao */
708   {"yi",	HB_TAG('J','I','I',' ')},	/* Yiddish [macrolanguage] */
709   {"yo",	HB_TAG('Y','B','A',' ')},	/* Yoruba */
710   {"yso",	HB_TAG('N','I','S',' ')},	/* Nisi (China) */
711   {"za",	HB_TAG('Z','H','A',' ')},	/* Chuang/Zhuang [macrolanguage] */
712   {"zea",	HB_TAG('Z','E','A',' ')},	/* Zeeuws */
713   {"zne",	HB_TAG('Z','N','D',' ')},	/* Zande */
714   {"zu",	HB_TAG('Z','U','L',' ')}, 	/* Zulu */
715   {"zum",	HB_TAG('L','R','C',' ')}	/* Kumzari */
716 
717   /* The corresponding languages IDs for the following IDs are unclear,
718    * overlap, or are architecturally weird. Needs more research. */
719 
720 /*{"ahg/awn/xan?",	HB_TAG('A','G','W',' ')},*/	/* Agaw */
721 /*{"gsw?/gsw-FR?",	HB_TAG('A','L','S',' ')},*/	/* Alsatian */
722 /*{"krc",	HB_TAG('B','A','L',' ')},*/	/* Balkar */
723 /*{"??",	HB_TAG('B','C','R',' ')},*/	/* Bible Cree */
724 /*{"zh?",	HB_TAG('C','H','N',' ')},*/	/* Chinese (seen in Microsoft fonts) */
725 /*{"acf/gcf?",	HB_TAG('F','A','N',' ')},*/	/* French Antillean */
726 /*{"enf?/yrk?",	HB_TAG('F','N','E',' ')},*/	/* Forest Nenets */
727 /*{"fuf?",	HB_TAG('F','T','A',' ')},*/	/* Futa */
728 /*{"ar-Syrc?",	HB_TAG('G','A','R',' ')},*/	/* Garshuni */
729 /*{"cfm/rnl?",	HB_TAG('H','A','L',' ')},*/	/* Halam */
730 /*{"fonipa",	HB_TAG('I','P','P','H')},*/	/* Phonetic transcription—IPA conventions */
731 /*{"ga-Latg?/Latg?",	HB_TAG('I','R','T',' ')},*/	/* Irish Traditional */
732 /*{"krc",	HB_TAG('K','A','R',' ')},*/	/* Karachay */
733 /*{"alw?/ktb?",	HB_TAG('K','E','B',' ')},*/	/* Kebena */
734 /*{"Geok",	HB_TAG('K','G','E',' ')},*/	/* Khutsuri Georgian */
735 /*{"kca",	HB_TAG('K','H','K',' ')},*/	/* Khanty-Kazim */
736 /*{"kca",	HB_TAG('K','H','S',' ')},*/	/* Khanty-Shurishkar */
737 /*{"kca",	HB_TAG('K','H','V',' ')},*/	/* Khanty-Vakhi */
738 /*{"guz?/kqs?/kss?",	HB_TAG('K','I','S',' ')},*/	/* Kisii */
739 /*{"kfa/kfi?/kpb?/xua?/xuj?",	HB_TAG('K','O','D',' ')},*/	/* Kodagu */
740 /*{"okm?/oko?",	HB_TAG('K','O','H',' ')},*/	/* Korean Old Hangul */
741 /*{"kon?/ktu?/...",	HB_TAG('K','O','N',' ')},*/	/* Kikongo */
742 /*{"kfx?",	HB_TAG('K','U','L',' ')},*/	/* Kulvi */
743 /*{"??",	HB_TAG('L','A','H',' ')},*/	/* Lahuli */
744 /*{"??",	HB_TAG('L','C','R',' ')},*/	/* L-Cree */
745 /*{"??",	HB_TAG('M','A','L',' ')},*/	/* Malayalam Traditional */
746 /*{"mnk?/mlq?/...",	HB_TAG('M','L','N',' ')},*/	/* Malinke */
747 /*{"??",	HB_TAG('N','C','R',' ')},*/	/* N-Cree */
748 /*{"??",	HB_TAG('N','H','C',' ')},*/	/* Norway House Cree */
749 /*{"jpa?/sam?",	HB_TAG('P','A','A',' ')},*/	/* Palestinian Aramaic */
750 /*{"polyton",	HB_TAG('P','G','R',' ')},*/	/* Polytonic Greek */
751 /*{"??",	HB_TAG('Q','I','N',' ')},*/	/* Asho Chin */
752 /*{"??",	HB_TAG('R','C','R',' ')},*/	/* R-Cree */
753 /*{"chp?",	HB_TAG('S','A','Y',' ')},*/	/* Sayisi */
754 /*{"xan?",	HB_TAG('S','E','K',' ')},*/	/* Sekota */
755 /*{"ngo?",	HB_TAG('S','X','T',' ')},*/	/* Sutu */
756 /*{"??",	HB_TAG('T','C','R',' ')},*/	/* TH-Cree */
757 /*{"tnz?/tog?/toi?",	HB_TAG('T','N','G',' ')},*/	/* Tonga */
758 /*{"enh?/yrk?",	HB_TAG('T','N','E',' ')},*/	/* Tundra Nenets */
759 /*{"??",	HB_TAG('W','C','R',' ')},*/	/* West-Cree */
760 /*{"cre?",	HB_TAG('Y','C','R',' ')},*/	/* Y-Cree */
761 /*{"??",	HB_TAG('Y','I','C',' ')},*/	/* Yi Classic */
762 /*{"ii?/Yiii?",	HB_TAG('Y','I','M',' ')},*/	/* Yi Modern */
763 /*{"??",	HB_TAG('Z','H','P',' ')},*/	/* Chinese Phonetic */
764 };
765 
766 typedef struct {
767   char language[8];
768   hb_tag_t tag;
769 } LangTagLong;
770 static const LangTagLong ot_languages_zh[] = {
771   {"zh-cn",	HB_TAG('Z','H','S',' ')},	/* Chinese (China) */
772   {"zh-hk",	HB_TAG('Z','H','H',' ')},	/* Chinese (Hong Kong) */
773   {"zh-mo",	HB_TAG('Z','H','T',' ')},	/* Chinese (Macao) */
774   {"zh-sg",	HB_TAG('Z','H','S',' ')},	/* Chinese (Singapore) */
775   {"zh-tw",	HB_TAG('Z','H','T',' ')},	/* Chinese (Taiwan) */
776   {"zh-hans",	HB_TAG('Z','H','S',' ')},	/* Chinese (Simplified) */
777   {"zh-hant",	HB_TAG('Z','H','T',' ')},	/* Chinese (Traditional) */
778 };
779 
780 static int
lang_compare_first_component(const char * a,const char * b)781 lang_compare_first_component (const char *a,
782 			      const char *b)
783 {
784   unsigned int da, db;
785   const char *p;
786 
787   p = strchr (a, '-');
788   da = p ? (unsigned int) (p - a) : strlen (a);
789 
790   p = strchr (b, '-');
791   db = p ? (unsigned int) (p - b) : strlen (b);
792 
793   return strncmp (a, b, MAX (da, db));
794 }
795 
796 static hb_bool_t
lang_matches(const char * lang_str,const char * spec)797 lang_matches (const char *lang_str, const char *spec)
798 {
799   unsigned int len = strlen (spec);
800 
801   return strncmp (lang_str, spec, len) == 0 &&
802 	 (lang_str[len] == '\0' || lang_str[len] == '-');
803 }
804 
805 hb_tag_t
hb_ot_tag_from_language(hb_language_t language)806 hb_ot_tag_from_language (hb_language_t language)
807 {
808   const char *lang_str, *s;
809 
810   if (language == HB_LANGUAGE_INVALID)
811     return HB_OT_TAG_DEFAULT_LANGUAGE;
812 
813   lang_str = hb_language_to_string (language);
814 
815   s = strstr (lang_str, "x-hbot");
816   if (s) {
817     char tag[4];
818     int i;
819     s += 6;
820     for (i = 0; i < 4 && ISALPHA (s[i]); i++)
821       tag[i] = TOUPPER (s[i]);
822     if (i) {
823       for (; i < 4; i++)
824 	tag[i] = ' ';
825       return HB_TAG_CHAR4 (tag);
826     }
827   }
828 
829   /* Find a language matching in the first component */
830   {
831     const LangTag *lang_tag;
832     lang_tag = (LangTag *) bsearch (lang_str, ot_languages,
833 				    ARRAY_LENGTH (ot_languages), sizeof (LangTag),
834 				    (hb_compare_func_t) lang_compare_first_component);
835     if (lang_tag)
836       return lang_tag->tag;
837   }
838 
839   /* Otherwise, check the Chinese ones */
840   if (0 == lang_compare_first_component (lang_str, "zh"))
841   {
842     unsigned int i;
843 
844     for (i = 0; i < ARRAY_LENGTH (ot_languages_zh); i++)
845     {
846       const LangTagLong *lang_tag;
847       lang_tag = &ot_languages_zh[i];
848       if (lang_matches (lang_str, lang_tag->language))
849 	return lang_tag->tag;
850     }
851 
852     /* Otherwise just return 'ZHS ' */
853     return HB_TAG('Z','H','S',' ');
854   }
855 
856   s = strchr (lang_str, '-');
857   if (!s)
858     s = lang_str + strlen (lang_str);
859   if (s - lang_str == 3) {
860     /* Assume it's ISO-639-3 and upper-case and use it. */
861     return hb_tag_from_string (lang_str, s - lang_str) & ~0x20202000u;
862   }
863 
864   return HB_OT_TAG_DEFAULT_LANGUAGE;
865 }
866 
867 hb_language_t
hb_ot_tag_to_language(hb_tag_t tag)868 hb_ot_tag_to_language (hb_tag_t tag)
869 {
870   unsigned int i;
871 
872   if (tag == HB_OT_TAG_DEFAULT_LANGUAGE)
873     return NULL;
874 
875   for (i = 0; i < ARRAY_LENGTH (ot_languages); i++)
876     if (ot_languages[i].tag == tag)
877       return hb_language_from_string (ot_languages[i].language, -1);
878 
879   /* If tag starts with ZH, it's Chinese */
880   if ((tag & 0xFFFF0000u)  == 0x5A480000u) {
881     switch (tag) {
882       case HB_TAG('Z','H','H',' '): return hb_language_from_string ("zh-hk", -1); /* Hong Kong */
883       case HB_TAG('Z','H','S',' '): return hb_language_from_string ("zh-Hans", -1); /* Simplified */
884       case HB_TAG('Z','H','T',' '): return hb_language_from_string ("zh-Hant", -1); /* Traditional */
885       default: break; /* Fall through */
886     }
887   }
888 
889   /* Else return a custom language in the form of "x-hbotABCD" */
890   {
891     unsigned char buf[11] = "x-hbot";
892     buf[6] = tag >> 24;
893     buf[7] = (tag >> 16) & 0xFF;
894     buf[8] = (tag >> 8) & 0xFF;
895     buf[9] = tag & 0xFF;
896     if (buf[9] == 0x20)
897       buf[9] = '\0';
898     buf[10] = '\0';
899     return hb_language_from_string ((char *) buf, -1);
900   }
901 }
902 
903 
904