/[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 8 - (show annotations)
Tue Oct 5 15:32:10 1999 UTC (24 years, 5 months ago) by frodo
File MIME type: text/plain
File size: 12740 byte(s)
(Frodo) Small bug fix

Instead of the contents of `font', the font pointers were compared; so they
were often inequal, leading to too many font emitions.

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 (strcmp(old->font->name,new->font->name)) ||
123 (old->font->screenfont != new->font->screenfont) ||
124 ((*flags & 0x03) == 3)) {
125 if (old->italic)
126 fputs("</I>",of);
127 if (old->bold)
128 fputs("</B>",of);
129 if (old->underline)
130 fputs("</U>",of);
131 if (old->strike_out)
132 fputs("</STRIKE>",of);
133 if (old->super_sub == psiconv_superscript)
134 fputs("</SUP>",of);
135 if (old->super_sub == psiconv_subscript)
136 fputs("</SUB>",of);
137 if ((*flags & 1) == 1)
138 fputs("</FONT>",of);
139 if ((*flags & 2) == 0) {
140 *flags |= 1;
141 fputs("<FONT SIZE=",of);
142 if (new->font_size <= 8.0)
143 fputs("1",of);
144 else if (new->font_size <= 10.0)
145 fputs("2",of);
146 else if (new->font_size <= 12.0)
147 fputs("3",of);
148 else if (new->font_size <= 14.0)
149 fputs("4",of);
150 else if (new->font_size <= 18.0)
151 fputs("5",of);
152 else if (new->font_size <= 24.0)
153 fputs("6",of);
154 else
155 fputs("7",of);
156 fprintf(of," COLOR=#%02x%02x%02x",new->color->red,new->color->green,
157 new->color->blue);
158 if (new->font->screenfont == 1)
159 fprintf(of," FACE=\"%s, Sans-Serif\">",new->font->name);
160 else if (new->font->screenfont == 2)
161 fprintf(of," FACE=\"%s, Monospace\">",new->font-> name);
162 else if (new->font->screenfont == 3)
163 fprintf(of," FACE=\"%s, Serif\">",new->font-> name);
164 else
165 fprintf(of," FACE=\"%s, Serif\">",new->font-> name);
166 }
167 if (new->italic)
168 fputs("<I>",of);
169 if (new->bold)
170 fputs("<B>",of);
171 if (new->underline)
172 fputs("<U>",of);
173 if (new->strike_out)
174 fputs("<STRIKE>",of);
175 if (new->super_sub == psiconv_superscript)
176 fputs("<SUP>",of);
177 if (new->super_sub == psiconv_subscript)
178 fputs("<SUB>",of);
179 } else {
180 if (font_set || (old->italic != new->italic)) {
181 if (old->italic)
182 fputs("</I>",of);
183 else
184 fputs("<I>",of);
185 }
186 if (old->bold != new->bold) {
187 if (old->bold)
188 fputs("</B>",of);
189 else
190 fputs("<B>",of);
191 }
192 if (old->underline != new->underline) {
193 if (old->underline)
194 fputs("</U>",of);
195 else
196 fputs("<U>",of);
197 }
198 if (old->strike_out != new->strike_out) {
199 if (old->strike_out)
200 fputs("</STRIKE>",of);
201 else
202 fputs("<STRIKE>",of);
203 }
204 if (old->super_sub != new->super_sub) {
205 if (old->super_sub == psiconv_superscript)
206 fputs("</SUP>",of);
207 else if (old->super_sub == psiconv_subscript)
208 fputs("</SUB>",of);
209 if (new->super_sub == psiconv_superscript)
210 fputs("<SUP>",of);
211 else if (new->super_sub == psiconv_subscript)
212 fputs("<SUB>",of);
213 }
214 }
215 }
216
217 void gen_para(FILE *of, const psiconv_paragraph para,
218 const psiconv_character_layout base_char)
219 {
220 int i,j,loc;
221 psiconv_character_layout cur_char;
222 psiconv_in_line_layout inl;
223 int flags = 0;
224
225
226 fputs("<P",of);
227 if (para->base_paragraph->justify_hor == psiconv_justify_left)
228 fputs(" ALIGN=left",of);
229 else if (para->base_paragraph->justify_hor == psiconv_justify_right)
230 fputs(" ALIGN=right",of);
231 else if (para->base_paragraph->justify_hor == psiconv_justify_centre)
232 fputs(" ALIGN=center",of);
233 else if (para->base_paragraph->justify_hor == psiconv_justify_full)
234 fputs(" ALIGN=left",of);
235 fputs(">",of);
236 if (para->base_paragraph->bullet->on)
237 fputs("<UL><LI>",of);
238
239 cur_char = base_char;
240
241 if (psiconv_list_length(para->in_lines) == 0) {
242 diff_char(of,cur_char,para->base_character,&flags);
243 cur_char = para->base_character;
244 }
245 loc = 0;
246
247 for (i = 0; i < psiconv_list_length(para->in_lines); i++) {
248 inl = psiconv_list_get(para->in_lines,i);
249 diff_char(of,cur_char,inl->layout,&flags);
250 cur_char = inl->layout;
251 for (j = loc; j < inl->length + loc; j ++) {
252 fputs(char_table[(unsigned char) (para->text[j])],of);
253 }
254 loc = j;
255 }
256
257 if (loc < strlen(para->text)) {
258 diff_char(of,cur_char,para->base_character,&flags);
259 cur_char = para->base_character;
260 for (j = loc; j < strlen(para->text); j ++) {
261 fputs(char_table[(unsigned char) (para->text[j])],of);
262 }
263 }
264
265 if (strlen(para->text) == 0)
266 fputs("<BR>",of);
267
268 flags |= 2;
269 diff_char(of,cur_char,base_char,&flags);
270
271 if (para->base_paragraph->bullet->on)
272 fputs("</UL>",of);
273
274 fputs("</P>\n",of);
275 }
276
277 void psiconv_gen_html(FILE *of,psiconv_file file)
278 {
279 if (file->type == psiconv_word_file)
280 psiconv_gen_html_word(of,(psiconv_word_f) file->file);
281 else if (file->type == psiconv_texted_file)
282 psiconv_gen_html_texted(of,(psiconv_texted_f) file->file);
283 else
284 return;
285 }
286
287 void psiconv_gen_html_texted(FILE *of,psiconv_texted_f tf)
288 {
289 psiconv_character_layout base_char;
290 psiconv_paragraph para;
291 int i;
292
293 /* We have nothing better */
294 base_char = psiconv_basic_character_layout();
295
296 fputs("<!doctype html public \"-//W3C//DTD HTML 3.2 Final//EN\">", of);
297 fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of);
298 fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of);
299 fputs("<BODY>\n",of);
300 for (i = 0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) {
301 para = psiconv_list_get(tf->texted_sec->paragraphs,i);
302 gen_para(of,para,base_char);
303 }
304 fputs("</BODY>\n</HTML>\n",of);
305 psiconv_free_character_layout(base_char);
306 }
307
308
309 void psiconv_gen_html_word(FILE *of,psiconv_word_f wf)
310 {
311 int i;
312 psiconv_paragraph para;
313 psiconv_color white,black;
314 psiconv_character_layout base_char;
315
316 white = malloc(sizeof(*white));
317 black = malloc(sizeof(*black));
318 white->red = 0x00;
319 white->green = 0x00;
320 white->blue = 0x00;
321 black->red = 0xff;
322 black->green = 0xff;
323 black->blue = 0xff;
324
325 /* To keep from generating a font desc for each line */
326 base_char = gen_base_char(wf->styles_sec->normal->character->font,
327 black,white);
328
329 psiconv_free_color(black);
330 psiconv_free_color(white);
331
332 fputs("<!doctype html public \"-//W3C//DTD HTML 3.2 Final//EN\">", of);
333 fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of);
334 fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of);
335 fputs("<BODY>\n",of);
336
337 for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) {
338 para = psiconv_list_get(wf->paragraphs,i);
339 gen_para(of,para,base_char);
340 }
341 fputs("</BODY>\n</HTML>\n",of);
342 psiconv_free_character_layout(base_char);
343 }
344
345

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