… | |
… | |
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 | |
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 | */ |
|
|
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> |
25 | #include <stdlib.h> |
37 | #include <stdlib.h> |
26 | #include "data.h" |
38 | #include "psiconv/data.h" |
27 | #include "list.h" |
39 | #include "psiconv/list.h" |
28 | #include "gen.h" |
40 | #include "gen.h" |
29 | #include "psiconv.h" |
41 | #include "psiconv.h" |
30 | |
42 | |
31 | #ifndef TRUE |
43 | #ifndef TRUE |
32 | #define TRUE (0==0) |
44 | #define TRUE (0==0) |
|
|
45 | #endif |
|
|
46 | |
|
|
47 | #ifdef DMALLOC |
|
|
48 | #include "dmalloc.h" |
33 | #endif |
49 | #endif |
34 | |
50 | |
35 | /* |
51 | /* |
36 | * Various string tables for HTML4 settings |
52 | * Various string tables for HTML4 settings |
37 | */ |
53 | */ |
… | |
… | |
86 | "ô", "õ", "ö", "÷", |
102 | "ô", "õ", "ö", "÷", |
87 | /* 0xf8 */ "ø", "ù", "ú", "û", |
103 | /* 0xf8 */ "ø", "ù", "ú", "û", |
88 | "ü", "ý", "þ", "ÿ" |
104 | "ü", "ý", "þ", "ÿ" |
89 | }; |
105 | }; |
90 | |
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 | |
91 | /* 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) */ |
92 | static const char *border_strings[] = { |
147 | static const char *border_strings[] = { |
93 | "none", "solid", "double", "dotted", "dashed", "dashed", "dotted" |
148 | "none", "solid", "double", "dotted", "dashed", "dashed", "dotted" |
94 | }; |
149 | }; |
95 | |
150 | |
… | |
… | |
117 | } |
172 | } |
118 | |
173 | |
119 | 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) { |
120 | int j; |
175 | int j; |
121 | 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 | } |
122 | |
183 | |
123 | for (j = 0; j < length; j++) { |
184 | for (j = 0; j < length; j++) { |
124 | space = (text[j] == ' '); |
185 | space = (text[j] == ' '); |
125 | if (*pwasspace && space) |
186 | if (*pwasspace && space) |
126 | fputs(" ", of); |
187 | fputs(" ", of); |
127 | else |
188 | else |
128 | fputs(char_table[(unsigned char) (text[j])], of); |
189 | fputs(table[(unsigned char) (text[j])], of); |
129 | *pwasspace = space; |
190 | *pwasspace = space; |
130 | } |
191 | } |
131 | } |
192 | } |
132 | |
193 | |
133 | static const char *screenfont_name(psiconv_u8 screenfont) |
194 | static const char *screenfont_name(psiconv_u8 screenfont) |
134 | { |
195 | { |
135 | if (screenfont == 1) |
196 | if (screenfont == psiconv_font_sansserif) |
136 | return "sans-serif"; |
197 | return "sans-serif"; |
137 | else if (screenfont == 2) |
198 | else if (screenfont == psiconv_font_nonprop) |
138 | return "monospace"; |
199 | return "monospace"; |
139 | else if (screenfont == 3) |
200 | else if (screenfont == psiconv_font_serif) |
140 | return "serif"; |
201 | return "serif"; |
141 | else |
202 | else |
142 | return "serif"; |
203 | return "serif"; |
143 | } |
204 | } |
144 | |
205 | |
… | |
… | |
210 | /* Paragraph formats */ |
271 | /* Paragraph formats */ |
211 | static int paragraph_layouts_different( |
272 | static int paragraph_layouts_different( |
212 | const psiconv_paragraph_layout old, |
273 | const psiconv_paragraph_layout old, |
213 | const psiconv_paragraph_layout new) |
274 | const psiconv_paragraph_layout new) |
214 | { |
275 | { |
215 | return ((old->top_space != new->top_space) || |
276 | return ((old->space_above != new->space_above) || |
216 | (old->indent_right != new->indent_right) || |
277 | (old->indent_right != new->indent_right) || |
217 | (old->bottom_space != new->bottom_space) || |
278 | (old->space_below != new->space_below) || |
218 | (old->indent_left != new->indent_left) || |
279 | (old->indent_left != new->indent_left) || |
219 | (old->indent_first != new->indent_first) || |
280 | (old->indent_first != new->indent_first) || |
220 | (old->justify_hor != new->justify_hor) || |
281 | (old->justify_hor != new->justify_hor) || |
221 | (old->interline_exact != new->interline_exact) || |
282 | (old->linespacing_exact != new->linespacing_exact) || |
222 | borders_different(old->left_border, new->left_border) || |
283 | borders_different(old->left_border, new->left_border) || |
223 | borders_different(old->right_border, new->right_border) || |
284 | borders_different(old->right_border, new->right_border) || |
224 | borders_different(old->top_border, new->top_border) || |
285 | borders_different(old->top_border, new->top_border) || |
225 | borders_different(old->bottom_border, new->bottom_border)); |
286 | borders_different(old->bottom_border, new->bottom_border)); |
226 | } |
287 | } |
227 | |
288 | |
228 | static void fput_paragraph_layout(FILE * of, |
289 | static void fput_paragraph_layout(FILE * of, |
229 | const psiconv_paragraph_layout old, |
290 | const psiconv_paragraph_layout old, |
230 | const psiconv_paragraph_layout new) |
291 | const psiconv_paragraph_layout new) |
231 | { |
292 | { |
232 | if (!old || (old->top_space != new->top_space)) |
293 | if (!old || (old->space_above != new->space_above)) |
233 | fprintf(of, "margin-top:%.1fpt;", new->top_space); |
294 | fprintf(of, "margin-top:%.1fpt;", new->space_above); |
234 | if (!old || (old->indent_right != new->indent_right)) |
295 | if (!old || (old->indent_right != new->indent_right)) |
235 | fprintf(of, "margin-right:%.2fcm;", new->indent_right); |
296 | fprintf(of, "margin-right:%.2fcm;", new->indent_right); |
236 | if (!old || (old->bottom_space != new->bottom_space)) |
297 | if (!old || (old->space_below != new->space_below)) |
237 | fprintf(of, "margin-bottom:%.1fpt;", new->bottom_space); |
298 | fprintf(of, "margin-bottom:%.1fpt;", new->space_below); |
238 | if (!old || |
299 | if (!old || |
239 | (old->bullet->on != new->bullet->on) || |
300 | (old->bullet->on != new->bullet->on) || |
240 | (old->bullet->indent != new->bullet->indent) || |
301 | (old->bullet->indent != new->bullet->indent) || |
241 | (old->indent_left != new->indent_left) || |
302 | (old->indent_left != new->indent_left) || |
242 | (old->indent_first != new->indent_first)) { |
303 | (old->indent_first != new->indent_first)) { |
… | |
… | |
252 | fprintf(of, "margin-left:%.2fcm;", margin); |
313 | fprintf(of, "margin-left:%.2fcm;", margin); |
253 | fprintf(of, "text-indent:%.2fcm;", indent); |
314 | fprintf(of, "text-indent:%.2fcm;", indent); |
254 | } |
315 | } |
255 | if (!old || (old->justify_hor != new->justify_hor)) |
316 | if (!old || (old->justify_hor != new->justify_hor)) |
256 | fprintf(of, "text-align:%s;", justify_strings[new->justify_hor]); |
317 | fprintf(of, "text-align:%s;", justify_strings[new->justify_hor]); |
257 | if (!old || (old->interline_exact != new->interline_exact)) { |
318 | if (!old || (old->linespacing_exact != new->linespacing_exact)) { |
258 | if (!old || old->interline_exact) |
319 | if (!old || old->linespacing_exact) |
259 | fputs("line-height:normal;", of); |
320 | fputs("line-height:normal;", of); |
260 | else |
321 | else |
261 | fprintf(of, "line-height:%.1fpt;", new->interline); |
322 | fprintf(of, "line-height:%.1fpt;", new->linespacing); |
262 | } |
323 | } |
263 | fput_border(of, "left", old ? old->left_border : NULL, |
324 | fput_border(of, "left", old ? old->left_border : NULL, |
264 | new->left_border); |
325 | new->left_border); |
265 | fput_border(of, "right", old ? old->right_border : NULL, |
326 | fput_border(of, "right", old ? old->right_border : NULL, |
266 | new->right_border); |
327 | new->right_border); |
… | |
… | |
286 | (old->back_color->blue != new->back_color->blue) || |
347 | (old->back_color->blue != new->back_color->blue) || |
287 | (old->italic != new->italic) || |
348 | (old->italic != new->italic) || |
288 | (old->bold != new->bold) || |
349 | (old->bold != new->bold) || |
289 | (old->super_sub != new->super_sub) || |
350 | (old->super_sub != new->super_sub) || |
290 | (old->underline != new->underline) || |
351 | (old->underline != new->underline) || |
291 | (old->strike_out != new->strike_out)); |
352 | (old->strikethrough != new->strikethrough)); |
292 | } |
353 | } |
293 | |
354 | |
294 | static void fput_character_layout(FILE * of, |
355 | static void fput_character_layout(FILE * of, |
295 | const psiconv_character_layout old, |
356 | const psiconv_character_layout old, |
296 | const psiconv_character_layout new, |
357 | const psiconv_character_layout new, |
… | |
… | |
315 | fprintf(of, "background-color:#%02x%02x%02x;", |
376 | fprintf(of, "background-color:#%02x%02x%02x;", |
316 | new->back_color->red, new->back_color->green, new->back_color->blue); |
377 | new->back_color->red, new->back_color->green, new->back_color->blue); |
317 | if (!old || (old->super_sub != new->super_sub)) |
378 | if (!old || (old->super_sub != new->super_sub)) |
318 | fprintf(of, "vertical-align:%s;", vertical_strings[new->super_sub]); |
379 | fprintf(of, "vertical-align:%s;", vertical_strings[new->super_sub]); |
319 | if (!old || (old->underline != new->underline) || |
380 | if (!old || (old->underline != new->underline) || |
320 | (old->strike_out != new->strike_out)) { |
381 | (old->strikethrough != new->strikethrough)) { |
321 | fputs("text-decoration:", of); |
382 | fputs("text-decoration:", of); |
322 | if (new->strike_out) |
383 | if (new->strikethrough) |
323 | fputs("line-through ", of); |
384 | fputs("line-through ", of); |
324 | if (new->underline) |
385 | if (new->underline) |
325 | fputs("underline", of); |
386 | fputs("underline", of); |
326 | else if (!new->strike_out) |
387 | else if (!new->strikethrough) |
327 | fputs("none", of); |
388 | fputs("none", of); |
328 | fputs(";", of); |
389 | fputs(";", of); |
329 | } |
390 | } |
330 | } |
391 | } |
331 | |
392 | |
… | |
… | |
342 | psiconv_in_line_layout inl; |
403 | psiconv_in_line_layout inl; |
343 | psiconv_word_style sty; |
404 | psiconv_word_style sty; |
344 | int spans = 0; |
405 | int spans = 0; |
345 | int wasspace = 0; |
406 | int wasspace = 0; |
346 | 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 | } |
347 | |
415 | |
348 | layout_stack = calloc(psiconv_list_length(para->in_lines), |
416 | layout_stack = calloc(psiconv_list_length(para->in_lines), |
349 | sizeof(*layout_stack)); |
417 | sizeof(*layout_stack)); |
350 | fputs("<P", of); |
418 | fputs("<P", of); |
351 | sty = psiconv_get_style(wf->styles_sec, para->base_style); |
419 | sty = psiconv_get_style(wf->styles_sec, para->base_style); |
… | |
… | |
384 | fprintf(of, "color:#%02x%02x%02x;", |
452 | fprintf(of, "color:#%02x%02x%02x;", |
385 | base_para->bullet->color->red, |
453 | base_para->bullet->color->red, |
386 | base_para->bullet->color->green, |
454 | base_para->bullet->color->green, |
387 | base_para->bullet->color->blue); |
455 | base_para->bullet->color->blue); |
388 | fprintf(of, "\">%s </SPAN>", |
456 | fprintf(of, "\">%s </SPAN>", |
389 | char_table[base_para->bullet->character]); |
457 | table[base_para->bullet->character]); |
390 | wasspace = TRUE; |
458 | wasspace = TRUE; |
391 | } |
459 | } |
392 | |
460 | |
393 | loc = 0; |
461 | loc = 0; |
394 | for (i = 0; i < psiconv_list_length(para->in_lines); i++) { |
462 | for (i = 0; i < psiconv_list_length(para->in_lines); i++) { |
… | |
… | |
446 | fput_character_layout(of, normal ? normal->character : NULL, sty->character, wf); |
514 | fput_character_layout(of, normal ? normal->character : NULL, sty->character, wf); |
447 | fputs("}\n", of); |
515 | fputs("}\n", of); |
448 | } |
516 | } |
449 | |
517 | |
450 | 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, |
451 | const char *dest) |
519 | const char *dest, const psiconv_encoding encoding_type) |
452 | { |
520 | { |
453 | FILE * of; |
521 | FILE * of; |
454 | int i; |
522 | int i; |
455 | psiconv_paragraph para; |
523 | psiconv_paragraph para; |
456 | psiconv_word_style normal, sty; |
524 | psiconv_word_style normal, sty; |
457 | psiconv_word_f wf; |
525 | psiconv_word_f wf; |
|
|
526 | |
|
|
527 | encoding=encoding_type; |
458 | |
528 | |
459 | if (file->type == psiconv_word_file) |
529 | if (file->type == psiconv_word_file) |
460 | wf = file->file; |
530 | wf = file->file; |
461 | else { |
531 | else { |
462 | /* Fall back on the normal HTML generator */ |
532 | /* Fall back on the normal HTML generator */ |
463 | return psiconv_gen_html(filename,file,dest); |
533 | return psiconv_gen_html(filename,file,dest,encoding_type); |
464 | } |
534 | } |
465 | |
535 | |
466 | if (! (of = fopen(filename,"w"))) |
536 | if (! (of = fopen(filename,"w"))) |
467 | return -1; |
537 | return -1; |
468 | |
538 | |
469 | 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); |
470 | fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); |
540 | fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); |
471 | 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); |
472 | |
547 | |
|
|
548 | if (wf->page_sec->header->text) { |
473 | if (psiconv_list_length(wf->page_sec->header->text->paragraphs) > 0) { |
549 | if (psiconv_list_length(wf->page_sec->header->text->paragraphs) > 0) { |
474 | fputs(" <TITLE>", of); |
550 | fputs(" <TITLE>", of); |
475 | para = psiconv_list_get(wf->page_sec->header->text->paragraphs, 0); |
551 | para = psiconv_list_get(wf->page_sec->header->text->paragraphs, 0); |
476 | i = 0; |
552 | i = 0; |
477 | fput_text(of, para->text, strlen(para->text), &i); |
553 | fput_text(of, para->text, strlen(para->text), &i); |
478 | fputs("</TITLE>\n", of); |
554 | fputs("</TITLE>\n", of); |
|
|
555 | } |
479 | } |
556 | } |
480 | |
557 | |
481 | normal = wf->styles_sec->normal; |
558 | normal = wf->styles_sec->normal; |
482 | fputs(" <STYLE TYPE=\"text/css\"><!--\n", of); |
559 | fputs(" <STYLE TYPE=\"text/css\"><!--\n", of); |
483 | fprintf(of," BODY { background-color: #%02x%02x%02x }\n", |
560 | fprintf(of," BODY { background-color: #%02x%02x%02x }\n", |
… | |
… | |
488 | for (i = 0; i < psiconv_list_length(wf->styles_sec->styles); i++) { |
565 | for (i = 0; i < psiconv_list_length(wf->styles_sec->styles); i++) { |
489 | sty = psiconv_list_get(wf->styles_sec->styles, i); |
566 | sty = psiconv_list_get(wf->styles_sec->styles, i); |
490 | fput_style(of, normal, sty, wf); |
567 | fput_style(of, normal, sty, wf); |
491 | } |
568 | } |
492 | fputs(" --></STYLE>\n</HEAD>\n<BODY>\n", of); |
569 | fputs(" --></STYLE>\n</HEAD>\n<BODY>\n", of); |
|
|
570 | if (wf->page_sec->header->text) { |
493 | for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { |
571 | for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { |
494 | para = psiconv_list_get(wf->paragraphs, i); |
572 | para = psiconv_list_get(wf->paragraphs, i); |
495 | fput_para(of, para, wf); |
573 | fput_para(of, para, wf); |
|
|
574 | } |
496 | } |
575 | } |
497 | fputs("</BODY>\n</HTML>\n", of); |
576 | fputs("</BODY>\n</HTML>\n", of); |
498 | |
577 | |
499 | return fclose(of); |
578 | return fclose(of); |
500 | } |
579 | } |