/[public]/psiconv/trunk/lib/psiconv/parse_layout.c
ViewVC logotype

Contents of /psiconv/trunk/lib/psiconv/parse_layout.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 168 - (show annotations)
Tue Nov 25 17:57:05 2003 UTC (20 years, 4 months ago) by frodo
File MIME type: text/plain
File size: 26463 byte(s)
(Frodo) config stuff and image generation stuff

* All parse and generate functions have a new config parameter
* New files configuration.[ch] in the psiconv lib
* Some image generation stuff (not ready, but won't do any harm)

1 /*
2 parse_layout.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999, 2000 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 "compat.h"
22
23 #include <stdlib.h>
24 #include <math.h>
25
26 #include "parse_routines.h"
27 #include "error.h"
28
29 #ifdef DMALLOC
30 #include <dmalloc.h>
31 #endif
32
33
34 int psiconv_parse_color(const psiconv_config config,
35 const psiconv_buffer buf, int lev, psiconv_u32 off,
36 int *length, psiconv_color *result)
37 {
38 int res = 0;
39 int len = 0;
40
41 psiconv_progress(config,lev+1,off,"Going to parse color");
42 if (!(*result = malloc(sizeof(**result))))
43 goto ERROR1;
44
45 (*result)->red = psiconv_read_u8(config,buf,lev+2,off+len,&res);
46 if (res)
47 goto ERROR2;
48 (*result)->green = psiconv_read_u8(config,buf,lev+2,off+len+1,&res);
49 if (res)
50 goto ERROR2;
51 (*result)->blue = psiconv_read_u8(config,buf,lev+2,off+len+2,&res);
52 if (res)
53 goto ERROR2;
54 len += 3;
55
56 psiconv_debug(config,lev+2,off,"Color: red %02x, green %02x, blue %02x",
57 (*result)->red, (*result)->green, (*result)->blue);
58 if (length)
59 *length = len;
60
61 psiconv_progress(config,lev+1,off+len-1,"End of color (total length: %08x)",len);
62 return 0;
63
64 ERROR2:
65 free(*result);
66 ERROR1:
67 psiconv_warn(config,lev+1,off,"Reading of Color failed");
68 if (length)
69 *length = 0;
70 if (res == 0)
71 return -PSICONV_E_NOMEM;
72 else
73 return res;
74 }
75
76
77
78 int psiconv_parse_font(const psiconv_config config,
79 const psiconv_buffer buf, int lev, psiconv_u32 off,
80 int *length, psiconv_font *result)
81 {
82 int res = 0;
83 int strlength,i;
84 char *str_copy;
85 int len;
86
87 psiconv_progress(config,lev+1,off,"Going to parse font");
88 if (!(*result = malloc(sizeof(**result))))
89 goto ERROR1;
90
91 strlength = psiconv_read_u8(config,buf,lev+2,off,&res);
92 if (res)
93 goto ERROR2;
94 if (!((*result)->name = malloc(strlength))) {
95 goto ERROR2;
96 }
97 for (i = 0; (i < strlength-1) && !res; i++)
98 (*result)->name[i] = psiconv_read_u8(config,buf,lev+2,off + 1 + i,&res);
99 if (res)
100 goto ERROR3;
101 (*result)->name[strlength-1] = 0;
102 (*result)->screenfont = psiconv_read_u8(config,buf,lev+2,off + strlength,&res);
103 if (res)
104 goto ERROR3;
105
106 if (!(str_copy = psiconv_make_printable((*result)->name)))
107 goto ERROR3;
108
109 psiconv_debug(config,lev+2,off+1,"Found font `%s', displayed with screen font %02x",
110 str_copy,(*result)->screenfont);
111 free(str_copy);
112 len = strlength + 1;
113 if (length)
114 *length = len;
115
116 psiconv_progress(config,lev+1,off + len - 1,"End of font (total length: %08x)",len);
117 return 0;
118
119 ERROR3:
120 free ((*result)->name);
121 ERROR2:
122 free (*result);
123 ERROR1:
124 psiconv_warn(config,lev+1,off,"Reading of Font failed");
125 if (length)
126 *length = 0;
127 if (!res)
128 return -PSICONV_E_NOMEM;
129 else
130 return res;
131 }
132
133 int psiconv_parse_border(const psiconv_config config,
134 const psiconv_buffer buf,int lev,psiconv_u32 off,
135 int *length, psiconv_border *result)
136 {
137 int res = 0;
138 int len = 0;
139 psiconv_u32 temp;
140 int leng;
141
142 psiconv_progress(config,lev+1,off,"Going to parse border data");
143 if (!(*result = malloc(sizeof(**result)))) {
144 goto ERROR1;
145 }
146
147 psiconv_progress(config,lev+2,off+len,"Going to read border kind");
148 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
149 if (res)
150 goto ERROR2;
151 if (temp == 0x00)
152 (*result)->kind = psiconv_border_none;
153 else if (temp == 0x01)
154 (*result)->kind = psiconv_border_solid;
155 else if (temp == 0x02)
156 (*result)->kind = psiconv_border_double;
157 else if (temp == 0x03)
158 (*result)->kind = psiconv_border_dotted;
159 else if (temp == 0x04)
160 (*result)->kind = psiconv_border_dashed;
161 else if (temp == 0x05)
162 (*result)->kind = psiconv_border_dotdashed;
163 else if (temp == 0x06)
164 (*result)->kind = psiconv_border_dotdotdashed;
165 else {
166 psiconv_warn(config,lev+2,off,"Unknown border kind (defaults to `none')");
167 (*result)->kind = psiconv_border_none;
168 }
169 psiconv_debug(config,lev+2,off+len,"Kind: %02x",temp);
170 len ++;
171
172 psiconv_progress(config,lev+2,off+len,"Going to read border thickness");
173 (*result)->thickness = psiconv_read_size(config,buf,lev+2,off+len,&leng,&res);
174 if (res)
175 goto ERROR2;
176 #if 0
177 /* This seems no longer necessary to test? */
178 if (((*result)->kind != psiconv_border_solid) &&
179 ((*result)->kind != psiconv_border_double) &&
180 ((*result)->thickness != 0.0) &&
181 (fabs((*result)->thickness - 1/20) >= 1/1000)) {
182 psiconv_warn(config,lev+2,off,
183 "Border thickness specified for unlikely border type");
184 }
185 #endif
186 psiconv_debug(config,lev+2,off+len,"Thickness: %f",(*result)->thickness);
187 len += leng;
188
189 psiconv_progress(config,lev+2,off+len,"Going to read the border color");
190 if ((psiconv_parse_color(config,buf,lev+2,off+len,&leng,&(*result)->color)))
191 goto ERROR2;
192 len += leng;
193
194 psiconv_progress(config,lev+2,off+len,"Going to read the final unknown byte "
195 "(0x00 or 0x01 expected)");
196 temp = psiconv_read_u8(config,buf,lev+2,off + len,&res);
197 if (res)
198 goto ERROR3;
199 if ((temp != 0x01) && (temp != 0x00)) {
200 psiconv_warn(config,lev+2,off,"Unknown last byte in border specification");
201 psiconv_debug(config,lev+2,off+len, "Last byte: read %02x, expected %02x or %02x",
202 temp,0x00,0x01);
203 }
204 len ++;
205
206 if (length)
207 *length = len;
208
209 psiconv_progress(config,lev+1,off + len - 1,
210 "End of border (total length: %08x)",len);
211
212 return 0;
213
214 ERROR3:
215 psiconv_free_color((*result)->color);
216 ERROR2:
217 free (result);
218 ERROR1:
219 psiconv_warn(config,lev+1,off,"Reading of Border failed");
220 if (length)
221 *length = 0;
222 if (!res)
223 return -PSICONV_E_NOMEM;
224 else
225 return res;
226 }
227
228 int psiconv_parse_bullet(const psiconv_config config,
229 const psiconv_buffer buf,int lev,psiconv_u32 off,
230 int *length, psiconv_bullet *result)
231 {
232 int res = 0;
233 int len = 0;
234 int leng;
235 int bullet_length;
236
237 if (!(*result = malloc(sizeof(**result))))
238 goto ERROR1;
239 (*result)->on = psiconv_bool_true;
240
241 psiconv_progress(config,lev+1,off,"Going to parse bullet data");
242 psiconv_progress(config,lev+2,off+len,"Going to read bullet length");
243 bullet_length = psiconv_read_u8(config,buf,lev+2,off+len,&res);
244 if (res)
245 goto ERROR2;
246 psiconv_debug(config,lev+2,off+len,"Length: %02x",bullet_length);
247 len ++;
248
249 psiconv_progress(config,lev+2,off+len,"Going to read bullet font size");
250 (*result)->font_size = psiconv_read_size(config,buf,lev+2,off+len, &leng,&res);
251 if (res)
252 goto ERROR2;
253 len +=leng;
254
255 psiconv_progress(config,lev+2,off+len,"Going to read bullet character");
256 (*result)->character = psiconv_read_u8(config,buf,lev+2,off+len,&res);
257 if (res)
258 goto ERROR2;
259 psiconv_debug(config,lev+2,off+len,"Character: %02x",(*result)->character);
260 len ++;
261
262 psiconv_progress(config,lev+2,off+len,"Going to read indent on/off");
263 if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng,&(*result)->indent)))
264 goto ERROR2;
265 psiconv_debug(config,lev+2,off+len,"Indent on: %02x",(*result)->indent);
266 len += leng;
267
268 psiconv_progress(config,lev+2,off+len,"Going to read bullet color");
269 if ((res = psiconv_parse_color(config,buf,lev+2,off+len,&leng,&(*result)->color)))
270 goto ERROR2;
271 len += leng;
272
273 psiconv_progress(config,lev+2,off+len,"Going to read bullet font");
274 if ((res = psiconv_parse_font(config,buf,lev+2,off+len,&leng,&(*result)->font)))
275 goto ERROR3;
276 len += leng;
277
278 if (len != bullet_length + 1) {
279 psiconv_warn(config,lev+2,off,"Bullet data structure length mismatch");
280 psiconv_debug(config,lev+2,off,"Length: specified %02x, found %02x",
281 bullet_length,len-1);
282 }
283
284 psiconv_progress(config,lev+1,off + len - 1,
285 "End of bullet data (total length: %08x)",len);
286
287 if (length)
288 *length = len;
289 return 0;
290
291 ERROR3:
292 psiconv_free_color((*result)->color);
293 ERROR2:
294 free (result);
295 ERROR1:
296 psiconv_warn(config,lev+1,off,"Reading of Bullet failed");
297 if (length)
298 *length = 0;
299 if (!res)
300 return -PSICONV_E_NOMEM;
301 else
302 return res;
303 }
304
305 int psiconv_parse_tab(const psiconv_config config,
306 const psiconv_buffer buf, int lev, psiconv_u32 off,
307 int *length, psiconv_tab *result)
308 {
309 int res = 0;
310 int len = 0;
311 int leng;
312 psiconv_u8 temp;
313
314 psiconv_progress(config,lev+1,off,"Going to parse tab");
315 if (!(*result = malloc(sizeof(**result))))
316 goto ERROR1;
317
318 psiconv_progress(config,lev+2,off,"Going to read tab location");
319 (*result)->location = psiconv_read_length(config,buf,lev+2,off+len,&leng,&res);
320 if (res)
321 goto ERROR2;
322 len += leng;
323
324 psiconv_progress(config,lev+2,off+len,"Going to read the tab kind");
325 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
326 if (res)
327 goto ERROR2;
328 if (temp == 1)
329 (*result)->kind = psiconv_tab_left;
330 else if (temp == 2)
331 (*result)->kind = psiconv_tab_centre;
332 else if (temp == 3)
333 (*result)->kind = psiconv_tab_right;
334 else {
335 psiconv_warn(config,lev+2,off+len,"Unknown tab kind argument");
336 psiconv_debug(config,lev+2,off+len,"Kind found: %02x (defaulted to left tab)",
337 temp);
338 (*result)->kind = psiconv_tab_left;
339 }
340 psiconv_debug(config,lev+2,off+len,"Kind: %02x",temp);
341 len ++;
342
343 if (length)
344 *length = len;
345
346 psiconv_progress(config,lev+1,off+len-1,"End of tab (total length: %08x)",len);
347 return 0;
348
349 ERROR2:
350 free (result);
351 ERROR1:
352 psiconv_warn(config,lev+1,off,"Reading of Tab failed");
353 if (length)
354 *length = 0;
355 if (!res)
356 return -PSICONV_E_NOMEM;
357 else
358 return res;
359 }
360
361 int psiconv_parse_paragraph_layout_list(const psiconv_config config,
362 const psiconv_buffer buf, int lev,
363 psiconv_u32 off, int *length,
364 psiconv_paragraph_layout result)
365 {
366 int res=0;
367 int len=0;
368 int list_length,leng,nr;
369 psiconv_u8 id;
370 psiconv_u32 temp;
371 psiconv_tab temp_tab;
372 psiconv_color temp_color;
373 psiconv_border temp_border;
374 psiconv_bullet temp_bullet;
375
376 psiconv_progress(config,lev+1,off,"Going to read paragraph layout list");
377
378 psiconv_progress(config,lev+2,off,"Going to read the list length");
379 list_length = psiconv_read_u32(config,buf,lev+2,off + len,&res);
380 if (res)
381 goto ERROR1;
382 psiconv_debug(config,lev+2,off,"Length in bytes: %08x",list_length);
383 len += 4;
384
385 nr = 0;
386 while(len - 4 < list_length) {
387 psiconv_progress(config,lev+2,off+len,"Going to read element %d",nr);
388 psiconv_progress(config,lev+3,off+len,"Going to read the element id");
389 id = psiconv_read_u8(config,buf,lev+2,off+len,&res);
390 if (res)
391 goto ERROR1;
392 psiconv_debug(config,lev+3,off+len,"Id: %02x",id);
393 len ++;
394 switch(id) {
395 case 0x01:
396 psiconv_progress(config,lev+3,off+len,"Going to read background color");
397 if ((res = psiconv_parse_color(config,buf,lev+3,off+len,&leng,&temp_color)))
398 goto ERROR1;
399 psiconv_free_color(result->back_color);
400 result->back_color = temp_color;
401 len += leng;
402 break;
403 case 0x02:
404 psiconv_progress(config,lev+3,off+len ,"Going to read indent left");
405 result->indent_left = psiconv_read_length(config,buf,lev+3,off+len,&leng,&res);
406 if (res)
407 goto ERROR1;
408 len += leng;
409 break;
410 case 0x03:
411 psiconv_progress(config,lev+3,off+len,"Going to read indent right");
412 result->indent_right = psiconv_read_length(config,buf,lev+2,off+len,&leng,
413 &res);
414 if (res)
415 goto ERROR1;
416 len += leng;
417 break;
418 case 0x04:
419 psiconv_progress(config,lev+3,off+len,"Going to read indent left first line");
420 result->indent_first = psiconv_read_length(config,buf,lev+2,off+len, &leng,
421 &res);
422 if (res)
423 goto ERROR1;
424 len += leng;
425 break;
426 case 0x05:
427 psiconv_progress(config,lev+3,off+len,"Going to read horizontal justify");
428 temp = psiconv_read_u8(config,buf,lev+3,off+len,&res);
429 if (res)
430 goto ERROR1;
431 if (temp == 0x00)
432 result->justify_hor = psiconv_justify_left;
433 else if (temp == 0x01)
434 result->justify_hor = psiconv_justify_centre;
435 else if (temp == 0x02)
436 result->justify_hor = psiconv_justify_right;
437 else if (temp == 0x03)
438 result->justify_hor = psiconv_justify_full;
439 else {
440 psiconv_warn(config,lev+3,off+len, "Unknown horizontal justify argument "
441 "in paragraph layout codes list");
442 result->justify_hor = psiconv_justify_left;
443 }
444 psiconv_debug(config,lev+3,off+len,"Justify: %02x",temp);
445 len ++;
446 break;
447 case 0x06:
448 psiconv_progress(config,lev+3,off+len,"Going to read vertical justify");
449 temp = psiconv_read_u8(config,buf,lev+3,off+len,&res);
450 if (res)
451 goto ERROR1;
452 if (temp == 0x00)
453 result->justify_ver = psiconv_justify_top;
454 else if (temp == 0x01)
455 result->justify_ver = psiconv_justify_middle;
456 else if (temp == 0x02)
457 result->justify_ver = psiconv_justify_bottom;
458 else {
459 psiconv_warn(config,lev+3,off+len, "Unknown vertical justify argument "
460 "in paragraph layout codes list");
461 result->justify_ver = psiconv_justify_bottom;
462 }
463 psiconv_debug(config,lev+3,off+len,"Justify: %02x",temp);
464 len ++;
465 break;
466 case 0x07:
467 psiconv_progress(config,lev+3,off+len,"Going to read linespacing distance");
468 result->linespacing = psiconv_read_size(config,buf,lev+3,off+len,&leng,&res);
469 if (res)
470 goto ERROR1;
471 len += leng;
472 break;
473 case 0x08:
474 psiconv_progress(config,lev+3,off+len,"Going to read linespacing exact");
475 if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng,
476 &result->linespacing_exact)))
477 goto ERROR1;
478 len += leng;
479 break;
480 case 0x09:
481 psiconv_progress(config,lev+3,off+len,"Going to read top space");
482 result->space_above = psiconv_read_size(config,buf,lev+3,off+len,&leng,&res);
483 if (res)
484 goto ERROR1;
485 len += leng;
486 break;
487 case 0x0a:
488 psiconv_progress(config,lev+3,off+len,"Going to read bottom space");
489 result->space_below = psiconv_read_size(config,buf,lev+3,off+len,&leng,&res);
490 if (res)
491 goto ERROR1;
492 len += leng;
493 break;
494 case 0x0b:
495 psiconv_progress(config,lev+3,off+len,"Going to read on one page");
496 if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng,
497 &result->keep_together)))
498 goto ERROR1;
499 len += leng;
500 break;
501 case 0x0c:
502 psiconv_progress(config,lev+3,off+len,"Going to read together with");
503 if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng,
504 &result->keep_with_next)))
505 goto ERROR1;
506 len += leng;
507 break;
508 case 0x0d:
509 psiconv_progress(config,lev+3,off+len,"Going to read on next page");
510 if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng,
511 &result->on_next_page)))
512 goto ERROR1;
513 len += leng;
514 break;
515 case 0x0e:
516 psiconv_progress(config,lev+3,off+len,"Going to read no widow protection");
517 if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng,
518 &result->no_widow_protection)))
519 goto ERROR1;
520 len += leng;
521 break;
522 case 0x0f:
523 psiconv_progress(config,lev+3,off+len,"Going to read wrap to fit cell limits");
524 if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng,
525 &result->wrap_to_fit_cell)))
526 goto ERROR1;
527 len += leng;
528 break;
529 case 0x10:
530 psiconv_progress(config,lev+3,off+len,"Going to read border distance to text");
531 result->border_distance = psiconv_read_length(config,buf,lev+3,
532 off+len,&leng,&res);
533 if (res)
534 goto ERROR1;
535 len += leng;
536 break;
537 case 0x11:
538 psiconv_progress(config,lev+3,off+len,"Going to read top border");
539 if ((res = psiconv_parse_border(config,buf,lev+3,off+len,&leng,&temp_border)))
540 goto ERROR1;
541 psiconv_free_border(result->top_border);
542 result->top_border = temp_border;
543 len += leng;
544 break;
545 case 0x12:
546 psiconv_progress(config,lev+3,off+len,"Going to read bottom border");
547 if ((res = psiconv_parse_border(config,buf,lev+3,off+len,&leng,&temp_border)))
548 goto ERROR1;
549 psiconv_free_border(result->bottom_border);
550 result->bottom_border = temp_border;
551 len += leng;
552 break;
553 case 0x13:
554 psiconv_progress(config,lev+3,off+len,"Going to read left border");
555 if ((res = psiconv_parse_border(config,buf,lev+3,off+len,&leng,&temp_border)))
556 goto ERROR1;
557 psiconv_free_border(result->left_border);
558 result->left_border = temp_border;
559 len += leng;
560 break;
561 case 0x14:
562 psiconv_progress(config,lev+3,off+len,"Going to read right border");
563 if ((res = psiconv_parse_border(config,buf,lev+3,off+len,&leng,&temp_border)))
564 goto ERROR1;
565 psiconv_free_border(result->right_border);
566 result->right_border = temp_border;
567 len += leng;
568 break;
569 case 0x15:
570 psiconv_progress(config,lev+3,off+len,"Going to read bullet");
571 if ((res = psiconv_parse_bullet(config,buf,lev+3,off+len,&leng,&temp_bullet)))
572 goto ERROR1;
573 psiconv_free_bullet(result->bullet);
574 result->bullet = temp_bullet;
575 len += leng;
576 break;
577 case 0x16:
578 psiconv_progress(config,lev+3,off+len,"Going to read standard tabs");
579 result->tabs->normal = psiconv_read_length(config,buf,lev+3,off+len,&leng,
580 &res);
581 if (res)
582 goto ERROR1;
583 len += leng;
584 break;
585 case 0x17:
586 psiconv_progress(config,lev+3,off+len,"Going to read extra tab");
587 if ((res = psiconv_parse_tab(config,buf,lev+3,off+len,&leng,&temp_tab)))
588 goto ERROR1;
589 if ((res = psiconv_list_add(result->tabs->extras,temp_tab))) {
590 psiconv_free_tab(temp_tab);
591 goto ERROR1;
592 }
593 psiconv_free_tab(temp_tab);
594 len += leng;
595 break;
596 default:
597 psiconv_warn(config,lev+3,off+len,
598 "Unknown code in paragraph layout codes list");
599 psiconv_debug(config,lev+3,off+len,"Code: %02x",id);
600 len ++;
601 break;
602 }
603 nr ++;
604 }
605
606 if (len - 4 != list_length) {
607 psiconv_warn(config,lev+2,off+len,
608 "Read past end of paragraph layout codes list. I probably lost track"
609 "somewhere!");
610 psiconv_debug(config,lev+2,off+len,"Read %d characters instead of %d",
611 len-4,list_length);
612 res = PSICONV_E_PARSE;
613 goto ERROR1;
614 }
615
616 len = list_length + 4;
617
618 psiconv_progress(config,lev+1,off+len,
619 "End of paragraph layout list (total length: %08x)",len);
620
621 if (length)
622 *length = len;
623 return 0;
624
625 ERROR1:
626 psiconv_warn(config,lev+1,off,"Reading of paragraph_layout_list failed");
627 if (length)
628 *length = 0;
629 if (!res)
630 return -PSICONV_E_NOMEM;
631 else
632 return res;
633 }
634
635 int psiconv_parse_character_layout_list(const psiconv_config config,
636 const psiconv_buffer buf, int lev,
637 psiconv_u32 off, int *length,
638 psiconv_character_layout result)
639 {
640 int res=0;
641 int len=0;
642 int list_length,leng,nr;
643 psiconv_u8 id;
644 psiconv_u32 temp;
645 psiconv_color temp_color;
646 psiconv_font temp_font;
647
648 psiconv_progress(config,lev+1,off,"Going to read character layout codes");
649
650 psiconv_progress(config,lev+2,off,"Going to read the list length");
651 list_length = psiconv_read_u32(config,buf,lev+2,off + len,&res);
652 if (res)
653 goto ERROR1;
654 psiconv_debug(config,lev+2,off,"Length in bytes: %08x",list_length);
655 len += 4;
656
657 nr = 0;
658 while(len-4 < list_length) {
659 psiconv_progress(config,lev+2,off+len,"Going to read element %d",nr);
660 psiconv_progress(config,lev+3,off+len,"Going to read the element id");
661 id = psiconv_read_u8(config,buf,lev+2,off+len,&res);
662 if (res)
663 goto ERROR1;
664 psiconv_debug(config,lev+3,off+len,"Id: %02x",id);
665 len ++;
666 switch(id) {
667 case 0x18:
668 psiconv_progress(config,lev+3,off+len,"Going to skip an unknown setting");
669 len ++;
670 break;
671 case 0x19:
672 psiconv_progress(config,lev+3,off+len,"Going to read text color");
673 if ((res = psiconv_parse_color(config,buf,lev+3,off+len, &leng,&temp_color)))
674 goto ERROR1;
675 psiconv_free_color(result->color);
676 result->color = temp_color;
677 len += leng;
678 break;
679 case 0x1a:
680 psiconv_progress(config,lev+3,off+len,"Going to read background color (?)");
681 if ((res = psiconv_parse_color(config,buf,lev+2,off+len, &leng,&temp_color)))
682 goto ERROR1;
683 psiconv_free_color(result->back_color);
684 result->back_color = temp_color;
685 len += leng;
686 break;
687 case 0x1b:
688 psiconv_progress(config,lev+3,off+len,"Going to skip an unknown setting");
689 len ++;
690 break;
691 case 0x1c:
692 psiconv_progress(config,lev+3,off+len,"Going to read font size");
693 result->font_size = psiconv_read_size(config,buf,lev+3,off+len,&leng,&res);
694 if (res)
695 goto ERROR1;
696 len += leng;
697 break;
698 case 0x1d:
699 psiconv_progress(config,lev+3,off+len,"Going to read italic");
700 if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng,&result->italic)))
701 goto ERROR1;
702 len += leng;
703 break;
704 case 0x1e:
705 psiconv_progress(config,lev+3,off+len,"Going to read bold");
706 if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng,&result->bold)))
707 goto ERROR1;
708 len += leng;
709 break;
710 case 0x1f:
711 psiconv_progress(config,lev+3,off+len,"Going to read super_sub");
712 temp = psiconv_read_u8(config,buf,lev+3,off+len,&res);
713 if (res)
714 goto ERROR1;
715 if (temp == 0x00)
716 result->super_sub = psiconv_normalscript;
717 else if (temp == 0x01)
718 result->super_sub = psiconv_superscript;
719 else if (temp == 0x02)
720 result->super_sub = psiconv_subscript;
721 else {
722 psiconv_warn(config,lev+3,off+len,
723 "Unknown super_sub argument in character layout codes list");
724 }
725 psiconv_debug(config,lev+3,off+len,"Super_sub: %02x",temp);
726 len ++;
727 break;
728 case 0x20:
729 psiconv_progress(config,lev+3,off+len,"Going to read underline");
730 if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng,
731 &result->underline)))
732 goto ERROR1;
733 len += leng;
734 break;
735 case 0x21:
736 psiconv_progress(config,lev+3,off+len,"Going to read strikethrough");
737 if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng,
738 &result->strikethrough)))
739 goto ERROR1;
740 len += leng;
741 break;
742 case 0x22:
743 psiconv_progress(config,lev+3,off+len,"Going to read font");
744 if ((res = psiconv_parse_font(config,buf,lev+3,off+len, &leng, &temp_font)))
745 goto ERROR1;
746 psiconv_free_font(result->font);
747 result->font = temp_font;
748 len += leng;
749 break;
750 case 0x23:
751 psiconv_progress(config,lev+3,off+len,"Going to skip an unknown setting");
752 len ++;
753 break;
754 case 0x24:
755 psiconv_progress(config,lev+3,off+len,
756 "Going to read unknown code 0x24 (%02x expected)", 0);
757 temp = psiconv_read_u8(config,buf,lev+3,off+len,&res);
758 if (res)
759 goto ERROR1;
760 if (temp != 0) {
761 psiconv_warn(config,lev+3,off+len,
762 "Unknown code 0x24 value != 0x0 (0x%02x)", temp);
763 }
764 len ++;
765 break;
766 default:
767 psiconv_warn(config,lev+3,off+len,"Unknown code in character layout list");
768 psiconv_debug(config,lev+3,off+len,"Code: %02x",id);
769 len ++;
770 break;
771 }
772 nr ++;
773 }
774
775 if (len - 4 != list_length) {
776 psiconv_warn(config,lev+2,off+len,
777 "Read past end of character layout codes list. I probably lost track"
778 "somewhere!");
779 psiconv_debug(config,lev+2,off+len,"Read %d characters instead of %d",
780 len-4,list_length);
781 res = PSICONV_E_PARSE;
782 goto ERROR1;
783 }
784
785 len = list_length + 4;
786
787 psiconv_progress(config,lev+1,off+len,
788 "End of character layout list (total length: %08x)",len);
789
790 if (length)
791 *length = len;
792 return res;
793
794 ERROR1:
795 psiconv_warn(config,lev+1,off,"Reading of character_layout_list failed");
796 if (length)
797 *length = 0;
798 if (!res)
799 return -PSICONV_E_NOMEM;
800 else
801 return res;
802 }

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