… | |
… | |
20 | |
20 | |
21 | #include "config.h" |
21 | #include "config.h" |
22 | #include "compat.h" |
22 | #include "compat.h" |
23 | #include <stdio.h> |
23 | #include <stdio.h> |
24 | #include <string.h> |
24 | #include <string.h> |
25 | #include "data.h" |
25 | #include "psiconv/data.h" |
26 | #include "list.h" |
26 | #include "psiconv/list.h" |
27 | #include "gen.h" |
27 | #include "gen.h" |
28 | #include "psiconv.h" |
28 | #include "psiconv.h" |
29 | |
29 | |
30 | |
30 | |
31 | /* |
31 | /* |
… | |
… | |
293 | |
293 | |
294 | fprintf(of,"{\\fonttbl"); |
294 | fprintf(of,"{\\fonttbl"); |
295 | for (i = 0; i < psiconv_list_length(fonts); i++) { |
295 | for (i = 0; i < psiconv_list_length(fonts); i++) { |
296 | font = psiconv_list_get(fonts,i); |
296 | font = psiconv_list_get(fonts,i); |
297 | fprintf(of,"{\\f%d",i); |
297 | fprintf(of,"{\\f%d",i); |
298 | if ((*font)->screenfont == 1) |
298 | if ((*font)->screenfont == psiconv_font_sansserif) |
299 | fprintf(of,"\\fswiss"); |
299 | fprintf(of,"\\fswiss"); |
300 | else if ((*font)->screenfont == 2) |
300 | else if ((*font)->screenfont == psiconv_font_nonprop) |
301 | fprintf(of,"\\fmodern"); |
301 | fprintf(of,"\\fmodern"); |
302 | else if ((*font)->screenfont == 3) |
302 | else if ((*font)->screenfont == psiconv_font_serif) |
303 | fprintf(of,"\\froman"); |
303 | fprintf(of,"\\froman"); |
304 | else |
304 | else |
305 | fprintf(of,"\\fnil"); |
305 | fprintf(of,"\\fnil"); |
306 | fprintf(of,"\\cpg1252\\f%s;}",(*font)->name); |
306 | fprintf(of,"\\cpg1252\\f%s;}",(*font)->name); |
307 | } |
307 | } |
… | |
… | |
325 | /* This is not necessarily the same as returned by basic_character_layout_status |
325 | /* This is not necessarily the same as returned by basic_character_layout_status |
326 | This one is specific for the base point of RTF */ |
326 | This one is specific for the base point of RTF */ |
327 | static psiconv_character_layout |
327 | static psiconv_character_layout |
328 | gen_base_char(psiconv_list colors, psiconv_list fonts) |
328 | gen_base_char(psiconv_list colors, psiconv_list fonts) |
329 | { |
329 | { |
330 | struct psiconv_color white = { 0,0,0 }; |
330 | struct psiconv_color_s white = { 0,0,0 }; |
331 | struct psiconv_color black = { 0xff,0xff,0xff }; |
331 | struct psiconv_color_s black = { 0xff,0xff,0xff }; |
332 | struct psiconv_font font = { NULL,-1 }; /* Pseudo - not added! */ |
332 | struct psiconv_font_s font = { NULL,-1 }; /* Pseudo - not added! */ |
333 | |
333 | |
334 | struct psiconv_character_layout base_char_struct = |
334 | struct psiconv_character_layout_s base_char_struct = |
335 | { |
335 | { |
336 | &black, /* color */ |
336 | &black, /* color */ |
337 | &white, /* back_color */ |
337 | &white, /* back_color */ |
338 | 13.0, /* font_size */ |
338 | 13.0, /* font_size */ |
339 | psiconv_bool_false, /* italic */ |
339 | psiconv_bool_false, /* italic */ |
340 | psiconv_bool_false, /* bold */ |
340 | psiconv_bool_false, /* bold */ |
341 | psiconv_normalscript, /* super_sub */ |
341 | psiconv_normalscript, /* super_sub */ |
342 | psiconv_bool_false, /* underline */ |
342 | psiconv_bool_false, /* underline */ |
343 | psiconv_bool_false, /* strike_out */ |
343 | psiconv_bool_false, /* strikethrough */ |
344 | &font, /* font */ |
344 | &font, /* font */ |
345 | }; |
345 | }; |
346 | |
346 | |
347 | font.name = strdup(""); |
347 | font.name = strdup(""); |
348 | add_color(colors,&white); |
348 | add_color(colors,&white); |
… | |
… | |
372 | fprintf(of,"\\b%s",new->bold?"":"0"); |
372 | fprintf(of,"\\b%s",new->bold?"":"0"); |
373 | if (old->italic != new->italic) |
373 | if (old->italic != new->italic) |
374 | fprintf(of,"\\i%s",new->italic?"":"0"); |
374 | fprintf(of,"\\i%s",new->italic?"":"0"); |
375 | if (old->underline != new->underline) |
375 | if (old->underline != new->underline) |
376 | fprintf(of,"\\ul%s",new->underline?"":"0"); |
376 | fprintf(of,"\\ul%s",new->underline?"":"0"); |
377 | if (old->strike_out != new->strike_out) |
377 | if (old->strikethrough != new->strikethrough) |
378 | fprintf(of,"\\strike%s",new->strike_out?"":"0"); |
378 | fprintf(of,"\\strike%s",new->strikethrough?"":"0"); |
379 | if ((old->color->red != new->color->red) || |
379 | if ((old->color->red != new->color->red) || |
380 | (old->color->green != new->color->green) || |
380 | (old->color->green != new->color->green) || |
381 | (old->color->blue != new->color->blue)) |
381 | (old->color->blue != new->color->blue)) |
382 | fprintf(of,"\\cf%d",lookup_color(colors,new->color)); |
382 | fprintf(of,"\\cf%d",lookup_color(colors,new->color)); |
383 | if ((old->back_color->red != new->back_color->red) || |
383 | if ((old->back_color->red != new->back_color->red) || |
… | |
… | |
411 | /* |
411 | /* |
412 | else if (para->justify_hor == psiconv_justify_left) |
412 | else if (para->justify_hor == psiconv_justify_left) |
413 | fprintf(of,"\\ql"); |
413 | fprintf(of,"\\ql"); |
414 | */ |
414 | */ |
415 | } |
415 | } |
416 | if (para->interline != 0.0) |
416 | if (para->linespacing != 0.0) |
417 | fprintf(of,"\\sl%d",(para->interline_exact?-1:1) * |
417 | fprintf(of,"\\sl%d",(para->linespacing_exact?-1:1) * |
418 | length_to_twips(para->interline)); |
418 | length_to_twips(para->linespacing)); |
419 | if (para->top_space != 0.0) |
419 | if (para->space_above != 0.0) |
420 | fprintf(of,"\\sb%d",length_to_twips(para->top_space)); |
420 | fprintf(of,"\\sb%d",length_to_twips(para->space_above)); |
421 | if (para->bottom_space != 0.0) |
421 | if (para->space_below != 0.0) |
422 | fprintf(of,"\\sa%d",length_to_twips(para->bottom_space)); |
422 | fprintf(of,"\\sa%d",length_to_twips(para->space_below)); |
423 | if (para->on_one_page) |
423 | if (para->keep_together) |
424 | fprintf(of,"\\keep"); |
424 | fprintf(of,"\\keep"); |
425 | if (para->together_with) |
425 | if (para->keep_with_next) |
426 | fprintf(of,"\\keepn"); |
426 | fprintf(of,"\\keepn"); |
427 | if (!para->on_next_page) |
427 | if (!para->on_next_page) |
428 | fprintf(of,"pagebb"); |
428 | fprintf(of,"pagebb"); |
429 | if (!para->no_widow_protection) |
429 | if (!para->no_widow_protection) |
430 | fprintf(of,"\\nowidctlpar"); |
430 | fprintf(of,"\\nowidctlpar"); |
… | |
… | |
520 | |
520 | |
521 | psiconv_list_free(fonts); |
521 | psiconv_list_free(fonts); |
522 | psiconv_list_free(colors); |
522 | psiconv_list_free(colors); |
523 | } |
523 | } |
524 | |
524 | |
525 | static int psiconv_gen_rtf(FILE * of, const psiconv_file file, const char *dest) |
525 | static int psiconv_gen_rtf(const char *filename, const psiconv_file file, |
|
|
526 | const char *dest) |
526 | { |
527 | { |
|
|
528 | FILE *of = fopen(filename,"w"); |
|
|
529 | if (! of) |
|
|
530 | return -1; |
|
|
531 | |
527 | if (file->type == psiconv_word_file) { |
532 | if (file->type == psiconv_word_file) { |
528 | psiconv_gen_rtf_word(of,(psiconv_word_f) file->file); |
533 | psiconv_gen_rtf_word(of,(psiconv_word_f) file->file); |
529 | return 0; |
|
|
530 | } else if (file->type == psiconv_texted_file) { |
534 | } else if (file->type == psiconv_texted_file) { |
531 | psiconv_gen_rtf_texted(of,(psiconv_texted_f) file->file); |
535 | psiconv_gen_rtf_texted(of,(psiconv_texted_f) file->file); |
532 | return 0; |
|
|
533 | } else |
536 | } else { |
|
|
537 | fclose(of); |
534 | return -1; |
538 | return -1; |
|
|
539 | } |
|
|
540 | return fclose(of); |
535 | } |
541 | } |
536 | |
542 | |
537 | static struct psiconv_fileformat ff = |
543 | static struct psiconv_fileformat_s ff = |
538 | { |
544 | { |
539 | "RTF", |
545 | "RTF", |
540 | "Rich Text Format (not functional yet!)", |
546 | "Rich Text Format (not functional yet!)", |
541 | psiconv_gen_rtf |
547 | psiconv_gen_rtf |
542 | }; |
548 | }; |