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

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

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

Revision 142 Revision 190
1/*
2 gen_html.c - Part of psiconv, a PSION 5 file formats converter 1/* gen_html.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl> 2 Copyright (c) 1999-2004 Frodo Looijaard <frodol@dds.nl>
4 3
5 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 6 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 7 (at your option) any later version.
9 8
10 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 12 GNU General Public License for more details.
14 13
15 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 15 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/ 17*/
19 18
20#include "config.h" 19#include "config.h"
21#include <stdio.h> 20
21#include <psiconv/configuration.h>
22#include <psiconv/data.h>
23#include "general.h"
24
22#include <string.h> 25#include <string.h>
23#include <stdlib.h> 26#include <stdlib.h>
24#include "psiconv/data.h"
25#include "psiconv/list.h"
26#include "gen.h"
27#include "psiconv.h"
28 27
29#ifdef DMALLOC 28#ifdef DMALLOC
30#include "dmalloc.h" 29#include "dmalloc.h"
31#endif 30#endif
32 31
33/* This determines for each character how it is displayed */ 32#define TEMPSTR_LEN 100
34static const char *char_table[0x100] =
35{
36 /* 0x00 */ "" ,"" ,"" ,"" ,"" ,"" ,"<P> ","<BR>" ,
37 /* 0x08 */ "<P>" ," " ,"" ,"" ,"" ,"" ,"" ,"" ,
38 /* 0x10 */ " " ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,
39 /* 0x18 */ "" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,
40 /* 0x20 */ " " ,"!" ,"&quot;","#" ,"$" ,"%" ,"&amp;","'" ,
41 /* 0x28 */ "(" ,")" ,"*" ,"+" ,"," ,"-" ,"." ,"/" ,
42 /* 0x30 */ "0" ,"1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7" ,
43 /* 0x38 */ "8" ,"9" ,":" ,";" ,"&lt;" ,"=" ,"&gt;" ,"?" ,
44 /* 0x40 */ "@" ,"A" ,"B" ,"C" ,"D" ,"E" ,"F" ,"G" ,
45 /* 0x48 */ "H" ,"I" ,"J" ,"K" ,"L" ,"M" ,"N" ,"O" ,
46 /* 0x50 */ "P" ,"Q" ,"R" ,"S" ,"T" ,"U" ,"V" ,"W" ,
47 /* 0x58 */ "X" ,"Y" ,"Z" ,"[" ,"\\" ,"]" ,"^" ,"_" ,
48 /* 0x60 */ "`" ,"a" ,"b" ,"c" ,"d" ,"e" ,"f" ,"g" ,
49 /* 0x68 */ "h" ,"i" ,"j" ,"k" ,"l" ,"m" ,"n" ,"o" ,
50 /* 0x70 */ "p" ,"q" ,"r" ,"s" ,"t" ,"u" ,"v" ,"w" ,
51 /* 0x78 */ "x" ,"y" ,"z" ,"{" ,"|" ,"}" ,"~" ,"" ,
52 /* 0x80 */ "" ,"","&sbquot;","&fnof;","&bdquo;","&hellip;",
53 "&dagger;","&Dagger;",
54 /* 0x88 */ "^","&permil;","&Scaron;","&lang;","&OElig;","" ,"" ,"" ,
55 /* 0x90 */ "","&lsquo;","&rsquo;","&ldquo;","&rdquo;",
56 "&middot;","&ndash","&mdash",
57 /* 0x98 */ "&tilde;","&trade;","&scaron;","&rang;","&oelig;","","","&Yuml;",
58 /* 0xa0 */ "","&iexcl;","&cent;","&pound;",
59 "&curren;","&yen;","&brvbar;","&sect",
60 /* 0xa8 */ "&quot;","&copy;","a","&laquo;","&not;","-","&reg;","&macron;",
61 /* 0xb0 */ "&deg;","&plusmn;","&sup2;","&sup3;",
62 "&rsquot;","&micron;","&para;","&middot;",
63 /* 0xb8 */ "&comma;","&sup1","&deg;","&raquo;",
64 "&frac14;","&frac12;","&frac34;","&iquest;",
65 /* 0xc0 */ "&Agrave;","&Aacute;","&Acirc;","&Atilde;",
66 "&Auml;","&Aring;","&AElig;","&Ccedil;",
67 /* 0xc8 */ "&Egrave;","&Eacute;","&Ecirc;","&Euml;",
68 "&Igrave;","&Iacute;","&Icirc;","&Iuml;",
69 /* 0xd0 */ "&ETH;","&Ntilde;","&Ograve;","&Oacute;",
70 "&Ocirc;","&Otilde;","&Ouml;","&times;",
71 /* 0xd8 */ "&Oslash;","&Ugrave;","&Uacute;","&Ucirc;",
72 "&Uuml;","&Yacute;","&THORN;","&szlig;",
73 /* 0xe0 */ "&agrave;","&aacute;","&acirc;","&atilde;",
74 "&auml;","&aring;","&aelig;","&ccedil;",
75 /* 0xe8 */ "&egrave;","&eacute;","&ecirc;","&euml;",
76 "&igrave;","&iacute;","&icirc;","&iuml;",
77 /* 0xf0 */ "&eth;","&ntilde;","&ograve;","&oacute;",
78 "&ocirc;","&otilde;","&ouml;","&divide;",
79 /* 0xf8 */ "&oslash;","&ugrave;","&uacute;","&ucirc;",
80 "&uuml;","&yacute;","&thorn;","&yuml;"
81};
82 33
83static psiconv_character_layout gen_base_char(const psiconv_font font, 34typedef enum output_type_e { output_html, output_xhtml } output_type;
84 const psiconv_color color,
85 const psiconv_color back_color);
86static void diff_char(FILE *of, const psiconv_character_layout old,
87 const psiconv_character_layout new, int *flags);
88static void gen_para(FILE *of, const psiconv_paragraph para,
89 const psiconv_character_layout base_char);
90 35
91static void psiconv_gen_html_word(FILE *of,psiconv_word_f wf); 36void character_layout_diffs(const psiconv_config config, psiconv_list list,
92static void psiconv_gen_html_texted(FILE *of,psiconv_texted_f tf);
93
94/* This is not necessarily the same as returned by basic_character_layout_status
95 This one is specific for the base point of HTML */
96psiconv_character_layout gen_base_char(const psiconv_font font,
97 const psiconv_color color,
98 const psiconv_color back_color)
99{
100 struct psiconv_character_layout_s base_char_struct =
101 {
102 NULL, /* color */
103 NULL, /* back_color */
104 13.0, /* font_size */
105 psiconv_bool_false, /* italic */
106 psiconv_bool_false, /* bold */
107 psiconv_normalscript, /* super_sub */
108 psiconv_bool_false, /* underline */
109 psiconv_bool_false, /* strikethrough */
110 NULL, /* font */
111 };
112 base_char_struct.color = color;
113 base_char_struct.back_color = back_color;
114 base_char_struct.font = font;
115 return psiconv_clone_character_layout(&base_char_struct);
116}
117
118/* flags & 1: 0 if no <FONT> was yet generated.
119 flags & 2: 1 if at end-of-paragraph
120*/
121void diff_char(FILE *of, const psiconv_character_layout old,
122 const psiconv_character_layout new, 37 const psiconv_character_layout new,
123 int *flags) 38 const psiconv_character_layout base,
39 const encoding enc)
124{ 40{
125 int font_set = 0; 41 if (new->italic != base->italic) {
42 output_simple_chars(config,list,"font-style:",enc);
43 output_simple_chars(config,list,new->italic?"italic":"normal",enc);
44 output_simple_chars(config,list,";",enc);
45 }
46 if ((new->underline != base->underline) ||
47 (new->strikethrough != base->strikethrough)) {
48 output_simple_chars(config,list,"text-decoration:",enc);
49 output_simple_chars(config,list,new->underline?"underline":
50 new->strikethrough?"line-through":
51 "none",enc);
52 output_simple_chars(config,list,";",enc);
53 }
54 if (new->bold != base->bold) {
55 output_simple_chars(config,list,"font-weight:",enc);
56 output_simple_chars(config,list,new->bold?"bold":"normal",enc);
57 output_simple_chars(config,list,";",enc);
58 }
59 if (new->super_sub != base->super_sub) {
60 output_simple_chars(config,list,"font-style:",enc);
61 output_simple_chars(config,list,
62 new->super_sub==psiconv_superscript?"super":
63 new->super_sub==psiconv_subscript?"sub":
64 "normal",enc);
65 output_simple_chars(config,list,";",enc);
66 }
67}
126 68
127 if ((old->font_size != new->font_size) || 69void paragraph_layout_diffs(const psiconv_config config, psiconv_list list,
128 (old->color->red != new->color->red) || 70 const psiconv_paragraph_layout new,
129 (old->color->green != new->color->green) || 71 const psiconv_paragraph_layout base)
130 (old->color->blue != new->color->blue) || 72{
131 (strcmp(old->font->name,new->font->name)) || 73}
132 (old->font->screenfont != new->font->screenfont) || 74
133 ((*flags & 0x03) == 3)) { 75void header(const psiconv_config config, psiconv_list list,
76 output_type type, const encoding enc)
77{
78 if (type == output_xhtml)
79 output_simple_chars(config,list,
80 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",enc);
81 output_simple_chars(config,list,"<!DOCTYPE html PUBLIC ",enc);
82 output_simple_chars(config,list,type == output_xhtml?
83 "\"-//W3C//DTD XHTML 1.0 Strict//EN\" ":
84 "\"-//W3C//DTD HTML 4.01//EN\" ",enc);
85 output_simple_chars(config,list,type == output_xhtml?
86 "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">":
87 "\"http://www.w3.org/TR/html4/strict.dtd\">",enc);
88 output_simple_chars(config,list,"\n<html",enc);
89 if (type == output_xhtml)
90 output_simple_chars(config,list,
91 " xmlns=\"http://www.w3.org/1999/xhtml\"",enc);
92 output_simple_chars(config,list,">\n",enc);
93 output_simple_chars(config,list,"<head>\n",enc);
94 output_simple_chars(config,list,"<meta http-equiv=\"Content-Type\" "
95 "content=\"text/html; charset=",enc);
96 output_simple_chars(config,list,enc==ENCODING_UTF8?"UTF-8":
97 enc==ENCODING_UCS2?"UTF-16BE":
98 enc==ENCODING_ASCII?"US-ASCII":
99 "",enc);
100 output_simple_chars(config,list,"\">\n",enc);
101 output_simple_chars(config,list,"<meta http-equiv=\"Content-Style-Type\" "
102 "content=\"text/css\">\n",enc);
103 output_simple_chars(config,list,"<title>EPOC32 file "
104 "converted by psiconv</title>\n",enc);
105 output_simple_chars(config,list,"</head>\n",enc);
106 output_simple_chars(config,list,"<body>\n",enc);
107}
108
109void footer(const psiconv_config config, psiconv_list list,
110 output_type type, const encoding enc)
111{
112 output_simple_chars(config,list,"</body>\n",enc);
113 output_simple_chars(config,list,"</html>\n",enc);
114}
115
116void color(const psiconv_config config, psiconv_list list,
117 psiconv_color color, output_type type, const encoding enc)
118{
119 char tempstr[TEMPSTR_LEN];
120 if ((color->red == 0xff) &&
121 (color->blue == 0xff) &&
122 (color->green == 0xff))
123 output_simple_chars(config,list,"transparant",enc);
124 else {
125 snprintf(tempstr,TEMPSTR_LEN,"rgb(%d,%d,%d)",
126 color->red,
127 color->green,
128 color->blue);
129 output_simple_chars(config,list,tempstr,enc);
130 }
131}
132
133void charlayout(const psiconv_config config, psiconv_list list,
134 psiconv_string_t text,psiconv_character_layout layout,
135 output_type type, const encoding enc)
136{
137 char tempstr[TEMPSTR_LEN];
134 if (old->italic) 138 if (layout->italic)
135 fputs("</I>",of); 139 output_simple_chars(config,list,"<i>",enc);
136 if (old->bold) 140 if (layout->bold)
137 fputs("</B>",of); 141 output_simple_chars(config,list,"<b>",enc);
138 if (old->underline)
139 fputs("</U>",of);
140 if (old->strikethrough)
141 fputs("</STRIKE>",of);
142 if (old->super_sub == psiconv_superscript) 142 if (layout->super_sub != psiconv_normalscript)
143 fputs("</SUP>",of); 143 output_simple_chars(config,list,
144 layout->super_sub == psiconv_superscript?"<sup>":
145 layout->super_sub == psiconv_subscript?"<sub>":
146 "",enc);
147
148 output_simple_chars(config,list,"<span style=\"",enc);
149
150 if (layout->underline || layout->strikethrough) {
151 output_simple_chars(config,list,"text-decoration:",enc);
152 output_simple_chars(config,list,layout->underline?"underline":
153 layout->strikethrough?"line-through":
154 "",enc);
155 output_simple_chars(config,list,";",enc);
156 }
157
158 output_simple_chars(config,list,"color:",enc);
159 color(config,list,layout->color,type,enc);
160 output_simple_chars(config,list,";",enc);
161
162 output_simple_chars(config,list,"background-color:",enc);
163 color(config,list,layout->back_color,type,enc);
164 output_simple_chars(config,list,";",enc);
165
166 output_simple_chars(config,list,"font-size:",enc);
167 snprintf(tempstr,TEMPSTR_LEN,"%f",layout->font_size);
168 output_simple_chars(config,list,tempstr,enc);
169 output_simple_chars(config,list,"pt;",enc);
170
171 output_simple_chars(config,list,"\">",enc);
172
173 output_string(config,list,text,enc);
174
175 output_simple_chars(config,list,"</span>",enc);
144 if (old->super_sub == psiconv_subscript) 176 if (layout->super_sub != psiconv_normalscript)
145 fputs("</SUB>",of); 177 output_simple_chars(config,list,
146 if ((*flags & 1) == 1) 178 layout->super_sub == psiconv_superscript?"</sup>":
147 fputs("</FONT>",of); 179 layout->super_sub == psiconv_subscript?"</sub>":
148 if ((*flags & 2) == 0) { 180 "",enc);
149 *flags |= 1; 181 if (layout->bold)
150 fputs("<FONT SIZE=",of); 182 output_simple_chars(config,list,"</b>",enc);
151 if (new->font_size <= 8.0) 183 if (layout->italic)
152 fputs("1",of); 184 output_simple_chars(config,list,"</i>",enc);
153 else if (new->font_size <= 10.0) 185}
154 fputs("2",of); 186
155 else if (new->font_size <= 12.0) 187void paragraph(const psiconv_config config, psiconv_list list,
156 fputs("3",of); 188 psiconv_paragraph para,output_type type,
157 else if (new->font_size <= 14.0) 189 const encoding enc)
158 fputs("4",of); 190{
159 else if (new->font_size <= 18.0) 191 char tempstr[TEMPSTR_LEN];
160 fputs("5",of); 192 int i,charnr;
161 else if (new->font_size <= 24.0) 193 psiconv_string_t text;
162 fputs("6",of); 194 psiconv_in_line_layout layout;
195
196 output_simple_chars(config,list,"<p style=\"",enc);
197
198 output_simple_chars(config,list,"background-color:",enc);
199 color(config,list,para->base_paragraph->back_color,type,enc);
200 output_simple_chars(config,list,";",enc);
201
202 output_simple_chars(config,list,"padding-left:",enc);
203 snprintf(tempstr,TEMPSTR_LEN,"%f",para->base_paragraph->indent_left);
204 output_simple_chars(config,list,tempstr,enc);
205 output_simple_chars(config,list,"cm;",enc);
206
207 output_simple_chars(config,list,"padding-right:",enc);
208 snprintf(tempstr,TEMPSTR_LEN,"%f",para->base_paragraph->indent_right);
209 output_simple_chars(config,list,tempstr,enc);
210 output_simple_chars(config,list,"cm;",enc);
211
212 output_simple_chars(config,list,"text-indent:",enc);
213 snprintf(tempstr,TEMPSTR_LEN,"%f",para->base_paragraph->indent_left - para->base_paragraph->indent_first);
214 output_simple_chars(config,list,tempstr,enc);
215 output_simple_chars(config,list,"cm;",enc);
216
217 output_simple_chars(config,list,"text-align:",enc);
218 output_simple_chars(config,list,para->base_paragraph->justify_hor==psiconv_justify_left?"left":
219 para->base_paragraph->justify_hor==psiconv_justify_centre?"center":
220 para->base_paragraph->justify_hor==psiconv_justify_right?"right":
221 para->base_paragraph->justify_hor==psiconv_justify_full?"justify":
222 "",enc);
223 output_simple_chars(config,list,";",enc);
224
225
226 output_simple_chars(config,list,"line-height:",enc);
227 snprintf(tempstr,TEMPSTR_LEN,"%f",para->base_paragraph->linespacing);
228 output_simple_chars(config,list,tempstr,enc);
229 output_simple_chars(config,list,"pt;",enc);
230
231 output_simple_chars(config,list,"padding-top:",enc);
232 snprintf(tempstr,TEMPSTR_LEN,"%f",para->base_paragraph->space_above);
233 output_simple_chars(config,list,tempstr,enc);
234 output_simple_chars(config,list,"pt;",enc);
235
236 output_simple_chars(config,list,"padding-bottom:",enc);
237 snprintf(tempstr,TEMPSTR_LEN,"%f",para->base_paragraph->space_below);
238 output_simple_chars(config,list,tempstr,enc);
239 output_simple_chars(config,list,"pt;",enc);
240
241 output_simple_chars(config,list,"\">",enc);
242
243 if (psiconv_list_length(para->in_lines) == 0) {
244 charlayout(config,list,para->text,para->base_character,type,enc);
163 else 245 } else {
164 fputs("7",of); 246 charnr = 0;
165 fprintf(of," COLOR=#%02x%02x%02x",new->color->red,new->color->green, 247 for (i = 0; i < psiconv_list_length(para->in_lines); i++) {
166 new->color->blue); 248 if (!(layout = psiconv_list_get(para->in_lines,i))) {
167 if (new->font->screenfont == psiconv_font_sansserif) 249 fputs("Internal data structures corruption\n",stderr);
168 fprintf(of," FACE=\"%s, Sans-Serif\">",new->font->name); 250 exit(1);
169 else if (new->font->screenfont == psiconv_font_nonprop) 251 }
170 fprintf(of," FACE=\"%s, Monospace\">",new->font-> name); 252 if (!(text = malloc(sizeof (*text) * (layout->length + 1)))) {
171 else if (new->font->screenfont == psiconv_font_serif) 253 fputs("Out of memory error\n",stderr);
172 fprintf(of," FACE=\"%s, Serif\">",new->font-> name); 254 exit(1);
173 else 255 }
174 fprintf(of," FACE=\"%s, Serif\">",new->font-> name); 256 memcpy(text,para->text+charnr,layout->length * sizeof(*text));
257 text[layout->length] = 0;
258 charlayout(config,list,text,layout->layout,type,enc);
259 free(text);
260 charnr += layout->length;
175 } 261 }
176 if (new->italic)
177 fputs("<I>",of);
178 if (new->bold)
179 fputs("<B>",of);
180 if (new->underline)
181 fputs("<U>",of);
182 if (new->strikethrough)
183 fputs("<STRIKE>",of);
184 if (new->super_sub == psiconv_superscript)
185 fputs("<SUP>",of);
186 if (new->super_sub == psiconv_subscript)
187 fputs("<SUB>",of);
188 } else {
189 if (font_set || (old->italic != new->italic)) {
190 if (old->italic)
191 fputs("</I>",of);
192 else
193 fputs("<I>",of);
194 } 262 }
195 if (old->bold != new->bold) { 263 output_simple_chars(config,list,"</p>\n",enc);
196 if (old->bold)
197 fputs("</B>",of);
198 else
199 fputs("<B>",of);
200 }
201 if (old->underline != new->underline) {
202 if (old->underline)
203 fputs("</U>",of);
204 else
205 fputs("<U>",of);
206 }
207 if (old->strikethrough != new->strikethrough) {
208 if (old->strikethrough)
209 fputs("</STRIKE>",of);
210 else
211 fputs("<STRIKE>",of);
212 }
213 if (old->super_sub != new->super_sub) {
214 if (old->super_sub == psiconv_superscript)
215 fputs("</SUP>",of);
216 else if (old->super_sub == psiconv_subscript)
217 fputs("</SUB>",of);
218 if (new->super_sub == psiconv_superscript)
219 fputs("<SUP>",of);
220 else if (new->super_sub == psiconv_subscript)
221 fputs("<SUB>",of);
222 }
223 }
224} 264}
225 265
226void gen_para(FILE *of, const psiconv_paragraph para, 266void paragraphs(const psiconv_config config, psiconv_list list,
227 const psiconv_character_layout base_char) 267 psiconv_text_and_layout paragraphs,output_type type,
228{ 268 const encoding enc)
229 int i,j,loc;
230 psiconv_character_layout cur_char;
231 psiconv_in_line_layout inl;
232 int flags = 0;
233
234
235 fputs("<P",of);
236 if (para->base_paragraph->justify_hor == psiconv_justify_left)
237 fputs(" ALIGN=left",of);
238 else if (para->base_paragraph->justify_hor == psiconv_justify_right)
239 fputs(" ALIGN=right",of);
240 else if (para->base_paragraph->justify_hor == psiconv_justify_centre)
241 fputs(" ALIGN=center",of);
242 else if (para->base_paragraph->justify_hor == psiconv_justify_full)
243 fputs(" ALIGN=left",of);
244 fputs(">",of);
245 if (para->base_paragraph->bullet->on)
246 fputs("<UL><LI>",of);
247
248 cur_char = base_char;
249
250 if (psiconv_list_length(para->in_lines) == 0) {
251 diff_char(of,cur_char,para->base_character,&flags);
252 cur_char = para->base_character;
253 }
254 loc = 0;
255
256 for (i = 0; i < psiconv_list_length(para->in_lines); i++) {
257 inl = psiconv_list_get(para->in_lines,i);
258 diff_char(of,cur_char,inl->layout,&flags);
259 cur_char = inl->layout;
260 for (j = loc; j < inl->length + loc; j ++) {
261 fputs(char_table[(unsigned char) (para->text[j])],of);
262 }
263 loc = j;
264 }
265
266 if (loc < strlen(para->text)) {
267 diff_char(of,cur_char,para->base_character,&flags);
268 cur_char = para->base_character;
269 for (j = loc; j < strlen(para->text); j ++) {
270 fputs(char_table[(unsigned char) (para->text[j])],of);
271 }
272 }
273
274 if (strlen(para->text) == 0)
275 fputs("<BR>",of);
276
277 flags |= 2;
278 diff_char(of,cur_char,base_char,&flags);
279
280 if (para->base_paragraph->bullet->on)
281 fputs("</UL>",of);
282
283 fputs("</P>\n",of);
284}
285
286int psiconv_gen_html(const char * filename,const psiconv_file file,
287 const char *dest)
288{
289 FILE *of = fopen(filename,"w");
290 if (! of)
291 return -1;
292
293 if (file->type == psiconv_word_file) {
294 psiconv_gen_html_word(of,(psiconv_word_f) file->file);
295 } else if (file->type == psiconv_texted_file) {
296 psiconv_gen_html_texted(of,(psiconv_texted_f) file->file);
297 } else {
298 fclose(of);
299 return -1;
300 }
301 return fclose(of);
302}
303
304void psiconv_gen_html_texted(FILE *of,psiconv_texted_f tf)
305{
306 psiconv_character_layout base_char;
307 psiconv_paragraph para;
308 int i;
309
310 /* We have nothing better */
311 base_char = psiconv_basic_character_layout();
312
313 fputs("<!doctype html public \"-//W3C//DTD HTML 3.2 Final//EN\">", of);
314 fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of);
315 fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of);
316 fputs("<BODY>\n",of);
317 for (i = 0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) {
318 para = psiconv_list_get(tf->texted_sec->paragraphs,i);
319 gen_para(of,para,base_char);
320 }
321 fputs("</BODY>\n</HTML>\n",of);
322 psiconv_free_character_layout(base_char);
323}
324
325
326void psiconv_gen_html_word(FILE *of,psiconv_word_f wf)
327{ 269{
328 int i; 270 int i;
329 psiconv_paragraph para; 271 psiconv_paragraph para;
330 psiconv_color white,black;
331 psiconv_character_layout base_char;
332
333 white = malloc(sizeof(*white));
334 black = malloc(sizeof(*black));
335 white->red = 0x00;
336 white->green = 0x00;
337 white->blue = 0x00;
338 black->red = 0xff;
339 black->green = 0xff;
340 black->blue = 0xff;
341
342 /* To keep from generating a font desc for each line */
343 base_char = gen_base_char(wf->styles_sec->normal->character->font,
344 black,white);
345
346 psiconv_free_color(black);
347 psiconv_free_color(white);
348
349 fputs("<!doctype html public \"-//W3C//DTD HTML 3.2 Final//EN\">", of);
350 fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of);
351 fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of);
352 fputs("<BODY>\n",of);
353
354 for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { 272 for (i = 0; i < psiconv_list_length(paragraphs); i++) {
355 para = psiconv_list_get(wf->paragraphs,i); 273 if (!(para = psiconv_list_get(paragraphs,i))) {
356 gen_para(of,para,base_char); 274 fputs("Internal datastructure corruption\n",stderr);
275 exit(1);
357 } 276 }
358 fputs("</BODY>\n</HTML>\n",of); 277 paragraph(config,list,para,type,enc);
359 psiconv_free_character_layout(base_char); 278 }
360} 279}
361 280
281void gen_html_word(const psiconv_config config, psiconv_list list,
282 const psiconv_word_f file, output_type type,
283 const encoding enc)
284{
285 if (!file)
286 return;
287
288 header(config,list,type,enc);
289 paragraphs(config,list,file->paragraphs,type,enc);
290 footer(config,list,type,enc);
291}
292
293
294void gen_html_texted(const psiconv_config config, psiconv_list list,
295 const psiconv_texted_f file, output_type type,
296 const encoding enc)
297{
298 header(config,list,type,enc);
299 paragraphs(config,list,file->texted_sec->paragraphs,type,enc);
300 footer(config,list,type,enc);
301}
302
303int gen_html(const psiconv_config config, psiconv_list list,
304 const psiconv_file file, const char *dest,
305 const encoding enc)
306{
307 output_type type;
308
309 if (!strcmp("HTML4",dest))
310 type = output_html;
311 else if (!strcmp("XHTML",dest))
312 type = output_xhtml;
313 else
314 return -1;
315
316 if (enc == ENCODING_PSION) {
317 fputs("Unsupported encoding\n",stderr);
318 return -1;
319 }
320
321 if (file->type == psiconv_word_file) {
322 gen_html_word(config,list,(psiconv_word_f) file->file,type,enc);
323 return 0;
324 } else if (file->type == psiconv_texted_file) {
325 gen_html_texted(config,list,(psiconv_texted_f) file->file,type, enc);
326 return 0;
327 } else
328 return -1;
329}
330
331
362static struct psiconv_fileformat_s ff = 332static struct fileformat_s ffs[] =
363 { 333 {
334 {
364 "HTML3", 335 "XHTML",
365 "HTML 3.2, not verified so probably not completely compliant", 336 "XHTML 1.0 Strict, using CSS for formatting",
366 &psiconv_gen_html 337 gen_html
338 },
339 {
340 "HTML4",
341 "HTML 4.01 Strict, using CSS for formatting",
342 gen_html
343 },
344 {
345 NULL,
346 NULL,
347 NULL
348 }
367 }; 349 };
368 350
351
369void init_html(void) 352void init_html(void)
370{ 353{
354 int i;
355 for (i = 0; ffs[i].name; i++)
371 psiconv_list_add(fileformat_list,&ff); 356 psiconv_list_add(fileformat_list,ffs+i);
372} 357}

Legend:
Removed from v.142  
changed lines
  Added in v.190

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