/[public]/psiconv/trunk/program/psiconv/gen_rtf.c
ViewVC logotype

Diff of /psiconv/trunk/program/psiconv/gen_rtf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 146 Revision 147
28#include "psiconv.h" 28#include "psiconv.h"
29 29
30#ifdef DMALLOC 30#ifdef DMALLOC
31#include "dmalloc.h" 31#include "dmalloc.h"
32#endif 32#endif
33
33 34
34 35
35/* 36/*
36 * Various string tables for RTF settings 37 * Various string tables for RTF settings
37 */ 38 */
71 /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef", 72 /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef",
72 /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7", 73 /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7",
73 /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff", 74 /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff",
74}; 75};
75 76
77static const char *utf_table[0x100] = {
78 /* 0x00 */ "", "", "", "", "", "", "\n", "\n",
79 /* 0x08 */ "\n", "\t", "", "", "", "", "", "",
80 /* 0x10 */ " ", "", "", "", "", "", "", "",
81 /* 0x18 */ "", "", "", "", "", "", "", "",
82 /* 0x20 */ " ", "!", "\"", "#", "$", "%", "&", "'",
83 /* 0x28 */ "(", ")", "*", "+", ",", "-", ".", "/",
84 /* 0x30 */ "0", "1", "2", "3", "4", "5", "6", "7",
85 /* 0x38 */ "8", "9", ":", ";", "<", "=", ">", "?",
86 /* 0x40 */ "@", "A", "B", "C", "D", "E", "F", "G",
87 /* 0x48 */ "H", "I", "J", "K", "L", "M", "N", "O",
88 /* 0x50 */ "P", "Q", "R", "S", "T", "U", "V", "W",
89 /* 0x58 */ "X", "Y", "Z", "[", "\\", "]", "^", "_",
90 /* 0x60 */ "`", "a", "b", "c", "d", "e", "f", "g",
91 /* 0x68 */ "h", "i", "j", "k", "l", "m", "n", "o",
92 /* 0x70 */ "p", "q", "r", "s", "t", "u", "v", "w",
93 /* 0x78 */ "x", "y", "z", "{", "|", "}", "~", "",
94 /* 0x80 */ "\x80", "\x81", "\x82", "\x83", "\x84", "\x85", "\x86", "\x87",
95 /* 0x88 */ "\x88", "\x89", "\x8a", "\x8b", "\x8c", "\x8d", "\x8e", "\x8f",
96 /* 0x90 */ "\x90", "\x91", "\x92", "\x93", "\x94", "\x95", "\x96", "\x97",
97 /* 0x98 */ "\x98", "\x99", "\x9a", "\x9b", "\x9c", "\x9d", "\x9e", "\x9f",
98 /* 0xa0 */ "\xa0", "\xa1", "\xa2", "\xa3", "\xa4", "\xa5", "\xa6", "\xa7",
99 /* 0xa8 */ "\xa8", "\xa9", "\xaa", "\xab", "\xac", "\xad", "\xae", "\xaf",
100 /* 0xb0 */ "\xb0", "\xb1", "\xb2", "\xb3", "\xb4", "\xb5", "\xb6", "\xb7",
101 /* 0xb8 */ "\xb8", "\xb9", "\xba", "\xbb", "\xbc", "\xbd", "\xbe", "\xbf",
102 /* 0xc0 */ "\xc0", "\xc1", "\xc2", "\xc3", "\xc4", "\xc5", "\xc6", "\xc7",
103 /* 0xc8 */ "\xc8", "\xc9", "\xca", "\xcb", "\xcc", "\xcd", "\xce", "\xcf",
104 /* 0xd0 */ "\xd0", "\xd1", "\xd2", "\xd3", "\xd4", "\xd5", "\xd6", "\xd7",
105 /* 0xd8 */ "\xd8", "\xd9", "\xda", "\xdb", "\xdc", "\xdd", "\xde", "\xdf",
106 /* 0xe0 */ "\xe0", "\xe1", "\xe2", "\xe3", "\xe4", "\xe5", "\xe6", "\xe7",
107 /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef",
108 /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7",
109 /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff",
110};
76 111
112/* a flag to indicate the use of UTF8 */
113static psiconv_encoding encoding= PSICONV_ENCODING_CP1252;
77 114
78static void fput_text(FILE * of, const char *text, int length) { 115static void fput_text(FILE * of, const char *text, int length) {
79 int j; 116 int j;
117 char ** table;
118 if (encoding == PSICONV_ENCODING_UTF8){
119 table = (char**) utf_table;
120 }else{
121 table = (char**) char_table;
80 122 }
81 for (j = 0; j < length; j++) { 123 for (j = 0; j < length; j++) {
82 fputs(char_table[(unsigned char) (text[j])], of); 124 fputs(table[(unsigned char) (text[j])], of);
83 } 125 }
84} 126}
85 127
86static int length_to_twips(psiconv_length_t len) 128static int length_to_twips(psiconv_length_t len)
87{ 129{
440{ 482{
441 psiconv_character_layout cur_char,base_char; 483 psiconv_character_layout cur_char,base_char;
442 psiconv_in_line_layout inl; 484 psiconv_in_line_layout inl;
443 int loc,i,j; 485 int loc,i,j;
444 486
487 char ** table;
488 if (encoding == PSICONV_ENCODING_UTF8){
489 table = (char**) utf_table;
490 }else{
491 table = (char**) char_table;
492 }
493
445 fprintf(of,"\\par\\pard"); 494 fprintf(of,"\\par\\pard");
446 gen_paragraph_codes(of,colors,fonts,para->base_paragraph); 495 gen_paragraph_codes(of,colors,fonts,para->base_paragraph);
447 496
448 base_char = gen_base_char(colors,fonts); 497 base_char = gen_base_char(colors,fonts);
449 cur_char = base_char; 498 cur_char = base_char;
457 for (i = 0; i < psiconv_list_length(para->in_lines); i++) { 506 for (i = 0; i < psiconv_list_length(para->in_lines); i++) {
458 inl = psiconv_list_get(para->in_lines,i); 507 inl = psiconv_list_get(para->in_lines,i);
459 diff_char(of,colors,fonts,cur_char,inl->layout); 508 diff_char(of,colors,fonts,cur_char,inl->layout);
460 cur_char = inl->layout; 509 cur_char = inl->layout;
461 for (j = loc; j < inl->length + loc; j ++) { 510 for (j = loc; j < inl->length + loc; j ++) {
462 fputs(char_table[(unsigned char) (para->text[j])],of); 511 fputs(table[(unsigned char) (para->text[j])],of);
463 } 512 }
464 loc = j; 513 loc = j;
465 } 514 }
466 515
467 if (loc < strlen(para->text)) { 516 if (loc < strlen(para->text)) {
468 diff_char(of,colors,fonts,cur_char,para->base_character); 517 diff_char(of,colors,fonts,cur_char,para->base_character);
469 cur_char = para->base_character; 518 cur_char = para->base_character;
470 for (j = loc; j < strlen(para->text); j ++) { 519 for (j = loc; j < strlen(para->text); j ++) {
471 fputs(char_table[(unsigned char) (para->text[j])],of); 520 fputs(table[(unsigned char) (para->text[j])],of);
472 } 521 }
473 } 522 }
474 523
475 psiconv_free_character_layout(base_char); 524 psiconv_free_character_layout(base_char);
476} 525}
525 psiconv_list_free(fonts); 574 psiconv_list_free(fonts);
526 psiconv_list_free(colors); 575 psiconv_list_free(colors);
527} 576}
528 577
529static int psiconv_gen_rtf(const char *filename, const psiconv_file file, 578static int psiconv_gen_rtf(const char *filename, const psiconv_file file,
530 const char *dest) 579 const char *dest, const psiconv_encoding encoding_type)
531{ 580{
532 FILE *of = fopen(filename,"w"); 581 FILE *of = fopen(filename,"w");
533 if (! of) 582 if (! of)
534 return -1; 583 return -1;
535 584
585 encoding = encoding_type;
536 if (file->type == psiconv_word_file) { 586 if (file->type == psiconv_word_file) {
537 psiconv_gen_rtf_word(of,(psiconv_word_f) file->file); 587 psiconv_gen_rtf_word(of,(psiconv_word_f) file->file);
538 } else if (file->type == psiconv_texted_file) { 588 } else if (file->type == psiconv_texted_file) {
539 psiconv_gen_rtf_texted(of,(psiconv_texted_f) file->file); 589 psiconv_gen_rtf_texted(of,(psiconv_texted_f) file->file);
540 } else { 590 } else {

Legend:
Removed from v.146  
changed lines
  Added in v.147

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26