… | |
… | |
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" |
26 | |
28 | |
27 | 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, |
28 | int *length,psiconv_page_header *result) |
30 | int *length,psiconv_page_header *result) |
29 | { |
31 | { |
30 | int res = 0; |
32 | int res = 0; |
31 | int len = 0; |
33 | int len = 0; |
32 | int i,leng; |
34 | int i,leng,has_content; |
33 | psiconv_u32 temp; |
35 | psiconv_u32 temp; |
34 | |
36 | |
35 | 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)"); |
36 | if (!(*result = malloc(sizeof(**result)))) |
38 | if (!(*result = malloc(sizeof(**result)))) |
37 | goto ERROR1; |
39 | goto ERROR1; |
38 | |
40 | |
39 | psiconv_progress(lev+2,off+len, |
41 | psiconv_progress(lev+2,off+len, |
40 | "Going to read the first byte (0x01 expected)"); |
42 | "Going to read the has_content flag"); |
41 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
43 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
42 | if (res) |
44 | if (res) |
43 | goto ERROR2; |
45 | goto ERROR2; |
44 | if (temp != 0x01) { |
46 | if (temp == 0x00) |
45 | psiconv_warn(lev+2,off+len,"Page header first byte mismatch"); |
47 | has_content = 0; |
46 | psiconv_debug(lev+2,off+len,"First byte: read %02x, expected %02x", |
48 | else if (temp == 0x01) |
47 | 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; |
48 | } |
55 | } |
|
|
56 | psiconv_debug(lev+2,off+len,"Has_content flag: %02x",has_content); |
49 | len += 1; |
57 | len += 1; |
50 | |
58 | |
51 | 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"); |
52 | if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
60 | if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
53 | &(*result)->on_first_page))) |
61 | &(*result)->on_first_page))) |
… | |
… | |
68 | } |
76 | } |
69 | |
77 | |
70 | 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"); |
71 | if (!((*result)->base_paragraph_layout = psiconv_basic_paragraph_layout())) |
79 | if (!((*result)->base_paragraph_layout = psiconv_basic_paragraph_layout())) |
72 | goto ERROR2; |
80 | goto ERROR2; |
|
|
81 | |
|
|
82 | if (has_content) { |
73 | 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, |
74 | (*result)->base_paragraph_layout))) |
84 | (*result)->base_paragraph_layout))) |
75 | goto ERROR3; |
85 | goto ERROR3; |
76 | len += leng; |
86 | len += leng; |
|
|
87 | } |
77 | |
88 | |
78 | 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"); |
79 | if (!((*result)->base_character_layout = psiconv_basic_character_layout())) |
90 | if (!((*result)->base_character_layout = psiconv_basic_character_layout())) |
80 | goto ERROR3; |
91 | goto ERROR3; |
|
|
92 | if (has_content) { |
81 | 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, |
82 | (*result)->base_character_layout))) |
94 | (*result)->base_character_layout))) |
83 | goto ERROR4; |
95 | goto ERROR4; |
|
|
96 | } |
84 | len += leng; |
97 | len += leng; |
85 | |
98 | |
86 | |
99 | |
87 | 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) { |
88 | 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, |
89 | &(*result)->text, |
103 | &(*result)->text, |
90 | (*result)->base_character_layout, |
104 | (*result)->base_character_layout, |
91 | (*result)->base_paragraph_layout))) |
105 | (*result)->base_paragraph_layout))) |
92 | goto ERROR4; |
106 | goto ERROR4; |
93 | len += leng; |
107 | len += leng; |
|
|
108 | } else { |
|
|
109 | (*result)->text = NULL; |
|
|
110 | } |
94 | |
111 | |
95 | if (length) |
112 | if (length) |
96 | *length = len; |
113 | *length = len; |
97 | |
114 | |
98 | psiconv_progress(lev+1,off+len-1,"End of page header" |
115 | psiconv_progress(lev+1,off+len-1,"End of page header" |
… | |
… | |
192 | |
209 | |
193 | psiconv_progress(lev+2,off+len,"Going to read page dimensions id"); |
210 | psiconv_progress(lev+2,off+len,"Going to read page dimensions id"); |
194 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
211 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
195 | if (res) |
212 | if (res) |
196 | goto ERROR4; |
213 | goto ERROR4; |
197 | if (temp != PSICONV_ID_PAGE_DIMENSIONS) { |
214 | if ((temp != PSICONV_ID_PAGE_DIMENSIONS1) && |
|
|
215 | (temp != PSICONV_ID_PAGE_DIMENSIONS2)) { |
198 | psiconv_warn(lev+2,off+len, |
216 | psiconv_warn(lev+2,off+len, |
199 | "Page layout section page dimensions marker not found"); |
217 | "Page layout section page dimensions marker not found"); |
200 | psiconv_debug(lev+2,off+len, |
218 | psiconv_debug(lev+2,off+len, |
201 | "Page dimensions marker: read %08x, expected %08x",temp, |
219 | "Page dimensions marker: read %08x, expected %08x or %08x", |
|
|
220 | temp, PSICONV_ID_PAGE_DIMENSIONS1, |
202 | PSICONV_ID_PAGE_DIMENSIONS); |
221 | PSICONV_ID_PAGE_DIMENSIONS2); |
203 | } |
222 | } |
204 | len += 4; |
223 | len += 4; |
205 | |
224 | |
206 | psiconv_progress(lev+2,off+len,"Going to read the page width"); |
225 | psiconv_progress(lev+2,off+len,"Going to read the page width"); |
207 | (*result)->page_width = psiconv_read_length(buf,lev+2,off+len,&leng,&res); |
226 | (*result)->page_width = psiconv_read_length(buf,lev+2,off+len,&leng,&res); |
… | |
… | |
214 | (*result)->page_height = psiconv_read_length(buf,lev+2,off+len,&leng,&res); |
233 | (*result)->page_height = psiconv_read_length(buf,lev+2,off+len,&leng,&res); |
215 | if (res) |
234 | if (res) |
216 | goto ERROR4; |
235 | goto ERROR4; |
217 | psiconv_debug(lev+2,off+len,"Page height: %6.3f",(*result)->page_height); |
236 | psiconv_debug(lev+2,off+len,"Page height: %6.3f",(*result)->page_height); |
218 | len += leng; |
237 | len += leng; |
|
|
238 | |
|
|
239 | psiconv_progress(lev+2,off+len,"Going to read page portrait/landscape"); |
|
|
240 | if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->landscape))) |
|
|
241 | goto ERROR4; |
|
|
242 | psiconv_debug(lev+2,off+len,"Landscape: %d",(*result)->landscape); |
|
|
243 | len += leng; |
|
|
244 | |
219 | |
245 | |
220 | if (length) |
246 | if (length) |
221 | *length = len; |
247 | *length = len; |
222 | |
248 | |
223 | psiconv_progress(lev,off+len-1,"End of page section (total length: %08x)", |
249 | psiconv_progress(lev,off+len-1,"End of page section (total length: %08x)", |