FLTK 1.3.9: ucs2fontmap.c Source File

FLTK 1.3.9

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