/[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 182 - (hide 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 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     char *str_copy;
84 frodo 182 int len=0;
85     int leng;
86 frodo 2
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 182 (*result)->name = psiconv_read_short_string(config,buf,lev+2,off+len,
92     &leng,&res);
93 frodo 64 if (res)
94     goto ERROR2;
95 frodo 182 len += leng;
96    
97     (*result)->screenfont = psiconv_read_u8(config,buf,lev+2,off+len,&res);
98 frodo 64 if (res)
99     goto ERROR3;
100 frodo 2
101 frodo 64 if (!(str_copy = psiconv_make_printable((*result)->name)))
102     goto ERROR3;
103    
104 frodo 182 psiconv_debug(config,lev+2,off+len,
105     "Found font `%s', displayed with screen font %02x",
106 frodo 2 str_copy,(*result)->screenfont);
107     free(str_copy);
108 frodo 182 len ++;
109    
110 frodo 2 if (length)
111     *length = len;
112    
113 frodo 182 psiconv_progress(config,lev+1,off + len - 1,
114     "End of font (total length: %08x)",len);
115 frodo 64 return 0;
116    
117     ERROR3:
118     free ((*result)->name);
119     ERROR2:
120     free (*result);
121     ERROR1:
122 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Font failed");
123 frodo 64 if (length)
124     *length = 0;
125     if (!res)
126     return -PSICONV_E_NOMEM;
127     else
128     return res;
129 frodo 2 }
130    
131 frodo 168 int psiconv_parse_border(const psiconv_config config,
132     const psiconv_buffer buf,int lev,psiconv_u32 off,
133 frodo 2 int *length, psiconv_border *result)
134     {
135     int res = 0;
136     int len = 0;
137     psiconv_u32 temp;
138     int leng;
139    
140 frodo 168 psiconv_progress(config,lev+1,off,"Going to parse border data");
141 frodo 64 if (!(*result = malloc(sizeof(**result)))) {
142     goto ERROR1;
143     }
144 frodo 2
145 frodo 168 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 frodo 64 if (res)
148     goto ERROR2;
149 frodo 2 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 frodo 67 (*result)->kind = psiconv_border_dashed;
159 frodo 2 else if (temp == 0x05)
160 frodo 67 (*result)->kind = psiconv_border_dotdashed;
161 frodo 2 else if (temp == 0x06)
162 frodo 67 (*result)->kind = psiconv_border_dotdotdashed;
163 frodo 2 else {
164 frodo 168 psiconv_warn(config,lev+2,off,"Unknown border kind (defaults to `none')");
165 frodo 2 (*result)->kind = psiconv_border_none;
166     }
167 frodo 168 psiconv_debug(config,lev+2,off+len,"Kind: %02x",temp);
168 frodo 2 len ++;
169    
170 frodo 168 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 frodo 64 if (res)
173     goto ERROR2;
174 frodo 84 #if 0
175     /* This seems no longer necessary to test? */
176 frodo 2 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 frodo 168 psiconv_warn(config,lev+2,off,
181 frodo 2 "Border thickness specified for unlikely border type");
182     }
183 frodo 84 #endif
184 frodo 168 psiconv_debug(config,lev+2,off+len,"Thickness: %f",(*result)->thickness);
185 frodo 2 len += leng;
186    
187 frodo 168 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 frodo 64 goto ERROR2;
190 frodo 2 len += leng;
191    
192 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the final unknown byte "
193 frodo 84 "(0x00 or 0x01 expected)");
194 frodo 168 temp = psiconv_read_u8(config,buf,lev+2,off + len,&res);
195 frodo 64 if (res)
196     goto ERROR3;
197 frodo 84 if ((temp != 0x01) && (temp != 0x00)) {
198 frodo 168 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 frodo 84 temp,0x00,0x01);
201 frodo 2 }
202     len ++;
203    
204     if (length)
205     *length = len;
206    
207 frodo 168 psiconv_progress(config,lev+1,off + len - 1,
208 frodo 2 "End of border (total length: %08x)",len);
209    
210 frodo 64 return 0;
211    
212     ERROR3:
213     psiconv_free_color((*result)->color);
214     ERROR2:
215     free (result);
216     ERROR1:
217 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Border failed");
218 frodo 64 if (length)
219     *length = 0;
220     if (!res)
221     return -PSICONV_E_NOMEM;
222     else
223     return res;
224 frodo 2 }
225    
226 frodo 168 int psiconv_parse_bullet(const psiconv_config config,
227     const psiconv_buffer buf,int lev,psiconv_u32 off,
228 frodo 2 int *length, psiconv_bullet *result)
229     {
230     int res = 0;
231     int len = 0;
232     int leng;
233     int bullet_length;
234    
235 frodo 64 if (!(*result = malloc(sizeof(**result))))
236     goto ERROR1;
237 frodo 2 (*result)->on = psiconv_bool_true;
238    
239 frodo 168 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 frodo 64 if (res)
243     goto ERROR2;
244 frodo 168 psiconv_debug(config,lev+2,off+len,"Length: %02x",bullet_length);
245 frodo 2 len ++;
246    
247 frodo 168 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 frodo 64 if (res)
250     goto ERROR2;
251 frodo 2 len +=leng;
252    
253 frodo 168 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 frodo 64 if (res)
256     goto ERROR2;
257 frodo 168 psiconv_debug(config,lev+2,off+len,"Character: %02x",(*result)->character);
258 frodo 2 len ++;
259    
260 frodo 168 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 frodo 64 goto ERROR2;
263 frodo 168 psiconv_debug(config,lev+2,off+len,"Indent on: %02x",(*result)->indent);
264 frodo 2 len += leng;
265    
266 frodo 168 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 frodo 64 goto ERROR2;
269 frodo 2 len += leng;
270    
271 frodo 168 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 frodo 64 goto ERROR3;
274 frodo 2 len += leng;
275    
276     if (len != bullet_length + 1) {
277 frodo 168 psiconv_warn(config,lev+2,off,"Bullet data structure length mismatch");
278     psiconv_debug(config,lev+2,off,"Length: specified %02x, found %02x",
279 frodo 2 bullet_length,len-1);
280     }
281    
282 frodo 168 psiconv_progress(config,lev+1,off + len - 1,
283 frodo 2 "End of bullet data (total length: %08x)",len);
284    
285     if (length)
286     *length = len;
287 frodo 65 return 0;
288 frodo 64
289     ERROR3:
290     psiconv_free_color((*result)->color);
291     ERROR2:
292     free (result);
293     ERROR1:
294 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Bullet failed");
295 frodo 64 if (length)
296     *length = 0;
297     if (!res)
298     return -PSICONV_E_NOMEM;
299     else
300     return res;
301 frodo 2 }
302    
303 frodo 168 int psiconv_parse_tab(const psiconv_config config,
304     const psiconv_buffer buf, int lev, psiconv_u32 off,
305 frodo 2 int *length, psiconv_tab *result)
306     {
307     int res = 0;
308     int len = 0;
309     int leng;
310     psiconv_u8 temp;
311    
312 frodo 168 psiconv_progress(config,lev+1,off,"Going to parse tab");
313 frodo 64 if (!(*result = malloc(sizeof(**result))))
314     goto ERROR1;
315 frodo 2
316 frodo 168 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 frodo 64 if (res)
319     goto ERROR2;
320 frodo 2 len += leng;
321    
322 frodo 168 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 frodo 64 if (res)
325     goto ERROR2;
326 frodo 2 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 frodo 168 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 frodo 2 temp);
336     (*result)->kind = psiconv_tab_left;
337     }
338 frodo 168 psiconv_debug(config,lev+2,off+len,"Kind: %02x",temp);
339 frodo 2 len ++;
340    
341     if (length)
342     *length = len;
343    
344 frodo 168 psiconv_progress(config,lev+1,off+len-1,"End of tab (total length: %08x)",len);
345 frodo 64 return 0;
346 frodo 2
347 frodo 64 ERROR2:
348     free (result);
349     ERROR1:
350 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Tab failed");
351 frodo 64 if (length)
352     *length = 0;
353     if (!res)
354     return -PSICONV_E_NOMEM;
355     else
356     return res;
357 frodo 2 }
358    
359 frodo 168 int psiconv_parse_paragraph_layout_list(const psiconv_config config,
360     const psiconv_buffer buf, int lev,
361 frodo 2 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 frodo 64 psiconv_tab temp_tab;
370     psiconv_color temp_color;
371     psiconv_border temp_border;
372     psiconv_bullet temp_bullet;
373 frodo 2
374 frodo 168 psiconv_progress(config,lev+1,off,"Going to read paragraph layout list");
375 frodo 2
376 frodo 168 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 frodo 64 if (res)
379     goto ERROR1;
380 frodo 168 psiconv_debug(config,lev+2,off,"Length in bytes: %08x",list_length);
381 frodo 2 len += 4;
382    
383     nr = 0;
384     while(len - 4 < list_length) {
385 frodo 168 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 frodo 64 if (res)
389     goto ERROR1;
390 frodo 168 psiconv_debug(config,lev+3,off+len,"Id: %02x",id);
391 frodo 2 len ++;
392     switch(id) {
393     case 0x01:
394 frodo 168 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 frodo 64 goto ERROR1;
397 frodo 2 psiconv_free_color(result->back_color);
398 frodo 64 result->back_color = temp_color;
399 frodo 2 len += leng;
400     break;
401     case 0x02:
402 frodo 168 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 frodo 64 if (res)
405     goto ERROR1;
406 frodo 2 len += leng;
407     break;
408     case 0x03:
409 frodo 168 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 frodo 64 &res);
412     if (res)
413     goto ERROR1;
414 frodo 2 len += leng;
415     break;
416     case 0x04:
417 frodo 168 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 frodo 64 &res);
420     if (res)
421     goto ERROR1;
422 frodo 2 len += leng;
423     break;
424     case 0x05:
425 frodo 168 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 frodo 64 if (res)
428     goto ERROR1;
429 frodo 2 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 frodo 168 psiconv_warn(config,lev+3,off+len, "Unknown horizontal justify argument "
439 frodo 2 "in paragraph layout codes list");
440 frodo 64 result->justify_hor = psiconv_justify_left;
441 frodo 2 }
442 frodo 168 psiconv_debug(config,lev+3,off+len,"Justify: %02x",temp);
443 frodo 2 len ++;
444     break;
445     case 0x06:
446 frodo 168 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 frodo 64 if (res)
449     goto ERROR1;
450 frodo 2 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 frodo 168 psiconv_warn(config,lev+3,off+len, "Unknown vertical justify argument "
458 frodo 2 "in paragraph layout codes list");
459 frodo 64 result->justify_ver = psiconv_justify_bottom;
460 frodo 2 }
461 frodo 168 psiconv_debug(config,lev+3,off+len,"Justify: %02x",temp);
462 frodo 2 len ++;
463 frodo 110 break;
464 frodo 2 case 0x07:
465 frodo 168 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 frodo 64 if (res)
468     goto ERROR1;
469 frodo 2 len += leng;
470     break;
471     case 0x08:
472 frodo 168 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 frodo 67 &result->linespacing_exact)))
475 frodo 64 goto ERROR1;
476 frodo 2 len += leng;
477     break;
478     case 0x09:
479 frodo 168 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 frodo 64 if (res)
482     goto ERROR1;
483 frodo 2 len += leng;
484     break;
485     case 0x0a:
486 frodo 168 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 frodo 64 if (res)
489     goto ERROR1;
490 frodo 2 len += leng;
491     break;
492     case 0x0b:
493 frodo 168 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 frodo 67 &result->keep_together)))
496 frodo 64 goto ERROR1;
497 frodo 2 len += leng;
498     break;
499     case 0x0c:
500 frodo 168 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 frodo 67 &result->keep_with_next)))
503 frodo 64 goto ERROR1;
504 frodo 2 len += leng;
505     break;
506     case 0x0d:
507 frodo 168 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 frodo 64 &result->on_next_page)))
510     goto ERROR1;
511 frodo 2 len += leng;
512     break;
513     case 0x0e:
514 frodo 168 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 frodo 64 &result->no_widow_protection)))
517     goto ERROR1;
518 frodo 2 len += leng;
519     break;
520 frodo 104 case 0x0f:
521 frodo 168 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 frodo 104 &result->wrap_to_fit_cell)))
524     goto ERROR1;
525     len += leng;
526     break;
527 frodo 2 case 0x10:
528 frodo 168 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 frodo 64 off+len,&leng,&res);
531     if (res)
532     goto ERROR1;
533 frodo 2 len += leng;
534     break;
535     case 0x11:
536 frodo 168 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 frodo 64 goto ERROR1;
539 frodo 2 psiconv_free_border(result->top_border);
540 frodo 64 result->top_border = temp_border;
541 frodo 2 len += leng;
542     break;
543     case 0x12:
544 frodo 168 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 frodo 64 goto ERROR1;
547 frodo 2 psiconv_free_border(result->bottom_border);
548 frodo 64 result->bottom_border = temp_border;
549 frodo 2 len += leng;
550     break;
551     case 0x13:
552 frodo 168 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 frodo 64 goto ERROR1;
555 frodo 2 psiconv_free_border(result->left_border);
556 frodo 64 result->left_border = temp_border;
557 frodo 2 len += leng;
558     break;
559     case 0x14:
560 frodo 168 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 frodo 64 goto ERROR1;
563 frodo 2 psiconv_free_border(result->right_border);
564 frodo 64 result->right_border = temp_border;
565 frodo 2 len += leng;
566     break;
567     case 0x15:
568 frodo 168 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 frodo 64 goto ERROR1;
571 frodo 2 psiconv_free_bullet(result->bullet);
572 frodo 64 result->bullet = temp_bullet;
573 frodo 2 len += leng;
574     break;
575     case 0x16:
576 frodo 168 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 frodo 64 &res);
579     if (res)
580     goto ERROR1;
581 frodo 2 len += leng;
582     break;
583     case 0x17:
584 frodo 168 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 frodo 64 goto ERROR1;
587     if ((res = psiconv_list_add(result->tabs->extras,temp_tab))) {
588     psiconv_free_tab(temp_tab);
589     goto ERROR1;
590     }
591 frodo 143 psiconv_free_tab(temp_tab);
592 frodo 2 len += leng;
593     break;
594     default:
595 frodo 168 psiconv_warn(config,lev+3,off+len,
596 frodo 2 "Unknown code in paragraph layout codes list");
597 frodo 168 psiconv_debug(config,lev+3,off+len,"Code: %02x",id);
598 frodo 2 len ++;
599     break;
600     }
601     nr ++;
602     }
603    
604     if (len - 4 != list_length) {
605 frodo 168 psiconv_warn(config,lev+2,off+len,
606 frodo 2 "Read past end of paragraph layout codes list. I probably lost track"
607     "somewhere!");
608 frodo 168 psiconv_debug(config,lev+2,off+len,"Read %d characters instead of %d",
609 frodo 2 len-4,list_length);
610 frodo 64 res = PSICONV_E_PARSE;
611     goto ERROR1;
612 frodo 2 }
613    
614     len = list_length + 4;
615    
616 frodo 168 psiconv_progress(config,lev+1,off+len,
617 frodo 2 "End of paragraph layout list (total length: %08x)",len);
618    
619     if (length)
620     *length = len;
621 frodo 64 return 0;
622    
623     ERROR1:
624 frodo 168 psiconv_warn(config,lev+1,off,"Reading of paragraph_layout_list failed");
625 frodo 64 if (length)
626     *length = 0;
627     if (!res)
628     return -PSICONV_E_NOMEM;
629     else
630     return res;
631 frodo 2 }
632    
633 frodo 168 int psiconv_parse_character_layout_list(const psiconv_config config,
634     const psiconv_buffer buf, int lev,
635 frodo 2 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 frodo 64 psiconv_color temp_color;
644     psiconv_font temp_font;
645 frodo 2
646 frodo 168 psiconv_progress(config,lev+1,off,"Going to read character layout codes");
647 frodo 2
648 frodo 168 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 frodo 64 if (res)
651     goto ERROR1;
652 frodo 168 psiconv_debug(config,lev+2,off,"Length in bytes: %08x",list_length);
653 frodo 2 len += 4;
654    
655     nr = 0;
656     while(len-4 < list_length) {
657 frodo 168 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 frodo 64 if (res)
661     goto ERROR1;
662 frodo 168 psiconv_debug(config,lev+3,off+len,"Id: %02x",id);
663 frodo 2 len ++;
664     switch(id) {
665 frodo 86 case 0x18:
666 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to skip an unknown setting");
667 frodo 86 len ++;
668     break;
669 frodo 2 case 0x19:
670 frodo 168 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 frodo 64 goto ERROR1;
673 frodo 2 psiconv_free_color(result->color);
674 frodo 64 result->color = temp_color;
675 frodo 2 len += leng;
676     break;
677     case 0x1a:
678 frodo 168 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 frodo 64 goto ERROR1;
681 frodo 2 psiconv_free_color(result->back_color);
682 frodo 64 result->back_color = temp_color;
683 frodo 2 len += leng;
684     break;
685 frodo 86 case 0x1b:
686 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to skip an unknown setting");
687 frodo 86 len ++;
688     break;
689 frodo 2 case 0x1c:
690 frodo 168 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 frodo 64 if (res)
693     goto ERROR1;
694 frodo 2 len += leng;
695     break;
696     case 0x1d:
697 frodo 168 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 frodo 64 goto ERROR1;
700 frodo 2 len += leng;
701     break;
702     case 0x1e:
703 frodo 168 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 frodo 64 goto ERROR1;
706 frodo 2 len += leng;
707     break;
708     case 0x1f:
709 frodo 168 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 frodo 64 if (res)
712     goto ERROR1;
713 frodo 2 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 frodo 168 psiconv_warn(config,lev+3,off+len,
721 frodo 2 "Unknown super_sub argument in character layout codes list");
722     }
723 frodo 168 psiconv_debug(config,lev+3,off+len,"Super_sub: %02x",temp);
724 frodo 2 len ++;
725     break;
726     case 0x20:
727 frodo 168 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 frodo 64 &result->underline)))
730     goto ERROR1;
731 frodo 2 len += leng;
732     break;
733     case 0x21:
734 frodo 168 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 frodo 67 &result->strikethrough)))
737 frodo 64 goto ERROR1;
738 frodo 2 len += leng;
739     break;
740     case 0x22:
741 frodo 168 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 frodo 64 goto ERROR1;
744 frodo 2 psiconv_free_font(result->font);
745 frodo 64 result->font = temp_font;
746 frodo 2 len += leng;
747     break;
748 frodo 86 case 0x23:
749 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to skip an unknown setting");
750 frodo 86 len ++;
751     break;
752 frodo 27 case 0x24:
753 frodo 168 psiconv_progress(config,lev+3,off+len,
754 frodo 27 "Going to read unknown code 0x24 (%02x expected)", 0);
755 frodo 168 temp = psiconv_read_u8(config,buf,lev+3,off+len,&res);
756 frodo 64 if (res)
757     goto ERROR1;
758 frodo 27 if (temp != 0) {
759 frodo 168 psiconv_warn(config,lev+3,off+len,
760 frodo 27 "Unknown code 0x24 value != 0x0 (0x%02x)", temp);
761     }
762     len ++;
763     break;
764 frodo 2 default:
765 frodo 168 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 frodo 2 len ++;
768     break;
769     }
770     nr ++;
771     }
772    
773     if (len - 4 != list_length) {
774 frodo 168 psiconv_warn(config,lev+2,off+len,
775 frodo 2 "Read past end of character layout codes list. I probably lost track"
776     "somewhere!");
777 frodo 168 psiconv_debug(config,lev+2,off+len,"Read %d characters instead of %d",
778 frodo 2 len-4,list_length);
779 frodo 64 res = PSICONV_E_PARSE;
780     goto ERROR1;
781 frodo 2 }
782    
783     len = list_length + 4;
784    
785 frodo 168 psiconv_progress(config,lev+1,off+len,
786 frodo 2 "End of character layout list (total length: %08x)",len);
787    
788     if (length)
789     *length = len;
790     return res;
791 frodo 64
792     ERROR1:
793 frodo 168 psiconv_warn(config,lev+1,off,"Reading of character_layout_list failed");
794 frodo 64 if (length)
795     *length = 0;
796     if (!res)
797     return -PSICONV_E_NOMEM;
798     else
799     return res;
800 frodo 2 }

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