--- psiconv/trunk/lib/psiconv/gen_rtf.c 1999/10/04 16:38:15 5 +++ psiconv/trunk/lib/psiconv/gen_rtf.c 1999/10/04 18:13:31 6 @@ -76,14 +76,269 @@ } } -static void psiconv_gen_rtf_word(FILE * of, psiconv_word_f tf) +static void add_color(psiconv_list colors, psiconv_color color) { - return; + int i; + psiconv_color comp; + if (color) { + for (i = 0; i < psiconv_list_length(colors); i ++) { + comp = * (psiconv_color *) psiconv_list_get(colors,i); + if ((comp->red == color->red) && (comp->green == color->green) && + (comp->blue == color->blue)) + return; + } + psiconv_list_add(colors,&color); + } +} + +static void add_font(psiconv_list fonts, psiconv_font font) +{ + int i; + psiconv_font comp; + if (font) { + for (i = 0; i < psiconv_list_length(fonts); i ++) { + comp = *(psiconv_font *) psiconv_list_get(fonts,i); + if ((comp->screenfont == font->screenfont) && + ! strcmp(comp->name,font->name)) + return; + } + psiconv_list_add(fonts,&font); + } +} + +static void scan_border(psiconv_list colors,psiconv_list fonts, + psiconv_border sec) +{ + if (sec) { + add_color(colors,sec->color); + } +} + +static void scan_bullet(psiconv_list colors,psiconv_list fonts, + psiconv_bullet sec) +{ + if (sec) { + add_color(colors,sec->color); + add_font(fonts,sec->font); + } +} + +static void scan_paragraph_layout(psiconv_list colors,psiconv_list fonts, + psiconv_paragraph_layout sec) +{ + if (sec) { + add_color(colors,sec->back_color); + scan_bullet(colors,fonts,sec->bullet); + scan_border(colors,fonts,sec->left_border); + scan_border(colors,fonts,sec->right_border); + scan_border(colors,fonts,sec->top_border); + scan_border(colors,fonts,sec->bottom_border); + } +} + +static void scan_character_layout(psiconv_list colors,psiconv_list fonts, + psiconv_character_layout sec) +{ + if (sec) { + add_color(colors,sec->color); + add_color(colors,sec->back_color); + add_font(fonts,sec->font); + } +} + +static void scan_in_line_layout(psiconv_list colors,psiconv_list fonts, + psiconv_in_line_layout sec) +{ + if (sec) { + scan_character_layout(colors,fonts,sec->layout); + } +} + +static void scan_in_line_layouts(psiconv_list colors,psiconv_list fonts, + psiconv_in_line_layouts sec) +{ + int i; + psiconv_in_line_layout layout; + if (sec) { + for (i = 0; i < psiconv_list_length(sec); i++) { + layout = psiconv_list_get(sec,i); + scan_in_line_layout(colors,fonts,layout); + } + } +} + +static void scan_paragraph(psiconv_list colors,psiconv_list fonts, + psiconv_paragraph sec) +{ + if (sec) { + scan_paragraph_layout(colors,fonts,sec->base_paragraph); + scan_character_layout(colors,fonts,sec->base_character); + scan_in_line_layouts(colors,fonts,sec->in_lines); + } +} + +static void scan_text_and_layout(psiconv_list colors,psiconv_list fonts, + psiconv_text_and_layout sec) +{ + int i; + psiconv_paragraph para; + if (sec) { + for (i = 0; i < psiconv_list_length(sec); i++) { + para = psiconv_list_get(sec,i); + scan_paragraph(colors,fonts,para); + } + } +} + +static void scan_texted_section(psiconv_list colors,psiconv_list fonts, + psiconv_texted_section sec) +{ + if (sec) { + scan_text_and_layout(colors,fonts,sec->paragraphs); + } +} + +static void scan_page_header(psiconv_list colors,psiconv_list fonts, + psiconv_page_header sec) +{ + if (sec) { + scan_paragraph_layout(colors,fonts,sec->base_paragraph_layout); + scan_character_layout(colors,fonts,sec->base_character_layout); + scan_texted_section(colors,fonts,sec->text); + } +} + +static void scan_page_layout_section(psiconv_list colors,psiconv_list fonts, + psiconv_page_layout_section sec) +{ + if (sec) { + scan_page_header(colors,fonts,sec->header); + scan_page_header(colors,fonts,sec->footer); + } +} + +static void scan_word_style(psiconv_list colors,psiconv_list fonts, + psiconv_word_style sec) +{ + if (sec) { + scan_character_layout(colors,fonts,sec->character); + scan_paragraph_layout(colors,fonts,sec->paragraph); + } +} + +static void scan_word_style_list(psiconv_list colors,psiconv_list fonts, + psiconv_word_style_list sec) +{ + int i; + psiconv_word_style style; + if (sec) { + for (i = 0; i < psiconv_list_length(sec); i++) { + style = psiconv_list_get(sec,i); + scan_word_style(colors,fonts,style); + } + } +} + +static void scan_word_styles_section(psiconv_list colors,psiconv_list fonts, + psiconv_word_styles_section sec) +{ + if (sec) { + scan_word_style(colors,fonts,sec->normal); + scan_word_style_list(colors,fonts,sec->styles); + } +} + + +static void scan_word_f(psiconv_list colors,psiconv_list fonts, + psiconv_word_f sec) +{ + if (sec) { + scan_page_layout_section(colors,fonts,sec->page_sec); + scan_text_and_layout(colors,fonts,sec->paragraphs); + scan_word_styles_section(colors,fonts,sec->styles_sec); + } +} + +static void scan_texted_f(psiconv_list colors,psiconv_list fonts, + psiconv_texted_f sec) +{ + if (sec) { + scan_page_layout_section(colors,fonts,sec->page_sec); + scan_texted_section(colors,fonts,sec->texted_sec); + } +} + +static gen_font_table(FILE *of,psiconv_list fonts) +{ + int i; + psiconv_font *font; + + fprintf(of,"{\\fonttbl"); + for (i = 0; i < psiconv_list_length(fonts); i++) { + font = psiconv_list_get(fonts,i); + fprintf(of,"{\\f%d",i); + if ((*font)->screenfont == 1) + fprintf(of,"\\fswiss"); + else if ((*font)->screenfont == 2) + fprintf(of,"\\fmodern"); + else if ((*font)->screenfont == 3) + fprintf(of,"\\froman"); + else + fprintf(of,"\\fnil"); + fprintf(of,"\\cpg1252\\f%s;}",(*font)->name); + } + fprintf(of,"}\n"); +} + +static gen_color_table(FILE *of, psiconv_list colors) +{ + int i; + psiconv_color *color; + + fprintf(of,"{\\colortbl"); + for (i = 0; i < psiconv_list_length(colors); i++) { + color = psiconv_list_get(colors,i); + fprintf(of,"\\red%d\\green%d\\blue%d;",(*color)->red, + (*color)->green, (*color)->blue); + } + fprintf(of,"}\n"); +} + +static void psiconv_gen_rtf_word(FILE * of, psiconv_word_f wf) +{ + psiconv_list fonts; + psiconv_list colors; + + fonts = psiconv_list_new(sizeof(psiconv_font)); + colors = psiconv_list_new(sizeof(psiconv_color)); + scan_word_f(colors,fonts,wf); + + fputs("{\\rtf1\\ansi\n",of); + gen_font_table(of,fonts); + gen_color_table(of,colors); + fputs("}\n",of); + + psiconv_list_free(fonts); + psiconv_list_free(colors); + } static void psiconv_gen_rtf_texted(FILE * of, psiconv_texted_f tf) { - return; + psiconv_list fonts; + psiconv_list colors; + + fonts = psiconv_list_new(sizeof(psiconv_font)); + colors = psiconv_list_new(sizeof(psiconv_color)); + scan_texted_f(colors,fonts,tf); + + fputs("{\\rtf1\\ansi\n",of); + gen_font_table(of,fonts); + gen_color_table(of,colors); + fputs("}\n",of); + + psiconv_list_free(fonts); + psiconv_list_free(colors); } void psiconv_gen_rtf(FILE * of, psiconv_file file)