… | |
… | |
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) |
32 | #endif |
33 | #endif |
33 | |
34 | |
… | |
… | |
209 | /* Paragraph formats */ |
210 | /* Paragraph formats */ |
210 | static int paragraph_layouts_different( |
211 | static int paragraph_layouts_different( |
211 | const psiconv_paragraph_layout old, |
212 | const psiconv_paragraph_layout old, |
212 | const psiconv_paragraph_layout new) |
213 | const psiconv_paragraph_layout new) |
213 | { |
214 | { |
214 | return ((old->top_space != new->top_space) || |
215 | return ((old->space_above != new->space_above) || |
215 | (old->indent_right != new->indent_right) || |
216 | (old->indent_right != new->indent_right) || |
216 | (old->bottom_space != new->bottom_space) || |
217 | (old->space_below != new->space_below) || |
217 | (old->indent_left != new->indent_left) || |
218 | (old->indent_left != new->indent_left) || |
218 | (old->indent_first != new->indent_first) || |
219 | (old->indent_first != new->indent_first) || |
219 | (old->justify_hor != new->justify_hor) || |
220 | (old->justify_hor != new->justify_hor) || |
220 | (old->interline_exact != new->interline_exact) || |
221 | (old->linespacing_exact != new->linespacing_exact) || |
221 | borders_different(old->left_border, new->left_border) || |
222 | borders_different(old->left_border, new->left_border) || |
222 | borders_different(old->right_border, new->right_border) || |
223 | borders_different(old->right_border, new->right_border) || |
223 | borders_different(old->top_border, new->top_border) || |
224 | borders_different(old->top_border, new->top_border) || |
224 | borders_different(old->bottom_border, new->bottom_border)); |
225 | borders_different(old->bottom_border, new->bottom_border)); |
225 | } |
226 | } |
226 | |
227 | |
227 | static void fput_paragraph_layout(FILE * of, |
228 | static void fput_paragraph_layout(FILE * of, |
228 | const psiconv_paragraph_layout old, |
229 | const psiconv_paragraph_layout old, |
229 | const psiconv_paragraph_layout new) |
230 | const psiconv_paragraph_layout new) |
230 | { |
231 | { |
231 | if (!old || (old->top_space != new->top_space)) |
232 | if (!old || (old->space_above != new->space_above)) |
232 | fprintf(of, "margin-top:%.1fpt;", new->top_space); |
233 | fprintf(of, "margin-top:%.1fpt;", new->space_above); |
233 | if (!old || (old->indent_right != new->indent_right)) |
234 | if (!old || (old->indent_right != new->indent_right)) |
234 | fprintf(of, "margin-right:%.2fcm;", new->indent_right); |
235 | fprintf(of, "margin-right:%.2fcm;", new->indent_right); |
235 | if (!old || (old->bottom_space != new->bottom_space)) |
236 | if (!old || (old->space_below != new->space_below)) |
236 | fprintf(of, "margin-bottom:%.1fpt;", new->bottom_space); |
237 | fprintf(of, "margin-bottom:%.1fpt;", new->space_below); |
237 | if (!old || |
238 | if (!old || |
238 | (old->bullet->on != new->bullet->on) || |
239 | (old->bullet->on != new->bullet->on) || |
239 | (old->bullet->indent != new->bullet->indent) || |
240 | (old->bullet->indent != new->bullet->indent) || |
240 | (old->indent_left != new->indent_left) || |
241 | (old->indent_left != new->indent_left) || |
241 | (old->indent_first != new->indent_first)) { |
242 | (old->indent_first != new->indent_first)) { |
… | |
… | |
251 | fprintf(of, "margin-left:%.2fcm;", margin); |
252 | fprintf(of, "margin-left:%.2fcm;", margin); |
252 | fprintf(of, "text-indent:%.2fcm;", indent); |
253 | fprintf(of, "text-indent:%.2fcm;", indent); |
253 | } |
254 | } |
254 | if (!old || (old->justify_hor != new->justify_hor)) |
255 | if (!old || (old->justify_hor != new->justify_hor)) |
255 | fprintf(of, "text-align:%s;", justify_strings[new->justify_hor]); |
256 | fprintf(of, "text-align:%s;", justify_strings[new->justify_hor]); |
256 | if (!old || (old->interline_exact != new->interline_exact)) { |
257 | if (!old || (old->linespacing_exact != new->linespacing_exact)) { |
257 | if (!old || old->interline_exact) |
258 | if (!old || old->linespacing_exact) |
258 | fputs("line-height:normal;", of); |
259 | fputs("line-height:normal;", of); |
259 | else |
260 | else |
260 | fprintf(of, "line-height:%.1fpt;", new->interline); |
261 | fprintf(of, "line-height:%.1fpt;", new->linespacing); |
261 | } |
262 | } |
262 | fput_border(of, "left", old ? old->left_border : NULL, |
263 | fput_border(of, "left", old ? old->left_border : NULL, |
263 | new->left_border); |
264 | new->left_border); |
264 | fput_border(of, "right", old ? old->right_border : NULL, |
265 | fput_border(of, "right", old ? old->right_border : NULL, |
265 | new->right_border); |
266 | new->right_border); |
… | |
… | |
285 | (old->back_color->blue != new->back_color->blue) || |
286 | (old->back_color->blue != new->back_color->blue) || |
286 | (old->italic != new->italic) || |
287 | (old->italic != new->italic) || |
287 | (old->bold != new->bold) || |
288 | (old->bold != new->bold) || |
288 | (old->super_sub != new->super_sub) || |
289 | (old->super_sub != new->super_sub) || |
289 | (old->underline != new->underline) || |
290 | (old->underline != new->underline) || |
290 | (old->strike_out != new->strike_out)); |
291 | (old->strikethrough != new->strikethrough)); |
291 | } |
292 | } |
292 | |
293 | |
293 | static void fput_character_layout(FILE * of, |
294 | static void fput_character_layout(FILE * of, |
294 | const psiconv_character_layout old, |
295 | const psiconv_character_layout old, |
295 | const psiconv_character_layout new, |
296 | const psiconv_character_layout new, |
… | |
… | |
314 | fprintf(of, "background-color:#%02x%02x%02x;", |
315 | fprintf(of, "background-color:#%02x%02x%02x;", |
315 | new->back_color->red, new->back_color->green, new->back_color->blue); |
316 | new->back_color->red, new->back_color->green, new->back_color->blue); |
316 | if (!old || (old->super_sub != new->super_sub)) |
317 | if (!old || (old->super_sub != new->super_sub)) |
317 | fprintf(of, "vertical-align:%s;", vertical_strings[new->super_sub]); |
318 | fprintf(of, "vertical-align:%s;", vertical_strings[new->super_sub]); |
318 | if (!old || (old->underline != new->underline) || |
319 | if (!old || (old->underline != new->underline) || |
319 | (old->strike_out != new->strike_out)) { |
320 | (old->strikethrough != new->strikethrough)) { |
320 | fputs("text-decoration:", of); |
321 | fputs("text-decoration:", of); |
321 | if (new->strike_out) |
322 | if (new->strikethrough) |
322 | fputs("line-through ", of); |
323 | fputs("line-through ", of); |
323 | if (new->underline) |
324 | if (new->underline) |
324 | fputs("underline", of); |
325 | fputs("underline", of); |
325 | else if (!new->strike_out) |
326 | else if (!new->strikethrough) |
326 | fputs("none", of); |
327 | fputs("none", of); |
327 | fputs(";", of); |
328 | fputs(";", of); |
328 | } |
329 | } |
329 | } |
330 | } |
330 | |
331 | |
… | |
… | |
444 | fput_paragraph_layout(of, normal ? normal->paragraph : NULL, sty->paragraph); |
445 | fput_paragraph_layout(of, normal ? normal->paragraph : NULL, sty->paragraph); |
445 | fput_character_layout(of, normal ? normal->character : NULL, sty->character, wf); |
446 | fput_character_layout(of, normal ? normal->character : NULL, sty->character, wf); |
446 | fputs("}\n", of); |
447 | fputs("}\n", of); |
447 | } |
448 | } |
448 | |
449 | |
449 | void psiconv_gen_html4(FILE * of, psiconv_file file) |
450 | static int psiconv_gen_html4(const char *filename, const psiconv_file file, |
|
|
451 | const char *dest) |
450 | { |
452 | { |
|
|
453 | FILE * of; |
451 | int i; |
454 | int i; |
452 | psiconv_paragraph para; |
455 | psiconv_paragraph para; |
453 | psiconv_word_style normal, sty; |
456 | psiconv_word_style normal, sty; |
454 | psiconv_word_f wf; |
457 | psiconv_word_f wf; |
455 | |
458 | |
456 | if (file->type == psiconv_word_file) |
459 | if (file->type == psiconv_word_file) |
457 | wf = file->file; |
460 | wf = file->file; |
458 | else { |
461 | else { |
459 | /* Fall back on the normal HTML generator */ |
462 | /* Fall back on the normal HTML generator */ |
460 | psiconv_gen_html(of,file); |
463 | return psiconv_gen_html(filename,file,dest); |
|
|
464 | } |
|
|
465 | |
|
|
466 | if (! (of = fopen(filename,"w"))) |
461 | return; |
467 | return -1; |
462 | } |
|
|
463 | |
468 | |
464 | fputs("<!doctype html public \"-//W3C//DTD HTML 4.0 STRICT//EN\">", of); |
469 | fputs("<!doctype html public \"-//W3C//DTD HTML 4.0 STRICT//EN\">", of); |
465 | fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); |
470 | fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); |
466 | fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of); |
471 | fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of); |
467 | |
472 | |
… | |
… | |
488 | for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { |
493 | for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { |
489 | para = psiconv_list_get(wf->paragraphs, i); |
494 | para = psiconv_list_get(wf->paragraphs, i); |
490 | fput_para(of, para, wf); |
495 | fput_para(of, para, wf); |
491 | } |
496 | } |
492 | fputs("</BODY>\n</HTML>\n", of); |
497 | fputs("</BODY>\n</HTML>\n", of); |
493 | } |
|
|
494 | |
498 | |
|
|
499 | return fclose(of); |
|
|
500 | } |
|
|
501 | |
|
|
502 | static struct psiconv_fileformat_s ff = |
|
|
503 | { |
|
|
504 | "HTML4", |
|
|
505 | "HTML 4.0 with cascading style sheets", |
|
|
506 | psiconv_gen_html4 |
|
|
507 | }; |
|
|
508 | |
|
|
509 | void init_html4(void) |
|
|
510 | { |
|
|
511 | psiconv_list_add(fileformat_list,&ff); |
|
|
512 | } |
|
|
513 | |