… | |
… | |
29 | int psiconv_parse_page_header(const psiconv_buffer buf,int lev,psiconv_u32 off, |
29 | int psiconv_parse_page_header(const psiconv_buffer buf,int lev,psiconv_u32 off, |
30 | int *length,psiconv_page_header *result) |
30 | int *length,psiconv_page_header *result) |
31 | { |
31 | { |
32 | int res = 0; |
32 | int res = 0; |
33 | int len = 0; |
33 | int len = 0; |
34 | int i,leng; |
34 | int i,leng,has_content; |
35 | psiconv_u32 temp; |
35 | psiconv_u32 temp; |
36 | |
36 | |
37 | psiconv_progress(lev+1,off,"Going to read a page header (or footer)"); |
37 | psiconv_progress(lev+1,off,"Going to read a page header (or footer)"); |
38 | if (!(*result = malloc(sizeof(**result)))) |
38 | if (!(*result = malloc(sizeof(**result)))) |
39 | goto ERROR1; |
39 | goto ERROR1; |
40 | |
40 | |
41 | psiconv_progress(lev+2,off+len, |
41 | psiconv_progress(lev+2,off+len, |
42 | "Going to read the first byte (0x01 expected)"); |
42 | "Going to read the has_content flag"); |
43 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
43 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
44 | if (res) |
44 | if (res) |
45 | goto ERROR2; |
45 | goto ERROR2; |
46 | if (temp != 0x01) { |
46 | if (temp == 0x00) |
47 | psiconv_warn(lev+2,off+len,"Page header first byte mismatch"); |
47 | has_content = 0; |
48 | psiconv_debug(lev+2,off+len,"First byte: read %02x, expected %02x", |
48 | else if (temp == 0x01) |
49 | temp,0x01); |
49 | has_content = 1; |
|
|
50 | else { |
|
|
51 | psiconv_warn(lev+2,off+len, |
|
|
52 | "Page header has_content flag unknown value (assumed default)"); |
|
|
53 | psiconv_debug(lev+2,off+len,"Flag: %02x",temp); |
|
|
54 | has_content = 1; |
50 | } |
55 | } |
|
|
56 | psiconv_debug(lev+2,off+len,"Has_content flag: %02x",has_content); |
51 | len += 1; |
57 | len += 1; |
52 | |
58 | |
53 | psiconv_progress(lev+2,off+len,"Going to read displayed-on-first-page flag"); |
59 | psiconv_progress(lev+2,off+len,"Going to read displayed-on-first-page flag"); |
54 | if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
60 | if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
55 | &(*result)->on_first_page))) |
61 | &(*result)->on_first_page))) |
… | |
… | |
70 | } |
76 | } |
71 | |
77 | |
72 | psiconv_progress(lev+2,off+len,"Going to read base paragraph layout"); |
78 | psiconv_progress(lev+2,off+len,"Going to read base paragraph layout"); |
73 | if (!((*result)->base_paragraph_layout = psiconv_basic_paragraph_layout())) |
79 | if (!((*result)->base_paragraph_layout = psiconv_basic_paragraph_layout())) |
74 | goto ERROR2; |
80 | goto ERROR2; |
|
|
81 | |
|
|
82 | if (has_content) { |
75 | if ((res = psiconv_parse_paragraph_layout_list(buf,lev+2,off+len,&leng, |
83 | if ((res = psiconv_parse_paragraph_layout_list(buf,lev+2,off+len,&leng, |
76 | (*result)->base_paragraph_layout))) |
84 | (*result)->base_paragraph_layout))) |
77 | goto ERROR3; |
85 | goto ERROR3; |
78 | len += leng; |
86 | len += leng; |
|
|
87 | } |
79 | |
88 | |
80 | psiconv_progress(lev+2,off+len,"Going to read base character layout"); |
89 | psiconv_progress(lev+2,off+len,"Going to read base character layout"); |
81 | if (!((*result)->base_character_layout = psiconv_basic_character_layout())) |
90 | if (!((*result)->base_character_layout = psiconv_basic_character_layout())) |
82 | goto ERROR3; |
91 | goto ERROR3; |
|
|
92 | if (has_content) { |
83 | if ((res = psiconv_parse_character_layout_list(buf,lev+2,off+len,&leng, |
93 | if ((res = psiconv_parse_character_layout_list(buf,lev+2,off+len,&leng, |
84 | (*result)->base_character_layout))) |
94 | (*result)->base_character_layout))) |
85 | goto ERROR4; |
95 | goto ERROR4; |
|
|
96 | } |
86 | len += leng; |
97 | len += leng; |
87 | |
98 | |
88 | |
99 | |
89 | psiconv_progress(lev+2,off+len,"Going to read the TextEd section"); |
100 | psiconv_progress(lev+2,off+len,"Going to read the TextEd section"); |
|
|
101 | if (has_content) { |
90 | if ((res = psiconv_parse_texted_section(buf,lev+2,off+len,&leng, |
102 | if ((res = psiconv_parse_texted_section(buf,lev+2,off+len,&leng, |
91 | &(*result)->text, |
103 | &(*result)->text, |
92 | (*result)->base_character_layout, |
104 | (*result)->base_character_layout, |
93 | (*result)->base_paragraph_layout))) |
105 | (*result)->base_paragraph_layout))) |
94 | goto ERROR4; |
106 | goto ERROR4; |
95 | len += leng; |
107 | len += leng; |
|
|
108 | } else { |
|
|
109 | (*result)->text = NULL; |
|
|
110 | } |
96 | |
111 | |
97 | if (length) |
112 | if (length) |
98 | *length = len; |
113 | *length = len; |
99 | |
114 | |
100 | psiconv_progress(lev+1,off+len-1,"End of page header" |
115 | psiconv_progress(lev+1,off+len-1,"End of page header" |