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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 193 - (show annotations)
Mon Feb 2 21:56:48 2004 UTC (20 years, 2 months ago) by frodo
File MIME type: text/plain
File size: 10463 byte(s)
(Frodo) Make the formats stuff work again

  * Amend the configure.in to select the right targets
  * Remove RTF support (it never worked anyway)
  * Update the links creation scripts

And in the psiconv program and library:
  * Some fixes to reduce compiler warnings
  * Emit tabs as spaces in the HTML4/XHTML generators

1 /* gen_html.c - Part of psiconv, a PSION 5 file formats converter
2 Copyright (c) 1999-2004 Frodo Looijaard <frodol@dds.nl>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include "config.h"
20
21 #include <psiconv/configuration.h>
22 #include <psiconv/data.h>
23 #include "general.h"
24
25 #include <string.h>
26 #include <stdlib.h>
27
28 #ifdef DMALLOC
29 #include "dmalloc.h"
30 #endif
31
32 #define TEMPSTR_LEN 100
33
34 static void text(const psiconv_config config,psiconv_list list,
35 psiconv_string_t data,const encoding enc);
36 static void header(const psiconv_config config, psiconv_list list,
37 const encoding enc);
38 static void footer(const psiconv_config config, psiconv_list list,
39 const encoding enc);
40 static void characters(const psiconv_config config, psiconv_list list,
41 const psiconv_string_t textstr,
42 const psiconv_character_layout layout,const encoding enc);
43 static void paragraph(const psiconv_config config, psiconv_list list,
44 psiconv_paragraph para, const encoding enc);
45 static void paragraphs(const psiconv_config config, psiconv_list list,
46 psiconv_text_and_layout paragraphs, const encoding enc);
47 static void gen_word(const psiconv_config config, psiconv_list list,
48 const psiconv_word_f file, const encoding enc);
49 static void gen_texted(const psiconv_config config, psiconv_list list,
50 const psiconv_texted_f file, const encoding enc);
51 static int gen_html4(const psiconv_config config, psiconv_list list,
52 const psiconv_file file, const char *dest,
53 const encoding enc);
54
55
56 void text(const psiconv_config config,psiconv_list list,
57 psiconv_string_t data,const encoding enc)
58 {
59 int i;
60 for (i = 0; i < psiconv_unicode_strlen(data); i++) {
61 if ((data[i] == 0x06) || (data[i] == 0x07) || (data[i] == 0x08))
62 output_simple_chars(config,list,"<BR>",enc);
63 else if ((data[i] == 0x0b) || (data[i] == 0x0c))
64 output_simple_chars(config,list,"-",enc);
65 else if ((data[i] == 0x0f) || (data[i] == 0x09) || (data[i] == 0x0a))
66 output_simple_chars(config,list," ",enc);
67 else if (data[i] >= 0x20)
68 output_char(config,list,data[i],enc);
69 }
70 }
71
72 void header(const psiconv_config config, psiconv_list list, const encoding enc)
73 {
74 output_simple_chars(config,list,"<!DOCTYPE html PUBLIC "
75 "\"-//W3C//DTD HTML 4.01 Transitional//EN\" "
76 "\"http://www.w3.org/TR/html4/loose.dtd\">\n",
77 enc);
78 output_simple_chars(config,list,"<HTML>\n",enc);
79 output_simple_chars(config,list,"<HEAD>\n",enc);
80 output_simple_chars(config,list,"<META HTTP-EQUIV=\"Content-Type\" "
81 "CONTENT=\"text/html; charset=",enc);
82 output_simple_chars(config,list,enc==ENCODING_UTF8?"UTF-8":
83 enc==ENCODING_UCS2?"UTF-16BE":
84 enc==ENCODING_ASCII?"US-ASCII":
85 "",enc);
86 output_simple_chars(config,list,"\">\n",enc);
87 output_simple_chars(config,list,"<TITLE>EPOC32 file "
88 "converted by psiconv</TITLE>\n",enc);
89 output_simple_chars(config,list,"</HEAD>\n",enc);
90 output_simple_chars(config,list,"<BODY>\n",enc);
91 }
92
93 void footer(const psiconv_config config, psiconv_list list, const encoding enc)
94 {
95 output_simple_chars(config,list,"</BODY>\n",enc);
96 output_simple_chars(config,list,"</HTML>\n",enc);
97 }
98
99
100 void characters(const psiconv_config config, psiconv_list list,
101 const psiconv_string_t textstr,
102 const psiconv_character_layout layout,const encoding enc)
103 {
104 char tempstr[TEMPSTR_LEN];
105
106 output_simple_chars(config,list,"<FONT face=\"",enc);
107 output_simple_chars(config,list,
108 layout->font->screenfont == psiconv_font_serif?"serif":
109 layout->font->screenfont == psiconv_font_sansserif?"sans-serif":
110 layout->font->screenfont == psiconv_font_nonprop?"monospace":
111 layout->font->screenfont == psiconv_font_misc?"fantasy":"",
112 enc);
113 output_simple_chars(config,list,"\"",enc);
114
115 if ((layout->font_size < 10) || (layout->font_size >= 13)) {
116 output_simple_chars(config,list," size=",enc);
117 output_simple_chars(config,list,
118 layout->font_size < 8 ?"1":
119 layout->font_size < 10 ?"2":
120 layout->font_size < 13 ?"3":
121 layout->font_size < 17 ?"4":
122 layout->font_size < 24 ?"5":
123 layout->font_size < 36 ?"6":"7",enc);
124 }
125 if ((layout->color->red != 0) || (layout->color->green != 0) ||
126 (layout->color->blue != 0)) {
127 snprintf(tempstr,TEMPSTR_LEN,"%02x%02x%02x",
128 layout->color->red,layout->color->green,layout->color->blue);
129 output_simple_chars(config,list," color=#",enc);
130 output_simple_chars(config,list,tempstr,enc);
131 }
132 output_simple_chars(config,list,">",enc);
133
134
135 if (layout->italic)
136 output_simple_chars(config,list,"<I>",enc);
137 if (layout->bold)
138 output_simple_chars(config,list,"<B>",enc);
139 if (layout->super_sub != psiconv_normalscript)
140 output_simple_chars(config,list,
141 layout->super_sub == psiconv_superscript?"<SUP>":
142 layout->super_sub == psiconv_subscript?"<SUB>":
143 "",enc);
144 if (layout->strikethrough)
145 output_simple_chars(config,list,"<S>",enc);
146 if (layout->underline)
147 output_simple_chars(config,list,"<U>",enc);
148
149 text(config,list,textstr,enc);
150
151 if (layout->underline)
152 output_simple_chars(config,list,"</U>",enc);
153 if (layout->strikethrough)
154 output_simple_chars(config,list,"</S>",enc);
155 if (layout->super_sub != psiconv_normalscript)
156 output_simple_chars(config,list,
157 layout->super_sub == psiconv_superscript?"</SUP>":
158 layout->super_sub == psiconv_subscript?"</SUB>":
159 "",enc);
160 if (layout->bold)
161 output_simple_chars(config,list,"</B>",enc);
162 if (layout->italic)
163 output_simple_chars(config,list,"</I>",enc);
164 output_simple_chars(config,list,"</FONT>",enc);
165 }
166
167 void paragraph(const psiconv_config config, psiconv_list list,
168 psiconv_paragraph para, const encoding enc)
169 {
170 int i,charnr;
171 psiconv_string_t text;
172 psiconv_in_line_layout layout;
173
174
175 output_simple_chars(config,list,
176 para->base_paragraph->bullet->on?"<UL><LI":"<P",enc);
177
178 if (para->base_paragraph->justify_hor == psiconv_justify_centre)
179 output_simple_chars(config,list," align=center",enc);
180 else if (para->base_paragraph->justify_hor == psiconv_justify_right)
181 output_simple_chars(config,list," align=right",enc);
182 else if (para->base_paragraph->justify_hor == psiconv_justify_full)
183 output_simple_chars(config,list," align=justify",enc);
184
185 output_simple_chars(config,list,">",enc);
186
187 if (psiconv_list_length(para->in_lines) == 0) {
188 characters(config,list,para->text,para->base_character,enc);
189 } else {
190 charnr = 0;
191 for (i = 0; i < psiconv_list_length(para->in_lines); i++) {
192 if (!(layout = psiconv_list_get(para->in_lines,i))) {
193 fputs("Internal data structures corruption\n",stderr);
194 exit(1);
195 }
196 if (!(text = malloc(sizeof (*text) * (layout->length + 1)))) {
197 fputs("Out of memory error\n",stderr);
198 exit(1);
199 }
200 memcpy(text,para->text+charnr,layout->length * sizeof(*text));
201 text[layout->length] = 0;
202 characters(config,list,text,layout->layout,enc);
203 free(text);
204 charnr += layout->length;
205 }
206 }
207 output_simple_chars(config, list,
208 para->base_paragraph->bullet->on?"</UL>\n":"\n",enc);
209 }
210
211 void paragraphs(const psiconv_config config, psiconv_list list,
212 psiconv_text_and_layout paragraphs, const encoding enc)
213 {
214 int i;
215 psiconv_paragraph para;
216 for (i = 0; i < psiconv_list_length(paragraphs); i++) {
217 if (!(para = psiconv_list_get(paragraphs,i))) {
218 fputs("Internal datastructure corruption\n",stderr);
219 exit(1);
220 }
221 paragraph(config,list,para,enc);
222 }
223 }
224
225 void gen_word(const psiconv_config config, psiconv_list list,
226 const psiconv_word_f file, const encoding enc)
227 {
228 if (!file)
229 return;
230
231 header(config,list,enc);
232 paragraphs(config,list,file->paragraphs,enc);
233 footer(config,list,enc);
234 }
235
236
237 void gen_texted(const psiconv_config config, psiconv_list list,
238 const psiconv_texted_f file, const encoding enc)
239 {
240 header(config,list,enc);
241 paragraphs(config,list,file->texted_sec->paragraphs,enc);
242 footer(config,list,enc);
243 }
244
245 int gen_html4(const psiconv_config config, psiconv_list list,
246 const psiconv_file file, const char *dest,
247 const encoding enc)
248 {
249 encoding enc1 = enc;
250
251 if (enc == ENCODING_PSION) {
252 fputs("Unsupported encoding\n",stderr);
253 return -1;
254 } else if (enc == ENCODING_ASCII)
255 enc1 = ENCODING_ASCII_HTML;
256
257 if (file->type == psiconv_word_file) {
258 gen_word(config,list,(psiconv_word_f) file->file,enc1);
259 return 0;
260 } else if (file->type == psiconv_texted_file) {
261 gen_texted(config,list,(psiconv_texted_f) file->file,enc1);
262 return 0;
263 } else
264 return -1;
265 }
266
267
268 static struct fileformat_s ffs[] =
269 {
270 {
271 "HTML4",
272 "HTML 4.01 Transitional, without CSS",
273 FORMAT_WORD | FORMAT_TEXTED,
274 gen_html4
275 },
276 {
277 NULL,
278 NULL,
279 0,
280 NULL
281 }
282 };
283
284
285 void init_html4(void)
286 {
287 int i;
288 for (i = 0; ffs[i].name; i++)
289 psiconv_list_add(fileformat_list,ffs+i);
290 }

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