--- psiconv/trunk/program/psiconv/gen_html4.c 1999/12/02 17:18:55 34 +++ psiconv/trunk/program/psiconv/gen_html4.c 2002/05/10 15:55:55 147 @@ -18,13 +18,25 @@ * 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 -#include "data.h" -#include "list.h" +#include "psiconv/data.h" +#include "psiconv/list.h" #include "gen.h" #include "psiconv.h" @@ -32,6 +44,10 @@ #define TRUE (0==0) #endif +#ifdef DMALLOC +#include "dmalloc.h" +#endif + /* * Various string tables for HTML4 settings */ @@ -88,6 +104,45 @@ "ü", "ý", "þ", "ÿ" }; +static const char *utf_table[0x100] = { + /* 0x00 */ "", "", "", "", "", "", "
\n", "
\n", + /* 0x08 */ "\n
\n", "\t", "", "", "", "", "", "", + /* 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; + + /* The order of these must match the enum psiconv_border_kind (data.h) */ static const char *border_strings[] = { "none", "solid", "double", "dotted", "dashed", "dashed", "dotted" @@ -119,24 +174,30 @@ static void fput_text(FILE * of, const char *text, int length, int *pwasspace) { int j; int space; + char ** table; + if (encoding == PSICONV_ENCODING_UTF8){ + table = (char**) utf_table; + }else{ + table=(char**) char_table; + } for (j = 0; j < length; j++) { space = (text[j] == ' '); if (*pwasspace && space) fputs(" ", of); else - fputs(char_table[(unsigned char) (text[j])], of); + fputs(table[(unsigned char) (text[j])], of); *pwasspace = space; } } static const char *screenfont_name(psiconv_u8 screenfont) { - if (screenfont == 1) + if (screenfont == psiconv_font_sansserif) return "sans-serif"; - else if (screenfont == 2) + else if (screenfont == psiconv_font_nonprop) return "monospace"; - else if (screenfont == 3) + else if (screenfont == psiconv_font_serif) return "serif"; else return "serif"; @@ -212,13 +273,13 @@ const psiconv_paragraph_layout old, const psiconv_paragraph_layout new) { - return ((old->top_space != new->top_space) || + return ((old->space_above != new->space_above) || (old->indent_right != new->indent_right) || - (old->bottom_space != new->bottom_space) || + (old->space_below != new->space_below) || (old->indent_left != new->indent_left) || (old->indent_first != new->indent_first) || (old->justify_hor != new->justify_hor) || - (old->interline_exact != new->interline_exact) || + (old->linespacing_exact != new->linespacing_exact) || borders_different(old->left_border, new->left_border) || borders_different(old->right_border, new->right_border) || borders_different(old->top_border, new->top_border) || @@ -229,12 +290,12 @@ const psiconv_paragraph_layout old, const psiconv_paragraph_layout new) { - if (!old || (old->top_space != new->top_space)) - fprintf(of, "margin-top:%.1fpt;", new->top_space); + if (!old || (old->space_above != new->space_above)) + fprintf(of, "margin-top:%.1fpt;", new->space_above); if (!old || (old->indent_right != new->indent_right)) fprintf(of, "margin-right:%.2fcm;", new->indent_right); - if (!old || (old->bottom_space != new->bottom_space)) - fprintf(of, "margin-bottom:%.1fpt;", new->bottom_space); + if (!old || (old->space_below != new->space_below)) + fprintf(of, "margin-bottom:%.1fpt;", new->space_below); if (!old || (old->bullet->on != new->bullet->on) || (old->bullet->indent != new->bullet->indent) || @@ -254,11 +315,11 @@ } if (!old || (old->justify_hor != new->justify_hor)) fprintf(of, "text-align:%s;", justify_strings[new->justify_hor]); - if (!old || (old->interline_exact != new->interline_exact)) { - if (!old || old->interline_exact) + if (!old || (old->linespacing_exact != new->linespacing_exact)) { + if (!old || old->linespacing_exact) fputs("line-height:normal;", of); else - fprintf(of, "line-height:%.1fpt;", new->interline); + fprintf(of, "line-height:%.1fpt;", new->linespacing); } fput_border(of, "left", old ? old->left_border : NULL, new->left_border); @@ -288,7 +349,7 @@ (old->bold != new->bold) || (old->super_sub != new->super_sub) || (old->underline != new->underline) || - (old->strike_out != new->strike_out)); + (old->strikethrough != new->strikethrough)); } static void fput_character_layout(FILE * of, @@ -317,13 +378,13 @@ if (!old || (old->super_sub != new->super_sub)) fprintf(of, "vertical-align:%s;", vertical_strings[new->super_sub]); if (!old || (old->underline != new->underline) || - (old->strike_out != new->strike_out)) { + (old->strikethrough != new->strikethrough)) { fputs("text-decoration:", of); - if (new->strike_out) + if (new->strikethrough) fputs("line-through ", of); if (new->underline) fputs("underline", of); - else if (!new->strike_out) + else if (!new->strikethrough) fputs("none", of); fputs(";", of); } @@ -344,6 +405,13 @@ int spans = 0; int wasspace = 0; int i, j, loc; + char ** table; + + if (encoding == PSICONV_ENCODING_UTF8){ + table= (char**) utf_table; + }else{ + table= (char**) char_table; + } layout_stack = calloc(psiconv_list_length(para->in_lines), sizeof(*layout_stack)); @@ -386,7 +454,7 @@ base_para->bullet->color->green, base_para->bullet->color->blue); fprintf(of, "\">%s ", - char_table[base_para->bullet->character]); + table[base_para->bullet->character]); wasspace = TRUE; } @@ -447,31 +515,44 @@ fputs("}\n", of); } -static int psiconv_gen_html4(FILE * of, const psiconv_file file, - const char *dest) +static int psiconv_gen_html4(const char *filename, const psiconv_file file, + const char *dest, const psiconv_encoding encoding_type) { + FILE * of; int i; psiconv_paragraph para; psiconv_word_style normal, sty; psiconv_word_f wf; + + encoding=encoding_type; if (file->type == psiconv_word_file) wf = file->file; else { /* Fall back on the normal HTML generator */ - return psiconv_gen_html(of,file,dest); + return psiconv_gen_html(filename,file,dest,encoding_type); } + if (! (of = fopen(filename,"w"))) + return -1; + fputs("", of); fputs("\n\n\n \n", of); - - if (psiconv_list_length(wf->page_sec->header->text->paragraphs) > 0) { - fputs(" ", of); - para = psiconv_list_get(wf->page_sec->header->text->paragraphs, 0); - i = 0; - fput_text(of, para->text, strlen(para->text), &i); - fputs("\n", of); + + fputs(" \n", of); + + if (wf->page_sec->header->text) { + if (psiconv_list_length(wf->page_sec->header->text->paragraphs) > 0) { + fputs(" ", of); + para = psiconv_list_get(wf->page_sec->header->text->paragraphs, 0); + i = 0; + fput_text(of, para->text, strlen(para->text), &i); + fputs("\n", of); + } } normal = wf->styles_sec->normal; @@ -486,15 +567,18 @@ fput_style(of, normal, sty, wf); } fputs(" -->\n\n\n", of); - for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { - para = psiconv_list_get(wf->paragraphs, i); - fput_para(of, para, wf); + if (wf->page_sec->header->text) { + for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { + para = psiconv_list_get(wf->paragraphs, i); + fput_para(of, para, wf); + } } fputs("\n\n", of); - return 0; + + return fclose(of); } -static struct psiconv_fileformat ff = +static struct psiconv_fileformat_s ff = { "HTML4", "HTML 4.0 with cascading style sheets",