/[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 71 - (show annotations)
Fri Dec 22 22:31:50 2000 UTC (23 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 24055 byte(s)
(Frodo) First generate routines! Reshuffled a few things to make it all work out

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

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