","
" ,
- /* 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 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);
-}
-/* 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);
- }
+#ifdef DMALLOC
+#include "dmalloc.h"
+#endif
+
+#define TEMPSTR_LEN 100
+
+typedef enum output_type_e { output_html, output_xhtml } output_type;
+
+void character_layout_diffs(const psiconv_config config, psiconv_list list,
+ const psiconv_character_layout new,
+ const psiconv_character_layout base,
+ const encoding enc)
+{
+ 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);
}
}
-void gen_para(FILE *of, const psiconv_paragraph para,
- const psiconv_character_layout base_char)
+void paragraph_layout_diffs(const psiconv_config config, psiconv_list list,
+ const psiconv_paragraph_layout new,
+ const psiconv_paragraph_layout base)
{
- int i,j,loc;
- psiconv_character_layout cur_char;
- psiconv_in_line_layout inl;
- int flags = 0;
-
-
- 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); - 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; + psiconv_paragraph para; + for (i = 0; i < psiconv_list_length(paragraphs); i++) { + if (!(para = psiconv_list_get(paragraphs,i))) { + fputs("Internal datastructure corruption\n",stderr); + exit(1); + } + paragraph(config,list,para,type,enc); + } +} - /* We have nothing better */ - base_char = psiconv_basic_character_layout(); +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; - fputs("", of); - fputs("\n\n\n \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); + 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); - - 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); }