… | |
… | |
15 | * |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software |
17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | */ |
19 | */ |
|
|
20 | |
|
|
21 | /* |
|
|
22 | 2002/Apr. Keita KAWABE |
|
|
23 | A: <META HTTP-EQUIV="Content-Type" CONTENT="text/html"> header |
|
|
24 | was added. |
|
|
25 | |
|
|
26 | B: Support for narrow build Asian Psions added. |
|
|
27 | If the encoding_type is PSICONV_ENCODING_UTF8, |
|
|
28 | B-1: use utf8_table for character conversion. |
|
|
29 | B-2: add the "Charset=UTF-8" in the Content-Type header. |
|
|
30 | Otherwise proceed as normal. |
|
|
31 | */ |
20 | |
32 | |
21 | #include "config.h" |
33 | #include "config.h" |
22 | #include <stdio.h> |
34 | #include <stdio.h> |
23 | #include <string.h> |
35 | #include <string.h> |
24 | #include <ctype.h> |
36 | #include <ctype.h> |
… | |
… | |
90 | "ô", "õ", "ö", "÷", |
102 | "ô", "õ", "ö", "÷", |
91 | /* 0xf8 */ "ø", "ù", "ú", "û", |
103 | /* 0xf8 */ "ø", "ù", "ú", "û", |
92 | "ü", "ý", "þ", "ÿ" |
104 | "ü", "ý", "þ", "ÿ" |
93 | }; |
105 | }; |
94 | |
106 | |
|
|
107 | static const char *utf_table[0x100] = { |
|
|
108 | /* 0x00 */ "", "", "", "", "", "", "<BR>\n", "<BR>\n", |
|
|
109 | /* 0x08 */ "\n<HR>\n", "\t", "", "", "", "", "", "", |
|
|
110 | /* 0x10 */ " ", "", "", "", "", "", "", "", |
|
|
111 | /* 0x18 */ "", "", "", "", "", "", "", "", |
|
|
112 | /* 0x20 */ " ", "!", """, "#", "$", "%", "&", "'", |
|
|
113 | /* 0x28 */ "(", ")", "*", "+", ",", "-", ".", "/", |
|
|
114 | /* 0x30 */ "0", "1", "2", "3", "4", "5", "6", "7", |
|
|
115 | /* 0x38 */ "8", "9", ":", ";", "<", "=", ">", "?", |
|
|
116 | /* 0x40 */ "@", "A", "B", "C", "D", "E", "F", "G", |
|
|
117 | /* 0x48 */ "H", "I", "J", "K", "L", "M", "N", "O", |
|
|
118 | /* 0x50 */ "P", "Q", "R", "S", "T", "U", "V", "W", |
|
|
119 | /* 0x58 */ "X", "Y", "Z", "[", "\\", "]", "^", "_", |
|
|
120 | /* 0x60 */ "`", "a", "b", "c", "d", "e", "f", "g", |
|
|
121 | /* 0x68 */ "h", "i", "j", "k", "l", "m", "n", "o", |
|
|
122 | /* 0x70 */ "p", "q", "r", "s", "t", "u", "v", "w", |
|
|
123 | /* 0x78 */ "x", "y", "z", "{", "|", "}", "~", "", |
|
|
124 | /* 0x80 */ "\x80", "\x81", "\x82", "\x83", "\x84", "\x85", "\x86", "\x87", |
|
|
125 | /* 0x88 */ "\x88", "\x89", "\x8a", "\x8b", "\x8c", "\x8d", "\x8e", "\x8f", |
|
|
126 | /* 0x90 */ "\x90", "\x91", "\x92", "\x93", "\x94", "\x95", "\x96", "\x97", |
|
|
127 | /* 0x98 */ "\x98", "\x99", "\x9a", "\x9b", "\x9c", "\x9d", "\x9e", "\x9f", |
|
|
128 | /* 0xa0 */ "\xa0", "\xa1", "\xa2", "\xa3", "\xa4", "\xa5", "\xa6", "\xa7", |
|
|
129 | /* 0xa8 */ "\xa8", "\xa9", "\xaa", "\xab", "\xac", "\xad", "\xae", "\xaf", |
|
|
130 | /* 0xb0 */ "\xb0", "\xb1", "\xb2", "\xb3", "\xb4", "\xb5", "\xb6", "\xb7", |
|
|
131 | /* 0xb8 */ "\xb8", "\xb9", "\xba", "\xbb", "\xbc", "\xbd", "\xbe", "\xbf", |
|
|
132 | /* 0xc0 */ "\xc0", "\xc1", "\xc2", "\xc3", "\xc4", "\xc5", "\xc6", "\xc7", |
|
|
133 | /* 0xc8 */ "\xc8", "\xc9", "\xca", "\xcb", "\xcc", "\xcd", "\xce", "\xcf", |
|
|
134 | /* 0xd0 */ "\xd0", "\xd1", "\xd2", "\xd3", "\xd4", "\xd5", "\xd6", "\xd7", |
|
|
135 | /* 0xd8 */ "\xd8", "\xd9", "\xda", "\xdb", "\xdc", "\xdd", "\xde", "\xdf", |
|
|
136 | /* 0xe0 */ "\xe0", "\xe1", "\xe2", "\xe3", "\xe4", "\xe5", "\xe6", "\xe7", |
|
|
137 | /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef", |
|
|
138 | /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7", |
|
|
139 | /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff", |
|
|
140 | }; |
|
|
141 | |
|
|
142 | /* a flag to indicate the use of UTF8 */ |
|
|
143 | static psiconv_encoding encoding=PSICONV_ENCODING_CP1252; |
|
|
144 | |
|
|
145 | |
95 | /* The order of these must match the enum psiconv_border_kind (data.h) */ |
146 | /* The order of these must match the enum psiconv_border_kind (data.h) */ |
96 | static const char *border_strings[] = { |
147 | static const char *border_strings[] = { |
97 | "none", "solid", "double", "dotted", "dashed", "dashed", "dotted" |
148 | "none", "solid", "double", "dotted", "dashed", "dashed", "dotted" |
98 | }; |
149 | }; |
99 | |
150 | |
… | |
… | |
121 | } |
172 | } |
122 | |
173 | |
123 | static void fput_text(FILE * of, const char *text, int length, int *pwasspace) { |
174 | static void fput_text(FILE * of, const char *text, int length, int *pwasspace) { |
124 | int j; |
175 | int j; |
125 | int space; |
176 | int space; |
|
|
177 | char ** table; |
|
|
178 | if (encoding == PSICONV_ENCODING_UTF8){ |
|
|
179 | table = (char**) utf_table; |
|
|
180 | }else{ |
|
|
181 | table=(char**) char_table; |
|
|
182 | } |
126 | |
183 | |
127 | for (j = 0; j < length; j++) { |
184 | for (j = 0; j < length; j++) { |
128 | space = (text[j] == ' '); |
185 | space = (text[j] == ' '); |
129 | if (*pwasspace && space) |
186 | if (*pwasspace && space) |
130 | fputs(" ", of); |
187 | fputs(" ", of); |
131 | else |
188 | else |
132 | fputs(char_table[(unsigned char) (text[j])], of); |
189 | fputs(table[(unsigned char) (text[j])], of); |
133 | *pwasspace = space; |
190 | *pwasspace = space; |
134 | } |
191 | } |
135 | } |
192 | } |
136 | |
193 | |
137 | static const char *screenfont_name(psiconv_u8 screenfont) |
194 | static const char *screenfont_name(psiconv_u8 screenfont) |
… | |
… | |
346 | psiconv_in_line_layout inl; |
403 | psiconv_in_line_layout inl; |
347 | psiconv_word_style sty; |
404 | psiconv_word_style sty; |
348 | int spans = 0; |
405 | int spans = 0; |
349 | int wasspace = 0; |
406 | int wasspace = 0; |
350 | int i, j, loc; |
407 | int i, j, loc; |
|
|
408 | char ** table; |
|
|
409 | |
|
|
410 | if (encoding == PSICONV_ENCODING_UTF8){ |
|
|
411 | table= (char**) utf_table; |
|
|
412 | }else{ |
|
|
413 | table= (char**) char_table; |
|
|
414 | } |
351 | |
415 | |
352 | layout_stack = calloc(psiconv_list_length(para->in_lines), |
416 | layout_stack = calloc(psiconv_list_length(para->in_lines), |
353 | sizeof(*layout_stack)); |
417 | sizeof(*layout_stack)); |
354 | fputs("<P", of); |
418 | fputs("<P", of); |
355 | sty = psiconv_get_style(wf->styles_sec, para->base_style); |
419 | sty = psiconv_get_style(wf->styles_sec, para->base_style); |
… | |
… | |
388 | fprintf(of, "color:#%02x%02x%02x;", |
452 | fprintf(of, "color:#%02x%02x%02x;", |
389 | base_para->bullet->color->red, |
453 | base_para->bullet->color->red, |
390 | base_para->bullet->color->green, |
454 | base_para->bullet->color->green, |
391 | base_para->bullet->color->blue); |
455 | base_para->bullet->color->blue); |
392 | fprintf(of, "\">%s </SPAN>", |
456 | fprintf(of, "\">%s </SPAN>", |
393 | char_table[base_para->bullet->character]); |
457 | table[base_para->bullet->character]); |
394 | wasspace = TRUE; |
458 | wasspace = TRUE; |
395 | } |
459 | } |
396 | |
460 | |
397 | loc = 0; |
461 | loc = 0; |
398 | for (i = 0; i < psiconv_list_length(para->in_lines); i++) { |
462 | for (i = 0; i < psiconv_list_length(para->in_lines); i++) { |
… | |
… | |
450 | fput_character_layout(of, normal ? normal->character : NULL, sty->character, wf); |
514 | fput_character_layout(of, normal ? normal->character : NULL, sty->character, wf); |
451 | fputs("}\n", of); |
515 | fputs("}\n", of); |
452 | } |
516 | } |
453 | |
517 | |
454 | static int psiconv_gen_html4(const char *filename, const psiconv_file file, |
518 | static int psiconv_gen_html4(const char *filename, const psiconv_file file, |
455 | const char *dest) |
519 | const char *dest, const psiconv_encoding encoding_type) |
456 | { |
520 | { |
457 | FILE * of; |
521 | FILE * of; |
458 | int i; |
522 | int i; |
459 | psiconv_paragraph para; |
523 | psiconv_paragraph para; |
460 | psiconv_word_style normal, sty; |
524 | psiconv_word_style normal, sty; |
461 | psiconv_word_f wf; |
525 | psiconv_word_f wf; |
|
|
526 | |
|
|
527 | encoding=encoding_type; |
462 | |
528 | |
463 | if (file->type == psiconv_word_file) |
529 | if (file->type == psiconv_word_file) |
464 | wf = file->file; |
530 | wf = file->file; |
465 | else { |
531 | else { |
466 | /* Fall back on the normal HTML generator */ |
532 | /* Fall back on the normal HTML generator */ |
467 | return psiconv_gen_html(filename,file,dest); |
533 | return psiconv_gen_html(filename,file,dest,encoding_type); |
468 | } |
534 | } |
469 | |
535 | |
470 | if (! (of = fopen(filename,"w"))) |
536 | if (! (of = fopen(filename,"w"))) |
471 | return -1; |
537 | return -1; |
472 | |
538 | |
473 | fputs("<!doctype html public \"-//W3C//DTD HTML 4.0 STRICT//EN\">", of); |
539 | fputs("<!doctype html public \"-//W3C//DTD HTML 4.0 STRICT//EN\">", of); |
474 | fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); |
540 | fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); |
475 | fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of); |
541 | fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of); |
|
|
542 | |
|
|
543 | fputs(" <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html", of); |
|
|
544 | if (encoding == PSICONV_ENCODING_UTF8) |
|
|
545 | fputs("; CHARSET=UTF-8", of); |
|
|
546 | fputs("\">\n", of); |
476 | |
547 | |
477 | if (wf->page_sec->header->text) { |
548 | if (wf->page_sec->header->text) { |
478 | if (psiconv_list_length(wf->page_sec->header->text->paragraphs) > 0) { |
549 | if (psiconv_list_length(wf->page_sec->header->text->paragraphs) > 0) { |
479 | fputs(" <TITLE>", of); |
550 | fputs(" <TITLE>", of); |
480 | para = psiconv_list_get(wf->page_sec->header->text->paragraphs, 0); |
551 | para = psiconv_list_get(wf->page_sec->header->text->paragraphs, 0); |