--- psiconv/trunk/program/psiconv/gen_html.c 2004/01/26 14:00:40 189 +++ psiconv/trunk/program/psiconv/gen_html.c 2004/01/26 21:56:49 190 @@ -1,447 +1,357 @@ -/* - gen_html.c - Part of psiconv, a PSION 5 file formats converter - Copyright (c) 1999 Frodo Looijaard - +/* gen_html.c - Part of psiconv, a PSION 5 file formats converter + Copyright (c) 1999-2004 Frodo Looijaard + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* - 2002/Apr. Keita KAWABE - A: header - was added. - - B: Support for narrow build Asian Psions added. - If the encoding_type is PSICONV_ENCODING_UTF8, - B-1: use utf8_table for character conversion. - B-2: add the "Charset=UTF-8" in the Content-Type header. - Otherwise proceed as normal. -*/ #include "config.h" -#include + +#include +#include +#include "general.h" + #include #include -#include "psiconv/data.h" -#include "psiconv/list.h" -#include "gen.h" -#include "psiconv.h" #ifdef DMALLOC #include "dmalloc.h" #endif -/* This determines for each character how it is displayed */ -static const char *char_table[0x100] = -{ - /* 0x00 */ "" ,"" ,"" ,"" ,"" ,"" ,"

","
" , - /* 0x08 */ "

" ," " ,"" ,"" ,"" ,"" ,"" ,"" , - /* 0x10 */ " " ,"" ,"" ,"" ,"" ,"" ,"" ,"" , - /* 0x18 */ "" ,"" ,"" ,"" ,"" ,"" ,"" ,"" , - /* 0x20 */ " " ,"!" ,""","#" ,"$" ,"%" ,"&","'" , - /* 0x28 */ "(" ,")" ,"*" ,"+" ,"," ,"-" ,"." ,"/" , - /* 0x30 */ "0" ,"1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7" , - /* 0x38 */ "8" ,"9" ,":" ,";" ,"<" ,"=" ,">" ,"?" , - /* 0x40 */ "@" ,"A" ,"B" ,"C" ,"D" ,"E" ,"F" ,"G" , - /* 0x48 */ "H" ,"I" ,"J" ,"K" ,"L" ,"M" ,"N" ,"O" , - /* 0x50 */ "P" ,"Q" ,"R" ,"S" ,"T" ,"U" ,"V" ,"W" , - /* 0x58 */ "X" ,"Y" ,"Z" ,"[" ,"\\" ,"]" ,"^" ,"_" , - /* 0x60 */ "`" ,"a" ,"b" ,"c" ,"d" ,"e" ,"f" ,"g" , - /* 0x68 */ "h" ,"i" ,"j" ,"k" ,"l" ,"m" ,"n" ,"o" , - /* 0x70 */ "p" ,"q" ,"r" ,"s" ,"t" ,"u" ,"v" ,"w" , - /* 0x78 */ "x" ,"y" ,"z" ,"{" ,"|" ,"}" ,"~" ,"" , - /* 0x80 */ "" ,"","&sbquot;","ƒ","„","…", - "†","‡", - /* 0x88 */ "^","‰","Š","⟨","Œ","" ,"" ,"" , - /* 0x90 */ "","‘","’","“","”", - "·","&ndash","&mdash", - /* 0x98 */ "˜","™","š","⟩","œ","","","Ÿ", - /* 0xa0 */ "","¡","¢","£", - "¤","¥","¦","§", - /* 0xa8 */ ""","©","a","«","¬","-","®","¯on;", - /* 0xb0 */ "°","±","²","³", - "&rsquot;","µn;","¶","·", - /* 0xb8 */ ",","¹","°","»", - "¼","½","¾","¿", - /* 0xc0 */ "À","Á","Â","Ã", - "Ä","Å","Æ","Ç", - /* 0xc8 */ "È","É","Ê","Ë", - "Ì","Í","Î","Ï", - /* 0xd0 */ "Ð","Ñ","Ò","Ó", - "Ô","Õ","Ö","×", - /* 0xd8 */ "Ø","Ù","Ú","Û", - "Ü","Ý","Þ","ß", - /* 0xe0 */ "à","á","â","ã", - "ä","å","æ","ç", - /* 0xe8 */ "è","é","ê","ë", - "ì","í","î","ï", - /* 0xf0 */ "ð","ñ","ò","ó", - "ô","õ","ö","÷", - /* 0xf8 */ "ø","ù","ú","û", - "ü","ý","þ","ÿ" -}; - -static const char *utf_table[0x100] = -{ - /* 0x00 */ "" ,"" ,"" ,"" ,"" ,"" ,"

","
" , - /* 0x08 */ "

" ," " ,"" ,"" ,"" ,"" ,"" ,"" , - /* 0x10 */ " " ,"" ,"" ,"" ,"" ,"" ,"" ,"" , - /* 0x18 */ "" ,"" ,"" ,"" ,"" ,"" ,"" ,"" , - /* 0x20 */ " " ,"!" ,""","#" ,"$" ,"%" ,"&","'" , - /* 0x28 */ "(" ,")" ,"*" ,"+" ,"," ,"-" ,"." ,"/" , - /* 0x30 */ "0" ,"1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7" , - /* 0x38 */ "8" ,"9" ,":" ,";" ,"<" ,"=" ,">" ,"?" , - /* 0x40 */ "@" ,"A" ,"B" ,"C" ,"D" ,"E" ,"F" ,"G" , - /* 0x48 */ "H" ,"I" ,"J" ,"K" ,"L" ,"M" ,"N" ,"O" , - /* 0x50 */ "P" ,"Q" ,"R" ,"S" ,"T" ,"U" ,"V" ,"W" , - /* 0x58 */ "X" ,"Y" ,"Z" ,"[" ,"\\" ,"]" ,"^" ,"_" , - /* 0x60 */ "`" ,"a" ,"b" ,"c" ,"d" ,"e" ,"f" ,"g" , - /* 0x68 */ "h" ,"i" ,"j" ,"k" ,"l" ,"m" ,"n" ,"o" , - /* 0x70 */ "p" ,"q" ,"r" ,"s" ,"t" ,"u" ,"v" ,"w" , - /* 0x78 */ "x" ,"y" ,"z" ,"{" ,"|" ,"}" ,"~" ,"" , - /* 0x80 */ "\x80", "\x81", "\x82", "\x83", "\x84", "\x85", "\x86", "\x87", - /* 0x88 */ "\x88", "\x89", "\x8a", "\x8b", "\x8c", "\x8d", "\x8e", "\x8f", - /* 0x90 */ "\x90", "\x91", "\x92", "\x93", "\x94", "\x95", "\x96", "\x97", - /* 0x98 */ "\x98", "\x99", "\x9a", "\x9b", "\x9c", "\x9d", "\x9e", "\x9f", - /* 0xa0 */ "\xa0", "\xa1", "\xa2", "\xa3", "\xa4", "\xa5", "\xa6", "\xa7", - /* 0xa8 */ "\xa8", "\xa9", "\xaa", "\xab", "\xac", "\xad", "\xae", "\xaf", - /* 0xb0 */ "\xb0", "\xb1", "\xb2", "\xb3", "\xb4", "\xb5", "\xb6", "\xb7", - /* 0xb8 */ "\xb8", "\xb9", "\xba", "\xbb", "\xbc", "\xbd", "\xbe", "\xbf", - /* 0xc0 */ "\xc0", "\xc1", "\xc2", "\xc3", "\xc4", "\xc5", "\xc6", "\xc7", - /* 0xc8 */ "\xc8", "\xc9", "\xca", "\xcb", "\xcc", "\xcd", "\xce", "\xcf", - /* 0xd0 */ "\xd0", "\xd1", "\xd2", "\xd3", "\xd4", "\xd5", "\xd6", "\xd7", - /* 0xd8 */ "\xd8", "\xd9", "\xda", "\xdb", "\xdc", "\xdd", "\xde", "\xdf", - /* 0xe0 */ "\xe0", "\xe1", "\xe2", "\xe3", "\xe4", "\xe5", "\xe6", "\xe7", - /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef", - /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7", - /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff", -}; - -/* a flag to indicate the use of UTF8 */ -static psiconv_encoding encoding= PSICONV_ENCODING_CP1252; - -static psiconv_character_layout gen_base_char(const psiconv_font font, - const psiconv_color color, - const psiconv_color back_color); -static void diff_char(FILE *of, const psiconv_character_layout old, - const psiconv_character_layout new, int *flags); -static void gen_para(FILE *of, const psiconv_paragraph para, - const psiconv_character_layout base_char); - -static void psiconv_gen_html_word(FILE *of,psiconv_word_f wf); -static void psiconv_gen_html_texted(FILE *of,psiconv_texted_f tf); - -/* This is not necessarily the same as returned by basic_character_layout_status - This one is specific for the base point of HTML */ -psiconv_character_layout gen_base_char(const psiconv_font font, - const psiconv_color color, - const psiconv_color back_color) -{ - struct psiconv_character_layout_s base_char_struct = - { - NULL, /* color */ - NULL, /* back_color */ - 13.0, /* font_size */ - psiconv_bool_false, /* italic */ - psiconv_bool_false, /* bold */ - psiconv_normalscript, /* super_sub */ - psiconv_bool_false, /* underline */ - psiconv_bool_false, /* strikethrough */ - NULL, /* font */ - }; - base_char_struct.color = color; - base_char_struct.back_color = back_color; - base_char_struct.font = font; - return psiconv_clone_character_layout(&base_char_struct); -} +#define TEMPSTR_LEN 100 -/* flags & 1: 0 if no was yet generated. - flags & 2: 1 if at end-of-paragraph -*/ -void diff_char(FILE *of, const psiconv_character_layout old, - const psiconv_character_layout new, - int *flags) -{ - int font_set = 0; - - if ((old->font_size != new->font_size) || - (old->color->red != new->color->red) || - (old->color->green != new->color->green) || - (old->color->blue != new->color->blue) || - (strcmp(old->font->name,new->font->name)) || - (old->font->screenfont != new->font->screenfont) || - ((*flags & 0x03) == 3)) { - if (old->italic) - fputs("",of); - if (old->bold) - fputs("",of); - if (old->underline) - fputs("",of); - if (old->strikethrough) - fputs("",of); - if (old->super_sub == psiconv_superscript) - fputs("",of); - if (old->super_sub == psiconv_subscript) - fputs("",of); - if ((*flags & 1) == 1) - fputs("",of); - if ((*flags & 2) == 0) { - *flags |= 1; - fputs("font_size <= 10.0) - fputs("2",of); - else if (new->font_size <= 12.0) - fputs("3",of); - else if (new->font_size <= 14.0) - fputs("4",of); - else if (new->font_size <= 18.0) - fputs("5",of); - else if (new->font_size <= 24.0) - fputs("6",of); - else - fputs("7",of); - fprintf(of," COLOR=#%02x%02x%02x",new->color->red,new->color->green, - new->color->blue); - if (new->font->screenfont == psiconv_font_sansserif) - fprintf(of," FACE=\"%s, Sans-Serif\">",new->font->name); - else if (new->font->screenfont == psiconv_font_nonprop) - fprintf(of," FACE=\"%s, Monospace\">",new->font-> name); - else if (new->font->screenfont == psiconv_font_serif) - fprintf(of," FACE=\"%s, Serif\">",new->font-> name); - else - fprintf(of," FACE=\"%s, Serif\">",new->font-> name); - } - if (new->italic) - fputs("",of); - if (new->bold) - fputs("",of); - if (new->underline) - fputs("",of); - if (new->strikethrough) - fputs("",of); - if (new->super_sub == psiconv_superscript) - fputs("",of); - if (new->super_sub == psiconv_subscript) - fputs("",of); - } else { - if (font_set || (old->italic != new->italic)) { - if (old->italic) - fputs("",of); - else - fputs("",of); - } - if (old->bold != new->bold) { - if (old->bold) - fputs("",of); - else - fputs("",of); - } - if (old->underline != new->underline) { - if (old->underline) - fputs("",of); - else - fputs("",of); - } - if (old->strikethrough != new->strikethrough) { - if (old->strikethrough) - fputs("",of); - else - fputs("",of); - } - if (old->super_sub != new->super_sub) { - if (old->super_sub == psiconv_superscript) - fputs("",of); - else if (old->super_sub == psiconv_subscript) - fputs("",of); - if (new->super_sub == psiconv_superscript) - fputs("",of); - else if (new->super_sub == psiconv_subscript) - fputs("",of); - } - } -} +typedef enum output_type_e { output_html, output_xhtml } output_type; -void gen_para(FILE *of, const psiconv_paragraph para, - const psiconv_character_layout base_char) +void character_layout_diffs(const psiconv_config config, psiconv_list list, + const psiconv_character_layout new, + const psiconv_character_layout base, + const encoding enc) { - int i,j,loc; - psiconv_character_layout cur_char; - psiconv_in_line_layout inl; - int flags = 0; - - char **table; - if (encoding == PSICONV_ENCODING_UTF8){ - table=(char**)utf_table; - }else{ - table=(char**)char_table; + if (new->italic != base->italic) { + output_simple_chars(config,list,"font-style:",enc); + output_simple_chars(config,list,new->italic?"italic":"normal",enc); + output_simple_chars(config,list,";",enc); } - - + if ((new->underline != base->underline) || + (new->strikethrough != base->strikethrough)) { + output_simple_chars(config,list,"text-decoration:",enc); + output_simple_chars(config,list,new->underline?"underline": + new->strikethrough?"line-through": + "none",enc); + output_simple_chars(config,list,";",enc); + } + if (new->bold != base->bold) { + output_simple_chars(config,list,"font-weight:",enc); + output_simple_chars(config,list,new->bold?"bold":"normal",enc); + output_simple_chars(config,list,";",enc); + } + if (new->super_sub != base->super_sub) { + output_simple_chars(config,list,"font-style:",enc); + output_simple_chars(config,list, + new->super_sub==psiconv_superscript?"super": + new->super_sub==psiconv_subscript?"sub": + "normal",enc); + output_simple_chars(config,list,";",enc); + } +} - fputs("base_paragraph->justify_hor == psiconv_justify_left) - fputs(" ALIGN=left",of); - else if (para->base_paragraph->justify_hor == psiconv_justify_right) - fputs(" ALIGN=right",of); - else if (para->base_paragraph->justify_hor == psiconv_justify_centre) - fputs(" ALIGN=center",of); - else if (para->base_paragraph->justify_hor == psiconv_justify_full) - fputs(" ALIGN=left",of); - fputs(">",of); - if (para->base_paragraph->bullet->on) - fputs("

  • ",of); +void paragraph_layout_diffs(const psiconv_config config, psiconv_list list, + const psiconv_paragraph_layout new, + const psiconv_paragraph_layout base) +{ +} - cur_char = base_char; +void header(const psiconv_config config, psiconv_list list, + output_type type, const encoding enc) +{ + if (type == output_xhtml) + output_simple_chars(config,list, + "\n",enc); + output_simple_chars(config,list,"": + "\"http://www.w3.org/TR/html4/strict.dtd\">",enc); + output_simple_chars(config,list,"\n\n",enc); + output_simple_chars(config,list,"\n",enc); + output_simple_chars(config,list,"\n",enc); + output_simple_chars(config,list,"\n",enc); + output_simple_chars(config,list,"EPOC32 file " + "converted by psiconv\n",enc); + output_simple_chars(config,list,"\n",enc); + output_simple_chars(config,list,"\n",enc); +} - if (psiconv_list_length(para->in_lines) == 0) { - diff_char(of,cur_char,para->base_character,&flags); - cur_char = para->base_character; - } - loc = 0; +void footer(const psiconv_config config, psiconv_list list, + output_type type, const encoding enc) +{ + output_simple_chars(config,list,"\n",enc); + output_simple_chars(config,list,"\n",enc); +} - for (i = 0; i < psiconv_list_length(para->in_lines); i++) { - inl = psiconv_list_get(para->in_lines,i); - diff_char(of,cur_char,inl->layout,&flags); - cur_char = inl->layout; - for (j = loc; j < inl->length + loc; j ++) { - fputs(table[(unsigned char) (para->text[j])],of); - } - loc = j; +void color(const psiconv_config config, psiconv_list list, + psiconv_color color, output_type type, const encoding enc) +{ + char tempstr[TEMPSTR_LEN]; + if ((color->red == 0xff) && + (color->blue == 0xff) && + (color->green == 0xff)) + output_simple_chars(config,list,"transparant",enc); + else { + snprintf(tempstr,TEMPSTR_LEN,"rgb(%d,%d,%d)", + color->red, + color->green, + color->blue); + output_simple_chars(config,list,tempstr,enc); } +} - if (loc < strlen(para->text)) { - diff_char(of,cur_char,para->base_character,&flags); - cur_char = para->base_character; - for (j = loc; j < strlen(para->text); j ++) { - fputs(table[(unsigned char) (para->text[j])],of); - } +void charlayout(const psiconv_config config, psiconv_list list, + psiconv_string_t text,psiconv_character_layout layout, + output_type type, const encoding enc) +{ + char tempstr[TEMPSTR_LEN]; + if (layout->italic) + output_simple_chars(config,list,"",enc); + if (layout->bold) + output_simple_chars(config,list,"",enc); + if (layout->super_sub != psiconv_normalscript) + output_simple_chars(config,list, + layout->super_sub == psiconv_superscript?"": + layout->super_sub == psiconv_subscript?"": + "",enc); + + output_simple_chars(config,list,"underline || layout->strikethrough) { + output_simple_chars(config,list,"text-decoration:",enc); + output_simple_chars(config,list,layout->underline?"underline": + layout->strikethrough?"line-through": + "",enc); + output_simple_chars(config,list,";",enc); } - if (strlen(para->text) == 0) - fputs("
    ",of); - - flags |= 2; - diff_char(of,cur_char,base_char,&flags); - - if (para->base_paragraph->bullet->on) - fputs("
",of); - - fputs("

\n",of); + output_simple_chars(config,list,"color:",enc); + color(config,list,layout->color,type,enc); + output_simple_chars(config,list,";",enc); + + output_simple_chars(config,list,"background-color:",enc); + color(config,list,layout->back_color,type,enc); + output_simple_chars(config,list,";",enc); + + output_simple_chars(config,list,"font-size:",enc); + snprintf(tempstr,TEMPSTR_LEN,"%f",layout->font_size); + output_simple_chars(config,list,tempstr,enc); + output_simple_chars(config,list,"pt;",enc); + + output_simple_chars(config,list,"\">",enc); + + output_string(config,list,text,enc); + + output_simple_chars(config,list,"",enc); + if (layout->super_sub != psiconv_normalscript) + output_simple_chars(config,list, + layout->super_sub == psiconv_superscript?"": + layout->super_sub == psiconv_subscript?"": + "",enc); + if (layout->bold) + output_simple_chars(config,list,"
",enc); + if (layout->italic) + output_simple_chars(config,list,"
",enc); } -int psiconv_gen_html(const char * filename,const psiconv_file file, - const char *dest, const psiconv_encoding encoding_type) +void paragraph(const psiconv_config config, psiconv_list list, + psiconv_paragraph para,output_type type, + const encoding enc) { - FILE *of = fopen(filename,"w"); - if (! of) - return -1; + char tempstr[TEMPSTR_LEN]; + int i,charnr; + psiconv_string_t text; + psiconv_in_line_layout layout; + + output_simple_chars(config,list,"

base_paragraph->back_color,type,enc); + output_simple_chars(config,list,";",enc); + + output_simple_chars(config,list,"padding-left:",enc); + snprintf(tempstr,TEMPSTR_LEN,"%f",para->base_paragraph->indent_left); + output_simple_chars(config,list,tempstr,enc); + output_simple_chars(config,list,"cm;",enc); + + output_simple_chars(config,list,"padding-right:",enc); + snprintf(tempstr,TEMPSTR_LEN,"%f",para->base_paragraph->indent_right); + output_simple_chars(config,list,tempstr,enc); + output_simple_chars(config,list,"cm;",enc); + + output_simple_chars(config,list,"text-indent:",enc); + snprintf(tempstr,TEMPSTR_LEN,"%f",para->base_paragraph->indent_left - para->base_paragraph->indent_first); + output_simple_chars(config,list,tempstr,enc); + output_simple_chars(config,list,"cm;",enc); + + output_simple_chars(config,list,"text-align:",enc); + output_simple_chars(config,list,para->base_paragraph->justify_hor==psiconv_justify_left?"left": + para->base_paragraph->justify_hor==psiconv_justify_centre?"center": + para->base_paragraph->justify_hor==psiconv_justify_right?"right": + para->base_paragraph->justify_hor==psiconv_justify_full?"justify": + "",enc); + output_simple_chars(config,list,";",enc); + + + output_simple_chars(config,list,"line-height:",enc); + snprintf(tempstr,TEMPSTR_LEN,"%f",para->base_paragraph->linespacing); + output_simple_chars(config,list,tempstr,enc); + output_simple_chars(config,list,"pt;",enc); + + output_simple_chars(config,list,"padding-top:",enc); + snprintf(tempstr,TEMPSTR_LEN,"%f",para->base_paragraph->space_above); + output_simple_chars(config,list,tempstr,enc); + output_simple_chars(config,list,"pt;",enc); + + output_simple_chars(config,list,"padding-bottom:",enc); + snprintf(tempstr,TEMPSTR_LEN,"%f",para->base_paragraph->space_below); + output_simple_chars(config,list,tempstr,enc); + output_simple_chars(config,list,"pt;",enc); + + output_simple_chars(config,list,"\">",enc); - encoding = encoding_type; - - if (file->type == psiconv_word_file) { - psiconv_gen_html_word(of,(psiconv_word_f) file->file); - } else if (file->type == psiconv_texted_file) { - psiconv_gen_html_texted(of,(psiconv_texted_f) file->file); + if (psiconv_list_length(para->in_lines) == 0) { + charlayout(config,list,para->text,para->base_character,type,enc); } else { - fclose(of); - return -1; + charnr = 0; + for (i = 0; i < psiconv_list_length(para->in_lines); i++) { + if (!(layout = psiconv_list_get(para->in_lines,i))) { + fputs("Internal data structures corruption\n",stderr); + exit(1); + } + if (!(text = malloc(sizeof (*text) * (layout->length + 1)))) { + fputs("Out of memory error\n",stderr); + exit(1); + } + memcpy(text,para->text+charnr,layout->length * sizeof(*text)); + text[layout->length] = 0; + charlayout(config,list,text,layout->layout,type,enc); + free(text); + charnr += layout->length; + } } - return fclose(of); + output_simple_chars(config,list,"

\n",enc); } -void psiconv_gen_html_texted(FILE *of,psiconv_texted_f tf) +void paragraphs(const psiconv_config config, psiconv_list list, + psiconv_text_and_layout paragraphs,output_type type, + const encoding enc) { - psiconv_character_layout base_char; - psiconv_paragraph para; int i; - - /* We have nothing better */ - base_char = psiconv_basic_character_layout(); - - fputs("", of); - fputs("\n\n\n \n", of); - - fputs(" \n", of); +} - fputs("\n",of); - fputs("\n",of); - for (i = 0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) { - para = psiconv_list_get(tf->texted_sec->paragraphs,i); - gen_para(of,para,base_char); - } - fputs("\n\n",of); - psiconv_free_character_layout(base_char); +void gen_html_word(const psiconv_config config, psiconv_list list, + const psiconv_word_f file, output_type type, + const encoding enc) +{ + if (!file) + return; + + header(config,list,type,enc); + paragraphs(config,list,file->paragraphs,type,enc); + footer(config,list,type,enc); } -void psiconv_gen_html_word(FILE *of,psiconv_word_f wf) +void gen_html_texted(const psiconv_config config, psiconv_list list, + const psiconv_texted_f file, output_type type, + const encoding enc) { - int i; - psiconv_paragraph para; - psiconv_color white,black; - psiconv_character_layout base_char; + header(config,list,type,enc); + paragraphs(config,list,file->texted_sec->paragraphs,type,enc); + footer(config,list,type,enc); +} + +int gen_html(const psiconv_config config, psiconv_list list, + const psiconv_file file, const char *dest, + const encoding enc) +{ + output_type type; + + if (!strcmp("HTML4",dest)) + type = output_html; + else if (!strcmp("XHTML",dest)) + type = output_xhtml; + else + return -1; - white = malloc(sizeof(*white)); - black = malloc(sizeof(*black)); - white->red = 0x00; - white->green = 0x00; - white->blue = 0x00; - black->red = 0xff; - black->green = 0xff; - black->blue = 0xff; - - /* To keep from generating a font desc for each line */ - base_char = gen_base_char(wf->styles_sec->normal->character->font, - black,white); - - psiconv_free_color(black); - psiconv_free_color(white); - - fputs("", of); - fputs("\n\n\n \n", of); - - fputs(" \n", of); - - fputs("\n",of); - fputs("\n",of); - - for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { - para = psiconv_list_get(wf->paragraphs,i); - gen_para(of,para,base_char); + if (enc == ENCODING_PSION) { + fputs("Unsupported encoding\n",stderr); + return -1; } - fputs("\n\n",of); - psiconv_free_character_layout(base_char); + + if (file->type == psiconv_word_file) { + gen_html_word(config,list,(psiconv_word_f) file->file,type,enc); + return 0; + } else if (file->type == psiconv_texted_file) { + gen_html_texted(config,list,(psiconv_texted_f) file->file,type, enc); + return 0; + } else + return -1; } + -static struct psiconv_fileformat_s ff = +static struct fileformat_s ffs[] = { - "HTML3", - "HTML 3.2, not verified so probably not completely compliant", - &psiconv_gen_html + { + "XHTML", + "XHTML 1.0 Strict, using CSS for formatting", + gen_html + }, + { + "HTML4", + "HTML 4.01 Strict, using CSS for formatting", + gen_html + }, + { + NULL, + NULL, + NULL + } }; + void init_html(void) { - psiconv_list_add(fileformat_list,&ff); + int i; + for (i = 0; ffs[i].name; i++) + psiconv_list_add(fileformat_list,ffs+i); }