/[public]/psiconv/trunk/program/psiconv/gen_html4.c
ViewVC logotype

Diff of /psiconv/trunk/program/psiconv/gen_html4.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 14 Revision 147
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 19 */
20 20
21/*
22 2002/Apr. Keita KAWABE
23 A: <META HTTP-EQUIV="Content-Type" CONTENT="text/html"> header
24 was added.
25
26 B: Support for narrow build Asian Psions added.
27 If the encoding_type is PSICONV_ENCODING_UTF8,
28 B-1: use utf8_table for character conversion.
29 B-2: add the "Charset=UTF-8" in the Content-Type header.
30 Otherwise proceed as normal.
31*/
32
21#include "config.h" 33#include "config.h"
22#include <stdio.h> 34#include <stdio.h>
23#include <string.h> 35#include <string.h>
24#include <ctype.h> 36#include <ctype.h>
25#include <stdlib.h> 37#include <stdlib.h>
26#include "data.h" 38#include "psiconv/data.h"
27#include "list.h" 39#include "psiconv/list.h"
28#include "gen.h" 40#include "gen.h"
41#include "psiconv.h"
29 42
30#ifndef TRUE 43#ifndef TRUE
31#define TRUE (0==0) 44#define TRUE (0==0)
45#endif
46
47#ifdef DMALLOC
48#include "dmalloc.h"
32#endif 49#endif
33 50
34/* 51/*
35 * Various string tables for HTML4 settings 52 * Various string tables for HTML4 settings
36 */ 53 */
85 "&ocirc;", "&otilde;", "&ouml;", "&divide;", 102 "&ocirc;", "&otilde;", "&ouml;", "&divide;",
86 /* 0xf8 */ "&oslash;", "&ugrave;", "&uacute;", "&ucirc;", 103 /* 0xf8 */ "&oslash;", "&ugrave;", "&uacute;", "&ucirc;",
87 "&uuml;", "&yacute;", "&thorn;", "&yuml;" 104 "&uuml;", "&yacute;", "&thorn;", "&yuml;"
88}; 105};
89 106
107static const char *utf_table[0x100] = {
108 /* 0x00 */ "", "", "", "", "", "", "<BR>\n", "<BR>\n",
109 /* 0x08 */ "\n<HR>\n", "\t", "", "", "", "", "", "",
110 /* 0x10 */ " ", "", "", "", "", "", "", "",
111 /* 0x18 */ "", "", "", "", "", "", "", "",
112 /* 0x20 */ " ", "!", "&quot;", "#", "$", "%", "&amp;", "'",
113 /* 0x28 */ "(", ")", "*", "+", ",", "-", ".", "/",
114 /* 0x30 */ "0", "1", "2", "3", "4", "5", "6", "7",
115 /* 0x38 */ "8", "9", ":", ";", "&lt;", "=", "&gt;", "?",
116 /* 0x40 */ "@", "A", "B", "C", "D", "E", "F", "G",
117 /* 0x48 */ "H", "I", "J", "K", "L", "M", "N", "O",
118 /* 0x50 */ "P", "Q", "R", "S", "T", "U", "V", "W",
119 /* 0x58 */ "X", "Y", "Z", "[", "\\", "]", "^", "_",
120 /* 0x60 */ "`", "a", "b", "c", "d", "e", "f", "g",
121 /* 0x68 */ "h", "i", "j", "k", "l", "m", "n", "o",
122 /* 0x70 */ "p", "q", "r", "s", "t", "u", "v", "w",
123 /* 0x78 */ "x", "y", "z", "{", "|", "}", "~", "",
124 /* 0x80 */ "\x80", "\x81", "\x82", "\x83", "\x84", "\x85", "\x86", "\x87",
125 /* 0x88 */ "\x88", "\x89", "\x8a", "\x8b", "\x8c", "\x8d", "\x8e", "\x8f",
126 /* 0x90 */ "\x90", "\x91", "\x92", "\x93", "\x94", "\x95", "\x96", "\x97",
127 /* 0x98 */ "\x98", "\x99", "\x9a", "\x9b", "\x9c", "\x9d", "\x9e", "\x9f",
128 /* 0xa0 */ "\xa0", "\xa1", "\xa2", "\xa3", "\xa4", "\xa5", "\xa6", "\xa7",
129 /* 0xa8 */ "\xa8", "\xa9", "\xaa", "\xab", "\xac", "\xad", "\xae", "\xaf",
130 /* 0xb0 */ "\xb0", "\xb1", "\xb2", "\xb3", "\xb4", "\xb5", "\xb6", "\xb7",
131 /* 0xb8 */ "\xb8", "\xb9", "\xba", "\xbb", "\xbc", "\xbd", "\xbe", "\xbf",
132 /* 0xc0 */ "\xc0", "\xc1", "\xc2", "\xc3", "\xc4", "\xc5", "\xc6", "\xc7",
133 /* 0xc8 */ "\xc8", "\xc9", "\xca", "\xcb", "\xcc", "\xcd", "\xce", "\xcf",
134 /* 0xd0 */ "\xd0", "\xd1", "\xd2", "\xd3", "\xd4", "\xd5", "\xd6", "\xd7",
135 /* 0xd8 */ "\xd8", "\xd9", "\xda", "\xdb", "\xdc", "\xdd", "\xde", "\xdf",
136 /* 0xe0 */ "\xe0", "\xe1", "\xe2", "\xe3", "\xe4", "\xe5", "\xe6", "\xe7",
137 /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef",
138 /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7",
139 /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff",
140};
141
142/* a flag to indicate the use of UTF8 */
143static psiconv_encoding encoding=PSICONV_ENCODING_CP1252;
144
145
90/* The order of these must match the enum psiconv_border_kind (data.h) */ 146/* The order of these must match the enum psiconv_border_kind (data.h) */
91static const char *border_strings[] = { 147static const char *border_strings[] = {
92 "none", "solid", "double", "dotted", "dashed", "dashed", "dotted" 148 "none", "solid", "double", "dotted", "dashed", "dashed", "dotted"
93}; 149};
94 150
116} 172}
117 173
118static void fput_text(FILE * of, const char *text, int length, int *pwasspace) { 174static void fput_text(FILE * of, const char *text, int length, int *pwasspace) {
119 int j; 175 int j;
120 int space; 176 int space;
177 char ** table;
178 if (encoding == PSICONV_ENCODING_UTF8){
179 table = (char**) utf_table;
180 }else{
181 table=(char**) char_table;
182 }
121 183
122 for (j = 0; j < length; j++) { 184 for (j = 0; j < length; j++) {
123 space = (text[j] == ' '); 185 space = (text[j] == ' ');
124 if (*pwasspace && space) 186 if (*pwasspace && space)
125 fputs("&nbsp;", of); 187 fputs("&nbsp;", of);
126 else 188 else
127 fputs(char_table[(unsigned char) (text[j])], of); 189 fputs(table[(unsigned char) (text[j])], of);
128 *pwasspace = space; 190 *pwasspace = space;
129 } 191 }
130} 192}
131 193
132static const char *screenfont_name(psiconv_u8 screenfont) 194static const char *screenfont_name(psiconv_u8 screenfont)
133{ 195{
134 if (screenfont == 1) 196 if (screenfont == psiconv_font_sansserif)
135 return "sans-serif"; 197 return "sans-serif";
136 else if (screenfont == 2) 198 else if (screenfont == psiconv_font_nonprop)
137 return "monospace"; 199 return "monospace";
138 else if (screenfont == 3) 200 else if (screenfont == psiconv_font_serif)
139 return "serif"; 201 return "serif";
140 else 202 else
141 return "serif"; 203 return "serif";
142} 204}
143 205
209/* Paragraph formats */ 271/* Paragraph formats */
210static int paragraph_layouts_different( 272static int paragraph_layouts_different(
211 const psiconv_paragraph_layout old, 273 const psiconv_paragraph_layout old,
212 const psiconv_paragraph_layout new) 274 const psiconv_paragraph_layout new)
213{ 275{
214 return ((old->top_space != new->top_space) || 276 return ((old->space_above != new->space_above) ||
215 (old->indent_right != new->indent_right) || 277 (old->indent_right != new->indent_right) ||
216 (old->bottom_space != new->bottom_space) || 278 (old->space_below != new->space_below) ||
217 (old->indent_left != new->indent_left) || 279 (old->indent_left != new->indent_left) ||
218 (old->indent_first != new->indent_first) || 280 (old->indent_first != new->indent_first) ||
219 (old->justify_hor != new->justify_hor) || 281 (old->justify_hor != new->justify_hor) ||
220 (old->interline_exact != new->interline_exact) || 282 (old->linespacing_exact != new->linespacing_exact) ||
221 borders_different(old->left_border, new->left_border) || 283 borders_different(old->left_border, new->left_border) ||
222 borders_different(old->right_border, new->right_border) || 284 borders_different(old->right_border, new->right_border) ||
223 borders_different(old->top_border, new->top_border) || 285 borders_different(old->top_border, new->top_border) ||
224 borders_different(old->bottom_border, new->bottom_border)); 286 borders_different(old->bottom_border, new->bottom_border));
225} 287}
226 288
227static void fput_paragraph_layout(FILE * of, 289static void fput_paragraph_layout(FILE * of,
228 const psiconv_paragraph_layout old, 290 const psiconv_paragraph_layout old,
229 const psiconv_paragraph_layout new) 291 const psiconv_paragraph_layout new)
230{ 292{
231 if (!old || (old->top_space != new->top_space)) 293 if (!old || (old->space_above != new->space_above))
232 fprintf(of, "margin-top:%.1fpt;", new->top_space); 294 fprintf(of, "margin-top:%.1fpt;", new->space_above);
233 if (!old || (old->indent_right != new->indent_right)) 295 if (!old || (old->indent_right != new->indent_right))
234 fprintf(of, "margin-right:%.2fcm;", new->indent_right); 296 fprintf(of, "margin-right:%.2fcm;", new->indent_right);
235 if (!old || (old->bottom_space != new->bottom_space)) 297 if (!old || (old->space_below != new->space_below))
236 fprintf(of, "margin-bottom:%.1fpt;", new->bottom_space); 298 fprintf(of, "margin-bottom:%.1fpt;", new->space_below);
237 if (!old || 299 if (!old ||
238 (old->bullet->on != new->bullet->on) || 300 (old->bullet->on != new->bullet->on) ||
239 (old->bullet->indent != new->bullet->indent) || 301 (old->bullet->indent != new->bullet->indent) ||
240 (old->indent_left != new->indent_left) || 302 (old->indent_left != new->indent_left) ||
241 (old->indent_first != new->indent_first)) { 303 (old->indent_first != new->indent_first)) {
251 fprintf(of, "margin-left:%.2fcm;", margin); 313 fprintf(of, "margin-left:%.2fcm;", margin);
252 fprintf(of, "text-indent:%.2fcm;", indent); 314 fprintf(of, "text-indent:%.2fcm;", indent);
253 } 315 }
254 if (!old || (old->justify_hor != new->justify_hor)) 316 if (!old || (old->justify_hor != new->justify_hor))
255 fprintf(of, "text-align:%s;", justify_strings[new->justify_hor]); 317 fprintf(of, "text-align:%s;", justify_strings[new->justify_hor]);
256 if (!old || (old->interline_exact != new->interline_exact)) { 318 if (!old || (old->linespacing_exact != new->linespacing_exact)) {
257 if (!old || old->interline_exact) 319 if (!old || old->linespacing_exact)
258 fputs("line-height:normal;", of); 320 fputs("line-height:normal;", of);
259 else 321 else
260 fprintf(of, "line-height:%.1fpt;", new->interline); 322 fprintf(of, "line-height:%.1fpt;", new->linespacing);
261 } 323 }
262 fput_border(of, "left", old ? old->left_border : NULL, 324 fput_border(of, "left", old ? old->left_border : NULL,
263 new->left_border); 325 new->left_border);
264 fput_border(of, "right", old ? old->right_border : NULL, 326 fput_border(of, "right", old ? old->right_border : NULL,
265 new->right_border); 327 new->right_border);
285 (old->back_color->blue != new->back_color->blue) || 347 (old->back_color->blue != new->back_color->blue) ||
286 (old->italic != new->italic) || 348 (old->italic != new->italic) ||
287 (old->bold != new->bold) || 349 (old->bold != new->bold) ||
288 (old->super_sub != new->super_sub) || 350 (old->super_sub != new->super_sub) ||
289 (old->underline != new->underline) || 351 (old->underline != new->underline) ||
290 (old->strike_out != new->strike_out)); 352 (old->strikethrough != new->strikethrough));
291} 353}
292 354
293static void fput_character_layout(FILE * of, 355static void fput_character_layout(FILE * of,
294 const psiconv_character_layout old, 356 const psiconv_character_layout old,
295 const psiconv_character_layout new, 357 const psiconv_character_layout new,
314 fprintf(of, "background-color:#%02x%02x%02x;", 376 fprintf(of, "background-color:#%02x%02x%02x;",
315 new->back_color->red, new->back_color->green, new->back_color->blue); 377 new->back_color->red, new->back_color->green, new->back_color->blue);
316 if (!old || (old->super_sub != new->super_sub)) 378 if (!old || (old->super_sub != new->super_sub))
317 fprintf(of, "vertical-align:%s;", vertical_strings[new->super_sub]); 379 fprintf(of, "vertical-align:%s;", vertical_strings[new->super_sub]);
318 if (!old || (old->underline != new->underline) || 380 if (!old || (old->underline != new->underline) ||
319 (old->strike_out != new->strike_out)) { 381 (old->strikethrough != new->strikethrough)) {
320 fputs("text-decoration:", of); 382 fputs("text-decoration:", of);
321 if (new->strike_out) 383 if (new->strikethrough)
322 fputs("line-through ", of); 384 fputs("line-through ", of);
323 if (new->underline) 385 if (new->underline)
324 fputs("underline", of); 386 fputs("underline", of);
325 else if (!new->strike_out) 387 else if (!new->strikethrough)
326 fputs("none", of); 388 fputs("none", of);
327 fputs(";", of); 389 fputs(";", of);
328 } 390 }
329} 391}
330 392
341 psiconv_in_line_layout inl; 403 psiconv_in_line_layout inl;
342 psiconv_word_style sty; 404 psiconv_word_style sty;
343 int spans = 0; 405 int spans = 0;
344 int wasspace = 0; 406 int wasspace = 0;
345 int i, j, loc; 407 int i, j, loc;
408 char ** table;
409
410 if (encoding == PSICONV_ENCODING_UTF8){
411 table= (char**) utf_table;
412 }else{
413 table= (char**) char_table;
414 }
346 415
347 layout_stack = calloc(psiconv_list_length(para->in_lines), 416 layout_stack = calloc(psiconv_list_length(para->in_lines),
348 sizeof(*layout_stack)); 417 sizeof(*layout_stack));
349 fputs("<P", of); 418 fputs("<P", of);
350 sty = psiconv_get_style(wf->styles_sec, para->base_style); 419 sty = psiconv_get_style(wf->styles_sec, para->base_style);
383 fprintf(of, "color:#%02x%02x%02x;", 452 fprintf(of, "color:#%02x%02x%02x;",
384 base_para->bullet->color->red, 453 base_para->bullet->color->red,
385 base_para->bullet->color->green, 454 base_para->bullet->color->green,
386 base_para->bullet->color->blue); 455 base_para->bullet->color->blue);
387 fprintf(of, "\">%s </SPAN>", 456 fprintf(of, "\">%s </SPAN>",
388 char_table[base_para->bullet->character]); 457 table[base_para->bullet->character]);
389 wasspace = TRUE; 458 wasspace = TRUE;
390 } 459 }
391 460
392 loc = 0; 461 loc = 0;
393 for (i = 0; i < psiconv_list_length(para->in_lines); i++) { 462 for (i = 0; i < psiconv_list_length(para->in_lines); i++) {
444 fput_paragraph_layout(of, normal ? normal->paragraph : NULL, sty->paragraph); 513 fput_paragraph_layout(of, normal ? normal->paragraph : NULL, sty->paragraph);
445 fput_character_layout(of, normal ? normal->character : NULL, sty->character, wf); 514 fput_character_layout(of, normal ? normal->character : NULL, sty->character, wf);
446 fputs("}\n", of); 515 fputs("}\n", of);
447} 516}
448 517
449void psiconv_gen_html4(FILE * of, psiconv_file file) 518static int psiconv_gen_html4(const char *filename, const psiconv_file file,
519 const char *dest, const psiconv_encoding encoding_type)
450{ 520{
521 FILE * of;
451 int i; 522 int i;
452 psiconv_paragraph para; 523 psiconv_paragraph para;
453 psiconv_word_style normal, sty; 524 psiconv_word_style normal, sty;
454 psiconv_word_f wf; 525 psiconv_word_f wf;
526
527 encoding=encoding_type;
455 528
456 if (file->type == psiconv_word_file) 529 if (file->type == psiconv_word_file)
457 wf = file->file; 530 wf = file->file;
458 else { 531 else {
459 /* Fall back on the normal HTML generator */ 532 /* Fall back on the normal HTML generator */
460 psiconv_gen_html(of,file); 533 return psiconv_gen_html(filename,file,dest,encoding_type);
534 }
535
536 if (! (of = fopen(filename,"w")))
461 return; 537 return -1;
462 }
463 538
464 fputs("<!doctype html public \"-//W3C//DTD HTML 4.0 STRICT//EN\">", of); 539 fputs("<!doctype html public \"-//W3C//DTD HTML 4.0 STRICT//EN\">", of);
465 fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); 540 fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of);
466 fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of); 541 fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of);
542
543 fputs(" <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html", of);
544 if (encoding == PSICONV_ENCODING_UTF8)
545 fputs("; CHARSET=UTF-8", of);
546 fputs("\">\n", of);
467 547
548 if (wf->page_sec->header->text) {
468 if (psiconv_list_length(wf->page_sec->header->text->paragraphs) > 0) { 549 if (psiconv_list_length(wf->page_sec->header->text->paragraphs) > 0) {
469 fputs(" <TITLE>", of); 550 fputs(" <TITLE>", of);
470 para = psiconv_list_get(wf->page_sec->header->text->paragraphs, 0); 551 para = psiconv_list_get(wf->page_sec->header->text->paragraphs, 0);
471 i = 0; 552 i = 0;
472 fput_text(of, para->text, strlen(para->text), &i); 553 fput_text(of, para->text, strlen(para->text), &i);
473 fputs("</TITLE>\n", of); 554 fputs("</TITLE>\n", of);
555 }
474 } 556 }
475 557
476 normal = wf->styles_sec->normal; 558 normal = wf->styles_sec->normal;
477 fputs(" <STYLE TYPE=\"text/css\"><!--\n", of); 559 fputs(" <STYLE TYPE=\"text/css\"><!--\n", of);
478 fprintf(of," BODY { background-color: #%02x%02x%02x }\n", 560 fprintf(of," BODY { background-color: #%02x%02x%02x }\n",
483 for (i = 0; i < psiconv_list_length(wf->styles_sec->styles); i++) { 565 for (i = 0; i < psiconv_list_length(wf->styles_sec->styles); i++) {
484 sty = psiconv_list_get(wf->styles_sec->styles, i); 566 sty = psiconv_list_get(wf->styles_sec->styles, i);
485 fput_style(of, normal, sty, wf); 567 fput_style(of, normal, sty, wf);
486 } 568 }
487 fputs(" --></STYLE>\n</HEAD>\n<BODY>\n", of); 569 fputs(" --></STYLE>\n</HEAD>\n<BODY>\n", of);
570 if (wf->page_sec->header->text) {
488 for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { 571 for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) {
489 para = psiconv_list_get(wf->paragraphs, i); 572 para = psiconv_list_get(wf->paragraphs, i);
490 fput_para(of, para, wf); 573 fput_para(of, para, wf);
574 }
491 } 575 }
492 fputs("</BODY>\n</HTML>\n", of); 576 fputs("</BODY>\n</HTML>\n", of);
493}
494 577
578 return fclose(of);
579}
580
581static struct psiconv_fileformat_s ff =
582 {
583 "HTML4",
584 "HTML 4.0 with cascading style sheets",
585 psiconv_gen_html4
586 };
587
588void init_html4(void)
589{
590 psiconv_list_add(fileformat_list,&ff);
591}
592

Legend:
Removed from v.14  
changed lines
  Added in v.147

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26