","
" ,
- /* 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(" 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);
- 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("
",of);
-
- fputs("
",of);
-
- flags |= 2;
- diff_char(of,cur_char,base_char,&flags);
-
- if (para->base_paragraph->bullet->on)
- fputs("
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); }