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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Sun Oct 3 21:10:47 1999 UTC (24 years, 6 months ago) by frodo
File MIME type: text/plain
File size: 12664 byte(s)
Imported sources

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

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