--- psiconv/trunk/program/psiconv/gen_html4.c 2002/05/10 15:55:55 147 +++ psiconv/trunk/program/psiconv/gen_html4.c 2004/02/02 20:43:04 192 @@ -1,592 +1,287 @@ -/* - * gen_html4.c - Part of psiconv, a PSION 5 data formats converter - * Copyright (c) 1999 Andrew Johnson - * Portions Copyright (c) 1999 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. +/* 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. */ #include "config.h" -#include + +#include +#include +#include "general.h" + #include -#include #include -#include "psiconv/data.h" -#include "psiconv/list.h" -#include "gen.h" -#include "psiconv.h" - -#ifndef TRUE -#define TRUE (0==0) -#endif #ifdef DMALLOC #include "dmalloc.h" #endif -/* - * Various string tables for HTML4 settings - */ - -/* How to display each character */ -static const char *char_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 */ "", "", "‚", "ƒ", - "„", "…", "†", "‡", - /* 0x88 */ "ˆ", "‰", "Š", "<", - "Œ", "", "", "", - /* 0x90 */ "", "‘", "’", "“", - "”","•", "–", "—", - /* 0x98 */ "˜", "™", "š", ">", - "œ", "", "", "Ÿ", - /* 0xa0 */ " ", "¡", "¢", "£", - "¤", "¥", "¦", "§", - /* 0xa8 */ "¨", "©", "ª", "«", - "¬", "­", "®", "¯", - /* 0xb0 */ "°", "±", "²", "³", - "´", "µ", "¶", "·", - /* 0xb8 */ "¸", "¹", "º", "»", - "¼", "½", "¾", "¿", - /* 0xc0 */ "À", "Á", "Â", "Ã", - "Ä", "Å", "Æ", "Ç", - /* 0xc8 */ "È", "É", "Ê", "Ë", - "Ì", "Í", "Î", "Ï", - /* 0xd0 */ "Ð", "Ñ", "Ò", "Ó", - "Ô", "Õ", "Ö", "×", - /* 0xd8 */ "Ø", "Ù", "Ú", "Û", - "Ü", "Ý", "Þ", "ß", - /* 0xe0 */ "à", "á", "â", "ã", - "ä", "å", "æ", "ç", - /* 0xe8 */ "è", "é", "ê", "ë", - "ì", "í", "î", "ï", - /* 0xf0 */ "ð", "ñ", "ò", "ó", - "ô", "õ", "ö", "÷", - /* 0xf8 */ "ø", "ù", "ú", "û", - "ü", "ý", "þ", "ÿ" -}; - -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" -}; - -/* The order of these must match the enum psiconv_justify (data.h) */ -static const char *justify_strings[] = { - "left", "center", "right", "justify" -}; - -/* The order of these must match the enum psiconv_super_sub (data.h) */ -static const char *vertical_strings[] = { - "baseline", "super", "sub" -}; - - -/* - * Support routines for particular formatting structures - */ - -static void fput_name(FILE * of, const char *string) { - int i; - - for (i = 0; i < strlen(string); i++) - if (isalnum(string[i])) - putc(string[i], of); -} +#define TEMPSTR_LEN 100 -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(table[(unsigned char) (text[j])], of); - *pwasspace = space; +static void text(const psiconv_config config,psiconv_list list, + psiconv_string_t data,const encoding enc); +static void header(const psiconv_config config, psiconv_list list, + const encoding enc); +static void footer(const psiconv_config config, psiconv_list list, + const encoding enc); +static void characters(const psiconv_config config, psiconv_list list, + const psiconv_string_t textstr, + const psiconv_character_layout layout,const encoding enc); +static void paragraph(const psiconv_config config, psiconv_list list, + psiconv_paragraph para, const encoding enc); +static void paragraphs(const psiconv_config config, psiconv_list list, + psiconv_text_and_layout paragraphs, const encoding enc); +static void gen_word(const psiconv_config config, psiconv_list list, + const psiconv_word_f file, const encoding enc); +static void gen_texted(const psiconv_config config, psiconv_list list, + const psiconv_texted_f file, const encoding enc); + + +void text(const psiconv_config config,psiconv_list list, + psiconv_string_t data,const encoding enc) +{ + int i; + for (i = 0; i < psiconv_unicode_strlen(data); i++) { + if ((data[i] == 0x06) || (data[i] == 0x07) || (data[i] == 0x08)) + output_simple_chars(config,list,"
",enc); + else if ((data[i] == 0x0b) || (data[i] == 0x0c)) + output_simple_chars(config,list,"-",enc); + else if (data[i] == 0x0f) + output_simple_chars(config,list," ",enc); + else if (data[i] >= 0x20) + output_char(config,list,data[i],enc); + } +} + +void header(const psiconv_config config, psiconv_list list, const encoding 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,"\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); +} + +void footer(const psiconv_config config, psiconv_list list, const encoding enc) +{ + output_simple_chars(config,list,"\n",enc); + output_simple_chars(config,list,"\n",enc); +} + + +void characters(const psiconv_config config, psiconv_list list, + const psiconv_string_t textstr, + const psiconv_character_layout layout,const encoding enc) +{ + char tempstr[TEMPSTR_LEN]; + + output_simple_chars(config,list,"font->screenfont == psiconv_font_serif?"serif": + layout->font->screenfont == psiconv_font_sansserif?"sans-serif": + layout->font->screenfont == psiconv_font_nonprop?"monospace": + layout->font->screenfont == psiconv_font_misc?"fantasy":"", + enc); + output_simple_chars(config,list,"\"",enc); + + if ((layout->font_size < 10) || (layout->font_size >= 13)) { + output_simple_chars(config,list," size=",enc); + output_simple_chars(config,list, + layout->font_size < 8 ?"1": + layout->font_size < 10 ?"2": + layout->font_size < 13 ?"3": + layout->font_size < 17 ?"4": + layout->font_size < 24 ?"5": + layout->font_size < 36 ?"6":"7",enc); + } + if ((layout->color->red != 0) || (layout->color->green != 0) || + (layout->color->blue != 0)) { + snprintf(tempstr,TEMPSTR_LEN,"%02x%02x%02x", + layout->color->red,layout->color->green,layout->color->blue); + output_simple_chars(config,list," color=#",enc); + output_simple_chars(config,list,tempstr,enc); + } + output_simple_chars(config,list,">",enc); + + + 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); + if (layout->strikethrough) + output_simple_chars(config,list,"",enc); + if (layout->underline) + output_simple_chars(config,list,"",enc); + + text(config,list,textstr,enc); + + if (layout->underline) + output_simple_chars(config,list,"",enc); + if (layout->strikethrough) + 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); + output_simple_chars(config,list,"",enc); +} + +void paragraph(const psiconv_config config, psiconv_list list, + psiconv_paragraph para, const encoding enc) +{ + int i,charnr; + psiconv_string_t text; + psiconv_in_line_layout layout; + + + output_simple_chars(config,list, + para->base_paragraph->bullet->on?"
    base_paragraph->justify_hor == psiconv_justify_centre) + output_simple_chars(config,list," align=center",enc); + else if (para->base_paragraph->justify_hor == psiconv_justify_right) + output_simple_chars(config,list," align=right",enc); + else if (para->base_paragraph->justify_hor == psiconv_justify_full) + output_simple_chars(config,list," align=justify",enc); + + output_simple_chars(config,list,">",enc); + + if (psiconv_list_length(para->in_lines) == 0) { + characters(config,list,para->text,para->base_character,enc); + } else { + 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; + characters(config,list,text,layout->layout,enc); + free(text); + charnr += layout->length; } + } + output_simple_chars(config, list, + para->base_paragraph->bullet->on?"
\n":"\n",enc); } -static const char *screenfont_name(psiconv_u8 screenfont) +void paragraphs(const psiconv_config config, psiconv_list list, + psiconv_text_and_layout paragraphs, const encoding enc) { - if (screenfont == psiconv_font_sansserif) - return "sans-serif"; - else if (screenfont == psiconv_font_nonprop) - return "monospace"; - else if (screenfont == psiconv_font_serif) - return "serif"; - else - return "serif"; -} - -static const char *generic_font_family(const char *font_name) { - static const char *sans_font_names[] = { - "Arial", "Univers", "Sans Serif" - }; - static const char *mono_font_names[] = { - "Courier New", "Courier", "Mono", "Lineprinter", "Elite", "Swiss", - "Courier (compressed)", "Courier (expanded)", "Letter Gothic" - }; - int i; - - for (i=0; i < sizeof(sans_font_names) / sizeof(sans_font_names[0]); i++) - if (!strcmp(font_name, sans_font_names[i])) - return "sans-serif"; - - for (i=0; i < sizeof(mono_font_names) / sizeof(mono_font_names[0]); i++) - if (!strcmp(font_name, mono_font_names[i])) - return "monospace"; - - return "serif"; -} - -static int colors_different( - const psiconv_color old, - const psiconv_color new) -{ - return ((old->red != new->red) || - (old->green != new->green) || - (old->blue != new->blue)); -} - - -/* Borders */ -static int borders_different( - const psiconv_border old, - const psiconv_border new) -{ - return (!old || - (old->kind != new->kind) || - colors_different(old->color, new->color) || - (old->thickness != new->thickness)); -} - -static void fput_border(FILE * of, - const char *which, - const psiconv_border old, - const psiconv_border new) -{ - /* If the border changed at all we'll set all parameters, as they're - * fairly closely linked and it's much easier to do it this way */ - if (borders_different(old, new)) { - fprintf(of, "border-%s-style:%s;", - which, border_strings[new->kind]); - if ((new->kind != psiconv_border_none) && - (new->color->red || new->color->green || new->color->blue)) - fprintf(of, "border-%s-color:#%02x%02x%02x;", which, - new->color->red, new->color->green, new->color->blue); - if ((new->kind == psiconv_border_solid) || - (new->kind == psiconv_border_double)) - fprintf(of, "border-%s-width:%.0fpx;", - which, (new->thickness / 10.0) - 1); - else if (new->kind != psiconv_border_none) - fprintf(of, "border-%s-width:1px;", which); + 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,enc); + } } -/* Paragraph formats */ -static int paragraph_layouts_different( - const psiconv_paragraph_layout old, - const psiconv_paragraph_layout new) +void gen_word(const psiconv_config config, psiconv_list list, + const psiconv_word_f file, const encoding enc) { - return ((old->space_above != new->space_above) || - (old->indent_right != new->indent_right) || - (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->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) || - borders_different(old->bottom_border, new->bottom_border)); -} + if (!file) + return; -static void fput_paragraph_layout(FILE * of, - const psiconv_paragraph_layout old, - const psiconv_paragraph_layout new) -{ - 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->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) || - (old->indent_left != new->indent_left) || - (old->indent_first != new->indent_first)) { - psiconv_length_t indent = new->indent_first; - psiconv_length_t margin = new->indent_left; - /* Bullets with indent set cause strange margin behaviour: */ - if (new->bullet->on && new->bullet->indent) { - if (indent > 0.0) { - margin += indent; - indent = new->indent_left - indent; - } - } - fprintf(of, "margin-left:%.2fcm;", margin); - fprintf(of, "text-indent:%.2fcm;", indent); - } - if (!old || (old->justify_hor != new->justify_hor)) - fprintf(of, "text-align:%s;", justify_strings[new->justify_hor]); - 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->linespacing); - } - fput_border(of, "left", old ? old->left_border : NULL, - new->left_border); - fput_border(of, "right", old ? old->right_border : NULL, - new->right_border); - fput_border(of, "top", old ? old->top_border : NULL, - new->top_border); - fput_border(of, "bottom", old ? old->bottom_border : NULL, - new->bottom_border); + header(config,list,enc); + paragraphs(config,list,file->paragraphs,enc); + footer(config,list,enc); } -/* Character formats */ -static int character_layouts_different( - const psiconv_character_layout old, - const psiconv_character_layout new) -{ - return ((old->font->screenfont != new->font->screenfont) || - (strcmp(old->font->name,new->font->name)) || - (old->font_size != new->font_size) || - (old->color->red != new->color->red) || - (old->color->green != new->color->green) || - (old->color->blue != new->color->blue) || - (old->back_color->red != new->back_color->red) || - (old->back_color->green != new->back_color->green) || - (old->back_color->blue != new->back_color->blue) || - (old->italic != new->italic) || - (old->bold != new->bold) || - (old->super_sub != new->super_sub) || - (old->underline != new->underline) || - (old->strikethrough != new->strikethrough)); -} -static void fput_character_layout(FILE * of, - const psiconv_character_layout old, - const psiconv_character_layout new, - psiconv_word_f wf) +void gen_texted(const psiconv_config config, psiconv_list list, + const psiconv_texted_f file, const encoding enc) { - if (!old || (old->font->screenfont != new->font->screenfont) || - strcmp(old->font->name,new->font->name)) { - fprintf(of, "font-family:%s,%s,%s;", new->font->name, - generic_font_family(new->font->name), - screenfont_name(new->font->screenfont)); - } - if (!old || (old->font_size != new->font_size)) - fprintf(of, "font-size:%.1f%%;", 100.0 * new->font_size / 10.0); - if (!old || (old->bold != new->bold)) - fprintf(of, "font-weight:%s;", new->bold ? "bold" : "normal"); - if (!old || (old->italic != new->italic)) - fprintf(of, "font-style:%s;", new->italic ? "italic" : "normal"); - if (!old || (colors_different(old->color, new->color))) - fprintf(of, "color:#%02x%02x%02x;", - new->color->red, new->color->green, new->color->blue); - if (!old || (colors_different(old->back_color, new->back_color))) - fprintf(of, "background-color:#%02x%02x%02x;", - new->back_color->red, new->back_color->green, new->back_color->blue); - 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->strikethrough != new->strikethrough)) { - fputs("text-decoration:", of); - if (new->strikethrough) - fputs("line-through ", of); - if (new->underline) - fputs("underline", of); - else if (!new->strikethrough) - fputs("none", of); - fputs(";", of); - } + header(config,list,enc); + paragraphs(config,list,file->texted_sec->paragraphs,enc); + footer(config,list,enc); } - -/* Formatted paragraphs */ -static void fput_para(FILE * of, - const psiconv_paragraph para, - psiconv_word_f wf) -{ - psiconv_paragraph_layout base_para = para->base_paragraph; - psiconv_character_layout base_char = para->base_character; - psiconv_character_layout cur_char; - psiconv_character_layout *layout_stack; - psiconv_in_line_layout inl; - psiconv_word_style sty; - 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)); - fputs("styles_sec, para->base_style); - cur_char = sty->character; - - if (sty->name) { - fputs(" CLASS=\"", of); - fput_name(of, sty->name); - putc('"', of); - } - - if (paragraph_layouts_different(sty->paragraph, base_para) || - character_layouts_different(cur_char, base_char)) { - fputs(" STYLE=\"", of); - fput_paragraph_layout(of, sty->paragraph, base_para); - fput_character_layout(of, cur_char, base_char, wf); - cur_char = base_char; - putc('"', of); - } - putc('>', of); - - if (base_para->bullet->on) { - fputs("bullet->font != base_char->font) { - fprintf(of, "font-family:%s,%s,%s;", - base_para->bullet->font->name, - generic_font_family(base_para->bullet->font->name), - screenfont_name(base_para->bullet->font->screenfont)); - } - if (base_para->bullet->font_size != base_char->font_size) - fprintf(of, "font-size:%.1f%%;", - 100.0 * base_para->bullet->font_size / 10.0); - if ((base_para->bullet->color->red != base_char->color->red) || - (base_para->bullet->color->green != base_char->color->green) || - (base_para->bullet->color->blue != base_char->color->blue)) - fprintf(of, "color:#%02x%02x%02x;", - base_para->bullet->color->red, - base_para->bullet->color->green, - base_para->bullet->color->blue); - fprintf(of, "\">%s ", - table[base_para->bullet->character]); - wasspace = TRUE; - } - - loc = 0; - for (i = 0; i < psiconv_list_length(para->in_lines); i++) { - inl = psiconv_list_get(para->in_lines, i); - if (character_layouts_different(cur_char, inl->layout)) { - for (j = 0; j < spans; j++) - if (!character_layouts_different(inl->layout, layout_stack[j])) - break; - if (j < spans) { - while (spans > j) { - fputs("",of); - spans--; - } - } else { - fputs("layout, wf); - fputs("\">",of); - layout_stack[spans++] = cur_char; - } - cur_char = inl->layout; - } - fput_text(of, ¶->text[loc], inl->length, &wasspace); - loc += inl->length; - } - - while (spans > 0) { - fputs("",of); - spans--; - } - - if (loc < strlen(para->text)) { - fput_text(of, ¶->text[loc], strlen(para->text) - loc, &wasspace); - } - - if (strlen(para->text) == 0) - fputs(" ", of); - - fputs("

\n", of); - free(layout_stack); -} - -static void fput_style(FILE * of, - const psiconv_word_style normal, - const psiconv_word_style sty, - psiconv_word_f wf) +int gen_html4(const psiconv_config config, psiconv_list list, + const psiconv_file file, const char *dest, + const encoding enc) { - if (sty->name == NULL) - fputs(" P {", of); - else { - fputs(" P.", of); - fput_name(of, sty->name); - fputs(" {", of); - } - fput_paragraph_layout(of, normal ? normal->paragraph : NULL, sty->paragraph); - fput_character_layout(of, normal ? normal->character : NULL, sty->character, wf); - fputs("}\n", of); -} + encoding enc1 = enc; -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(filename,file,dest,encoding_type); - } - - if (! (of = fopen(filename,"w"))) - return -1; + if (enc == ENCODING_PSION) { + fputs("Unsupported encoding\n",stderr); + return -1; + } else if (enc == ENCODING_ASCII) + enc1 = ENCODING_ASCII_HTML; - fputs("", of); - fputs("\n\n\n \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; - fputs(" \n\n\n", of); - 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 fclose(of); + if (file->type == psiconv_word_file) { + gen_word(config,list,(psiconv_word_f) file->file,enc1); + return 0; + } else if (file->type == psiconv_texted_file) { + gen_texted(config,list,(psiconv_texted_f) file->file,enc1); + return 0; + } else + return -1; } + -static struct psiconv_fileformat_s ff = +static struct fileformat_s ffs[] = { - "HTML4", - "HTML 4.0 with cascading style sheets", - psiconv_gen_html4 + { + "HTML4", + "HTML 4.01 Transitional, without CSS", + FORMAT_WORD | FORMAT_TEXTED, + gen_html4 + }, + { + NULL, + NULL, + 0, + NULL + } }; + void init_html4(void) { - psiconv_list_add(fileformat_list,&ff); + int i; + for (i = 0; ffs[i].name; i++) + psiconv_list_add(fileformat_list,ffs+i); } -