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

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

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

Revision 190 Revision 191
29#include "dmalloc.h" 29#include "dmalloc.h"
30#endif 30#endif
31 31
32#define TEMPSTR_LEN 100 32#define TEMPSTR_LEN 100
33 33
34void text(const psiconv_config config,psiconv_list list,
35 psiconv_string_t data,const encoding enc)
36{
37 int i;
38 for (i = 0; i < psiconv_unicode_strlen(data); i++) {
39 if ((data[i] == 0x06) || (data[i] == 0x07) || (data[i] == 0x08))
40 output_simple_chars(config,list,"<br/>",enc);
41 else if ((data[i] == 0x0b) || (data[i] == 0x0c))
42 output_simple_chars(config,list,"-",enc);
43 else if (data[i] == 0x0f)
44 output_simple_chars(config,list," ",enc);
45 else if (data[i] >= 0x20)
46 output_char(config,list,data[i],enc);
47 }
48}
49
34void color(const psiconv_config config, psiconv_list list, 50void color(const psiconv_config config, psiconv_list list,
35 psiconv_color color,int may_be_transparant, const encoding enc) 51 psiconv_color color,int may_be_transparant, const encoding enc)
36{ 52{
37 char tempstr[TEMPSTR_LEN]; 53 char tempstr[TEMPSTR_LEN];
38 if (may_be_transparant && 54 if (may_be_transparant &&
47 color->blue); 63 color->blue);
48 output_simple_chars(config,list,tempstr,enc); 64 output_simple_chars(config,list,tempstr,enc);
49 } 65 }
50} 66}
51 67
68void border(const psiconv_config config, psiconv_list list,
69 psiconv_border_kind_t border,const encoding enc)
70{
71 output_simple_chars(config,list,
72 border == psiconv_border_none?"none":
73 border == psiconv_border_solid?"solid":
74 border == psiconv_border_double?"double":
75 border == psiconv_border_dotted?"dotted":
76 border == psiconv_border_dashed?"dashed":
77 border == psiconv_border_dotdashed?"dashed":
78 border == psiconv_border_dotdotdashed?"dashed":"",enc);
79}
80
52void style_name(const psiconv_config config, psiconv_list list, 81void style_name(const psiconv_config config, psiconv_list list,
53 const psiconv_string_t name,const encoding enc) 82 const psiconv_string_t name,const encoding enc)
54{ 83{
55 psiconv_string_t name_copy; 84 psiconv_string_t name_copy;
56 int i; 85 int i;
76 const psiconv_character_layout base, 105 const psiconv_character_layout base,
77 const encoding enc) 106 const encoding enc)
78{ 107{
79 char tempstr[TEMPSTR_LEN]; 108 char tempstr[TEMPSTR_LEN];
80 109
110 if (!base || (new->color->red != base->color->red) ||
111 (new->color->green != base->color->green) ||
112 (new->color->blue != base->color->blue)) {
113 output_simple_chars(config,list,"color:",enc);
114 color(config,list,new->color,0,enc);
115 output_simple_chars(config,list,";",enc);
116 }
117
118 if (!base || (new->back_color->red != base->back_color->red) ||
119 (new->back_color->green != base->back_color->green) ||
120 (new->back_color->blue != base->back_color->blue)) {
121 output_simple_chars(config,list,"background-color:",enc);
122 color(config,list,new->back_color,1,enc);
123 output_simple_chars(config,list,";",enc);
124 }
125
126 if (!base || (new->font_size != base->font_size)) {
127 output_simple_chars(config,list,"font-size:",enc);
128 snprintf(tempstr,TEMPSTR_LEN,"%f",new->font_size);
129 output_simple_chars(config,list,tempstr,enc);
130 output_simple_chars(config,list,"pt;",enc);
131 }
132
81 if (!base || (new->italic != base->italic)) { 133 if (!base || (new->italic != base->italic)) {
82 output_simple_chars(config,list,"font-style:",enc); 134 output_simple_chars(config,list,"font-style:",enc);
83 output_simple_chars(config,list,new->italic?"italic":"normal",enc); 135 output_simple_chars(config,list,new->italic?"italic":"normal",enc);
136 output_simple_chars(config,list,";",enc);
137 }
138 if (!base || (new->bold != base->bold)) {
139 output_simple_chars(config,list,"font-weight:",enc);
140 output_simple_chars(config,list,new->bold?"bold":"normal",enc);
141 output_simple_chars(config,list,";",enc);
142 }
143 if (!base || (new->super_sub != base->super_sub)) {
144 output_simple_chars(config,list,"font-style:",enc);
145 output_simple_chars(config,list,
146 new->super_sub==psiconv_superscript?"super":
147 new->super_sub==psiconv_subscript?"sub":
148 "normal",enc);
84 output_simple_chars(config,list,";",enc); 149 output_simple_chars(config,list,";",enc);
85 } 150 }
86 if (!base || (new->underline != base->underline) || 151 if (!base || (new->underline != base->underline) ||
87 (new->strikethrough != base->strikethrough)) { 152 (new->strikethrough != base->strikethrough)) {
88 output_simple_chars(config,list,"text-decoration:",enc); 153 output_simple_chars(config,list,"text-decoration:",enc);
89 output_simple_chars(config,list,new->underline?"underline": 154 output_simple_chars(config,list,new->underline?"underline":
90 new->strikethrough?"line-through": 155 new->strikethrough?"line-through":
91 "none",enc); 156 "none",enc);
92 output_simple_chars(config,list,";",enc); 157 output_simple_chars(config,list,";",enc);
93 } 158 }
94 if (!base || (new->bold != base->bold)) { 159 if (!base || (new->font->screenfont != base->font->screenfont)) {
95 output_simple_chars(config,list,"font-weight:",enc);
96 output_simple_chars(config,list,new->bold?"bold":"normal",enc);
97 output_simple_chars(config,list,";",enc);
98 }
99 if (!base || (new->super_sub != base->super_sub)) {
100 output_simple_chars(config,list,"font-style:",enc); 160 output_simple_chars(config,list,"font-family:",enc);
101 output_simple_chars(config,list, 161 output_simple_chars(config,list,
102 new->super_sub==psiconv_superscript?"super": 162 new->font->screenfont == psiconv_font_serif?"serif":
103 new->super_sub==psiconv_subscript?"sub": 163 new->font->screenfont == psiconv_font_sansserif?"sans-serif":
104 "normal",enc); 164 new->font->screenfont == psiconv_font_nonprop?"monospace":
105 output_simple_chars(config,list,";",enc); 165 new->font->screenfont == psiconv_font_misc?"fantasy":"",
106 } 166 enc);
107
108 if (!base || (new->color->red != base->color->red) ||
109 (new->color->green != base->color->green) ||
110 (new->color->blue != base->color->blue)) {
111 output_simple_chars(config,list,"color:",enc);
112 color(config,list,new->color,0,enc);
113 output_simple_chars(config,list,";",enc);
114 }
115
116 if (!base || (new->back_color->red != base->back_color->red) ||
117 (new->back_color->green != base->back_color->green) ||
118 (new->back_color->blue != base->back_color->blue)) {
119 output_simple_chars(config,list,"background-color:",enc);
120 color(config,list,new->back_color,1,enc);
121 output_simple_chars(config,list,";",enc);
122 }
123
124 if (!base || (new->font_size != base->font_size)) {
125 output_simple_chars(config,list,"font-size:",enc);
126 snprintf(tempstr,TEMPSTR_LEN,"%f",new->font_size);
127 output_simple_chars(config,list,tempstr,enc);
128 output_simple_chars(config,list,"pt;",enc);
129 } 167 }
130} 168}
131 169
132void paragraph_layout_diffs(const psiconv_config config, psiconv_list list, 170void paragraph_layout_diffs(const psiconv_config config, psiconv_list list,
133 const psiconv_paragraph_layout new, 171 const psiconv_paragraph_layout new,
134 const psiconv_paragraph_layout base, 172 const psiconv_paragraph_layout base,
135 const encoding enc) 173 const encoding enc)
136{ 174{
137 char tempstr[TEMPSTR_LEN]; 175 char tempstr[TEMPSTR_LEN];
176 float pad_left_base=0.0,pad_left_new,text_indent_base=0.0,text_indent_new;
177
178 if (new->bullet->on) {
179 pad_left_new = new->indent_left < new->indent_first?
180 new->indent_left:new->indent_first;
181 text_indent_new = 0.0;
182 } else {
183 pad_left_new = new->indent_left;
184 text_indent_new = new->indent_first;
185 }
186 if (base) {
187 if (base->bullet->on) {
188 pad_left_base = base->indent_left < base->indent_first?
189 base->indent_left:base->indent_first;
190 text_indent_base = 0.0;
191 } else {
192 pad_left_base = base->indent_left;
193 text_indent_base = base->indent_first;
194 }
195 }
196
138 197
139 if (!base || (new->back_color->red != base->back_color->red) || 198 if (!base || (new->back_color->red != base->back_color->red) ||
140 (new->back_color->green != base->back_color->green) || 199 (new->back_color->green != base->back_color->green) ||
141 (new->back_color->blue != base->back_color->blue)) { 200 (new->back_color->blue != base->back_color->blue)) {
142 output_simple_chars(config,list,"background-color:",enc); 201 output_simple_chars(config,list,"background-color:",enc);
143 color(config,list,new->back_color,1,enc); 202 color(config,list,new->back_color,1,enc);
144 output_simple_chars(config,list,";",enc); 203 output_simple_chars(config,list,";",enc);
145 } 204 }
146 205
147 if (!base || (new->indent_left != base->indent_left)) { 206 if (!base || (pad_left_new != pad_left_base)) {
148 output_simple_chars(config,list,"padding-left:",enc); 207 output_simple_chars(config,list,"padding-left:",enc);
149 snprintf(tempstr,TEMPSTR_LEN,"%f",new->indent_left); 208 snprintf(tempstr,TEMPSTR_LEN,"%f",pad_left_new);
150 output_simple_chars(config,list,tempstr,enc); 209 output_simple_chars(config,list,tempstr,enc);
151 output_simple_chars(config,list,"cm;",enc); 210 output_simple_chars(config,list,"cm;",enc);
152 } 211 }
153 212
154 if (!base || (new->indent_right != base->indent_right)) { 213 if (!base || (new->indent_right != base->indent_right)) {
156 snprintf(tempstr,TEMPSTR_LEN,"%f",new->indent_right); 215 snprintf(tempstr,TEMPSTR_LEN,"%f",new->indent_right);
157 output_simple_chars(config,list,tempstr,enc); 216 output_simple_chars(config,list,tempstr,enc);
158 output_simple_chars(config,list,"cm;",enc); 217 output_simple_chars(config,list,"cm;",enc);
159 } 218 }
160 219
161 if (!base || (new->indent_left - new->indent_first != 220 if (!base || (text_indent_new != text_indent_base)) {
162 base->indent_left - base->indent_first)) {
163 output_simple_chars(config,list,"text-indent:",enc); 221 output_simple_chars(config,list,"text-indent:",enc);
164 snprintf(tempstr,TEMPSTR_LEN,"%f",new->indent_right - new->indent_first); 222 snprintf(tempstr,TEMPSTR_LEN,"%f",text_indent_new);
165 output_simple_chars(config,list,tempstr,enc); 223 output_simple_chars(config,list,tempstr,enc);
166 output_simple_chars(config,list,"cm;",enc); 224 output_simple_chars(config,list,"cm;",enc);
167 } 225 }
168 226
169 if (!base || (new->justify_hor != base ->justify_hor)) { 227 if (!base || (new->justify_hor != base ->justify_hor)) {
195 output_simple_chars(config,list,"padding-bottom:",enc); 253 output_simple_chars(config,list,"padding-bottom:",enc);
196 snprintf(tempstr,TEMPSTR_LEN,"%f",new->space_below); 254 snprintf(tempstr,TEMPSTR_LEN,"%f",new->space_below);
197 output_simple_chars(config,list,tempstr,enc); 255 output_simple_chars(config,list,tempstr,enc);
198 output_simple_chars(config,list,"pt;",enc); 256 output_simple_chars(config,list,"pt;",enc);
199 } 257 }
200 258
259 if (!base || (new->right_border->kind != base->right_border->kind)) {
260 output_simple_chars(config,list,"border-right-style:",enc);
261 border(config,list,new->right_border->kind,enc);
262 output_simple_chars(config,list,";",enc);
263 }
264 if (!base || (new->bottom_border->kind != base->bottom_border->kind)) {
265 output_simple_chars(config,list,"border-bottom-style:",enc);
266 border(config,list,new->bottom_border->kind,enc);
267 output_simple_chars(config,list,";",enc);
268 }
269 if (!base || (new->top_border->kind != base->top_border->kind)) {
270 output_simple_chars(config,list,"border-top-style:",enc);
271 border(config,list,new->top_border->kind,enc);
272 output_simple_chars(config,list,";",enc);
273 }
274 if (!base || (new->left_border->kind != base->left_border->kind)) {
275 output_simple_chars(config,list,"border-left-style:",enc);
276 border(config,list,new->left_border->kind,enc);
277 output_simple_chars(config,list,";",enc);
278 }
279
280 if (!base ||
281 ((new->right_border->kind != psiconv_border_none) &&
282 (new->right_border->thickness != base->right_border->thickness))) {
283 output_simple_chars(config,list,"border-right-width:",enc);
284 snprintf(tempstr,TEMPSTR_LEN,"%f",new->right_border->thickness);
285 output_simple_chars(config,list,tempstr,enc);
286 output_simple_chars(config,list,"pt;",enc);
287 }
288 if (!base ||
289 ((new->bottom_border->kind != psiconv_border_none) &&
290 (new->bottom_border->thickness != base->bottom_border->thickness))) {
291 output_simple_chars(config,list,"border-bottom-width:",enc);
292 snprintf(tempstr,TEMPSTR_LEN,"%f",new->bottom_border->thickness);
293 output_simple_chars(config,list,tempstr,enc);
294 output_simple_chars(config,list,"pt;",enc);
295 }
296 if (!base ||
297 ((new->top_border->kind != psiconv_border_none) &&
298 ( new->top_border->thickness != base->top_border->thickness))) {
299 output_simple_chars(config,list,"border-top-width:",enc);
300 snprintf(tempstr,TEMPSTR_LEN,"%f",new->top_border->thickness);
301 output_simple_chars(config,list,tempstr,enc);
302 output_simple_chars(config,list,"pt;",enc);
303 }
304 if (!base ||
305 ((new->left_border->kind != psiconv_border_none) &&
306 (new->left_border->thickness != base->left_border->thickness))) {
307 output_simple_chars(config,list,"border-left-width:",enc);
308 snprintf(tempstr,TEMPSTR_LEN,"%f",new->left_border->thickness);
309 output_simple_chars(config,list,tempstr,enc);
310 output_simple_chars(config,list,"pt;",enc);
311 }
312
313 if (!base ||
314 ((new->right_border->kind != psiconv_border_none) &&
315 ((new->right_border->color->red != base->right_border->color->red) ||
316 (new->right_border->color->green != base->right_border->color->green)||
317 (new->right_border->color->blue != base->right_border->color->blue)))) {
318 output_simple_chars(config,list,"border-right-color:",enc);
319 color(config,list,new->right_border->color,0,enc);
320 output_simple_chars(config,list,";",enc);
321 }
322 if (!base ||
323 ((new->top_border->kind != psiconv_border_none) &&
324 ((new->top_border->color->red != base->top_border->color->red) ||
325 (new->top_border->color->green != base->top_border->color->green) ||
326 (new->top_border->color->blue != base->top_border->color->blue)))) {
327 output_simple_chars(config,list,"border-top-color:",enc);
328 color(config,list,new->top_border->color,0,enc);
329 output_simple_chars(config,list,";",enc);
330 }
331 if (!base ||
332 ((new->bottom_border->kind != psiconv_border_none) &&
333 ((new->bottom_border->color->red != base->bottom_border->color->red) ||
334 (new->bottom_border->color->green !=base->bottom_border->color->green)||
335 (new->bottom_border->color->blue != base->bottom_border->color->blue)))){
336 output_simple_chars(config,list,"border-bottom-color:",enc);
337 color(config,list,new->bottom_border->color,0,enc);
338 output_simple_chars(config,list,";",enc);
339 }
340 if (!base ||
341 ((new->left_border->kind != psiconv_border_none) &&
342 ((new->left_border->color->red != base->left_border->color->red) ||
343 (new->left_border->color->green != base->left_border->color->green) ||
344 (new->left_border->color->blue != base->left_border->color->blue)))) {
345 output_simple_chars(config,list,"border-left-color:",enc);
346 color(config,list,new->left_border->color,0,enc);
347 output_simple_chars(config,list,";",enc);
348 }
201} 349}
202 350
203void style(const psiconv_config config, psiconv_list list, 351void style(const psiconv_config config, psiconv_list list,
204 const psiconv_word_style style, 352 const psiconv_word_style style,
205 const psiconv_paragraph_layout base_para, 353 const psiconv_paragraph_layout base_para,
206 const psiconv_character_layout base_char, 354 const psiconv_character_layout base_char,
207 const encoding enc) 355 const encoding enc)
208{ 356{
209 output_simple_chars(config,list,"p[class=\"style_",enc); 357 output_simple_chars(config,list,"*.style_",enc);
210 style_name(config,list,style->name,enc); 358 style_name(config,list,style->name,enc);
211 output_simple_chars(config,list,"\"] {",enc); 359 output_simple_chars(config,list," {",enc);
212 paragraph_layout_diffs(config,list,style->paragraph,base_para,enc); 360 paragraph_layout_diffs(config,list,style->paragraph,base_para,enc);
213 character_layout_diffs(config,list,style->character,base_char,enc); 361 character_layout_diffs(config,list,style->character,base_char,enc);
214 output_simple_chars(config,list,"}\n",enc); 362 output_simple_chars(config,list,"}\n",enc);
215} 363}
216 364
291 output_simple_chars(config,list,"</body>\n",enc); 439 output_simple_chars(config,list,"</body>\n",enc);
292 output_simple_chars(config,list,"</html>\n",enc); 440 output_simple_chars(config,list,"</html>\n",enc);
293} 441}
294 442
295void characters(const psiconv_config config, psiconv_list list, 443void characters(const psiconv_config config, psiconv_list list,
296 const psiconv_string_t text, 444 const psiconv_string_t textstr,
297 const psiconv_character_layout layout, 445 const psiconv_character_layout layout,
298 const psiconv_character_layout base, 446 const psiconv_character_layout base,
299 const encoding enc) 447 const encoding enc)
300{ 448{
301 psiconv_list templist; 449 psiconv_list templist;
313 exit(1); 461 exit(1);
314 } 462 }
315 output_simple_chars(config,list,"\">",enc); 463 output_simple_chars(config,list,"\">",enc);
316 } 464 }
317 465
318 output_string(config,list,text,enc); 466 text(config,list,textstr,enc);
319 467
320 if (psiconv_list_length(templist)) { 468 if (psiconv_list_length(templist)) {
321 output_simple_chars(config,list,"</span>",enc); 469 output_simple_chars(config,list,"</span>",enc);
322 } 470 }
323 471
356 fputs("Out of memory error\n",stderr); 504 fputs("Out of memory error\n",stderr);
357 exit(1); 505 exit(1);
358 } 506 }
359 } 507 }
360 508
361 output_simple_chars(config,list,"<p ",enc); 509 output_simple_chars(config,
510 list,para->base_paragraph->bullet->on?"<ul><li ":"<p ",
511 enc);
362 512
363 if (styles_sec) { 513 if (styles_sec) {
364 output_simple_chars(config,list,"class=\"style_",enc); 514 output_simple_chars(config,list,"class=\"style_",enc);
365 style_name(config,list,style->name,enc); 515 style_name(config,list,style->name,enc);
366 output_simple_chars(config,list,"\" ",enc); 516 output_simple_chars(config,list,"\" ",enc);
398 characters(config,list,text,layout->layout,para->base_character,enc); 548 characters(config,list,text,layout->layout,para->base_character,enc);
399 free(text); 549 free(text);
400 charnr += layout->length; 550 charnr += layout->length;
401 } 551 }
402 } 552 }
403 output_simple_chars(config,list,"</p>\n",enc); 553 output_simple_chars(config, list,
554 para->base_paragraph->bullet->on?"</li></ul>\n":"<p>\n",
555 enc);
404 if (!styles_sec) { 556 if (!styles_sec) {
405 psiconv_free_paragraph_layout(base_para); 557 psiconv_free_paragraph_layout(base_para);
406 psiconv_free_character_layout(base_char); 558 psiconv_free_character_layout(base_char);
407 } 559 }
408 psiconv_list_free(templist); 560 psiconv_list_free(templist);

Legend:
Removed from v.190  
changed lines
  Added in v.191

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