1 /*
2 * Copyright (c) 2003 Ben Harris
3 * All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following
12 * conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
22 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26 /*
27 * macenc.c -- Convert a Mac OS script/region/font combination to our
28 * internal charset code.
29 */
30
31 #include <string.h>
32
33 #include "charset.h"
34 #include "internal.h"
35
36 /*
37 * These are defined by Mac OS's <Script.h>, but we'd like to be
38 * independent of that.
39 */
40
41 #define smRoman 0
42 #define smJapanese 1
43 #define smTradChinese 2
44 #define smKorean 3
45 #define smArabic 4
46 #define smHebrew 5
47 #define smCyrillic 7
48 #define smDevenagari 9
49 #define smGurmukhi 10
50 #define smGujurati 11
51 #define smThai 21
52 #define smSimpChinese 25
53 #define smTibetan 26
54 #define smEthiopic 28
55 #define smCentralEuroRoman 29
56
57 #define verGreece 20
58 #define verIceland 21
59 #define verTurkey 24
60 #define verYugoCroatian 25
61 #define verRomania 39
62 #define verFaroeIsl 47
63 #define verIran 48
64 #define verRussia 49
65 #define verSlovenian 66
66 #define verCroatia 68
67 #define verBulgaria 72
68 #define verScottishGaelic 75
69 #define verManxGaelic 76
70 #define verBreton 77
71 #define verNunavut 78
72 #define verWelsh 79
73 #define verIrishGaelicScript 81
74
75 static const struct {
76 int script;
77 int region;
78 int sysvermin;
79 char const *fontname;
80 int charset;
81 } macencs[] = {
82 { smRoman, -1, 0x850, "VT100", CS_MAC_VT100 },
83 { smRoman, -1, 0, "VT100", CS_MAC_VT100_OLD },
84 /*
85 * From here on, this table is largely derived from
86 * <http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/README.TXT>,
87 * with _OLD version added based on the comments in individual
88 * mapping files.
89 */
90 { smRoman, -1, 0, "Symbol", CS_MAC_SYMBOL },
91 { smRoman, -1, 0, "Zapf Dingbats", CS_MAC_DINGBATS },
92 { smRoman, verTurkey, 0, NULL, CS_MAC_TURKISH },
93 { smRoman, verYugoCroatian, 0x850, NULL, CS_MAC_CROATIAN },
94 { smRoman, verYugoCroatian, 0, NULL, CS_MAC_CROATIAN_OLD },
95 { smRoman, verSlovenian, 0x850, NULL, CS_MAC_CROATIAN },
96 { smRoman, verSlovenian, 0, NULL, CS_MAC_CROATIAN_OLD },
97 { smRoman, verCroatia, 0x850, NULL, CS_MAC_CROATIAN },
98 { smRoman, verCroatia, 0, NULL, CS_MAC_CROATIAN_OLD },
99 { smRoman, verIceland, 0x850, NULL, CS_MAC_ICELAND },
100 { smRoman, verIceland, 0, NULL, CS_MAC_ICELAND_OLD },
101 { smRoman, verFaroeIsl, 0x850, NULL, CS_MAC_ICELAND },
102 { smRoman, verFaroeIsl, 0, NULL, CS_MAC_ICELAND_OLD },
103 { smRoman, verRomania, 0x850, NULL, CS_MAC_ROMANIAN },
104 { smRoman, verRomania, 0, NULL, CS_MAC_ROMANIAN_OLD },
105 #if 0 /* No mapping table on ftp.unicode.org */
106 { smRoman, verIreland, 0x850, NULL, CS_MAC_CELTIC },
107 { smRoman, verIreland, 0, NULL, CS_MAC_CELTIC_OLD },
108 { smRoman, verScottishGaelic, 0x850, NULL, CS_MAC_CELTIC },
109 { smRoman, verScottishGaelic, 0, NULL, CS_MAC_CELTIC_OLD },
110 { smRoman, verManxGaelic, 0x850, NULL, CS_MAC_CELTIC },
111 { smRoman, verManxGaelic, 0, NULL, CS_MAC_CELTIC_OLD },
112 { smRoman, verBreton, 0x850, NULL, CS_MAC_CELTIC },
113 { smRoman, verBreton, 0, NULL, CS_MAC_CELTIC_OLD },
114 { smRoman, verWelsh, 0x850, NULL, CS_MAC_CELTIC },
115 { smRoman, verWelsh, 0, NULL, CS_MAC_CELTIC_OLD },
116 { smRoman, verIrishGaelicScript, 0x850, NULL, CS_MAC_GAELIC },
117 { smRoman, verIrishGaelicScript, 0, NULL, CS_MAC_GAELIC_OLD },
118 #endif
119 { smRoman, verGreece, 0x922, NULL, CS_MAC_GREEK },
120 { smRoman, verGreece, 0, NULL, CS_MAC_GREEK_OLD },
121 { smRoman, -1, 0x850, NULL, CS_MAC_ROMAN },
122 { smRoman, -1, 0, NULL, CS_MAC_ROMAN_OLD },
123 #if 0 /* Multi-byte encodings, not yet supported */
124 { smJapanese, -1, 0, NULL, CS_MAC_JAPANESE },
125 { smTradChinese, -1, 0, NULL, CS_MAC_CHINTRAD },
126 { smKorean, -1, 0, NULL, CS_MAC_KOREAN },
127 #endif
128 #if 0 /* Bidirectional encodings, not yet supported */
129 { smArabic, verIran, 0, NULL, CS_MAC_FARSI },
130 { smArabic, -1, 0, NULL, CS_MAC_ARABIC },
131 { smHebrew, -1, 0, NULL, CS_MAC_HEBREW },
132 #endif
133 { smCyrillic, -1, 0x900, NULL, CS_MAC_CYRILLIC },
134 { smCyrillic, verRussia, 0, NULL, CS_MAC_CYRILLIC_OLD },
135 { smCyrillic, verBulgaria, 0, NULL, CS_MAC_CYRILLIC_OLD },
136 { smCyrillic, -1, 0, NULL, CS_MAC_UKRAINE },
137 #if 0 /* Complex Indic scripts, not yet supported */
138 { smDevanagari, -1, 0, NULL, CS_MAC_DEVENAGA },
139 { smGurmukhi, -1, 0, NULL, CS_MAC_GURMUKHI },
140 { smGujurati, -1, 0, NULL, CS_MAC_GUJURATI },
141 #endif
142 { smThai, -1, 0, NULL, CS_MAC_THAI },
143 #if 0 /* Multi-byte encoding, not yet supported */
144 { smSimpChinese, -1, 0, NULL, CS_MAC_CHINSIMP },
145 #endif
146 #if 0 /* No mapping table on ftp.unicode.org */
147 { smTibetan, -1, 0, NULL, CS_MAC_TIBETAN },
148 { smEthiopic, -1, 0, NULL, CS_MAC_ETHIOPIC },
149 { smEthiopic, verNanavut, 0, NULL, CS_MAC_INUIT },
150 #endif
151 { smCentralEuroRoman, -1, 0, NULL, CS_MAC_CENTEURO },
152 };
153
charset_from_macenc(int script,int region,int sysvers,char const * fontname)154 int charset_from_macenc(int script, int region, int sysvers,
155 char const *fontname)
156 {
157 int i;
158
159 for (i = 0; i < (int)lenof(macencs); i++)
160 if ((macencs[i].script == script) &&
161 (macencs[i].region < 0 || macencs[i].region == region) &&
162 (macencs[i].sysvermin <= sysvers) &&
163 (macencs[i].fontname == NULL ||
164 (fontname != NULL && strcmp(macencs[i].fontname, fontname) == 0)))
165 return macencs[i].charset;
166
167 return CS_NONE;
168 }
169