1 |
frodo |
73 |
/* |
2 |
|
|
generate_page.c - Part of psiconv, a PSION 5 file formats converter |
3 |
frodo |
196 |
Copyright (c) 2000-2004 Frodo Looijaard <frodol@dds.nl> |
4 |
frodo |
73 |
|
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 |
|
|
|
23 |
|
|
#include <stdlib.h> |
24 |
|
|
#include <string.h> |
25 |
|
|
|
26 |
|
|
#include "generate_routines.h" |
27 |
|
|
#include "error.h" |
28 |
|
|
|
29 |
frodo |
142 |
#ifdef DMALLOC |
30 |
|
|
#include <dmalloc.h> |
31 |
|
|
#endif |
32 |
frodo |
73 |
|
33 |
frodo |
142 |
|
34 |
|
|
|
35 |
frodo |
168 |
int psiconv_write_page_header(const psiconv_config config, |
36 |
frodo |
184 |
psiconv_buffer buf, int lev, |
37 |
frodo |
80 |
const psiconv_page_header value, |
38 |
|
|
psiconv_buffer *extra_buf) |
39 |
frodo |
73 |
{ |
40 |
|
|
int res; |
41 |
|
|
psiconv_paragraph_layout basepara; |
42 |
|
|
psiconv_character_layout basechar; |
43 |
|
|
|
44 |
frodo |
184 |
psiconv_progress(config,lev,0,"Writing page header"); |
45 |
|
|
|
46 |
frodo |
73 |
if (!value) { |
47 |
frodo |
231 |
psiconv_error(config,lev,0,"Null page header"); |
48 |
frodo |
73 |
res = -PSICONV_E_GENERATE; |
49 |
|
|
goto ERROR1; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
if (!(basepara=psiconv_basic_paragraph_layout())) { |
53 |
|
|
res = -PSICONV_E_NOMEM; |
54 |
|
|
goto ERROR1; |
55 |
|
|
} |
56 |
|
|
if (!(basechar=psiconv_basic_character_layout())) { |
57 |
|
|
res = -PSICONV_E_NOMEM; |
58 |
|
|
goto ERROR2; |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
/* Unknown byte */ |
62 |
frodo |
184 |
if ((res = psiconv_write_u8(config,buf,lev+1,0x01))) |
63 |
frodo |
73 |
goto ERROR3; |
64 |
frodo |
184 |
if ((res = psiconv_write_bool(config,buf,lev+1,value->on_first_page))) |
65 |
frodo |
73 |
goto ERROR3; |
66 |
frodo |
76 |
/* Three unknown bytes */ |
67 |
frodo |
184 |
if ((res = psiconv_write_u8(config,buf,lev+1,0x00))) |
68 |
frodo |
76 |
goto ERROR3; |
69 |
frodo |
184 |
if ((res = psiconv_write_u8(config,buf,lev+1,0x00))) |
70 |
frodo |
76 |
goto ERROR3; |
71 |
frodo |
184 |
if ((res = psiconv_write_u8(config,buf,lev+1,0x00))) |
72 |
frodo |
76 |
goto ERROR3; |
73 |
frodo |
184 |
if ((res = psiconv_write_paragraph_layout_list(config,buf,lev+1, |
74 |
frodo |
73 |
value->base_paragraph_layout,basepara))) |
75 |
|
|
goto ERROR3; |
76 |
frodo |
184 |
if ((res = psiconv_write_character_layout_list(config,buf,lev+1, |
77 |
frodo |
73 |
value->base_character_layout,basechar))) |
78 |
|
|
goto ERROR3; |
79 |
frodo |
184 |
res = psiconv_write_texted_section(config,buf,lev+1,value->text, |
80 |
frodo |
73 |
value->base_character_layout, |
81 |
frodo |
80 |
value->base_paragraph_layout,extra_buf); |
82 |
frodo |
73 |
ERROR3: |
83 |
|
|
psiconv_free_character_layout(basechar); |
84 |
|
|
ERROR2: |
85 |
|
|
psiconv_free_paragraph_layout(basepara); |
86 |
|
|
ERROR1: |
87 |
frodo |
231 |
if (res) |
88 |
|
|
psiconv_error(config,lev,0,"Writing of page header failed"); |
89 |
|
|
else |
90 |
|
|
psiconv_progress(config,lev,0,"End of page header"); |
91 |
frodo |
73 |
return res; |
92 |
|
|
} |
93 |
|
|
|
94 |
frodo |
168 |
int psiconv_write_page_layout_section(const psiconv_config config, |
95 |
frodo |
184 |
psiconv_buffer buf, int lev, |
96 |
frodo |
73 |
const psiconv_page_layout_section value) |
97 |
|
|
{ |
98 |
|
|
int res; |
99 |
frodo |
80 |
psiconv_buffer header_buf,footer_buf; |
100 |
frodo |
73 |
|
101 |
frodo |
184 |
psiconv_progress(config,lev,0,"Writing page layout section"); |
102 |
|
|
|
103 |
frodo |
73 |
if (!value) { |
104 |
frodo |
231 |
psiconv_error(config,lev,0,"Null page section"); |
105 |
frodo |
80 |
res = -PSICONV_E_GENERATE; |
106 |
|
|
goto ERROR1; |
107 |
frodo |
73 |
} |
108 |
|
|
|
109 |
frodo |
184 |
if ((res = psiconv_write_u32(config,buf,lev+1,value->first_page_nr))) |
110 |
frodo |
80 |
goto ERROR1; |
111 |
frodo |
184 |
if ((res = psiconv_write_length(config,buf,lev+1,value->header_dist))) |
112 |
frodo |
80 |
goto ERROR1; |
113 |
frodo |
184 |
if ((res = psiconv_write_length(config,buf,lev+1,value->footer_dist))) |
114 |
frodo |
80 |
goto ERROR1; |
115 |
frodo |
184 |
if ((res = psiconv_write_length(config,buf,lev+1,value->left_margin))) |
116 |
frodo |
80 |
goto ERROR1; |
117 |
frodo |
184 |
if ((res = psiconv_write_length(config,buf,lev+1,value->right_margin))) |
118 |
frodo |
80 |
goto ERROR1; |
119 |
frodo |
184 |
if ((res = psiconv_write_length(config,buf,lev+1,value->top_margin))) |
120 |
frodo |
80 |
goto ERROR1; |
121 |
frodo |
184 |
if ((res = psiconv_write_length(config,buf,lev+1,value->bottom_margin))) |
122 |
frodo |
80 |
goto ERROR1; |
123 |
frodo |
184 |
if ((res = psiconv_write_page_header(config,buf,lev+1,value->header,&header_buf))) |
124 |
frodo |
80 |
goto ERROR1; |
125 |
frodo |
184 |
if ((res = psiconv_write_page_header(config,buf,lev+1,value->footer,&footer_buf))) |
126 |
frodo |
80 |
goto ERROR2; |
127 |
frodo |
184 |
if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_PAGE_DIMENSIONS2))) |
128 |
frodo |
80 |
goto ERROR3; |
129 |
frodo |
184 |
if ((res = psiconv_write_length(config,buf,lev+1,value->page_width))) |
130 |
frodo |
80 |
goto ERROR3; |
131 |
frodo |
184 |
if ((res = psiconv_write_length(config,buf,lev+1,value->page_height))) |
132 |
frodo |
80 |
goto ERROR3; |
133 |
frodo |
184 |
if ((res = psiconv_write_bool(config,buf,lev+1,value->landscape))) |
134 |
frodo |
80 |
goto ERROR3; |
135 |
|
|
if ((res = psiconv_buffer_concat(buf,header_buf))) |
136 |
|
|
goto ERROR3; |
137 |
|
|
res = psiconv_buffer_concat(buf,footer_buf); |
138 |
|
|
|
139 |
|
|
|
140 |
|
|
ERROR3: |
141 |
|
|
psiconv_buffer_free(footer_buf); |
142 |
|
|
ERROR2: |
143 |
|
|
psiconv_buffer_free(header_buf); |
144 |
|
|
ERROR1: |
145 |
frodo |
231 |
if (res) |
146 |
|
|
psiconv_error(config,lev,0,"Writing of page layout section failed"); |
147 |
|
|
else |
148 |
|
|
psiconv_progress(config,lev,0,"End of page layout section"); |
149 |
frodo |
80 |
return res; |
150 |
frodo |
73 |
} |