| … | |
… | |
| 28 | #ifdef DMALLOC |
28 | #ifdef DMALLOC |
| 29 | #include <dmalloc.h> |
29 | #include <dmalloc.h> |
| 30 | #endif |
30 | #endif |
| 31 | |
31 | |
| 32 | static int psiconv_write_layout_section(const psiconv_config config, |
32 | static int psiconv_write_layout_section(const psiconv_config config, |
| 33 | psiconv_buffer buf, |
33 | psiconv_buffer buf, int lev, |
| 34 | const psiconv_text_and_layout value, |
34 | const psiconv_text_and_layout value, |
| 35 | const psiconv_word_styles_section styles, |
35 | const psiconv_word_styles_section styles, |
| 36 | int with_styles); |
36 | int with_styles); |
| 37 | |
37 | |
| 38 | /* Maybe use a psiconv_header_section variable instead? */ |
38 | /* Maybe use a psiconv_header_section variable instead? */ |
| 39 | int psiconv_write_header_section(const psiconv_config config, |
39 | int psiconv_write_header_section(const psiconv_config config, |
| 40 | psiconv_buffer buf,psiconv_u32 uid1, |
40 | psiconv_buffer buf,int lev,psiconv_u32 uid1, |
| 41 | psiconv_u32 uid2, psiconv_u32 uid3) |
41 | psiconv_u32 uid2, psiconv_u32 uid3) |
| 42 | { |
42 | { |
| 43 | int res; |
43 | int res; |
|
|
44 | psiconv_progress(config,lev,0,"Writing header section"); |
| 44 | if ((res = psiconv_write_u32(config,buf,uid1))) |
45 | if ((res = psiconv_write_u32(config,buf,lev+1,uid1))) |
| 45 | return res; |
46 | return res; |
| 46 | if ((res = psiconv_write_u32(config,buf,uid2))) |
47 | if ((res = psiconv_write_u32(config,buf,lev+1,uid2))) |
| 47 | return res; |
48 | return res; |
| 48 | if ((res = psiconv_write_u32(config,buf,uid3))) |
49 | if ((res = psiconv_write_u32(config,buf,lev+1,uid3))) |
| 49 | return res; |
50 | return res; |
| 50 | return psiconv_write_u32(config,buf,psiconv_checkuid(uid1,uid2,uid3)); |
51 | return psiconv_write_u32(config,buf,lev+1,psiconv_checkuid(uid1,uid2,uid3)); |
| 51 | } |
52 | } |
| 52 | |
53 | |
| 53 | int psiconv_write_section_table_section(const psiconv_config config, |
54 | int psiconv_write_section_table_section(const psiconv_config config, |
| 54 | psiconv_buffer buf, |
55 | psiconv_buffer buf,int lev, |
| 55 | const psiconv_section_table_section value) |
56 | const psiconv_section_table_section value) |
| 56 | { |
57 | { |
| 57 | int res,i; |
58 | int res,i; |
| 58 | psiconv_section_table_entry entry; |
59 | psiconv_section_table_entry entry; |
| 59 | |
60 | |
|
|
61 | psiconv_progress(config,lev,0,"Writing section table section"); |
| 60 | if (!value) { |
62 | if (!value) { |
| 61 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null section table section"); |
63 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null section table section"); |
| 62 | return -PSICONV_E_GENERATE; |
64 | return -PSICONV_E_GENERATE; |
| 63 | } |
65 | } |
| 64 | |
66 | |
| 65 | if ((res = psiconv_write_u8(config,buf,2 * psiconv_list_length(value)))) |
67 | if ((res = psiconv_write_u8(config,buf,lev+1,2 * psiconv_list_length(value)))) |
| 66 | return res; |
68 | return res; |
| 67 | for (i = 0; i < psiconv_list_length(value); i++) { |
69 | for (i = 0; i < psiconv_list_length(value); i++) { |
| 68 | if (!(entry = psiconv_list_get(value,i))) { |
70 | if (!(entry = psiconv_list_get(value,i))) { |
| 69 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
71 | psiconv_error(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
| 70 | return -PSICONV_E_NOMEM; |
72 | return -PSICONV_E_NOMEM; |
| 71 | } |
73 | } |
| 72 | if ((res = psiconv_write_u32(config,buf,entry->id))) |
74 | if ((res = psiconv_write_u32(config,buf,lev+1,entry->id))) |
| 73 | return res; |
75 | return res; |
| 74 | if ((res = psiconv_write_offset(config,buf,entry->offset))) |
76 | if ((res = psiconv_write_offset(config,buf,lev+1,entry->offset))) |
| 75 | return res; |
77 | return res; |
| 76 | } |
78 | } |
| 77 | return -PSICONV_E_OK; |
79 | return -PSICONV_E_OK; |
| 78 | } |
80 | } |
| 79 | |
81 | |
| 80 | int psiconv_write_application_id_section(const psiconv_config config, |
82 | int psiconv_write_application_id_section(const psiconv_config config, |
| 81 | psiconv_buffer buf,psiconv_u32 id, |
83 | psiconv_buffer buf,int lev,psiconv_u32 id, |
| 82 | const psiconv_string_t text) |
84 | const psiconv_string_t text) |
| 83 | { |
85 | { |
| 84 | int res; |
86 | int res; |
|
|
87 | psiconv_progress(config,lev,0,"Writing application id section"); |
| 85 | if ((res = psiconv_write_u32(config,buf,id))) |
88 | if ((res = psiconv_write_u32(config,buf,lev+1,id))) |
| 86 | return res; |
89 | return res; |
| 87 | return psiconv_write_string(config,buf,text); |
90 | return psiconv_write_string(config,buf,lev+1,text); |
| 88 | } |
91 | } |
| 89 | |
92 | |
| 90 | int psiconv_write_text_section(const psiconv_config config, |
93 | int psiconv_write_text_section(const psiconv_config config, |
| 91 | psiconv_buffer buf, |
94 | psiconv_buffer buf,int lev, |
| 92 | const psiconv_text_and_layout value) |
95 | const psiconv_text_and_layout value) |
| 93 | { |
96 | { |
| 94 | int res; |
97 | int res; |
| 95 | psiconv_buffer extra_buf; |
98 | psiconv_buffer extra_buf; |
| 96 | int i,j; |
99 | int i,j; |
| 97 | psiconv_paragraph paragraph; |
100 | psiconv_paragraph paragraph; |
| 98 | |
101 | |
|
|
102 | psiconv_progress(config,lev,0,"Writing text section"); |
| 99 | if (!value) { |
103 | if (!value) { |
| 100 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null text section"); |
104 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null text section"); |
| 101 | return -PSICONV_E_GENERATE; |
105 | return -PSICONV_E_GENERATE; |
| 102 | } |
106 | } |
| 103 | |
107 | |
| 104 | if (psiconv_list_length(value)) { |
108 | if (psiconv_list_length(value)) { |
| 105 | if (!(extra_buf = psiconv_buffer_new())) |
109 | if (!(extra_buf = psiconv_buffer_new())) |
| 106 | return -PSICONV_E_NOMEM; |
110 | return -PSICONV_E_NOMEM; |
| 107 | for (i = 0; i < psiconv_list_length(value); i++) { |
111 | for (i = 0; i < psiconv_list_length(value); i++) { |
| 108 | if (!(paragraph = psiconv_list_get(value,i))) { |
112 | if (!(paragraph = psiconv_list_get(value,i))) { |
| 109 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
113 | psiconv_error(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
| 110 | res = -PSICONV_E_OTHER; |
114 | res = -PSICONV_E_NOMEM; |
| 111 | goto ERROR; |
115 | goto ERROR; |
| 112 | } |
116 | } |
| 113 | for (j = 0; j < strlen(paragraph->text); j++) |
117 | for (j = 0; j < psiconv_unicode_strlen(paragraph->text); j++) |
| 114 | if ((res = psiconv_write_u8(config,extra_buf,paragraph->text[j]))) |
118 | if ((res = psiconv_write_u8(config,extra_buf,lev+1, |
|
|
119 | psiconv_unicode_to_char(config,paragraph->text[j])))) |
| 115 | goto ERROR; |
120 | goto ERROR; |
| 116 | psiconv_write_u8(config,extra_buf,0x06); |
121 | psiconv_write_u8(config,extra_buf,lev+1,0x06); |
| 117 | } |
122 | } |
| 118 | if ((res = psiconv_write_X(config,buf,psiconv_buffer_length(extra_buf)))) |
123 | if ((res = psiconv_write_X(config,buf,lev+1,psiconv_buffer_length(extra_buf)))) |
| 119 | goto ERROR; |
124 | goto ERROR; |
| 120 | res = psiconv_buffer_concat(buf,extra_buf); |
125 | res = psiconv_buffer_concat(buf,extra_buf); |
| 121 | } else |
126 | } else |
| 122 | /* Hack: empty text sections are just not allowed */ |
127 | /* Hack: empty text sections are just not allowed */ |
| 123 | return psiconv_write_u16(config,buf,0x0602); |
128 | return psiconv_write_u16(config,buf,lev+1,0x0602); |
| 124 | |
129 | |
| 125 | ERROR: |
130 | ERROR: |
| 126 | psiconv_buffer_free(extra_buf); |
131 | psiconv_buffer_free(extra_buf); |
| 127 | return res; |
132 | return res; |
| 128 | } |
133 | } |
| 129 | |
134 | |
| 130 | int psiconv_write_layout_section(const psiconv_config config, |
135 | int psiconv_write_layout_section(const psiconv_config config, |
| 131 | psiconv_buffer buf, |
136 | psiconv_buffer buf,int lev, |
| 132 | const psiconv_text_and_layout value, |
137 | const psiconv_text_and_layout value, |
| 133 | const psiconv_word_styles_section styles, |
138 | const psiconv_word_styles_section styles, |
| 134 | int with_styles) |
139 | int with_styles) |
| 135 | { |
140 | { |
| 136 | typedef struct psiconv_paragraph_type_list_s |
141 | typedef struct psiconv_paragraph_type_list_s |
| … | |
… | |
| 149 | psiconv_in_line_layout in_line = NULL; |
154 | psiconv_in_line_layout in_line = NULL; |
| 150 | psiconv_word_style style; |
155 | psiconv_word_style style; |
| 151 | psiconv_character_layout para_charlayout; |
156 | psiconv_character_layout para_charlayout; |
| 152 | int i,j,para_type,nr_of_inlines=0,res,ptl_length,pel_length,thislen,paralen; |
157 | int i,j,para_type,nr_of_inlines=0,res,ptl_length,pel_length,thislen,paralen; |
| 153 | |
158 | |
|
|
159 | psiconv_progress(config,lev,0,"Writing layout section"); |
| 154 | if (!value) { |
160 | if (!value) { |
| 155 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null text section"); |
161 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null text section"); |
| 156 | return -PSICONV_E_GENERATE; |
162 | return -PSICONV_E_GENERATE; |
| 157 | } |
163 | } |
| 158 | |
164 | |
| 159 | if (!(paragraph_type_list = psiconv_list_new(sizeof(new_type)))) { |
165 | if (!(paragraph_type_list = psiconv_list_new(sizeof(new_type)))) { |
| 160 | res = -PSICONV_E_NOMEM; |
166 | res = -PSICONV_E_NOMEM; |
| … | |
… | |
| 181 | goto ERROR5; |
187 | goto ERROR5; |
| 182 | } |
188 | } |
| 183 | |
189 | |
| 184 | for (i = 0; i < psiconv_list_length(value); i++) { |
190 | for (i = 0; i < psiconv_list_length(value); i++) { |
| 185 | if (!(paragraph = psiconv_list_get(value,i))) { |
191 | if (!(paragraph = psiconv_list_get(value,i))) { |
| 186 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
192 | psiconv_error(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
| 187 | res = -PSICONV_E_OTHER; |
193 | res = -PSICONV_E_NOMEM; |
| 188 | goto ERROR6; |
194 | goto ERROR6; |
| 189 | } |
195 | } |
| 190 | if ((res = psiconv_write_u32(config,buf_elements,strlen(paragraph->text)+1))) |
196 | if ((res = psiconv_write_u32(config,buf_elements,lev+1, |
|
|
197 | psiconv_unicode_strlen(paragraph->text)+1))) |
| 191 | goto ERROR6; |
198 | goto ERROR6; |
| 192 | |
199 | |
| 193 | /* We need it for the next if-statement */ |
200 | /* We need it for the next if-statement */ |
| 194 | if (psiconv_list_length(paragraph->in_lines) == 1) |
201 | if (psiconv_list_length(paragraph->in_lines) == 1) |
| 195 | if (!(in_line = psiconv_list_get(paragraph->in_lines,1))) |
202 | if (!(in_line = psiconv_list_get(paragraph->in_lines,1))) |
| … | |
… | |
| 198 | if ((psiconv_list_length(paragraph->in_lines) > 1) || |
205 | if ((psiconv_list_length(paragraph->in_lines) > 1) || |
| 199 | ((psiconv_list_length(paragraph->in_lines) == 1) && |
206 | ((psiconv_list_length(paragraph->in_lines) == 1) && |
| 200 | (in_line->object != NULL))) { |
207 | (in_line->object != NULL))) { |
| 201 | /* Inline layouts, or an object, so we generate a paragraph element |
208 | /* Inline layouts, or an object, so we generate a paragraph element |
| 202 | and inline elements */ |
209 | and inline elements */ |
| 203 | if ((res = psiconv_write_u8(config,buf_elements,0x00))) |
210 | if ((res = psiconv_write_u8(config,buf_elements,lev+1,0x00))) |
| 204 | goto ERROR6; |
211 | goto ERROR6; |
| 205 | if (!(style = psiconv_get_style(styles,paragraph->base_style))) { |
212 | if (!(style = psiconv_get_style(styles,paragraph->base_style))) { |
| 206 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Unknown style"); |
213 | psiconv_error(config,0,psiconv_buffer_length(buf),"Unknown style"); |
| 207 | res = -PSICONV_E_GENERATE; |
214 | res = -PSICONV_E_GENERATE; |
| 208 | goto ERROR6; |
215 | goto ERROR6; |
| 209 | } |
216 | } |
| 210 | if ((res = psiconv_write_paragraph_layout_list(config,buf_elements, |
217 | if ((res = psiconv_write_paragraph_layout_list(config,buf_elements,lev+1, |
| 211 | paragraph->base_paragraph, |
218 | paragraph->base_paragraph, |
| 212 | style->paragraph))) |
219 | style->paragraph))) |
| 213 | goto ERROR6; |
220 | goto ERROR6; |
| 214 | if (with_styles) |
221 | if (with_styles) |
| 215 | if ((res = psiconv_write_u8(config,buf_elements,paragraph->base_style))) |
222 | if ((res = psiconv_write_u8(config,buf_elements,lev+1,paragraph->base_style))) |
| 216 | goto ERROR6; |
223 | goto ERROR6; |
| 217 | if ((res = psiconv_write_u32(config,buf_elements, |
224 | if ((res = psiconv_write_u32(config,buf_elements,lev+1, |
| 218 | psiconv_list_length(paragraph->in_lines)))) |
225 | psiconv_list_length(paragraph->in_lines)))) |
| 219 | goto ERROR6; |
226 | goto ERROR6; |
| 220 | |
227 | |
| 221 | /* Generate the inlines. NB: Against what are all settings relative?!? */ |
228 | /* Generate the inlines. NB: Against what are all settings relative?!? */ |
| 222 | paralen = 0; |
229 | paralen = 0; |
| 223 | for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) { |
230 | for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) { |
| 224 | nr_of_inlines ++; |
231 | nr_of_inlines ++; |
| 225 | if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) { |
232 | if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) { |
| 226 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
233 | psiconv_error(config,0,psiconv_buffer_length(buf), |
| 227 | "Massive memory corruption"); |
234 | "Massive memory corruption"); |
| 228 | res = -PSICONV_E_OTHER; |
235 | res = -PSICONV_E_NOMEM; |
| 229 | goto ERROR6; |
236 | goto ERROR6; |
| 230 | } |
237 | } |
| 231 | if ((res = psiconv_write_u8(config,buf_inlines,in_line->object?0x01:0x00))) |
238 | if ((res = psiconv_write_u8(config,buf_inlines,lev+1,in_line->object?0x01:0x00))) |
| 232 | goto ERROR6; |
239 | goto ERROR6; |
| 233 | thislen = in_line->length; |
240 | thislen = in_line->length; |
| 234 | paralen += thislen; |
241 | paralen += thislen; |
| 235 | /* If this is the last in_line, we need to make sure that the |
242 | /* If this is the last in_line, we need to make sure that the |
| 236 | complete length of all inlines equals the text length */ |
243 | complete length of all inlines equals the text length */ |
| 237 | if (j == psiconv_list_length(paragraph->in_lines)-1) { |
244 | if (j == psiconv_list_length(paragraph->in_lines)-1) { |
| 238 | if (paralen > strlen(paragraph->text)+1) { |
245 | if (paralen > psiconv_unicode_strlen(paragraph->text)+1) { |
| 239 | res = -PSICONV_E_GENERATE; |
246 | res = -PSICONV_E_GENERATE; |
| 240 | goto ERROR6; |
247 | goto ERROR6; |
| 241 | } |
248 | } |
| 242 | thislen += strlen(paragraph->text)+1-paralen; |
249 | thislen += psiconv_unicode_strlen(paragraph->text)+1-paralen; |
| 243 | } |
250 | } |
| 244 | if ((res = psiconv_write_u32(config,buf_inlines,thislen))) |
251 | if ((res = psiconv_write_u32(config,buf_inlines,lev+1,thislen))) |
| 245 | goto ERROR6; |
252 | goto ERROR6; |
| 246 | if ((res = psiconv_write_character_layout_list(config,buf_inlines, |
253 | if ((res = psiconv_write_character_layout_list(config,buf_inlines,lev+1, |
| 247 | in_line->layout, |
254 | in_line->layout, |
| 248 | style->character))) |
255 | style->character))) |
| 249 | goto ERROR6; |
256 | goto ERROR6; |
| 250 | if (in_line->object) { |
257 | if (in_line->object) { |
| 251 | if ((res = psiconv_write_u32(config,buf_inlines,PSICONV_ID_OBJECT))) |
258 | if ((res = psiconv_write_u32(config,buf_inlines,lev+1,PSICONV_ID_OBJECT))) |
| 252 | goto ERROR6; |
259 | goto ERROR6; |
| 253 | obj_id = psiconv_buffer_unique_id(); |
260 | obj_id = psiconv_buffer_unique_id(); |
| 254 | if ((res = psiconv_buffer_add_reference(buf_inlines,obj_id))) |
261 | if ((res = psiconv_buffer_add_reference(buf_inlines,obj_id))) |
| 255 | goto ERROR6; |
262 | goto ERROR6; |
| 256 | if ((res = psiconv_buffer_add_target(buf_objects,obj_id))) |
263 | if ((res = psiconv_buffer_add_target(buf_objects,obj_id))) |
| 257 | goto ERROR6; |
264 | goto ERROR6; |
| 258 | if ((res = psiconv_write_embedded_object_section(config,buf_objects, |
265 | if ((res = psiconv_write_embedded_object_section(config,buf_objects,lev+1, |
| 259 | in_line->object))) |
266 | in_line->object))) |
| 260 | goto ERROR6; |
267 | goto ERROR6; |
| 261 | if ((res = psiconv_write_length(config,buf_inlines,in_line->object_width))) |
268 | if ((res = psiconv_write_length(config,buf_inlines,lev+1,in_line->object_width))) |
| 262 | goto ERROR6; |
269 | goto ERROR6; |
| 263 | if ((res = psiconv_write_length(config,buf_inlines,in_line->object_height))) |
270 | if ((res = psiconv_write_length(config,buf_inlines,lev+1,in_line->object_height))) |
| 264 | goto ERROR6; |
271 | goto ERROR6; |
| 265 | } |
272 | } |
| 266 | } |
273 | } |
| 267 | } else { |
274 | } else { |
| 268 | /* No inline layouts (or only 1), so we generate a paragraph type list */ |
275 | /* No inline layouts (or only 1), so we generate a paragraph type list */ |
| … | |
… | |
| 270 | /* Set para_charlayout to the correct character-level layout */ |
277 | /* Set para_charlayout to the correct character-level layout */ |
| 271 | if (psiconv_list_length(paragraph->in_lines) == 0) |
278 | if (psiconv_list_length(paragraph->in_lines) == 0) |
| 272 | para_charlayout = paragraph->base_character; |
279 | para_charlayout = paragraph->base_character; |
| 273 | else { |
280 | else { |
| 274 | if (!(in_line = psiconv_list_get(paragraph->in_lines,0))) { |
281 | if (!(in_line = psiconv_list_get(paragraph->in_lines,0))) { |
| 275 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
282 | psiconv_error(config,0,psiconv_buffer_length(buf), |
| 276 | "Massive memory corruption"); |
283 | "Massive memory corruption"); |
| 277 | res = -PSICONV_E_OTHER; |
284 | res = -PSICONV_E_NOMEM; |
| 278 | goto ERROR6; |
285 | goto ERROR6; |
| 279 | } |
286 | } |
| 280 | para_charlayout = in_line->layout; |
287 | para_charlayout = in_line->layout; |
| 281 | } |
288 | } |
| 282 | for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) { |
289 | for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) { |
| 283 | if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) { |
290 | if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) { |
| 284 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
291 | psiconv_error(config,0,psiconv_buffer_length(buf), |
| 285 | "Massive memory corruption"); |
292 | "Massive memory corruption"); |
| 286 | res = -PSICONV_E_OTHER; |
293 | res = -PSICONV_E_NOMEM; |
| 287 | goto ERROR6; |
294 | goto ERROR6; |
| 288 | } |
295 | } |
| 289 | if ((paragraph->base_style == paragraph_type->style) && |
296 | if ((paragraph->base_style == paragraph_type->style) && |
| 290 | !psiconv_compare_character_layout(para_charlayout, |
297 | !psiconv_compare_character_layout(para_charlayout, |
| 291 | paragraph_type->character) && |
298 | paragraph_type->character) && |
| … | |
… | |
| 303 | new_type.character = para_charlayout; |
310 | new_type.character = para_charlayout; |
| 304 | new_type.style = paragraph->base_style; |
311 | new_type.style = paragraph->base_style; |
| 305 | paragraph_type = &new_type; |
312 | paragraph_type = &new_type; |
| 306 | if ((res = psiconv_list_add(paragraph_type_list,paragraph_type))) |
313 | if ((res = psiconv_list_add(paragraph_type_list,paragraph_type))) |
| 307 | goto ERROR6; |
314 | goto ERROR6; |
| 308 | if ((res = psiconv_write_u32(config,buf_types,paragraph_type->nr))) |
315 | if ((res = psiconv_write_u32(config,buf_types,lev+1,paragraph_type->nr))) |
| 309 | goto ERROR6; |
316 | goto ERROR6; |
| 310 | if (!(style = psiconv_get_style(styles,paragraph_type->style))) { |
317 | if (!(style = psiconv_get_style(styles,paragraph_type->style))) { |
| 311 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Unknown style"); |
318 | psiconv_error(config,0,psiconv_buffer_length(buf),"Unknown style"); |
| 312 | res = -PSICONV_E_GENERATE; |
319 | res = -PSICONV_E_GENERATE; |
| 313 | goto ERROR6; |
320 | goto ERROR6; |
| 314 | } |
321 | } |
| 315 | if ((res = psiconv_write_paragraph_layout_list(config,buf_types, |
322 | if ((res = psiconv_write_paragraph_layout_list(config,buf_types,lev+1, |
| 316 | paragraph_type->paragraph,style->paragraph))) |
323 | paragraph_type->paragraph,style->paragraph))) |
| 317 | goto ERROR6; |
324 | goto ERROR6; |
| 318 | if (with_styles) |
325 | if (with_styles) |
| 319 | if ((res = psiconv_write_u8(config,buf_types,paragraph_type->style))) |
326 | if ((res = psiconv_write_u8(config,buf_types,lev+1,paragraph_type->style))) |
| 320 | goto ERROR6; |
327 | goto ERROR6; |
| 321 | if ((res = psiconv_write_character_layout_list(config,buf_types, |
328 | if ((res = psiconv_write_character_layout_list(config,buf_types,lev+1, |
| 322 | paragraph_type->character,style->character))) |
329 | paragraph_type->character,style->character))) |
| 323 | goto ERROR6; |
330 | goto ERROR6; |
| 324 | } |
331 | } |
| 325 | if ((res = psiconv_write_u8(config,buf_elements,para_type))) |
332 | if ((res = psiconv_write_u8(config,buf_elements,lev+1,para_type))) |
| 326 | goto ERROR6; |
333 | goto ERROR6; |
| 327 | } |
334 | } |
| 328 | } |
335 | } |
| 329 | |
336 | |
| 330 | /* HACK: special case: no paragraphs at all. We need to improvize. */ |
337 | /* HACK: special case: no paragraphs at all. We need to improvize. */ |
| 331 | if (!psiconv_list_length(value)) { |
338 | if (!psiconv_list_length(value)) { |
| 332 | if ((res = psiconv_write_u32(config,buf_types,1))) |
339 | if ((res = psiconv_write_u32(config,buf_types,lev+1,1))) |
| 333 | goto ERROR6; |
340 | goto ERROR6; |
| 334 | if ((res = psiconv_write_u32(config,buf_types,0))) |
341 | if ((res = psiconv_write_u32(config,buf_types,lev+1,0))) |
| 335 | goto ERROR6; |
342 | goto ERROR6; |
| 336 | if (with_styles) |
343 | if (with_styles) |
| 337 | if ((res = psiconv_write_u8(config,buf_types,0))) |
344 | if ((res = psiconv_write_u8(config,buf_types,lev+1,0))) |
| 338 | goto ERROR6; |
345 | goto ERROR6; |
| 339 | if ((res = psiconv_write_u32(config,buf_types,0))) |
346 | if ((res = psiconv_write_u32(config,buf_types,lev+1,0))) |
| 340 | goto ERROR6; |
347 | goto ERROR6; |
| 341 | |
348 | |
| 342 | if ((res = psiconv_write_u32(config,buf_elements,1))) |
349 | if ((res = psiconv_write_u32(config,buf_elements,lev+1,1))) |
| 343 | goto ERROR6; |
350 | goto ERROR6; |
| 344 | if ((res = psiconv_write_u8(config,buf_elements,1))) |
351 | if ((res = psiconv_write_u8(config,buf_elements,lev+1,1))) |
| 345 | goto ERROR6; |
352 | goto ERROR6; |
| 346 | pel_length = 1; |
353 | pel_length = 1; |
| 347 | ptl_length = 1; |
354 | ptl_length = 1; |
| 348 | } else { |
355 | } else { |
| 349 | pel_length = psiconv_list_length(value); |
356 | pel_length = psiconv_list_length(value); |
| 350 | ptl_length = psiconv_list_length(paragraph_type_list); |
357 | ptl_length = psiconv_list_length(paragraph_type_list); |
| 351 | } |
358 | } |
| 352 | |
359 | |
| 353 | /* Now append everything */ |
360 | /* Now append everything */ |
| 354 | if ((res = psiconv_write_u16(config,buf,with_styles?0x0001:0x0000))) |
361 | if ((res = psiconv_write_u16(config,buf,lev+1,with_styles?0x0001:0x0000))) |
| 355 | goto ERROR6; |
362 | goto ERROR6; |
| 356 | if ((res = psiconv_write_u8(config,buf, ptl_length))) |
363 | if ((res = psiconv_write_u8(config,buf,lev+1, ptl_length))) |
| 357 | goto ERROR6; |
364 | goto ERROR6; |
| 358 | if ((res = psiconv_buffer_concat(buf,buf_types))) |
365 | if ((res = psiconv_buffer_concat(buf,buf_types))) |
| 359 | goto ERROR6; |
366 | goto ERROR6; |
| 360 | if ((res = psiconv_write_u32(config,buf,pel_length))) |
367 | if ((res = psiconv_write_u32(config,buf,lev+1,pel_length))) |
| 361 | goto ERROR6; |
368 | goto ERROR6; |
| 362 | if ((res = psiconv_buffer_concat(buf,buf_elements))) |
369 | if ((res = psiconv_buffer_concat(buf,buf_elements))) |
| 363 | goto ERROR6; |
370 | goto ERROR6; |
| 364 | if ((res = psiconv_write_u32(config,buf,nr_of_inlines))) |
371 | if ((res = psiconv_write_u32(config,buf,lev+1,nr_of_inlines))) |
| 365 | goto ERROR6; |
372 | goto ERROR6; |
| 366 | if ((res = psiconv_buffer_concat(buf,buf_inlines))) |
373 | if ((res = psiconv_buffer_concat(buf,buf_inlines))) |
| 367 | goto ERROR6; |
374 | goto ERROR6; |
| 368 | if ((res = psiconv_buffer_concat(buf,buf_objects))) |
375 | if ((res = psiconv_buffer_concat(buf,buf_objects))) |
| 369 | goto ERROR6; |
376 | goto ERROR6; |
| … | |
… | |
| 381 | ERROR1: |
388 | ERROR1: |
| 382 | return res; |
389 | return res; |
| 383 | } |
390 | } |
| 384 | |
391 | |
| 385 | int psiconv_write_styled_layout_section(const psiconv_config config, |
392 | int psiconv_write_styled_layout_section(const psiconv_config config, |
| 386 | psiconv_buffer buf, |
393 | psiconv_buffer buf,int lev, |
| 387 | psiconv_text_and_layout result, |
394 | psiconv_text_and_layout result, |
| 388 | psiconv_word_styles_section styles) |
395 | psiconv_word_styles_section styles) |
| 389 | { |
396 | { |
|
|
397 | psiconv_progress(config,lev,0,"Writing styled layout section"); |
| 390 | return psiconv_write_layout_section(config,buf,result,styles,1); |
398 | return psiconv_write_layout_section(config,buf,lev+1,result,styles,1); |
| 391 | } |
399 | } |
| 392 | |
400 | |
| 393 | int psiconv_write_styleless_layout_section(const psiconv_config config, |
401 | int psiconv_write_styleless_layout_section(const psiconv_config config, |
| 394 | psiconv_buffer buf, |
402 | psiconv_buffer buf,int lev, |
| 395 | const psiconv_text_and_layout value, |
403 | const psiconv_text_and_layout value, |
| 396 | const psiconv_character_layout base_char, |
404 | const psiconv_character_layout base_char, |
| 397 | const psiconv_paragraph_layout base_para) |
405 | const psiconv_paragraph_layout base_para) |
| 398 | { |
406 | { |
| 399 | int res = 0; |
407 | int res = 0; |
| 400 | psiconv_word_styles_section styles_section; |
408 | psiconv_word_styles_section styles_section; |
| 401 | |
409 | |
|
|
410 | psiconv_progress(config,lev,0,"Writing styleless layout section"); |
| 402 | if (!(styles_section = malloc(sizeof(*styles_section)))) |
411 | if (!(styles_section = malloc(sizeof(*styles_section)))) |
| 403 | goto ERROR1; |
412 | goto ERROR1; |
| 404 | if (!(styles_section->normal = malloc(sizeof(*styles_section->normal)))) |
413 | if (!(styles_section->normal = malloc(sizeof(*styles_section->normal)))) |
| 405 | goto ERROR2; |
414 | goto ERROR2; |
| 406 | if (!(styles_section->normal->character = |
415 | if (!(styles_section->normal->character = |
| … | |
… | |
| 408 | goto ERROR3; |
417 | goto ERROR3; |
| 409 | if (!(styles_section->normal->paragraph = |
418 | if (!(styles_section->normal->paragraph = |
| 410 | psiconv_clone_paragraph_layout(base_para))) |
419 | psiconv_clone_paragraph_layout(base_para))) |
| 411 | goto ERROR4; |
420 | goto ERROR4; |
| 412 | styles_section->normal->hotkey = 0; |
421 | styles_section->normal->hotkey = 0; |
| 413 | if (!(styles_section->normal->name = strdup(""))) |
422 | if ((res = psiconv_unicode_from_chars(config,"", |
|
|
423 | &styles_section->normal->name))) |
| 414 | goto ERROR5; |
424 | goto ERROR5; |
| 415 | if (!(styles_section->styles = psiconv_list_new(sizeof( |
425 | if (!(styles_section->styles = psiconv_list_new(sizeof( |
| 416 | struct psiconv_word_style_s)))) |
426 | struct psiconv_word_style_s)))) |
| 417 | goto ERROR6; |
427 | goto ERROR6; |
| 418 | |
428 | |
| 419 | res = psiconv_write_layout_section(config,buf,value,styles_section,0); |
429 | res = psiconv_write_layout_section(config,buf,lev+1,value,styles_section,0); |
| 420 | psiconv_free_word_styles_section(styles_section); |
430 | psiconv_free_word_styles_section(styles_section); |
| 421 | return res; |
431 | return res; |
| 422 | |
432 | |
| 423 | ERROR6: |
433 | ERROR6: |
| 424 | free(styles_section->normal->name); |
434 | free(styles_section->normal->name); |
| … | |
… | |
| 437 | return res; |
447 | return res; |
| 438 | } |
448 | } |
| 439 | |
449 | |
| 440 | |
450 | |
| 441 | int psiconv_write_embedded_object_section(const psiconv_config config, |
451 | int psiconv_write_embedded_object_section(const psiconv_config config, |
| 442 | psiconv_buffer buf, |
452 | psiconv_buffer buf,int lev, |
| 443 | const psiconv_embedded_object_section value) |
453 | const psiconv_embedded_object_section value) |
| 444 | { |
454 | { |
| 445 | int res; |
455 | int res; |
| 446 | psiconv_u32 display_id,icon_id,table_id; |
456 | psiconv_u32 display_id,icon_id,table_id; |
| 447 | psiconv_buffer extra_buf; |
457 | psiconv_buffer extra_buf; |
| 448 | |
458 | |
|
|
459 | psiconv_progress(config,lev,0,"Writing embedded object section"); |
| 449 | if (!value) { |
460 | if (!value) { |
| 450 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null Object"); |
461 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null Object"); |
| 451 | res = -PSICONV_E_GENERATE; |
462 | res = -PSICONV_E_GENERATE; |
| 452 | goto ERROR1; |
463 | goto ERROR1; |
| 453 | } |
464 | } |
| 454 | |
465 | |
| 455 | if (!(extra_buf = psiconv_buffer_new())) { |
466 | if (!(extra_buf = psiconv_buffer_new())) { |
| … | |
… | |
| 458 | } |
469 | } |
| 459 | |
470 | |
| 460 | display_id = psiconv_buffer_unique_id(); |
471 | display_id = psiconv_buffer_unique_id(); |
| 461 | icon_id = psiconv_buffer_unique_id(); |
472 | icon_id = psiconv_buffer_unique_id(); |
| 462 | table_id = psiconv_buffer_unique_id(); |
473 | table_id = psiconv_buffer_unique_id(); |
| 463 | if ((res = psiconv_write_u8(config,buf,0x06))) |
474 | if ((res = psiconv_write_u8(config,buf,lev+1,0x06))) |
| 464 | goto ERROR2; |
475 | goto ERROR2; |
| 465 | if ((res = psiconv_write_u32(config,buf,PSICONV_ID_OBJECT_DISPLAY_SECTION))) |
476 | if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_OBJECT_DISPLAY_SECTION))) |
| 466 | goto ERROR2; |
477 | goto ERROR2; |
| 467 | if ((res = psiconv_buffer_add_reference(buf,display_id))) |
478 | if ((res = psiconv_buffer_add_reference(buf,display_id))) |
| 468 | goto ERROR2; |
479 | goto ERROR2; |
| 469 | if ((res = psiconv_write_u32(config,buf,PSICONV_ID_OBJECT_ICON_SECTION))) |
480 | if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_OBJECT_ICON_SECTION))) |
| 470 | goto ERROR2; |
481 | goto ERROR2; |
| 471 | if ((res = psiconv_buffer_add_reference(buf,icon_id))) |
482 | if ((res = psiconv_buffer_add_reference(buf,icon_id))) |
| 472 | goto ERROR2; |
483 | goto ERROR2; |
| 473 | if ((res = psiconv_write_u32(config,buf,PSICONV_ID_OBJECT_SECTION_TABLE_SECTION))) |
484 | if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_OBJECT_SECTION_TABLE_SECTION))) |
| 474 | goto ERROR2; |
485 | goto ERROR2; |
| 475 | if ((res = psiconv_buffer_add_reference(buf,table_id))) |
486 | if ((res = psiconv_buffer_add_reference(buf,table_id))) |
| 476 | goto ERROR2; |
487 | goto ERROR2; |
| 477 | |
488 | |
| 478 | if ((res = psiconv_buffer_add_target(buf,display_id))) |
489 | if ((res = psiconv_buffer_add_target(buf,display_id))) |
| 479 | goto ERROR2; |
490 | goto ERROR2; |
| 480 | if ((res = psiconv_write_object_display_section(config,buf,value->display))) |
491 | if ((res = psiconv_write_object_display_section(config,buf,lev+1,value->display))) |
| 481 | goto ERROR2; |
492 | goto ERROR2; |
| 482 | if ((res = psiconv_buffer_add_target(buf,icon_id))) |
493 | if ((res = psiconv_buffer_add_target(buf,icon_id))) |
| 483 | goto ERROR2; |
494 | goto ERROR2; |
| 484 | if ((res = psiconv_write_object_icon_section(config,buf,value->icon))) |
495 | if ((res = psiconv_write_object_icon_section(config,buf,lev+1,value->icon))) |
| 485 | goto ERROR2; |
496 | goto ERROR2; |
| 486 | if ((res = psiconv_buffer_add_target(buf,table_id))) |
497 | if ((res = psiconv_buffer_add_target(buf,table_id))) |
| 487 | goto ERROR2; |
498 | goto ERROR2; |
| 488 | switch(value->object->type) { |
499 | switch(value->object->type) { |
| 489 | case psiconv_word_file: |
500 | case psiconv_word_file: |
| 490 | if ((res = psiconv_write_word_file(config,extra_buf, |
501 | if ((res = psiconv_write_word_file(config,extra_buf,lev+1, |
| 491 | (psiconv_word_f) value->object->file))) |
502 | (psiconv_word_f) value->object->file))) |
| 492 | goto ERROR2; |
503 | goto ERROR2; |
| 493 | break; |
504 | break; |
| 494 | case psiconv_sketch_file: |
505 | case psiconv_sketch_file: |
| 495 | if ((res = psiconv_write_sketch_file(config,extra_buf, |
506 | if ((res = psiconv_write_sketch_file(config,extra_buf,lev+1, |
| 496 | (psiconv_sketch_f) value->object->file))) |
507 | (psiconv_sketch_f) value->object->file))) |
| 497 | goto ERROR2; |
508 | goto ERROR2; |
| 498 | break; |
509 | break; |
| 499 | /* |
510 | /* |
| 500 | case psiconv_sheet_file: |
511 | case psiconv_sheet_file: |
| 501 | if ((res = psiconv_write_sheet_file(config,extra_buf, |
512 | if ((res = psiconv_write_sheet_file(config,extra_buf,lev+1, |
| 502 | (psiconv_sheet_f) value->object->file))) |
513 | (psiconv_sheet_f) value->object->file))) |
| 503 | goto ERROR2; |
514 | goto ERROR2; |
| 504 | break; |
515 | break; |
| 505 | */ |
516 | */ |
| 506 | default: |
517 | default: |
| 507 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
518 | psiconv_error(config,0,psiconv_buffer_length(buf), |
| 508 | "Unknown or unsupported object type"); |
519 | "Unknown or unsupported object type"); |
| 509 | res = -PSICONV_E_GENERATE; |
520 | res = -PSICONV_E_GENERATE; |
| 510 | goto ERROR2; |
521 | goto ERROR2; |
| 511 | } |
522 | } |
| 512 | |
523 | |
| … | |
… | |
| 523 | return res; |
534 | return res; |
| 524 | } |
535 | } |
| 525 | |
536 | |
| 526 | |
537 | |
| 527 | int psiconv_write_object_display_section(const psiconv_config config, |
538 | int psiconv_write_object_display_section(const psiconv_config config, |
| 528 | psiconv_buffer buf, |
539 | psiconv_buffer buf,int lev, |
| 529 | const psiconv_object_display_section value) |
540 | const psiconv_object_display_section value) |
| 530 | { |
541 | { |
| 531 | int res; |
542 | int res; |
| 532 | |
543 | |
|
|
544 | psiconv_progress(config,lev,0,"Writing object display section"); |
|
|
545 | |
| 533 | if (!value) { |
546 | if (!value) { |
| 534 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null Object Display Section"); |
547 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null Object Display Section"); |
| 535 | res = -PSICONV_E_GENERATE; |
548 | res = -PSICONV_E_GENERATE; |
| 536 | goto ERROR1; |
549 | goto ERROR1; |
| 537 | } |
550 | } |
| 538 | |
551 | |
| 539 | if ((res = psiconv_write_u8(config,buf,value->show_icon?0x00:0x01))) |
552 | if ((res = psiconv_write_u8(config,buf,lev+1,value->show_icon?0x00:0x01))) |
| 540 | goto ERROR1; |
553 | goto ERROR1; |
| 541 | if ((res = psiconv_write_length(config,buf,value->width))) |
554 | if ((res = psiconv_write_length(config,buf,lev+1,value->width))) |
| 542 | goto ERROR1; |
555 | goto ERROR1; |
| 543 | if ((res = psiconv_write_length(config,buf,value->height))) |
556 | if ((res = psiconv_write_length(config,buf,lev+1,value->height))) |
| 544 | goto ERROR1; |
557 | goto ERROR1; |
| 545 | if ((res = psiconv_write_u32(config,buf,0x00000000))) |
558 | if ((res = psiconv_write_u32(config,buf,lev+1,0x00000000))) |
| 546 | goto ERROR1; |
559 | goto ERROR1; |
| 547 | |
560 | |
| 548 | return 0; |
561 | return 0; |
| 549 | |
562 | |
| 550 | ERROR1: |
563 | ERROR1: |
| 551 | return res; |
564 | return res; |
| 552 | } |
565 | } |
| 553 | |
566 | |
| 554 | int psiconv_write_object_icon_section(const psiconv_config config, |
567 | int psiconv_write_object_icon_section(const psiconv_config config, |
| 555 | psiconv_buffer buf, |
568 | psiconv_buffer buf,int lev, |
| 556 | const psiconv_object_icon_section value) |
569 | const psiconv_object_icon_section value) |
| 557 | { |
570 | { |
| 558 | int res; |
571 | int res; |
| 559 | |
572 | |
|
|
573 | psiconv_progress(config,lev,0,"Writing object icon section"); |
|
|
574 | |
| 560 | if (!value) { |
575 | if (!value) { |
| 561 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null Object Icon Section"); |
576 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null Object Icon Section"); |
| 562 | res = -PSICONV_E_GENERATE; |
577 | res = -PSICONV_E_GENERATE; |
| 563 | goto ERROR1; |
578 | goto ERROR1; |
| 564 | } |
579 | } |
| 565 | |
580 | |
| 566 | if ((res = psiconv_write_string(config,buf,value->icon_name))) |
581 | if ((res = psiconv_write_string(config,buf,lev+1,value->icon_name))) |
| 567 | goto ERROR1; |
582 | goto ERROR1; |
| 568 | if ((res = psiconv_write_length(config,buf,value->icon_width))) |
583 | if ((res = psiconv_write_length(config,buf,lev+1,value->icon_width))) |
| 569 | goto ERROR1; |
584 | goto ERROR1; |
| 570 | if ((res = psiconv_write_length(config,buf,value->icon_height))) |
585 | if ((res = psiconv_write_length(config,buf,lev+1,value->icon_height))) |
| 571 | goto ERROR1; |
586 | goto ERROR1; |
| 572 | |
587 | |
| 573 | return 0; |
588 | return 0; |
| 574 | |
589 | |
| 575 | ERROR1: |
590 | ERROR1: |