… | |
… | |
17 | * along with this program; if not, write to the Free Software |
17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | */ |
19 | */ |
20 | |
20 | |
21 | #include "config.h" |
21 | #include "config.h" |
|
|
22 | #include "compat.h" |
22 | #include <stdio.h> |
23 | #include <stdio.h> |
23 | #include <string.h> |
24 | #include <string.h> |
24 | #include "data.h" |
25 | #include "psiconv/data.h" |
25 | #include "list.h" |
26 | #include "psiconv/list.h" |
26 | #include "gen.h" |
27 | #include "gen.h" |
|
|
28 | #include "psiconv.h" |
|
|
29 | |
|
|
30 | #ifdef DMALLOC |
|
|
31 | #include "dmalloc.h" |
|
|
32 | #endif |
27 | |
33 | |
28 | |
34 | |
29 | /* |
35 | /* |
30 | * Various string tables for RTF settings |
36 | * Various string tables for RTF settings |
31 | */ |
37 | */ |
… | |
… | |
291 | |
297 | |
292 | fprintf(of,"{\\fonttbl"); |
298 | fprintf(of,"{\\fonttbl"); |
293 | for (i = 0; i < psiconv_list_length(fonts); i++) { |
299 | for (i = 0; i < psiconv_list_length(fonts); i++) { |
294 | font = psiconv_list_get(fonts,i); |
300 | font = psiconv_list_get(fonts,i); |
295 | fprintf(of,"{\\f%d",i); |
301 | fprintf(of,"{\\f%d",i); |
296 | if ((*font)->screenfont == 1) |
302 | if ((*font)->screenfont == psiconv_font_sansserif) |
297 | fprintf(of,"\\fswiss"); |
303 | fprintf(of,"\\fswiss"); |
298 | else if ((*font)->screenfont == 2) |
304 | else if ((*font)->screenfont == psiconv_font_nonprop) |
299 | fprintf(of,"\\fmodern"); |
305 | fprintf(of,"\\fmodern"); |
300 | else if ((*font)->screenfont == 3) |
306 | else if ((*font)->screenfont == psiconv_font_serif) |
301 | fprintf(of,"\\froman"); |
307 | fprintf(of,"\\froman"); |
302 | else |
308 | else |
303 | fprintf(of,"\\fnil"); |
309 | fprintf(of,"\\fnil"); |
304 | fprintf(of,"\\cpg1252\\f%s;}",(*font)->name); |
310 | fprintf(of,"\\cpg1252\\f%s;}",(*font)->name); |
305 | } |
311 | } |
… | |
… | |
323 | /* This is not necessarily the same as returned by basic_character_layout_status |
329 | /* This is not necessarily the same as returned by basic_character_layout_status |
324 | This one is specific for the base point of RTF */ |
330 | This one is specific for the base point of RTF */ |
325 | static psiconv_character_layout |
331 | static psiconv_character_layout |
326 | gen_base_char(psiconv_list colors, psiconv_list fonts) |
332 | gen_base_char(psiconv_list colors, psiconv_list fonts) |
327 | { |
333 | { |
328 | struct psiconv_color white = { 0,0,0 }; |
334 | struct psiconv_color_s white = { 0,0,0 }; |
329 | struct psiconv_color black = { 0xff,0xff,0xff }; |
335 | struct psiconv_color_s black = { 0xff,0xff,0xff }; |
330 | struct psiconv_font font = { strdup(""),-1 }; /* Pseudo - not added! */ |
336 | struct psiconv_font_s font = { NULL,-1 }; /* Pseudo - not added! */ |
331 | |
337 | |
332 | struct psiconv_character_layout base_char_struct = |
338 | struct psiconv_character_layout_s base_char_struct = |
333 | { |
339 | { |
334 | &black, /* color */ |
340 | &black, /* color */ |
335 | &white, /* back_color */ |
341 | &white, /* back_color */ |
336 | 13.0, /* font_size */ |
342 | 13.0, /* font_size */ |
337 | psiconv_bool_false, /* italic */ |
343 | psiconv_bool_false, /* italic */ |
338 | psiconv_bool_false, /* bold */ |
344 | psiconv_bool_false, /* bold */ |
339 | psiconv_normalscript, /* super_sub */ |
345 | psiconv_normalscript, /* super_sub */ |
340 | psiconv_bool_false, /* underline */ |
346 | psiconv_bool_false, /* underline */ |
341 | psiconv_bool_false, /* strike_out */ |
347 | psiconv_bool_false, /* strikethrough */ |
342 | &font, /* font */ |
348 | &font, /* font */ |
343 | }; |
349 | }; |
344 | |
350 | |
|
|
351 | font.name = strdup(""); |
345 | add_color(colors,&white); |
352 | add_color(colors,&white); |
346 | add_color(colors,&black); |
353 | add_color(colors,&black); |
347 | |
354 | |
348 | return psiconv_clone_character_layout(&base_char_struct); |
355 | return psiconv_clone_character_layout(&base_char_struct); |
349 | } |
356 | } |
350 | |
357 | |
351 | void diff_char(FILE *of,psiconv_list colors, psiconv_list fonts, |
358 | static void diff_char(FILE *of,psiconv_list colors, psiconv_list fonts, |
352 | const psiconv_character_layout old, |
359 | const psiconv_character_layout old, |
353 | const psiconv_character_layout new) |
360 | const psiconv_character_layout new) |
354 | { |
361 | { |
355 | if ((old->font->screenfont != new->font->screenfont) || |
362 | if ((old->font->screenfont != new->font->screenfont) || |
356 | strcmp(old->font->name,new->font->name)) |
363 | strcmp(old->font->name,new->font->name)) |
… | |
… | |
369 | fprintf(of,"\\b%s",new->bold?"":"0"); |
376 | fprintf(of,"\\b%s",new->bold?"":"0"); |
370 | if (old->italic != new->italic) |
377 | if (old->italic != new->italic) |
371 | fprintf(of,"\\i%s",new->italic?"":"0"); |
378 | fprintf(of,"\\i%s",new->italic?"":"0"); |
372 | if (old->underline != new->underline) |
379 | if (old->underline != new->underline) |
373 | fprintf(of,"\\ul%s",new->underline?"":"0"); |
380 | fprintf(of,"\\ul%s",new->underline?"":"0"); |
374 | if (old->strike_out != new->strike_out) |
381 | if (old->strikethrough != new->strikethrough) |
375 | fprintf(of,"\\strike%s",new->strike_out?"":"0"); |
382 | fprintf(of,"\\strike%s",new->strikethrough?"":"0"); |
376 | if ((old->color->red != new->color->red) || |
383 | if ((old->color->red != new->color->red) || |
377 | (old->color->green != new->color->green) || |
384 | (old->color->green != new->color->green) || |
378 | (old->color->blue != new->color->blue)) |
385 | (old->color->blue != new->color->blue)) |
379 | fprintf(of,"\\cf%d",lookup_color(colors,new->color)); |
386 | fprintf(of,"\\cf%d",lookup_color(colors,new->color)); |
380 | if ((old->back_color->red != new->back_color->red) || |
387 | if ((old->back_color->red != new->back_color->red) || |
… | |
… | |
408 | /* |
415 | /* |
409 | else if (para->justify_hor == psiconv_justify_left) |
416 | else if (para->justify_hor == psiconv_justify_left) |
410 | fprintf(of,"\\ql"); |
417 | fprintf(of,"\\ql"); |
411 | */ |
418 | */ |
412 | } |
419 | } |
413 | if (para->interline != 0.0) |
420 | if (para->linespacing != 0.0) |
414 | fprintf(of,"\\sl%d",(para->interline_exact?-1:1) * |
421 | fprintf(of,"\\sl%d",(para->linespacing_exact?-1:1) * |
415 | length_to_twips(para->interline)); |
422 | length_to_twips(para->linespacing)); |
416 | if (para->top_space != 0.0) |
423 | if (para->space_above != 0.0) |
417 | fprintf(of,"\\sb%d",length_to_twips(para->top_space)); |
424 | fprintf(of,"\\sb%d",length_to_twips(para->space_above)); |
418 | if (para->bottom_space != 0.0) |
425 | if (para->space_below != 0.0) |
419 | fprintf(of,"\\sa%d",length_to_twips(para->bottom_space)); |
426 | fprintf(of,"\\sa%d",length_to_twips(para->space_below)); |
420 | if (para->on_one_page) |
427 | if (para->keep_together) |
421 | fprintf(of,"\\keep"); |
428 | fprintf(of,"\\keep"); |
422 | if (para->together_with) |
429 | if (para->keep_with_next) |
423 | fprintf(of,"\\keepn"); |
430 | fprintf(of,"\\keepn"); |
424 | if (!para->on_next_page) |
431 | if (!para->on_next_page) |
425 | fprintf(of,"pagebb"); |
432 | fprintf(of,"pagebb"); |
426 | if (!para->no_widow_protection) |
433 | if (!para->no_widow_protection) |
427 | fprintf(of,"\\nowidctlpar"); |
434 | fprintf(of,"\\nowidctlpar"); |
… | |
… | |
517 | |
524 | |
518 | psiconv_list_free(fonts); |
525 | psiconv_list_free(fonts); |
519 | psiconv_list_free(colors); |
526 | psiconv_list_free(colors); |
520 | } |
527 | } |
521 | |
528 | |
522 | void psiconv_gen_rtf(FILE * of, psiconv_file file) |
529 | static int psiconv_gen_rtf(const char *filename, const psiconv_file file, |
|
|
530 | const char *dest) |
523 | { |
531 | { |
|
|
532 | FILE *of = fopen(filename,"w"); |
|
|
533 | if (! of) |
|
|
534 | return -1; |
|
|
535 | |
524 | if (file->type == psiconv_word_file) |
536 | if (file->type == psiconv_word_file) { |
525 | psiconv_gen_rtf_word(of,(psiconv_word_f) file->file); |
537 | psiconv_gen_rtf_word(of,(psiconv_word_f) file->file); |
526 | else if (file->type == psiconv_texted_file) |
538 | } else if (file->type == psiconv_texted_file) { |
527 | psiconv_gen_rtf_texted(of,(psiconv_texted_f) file->file); |
539 | psiconv_gen_rtf_texted(of,(psiconv_texted_f) file->file); |
528 | else |
540 | } else { |
|
|
541 | fclose(of); |
529 | return; |
542 | return -1; |
|
|
543 | } |
|
|
544 | return fclose(of); |
530 | } |
545 | } |
531 | |
546 | |
|
|
547 | static struct psiconv_fileformat_s ff = |
|
|
548 | { |
|
|
549 | "RTF", |
|
|
550 | "Rich Text Format (not functional yet!)", |
|
|
551 | psiconv_gen_rtf |
|
|
552 | }; |
|
|
553 | |
|
|
554 | void init_rtf(void) |
|
|
555 | { |
|
|
556 | /* psiconv_list_add(fileformat_list,&ff); */ |
|
|
557 | } |
|
|
558 | |