FLTK 1.4.4: ucs2fontmap.c Source File

FLTK 1.4.4

Loading...
Searching...
No Matches
ucs2fontmap.c
1/*
2 * Author: Jean-Marc Lienher ( http://oksid.ch )
3 * Copyright 2000-2003 by O'ksi'D.
4 *
5 * This library is free software. Distribution and use rights are outlined in
6 * the file "COPYING" which should have been included with this file. If this
7 * file is missing or damaged, see the license at:
8 *
9 * https://www.fltk.org/COPYING.php
10 *
11 * Please see the following page on how to report bugs and issues:
12 *
13 * https://www.fltk.org/bugs.php
14 */
15
16#include <stdlib.h>
17#include <string.h>
18
19#define RET_ILSEQ -1
20#define RET_TOOFEW(x) (-10 - x)
21#define RET_TOOSMALL -2
22#define conv_t void*
23#define ucs4_t unsigned int
24typedef struct {
25 unsigned short indx;
26 unsigned short used;
27} Summary16;
28
29#define NEED_TOMB /* indicates what part of these include files is needed here (avoid compilation warnings) */
30#include "lcUniConv/cp936ext.h"
31#include "lcUniConv/big5.h"
32#include "lcUniConv/gb2312.h"
33#include "lcUniConv/iso8859_10.h"
34#include "lcUniConv/iso8859_11.h"
35#include "lcUniConv/iso8859_13.h"
36#include "lcUniConv/iso8859_14.h"
37#include "lcUniConv/iso8859_15.h"
38#include "lcUniConv/iso8859_2.h"
39#include "lcUniConv/iso8859_3.h"
40#include "lcUniConv/iso8859_4.h"
41#include "lcUniConv/iso8859_5.h"
42#include "lcUniConv/iso8859_6.h"
43#include "lcUniConv/iso8859_7.h"
44#include "lcUniConv/iso8859_8.h"
45#include "lcUniConv/iso8859_9.h"
46#include "lcUniConv/jisx0201.h"
47#include "lcUniConv/jisx0208.h"
48#include "lcUniConv/jisx0212.h"
49#include "lcUniConv/koi8_r.h"
50#include "lcUniConv/koi8_u.h"
51#include "lcUniConv/ksc5601.h"
52#include "lcUniConv/cp1251.h"
53#include "headers/symbol_.h"
54#include "headers/dingbats_.h"
55
56/*************** conv_gen.c ************/
57
58/*const*/
59static int ucs2fontmap(char *s, unsigned int ucs, int enc) {
60 switch(enc) {
61 case 0: /* iso10646-1 */
62 s[0] = (char) ((ucs & 0xFF00) >> 8);
63 s[1] = (char) (ucs & 0xFF);
64 return 0;
65 case 1: /* iso8859-1 */
66 if (ucs <= 0x00FF) {
67 if (ucs >= 0x0001) {
68 s[0] = 0;
69 s[1] = (char) (ucs & 0xFF);
70 return 1;
71 }
72 }
73 break;
74 case 2: /* iso8859-2 */
75 if (ucs <= 0x00a0) {
76 s[0] = 0;
77 s[1] = (char) ucs;
78 return 2;
79 } else if (ucs < 0x0180) {
80 if (ucs >= 0x00a0) {
81 s[0] = 0;
82 s[1] = (char) iso8859_2_page00[ucs-0x00a0];
83 if (s[1]) return 2;
84 }
85 } else if (ucs < 0x02e0) {
86 if (ucs >= 0x02c0) {
87 s[0] = 0;
88 s[1] = (char) iso8859_2_page02[ucs-0x02c0];
89 if (s[1]) return 2;
90 }
91 }
92 break;
93 case 3: /* iso8859-3 */
94 if (iso8859_3_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
95 return 3;
96 }
97 break;
98 case 4: /* iso8859-4 */
99 if (iso8859_4_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
100 return 4;
101 }
102 break;
103 case 5: /* iso8859-5 */
104 if (iso8859_5_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
105 return 5;
106 }
107 break;
108 case 6: /* iso8859-6 */
109 if (iso8859_6_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
110 return 6;
111 }
112 break;
113 case 7: /* iso8859-7 */
114 if (iso8859_7_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
115 return 7;
116 }
117 break;
118 case 8: /* iso8859-8 */
119 if (iso8859_8_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
120 return 8;
121 }
122 break;
123 case 9: /* iso8859-9 */
124 if (iso8859_9_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
125 return 9;
126 }
127 break;
128 case 10: /* iso8859-10 */
129 if (iso8859_10_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
130 return 10;
131 }
132 break;
133 case 25: /* iso8859-11 */
134 if (iso8859_11_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
135 return 25;
136 }
137 break;
138 case 11: /* iso8859-13 */
139 if (iso8859_13_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
140 return 11;
141 }
142 break;
143 case 12: /* iso8859-14 */
144 if (iso8859_14_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
145 return 12;
146 }
147 break;
148 case 13: /* iso8859-15 */
149 if (iso8859_15_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
150 return 13;
151 }
152 break;
153 case 14: /* koi8-r */
154 if (koi8_r_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
155 return 14;
156 }
157 break;
158 case 15: /* big5 */
159 if (big5_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
160 return 15;
161 }
162 break;
163 case 16: /* ksc5601.1987-0 */
164 if (ksc5601_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
165 return 16;
166 }
167 break;
168 case 17: /* gb2312.1980-0 */
169 if (gb2312_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
170 return 17;
171 }
172 break;
173 case 18: /* jisx0201.1976-0 */
174 if (jisx0201_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
175 return 18;
176 }
177 break;
178 case 19: /* jisx0208.1983-0 */
179 if (jisx0208_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
180 return 19;
181 }
182 break;
183 case 20: /* jisx0212.1990-0 */
184 if (jisx0212_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
185 return 20;
186 }
187 break;
188 case 21: /* symbol */
189 if (ucs <= 0x00F7) {
190 if (ucs >= 0x0020) {
191 s[0] = 0;
192 s[1] = unicode_to_symbol_1b_0020[ucs - 0x0020];
193 if (s[1]) return 21;
194 }
195 } else if (ucs <= 0x0192) {
196 if (ucs >= 0x0192) {
197 s[0] = 0;
198 s[1] = unicode_to_symbol_1b_0192[ucs - 0x0192];
199 if (s[1]) return 21;
200 }
201 } else if (ucs <= 0x03D6) {
202 if (ucs >= 0x0391) {
203 s[0] = 0;
204 s[1] = unicode_to_symbol_1b_0391[ucs - 0x0391];
205 if (s[1]) return 21;
206 }
207 } else if (ucs <= 0x232A) {
208 if (ucs >= 0x2022) {
209 s[0] = 0;
210 s[1] = unicode_to_symbol_1b_2022[ucs - 0x2022];
211 if (s[1]) return 21;
212 }
213 } else if (ucs <= 0x25CA) {
214 if (ucs >= 0x25CA) {
215 s[0] = 0;
216 s[1] = unicode_to_symbol_1b_25CA[ucs - 0x25CA];
217 if (s[1]) return 21;
218 }
219 } else if (ucs <= 0x2666) {
220 if (ucs >= 0x2660) {
221 s[0] = 0;
222 s[1] = unicode_to_symbol_1b_2660[ucs - 0x2660];
223 if (s[1]) return 21;
224 }
225 } else if (ucs <= 0xF6DB) {
226 if (ucs >= 0xF6D9) {
227 s[0] = 0;
228 s[1] = unicode_to_symbol_1b_F6D9[ucs - 0xF6D9];
229 if (s[1]) return 21;
230 }
231 } else if (ucs <= 0xF8FE) {
232 if (ucs >= 0xF8E5) {
233 s[0] = 0;
234 s[1] = unicode_to_symbol_1b_F8E5[ucs - 0xF8E5];
235 if (s[1]) return 21;
236 }
237 }
238 break;
239 case 22: /* dingbats */
240 if (ucs <= 0x00A0) {
241 if (ucs >= 0x0020) {
242 s[0] = 0;
243 s[1] = unicode_to_dingbats_1b_0020[ucs - 0x0020];
244 if (s[1]) return 22;
245 }
246 } else if (ucs <= 0x2195) {
247 if (ucs >= 0x2192) {
248 s[0] = 0;
249 s[1] = unicode_to_dingbats_1b_2192[ucs - 0x2192];
250 if (s[1]) return 22;
251 }
252 } else if (ucs <= 0x2469) {
253 if (ucs >= 0x2460) {
254 s[0] = 0;
255 s[1] = unicode_to_dingbats_1b_2460[ucs - 0x2460];
256 if (s[1]) return 22;
257 }
258 } else if (ucs <= 0x2666) {
259 if (ucs >= 0x25A0) {
260 s[0] = 0;
261 s[1] = unicode_to_dingbats_1b_25A0[ucs - 0x25A0];
262 if (s[1]) return 22;
263 }
264 } else if (ucs <= 0x27BE) {
265 if (ucs >= 0x2701) {
266 s[0] = 0;
267 s[1] = unicode_to_dingbats_1b_2701[ucs - 0x2701];
268 if (s[1]) return 22;
269 }
270 } else if (ucs <= 0xF8E4) {
271 if (ucs >= 0xF8D7) {
272 s[0] = 0;
273 s[1] = unicode_to_dingbats_1b_F8D7[ucs - 0xF8D7];
274 if (s[1]) return 22;
275 }
276 }
277 break;
278 case 23: /* koi8-u */
279 if (koi8_u_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
280 return 23;
281 }
282 break;
283 case 24: /* microsoft-cp1251 */
284 if (cp1251_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
285 return 24;
286 }
287 break;
288 case 26: /* gbk/cp936ext */
289 if (cp936ext_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
290 return 26;
291 }
292 break;
293 default:
294 break;
295 };
296 return -1;
297}
298
299/*const*/
300static int encoding_number(const char *enc) {
301 if (!enc || !strncmp(enc, "iso10646-1", 10)) {
302 return 0;
303 } else if (!strcmp(enc, "iso8859-1")) {
304 return 1;
305 } else if (!strcmp(enc, "iso8859-2")) {
306 return 2;
307 } else if (!strcmp(enc, "iso8859-3")) {
308 return 3;
309 } else if (!strcmp(enc, "iso8859-4")) {
310 return 4;
311 } else if (!strcmp(enc, "iso8859-5")) {
312 return 5;
313 } else if (!strcmp(enc, "iso8859-6")) {
314 return 6;
315 } else if (!strcmp(enc, "iso8859-7")) {
316 return 7;
317 } else if (!strcmp(enc, "iso8859-8")) {
318 return 8;
319 } else if (!strcmp(enc, "iso8859-9")) {
320 return 9;
321 } else if (!strcmp(enc, "iso8859-10")) {
322 return 10;
323 } else if (!strcmp(enc, "iso8859-13")) {
324 return 11;
325 } else if (!strcmp(enc, "iso8859-14")) {
326 return 12;
327 } else if (!strcmp(enc, "iso8859-15")) {
328 return 13;
329 } else if (!strcmp(enc, "koi8-r")) {
330 return 14;
331 } else if (!strcmp(enc, "big5-0") || !strcmp(enc, "big5.eten-0") ||
332 !strcmp(enc, "big5p-0"))
333 {
334 return 15;
335 } else if (!strcmp(enc, "ksc5601.1987-0")) {
336 return 16;
337 } else if (!strcmp(enc, "gb2312.1980-0") || !strcmp(enc, "gb2312.80-0") ||
338 !strcmp(enc, "gb2312.80&gb8565.88") || !strcmp(enc, "gb2312.80-0"))
339 {
340 return 17;
341 } else if (!strcmp(enc, "jisx0201.1976-0")) {
342 return 18;
343 } else if (!strcmp(enc, "jisx0208.1983-0") || !strcmp(enc, "jisx0208.1990-0")
344 || !strcmp(enc, "jisx0208.1978-0"))
345 {
346 return 19;
347 } else if (!strcmp(enc, "jisx0212.1990-0")) {
348 return 20;
349 } else if (!strcmp(enc, "symbol")) {
350 return 21;
351 } else if (!strcmp(enc, "dingbats") || !strcmp(enc, "zapfdingbats") ||
352 !strcmp(enc, "zapf dingbats") || !strcmp(enc, "itc zapf dingbats"))
353 {
354 return 22;
355 } else if (!strcmp(enc, "koi8-u")) {
356 return 23;
357 } else if (!strcmp(enc, "microsoft-cp1251")) {
358 return 24;
359 } else if (!strcmp(enc, "iso8859-11")) {
360 return 25;
361 } else if (!strcmp(enc, "gbk-0") || !strcmp(enc, "cp936") || !strcmp(enc, "gbk")) {
362 return 26;
363 };
364 return -1;
365}