… | |
… | |
21 | #include "config.h" |
21 | #include "config.h" |
22 | #include <stdio.h> |
22 | #include <stdio.h> |
23 | #include <string.h> |
23 | #include <string.h> |
24 | #include <ctype.h> |
24 | #include <ctype.h> |
25 | #include <stdlib.h> |
25 | #include <stdlib.h> |
26 | #include "data.h" |
26 | #include "psiconv/data.h" |
27 | #include "list.h" |
27 | #include "psiconv/list.h" |
28 | #include "gen.h" |
28 | #include "gen.h" |
29 | #include "psiconv.h" |
29 | #include "psiconv.h" |
30 | |
30 | |
31 | #ifndef TRUE |
31 | #ifndef TRUE |
32 | #define TRUE (0==0) |
32 | #define TRUE (0==0) |
|
|
33 | #endif |
|
|
34 | |
|
|
35 | #ifdef DMALLOC |
|
|
36 | #include "dmalloc.h" |
33 | #endif |
37 | #endif |
34 | |
38 | |
35 | /* |
39 | /* |
36 | * Various string tables for HTML4 settings |
40 | * Various string tables for HTML4 settings |
37 | */ |
41 | */ |
… | |
… | |
130 | } |
134 | } |
131 | } |
135 | } |
132 | |
136 | |
133 | static const char *screenfont_name(psiconv_u8 screenfont) |
137 | static const char *screenfont_name(psiconv_u8 screenfont) |
134 | { |
138 | { |
135 | if (screenfont == 1) |
139 | if (screenfont == psiconv_font_sansserif) |
136 | return "sans-serif"; |
140 | return "sans-serif"; |
137 | else if (screenfont == 2) |
141 | else if (screenfont == psiconv_font_nonprop) |
138 | return "monospace"; |
142 | return "monospace"; |
139 | else if (screenfont == 3) |
143 | else if (screenfont == psiconv_font_serif) |
140 | return "serif"; |
144 | return "serif"; |
141 | else |
145 | else |
142 | return "serif"; |
146 | return "serif"; |
143 | } |
147 | } |
144 | |
148 | |
… | |
… | |
210 | /* Paragraph formats */ |
214 | /* Paragraph formats */ |
211 | static int paragraph_layouts_different( |
215 | static int paragraph_layouts_different( |
212 | const psiconv_paragraph_layout old, |
216 | const psiconv_paragraph_layout old, |
213 | const psiconv_paragraph_layout new) |
217 | const psiconv_paragraph_layout new) |
214 | { |
218 | { |
215 | return ((old->top_space != new->top_space) || |
219 | return ((old->space_above != new->space_above) || |
216 | (old->indent_right != new->indent_right) || |
220 | (old->indent_right != new->indent_right) || |
217 | (old->bottom_space != new->bottom_space) || |
221 | (old->space_below != new->space_below) || |
218 | (old->indent_left != new->indent_left) || |
222 | (old->indent_left != new->indent_left) || |
219 | (old->indent_first != new->indent_first) || |
223 | (old->indent_first != new->indent_first) || |
220 | (old->justify_hor != new->justify_hor) || |
224 | (old->justify_hor != new->justify_hor) || |
221 | (old->interline_exact != new->interline_exact) || |
225 | (old->linespacing_exact != new->linespacing_exact) || |
222 | borders_different(old->left_border, new->left_border) || |
226 | borders_different(old->left_border, new->left_border) || |
223 | borders_different(old->right_border, new->right_border) || |
227 | borders_different(old->right_border, new->right_border) || |
224 | borders_different(old->top_border, new->top_border) || |
228 | borders_different(old->top_border, new->top_border) || |
225 | borders_different(old->bottom_border, new->bottom_border)); |
229 | borders_different(old->bottom_border, new->bottom_border)); |
226 | } |
230 | } |
227 | |
231 | |
228 | static void fput_paragraph_layout(FILE * of, |
232 | static void fput_paragraph_layout(FILE * of, |
229 | const psiconv_paragraph_layout old, |
233 | const psiconv_paragraph_layout old, |
230 | const psiconv_paragraph_layout new) |
234 | const psiconv_paragraph_layout new) |
231 | { |
235 | { |
232 | if (!old || (old->top_space != new->top_space)) |
236 | if (!old || (old->space_above != new->space_above)) |
233 | fprintf(of, "margin-top:%.1fpt;", new->top_space); |
237 | fprintf(of, "margin-top:%.1fpt;", new->space_above); |
234 | if (!old || (old->indent_right != new->indent_right)) |
238 | if (!old || (old->indent_right != new->indent_right)) |
235 | fprintf(of, "margin-right:%.2fcm;", new->indent_right); |
239 | fprintf(of, "margin-right:%.2fcm;", new->indent_right); |
236 | if (!old || (old->bottom_space != new->bottom_space)) |
240 | if (!old || (old->space_below != new->space_below)) |
237 | fprintf(of, "margin-bottom:%.1fpt;", new->bottom_space); |
241 | fprintf(of, "margin-bottom:%.1fpt;", new->space_below); |
238 | if (!old || |
242 | if (!old || |
239 | (old->bullet->on != new->bullet->on) || |
243 | (old->bullet->on != new->bullet->on) || |
240 | (old->bullet->indent != new->bullet->indent) || |
244 | (old->bullet->indent != new->bullet->indent) || |
241 | (old->indent_left != new->indent_left) || |
245 | (old->indent_left != new->indent_left) || |
242 | (old->indent_first != new->indent_first)) { |
246 | (old->indent_first != new->indent_first)) { |
… | |
… | |
252 | fprintf(of, "margin-left:%.2fcm;", margin); |
256 | fprintf(of, "margin-left:%.2fcm;", margin); |
253 | fprintf(of, "text-indent:%.2fcm;", indent); |
257 | fprintf(of, "text-indent:%.2fcm;", indent); |
254 | } |
258 | } |
255 | if (!old || (old->justify_hor != new->justify_hor)) |
259 | if (!old || (old->justify_hor != new->justify_hor)) |
256 | fprintf(of, "text-align:%s;", justify_strings[new->justify_hor]); |
260 | fprintf(of, "text-align:%s;", justify_strings[new->justify_hor]); |
257 | if (!old || (old->interline_exact != new->interline_exact)) { |
261 | if (!old || (old->linespacing_exact != new->linespacing_exact)) { |
258 | if (!old || old->interline_exact) |
262 | if (!old || old->linespacing_exact) |
259 | fputs("line-height:normal;", of); |
263 | fputs("line-height:normal;", of); |
260 | else |
264 | else |
261 | fprintf(of, "line-height:%.1fpt;", new->interline); |
265 | fprintf(of, "line-height:%.1fpt;", new->linespacing); |
262 | } |
266 | } |
263 | fput_border(of, "left", old ? old->left_border : NULL, |
267 | fput_border(of, "left", old ? old->left_border : NULL, |
264 | new->left_border); |
268 | new->left_border); |
265 | fput_border(of, "right", old ? old->right_border : NULL, |
269 | fput_border(of, "right", old ? old->right_border : NULL, |
266 | new->right_border); |
270 | new->right_border); |
… | |
… | |
286 | (old->back_color->blue != new->back_color->blue) || |
290 | (old->back_color->blue != new->back_color->blue) || |
287 | (old->italic != new->italic) || |
291 | (old->italic != new->italic) || |
288 | (old->bold != new->bold) || |
292 | (old->bold != new->bold) || |
289 | (old->super_sub != new->super_sub) || |
293 | (old->super_sub != new->super_sub) || |
290 | (old->underline != new->underline) || |
294 | (old->underline != new->underline) || |
291 | (old->strike_out != new->strike_out)); |
295 | (old->strikethrough != new->strikethrough)); |
292 | } |
296 | } |
293 | |
297 | |
294 | static void fput_character_layout(FILE * of, |
298 | static void fput_character_layout(FILE * of, |
295 | const psiconv_character_layout old, |
299 | const psiconv_character_layout old, |
296 | const psiconv_character_layout new, |
300 | const psiconv_character_layout new, |
… | |
… | |
315 | fprintf(of, "background-color:#%02x%02x%02x;", |
319 | fprintf(of, "background-color:#%02x%02x%02x;", |
316 | new->back_color->red, new->back_color->green, new->back_color->blue); |
320 | new->back_color->red, new->back_color->green, new->back_color->blue); |
317 | if (!old || (old->super_sub != new->super_sub)) |
321 | if (!old || (old->super_sub != new->super_sub)) |
318 | fprintf(of, "vertical-align:%s;", vertical_strings[new->super_sub]); |
322 | fprintf(of, "vertical-align:%s;", vertical_strings[new->super_sub]); |
319 | if (!old || (old->underline != new->underline) || |
323 | if (!old || (old->underline != new->underline) || |
320 | (old->strike_out != new->strike_out)) { |
324 | (old->strikethrough != new->strikethrough)) { |
321 | fputs("text-decoration:", of); |
325 | fputs("text-decoration:", of); |
322 | if (new->strike_out) |
326 | if (new->strikethrough) |
323 | fputs("line-through ", of); |
327 | fputs("line-through ", of); |
324 | if (new->underline) |
328 | if (new->underline) |
325 | fputs("underline", of); |
329 | fputs("underline", of); |
326 | else if (!new->strike_out) |
330 | else if (!new->strikethrough) |
327 | fputs("none", of); |
331 | fputs("none", of); |
328 | fputs(";", of); |
332 | fputs(";", of); |
329 | } |
333 | } |
330 | } |
334 | } |
331 | |
335 | |
… | |
… | |
445 | fput_paragraph_layout(of, normal ? normal->paragraph : NULL, sty->paragraph); |
449 | fput_paragraph_layout(of, normal ? normal->paragraph : NULL, sty->paragraph); |
446 | fput_character_layout(of, normal ? normal->character : NULL, sty->character, wf); |
450 | fput_character_layout(of, normal ? normal->character : NULL, sty->character, wf); |
447 | fputs("}\n", of); |
451 | fputs("}\n", of); |
448 | } |
452 | } |
449 | |
453 | |
450 | static int psiconv_gen_html4(FILE * of, const psiconv_file file, |
454 | static int psiconv_gen_html4(const char *filename, const psiconv_file file, |
451 | const char *dest) |
455 | const char *dest) |
452 | { |
456 | { |
|
|
457 | FILE * of; |
453 | int i; |
458 | int i; |
454 | psiconv_paragraph para; |
459 | psiconv_paragraph para; |
455 | psiconv_word_style normal, sty; |
460 | psiconv_word_style normal, sty; |
456 | psiconv_word_f wf; |
461 | psiconv_word_f wf; |
457 | |
462 | |
458 | if (file->type == psiconv_word_file) |
463 | if (file->type == psiconv_word_file) |
459 | wf = file->file; |
464 | wf = file->file; |
460 | else { |
465 | else { |
461 | /* Fall back on the normal HTML generator */ |
466 | /* Fall back on the normal HTML generator */ |
462 | return psiconv_gen_html(of,file,dest); |
467 | return psiconv_gen_html(filename,file,dest); |
463 | } |
468 | } |
|
|
469 | |
|
|
470 | if (! (of = fopen(filename,"w"))) |
|
|
471 | return -1; |
464 | |
472 | |
465 | fputs("<!doctype html public \"-//W3C//DTD HTML 4.0 STRICT//EN\">", of); |
473 | fputs("<!doctype html public \"-//W3C//DTD HTML 4.0 STRICT//EN\">", of); |
466 | fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); |
474 | fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); |
467 | fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of); |
475 | fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of); |
468 | |
476 | |
|
|
477 | if (wf->page_sec->header->text) { |
469 | if (psiconv_list_length(wf->page_sec->header->text->paragraphs) > 0) { |
478 | if (psiconv_list_length(wf->page_sec->header->text->paragraphs) > 0) { |
470 | fputs(" <TITLE>", of); |
479 | fputs(" <TITLE>", of); |
471 | para = psiconv_list_get(wf->page_sec->header->text->paragraphs, 0); |
480 | para = psiconv_list_get(wf->page_sec->header->text->paragraphs, 0); |
472 | i = 0; |
481 | i = 0; |
473 | fput_text(of, para->text, strlen(para->text), &i); |
482 | fput_text(of, para->text, strlen(para->text), &i); |
474 | fputs("</TITLE>\n", of); |
483 | fputs("</TITLE>\n", of); |
|
|
484 | } |
475 | } |
485 | } |
476 | |
486 | |
477 | normal = wf->styles_sec->normal; |
487 | normal = wf->styles_sec->normal; |
478 | fputs(" <STYLE TYPE=\"text/css\"><!--\n", of); |
488 | fputs(" <STYLE TYPE=\"text/css\"><!--\n", of); |
479 | fprintf(of," BODY { background-color: #%02x%02x%02x }\n", |
489 | fprintf(of," BODY { background-color: #%02x%02x%02x }\n", |
… | |
… | |
484 | for (i = 0; i < psiconv_list_length(wf->styles_sec->styles); i++) { |
494 | for (i = 0; i < psiconv_list_length(wf->styles_sec->styles); i++) { |
485 | sty = psiconv_list_get(wf->styles_sec->styles, i); |
495 | sty = psiconv_list_get(wf->styles_sec->styles, i); |
486 | fput_style(of, normal, sty, wf); |
496 | fput_style(of, normal, sty, wf); |
487 | } |
497 | } |
488 | fputs(" --></STYLE>\n</HEAD>\n<BODY>\n", of); |
498 | fputs(" --></STYLE>\n</HEAD>\n<BODY>\n", of); |
|
|
499 | if (wf->page_sec->header->text) { |
489 | for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { |
500 | for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { |
490 | para = psiconv_list_get(wf->paragraphs, i); |
501 | para = psiconv_list_get(wf->paragraphs, i); |
491 | fput_para(of, para, wf); |
502 | fput_para(of, para, wf); |
|
|
503 | } |
492 | } |
504 | } |
493 | fputs("</BODY>\n</HTML>\n", of); |
505 | fputs("</BODY>\n</HTML>\n", of); |
494 | return 0; |
|
|
495 | } |
|
|
496 | |
506 | |
|
|
507 | return fclose(of); |
|
|
508 | } |
|
|
509 | |
497 | static struct psiconv_fileformat ff = |
510 | static struct psiconv_fileformat_s ff = |
498 | { |
511 | { |
499 | "HTML4", |
512 | "HTML4", |
500 | "HTML 4.0 with cascading style sheets", |
513 | "HTML 4.0 with cascading style sheets", |
501 | psiconv_gen_html4 |
514 | psiconv_gen_html4 |
502 | }; |
515 | }; |