/[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 184 - (hide annotations)
Tue Jan 6 20:15:01 2004 UTC (20 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 26452 byte(s)
(Frodo) Unicode transition

Note: this commit breaks psiconv. The programs in the extra directory should
work properly.

  * Change all datastructures to use unicode for character encodings
  * Added psiconv_error function
  * Called psiconv_error at places where a warning was stupid
  * Added psiconv_progress in all generate functions
  * Added lev parameter to all generate functions
  * Removed general.h from CVS (we have general.h.in, after all)
  * Probably other stuff I forgot

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

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