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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 192 Revision 267
1/*
1/* gen_html.c - Part of psiconv, a PSION 5 file formats converter 2 gen_html.c - Part of psiconv, a PSION 5 file formats converter
2 Copyright (c) 1999-2004 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 1999-2004 Frodo Looijaard <frodol@dds.nl>
3 4
4 This program is free software; you can redistribute it and/or modify 5 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 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 the Free Software Foundation; either version 2 of the License, or
46 psiconv_text_and_layout paragraphs, const encoding enc); 47 psiconv_text_and_layout paragraphs, const encoding enc);
47static void gen_word(const psiconv_config config, psiconv_list list, 48static void gen_word(const psiconv_config config, psiconv_list list,
48 const psiconv_word_f file, const encoding enc); 49 const psiconv_word_f file, const encoding enc);
49static void gen_texted(const psiconv_config config, psiconv_list list, 50static void gen_texted(const psiconv_config config, psiconv_list list,
50 const psiconv_texted_f file, const encoding enc); 51 const psiconv_texted_f file, const encoding enc);
52static int gen_html4(const psiconv_config config, psiconv_list list,
53 const psiconv_file file, const char *dest,
54 const encoding enc);
51 55
52 56
53void text(const psiconv_config config,psiconv_list list, 57void text(const psiconv_config config,psiconv_list list,
54 psiconv_string_t data,const encoding enc) 58 psiconv_string_t data,const encoding enc)
55{ 59{
57 for (i = 0; i < psiconv_unicode_strlen(data); i++) { 61 for (i = 0; i < psiconv_unicode_strlen(data); i++) {
58 if ((data[i] == 0x06) || (data[i] == 0x07) || (data[i] == 0x08)) 62 if ((data[i] == 0x06) || (data[i] == 0x07) || (data[i] == 0x08))
59 output_simple_chars(config,list,"<BR>",enc); 63 output_simple_chars(config,list,"<BR>",enc);
60 else if ((data[i] == 0x0b) || (data[i] == 0x0c)) 64 else if ((data[i] == 0x0b) || (data[i] == 0x0c))
61 output_simple_chars(config,list,"-",enc); 65 output_simple_chars(config,list,"-",enc);
62 else if (data[i] == 0x0f) 66 else if ((data[i] == 0x0f) || (data[i] == 0x09) || (data[i] == 0x0a))
63 output_simple_chars(config,list," ",enc); 67 output_simple_chars(config,list," ",enc);
64 else if (data[i] >= 0x20) 68 else if (data[i] >= 0x20)
65 output_char(config,list,data[i],enc); 69 output_char(config,list,data[i],enc);
66 } 70 }
67} 71}
91{ 95{
92 output_simple_chars(config,list,"</BODY>\n",enc); 96 output_simple_chars(config,list,"</BODY>\n",enc);
93 output_simple_chars(config,list,"</HTML>\n",enc); 97 output_simple_chars(config,list,"</HTML>\n",enc);
94} 98}
95 99
100int character_layout_equal(const psiconv_character_layout l1,
101 const psiconv_character_layout l2)
102{
103 int font_size1,font_size2;
96 104
105 font_size1 = l1->font_size < 8 ?1:
106 l1->font_size < 10 ?2:
107 l1->font_size < 13 ?3:
108 l1->font_size < 17 ?4:
109 l1->font_size < 24 ?5:
110 l1->font_size < 36 ?6:7;
111 font_size2 = l2->font_size < 8 ?1:
112 l2->font_size < 10 ?2:
113 l2->font_size < 13 ?3:
114 l2->font_size < 17 ?4:
115 l2->font_size < 24 ?5:
116 l2->font_size < 36 ?6:7;
117
118 return (l1 && l2 &&
119 (l1->color->red == l2->color->red) &&
120 (l1->color->green == l2->color->green) &&
121 (l1->color->blue == l2->color->blue) &&
122 (font_size1 == font_size2) &&
123 (l1->italic == l2->italic) &&
124 (l1->bold == l2->bold) &&
125 (l1->super_sub == l2->super_sub) &&
126 (l1->underline == l2->underline) &&
127 (l1->strikethrough == l2->strikethrough) &&
128 (l1->font->screenfont == l2->font->screenfont));
129}
130
97void characters(const psiconv_config config, psiconv_list list, 131void characters(const psiconv_config config, psiconv_list list,
98 const psiconv_string_t textstr, 132 const psiconv_string_t textstr,
99 const psiconv_character_layout layout,const encoding enc) 133 const psiconv_character_layout layout,const encoding enc)
100{ 134{
101 char tempstr[TEMPSTR_LEN]; 135 char tempstr[TEMPSTR_LEN];
162} 196}
163 197
164void paragraph(const psiconv_config config, psiconv_list list, 198void paragraph(const psiconv_config config, psiconv_list list,
165 psiconv_paragraph para, const encoding enc) 199 psiconv_paragraph para, const encoding enc)
166{ 200{
167 int i,charnr; 201 int i,charnr,start,len;
168 psiconv_string_t text; 202 psiconv_string_t text;
169 psiconv_in_line_layout layout; 203 psiconv_in_line_layout layout,next_layout;
170 204
171 205
172 output_simple_chars(config,list, 206 output_simple_chars(config,list,
173 para->base_paragraph->bullet->on?"<UL><LI":"<P",enc); 207 para->base_paragraph->bullet->on?"<UL><LI":"<P",enc);
174 208
180 output_simple_chars(config,list," align=justify",enc); 214 output_simple_chars(config,list," align=justify",enc);
181 215
182 output_simple_chars(config,list,">",enc); 216 output_simple_chars(config,list,">",enc);
183 217
184 if (psiconv_list_length(para->in_lines) == 0) { 218 if (psiconv_list_length(para->in_lines) == 0) {
219 if (psiconv_unicode_strlen(para->text))
185 characters(config,list,para->text,para->base_character,enc); 220 characters(config,list,para->text,para->base_character,enc);
186 } else { 221 } else {
187 charnr = 0; 222 charnr = 0;
223 start = -1;
188 for (i = 0; i < psiconv_list_length(para->in_lines); i++) { 224 for (i = 0; i < psiconv_list_length(para->in_lines); i++) {
225 if (start < 0)
226 start = charnr;
189 if (!(layout = psiconv_list_get(para->in_lines,i))) { 227 if (!(layout = psiconv_list_get(para->in_lines,i))) {
190 fputs("Internal data structures corruption\n",stderr); 228 fputs("Internal data structures corruption\n",stderr);
191 exit(1); 229 exit(1);
192 } 230 }
193 if (!(text = malloc(sizeof (*text) * (layout->length + 1)))) { 231 if (i+1 < psiconv_list_length(para->in_lines)) {
194 fputs("Out of memory error\n",stderr); 232 if (!(next_layout = psiconv_list_get(para->in_lines,i+1))) {
233 fputs("Internal data structures corruption\n",stderr);
195 exit(1); 234 exit(1);
235 }
236 } else {
237 next_layout = NULL;
196 } 238 }
239 if (next_layout &&
240 character_layout_equal(layout->layout,next_layout->layout)) {
241 charnr += layout->length;
242 continue;
243 }
244 len = charnr - start + layout->length;
245 if (len) {
246 if (!(text = malloc(sizeof (*text) * (len + 1)))) {
247 fputs("Out of memory error\n",stderr);
248 exit(1);
249 }
197 memcpy(text,para->text+charnr,layout->length * sizeof(*text)); 250 memcpy(text,para->text+charnr,len * sizeof(*text));
198 text[layout->length] = 0; 251 text[len] = 0;
199 characters(config,list,text,layout->layout,enc); 252 characters(config,list,text,layout->layout,enc);
200 free(text); 253 free(text);
254 }
201 charnr += layout->length; 255 charnr += layout->length;
256 start = -1;
202 } 257 }
203 } 258 }
204 output_simple_chars(config, list, 259 output_simple_chars(config, list,
205 para->base_paragraph->bullet->on?"</UL>\n":"\n",enc); 260 para->base_paragraph->bullet->on?"</UL>\n":"\n",enc);
206} 261}
260 } else 315 } else
261 return -1; 316 return -1;
262} 317}
263 318
264 319
265static struct fileformat_s ffs[] = 320static struct fileformat_s fileformats[] =
266 { 321 {
267 { 322 {
268 "HTML4", 323 "HTML4",
269 "HTML 4.01 Transitional, without CSS", 324 "HTML 4.01 Transitional, without CSS",
270 FORMAT_WORD | FORMAT_TEXTED, 325 FORMAT_WORD | FORMAT_TEXTED,
280 335
281 336
282void init_html4(void) 337void init_html4(void)
283{ 338{
284 int i; 339 int i;
285 for (i = 0; ffs[i].name; i++) 340 for (i = 0; fileformats[i].name; i++)
286 psiconv_list_add(fileformat_list,ffs+i); 341 psiconv_list_add(fileformat_list,fileformats+i);
287} 342}

Legend:
Removed from v.192  
changed lines
  Added in v.267

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