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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 168 - (hide annotations)
Tue Nov 25 17:57:05 2003 UTC (20 years, 5 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 frodo 2 /*
2     parse_layout.c - Part of psiconv, a PSION 5 file formats converter
3 frodo 63 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl>
4 frodo 2
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 frodo 71 #include "compat.h"
22    
23 frodo 2 #include <stdlib.h>
24     #include <math.h>
25    
26     #include "parse_routines.h"
27 frodo 71 #include "error.h"
28 frodo 2
29 frodo 142 #ifdef DMALLOC
30     #include <dmalloc.h>
31     #endif
32    
33    
34 frodo 168 int psiconv_parse_color(const psiconv_config config,
35     const psiconv_buffer buf, int lev, psiconv_u32 off,
36 frodo 2 int *length, psiconv_color *result)
37     {
38     int res = 0;
39     int len = 0;
40    
41 frodo 168 psiconv_progress(config,lev+1,off,"Going to parse color");
42 frodo 64 if (!(*result = malloc(sizeof(**result))))
43     goto ERROR1;
44 frodo 2
45 frodo 168 (*result)->red = psiconv_read_u8(config,buf,lev+2,off+len,&res);
46 frodo 64 if (res)
47     goto ERROR2;
48 frodo 168 (*result)->green = psiconv_read_u8(config,buf,lev+2,off+len+1,&res);
49 frodo 64 if (res)
50     goto ERROR2;
51 frodo 168 (*result)->blue = psiconv_read_u8(config,buf,lev+2,off+len+2,&res);
52 frodo 64 if (res)
53     goto ERROR2;
54 frodo 2 len += 3;
55    
56 frodo 168 psiconv_debug(config,lev+2,off,"Color: red %02x, green %02x, blue %02x",
57 frodo 2 (*result)->red, (*result)->green, (*result)->blue);
58     if (length)
59     *length = len;
60    
61 frodo 168 psiconv_progress(config,lev+1,off+len-1,"End of color (total length: %08x)",len);
62 frodo 64 return 0;
63    
64     ERROR2:
65     free(*result);
66     ERROR1:
67 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Color failed");
68 frodo 64 if (length)
69     *length = 0;
70     if (res == 0)
71     return -PSICONV_E_NOMEM;
72     else
73     return res;
74 frodo 2 }
75    
76    
77    
78 frodo 168 int psiconv_parse_font(const psiconv_config config,
79     const psiconv_buffer buf, int lev, psiconv_u32 off,
80 frodo 2 int *length, psiconv_font *result)
81     {
82     int res = 0;
83     int strlength,i;
84     char *str_copy;
85     int len;
86    
87 frodo 168 psiconv_progress(config,lev+1,off,"Going to parse font");
88 frodo 64 if (!(*result = malloc(sizeof(**result))))
89     goto ERROR1;
90 frodo 2
91 frodo 168 strlength = psiconv_read_u8(config,buf,lev+2,off,&res);
92 frodo 64 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 frodo 168 (*result)->name[i] = psiconv_read_u8(config,buf,lev+2,off + 1 + i,&res);
99 frodo 64 if (res)
100     goto ERROR3;
101 frodo 2 (*result)->name[strlength-1] = 0;
102 frodo 168 (*result)->screenfont = psiconv_read_u8(config,buf,lev+2,off + strlength,&res);
103 frodo 64 if (res)
104     goto ERROR3;
105 frodo 2
106 frodo 64 if (!(str_copy = psiconv_make_printable((*result)->name)))
107     goto ERROR3;
108    
109 frodo 168 psiconv_debug(config,lev+2,off+1,"Found font `%s', displayed with screen font %02x",
110 frodo 2 str_copy,(*result)->screenfont);
111     free(str_copy);
112     len = strlength + 1;
113     if (length)
114     *length = len;
115    
116 frodo 168 psiconv_progress(config,lev+1,off + len - 1,"End of font (total length: %08x)",len);
117 frodo 64 return 0;
118    
119     ERROR3:
120     free ((*result)->name);
121     ERROR2:
122     free (*result);
123     ERROR1:
124 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Font failed");
125 frodo 64 if (length)
126     *length = 0;
127     if (!res)
128     return -PSICONV_E_NOMEM;
129     else
130     return res;
131 frodo 2 }
132    
133 frodo 168 int psiconv_parse_border(const psiconv_config config,
134     const psiconv_buffer buf,int lev,psiconv_u32 off,
135 frodo 2 int *length, psiconv_border *result)
136     {
137     int res = 0;
138     int len = 0;
139     psiconv_u32 temp;
140     int leng;
141    
142 frodo 168 psiconv_progress(config,lev+1,off,"Going to parse border data");
143 frodo 64 if (!(*result = malloc(sizeof(**result)))) {
144     goto ERROR1;
145     }
146 frodo 2
147 frodo 168 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 frodo 64 if (res)
150     goto ERROR2;
151 frodo 2 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 frodo 67 (*result)->kind = psiconv_border_dashed;
161 frodo 2 else if (temp == 0x05)
162 frodo 67 (*result)->kind = psiconv_border_dotdashed;
163 frodo 2 else if (temp == 0x06)
164 frodo 67 (*result)->kind = psiconv_border_dotdotdashed;
165 frodo 2 else {
166 frodo 168 psiconv_warn(config,lev+2,off,"Unknown border kind (defaults to `none')");
167 frodo 2 (*result)->kind = psiconv_border_none;
168     }
169 frodo 168 psiconv_debug(config,lev+2,off+len,"Kind: %02x",temp);
170 frodo 2 len ++;
171    
172 frodo 168 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 frodo 64 if (res)
175     goto ERROR2;
176 frodo 84 #if 0
177     /* This seems no longer necessary to test? */
178 frodo 2 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 frodo 168 psiconv_warn(config,lev+2,off,
183 frodo 2 "Border thickness specified for unlikely border type");
184     }
185 frodo 84 #endif
186 frodo 168 psiconv_debug(config,lev+2,off+len,"Thickness: %f",(*result)->thickness);
187 frodo 2 len += leng;
188    
189 frodo 168 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 frodo 64 goto ERROR2;
192 frodo 2 len += leng;
193    
194 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the final unknown byte "
195 frodo 84 "(0x00 or 0x01 expected)");
196 frodo 168 temp = psiconv_read_u8(config,buf,lev+2,off + len,&res);
197 frodo 64 if (res)
198     goto ERROR3;
199 frodo 84 if ((temp != 0x01) && (temp != 0x00)) {
200 frodo 168 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 frodo 84 temp,0x00,0x01);
203 frodo 2 }
204     len ++;
205    
206     if (length)
207     *length = len;
208    
209 frodo 168 psiconv_progress(config,lev+1,off + len - 1,
210 frodo 2 "End of border (total length: %08x)",len);
211    
212 frodo 64 return 0;
213    
214     ERROR3:
215     psiconv_free_color((*result)->color);
216     ERROR2:
217     free (result);
218     ERROR1:
219 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Border failed");
220 frodo 64 if (length)
221     *length = 0;
222     if (!res)
223     return -PSICONV_E_NOMEM;
224     else
225     return res;
226 frodo 2 }
227    
228 frodo 168 int psiconv_parse_bullet(const psiconv_config config,
229     const psiconv_buffer buf,int lev,psiconv_u32 off,
230 frodo 2 int *length, psiconv_bullet *result)
231     {
232     int res = 0;
233     int len = 0;
234     int leng;
235     int bullet_length;
236    
237 frodo 64 if (!(*result = malloc(sizeof(**result))))
238     goto ERROR1;
239 frodo 2 (*result)->on = psiconv_bool_true;
240    
241 frodo 168 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 frodo 64 if (res)
245     goto ERROR2;
246 frodo 168 psiconv_debug(config,lev+2,off+len,"Length: %02x",bullet_length);
247 frodo 2 len ++;
248    
249 frodo 168 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 frodo 64 if (res)
252     goto ERROR2;
253 frodo 2 len +=leng;
254    
255 frodo 168 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 frodo 64 if (res)
258     goto ERROR2;
259 frodo 168 psiconv_debug(config,lev+2,off+len,"Character: %02x",(*result)->character);
260 frodo 2 len ++;
261    
262 frodo 168 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 frodo 64 goto ERROR2;
265 frodo 168 psiconv_debug(config,lev+2,off+len,"Indent on: %02x",(*result)->indent);
266 frodo 2 len += leng;
267    
268 frodo 168 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 frodo 64 goto ERROR2;
271 frodo 2 len += leng;
272    
273 frodo 168 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 frodo 64 goto ERROR3;
276 frodo 2 len += leng;
277    
278     if (len != bullet_length + 1) {
279 frodo 168 psiconv_warn(config,lev+2,off,"Bullet data structure length mismatch");
280     psiconv_debug(config,lev+2,off,"Length: specified %02x, found %02x",
281 frodo 2 bullet_length,len-1);
282     }
283    
284 frodo 168 psiconv_progress(config,lev+1,off + len - 1,
285 frodo 2 "End of bullet data (total length: %08x)",len);
286    
287     if (length)
288     *length = len;
289 frodo 65 return 0;
290 frodo 64
291     ERROR3:
292     psiconv_free_color((*result)->color);
293     ERROR2:
294     free (result);
295     ERROR1:
296 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Bullet failed");
297 frodo 64 if (length)
298     *length = 0;
299     if (!res)
300     return -PSICONV_E_NOMEM;
301     else
302     return res;
303 frodo 2 }
304    
305 frodo 168 int psiconv_parse_tab(const psiconv_config config,
306     const psiconv_buffer buf, int lev, psiconv_u32 off,
307 frodo 2 int *length, psiconv_tab *result)
308     {
309     int res = 0;
310     int len = 0;
311     int leng;
312     psiconv_u8 temp;
313    
314 frodo 168 psiconv_progress(config,lev+1,off,"Going to parse tab");
315 frodo 64 if (!(*result = malloc(sizeof(**result))))
316     goto ERROR1;
317 frodo 2
318 frodo 168 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 frodo 64 if (res)
321     goto ERROR2;
322 frodo 2 len += leng;
323    
324 frodo 168 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 frodo 64 if (res)
327     goto ERROR2;
328 frodo 2 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 frodo 168 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 frodo 2 temp);
338     (*result)->kind = psiconv_tab_left;
339     }
340 frodo 168 psiconv_debug(config,lev+2,off+len,"Kind: %02x",temp);
341 frodo 2 len ++;
342    
343     if (length)
344     *length = len;
345    
346 frodo 168 psiconv_progress(config,lev+1,off+len-1,"End of tab (total length: %08x)",len);
347 frodo 64 return 0;
348 frodo 2
349 frodo 64 ERROR2:
350     free (result);
351     ERROR1:
352 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Tab failed");
353 frodo 64 if (length)
354     *length = 0;
355     if (!res)
356     return -PSICONV_E_NOMEM;
357     else
358     return res;
359 frodo 2 }
360    
361 frodo 168 int psiconv_parse_paragraph_layout_list(const psiconv_config config,
362     const psiconv_buffer buf, int lev,
363 frodo 2 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 frodo 64 psiconv_tab temp_tab;
372     psiconv_color temp_color;
373     psiconv_border temp_border;
374     psiconv_bullet temp_bullet;
375 frodo 2
376 frodo 168 psiconv_progress(config,lev+1,off,"Going to read paragraph layout list");
377 frodo 2
378 frodo 168 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 frodo 64 if (res)
381     goto ERROR1;
382 frodo 168 psiconv_debug(config,lev+2,off,"Length in bytes: %08x",list_length);
383 frodo 2 len += 4;
384    
385     nr = 0;
386     while(len - 4 < list_length) {
387 frodo 168 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 frodo 64 if (res)
391     goto ERROR1;
392 frodo 168 psiconv_debug(config,lev+3,off+len,"Id: %02x",id);
393 frodo 2 len ++;
394     switch(id) {
395     case 0x01:
396 frodo 168 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 frodo 64 goto ERROR1;
399 frodo 2 psiconv_free_color(result->back_color);
400 frodo 64 result->back_color = temp_color;
401 frodo 2 len += leng;
402     break;
403     case 0x02:
404 frodo 168 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 frodo 64 if (res)
407     goto ERROR1;
408 frodo 2 len += leng;
409     break;
410     case 0x03:
411 frodo 168 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 frodo 64 &res);
414     if (res)
415     goto ERROR1;
416 frodo 2 len += leng;
417     break;
418     case 0x04:
419 frodo 168 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 frodo 64 &res);
422     if (res)
423     goto ERROR1;
424 frodo 2 len += leng;
425     break;
426     case 0x05:
427 frodo 168 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 frodo 64 if (res)
430     goto ERROR1;
431 frodo 2 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 frodo 168 psiconv_warn(config,lev+3,off+len, "Unknown horizontal justify argument "
441 frodo 2 "in paragraph layout codes list");
442 frodo 64 result->justify_hor = psiconv_justify_left;
443 frodo 2 }
444 frodo 168 psiconv_debug(config,lev+3,off+len,"Justify: %02x",temp);
445 frodo 2 len ++;
446     break;
447     case 0x06:
448 frodo 168 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 frodo 64 if (res)
451     goto ERROR1;
452 frodo 2 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 frodo 168 psiconv_warn(config,lev+3,off+len, "Unknown vertical justify argument "
460 frodo 2 "in paragraph layout codes list");
461 frodo 64 result->justify_ver = psiconv_justify_bottom;
462 frodo 2 }
463 frodo 168 psiconv_debug(config,lev+3,off+len,"Justify: %02x",temp);
464 frodo 2 len ++;
465 frodo 110 break;
466 frodo 2 case 0x07:
467 frodo 168 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 frodo 64 if (res)
470     goto ERROR1;
471 frodo 2 len += leng;
472     break;
473     case 0x08:
474 frodo 168 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 frodo 67 &result->linespacing_exact)))
477 frodo 64 goto ERROR1;
478 frodo 2 len += leng;
479     break;
480     case 0x09:
481 frodo 168 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 frodo 64 if (res)
484     goto ERROR1;
485 frodo 2 len += leng;
486     break;
487     case 0x0a:
488 frodo 168 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 frodo 64 if (res)
491     goto ERROR1;
492 frodo 2 len += leng;
493     break;
494     case 0x0b:
495 frodo 168 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 frodo 67 &result->keep_together)))
498 frodo 64 goto ERROR1;
499 frodo 2 len += leng;
500     break;
501     case 0x0c:
502 frodo 168 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 frodo 67 &result->keep_with_next)))
505 frodo 64 goto ERROR1;
506 frodo 2 len += leng;
507     break;
508     case 0x0d:
509 frodo 168 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 frodo 64 &result->on_next_page)))
512     goto ERROR1;
513 frodo 2 len += leng;
514     break;
515     case 0x0e:
516 frodo 168 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 frodo 64 &result->no_widow_protection)))
519     goto ERROR1;
520 frodo 2 len += leng;
521     break;
522 frodo 104 case 0x0f:
523 frodo 168 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 frodo 104 &result->wrap_to_fit_cell)))
526     goto ERROR1;
527     len += leng;
528     break;
529 frodo 2 case 0x10:
530 frodo 168 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 frodo 64 off+len,&leng,&res);
533     if (res)
534     goto ERROR1;
535 frodo 2 len += leng;
536     break;
537     case 0x11:
538 frodo 168 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 frodo 64 goto ERROR1;
541 frodo 2 psiconv_free_border(result->top_border);
542 frodo 64 result->top_border = temp_border;
543 frodo 2 len += leng;
544     break;
545     case 0x12:
546 frodo 168 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 frodo 64 goto ERROR1;
549 frodo 2 psiconv_free_border(result->bottom_border);
550 frodo 64 result->bottom_border = temp_border;
551 frodo 2 len += leng;
552     break;
553     case 0x13:
554 frodo 168 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 frodo 64 goto ERROR1;
557 frodo 2 psiconv_free_border(result->left_border);
558 frodo 64 result->left_border = temp_border;
559 frodo 2 len += leng;
560     break;
561     case 0x14:
562 frodo 168 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 frodo 64 goto ERROR1;
565 frodo 2 psiconv_free_border(result->right_border);
566 frodo 64 result->right_border = temp_border;
567 frodo 2 len += leng;
568     break;
569     case 0x15:
570 frodo 168 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 frodo 64 goto ERROR1;
573 frodo 2 psiconv_free_bullet(result->bullet);
574 frodo 64 result->bullet = temp_bullet;
575 frodo 2 len += leng;
576     break;
577     case 0x16:
578 frodo 168 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 frodo 64 &res);
581     if (res)
582     goto ERROR1;
583 frodo 2 len += leng;
584     break;
585     case 0x17:
586 frodo 168 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 frodo 64 goto ERROR1;
589     if ((res = psiconv_list_add(result->tabs->extras,temp_tab))) {
590     psiconv_free_tab(temp_tab);
591     goto ERROR1;
592     }
593 frodo 143 psiconv_free_tab(temp_tab);
594 frodo 2 len += leng;
595     break;
596     default:
597 frodo 168 psiconv_warn(config,lev+3,off+len,
598 frodo 2 "Unknown code in paragraph layout codes list");
599 frodo 168 psiconv_debug(config,lev+3,off+len,"Code: %02x",id);
600 frodo 2 len ++;
601     break;
602     }
603     nr ++;
604     }
605    
606     if (len - 4 != list_length) {
607 frodo 168 psiconv_warn(config,lev+2,off+len,
608 frodo 2 "Read past end of paragraph layout codes list. I probably lost track"
609     "somewhere!");
610 frodo 168 psiconv_debug(config,lev+2,off+len,"Read %d characters instead of %d",
611 frodo 2 len-4,list_length);
612 frodo 64 res = PSICONV_E_PARSE;
613     goto ERROR1;
614 frodo 2 }
615    
616     len = list_length + 4;
617    
618 frodo 168 psiconv_progress(config,lev+1,off+len,
619 frodo 2 "End of paragraph layout list (total length: %08x)",len);
620    
621     if (length)
622     *length = len;
623 frodo 64 return 0;
624    
625     ERROR1:
626 frodo 168 psiconv_warn(config,lev+1,off,"Reading of paragraph_layout_list failed");
627 frodo 64 if (length)
628     *length = 0;
629     if (!res)
630     return -PSICONV_E_NOMEM;
631     else
632     return res;
633 frodo 2 }
634    
635 frodo 168 int psiconv_parse_character_layout_list(const psiconv_config config,
636     const psiconv_buffer buf, int lev,
637 frodo 2 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 frodo 64 psiconv_color temp_color;
646     psiconv_font temp_font;
647 frodo 2
648 frodo 168 psiconv_progress(config,lev+1,off,"Going to read character layout codes");
649 frodo 2
650 frodo 168 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 frodo 64 if (res)
653     goto ERROR1;
654 frodo 168 psiconv_debug(config,lev+2,off,"Length in bytes: %08x",list_length);
655 frodo 2 len += 4;
656    
657     nr = 0;
658     while(len-4 < list_length) {
659 frodo 168 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 frodo 64 if (res)
663     goto ERROR1;
664 frodo 168 psiconv_debug(config,lev+3,off+len,"Id: %02x",id);
665 frodo 2 len ++;
666     switch(id) {
667 frodo 86 case 0x18:
668 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to skip an unknown setting");
669 frodo 86 len ++;
670     break;
671 frodo 2 case 0x19:
672 frodo 168 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 frodo 64 goto ERROR1;
675 frodo 2 psiconv_free_color(result->color);
676 frodo 64 result->color = temp_color;
677 frodo 2 len += leng;
678     break;
679     case 0x1a:
680 frodo 168 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 frodo 64 goto ERROR1;
683 frodo 2 psiconv_free_color(result->back_color);
684 frodo 64 result->back_color = temp_color;
685 frodo 2 len += leng;
686     break;
687 frodo 86 case 0x1b:
688 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to skip an unknown setting");
689 frodo 86 len ++;
690     break;
691 frodo 2 case 0x1c:
692 frodo 168 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 frodo 64 if (res)
695     goto ERROR1;
696 frodo 2 len += leng;
697     break;
698     case 0x1d:
699 frodo 168 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 frodo 64 goto ERROR1;
702 frodo 2 len += leng;
703     break;
704     case 0x1e:
705 frodo 168 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 frodo 64 goto ERROR1;
708 frodo 2 len += leng;
709     break;
710     case 0x1f:
711 frodo 168 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 frodo 64 if (res)
714     goto ERROR1;
715 frodo 2 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 frodo 168 psiconv_warn(config,lev+3,off+len,
723 frodo 2 "Unknown super_sub argument in character layout codes list");
724     }
725 frodo 168 psiconv_debug(config,lev+3,off+len,"Super_sub: %02x",temp);
726 frodo 2 len ++;
727     break;
728     case 0x20:
729 frodo 168 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 frodo 64 &result->underline)))
732     goto ERROR1;
733 frodo 2 len += leng;
734     break;
735     case 0x21:
736 frodo 168 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 frodo 67 &result->strikethrough)))
739 frodo 64 goto ERROR1;
740 frodo 2 len += leng;
741     break;
742     case 0x22:
743 frodo 168 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 frodo 64 goto ERROR1;
746 frodo 2 psiconv_free_font(result->font);
747 frodo 64 result->font = temp_font;
748 frodo 2 len += leng;
749     break;
750 frodo 86 case 0x23:
751 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to skip an unknown setting");
752 frodo 86 len ++;
753     break;
754 frodo 27 case 0x24:
755 frodo 168 psiconv_progress(config,lev+3,off+len,
756 frodo 27 "Going to read unknown code 0x24 (%02x expected)", 0);
757 frodo 168 temp = psiconv_read_u8(config,buf,lev+3,off+len,&res);
758 frodo 64 if (res)
759     goto ERROR1;
760 frodo 27 if (temp != 0) {
761 frodo 168 psiconv_warn(config,lev+3,off+len,
762 frodo 27 "Unknown code 0x24 value != 0x0 (0x%02x)", temp);
763     }
764     len ++;
765     break;
766 frodo 2 default:
767 frodo 168 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 frodo 2 len ++;
770     break;
771     }
772     nr ++;
773     }
774    
775     if (len - 4 != list_length) {
776 frodo 168 psiconv_warn(config,lev+2,off+len,
777 frodo 2 "Read past end of character layout codes list. I probably lost track"
778     "somewhere!");
779 frodo 168 psiconv_debug(config,lev+2,off+len,"Read %d characters instead of %d",
780 frodo 2 len-4,list_length);
781 frodo 64 res = PSICONV_E_PARSE;
782     goto ERROR1;
783 frodo 2 }
784    
785     len = list_length + 4;
786    
787 frodo 168 psiconv_progress(config,lev+1,off+len,
788 frodo 2 "End of character layout list (total length: %08x)",len);
789    
790     if (length)
791     *length = len;
792     return res;
793 frodo 64
794     ERROR1:
795 frodo 168 psiconv_warn(config,lev+1,off,"Reading of character_layout_list failed");
796 frodo 64 if (length)
797     *length = 0;
798     if (!res)
799     return -PSICONV_E_NOMEM;
800     else
801     return res;
802 frodo 2 }

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