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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 34 - (show annotations)
Thu Dec 2 17:18:55 1999 UTC (20 years, 4 months ago) by frodo
File MIME type: text/plain
File size: 13169 byte(s)
(Frodo) Full ImageLib support!

To do:
  * More than one picture in a file
  * Special features like clipping

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

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