/[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 20 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>
27
28#ifdef DMALLOC
24#include "data.h" 29#include "dmalloc.h"
25#include "list.h" 30#endif
26#include "gen.h"
27 31
28/* This determines for each character how it is displayed */ 32#define TEMPSTR_LEN 100
29static const char *char_table[0x100] =
30{
31 /* 0x00 */ "" ,"" ,"" ,"" ,"" ,"" ,"<P> ","<BR>" ,
32 /* 0x08 */ "<P>" ," " ,"" ,"" ,"" ,"" ,"" ,"" ,
33 /* 0x10 */ " " ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,
34 /* 0x18 */ "" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,
35 /* 0x20 */ " " ,"!" ,"&quot;","#" ,"$" ,"%" ,"&amp;","'" ,
36 /* 0x28 */ "(" ,")" ,"*" ,"+" ,"," ,"-" ,"." ,"/" ,
37 /* 0x30 */ "0" ,"1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7" ,
38 /* 0x38 */ "8" ,"9" ,":" ,";" ,"&lt;" ,"=" ,"&gt;" ,"?" ,
39 /* 0x40 */ "@" ,"A" ,"B" ,"C" ,"D" ,"E" ,"F" ,"G" ,
40 /* 0x48 */ "H" ,"I" ,"J" ,"K" ,"L" ,"M" ,"N" ,"O" ,
41 /* 0x50 */ "P" ,"Q" ,"R" ,"S" ,"T" ,"U" ,"V" ,"W" ,
42 /* 0x58 */ "X" ,"Y" ,"Z" ,"[" ,"\\" ,"]" ,"^" ,"_" ,
43 /* 0x60 */ "`" ,"a" ,"b" ,"c" ,"d" ,"e" ,"f" ,"g" ,
44 /* 0x68 */ "h" ,"i" ,"j" ,"k" ,"l" ,"m" ,"n" ,"o" ,
45 /* 0x70 */ "p" ,"q" ,"r" ,"s" ,"t" ,"u" ,"v" ,"w" ,
46 /* 0x78 */ "x" ,"y" ,"z" ,"{" ,"|" ,"}" ,"~" ,"" ,
47 /* 0x80 */ "" ,"","&sbquot;","&fnof;","&bdquo;","&hellip;",
48 "&dagger;","&Dagger;",
49 /* 0x88 */ "^","&permil;","&Scaron;","&lang;","&OElig;","" ,"" ,"" ,
50 /* 0x90 */ "","&lsquo;","&rsquo;","&ldquo;","&rdquo;",
51 "&middot;","&ndash","&mdash",
52 /* 0x98 */ "&tilde;","&trade;","&scaron;","&rang;","&oelig;","","","&Yuml;",
53 /* 0xa0 */ "","&iexcl;","&cent;","&pound;",
54 "&curren;","&yen;","&brvbar;","&sect",
55 /* 0xa8 */ "&quot;","&copy;","a","&laquo;","&not;","-","&reg;","&macron;",
56 /* 0xb0 */ "&deg;","&plusmn;","&sup2;","&sup3;",
57 "&rsquot;","&micron;","&para;","&middot;",
58 /* 0xb8 */ "&comma;","&sup1","&deg;","&raquo;",
59 "&frac14;","&frac12;","&frac34;","&iquest;",
60 /* 0xc0 */ "&Agrave;","&Aacute;","&Acirc;","&Atilde;",
61 "&Auml;","&Aring;","&AElig;","&Ccedil;",
62 /* 0xc8 */ "&Egrave;","&Eacute;","&Ecirc;","&Euml;",
63 "&Igrave;","&Iacute;","&Icirc;","&Iuml;",
64 /* 0xd0 */ "&ETH;","&Ntilde;","&Ograve;","&Oacute;",
65 "&Ocirc;","&Otilde;","&Ouml;","&times;",
66 /* 0xd8 */ "&Oslash;","&Ugrave;","&Uacute;","&Ucirc;",
67 "&Uuml;","&Yacute;","&THORN;","&szlig;",
68 /* 0xe0 */ "&agrave;","&aacute;","&acirc;","&atilde;",
69 "&auml;","&aring;","&aelig;","&ccedil;",
70 /* 0xe8 */ "&egrave;","&eacute;","&ecirc;","&euml;",
71 "&igrave;","&iacute;","&icirc;","&iuml;",
72 /* 0xf0 */ "&eth;","&ntilde;","&ograve;","&oacute;",
73 "&ocirc;","&otilde;","&ouml;","&divide;",
74 /* 0xf8 */ "&oslash;","&ugrave;","&uacute;","&ucirc;",
75 "&uuml;","&yacute;","&thorn;","&yuml;"
76};
77 33
78static psiconv_character_layout gen_base_char(const psiconv_font font, 34typedef enum output_type_e { output_html, output_xhtml } output_type;
79 const psiconv_color color,
80 const psiconv_color back_color);
81static void diff_char(FILE *of, const psiconv_character_layout old,
82 const psiconv_character_layout new, int *flags);
83static void gen_para(FILE *of, const psiconv_paragraph para,
84 const psiconv_character_layout base_char);
85 35
86static void psiconv_gen_html_word(FILE *of,psiconv_word_f wf); 36void character_layout_diffs(const psiconv_config config, psiconv_list list,
87static void psiconv_gen_html_texted(FILE *of,psiconv_texted_f tf);
88
89/* This is not necessarily the same as returned by basic_character_layout_status
90 This one is specific for the base point of HTML */
91psiconv_character_layout gen_base_char(const psiconv_font font,
92 const psiconv_color color,
93 const psiconv_color back_color)
94{
95 struct psiconv_character_layout base_char_struct =
96 {
97 NULL, /* color */
98 NULL, /* back_color */
99 13.0, /* font_size */
100 psiconv_bool_false, /* italic */
101 psiconv_bool_false, /* bold */
102 psiconv_normalscript, /* super_sub */
103 psiconv_bool_false, /* underline */
104 psiconv_bool_false, /* strike_out */
105 NULL, /* font */
106 };
107 base_char_struct.color = color;
108 base_char_struct.back_color = back_color;
109 base_char_struct.font = font;
110 return psiconv_clone_character_layout(&base_char_struct);
111}
112
113/* flags & 1: 0 if no <FONT> was yet generated.
114 flags & 2: 1 if at end-of-paragraph
115*/
116void diff_char(FILE *of, const psiconv_character_layout old,
117 const psiconv_character_layout new, 37 const psiconv_character_layout new,
118 int *flags) 38 const psiconv_character_layout base,
39 const encoding enc)
119{ 40{
120 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}
121 68
122 if ((old->font_size != new->font_size) || 69void paragraph_layout_diffs(const psiconv_config config, psiconv_list list,
123 (old->color->red != new->color->red) || 70 const psiconv_paragraph_layout new,
124 (old->color->green != new->color->green) || 71 const psiconv_paragraph_layout base)
125 (old->color->blue != new->color->blue) || 72{
126 (strcmp(old->font->name,new->font->name)) || 73}
127 (old->font->screenfont != new->font->screenfont) || 74
128 ((*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];
129 if (old->italic) 138 if (layout->italic)
130 fputs("</I>",of); 139 output_simple_chars(config,list,"<i>",enc);
131 if (old->bold) 140 if (layout->bold)
132 fputs("</B>",of); 141 output_simple_chars(config,list,"<b>",enc);
133 if (old->underline)
134 fputs("</U>",of);
135 if (old->strike_out)
136 fputs("</STRIKE>",of);
137 if (old->super_sub == psiconv_superscript) 142 if (layout->super_sub != psiconv_normalscript)
138 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);
139 if (old->super_sub == psiconv_subscript) 176 if (layout->super_sub != psiconv_normalscript)
140 fputs("</SUB>",of); 177 output_simple_chars(config,list,
141 if ((*flags & 1) == 1) 178 layout->super_sub == psiconv_superscript?"</sup>":
142 fputs("</FONT>",of); 179 layout->super_sub == psiconv_subscript?"</sub>":
143 if ((*flags & 2) == 0) { 180 "",enc);
144 *flags |= 1; 181 if (layout->bold)
145 fputs("<FONT SIZE=",of); 182 output_simple_chars(config,list,"</b>",enc);
146 if (new->font_size <= 8.0) 183 if (layout->italic)
147 fputs("1",of); 184 output_simple_chars(config,list,"</i>",enc);
148 else if (new->font_size <= 10.0) 185}
149 fputs("2",of); 186
150 else if (new->font_size <= 12.0) 187void paragraph(const psiconv_config config, psiconv_list list,
151 fputs("3",of); 188 psiconv_paragraph para,output_type type,
152 else if (new->font_size <= 14.0) 189 const encoding enc)
153 fputs("4",of); 190{
154 else if (new->font_size <= 18.0) 191 char tempstr[TEMPSTR_LEN];
155 fputs("5",of); 192 int i,charnr;
156 else if (new->font_size <= 24.0) 193 psiconv_string_t text;
157 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);
158 else 245 } else {
159 fputs("7",of); 246 charnr = 0;
160 fprintf(of," COLOR=#%02x%02x%02x",new->color->red,new->color->green, 247 for (i = 0; i < psiconv_list_length(para->in_lines); i++) {
161 new->color->blue); 248 if (!(layout = psiconv_list_get(para->in_lines,i))) {
162 if (new->font->screenfont == 1) 249 fputs("Internal data structures corruption\n",stderr);
163 fprintf(of," FACE=\"%s, Sans-Serif\">",new->font->name); 250 exit(1);
164 else if (new->font->screenfont == 2) 251 }
165 fprintf(of," FACE=\"%s, Monospace\">",new->font-> name); 252 if (!(text = malloc(sizeof (*text) * (layout->length + 1)))) {
166 else if (new->font->screenfont == 3) 253 fputs("Out of memory error\n",stderr);
167 fprintf(of," FACE=\"%s, Serif\">",new->font-> name); 254 exit(1);
168 else 255 }
169 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;
170 } 261 }
171 if (new->italic)
172 fputs("<I>",of);
173 if (new->bold)
174 fputs("<B>",of);
175 if (new->underline)
176 fputs("<U>",of);
177 if (new->strike_out)
178 fputs("<STRIKE>",of);
179 if (new->super_sub == psiconv_superscript)
180 fputs("<SUP>",of);
181 if (new->super_sub == psiconv_subscript)
182 fputs("<SUB>",of);
183 } else {
184 if (font_set || (old->italic != new->italic)) {
185 if (old->italic)
186 fputs("</I>",of);
187 else
188 fputs("<I>",of);
189 } 262 }
190 if (old->bold != new->bold) { 263 output_simple_chars(config,list,"</p>\n",enc);
191 if (old->bold)
192 fputs("</B>",of);
193 else
194 fputs("<B>",of);
195 }
196 if (old->underline != new->underline) {
197 if (old->underline)
198 fputs("</U>",of);
199 else
200 fputs("<U>",of);
201 }
202 if (old->strike_out != new->strike_out) {
203 if (old->strike_out)
204 fputs("</STRIKE>",of);
205 else
206 fputs("<STRIKE>",of);
207 }
208 if (old->super_sub != new->super_sub) {
209 if (old->super_sub == psiconv_superscript)
210 fputs("</SUP>",of);
211 else if (old->super_sub == psiconv_subscript)
212 fputs("</SUB>",of);
213 if (new->super_sub == psiconv_superscript)
214 fputs("<SUP>",of);
215 else if (new->super_sub == psiconv_subscript)
216 fputs("<SUB>",of);
217 }
218 }
219} 264}
220 265
221void gen_para(FILE *of, const psiconv_paragraph para, 266void paragraphs(const psiconv_config config, psiconv_list list,
222 const psiconv_character_layout base_char) 267 psiconv_text_and_layout paragraphs,output_type type,
223{ 268 const encoding enc)
224 int i,j,loc;
225 psiconv_character_layout cur_char;
226 psiconv_in_line_layout inl;
227 int flags = 0;
228
229
230 fputs("<P",of);
231 if (para->base_paragraph->justify_hor == psiconv_justify_left)
232 fputs(" ALIGN=left",of);
233 else if (para->base_paragraph->justify_hor == psiconv_justify_right)
234 fputs(" ALIGN=right",of);
235 else if (para->base_paragraph->justify_hor == psiconv_justify_centre)
236 fputs(" ALIGN=center",of);
237 else if (para->base_paragraph->justify_hor == psiconv_justify_full)
238 fputs(" ALIGN=left",of);
239 fputs(">",of);
240 if (para->base_paragraph->bullet->on)
241 fputs("<UL><LI>",of);
242
243 cur_char = base_char;
244
245 if (psiconv_list_length(para->in_lines) == 0) {
246 diff_char(of,cur_char,para->base_character,&flags);
247 cur_char = para->base_character;
248 }
249 loc = 0;
250
251 for (i = 0; i < psiconv_list_length(para->in_lines); i++) {
252 inl = psiconv_list_get(para->in_lines,i);
253 diff_char(of,cur_char,inl->layout,&flags);
254 cur_char = inl->layout;
255 for (j = loc; j < inl->length + loc; j ++) {
256 fputs(char_table[(unsigned char) (para->text[j])],of);
257 }
258 loc = j;
259 }
260
261 if (loc < strlen(para->text)) {
262 diff_char(of,cur_char,para->base_character,&flags);
263 cur_char = para->base_character;
264 for (j = loc; j < strlen(para->text); j ++) {
265 fputs(char_table[(unsigned char) (para->text[j])],of);
266 }
267 }
268
269 if (strlen(para->text) == 0)
270 fputs("<BR>",of);
271
272 flags |= 2;
273 diff_char(of,cur_char,base_char,&flags);
274
275 if (para->base_paragraph->bullet->on)
276 fputs("</UL>",of);
277
278 fputs("</P>\n",of);
279}
280
281void psiconv_gen_html(FILE *of,psiconv_file file)
282{
283 if (file->type == psiconv_word_file)
284 psiconv_gen_html_word(of,(psiconv_word_f) file->file);
285 else if (file->type == psiconv_texted_file)
286 psiconv_gen_html_texted(of,(psiconv_texted_f) file->file);
287 else
288 return;
289}
290
291void psiconv_gen_html_texted(FILE *of,psiconv_texted_f tf)
292{
293 psiconv_character_layout base_char;
294 psiconv_paragraph para;
295 int i;
296
297 /* We have nothing better */
298 base_char = psiconv_basic_character_layout();
299
300 fputs("<!doctype html public \"-//W3C//DTD HTML 3.2 Final//EN\">", of);
301 fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of);
302 fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of);
303 fputs("<BODY>\n",of);
304 for (i = 0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) {
305 para = psiconv_list_get(tf->texted_sec->paragraphs,i);
306 gen_para(of,para,base_char);
307 }
308 fputs("</BODY>\n</HTML>\n",of);
309 psiconv_free_character_layout(base_char);
310}
311
312
313void psiconv_gen_html_word(FILE *of,psiconv_word_f wf)
314{ 269{
315 int i; 270 int i;
316 psiconv_paragraph para; 271 psiconv_paragraph para;
317 psiconv_color white,black;
318 psiconv_character_layout base_char;
319
320 white = malloc(sizeof(*white));
321 black = malloc(sizeof(*black));
322 white->red = 0x00;
323 white->green = 0x00;
324 white->blue = 0x00;
325 black->red = 0xff;
326 black->green = 0xff;
327 black->blue = 0xff;
328
329 /* To keep from generating a font desc for each line */
330 base_char = gen_base_char(wf->styles_sec->normal->character->font,
331 black,white);
332
333 psiconv_free_color(black);
334 psiconv_free_color(white);
335
336 fputs("<!doctype html public \"-//W3C//DTD HTML 3.2 Final//EN\">", of);
337 fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of);
338 fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of);
339 fputs("<BODY>\n",of);
340
341 for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { 272 for (i = 0; i < psiconv_list_length(paragraphs); i++) {
342 para = psiconv_list_get(wf->paragraphs,i); 273 if (!(para = psiconv_list_get(paragraphs,i))) {
343 gen_para(of,para,base_char); 274 fputs("Internal datastructure corruption\n",stderr);
275 exit(1);
276 }
277 paragraph(config,list,para,type,enc);
278 }
279}
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
332static struct fileformat_s ffs[] =
333 {
334 {
335 "XHTML",
336 "XHTML 1.0 Strict, using CSS for formatting",
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 }
344 } 349 };
345 fputs("</BODY>\n</HTML>\n",of);
346 psiconv_free_character_layout(base_char);
347}
348 350
349 351
352void init_html(void)
353{
354 int i;
355 for (i = 0; ffs[i].name; i++)
356 psiconv_list_add(fileformat_list,ffs+i);
357}

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

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