--- psiconv/trunk/program/psiconv/gen_html4.c 1999/10/11 19:17:17 14
+++ psiconv/trunk/program/psiconv/gen_html4.c 2004/02/02 21:56:48 193
@@ -1,494 +1,290 @@
-/*
- * gen_html4.c - Part of psiconv, a PSION 5 data formats converter
- * Copyright (c) 1999 Andrew Johnson 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 ",
- char_table[base_para->bullet->character]);
- wasspace = TRUE;
- }
-
- loc = 0;
+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);
+static int gen_html4(const psiconv_config config, psiconv_list list,
+ const psiconv_file file, const char *dest,
+ 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,"
\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 */ "ø", "ù", "ú", "û",
- "ü", "ý", "þ", "ÿ"
-};
-
-/* 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);
-}
-
-static void fput_text(FILE * of, const char *text, int length, int *pwasspace) {
- int j;
- int space;
-
- for (j = 0; j < length; j++) {
- space = (text[j] == ' ');
- if (*pwasspace && space)
- fputs(" ", of);
- else
- fputs(char_table[(unsigned char) (text[j])], of);
- *pwasspace = space;
- }
-}
-
-static const char *screenfont_name(psiconv_u8 screenfont)
-{
- if (screenfont == 1)
- return "sans-serif";
- else if (screenfont == 2)
- return "monospace";
- else if (screenfont == 3)
- 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));
-}
+#define TEMPSTR_LEN 100
-
-/* 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);
- }
-}
-
-/* Paragraph formats */
-static int paragraph_layouts_different(
- const psiconv_paragraph_layout old,
- const psiconv_paragraph_layout new)
-{
- return ((old->top_space != new->top_space) ||
- (old->indent_right != new->indent_right) ||
- (old->bottom_space != new->bottom_space) ||
- (old->indent_left != new->indent_left) ||
- (old->indent_first != new->indent_first) ||
- (old->justify_hor != new->justify_hor) ||
- (old->interline_exact != new->interline_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));
-}
-
-static void fput_paragraph_layout(FILE * of,
- 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->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->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->interline_exact != new->interline_exact)) {
- if (!old || old->interline_exact)
- fputs("line-height:normal;", of);
- else
- fprintf(of, "line-height:%.1fpt;", new->interline);
- }
- 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);
-}
-
-/* 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->strike_out != new->strike_out));
-}
-
-static void fput_character_layout(FILE * of,
- const psiconv_character_layout old,
- const psiconv_character_layout new,
- psiconv_word_f wf)
-{
- 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->strike_out != new->strike_out)) {
- fputs("text-decoration:", of);
- if (new->strike_out)
- fputs("line-through ", of);
- if (new->underline)
- fputs("underline", of);
- else if (!new->strike_out)
- fputs("none", of);
- fputs(";", of);
- }
-}
-
-
-/* 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;
-
- layout_stack = calloc(psiconv_list_length(para->in_lines),
- sizeof(*layout_stack));
- fputs("
",enc);
+ else if ((data[i] == 0x0b) || (data[i] == 0x0c))
+ output_simple_chars(config,list,"-",enc);
+ else if ((data[i] == 0x0f) || (data[i] == 0x09) || (data[i] == 0x0a))
+ 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,"",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?"