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