… | |
… | |
14 | |
14 | |
15 | You should have received a copy of the GNU General Public License |
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 |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 | */ |
18 | */ |
|
|
19 | /* |
|
|
20 | 2002/Apr. Keita KAWABE |
|
|
21 | A: <META HTTP-EQUIV="Content-Type" CONTENT="text/html"> header |
|
|
22 | was added. |
|
|
23 | |
|
|
24 | B: Support for narrow build Asian Psions added. |
|
|
25 | If the encoding_type is PSICONV_ENCODING_UTF8, |
|
|
26 | B-1: use utf8_table for character conversion. |
|
|
27 | B-2: add the "Charset=UTF-8" in the Content-Type header. |
|
|
28 | Otherwise proceed as normal. |
|
|
29 | */ |
19 | |
30 | |
20 | #include "config.h" |
31 | #include "config.h" |
21 | #include <stdio.h> |
32 | #include <stdio.h> |
22 | #include <string.h> |
33 | #include <string.h> |
23 | #include <stdlib.h> |
34 | #include <stdlib.h> |
24 | #include "data.h" |
35 | #include "psiconv/data.h" |
25 | #include "list.h" |
36 | #include "psiconv/list.h" |
26 | #include "gen.h" |
37 | #include "gen.h" |
27 | #include "psiconv.h" |
38 | #include "psiconv.h" |
|
|
39 | |
|
|
40 | #ifdef DMALLOC |
|
|
41 | #include "dmalloc.h" |
|
|
42 | #endif |
28 | |
43 | |
29 | /* This determines for each character how it is displayed */ |
44 | /* This determines for each character how it is displayed */ |
30 | static const char *char_table[0x100] = |
45 | static const char *char_table[0x100] = |
31 | { |
46 | { |
32 | /* 0x00 */ "" ,"" ,"" ,"" ,"" ,"" ,"<P> ","<BR>" , |
47 | /* 0x00 */ "" ,"" ,"" ,"" ,"" ,"" ,"<P> ","<BR>" , |
… | |
… | |
74 | "ô","õ","ö","÷", |
89 | "ô","õ","ö","÷", |
75 | /* 0xf8 */ "ø","ù","ú","û", |
90 | /* 0xf8 */ "ø","ù","ú","û", |
76 | "ü","ý","þ","ÿ" |
91 | "ü","ý","þ","ÿ" |
77 | }; |
92 | }; |
78 | |
93 | |
|
|
94 | static const char *utf_table[0x100] = |
|
|
95 | { |
|
|
96 | /* 0x00 */ "" ,"" ,"" ,"" ,"" ,"" ,"<P> ","<BR>" , |
|
|
97 | /* 0x08 */ "<P>" ," " ,"" ,"" ,"" ,"" ,"" ,"" , |
|
|
98 | /* 0x10 */ " " ,"" ,"" ,"" ,"" ,"" ,"" ,"" , |
|
|
99 | /* 0x18 */ "" ,"" ,"" ,"" ,"" ,"" ,"" ,"" , |
|
|
100 | /* 0x20 */ " " ,"!" ,""","#" ,"$" ,"%" ,"&","'" , |
|
|
101 | /* 0x28 */ "(" ,")" ,"*" ,"+" ,"," ,"-" ,"." ,"/" , |
|
|
102 | /* 0x30 */ "0" ,"1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7" , |
|
|
103 | /* 0x38 */ "8" ,"9" ,":" ,";" ,"<" ,"=" ,">" ,"?" , |
|
|
104 | /* 0x40 */ "@" ,"A" ,"B" ,"C" ,"D" ,"E" ,"F" ,"G" , |
|
|
105 | /* 0x48 */ "H" ,"I" ,"J" ,"K" ,"L" ,"M" ,"N" ,"O" , |
|
|
106 | /* 0x50 */ "P" ,"Q" ,"R" ,"S" ,"T" ,"U" ,"V" ,"W" , |
|
|
107 | /* 0x58 */ "X" ,"Y" ,"Z" ,"[" ,"\\" ,"]" ,"^" ,"_" , |
|
|
108 | /* 0x60 */ "`" ,"a" ,"b" ,"c" ,"d" ,"e" ,"f" ,"g" , |
|
|
109 | /* 0x68 */ "h" ,"i" ,"j" ,"k" ,"l" ,"m" ,"n" ,"o" , |
|
|
110 | /* 0x70 */ "p" ,"q" ,"r" ,"s" ,"t" ,"u" ,"v" ,"w" , |
|
|
111 | /* 0x78 */ "x" ,"y" ,"z" ,"{" ,"|" ,"}" ,"~" ,"" , |
|
|
112 | /* 0x80 */ "\x80", "\x81", "\x82", "\x83", "\x84", "\x85", "\x86", "\x87", |
|
|
113 | /* 0x88 */ "\x88", "\x89", "\x8a", "\x8b", "\x8c", "\x8d", "\x8e", "\x8f", |
|
|
114 | /* 0x90 */ "\x90", "\x91", "\x92", "\x93", "\x94", "\x95", "\x96", "\x97", |
|
|
115 | /* 0x98 */ "\x98", "\x99", "\x9a", "\x9b", "\x9c", "\x9d", "\x9e", "\x9f", |
|
|
116 | /* 0xa0 */ "\xa0", "\xa1", "\xa2", "\xa3", "\xa4", "\xa5", "\xa6", "\xa7", |
|
|
117 | /* 0xa8 */ "\xa8", "\xa9", "\xaa", "\xab", "\xac", "\xad", "\xae", "\xaf", |
|
|
118 | /* 0xb0 */ "\xb0", "\xb1", "\xb2", "\xb3", "\xb4", "\xb5", "\xb6", "\xb7", |
|
|
119 | /* 0xb8 */ "\xb8", "\xb9", "\xba", "\xbb", "\xbc", "\xbd", "\xbe", "\xbf", |
|
|
120 | /* 0xc0 */ "\xc0", "\xc1", "\xc2", "\xc3", "\xc4", "\xc5", "\xc6", "\xc7", |
|
|
121 | /* 0xc8 */ "\xc8", "\xc9", "\xca", "\xcb", "\xcc", "\xcd", "\xce", "\xcf", |
|
|
122 | /* 0xd0 */ "\xd0", "\xd1", "\xd2", "\xd3", "\xd4", "\xd5", "\xd6", "\xd7", |
|
|
123 | /* 0xd8 */ "\xd8", "\xd9", "\xda", "\xdb", "\xdc", "\xdd", "\xde", "\xdf", |
|
|
124 | /* 0xe0 */ "\xe0", "\xe1", "\xe2", "\xe3", "\xe4", "\xe5", "\xe6", "\xe7", |
|
|
125 | /* 0xe8 */ "\xe8", "\xe9", "\xea", "\xeb", "\xec", "\xed", "\xee", "\xef", |
|
|
126 | /* 0xf0 */ "\xf0", "\xf1", "\xf2", "\xf3", "\xf4", "\xf5", "\xf6", "\xf7", |
|
|
127 | /* 0xf8 */ "\xf8", "\xf9", "\xfa", "\xfb", "\xfc", "\xfd", "\xfe", "\xff", |
|
|
128 | }; |
|
|
129 | |
|
|
130 | /* a flag to indicate the use of UTF8 */ |
|
|
131 | static psiconv_encoding encoding= PSICONV_ENCODING_CP1252; |
|
|
132 | |
79 | static psiconv_character_layout gen_base_char(const psiconv_font font, |
133 | static psiconv_character_layout gen_base_char(const psiconv_font font, |
80 | const psiconv_color color, |
134 | const psiconv_color color, |
81 | const psiconv_color back_color); |
135 | const psiconv_color back_color); |
82 | static void diff_char(FILE *of, const psiconv_character_layout old, |
136 | static void diff_char(FILE *of, const psiconv_character_layout old, |
83 | const psiconv_character_layout new, int *flags); |
137 | const psiconv_character_layout new, int *flags); |
… | |
… | |
91 | This one is specific for the base point of HTML */ |
145 | This one is specific for the base point of HTML */ |
92 | psiconv_character_layout gen_base_char(const psiconv_font font, |
146 | psiconv_character_layout gen_base_char(const psiconv_font font, |
93 | const psiconv_color color, |
147 | const psiconv_color color, |
94 | const psiconv_color back_color) |
148 | const psiconv_color back_color) |
95 | { |
149 | { |
96 | struct psiconv_character_layout base_char_struct = |
150 | struct psiconv_character_layout_s base_char_struct = |
97 | { |
151 | { |
98 | NULL, /* color */ |
152 | NULL, /* color */ |
99 | NULL, /* back_color */ |
153 | NULL, /* back_color */ |
100 | 13.0, /* font_size */ |
154 | 13.0, /* font_size */ |
101 | psiconv_bool_false, /* italic */ |
155 | psiconv_bool_false, /* italic */ |
102 | psiconv_bool_false, /* bold */ |
156 | psiconv_bool_false, /* bold */ |
103 | psiconv_normalscript, /* super_sub */ |
157 | psiconv_normalscript, /* super_sub */ |
104 | psiconv_bool_false, /* underline */ |
158 | psiconv_bool_false, /* underline */ |
105 | psiconv_bool_false, /* strike_out */ |
159 | psiconv_bool_false, /* strikethrough */ |
106 | NULL, /* font */ |
160 | NULL, /* font */ |
107 | }; |
161 | }; |
108 | base_char_struct.color = color; |
162 | base_char_struct.color = color; |
109 | base_char_struct.back_color = back_color; |
163 | base_char_struct.back_color = back_color; |
110 | base_char_struct.font = font; |
164 | base_char_struct.font = font; |
… | |
… | |
131 | fputs("</I>",of); |
185 | fputs("</I>",of); |
132 | if (old->bold) |
186 | if (old->bold) |
133 | fputs("</B>",of); |
187 | fputs("</B>",of); |
134 | if (old->underline) |
188 | if (old->underline) |
135 | fputs("</U>",of); |
189 | fputs("</U>",of); |
136 | if (old->strike_out) |
190 | if (old->strikethrough) |
137 | fputs("</STRIKE>",of); |
191 | fputs("</STRIKE>",of); |
138 | if (old->super_sub == psiconv_superscript) |
192 | if (old->super_sub == psiconv_superscript) |
139 | fputs("</SUP>",of); |
193 | fputs("</SUP>",of); |
140 | if (old->super_sub == psiconv_subscript) |
194 | if (old->super_sub == psiconv_subscript) |
141 | fputs("</SUB>",of); |
195 | fputs("</SUB>",of); |
… | |
… | |
158 | fputs("6",of); |
212 | fputs("6",of); |
159 | else |
213 | else |
160 | fputs("7",of); |
214 | fputs("7",of); |
161 | fprintf(of," COLOR=#%02x%02x%02x",new->color->red,new->color->green, |
215 | fprintf(of," COLOR=#%02x%02x%02x",new->color->red,new->color->green, |
162 | new->color->blue); |
216 | new->color->blue); |
163 | if (new->font->screenfont == 1) |
217 | if (new->font->screenfont == psiconv_font_sansserif) |
164 | fprintf(of," FACE=\"%s, Sans-Serif\">",new->font->name); |
218 | fprintf(of," FACE=\"%s, Sans-Serif\">",new->font->name); |
165 | else if (new->font->screenfont == 2) |
219 | else if (new->font->screenfont == psiconv_font_nonprop) |
166 | fprintf(of," FACE=\"%s, Monospace\">",new->font-> name); |
220 | fprintf(of," FACE=\"%s, Monospace\">",new->font-> name); |
167 | else if (new->font->screenfont == 3) |
221 | else if (new->font->screenfont == psiconv_font_serif) |
168 | fprintf(of," FACE=\"%s, Serif\">",new->font-> name); |
222 | fprintf(of," FACE=\"%s, Serif\">",new->font-> name); |
169 | else |
223 | else |
170 | fprintf(of," FACE=\"%s, Serif\">",new->font-> name); |
224 | fprintf(of," FACE=\"%s, Serif\">",new->font-> name); |
171 | } |
225 | } |
172 | if (new->italic) |
226 | if (new->italic) |
173 | fputs("<I>",of); |
227 | fputs("<I>",of); |
174 | if (new->bold) |
228 | if (new->bold) |
175 | fputs("<B>",of); |
229 | fputs("<B>",of); |
176 | if (new->underline) |
230 | if (new->underline) |
177 | fputs("<U>",of); |
231 | fputs("<U>",of); |
178 | if (new->strike_out) |
232 | if (new->strikethrough) |
179 | fputs("<STRIKE>",of); |
233 | fputs("<STRIKE>",of); |
180 | if (new->super_sub == psiconv_superscript) |
234 | if (new->super_sub == psiconv_superscript) |
181 | fputs("<SUP>",of); |
235 | fputs("<SUP>",of); |
182 | if (new->super_sub == psiconv_subscript) |
236 | if (new->super_sub == psiconv_subscript) |
183 | fputs("<SUB>",of); |
237 | fputs("<SUB>",of); |
… | |
… | |
198 | if (old->underline) |
252 | if (old->underline) |
199 | fputs("</U>",of); |
253 | fputs("</U>",of); |
200 | else |
254 | else |
201 | fputs("<U>",of); |
255 | fputs("<U>",of); |
202 | } |
256 | } |
203 | if (old->strike_out != new->strike_out) { |
257 | if (old->strikethrough != new->strikethrough) { |
204 | if (old->strike_out) |
258 | if (old->strikethrough) |
205 | fputs("</STRIKE>",of); |
259 | fputs("</STRIKE>",of); |
206 | else |
260 | else |
207 | fputs("<STRIKE>",of); |
261 | fputs("<STRIKE>",of); |
208 | } |
262 | } |
209 | if (old->super_sub != new->super_sub) { |
263 | if (old->super_sub != new->super_sub) { |
… | |
… | |
224 | { |
278 | { |
225 | int i,j,loc; |
279 | int i,j,loc; |
226 | psiconv_character_layout cur_char; |
280 | psiconv_character_layout cur_char; |
227 | psiconv_in_line_layout inl; |
281 | psiconv_in_line_layout inl; |
228 | int flags = 0; |
282 | int flags = 0; |
|
|
283 | |
|
|
284 | char **table; |
|
|
285 | if (encoding == PSICONV_ENCODING_UTF8){ |
|
|
286 | table=(char**)utf_table; |
|
|
287 | }else{ |
|
|
288 | table=(char**)char_table; |
|
|
289 | } |
|
|
290 | |
229 | |
291 | |
230 | |
292 | |
231 | fputs("<P",of); |
293 | fputs("<P",of); |
232 | if (para->base_paragraph->justify_hor == psiconv_justify_left) |
294 | if (para->base_paragraph->justify_hor == psiconv_justify_left) |
233 | fputs(" ALIGN=left",of); |
295 | fputs(" ALIGN=left",of); |
… | |
… | |
252 | for (i = 0; i < psiconv_list_length(para->in_lines); i++) { |
314 | for (i = 0; i < psiconv_list_length(para->in_lines); i++) { |
253 | inl = psiconv_list_get(para->in_lines,i); |
315 | inl = psiconv_list_get(para->in_lines,i); |
254 | diff_char(of,cur_char,inl->layout,&flags); |
316 | diff_char(of,cur_char,inl->layout,&flags); |
255 | cur_char = inl->layout; |
317 | cur_char = inl->layout; |
256 | for (j = loc; j < inl->length + loc; j ++) { |
318 | for (j = loc; j < inl->length + loc; j ++) { |
257 | fputs(char_table[(unsigned char) (para->text[j])],of); |
319 | fputs(table[(unsigned char) (para->text[j])],of); |
258 | } |
320 | } |
259 | loc = j; |
321 | loc = j; |
260 | } |
322 | } |
261 | |
323 | |
262 | if (loc < strlen(para->text)) { |
324 | if (loc < strlen(para->text)) { |
263 | diff_char(of,cur_char,para->base_character,&flags); |
325 | diff_char(of,cur_char,para->base_character,&flags); |
264 | cur_char = para->base_character; |
326 | cur_char = para->base_character; |
265 | for (j = loc; j < strlen(para->text); j ++) { |
327 | for (j = loc; j < strlen(para->text); j ++) { |
266 | fputs(char_table[(unsigned char) (para->text[j])],of); |
328 | fputs(table[(unsigned char) (para->text[j])],of); |
267 | } |
329 | } |
268 | } |
330 | } |
269 | |
331 | |
270 | if (strlen(para->text) == 0) |
332 | if (strlen(para->text) == 0) |
271 | fputs("<BR>",of); |
333 | fputs("<BR>",of); |
… | |
… | |
278 | |
340 | |
279 | fputs("</P>\n",of); |
341 | fputs("</P>\n",of); |
280 | } |
342 | } |
281 | |
343 | |
282 | int psiconv_gen_html(const char * filename,const psiconv_file file, |
344 | int psiconv_gen_html(const char * filename,const psiconv_file file, |
283 | const char *dest) |
345 | const char *dest, const psiconv_encoding encoding_type) |
284 | { |
346 | { |
285 | FILE *of = fopen(filename,"w"); |
347 | FILE *of = fopen(filename,"w"); |
286 | if (! of) |
348 | if (! of) |
287 | return -1; |
349 | return -1; |
|
|
350 | |
|
|
351 | encoding = encoding_type; |
288 | |
352 | |
289 | if (file->type == psiconv_word_file) { |
353 | if (file->type == psiconv_word_file) { |
290 | psiconv_gen_html_word(of,(psiconv_word_f) file->file); |
354 | psiconv_gen_html_word(of,(psiconv_word_f) file->file); |
291 | } else if (file->type == psiconv_texted_file) { |
355 | } else if (file->type == psiconv_texted_file) { |
292 | psiconv_gen_html_texted(of,(psiconv_texted_f) file->file); |
356 | psiconv_gen_html_texted(of,(psiconv_texted_f) file->file); |
… | |
… | |
307 | base_char = psiconv_basic_character_layout(); |
371 | base_char = psiconv_basic_character_layout(); |
308 | |
372 | |
309 | fputs("<!doctype html public \"-//W3C//DTD HTML 3.2 Final//EN\">", of); |
373 | fputs("<!doctype html public \"-//W3C//DTD HTML 3.2 Final//EN\">", of); |
310 | fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); |
374 | fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); |
311 | fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of); |
375 | fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of); |
|
|
376 | |
|
|
377 | fputs(" <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html", of); |
|
|
378 | if (encoding == PSICONV_ENCODING_UTF8){ |
|
|
379 | fputs("; CHARSET=UTF-8", of); |
|
|
380 | } |
|
|
381 | fputs("\">\n", of); |
|
|
382 | |
|
|
383 | fputs("</HEAD>\n",of); |
312 | fputs("<BODY>\n",of); |
384 | fputs("<BODY>\n",of); |
313 | for (i = 0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) { |
385 | for (i = 0; i < psiconv_list_length(tf->texted_sec->paragraphs); i++) { |
314 | para = psiconv_list_get(tf->texted_sec->paragraphs,i); |
386 | para = psiconv_list_get(tf->texted_sec->paragraphs,i); |
315 | gen_para(of,para,base_char); |
387 | gen_para(of,para,base_char); |
316 | } |
388 | } |
… | |
… | |
343 | psiconv_free_color(white); |
415 | psiconv_free_color(white); |
344 | |
416 | |
345 | fputs("<!doctype html public \"-//W3C//DTD HTML 3.2 Final//EN\">", of); |
417 | fputs("<!doctype html public \"-//W3C//DTD HTML 3.2 Final//EN\">", of); |
346 | fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); |
418 | fputs("\n<HTML>\n<HEAD>\n <META NAME=\"GENERATOR\"", of); |
347 | fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of); |
419 | fputs(" CONTENT=\"psiconv-" VERSION "\">\n", of); |
|
|
420 | |
|
|
421 | fputs(" <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html", of); |
|
|
422 | if (encoding == PSICONV_ENCODING_UTF8) |
|
|
423 | fputs("; CHARSET=UTF-8", of); |
|
|
424 | fputs("\">\n", of); |
|
|
425 | |
|
|
426 | fputs("</HEAD>\n",of); |
348 | fputs("<BODY>\n",of); |
427 | fputs("<BODY>\n",of); |
349 | |
428 | |
350 | for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { |
429 | for (i = 0; i < psiconv_list_length(wf->paragraphs); i++) { |
351 | para = psiconv_list_get(wf->paragraphs,i); |
430 | para = psiconv_list_get(wf->paragraphs,i); |
352 | gen_para(of,para,base_char); |
431 | gen_para(of,para,base_char); |
353 | } |
432 | } |
354 | fputs("</BODY>\n</HTML>\n",of); |
433 | fputs("</BODY>\n</HTML>\n",of); |
355 | psiconv_free_character_layout(base_char); |
434 | psiconv_free_character_layout(base_char); |
356 | } |
435 | } |
357 | |
436 | |
358 | static struct psiconv_fileformat ff = |
437 | static struct psiconv_fileformat_s ff = |
359 | { |
438 | { |
360 | "HTML3", |
439 | "HTML3", |
361 | "HTML 3.2, not verified so probably not completely compliant", |
440 | "HTML 3.2, not verified so probably not completely compliant", |
362 | &psiconv_gen_html |
441 | &psiconv_gen_html |
363 | }; |
442 | }; |