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

Diff of /psiconv/trunk/lib/psiconv/parse_page.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 64 Revision 142
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/ 18*/
19 19
20#include "config.h" 20#include "config.h"
21#include "compat.h"
22
21#include <stdlib.h> 23#include <stdlib.h>
22#include <string.h> 24#include <string.h>
23 25
24#include "data.h"
25#include "parse_routines.h" 26#include "parse_routines.h"
27#include "error.h"
28
29#ifdef DMALLOC
30#include <dmalloc.h>
31#endif
32
26 33
27int psiconv_parse_page_header(const psiconv_buffer buf,int lev,psiconv_u32 off, 34int psiconv_parse_page_header(const psiconv_buffer buf,int lev,psiconv_u32 off,
28 int *length,psiconv_page_header *result) 35 int *length,psiconv_page_header *result)
29{ 36{
30 int res = 0; 37 int res = 0;
31 int len = 0; 38 int len = 0;
32 int i,leng; 39 int i,leng,has_content;
33 psiconv_u32 temp; 40 psiconv_u32 temp;
34 41
35 psiconv_progress(lev+1,off,"Going to read a page header (or footer)"); 42 psiconv_progress(lev+1,off,"Going to read a page header (or footer)");
36 if (!(*result = malloc(sizeof(**result)))) 43 if (!(*result = malloc(sizeof(**result))))
37 goto ERROR1; 44 goto ERROR1;
38 45
39 psiconv_progress(lev+2,off+len, 46 psiconv_progress(lev+2,off+len,
40 "Going to read the first byte (0x01 expected)"); 47 "Going to read the has_content flag");
41 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 48 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
42 if (!res) 49 if (res)
43 goto ERROR2; 50 goto ERROR2;
44 if (temp != 0x01) { 51 if (temp == 0x00)
45 psiconv_warn(lev+2,off+len,"Page header first byte mismatch"); 52 has_content = 0;
46 psiconv_debug(lev+2,off+len,"First byte: read %02x, expected %02x", 53 else if (temp == 0x01)
47 temp,0x01); 54 has_content = 1;
55 else {
56 psiconv_warn(lev+2,off+len,
57 "Page header has_content flag unknown value (assumed default)");
58 psiconv_debug(lev+2,off+len,"Flag: %02x",temp);
59 has_content = 1;
48 } 60 }
61 psiconv_debug(lev+2,off+len,"Has_content flag: %02x",has_content);
49 len += 1; 62 len += 1;
50 63
51 psiconv_progress(lev+2,off+len,"Going to read displayed-on-first-page flag"); 64 psiconv_progress(lev+2,off+len,"Going to read displayed-on-first-page flag");
52 if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, 65 if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng,
53 &(*result)->on_first_page))) 66 &(*result)->on_first_page)))
68 } 81 }
69 82
70 psiconv_progress(lev+2,off+len,"Going to read base paragraph layout"); 83 psiconv_progress(lev+2,off+len,"Going to read base paragraph layout");
71 if (!((*result)->base_paragraph_layout = psiconv_basic_paragraph_layout())) 84 if (!((*result)->base_paragraph_layout = psiconv_basic_paragraph_layout()))
72 goto ERROR2; 85 goto ERROR2;
86
87 if (has_content) {
73 if ((res = psiconv_parse_paragraph_layout_list(buf,lev+2,off+len,&leng, 88 if ((res = psiconv_parse_paragraph_layout_list(buf,lev+2,off+len,&leng,
74 (*result)->base_paragraph_layout))) 89 (*result)->base_paragraph_layout)))
75 goto ERROR3; 90 goto ERROR3;
76 len += leng; 91 len += leng;
92 }
77 93
78 psiconv_progress(lev+2,off+len,"Going to read base character layout"); 94 psiconv_progress(lev+2,off+len,"Going to read base character layout");
79 if (!((*result)->base_character_layout = psiconv_basic_character_layout())) 95 if (!((*result)->base_character_layout = psiconv_basic_character_layout()))
80 goto ERROR3; 96 goto ERROR3;
97 if (has_content) {
81 if ((res = psiconv_parse_character_layout_list(buf,lev+2,off+len,&leng, 98 if ((res = psiconv_parse_character_layout_list(buf,lev+2,off+len,&leng,
82 (*result)->base_character_layout))) 99 (*result)->base_character_layout)))
83 goto ERROR4; 100 goto ERROR4;
101 }
84 len += leng; 102 len += leng;
85 103
86 104
87 psiconv_progress(lev+2,off+len,"Going to read the TextEd section"); 105 psiconv_progress(lev+2,off+len,"Going to read the TextEd section");
106 if (has_content) {
88 if ((res = psiconv_parse_texted_section(buf,lev+2,off+len,&leng, 107 if ((res = psiconv_parse_texted_section(buf,lev+2,off+len,&leng,
89 &(*result)->text, 108 &(*result)->text,
90 (*result)->base_character_layout, 109 (*result)->base_character_layout,
91 (*result)->base_paragraph_layout))) 110 (*result)->base_paragraph_layout)))
92 goto ERROR4; 111 goto ERROR4;
93 len += leng; 112 len += leng;
113 } else {
114 (*result)->text = NULL;
115 }
94 116
95 if (length) 117 if (length)
96 *length = len; 118 *length = len;
97 119
98 psiconv_progress(lev+1,off+len-1,"End of page header" 120 psiconv_progress(lev+1,off+len-1,"End of page header"
192 214
193 psiconv_progress(lev+2,off+len,"Going to read page dimensions id"); 215 psiconv_progress(lev+2,off+len,"Going to read page dimensions id");
194 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 216 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
195 if (res) 217 if (res)
196 goto ERROR4; 218 goto ERROR4;
197 if (temp != PSICONV_ID_PAGE_DIMENSIONS) { 219 if ((temp != PSICONV_ID_PAGE_DIMENSIONS1) &&
220 (temp != PSICONV_ID_PAGE_DIMENSIONS2)) {
198 psiconv_warn(lev+2,off+len, 221 psiconv_warn(lev+2,off+len,
199 "Page layout section page dimensions marker not found"); 222 "Page layout section page dimensions marker not found");
200 psiconv_debug(lev+2,off+len, 223 psiconv_debug(lev+2,off+len,
201 "Page dimensions marker: read %08x, expected %08x",temp, 224 "Page dimensions marker: read %08x, expected %08x or %08x",
225 temp, PSICONV_ID_PAGE_DIMENSIONS1,
202 PSICONV_ID_PAGE_DIMENSIONS); 226 PSICONV_ID_PAGE_DIMENSIONS2);
203 } 227 }
228 len += 4;
204 229
205 psiconv_progress(lev+2,off+len,"Going to read the page width"); 230 psiconv_progress(lev+2,off+len,"Going to read the page width");
206 (*result)->page_width = psiconv_read_length(buf,lev+2,off+len,&leng,&res); 231 (*result)->page_width = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
207 if (!res) 232 if (res)
208 goto ERROR4; 233 goto ERROR4;
209 psiconv_debug(lev+2,off+len,"Page width: %6.3f",(*result)->page_width); 234 psiconv_debug(lev+2,off+len,"Page width: %6.3f",(*result)->page_width);
210 len += leng; 235 len += leng;
211 236
212 psiconv_progress(lev+2,off+len,"Going to read the page height"); 237 psiconv_progress(lev+2,off+len,"Going to read the page height");
213 (*result)->page_height = psiconv_read_length(buf,lev+2,off+len,&leng,&res); 238 (*result)->page_height = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
214 if (!res) 239 if (res)
215 goto ERROR4; 240 goto ERROR4;
216 psiconv_debug(lev+2,off+len,"Page height: %6.3f",(*result)->page_height); 241 psiconv_debug(lev+2,off+len,"Page height: %6.3f",(*result)->page_height);
217 len += leng; 242 len += leng;
243
244 psiconv_progress(lev+2,off+len,"Going to read page portrait/landscape");
245 if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->landscape)))
246 goto ERROR4;
247 psiconv_debug(lev+2,off+len,"Landscape: %d",(*result)->landscape);
248 len += leng;
249
218 250
219 if (length) 251 if (length)
220 *length = len; 252 *length = len;
221 253
222 psiconv_progress(lev,off+len-1,"End of page section (total length: %08x)", 254 psiconv_progress(lev,off+len-1,"End of page section (total length: %08x)",

Legend:
Removed from v.64  
changed lines
  Added in v.142

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