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