/[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 182 - (show annotations)
Sun Jan 4 22:07:02 2004 UTC (20 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 26275 byte(s)
(Frodo) Move fontnames to psiconv_string type

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

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