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