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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 196 - (show annotations)
Wed Feb 4 12:19:09 2004 UTC (20 years, 1 month ago) by frodo
File MIME type: text/plain
File size: 20641 byte(s)
(Frodo) Copyright dates update

1 /*
2 * gen_rtf.c - Part of psiconv, a PSION 5 file formats converter
3 * Copyright (c) 1999 Andrew Johnson <anjohnson@iee.org>
4 * Portions Copyright (c) 1999-2004 Frodo Looijaard <frodol@dds.nl>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "config.h"
22 #include "compat.h"
23 #include <stdio.h>
24 #include <string.h>
25 #include "psiconv/data.h"
26 #include "psiconv/list.h"
27 #include "gen.h"
28 #include "psiconv.h"
29
30 #ifdef DMALLOC
31 #include "dmalloc.h"
32 #endif
33
34
35
36 /*
37 * Various string tables for RTF settings
38 */
39
40 /* Character conversion table */
41 /* TO BE ADJUSTED FOR RTF! */
42 static const char *char_table[0x100] = {
43 /* 0x00 */ "", "", "", "", "", "", "\n", "\n",
44 /* 0x08 */ "\n", "\t", "", "", "", "", "", "",
45 /* 0x10 */ " ", "", "", "", "", "", "", "",
46 /* 0x18 */ "", "", "", "", "", "", "", "",
47 /* 0x20 */ " ", "!", "\"", "#", "$", "%", "&", "'",
48 /* 0x28 */ "(", ")", "*", "+", ",", "-", ".", "/",
49 /* 0x30 */ "0", "1", "2", "3", "4", "5", "6", "7",
50 /* 0x38 */ "8", "9", ":", ";", "<", "=", ">", "?",
51 /* 0x40 */ "@", "A", "B", "C", "D", "E", "F", "G",
52 /* 0x48 */ "H", "I", "J", "K", "L", "M", "N", "O",
53 /* 0x50 */ "P", "Q", "R", "S", "T", "U", "V", "W",
54 /* 0x58 */ "X", "Y", "Z", "[", "\\", "]", "^", "_",
55 /* 0x60 */ "`", "a", "b", "c", "d", "e", "f", "g",
56 /* 0x68 */ "h", "i", "j", "k", "l", "m", "n", "o",
57 /* 0x70 */ "p", "q", "r", "s", "t", "u", "v", "w",
58 /* 0x78 */ "x", "y", "z", "{", "|", "}", "~", "",
59 /* 0x80 */ "", "", ",", "f", ",,", "...", "+", "#",
60 /* 0x88 */ "^", "\176/oo","S", "<", "OE", "", "", "",
61 /* 0x90 */ "", "`", "'", "``", "''", "*", "-", "--",
62 /* 0x98 */ "~", "(TM)", "s", ">", "oe", "", "", "Y",
63 /* 0xa0 */ "\xa0", "\xa1", "\xa2", "\xa3", "\xa4", "\xa5", "\xa6", "\xa7",
64 /* 0xa8 */ "\xa8", "\xa9", "\xaa", "\xab", "\xac", "\xad", "\xae", "\xaf",
65 /* 0xb0 */ "\xb0", "\xb1", "\xb2", "\xb3", "\xb4", "\xb5", "\xb6", "\xb7",
66 /* 0xb8 */ "\xb8", "\xb9", "\xba", "\xbb", "\xbc", "\xbd", "\xbe", "\xbf",
67 /* 0xc0 */ "\xc0", "\xc1", "\xc2", "\xc3", "\xc4", "\xc5", "\xc6", "\xc7",
68 /* 0xc8 */ "\xc8", "\xc9", "\xca", "\xcb", "\xcc", "\xcd", "\xce", "\xcf",
69 /* 0xd0 */ "\xd0", "\xd1", "\xd2", "\xd3", "\xd4", "\xd5", "\xd6", "\xd7",
70 /* 0xd8 */ "\xd8", "\xd9", "\xda", "\xdb", "\xdc", "\xdd", "\xde", "\xdf",
71 /* 0xe0 */ "\xe0", "\xe1", "\xe2", "\xe3", "\xe4", "\xe5", "\xe6", "\xe7",
72 /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef",
73 /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7",
74 /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff",
75 };
76
77 static 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 };
111
112 /* a flag to indicate the use of UTF8 */
113 static psiconv_encoding encoding= PSICONV_ENCODING_CP1252;
114
115 static void fput_text(FILE * of, const char *text, int length) {
116 int j;
117 char ** table;
118 if (encoding == PSICONV_ENCODING_UTF8){
119 table = (char**) utf_table;
120 }else{
121 table = (char**) char_table;
122 }
123 for (j = 0; j < length; j++) {
124 fputs(table[(unsigned char) (text[j])], of);
125 }
126 }
127
128 static int length_to_twips(psiconv_length_t len)
129 {
130 return 1440.0 / 2.54 * len;
131 }
132
133 static int lookup_color(psiconv_list colors,psiconv_color color)
134 {
135 int i;
136 psiconv_color comp;
137 for (i = 0; i < psiconv_list_length(colors); i ++) {
138 comp = * (psiconv_color *) psiconv_list_get(colors,i);
139 if ((comp->red == color->red) && (comp->green == color->green) &&
140 (comp->blue == color->blue))
141 return i;
142 }
143 return -1;
144 }
145
146 static void add_color(psiconv_list colors, psiconv_color color)
147 {
148 if (color)
149 if (lookup_color(colors,color) < 0)
150 psiconv_list_add(colors,&color);
151 }
152
153 static int lookup_font(psiconv_list fonts,psiconv_font font)
154 {
155 int i;
156 psiconv_font comp;
157 for (i = 0; i < psiconv_list_length(fonts); i ++) {
158 comp = *(psiconv_font *) psiconv_list_get(fonts,i);
159 if ((comp->screenfont == font->screenfont) &&
160 ! strcmp(comp->name,font->name))
161 return i;
162 }
163 return -1;
164 }
165
166 static void add_font(psiconv_list fonts, psiconv_font font)
167 {
168 if (font)
169 if (lookup_font(fonts,font) < 0)
170 psiconv_list_add(fonts,&font);
171 }
172
173 static void scan_border(psiconv_list colors,psiconv_list fonts,
174 psiconv_border sec)
175 {
176 if (sec) {
177 add_color(colors,sec->color);
178 }
179 }
180
181 static void scan_bullet(psiconv_list colors,psiconv_list fonts,
182 psiconv_bullet sec)
183 {
184 if (sec) {
185 add_color(colors,sec->color);
186 add_font(fonts,sec->font);
187 }
188 }
189
190 static void scan_paragraph_layout(psiconv_list colors,psiconv_list fonts,
191 psiconv_paragraph_layout sec)
192 {
193 if (sec) {
194 add_color(colors,sec->back_color);
195 scan_bullet(colors,fonts,sec->bullet);
196 scan_border(colors,fonts,sec->left_border);
197 scan_border(colors,fonts,sec->right_border);
198 scan_border(colors,fonts,sec->top_border);
199 scan_border(colors,fonts,sec->bottom_border);
200 }
201 }
202
203 static void scan_character_layout(psiconv_list colors,psiconv_list fonts,
204 psiconv_character_layout sec)
205 {
206 if (sec) {
207 add_color(colors,sec->color);
208 add_color(colors,sec->back_color);
209 add_font(fonts,sec->font);
210 }
211 }
212
213 static void scan_in_line_layout(psiconv_list colors,psiconv_list fonts,
214 psiconv_in_line_layout sec)
215 {
216 if (sec) {
217 scan_character_layout(colors,fonts,sec->layout);
218 }
219 }
220
221 static void scan_in_line_layouts(psiconv_list colors,psiconv_list fonts,
222 psiconv_in_line_layouts sec)
223 {
224 int i;
225 psiconv_in_line_layout layout;
226 if (sec) {
227 for (i = 0; i < psiconv_list_length(sec); i++) {
228 layout = psiconv_list_get(sec,i);
229 scan_in_line_layout(colors,fonts,layout);
230 }
231 }
232 }
233
234 static void scan_paragraph(psiconv_list colors,psiconv_list fonts,
235 psiconv_paragraph sec)
236 {
237 if (sec) {
238 scan_paragraph_layout(colors,fonts,sec->base_paragraph);
239 scan_character_layout(colors,fonts,sec->base_character);
240 scan_in_line_layouts(colors,fonts,sec->in_lines);
241 }
242 }
243
244 static void scan_text_and_layout(psiconv_list colors,psiconv_list fonts,
245 psiconv_text_and_layout sec)
246 {
247 int i;
248 psiconv_paragraph para;
249 if (sec) {
250 for (i = 0; i < psiconv_list_length(sec); i++) {
251 para = psiconv_list_get(sec,i);
252 scan_paragraph(colors,fonts,para);
253 }
254 }
255 }
256
257 static void scan_texted_section(psiconv_list colors,psiconv_list fonts,
258 psiconv_texted_section sec)
259 {
260 if (sec) {
261 scan_text_and_layout(colors,fonts,sec->paragraphs);
262 }
263 }
264
265 static void scan_page_header(psiconv_list colors,psiconv_list fonts,
266 psiconv_page_header sec)
267 {
268 if (sec) {
269 scan_paragraph_layout(colors,fonts,sec->base_paragraph_layout);
270 scan_character_layout(colors,fonts,sec->base_character_layout);
271 scan_texted_section(colors,fonts,sec->text);
272 }
273 }
274
275 static void scan_page_layout_section(psiconv_list colors,psiconv_list fonts,
276 psiconv_page_layout_section sec)
277 {
278 if (sec) {
279 scan_page_header(colors,fonts,sec->header);
280 scan_page_header(colors,fonts,sec->footer);
281 }
282 }
283
284 static void scan_word_style(psiconv_list colors,psiconv_list fonts,
285 psiconv_word_style sec)
286 {
287 if (sec) {
288 scan_character_layout(colors,fonts,sec->character);
289 scan_paragraph_layout(colors,fonts,sec->paragraph);
290 }
291 }
292
293 static void scan_word_style_list(psiconv_list colors,psiconv_list fonts,
294 psiconv_word_style_list sec)
295 {
296 int i;
297 psiconv_word_style style;
298 if (sec) {
299 for (i = 0; i < psiconv_list_length(sec); i++) {
300 style = psiconv_list_get(sec,i);
301 scan_word_style(colors,fonts,style);
302 }
303 }
304 }
305
306 static void scan_word_styles_section(psiconv_list colors,psiconv_list fonts,
307 psiconv_word_styles_section sec)
308 {
309 if (sec) {
310 scan_word_style(colors,fonts,sec->normal);
311 scan_word_style_list(colors,fonts,sec->styles);
312 }
313 }
314
315
316 static void scan_word_f(psiconv_list colors,psiconv_list fonts,
317 psiconv_word_f sec)
318 {
319 if (sec) {
320 scan_page_layout_section(colors,fonts,sec->page_sec);
321 scan_text_and_layout(colors,fonts,sec->paragraphs);
322 scan_word_styles_section(colors,fonts,sec->styles_sec);
323 }
324 }
325
326 static void scan_texted_f(psiconv_list colors,psiconv_list fonts,
327 psiconv_texted_f sec)
328 {
329 if (sec) {
330 scan_page_layout_section(colors,fonts,sec->page_sec);
331 scan_texted_section(colors,fonts,sec->texted_sec);
332 }
333 }
334
335 static void gen_font_table(FILE *of,psiconv_list fonts)
336 {
337 int i;
338 psiconv_font *font;
339
340 fprintf(of,"{\\fonttbl");
341 for (i = 0; i < psiconv_list_length(fonts); i++) {
342 font = psiconv_list_get(fonts,i);
343 fprintf(of,"{\\f%d",i);
344 if ((*font)->screenfont == psiconv_font_sansserif)
345 fprintf(of,"\\fswiss");
346 else if ((*font)->screenfont == psiconv_font_nonprop)
347 fprintf(of,"\\fmodern");
348 else if ((*font)->screenfont == psiconv_font_serif)
349 fprintf(of,"\\froman");
350 else
351 fprintf(of,"\\fnil");
352 fprintf(of,"\\cpg1252\\f%s;}",(*font)->name);
353 }
354 fprintf(of,"}\n");
355 }
356
357 static void gen_color_table(FILE *of, psiconv_list colors)
358 {
359 int i;
360 psiconv_color *color;
361
362 fprintf(of,"{\\colortbl");
363 for (i = 0; i < psiconv_list_length(colors); i++) {
364 color = psiconv_list_get(colors,i);
365 fprintf(of,"\\red%d\\green%d\\blue%d;",(*color)->red,
366 (*color)->green, (*color)->blue);
367 }
368 fprintf(of,"}\n");
369 }
370
371 /* This is not necessarily the same as returned by basic_character_layout_status
372 This one is specific for the base point of RTF */
373 static psiconv_character_layout
374 gen_base_char(psiconv_list colors, psiconv_list fonts)
375 {
376 struct psiconv_color_s white = { 0,0,0 };
377 struct psiconv_color_s black = { 0xff,0xff,0xff };
378 struct psiconv_font_s font = { NULL,-1 }; /* Pseudo - not added! */
379
380 struct psiconv_character_layout_s base_char_struct =
381 {
382 &black, /* color */
383 &white, /* back_color */
384 13.0, /* font_size */
385 psiconv_bool_false, /* italic */
386 psiconv_bool_false, /* bold */
387 psiconv_normalscript, /* super_sub */
388 psiconv_bool_false, /* underline */
389 psiconv_bool_false, /* strikethrough */
390 &font, /* font */
391 };
392
393 font.name = strdup("");
394 add_color(colors,&white);
395 add_color(colors,&black);
396
397 return psiconv_clone_character_layout(&base_char_struct);
398 }
399
400 static void diff_char(FILE *of,psiconv_list colors, psiconv_list fonts,
401 const psiconv_character_layout old,
402 const psiconv_character_layout new)
403 {
404 if ((old->font->screenfont != new->font->screenfont) ||
405 strcmp(old->font->name,new->font->name))
406 fprintf(of,"\\f%d",lookup_font(fonts,new->font));
407 if (old->font_size != new->font_size)
408 fprintf(of,"\\fs%d",(int) (new->font_size * 2));
409 if (old->super_sub != new->super_sub) {
410 if (new->super_sub == psiconv_normalscript)
411 fprintf(of,"\\nosupersub");
412 else if (new->super_sub == psiconv_superscript)
413 fprintf(of,"\\super");
414 else if (new->super_sub == psiconv_subscript)
415 fprintf(of,"\\sub");
416 }
417 if (old->bold != new->bold)
418 fprintf(of,"\\b%s",new->bold?"":"0");
419 if (old->italic != new->italic)
420 fprintf(of,"\\i%s",new->italic?"":"0");
421 if (old->underline != new->underline)
422 fprintf(of,"\\ul%s",new->underline?"":"0");
423 if (old->strikethrough != new->strikethrough)
424 fprintf(of,"\\strike%s",new->strikethrough?"":"0");
425 if ((old->color->red != new->color->red) ||
426 (old->color->green != new->color->green) ||
427 (old->color->blue != new->color->blue))
428 fprintf(of,"\\cf%d",lookup_color(colors,new->color));
429 if ((old->back_color->red != new->back_color->red) ||
430 (old->back_color->green != new->back_color->green) ||
431 (old->back_color->blue != new->back_color->blue))
432 fprintf(of,"\\cb%d",lookup_color(colors,new->back_color));
433 }
434
435
436 /* Note: this generates also some character formatting; Psion Word and
437 RTF do not agree on what is paragraph-level formatting and what is
438 character-level formatting. The character-level formatting is put
439 at the end. This should work out. */
440 static void gen_paragraph_codes(FILE *of, psiconv_list colors,
441 psiconv_list fonts,
442 psiconv_paragraph_layout para)
443 {
444 if (para->indent_first != 0.0)
445 fprintf(of,"\\fl%d",length_to_twips( para->indent_first));
446 if (para->indent_left != 0.0)
447 fprintf(of,"\\ll%d",length_to_twips(para->indent_left));
448 if (para->indent_right != 0.0)
449 fprintf(of,"\\rl%d",length_to_twips(para->indent_right));
450 if (para->justify_hor != psiconv_justify_left) {
451 if (para->justify_hor == psiconv_justify_right)
452 fprintf(of,"\\qr");
453 else if (para->justify_hor == psiconv_justify_centre)
454 fprintf(of,"\\qc");
455 else if (para->justify_hor == psiconv_justify_full)
456 fprintf(of,"\\qj");
457 /*
458 else if (para->justify_hor == psiconv_justify_left)
459 fprintf(of,"\\ql");
460 */
461 }
462 if (para->linespacing != 0.0)
463 fprintf(of,"\\sl%d",(para->linespacing_exact?-1:1) *
464 length_to_twips(para->linespacing));
465 if (para->space_above != 0.0)
466 fprintf(of,"\\sb%d",length_to_twips(para->space_above));
467 if (para->space_below != 0.0)
468 fprintf(of,"\\sa%d",length_to_twips(para->space_below));
469 if (para->keep_together)
470 fprintf(of,"\\keep");
471 if (para->keep_with_next)
472 fprintf(of,"\\keepn");
473 if (!para->on_next_page)
474 fprintf(of,"pagebb");
475 if (!para->no_widow_protection)
476 fprintf(of,"\\nowidctlpar");
477 }
478
479
480 static void gen_para(FILE *of, psiconv_list colors, psiconv_list fonts,
481 psiconv_paragraph para)
482 {
483 psiconv_character_layout cur_char,base_char;
484 psiconv_in_line_layout inl;
485 int loc,i,j;
486
487 char ** table;
488 if (encoding == PSICONV_ENCODING_UTF8){
489 table = (char**) utf_table;
490 }else{
491 table = (char**) char_table;
492 }
493
494 fprintf(of,"\\par\\pard");
495 gen_paragraph_codes(of,colors,fonts,para->base_paragraph);
496
497 base_char = gen_base_char(colors,fonts);
498 cur_char = base_char;
499
500 if (psiconv_list_length(para->in_lines) == 0) {
501 diff_char(of,colors,fonts,cur_char,para->base_character);
502 cur_char = para->base_character;
503 }
504 loc = 0;
505
506 for (i = 0; i < psiconv_list_length(para->in_lines); i++) {
507 inl = psiconv_list_get(para->in_lines,i);
508 diff_char(of,colors,fonts,cur_char,inl->layout);
509 cur_char = inl->layout;
510 for (j = loc; j < inl->length + loc; j ++) {
511 fputs(table[(unsigned char) (para->text[j])],of);
512 }
513 loc = j;
514 }
515
516 if (loc < strlen(para->text)) {
517 diff_char(of,colors,fonts,cur_char,para->base_character);
518 cur_char = para->base_character;
519 for (j = loc; j < strlen(para->text); j ++) {
520 fputs(table[(unsigned char) (para->text[j])],of);
521 }
522 }
523
524 psiconv_free_character_layout(base_char);
525 }
526
527 static void gen_text(FILE *of, psiconv_list colors, psiconv_list fonts,
528 psiconv_text_and_layout paragraphs)
529 {
530 int i;
531 psiconv_paragraph para;
532 fprintf(of,"\\sect");
533 for (i = 0; i < psiconv_list_length(paragraphs); i++) {
534 para = psiconv_list_get(paragraphs,i);
535 gen_para(of,colors,fonts,para);
536 }
537 }
538
539 static void psiconv_gen_rtf_word(FILE * of, psiconv_word_f wf)
540 {
541 psiconv_list fonts;
542 psiconv_list colors;
543
544 fonts = psiconv_list_new(sizeof(psiconv_font));
545 colors = psiconv_list_new(sizeof(psiconv_color));
546 scan_word_f(colors,fonts,wf);
547
548 fputs("{\\rtf1\\ansi\n",of);
549 gen_font_table(of,fonts);
550 gen_color_table(of,colors);
551 gen_text(of,colors,fonts,wf->paragraphs);
552 fputs("}\n",of);
553
554 psiconv_list_free(fonts);
555 psiconv_list_free(colors);
556
557 }
558
559 static void psiconv_gen_rtf_texted(FILE * of, psiconv_texted_f tf)
560 {
561 psiconv_list fonts;
562 psiconv_list colors;
563
564 fonts = psiconv_list_new(sizeof(psiconv_font));
565 colors = psiconv_list_new(sizeof(psiconv_color));
566 scan_texted_f(colors,fonts,tf);
567
568 fputs("{\\rtf1\\ansi\n",of);
569 gen_font_table(of,fonts);
570 gen_color_table(of,colors);
571 gen_text(of,colors,fonts,tf->texted_sec->paragraphs);
572 fputs("}\n",of);
573
574 psiconv_list_free(fonts);
575 psiconv_list_free(colors);
576 }
577
578 static int psiconv_gen_rtf(const char *filename, const psiconv_file file,
579 const char *dest, const psiconv_encoding encoding_type)
580 {
581 FILE *of = fopen(filename,"w");
582 if (! of)
583 return -1;
584
585 encoding = encoding_type;
586 if (file->type == psiconv_word_file) {
587 psiconv_gen_rtf_word(of,(psiconv_word_f) file->file);
588 } else if (file->type == psiconv_texted_file) {
589 psiconv_gen_rtf_texted(of,(psiconv_texted_f) file->file);
590 } else {
591 fclose(of);
592 return -1;
593 }
594 return fclose(of);
595 }
596
597 static struct psiconv_fileformat_s ff =
598 {
599 "RTF",
600 "Rich Text Format (not functional yet!)",
601 psiconv_gen_rtf
602 };
603
604 void init_rtf(void)
605 {
606 /* psiconv_list_add(fileformat_list,&ff); */
607 }
608

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