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