1 | /* |
1 | /* |
2 | generate_layout.c - Part of psiconv, a PSION 5 file formats converter |
2 | generate_layout.c - Part of psiconv, a PSION 5 file formats converter |
3 | Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 2000-2004 Frodo Looijaard <frodol@dds.nl> |
4 | |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
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 |
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 |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
15 | You should have received a copy of the GNU General Public License |
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 |
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 <string.h> |
|
|
21 | |
|
|
22 | #include "config.h" |
20 | #include "config.h" |
23 | #include "compat.h" |
21 | #include "compat.h" |
|
|
22 | |
|
|
23 | #include <string.h> |
24 | |
24 | |
25 | #include "generate_routines.h" |
25 | #include "generate_routines.h" |
26 | #include "error.h" |
26 | #include "error.h" |
27 | |
27 | |
28 | #ifdef DMALLOC |
28 | #ifdef DMALLOC |
29 | #include <dmalloc.h> |
29 | #include <dmalloc.h> |
30 | #endif |
30 | #endif |
31 | |
31 | |
32 | |
32 | |
33 | int psiconv_write_color(const psiconv_config config, psiconv_buffer buf, const psiconv_color value) |
33 | int psiconv_write_color(const psiconv_config config, psiconv_buffer buf, |
|
|
34 | int lev, const psiconv_color value) |
34 | { |
35 | { |
35 | int res; |
36 | int res; |
|
|
37 | |
|
|
38 | psiconv_progress(config,lev,0,"Writing color"); |
|
|
39 | |
36 | if (!value) { |
40 | if (!value) { |
37 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null color"); |
41 | psiconv_error(config,lev,0,"Null color"); |
38 | return -PSICONV_E_GENERATE; |
42 | res = -PSICONV_E_GENERATE; |
|
|
43 | goto ERROR; |
39 | } |
44 | } |
40 | if ((res = psiconv_write_u8(config,buf,value->red))) |
45 | if ((res = psiconv_write_u8(config,buf,lev+1,value->red))) |
41 | return res; |
46 | goto ERROR; |
42 | if ((res = psiconv_write_u8(config,buf,value->green))) |
47 | if ((res = psiconv_write_u8(config,buf,lev+1,value->green))) |
|
|
48 | goto ERROR; |
|
|
49 | if ((res = psiconv_write_u8(config,buf,lev+1,value->blue))) |
|
|
50 | goto ERROR; |
|
|
51 | psiconv_progress(config,lev,0,"End of color"); |
|
|
52 | return 0; |
|
|
53 | |
|
|
54 | ERROR: |
|
|
55 | psiconv_error(config,lev,0,"Writing of color failed"); |
43 | return res; |
56 | return res; |
44 | return psiconv_write_u8(config,buf,value->blue); |
|
|
45 | } |
57 | } |
46 | |
58 | |
|
|
59 | int psiconv_write_font(const psiconv_config config, psiconv_buffer buf, |
|
|
60 | int lev, const psiconv_font value) |
|
|
61 | { |
|
|
62 | int res,len; |
|
|
63 | |
|
|
64 | psiconv_progress(config,lev,0,"Writing font"); |
|
|
65 | if (!value) { |
|
|
66 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null font"); |
|
|
67 | res = -PSICONV_E_GENERATE; |
|
|
68 | goto ERROR; |
|
|
69 | } |
|
|
70 | len = psiconv_unicode_strlen(value->name); |
|
|
71 | if ((res = psiconv_write_u8(config,buf,lev+1,len+1))) |
|
|
72 | goto ERROR; |
|
|
73 | if ((res = psiconv_write_charlist(config,buf,lev+1,value->name))) |
|
|
74 | goto ERROR; |
|
|
75 | if ((res = psiconv_write_u8(config,buf,lev+1,value->screenfont))) |
|
|
76 | goto ERROR; |
|
|
77 | psiconv_progress(config,lev,0,"End of font"); |
|
|
78 | return 0; |
|
|
79 | |
|
|
80 | ERROR: |
|
|
81 | psiconv_error(config,lev,0,"Writing of font failed"); |
|
|
82 | return res; |
|
|
83 | } |
|
|
84 | |
47 | int psiconv_write_font(const psiconv_config config, psiconv_buffer buf, const psiconv_font value) |
85 | int psiconv_write_border(const psiconv_config config, psiconv_buffer buf,int lev, const psiconv_border value) |
48 | { |
86 | { |
49 | int res; |
87 | int res; |
|
|
88 | |
|
|
89 | psiconv_progress(config,lev,0,"Writing border"); |
|
|
90 | |
50 | if (!value) { |
91 | if (!value) { |
51 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null font"); |
92 | psiconv_error(config,lev,0,"Null border"); |
52 | return -PSICONV_E_GENERATE; |
93 | res = -PSICONV_E_GENERATE; |
53 | } |
94 | goto ERROR; |
54 | if ((res = psiconv_write_short_string(config,buf,value->name))) |
|
|
55 | return res; |
|
|
56 | return psiconv_write_u8(config,buf,value->screenfont); |
|
|
57 | } |
|
|
58 | |
|
|
59 | int psiconv_write_border(const psiconv_config config, psiconv_buffer buf, const psiconv_border value) |
|
|
60 | { |
|
|
61 | int res; |
|
|
62 | |
|
|
63 | if (!value) { |
|
|
64 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null border"); |
|
|
65 | return -PSICONV_E_GENERATE; |
|
|
66 | } |
95 | } |
67 | if (value->kind > psiconv_border_dotdotdashed) |
96 | if (value->kind > psiconv_border_dotdotdashed) |
68 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
97 | psiconv_warn(config,lev,0, |
69 | "Unknown border kind (%d); assuming none",value->kind); |
98 | "Unknown border kind (%d); assuming none",value->kind); |
70 | if ((res =psiconv_write_u8(config,buf,value->kind == psiconv_border_none?0: |
99 | if ((res =psiconv_write_u8(config,buf,lev+1, |
|
|
100 | value->kind == psiconv_border_none?0: |
71 | value->kind == psiconv_border_solid?1: |
101 | value->kind == psiconv_border_solid?1: |
72 | value->kind == psiconv_border_double?2: |
102 | value->kind == psiconv_border_double?2: |
73 | value->kind == psiconv_border_dotted?3: |
103 | value->kind == psiconv_border_dotted?3: |
74 | value->kind == psiconv_border_dashed?4: |
104 | value->kind == psiconv_border_dashed?4: |
75 | value->kind == psiconv_border_dotdashed?5: |
105 | value->kind == psiconv_border_dotdashed?5: |
76 | value->kind == psiconv_border_dotdotdashed?6: |
106 | value->kind == psiconv_border_dotdotdashed?6: |
77 | 0))) |
107 | 0))) |
78 | return res; |
108 | goto ERROR; |
79 | if ((res = psiconv_write_size(config,buf,(value->kind == psiconv_border_solid) || |
109 | if ((res = psiconv_write_size(config,buf,lev+1, |
|
|
110 | (value->kind == psiconv_border_solid) || |
80 | (value->kind == psiconv_border_double) ? |
111 | (value->kind == psiconv_border_double) ? |
81 | value->thickness:1.0/20.0))) |
112 | value->thickness:1.0/20.0))) |
82 | return res; |
113 | goto ERROR; |
83 | if ((res = psiconv_write_color(config,buf,value->color))) |
114 | if ((res = psiconv_write_color(config,buf,lev+1,value->color))) |
|
|
115 | goto ERROR; |
|
|
116 | /* Unknown byte */ |
|
|
117 | if ((res = psiconv_write_u8(config,buf,lev+1,1))) |
|
|
118 | goto ERROR; |
|
|
119 | psiconv_progress(config,lev,0,"End of border"); |
|
|
120 | return 0; |
|
|
121 | |
|
|
122 | ERROR: |
|
|
123 | psiconv_error(config,lev,0,"Writing of border failed"); |
84 | return res; |
124 | return res; |
85 | // Unknown byte |
|
|
86 | return psiconv_write_u8(config,buf,1); |
|
|
87 | } |
125 | } |
88 | |
126 | |
89 | int psiconv_write_bullet(const psiconv_config config, psiconv_buffer buf, const psiconv_bullet value) |
127 | int psiconv_write_bullet(const psiconv_config config, psiconv_buffer buf,int lev, const psiconv_bullet value) |
90 | { |
128 | { |
91 | int res; |
129 | int res; |
92 | psiconv_buffer extra_buf; |
130 | psiconv_buffer extra_buf; |
|
|
131 | |
|
|
132 | psiconv_progress(config,lev,0,"Writing bullet"); |
|
|
133 | |
93 | if (!value) { |
134 | if (!value) { |
94 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null bullet"); |
135 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null bullet"); |
95 | return -PSICONV_E_GENERATE; |
136 | res = -PSICONV_E_GENERATE; |
|
|
137 | goto ERROR1; |
96 | } |
138 | } |
97 | |
139 | |
98 | if (!(extra_buf = psiconv_buffer_new())) |
140 | if (!(extra_buf = psiconv_buffer_new())) { |
99 | return -PSICONV_E_NOMEM; |
141 | res = -PSICONV_E_NOMEM; |
100 | if ((res = psiconv_write_size(config,extra_buf,value->font_size))) |
|
|
101 | goto ERROR; |
142 | goto ERROR1; |
|
|
143 | } |
102 | if ((res = psiconv_write_u8(config,extra_buf,value->character))) |
144 | if ((res = psiconv_write_size(config,extra_buf,lev+1,value->font_size))) |
103 | goto ERROR; |
145 | goto ERROR2; |
104 | if ((res = psiconv_write_bool(config,extra_buf,value->indent))) |
146 | if ((res = psiconv_unicode_write_char(config,extra_buf,lev+1, |
|
|
147 | value->character))) |
105 | goto ERROR; |
148 | goto ERROR2; |
106 | if ((res = psiconv_write_color(config,extra_buf,value->color))) |
149 | if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->indent))) |
107 | goto ERROR; |
150 | goto ERROR2; |
108 | if ((res = psiconv_write_font(config,extra_buf,value->font))) |
151 | if ((res = psiconv_write_color(config,extra_buf,lev+1,value->color))) |
109 | goto ERROR; |
152 | goto ERROR2; |
110 | |
153 | if ((res = psiconv_write_font(config,extra_buf,lev+1,value->font))) |
111 | if ((res = psiconv_write_u8(config,buf,psiconv_buffer_length(extra_buf)))) |
|
|
112 | goto ERROR; |
154 | goto ERROR2; |
|
|
155 | |
|
|
156 | if ((res = psiconv_write_u8(config,buf,lev+1,psiconv_buffer_length(extra_buf)))) |
|
|
157 | goto ERROR2; |
113 | res = psiconv_buffer_concat(buf,extra_buf); |
158 | res = psiconv_buffer_concat(buf,extra_buf); |
114 | |
159 | |
115 | ERROR: |
160 | ERROR2: |
116 | psiconv_buffer_free(extra_buf); |
161 | psiconv_buffer_free(extra_buf); |
|
|
162 | ERROR1: |
|
|
163 | if (res) |
|
|
164 | psiconv_error(config,lev,0,"Writing of bullet failed"); |
|
|
165 | else |
|
|
166 | psiconv_progress(config,lev,0,"End of bullet"); |
117 | return res; |
167 | return res; |
118 | } |
168 | } |
119 | |
169 | |
120 | int psiconv_write_tab(const psiconv_config config, psiconv_buffer buf,psiconv_tab value) |
170 | int psiconv_write_tab(const psiconv_config config, psiconv_buffer buf,int lev, psiconv_tab value) |
121 | { |
171 | { |
122 | int res; |
172 | int res; |
|
|
173 | |
|
|
174 | psiconv_progress(config,lev,0,"Writing tab"); |
|
|
175 | |
123 | if (!value) { |
176 | if (!value) { |
124 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null tab"); |
177 | psiconv_error(config,lev,0,"Null tab"); |
125 | return -PSICONV_E_GENERATE; |
178 | res = -PSICONV_E_GENERATE; |
|
|
179 | goto ERROR; |
126 | } |
180 | } |
127 | if ((res = psiconv_write_length(config,buf,value->location))) |
181 | if ((res = psiconv_write_length(config,buf,lev+1,value->location))) |
128 | return res; |
182 | goto ERROR; |
129 | if ((value->kind != psiconv_tab_left) && |
183 | if ((value->kind != psiconv_tab_left) && |
130 | (value->kind != psiconv_tab_right) && |
184 | (value->kind != psiconv_tab_right) && |
131 | (value->kind != psiconv_tab_centre)) |
185 | (value->kind != psiconv_tab_centre)) |
132 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
186 | psiconv_warn(config,lev,0, |
133 | "Unknown tab kind (%d); assuming left",value->kind); |
187 | "Unknown tab kind (%d); assuming left",value->kind); |
134 | return psiconv_write_u8(config,buf, value->kind == psiconv_tab_right?2: |
188 | if ((res = psiconv_write_u8(config,buf,lev+1, |
|
|
189 | value->kind == psiconv_tab_right?2: |
135 | value->kind == psiconv_tab_centre?3:1); |
190 | value->kind == psiconv_tab_centre?3:1))) |
|
|
191 | goto ERROR; |
|
|
192 | psiconv_progress(config,lev,0,"End of tab"); |
|
|
193 | return 0; |
|
|
194 | ERROR: |
|
|
195 | psiconv_error(config,lev,0,"Writing of tab failed"); |
|
|
196 | return res; |
136 | } |
197 | } |
137 | |
198 | |
138 | int psiconv_write_paragraph_layout_list(const psiconv_config config, |
199 | int psiconv_write_paragraph_layout_list(const psiconv_config config, |
139 | psiconv_buffer buf, |
200 | psiconv_buffer buf,int lev, |
140 | psiconv_paragraph_layout value, |
201 | psiconv_paragraph_layout value, |
141 | psiconv_paragraph_layout base) |
202 | psiconv_paragraph_layout base) |
142 | { |
203 | { |
143 | int res,i; |
204 | int res,i; |
144 | psiconv_buffer extra_buf; |
205 | psiconv_buffer extra_buf; |
145 | psiconv_tab tab; |
206 | psiconv_tab tab; |
146 | |
207 | |
|
|
208 | psiconv_progress(config,lev,0,"Writing paragraph layout list"); |
|
|
209 | |
147 | if (!value) { |
210 | if (!value) { |
148 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null paragraph layout list"); |
211 | psiconv_error(config,lev,0,"Null paragraph layout list"); |
149 | return -PSICONV_E_GENERATE; |
212 | res = -PSICONV_E_GENERATE; |
|
|
213 | goto ERROR1; |
150 | } |
214 | } |
151 | if (!(extra_buf = psiconv_buffer_new())) |
215 | if (!(extra_buf = psiconv_buffer_new())) { |
152 | return -PSICONV_E_NOMEM; |
216 | res = -PSICONV_E_NOMEM; |
|
|
217 | goto ERROR1; |
|
|
218 | } |
153 | |
219 | |
154 | if (!base || psiconv_compare_color(base->back_color,value->back_color)) { |
220 | if (!base || psiconv_compare_color(base->back_color,value->back_color)) { |
155 | if ((res = psiconv_write_u8(config,extra_buf,0x01))) |
221 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x01))) |
156 | goto ERROR; |
222 | goto ERROR2; |
157 | if ((res = psiconv_write_color(config,extra_buf,value->back_color))) |
223 | if ((res = psiconv_write_color(config,extra_buf,lev+1,value->back_color))) |
158 | goto ERROR; |
224 | goto ERROR2; |
159 | } |
225 | } |
160 | |
226 | |
161 | if (!base || (value->indent_left != base->indent_left)) { |
227 | if (!base || (value->indent_left != base->indent_left)) { |
162 | if ((res = psiconv_write_u8(config,extra_buf,0x02))) |
228 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x02))) |
163 | goto ERROR; |
229 | goto ERROR2; |
164 | if ((res = psiconv_write_length(config,extra_buf,value->indent_left))) |
230 | if ((res = psiconv_write_length(config,extra_buf,lev+1,value->indent_left))) |
165 | goto ERROR; |
231 | goto ERROR2; |
166 | } |
232 | } |
167 | |
233 | |
168 | if (!base || (value->indent_right != base->indent_right)) { |
234 | if (!base || (value->indent_right != base->indent_right)) { |
169 | if ((res = psiconv_write_u8(config,extra_buf,0x03))) |
235 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x03))) |
170 | goto ERROR; |
236 | goto ERROR2; |
171 | if ((res = psiconv_write_length(config,extra_buf,value->indent_right))) |
237 | if ((res = psiconv_write_length(config,extra_buf,lev+1,value->indent_right))) |
172 | goto ERROR; |
238 | goto ERROR2; |
173 | } |
239 | } |
174 | |
240 | |
175 | if (!base || (value->indent_first != base->indent_first)) { |
241 | if (!base || (value->indent_first != base->indent_first)) { |
176 | if ((res = psiconv_write_u8(config,extra_buf,0x04))) |
242 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x04))) |
177 | goto ERROR; |
243 | goto ERROR2; |
178 | if ((res = psiconv_write_length(config,extra_buf,value->indent_first))) |
244 | if ((res = psiconv_write_length(config,extra_buf,lev+1,value->indent_first))) |
179 | goto ERROR; |
245 | goto ERROR2; |
180 | } |
246 | } |
181 | |
247 | |
182 | if (!base || (value->justify_hor != base->justify_hor)) { |
248 | if (!base || (value->justify_hor != base->justify_hor)) { |
183 | if ((res = psiconv_write_u8(config,extra_buf,0x05))) |
249 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x05))) |
184 | goto ERROR; |
250 | goto ERROR2; |
185 | if ((value->justify_hor < psiconv_justify_left) || |
251 | if ((value->justify_hor < psiconv_justify_left) || |
186 | (value->justify_hor > psiconv_justify_full)) |
252 | (value->justify_hor > psiconv_justify_full)) |
187 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
253 | psiconv_warn(config,lev,0, |
188 | "Unknown horizontal justify (%d); assuming left", |
254 | "Unknown horizontal justify (%d); assuming left", |
189 | value->justify_hor); |
255 | value->justify_hor); |
190 | if ((res = psiconv_write_u8(config,extra_buf, |
256 | if ((res = psiconv_write_u8(config,extra_buf,lev+1, |
191 | value->justify_hor == psiconv_justify_centre?1: |
257 | value->justify_hor == psiconv_justify_centre?1: |
192 | value->justify_hor == psiconv_justify_right?2: |
258 | value->justify_hor == psiconv_justify_right?2: |
193 | value->justify_hor == psiconv_justify_full?3:0))) |
259 | value->justify_hor == psiconv_justify_full?3:0))) |
194 | goto ERROR; |
260 | goto ERROR2; |
195 | } |
261 | } |
196 | |
262 | |
197 | if (!base || (value->justify_ver != base->justify_ver)) { |
263 | if (!base || (value->justify_ver != base->justify_ver)) { |
198 | if ((res = psiconv_write_u8(config,extra_buf,0x06))) |
264 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x06))) |
199 | goto ERROR; |
265 | goto ERROR2; |
200 | if ((value->justify_ver < psiconv_justify_top) || |
266 | if ((value->justify_ver < psiconv_justify_top) || |
201 | (value->justify_ver > psiconv_justify_bottom)) |
267 | (value->justify_ver > psiconv_justify_bottom)) |
202 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
268 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
203 | "Unknown vertical justify (%d); assuming middle", |
269 | "Unknown vertical justify (%d); assuming middle", |
204 | value->justify_ver); |
270 | value->justify_ver); |
205 | if ((res = psiconv_write_u8(config,extra_buf, |
271 | if ((res = psiconv_write_u8(config,extra_buf,lev+1, |
206 | value->justify_ver == psiconv_justify_centre?1: |
272 | value->justify_ver == psiconv_justify_centre?1: |
207 | value->justify_ver == psiconv_justify_right?2:0))) |
273 | value->justify_ver == psiconv_justify_right?2:0))) |
208 | goto ERROR; |
274 | goto ERROR2; |
209 | } |
275 | } |
210 | |
276 | |
211 | if (!base || (value->linespacing != base->linespacing)) { |
277 | if (!base || (value->linespacing != base->linespacing)) { |
212 | if ((res = psiconv_write_u8(config,extra_buf,0x07))) |
278 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x07))) |
213 | goto ERROR; |
279 | goto ERROR2; |
214 | if ((res = psiconv_write_size(config,extra_buf,value->linespacing))) |
280 | if ((res = psiconv_write_size(config,extra_buf,lev+1,value->linespacing))) |
215 | goto ERROR; |
281 | goto ERROR2; |
216 | } |
282 | } |
217 | |
283 | |
218 | if (!base || (value->linespacing_exact != base->linespacing_exact)) { |
284 | if (!base || (value->linespacing_exact != base->linespacing_exact)) { |
219 | if ((res = psiconv_write_u8(config,extra_buf,0x08))) |
285 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x08))) |
220 | goto ERROR; |
286 | goto ERROR2; |
221 | if ((res = psiconv_write_bool(config,extra_buf,value->linespacing_exact))) |
287 | if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->linespacing_exact))) |
222 | goto ERROR; |
288 | goto ERROR2; |
223 | } |
289 | } |
224 | |
290 | |
225 | if (!base || (value->space_above != base->space_above)) { |
291 | if (!base || (value->space_above != base->space_above)) { |
226 | if ((res = psiconv_write_u8(config,extra_buf,0x09))) |
292 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x09))) |
227 | goto ERROR; |
293 | goto ERROR2; |
228 | if ((res = psiconv_write_size(config,extra_buf,value->space_above))) |
294 | if ((res = psiconv_write_size(config,extra_buf,lev+1,value->space_above))) |
229 | goto ERROR; |
295 | goto ERROR2; |
230 | } |
296 | } |
231 | |
297 | |
232 | if (!base || (value->space_below != base->space_below)) { |
298 | if (!base || (value->space_below != base->space_below)) { |
233 | if ((res = psiconv_write_u8(config,extra_buf,0x0a))) |
299 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x0a))) |
234 | goto ERROR; |
300 | goto ERROR2; |
235 | if ((res = psiconv_write_size(config,extra_buf,value->space_below))) |
301 | if ((res = psiconv_write_size(config,extra_buf,lev+1,value->space_below))) |
236 | goto ERROR; |
302 | goto ERROR2; |
237 | } |
303 | } |
238 | |
304 | |
239 | if (!base || (value->keep_together != base->keep_together)) { |
305 | if (!base || (value->keep_together != base->keep_together)) { |
240 | if ((res = psiconv_write_u8(config,extra_buf,0x0b))) |
306 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x0b))) |
241 | goto ERROR; |
307 | goto ERROR2; |
242 | if ((res = psiconv_write_bool(config,extra_buf,value->keep_together))) |
308 | if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->keep_together))) |
243 | goto ERROR; |
309 | goto ERROR2; |
244 | } |
310 | } |
245 | |
311 | |
246 | if (!base || (value->keep_with_next != base->keep_with_next)) { |
312 | if (!base || (value->keep_with_next != base->keep_with_next)) { |
247 | if ((res = psiconv_write_u8(config,extra_buf,0x0c))) |
313 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x0c))) |
248 | goto ERROR; |
314 | goto ERROR2; |
249 | if ((res = psiconv_write_bool(config,extra_buf,value->keep_with_next))) |
315 | if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->keep_with_next))) |
250 | goto ERROR; |
316 | goto ERROR2; |
251 | } |
317 | } |
252 | |
318 | |
253 | if (!base || (value->on_next_page != base->on_next_page)) { |
319 | if (!base || (value->on_next_page != base->on_next_page)) { |
254 | if ((res = psiconv_write_u8(config,extra_buf,0x0d))) |
320 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x0d))) |
255 | goto ERROR; |
321 | goto ERROR2; |
256 | if ((res = psiconv_write_bool(config,extra_buf,value->on_next_page))) |
322 | if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->on_next_page))) |
257 | goto ERROR; |
323 | goto ERROR2; |
258 | } |
324 | } |
259 | |
325 | |
260 | if (!base || (value->no_widow_protection != base->no_widow_protection)) { |
326 | if (!base || (value->no_widow_protection != base->no_widow_protection)) { |
261 | if ((res = psiconv_write_u8(config,extra_buf,0x0e))) |
327 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x0e))) |
262 | goto ERROR; |
328 | goto ERROR2; |
263 | if ((res = psiconv_write_bool(config,extra_buf,value->no_widow_protection))) |
329 | if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->no_widow_protection))) |
264 | goto ERROR; |
330 | goto ERROR2; |
265 | } |
331 | } |
266 | |
332 | |
267 | if (!base || (value->wrap_to_fit_cell != base->wrap_to_fit_cell)) { |
333 | if (!base || (value->wrap_to_fit_cell != base->wrap_to_fit_cell)) { |
268 | if ((res = psiconv_write_u8(config,extra_buf,0x0f))) |
334 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x0f))) |
269 | goto ERROR; |
335 | goto ERROR2; |
270 | if ((res = psiconv_write_bool(config,extra_buf,value->wrap_to_fit_cell))) |
336 | if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->wrap_to_fit_cell))) |
271 | goto ERROR; |
337 | goto ERROR2; |
272 | } |
338 | } |
273 | |
339 | |
274 | if (!base || (value->border_distance != base->border_distance)) { |
340 | if (!base || (value->border_distance != base->border_distance)) { |
275 | if ((res = psiconv_write_u8(config,extra_buf,0x10))) |
341 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x10))) |
276 | goto ERROR; |
342 | goto ERROR2; |
277 | if ((res = psiconv_write_length(config,extra_buf,value->border_distance))) |
343 | if ((res = psiconv_write_length(config,extra_buf,lev+1,value->border_distance))) |
278 | goto ERROR; |
344 | goto ERROR2; |
279 | } |
345 | } |
280 | |
346 | |
281 | if (!base || psiconv_compare_border(value->top_border,base->top_border)) { |
347 | if (!base || psiconv_compare_border(value->top_border,base->top_border)) { |
282 | if ((res = psiconv_write_u8(config,extra_buf,0x11))) |
348 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x11))) |
283 | goto ERROR; |
349 | goto ERROR2; |
284 | if ((res = psiconv_write_border(config,extra_buf,value->top_border))) |
350 | if ((res = psiconv_write_border(config,extra_buf,lev+1,value->top_border))) |
285 | goto ERROR; |
351 | goto ERROR2; |
286 | } |
352 | } |
287 | |
353 | |
288 | if (!base || psiconv_compare_border(value->bottom_border, |
354 | if (!base || psiconv_compare_border(value->bottom_border, |
289 | base->bottom_border)) { |
355 | base->bottom_border)) { |
290 | if ((res = psiconv_write_u8(config,extra_buf,0x12))) |
356 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x12))) |
291 | goto ERROR; |
357 | goto ERROR2; |
292 | if ((res = psiconv_write_border(config,extra_buf,value->bottom_border))) |
358 | if ((res = psiconv_write_border(config,extra_buf,lev+1,value->bottom_border))) |
293 | goto ERROR; |
359 | goto ERROR2; |
294 | } |
360 | } |
295 | |
361 | |
296 | if (!base || psiconv_compare_border(value->left_border, |
362 | if (!base || psiconv_compare_border(value->left_border, |
297 | base->left_border)) { |
363 | base->left_border)) { |
298 | if ((res = psiconv_write_u8(config,extra_buf,0x13))) |
364 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x13))) |
299 | goto ERROR; |
365 | goto ERROR2; |
300 | if ((res = psiconv_write_border(config,extra_buf,value->left_border))) |
366 | if ((res = psiconv_write_border(config,extra_buf,lev+1,value->left_border))) |
301 | goto ERROR; |
367 | goto ERROR2; |
302 | } |
368 | } |
303 | |
369 | |
304 | if (!base || psiconv_compare_border(value->right_border, |
370 | if (!base || psiconv_compare_border(value->right_border, |
305 | base->right_border)) { |
371 | base->right_border)) { |
306 | if ((res = psiconv_write_u8(config,extra_buf,0x14))) |
372 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x14))) |
307 | goto ERROR; |
373 | goto ERROR2; |
308 | if ((res = psiconv_write_border(config,extra_buf,value->right_border))) |
374 | if ((res = psiconv_write_border(config,extra_buf,lev+1,value->right_border))) |
309 | goto ERROR; |
375 | goto ERROR2; |
310 | } |
376 | } |
311 | |
377 | |
312 | if (!base || psiconv_compare_bullet(value->bullet, |
378 | if (!base || psiconv_compare_bullet(value->bullet, |
313 | base->bullet)) { |
379 | base->bullet)) { |
314 | if ((res = psiconv_write_u8(config,extra_buf,0x15))) |
380 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x15))) |
315 | goto ERROR; |
381 | goto ERROR2; |
316 | if ((res = psiconv_write_bullet(config,extra_buf,value->bullet))) |
382 | if ((res = psiconv_write_bullet(config,extra_buf,lev+1,value->bullet))) |
317 | goto ERROR; |
383 | goto ERROR2; |
318 | } |
384 | } |
319 | |
385 | |
320 | if (!value->tabs || !value->tabs->extras) { |
386 | if (!value->tabs || !value->tabs->extras) { |
321 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null tabs"); |
387 | psiconv_error(config,0,psiconv_buffer_length(buf),"Null tabs"); |
322 | res = -PSICONV_E_GENERATE; |
388 | res = -PSICONV_E_GENERATE; |
323 | goto ERROR; |
389 | goto ERROR2; |
324 | } |
390 | } |
325 | |
391 | |
326 | /* It is not entirely clear how tabs are inherited. For now, I assume |
392 | /* It is not entirely clear how tabs are inherited. For now, I assume |
327 | if there is any difference at all, we will have to generate both |
393 | if there is any difference at all, we will have to generate both |
328 | the normal tab-interval, and all specific tabs */ |
394 | the normal tab-interval, and all specific tabs */ |
329 | if (!base || psiconv_compare_all_tabs(value->tabs,base->tabs)) { |
395 | if (!base || psiconv_compare_all_tabs(value->tabs,base->tabs)) { |
330 | if ((res = psiconv_write_u8(config,extra_buf,0x16))) |
396 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x16))) |
331 | goto ERROR; |
397 | goto ERROR2; |
332 | if ((res = psiconv_write_length(config,extra_buf,value->tabs->normal))) |
398 | if ((res = psiconv_write_length(config,extra_buf,lev+1,value->tabs->normal))) |
333 | goto ERROR; |
399 | goto ERROR2; |
334 | for (i = 0; i < psiconv_list_length(value->tabs->extras); i++) { |
400 | for (i = 0; i < psiconv_list_length(value->tabs->extras); i++) { |
335 | if (!(tab = psiconv_list_get(value->tabs->extras,i))) { |
401 | if (!(tab = psiconv_list_get(value->tabs->extras,i))) { |
336 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
402 | psiconv_error(config,lev+1,0,"Massive memory corruption"); |
337 | res = -PSICONV_E_NOMEM; |
403 | res = -PSICONV_E_NOMEM; |
338 | goto ERROR; |
404 | goto ERROR2; |
339 | } |
405 | } |
340 | if ((res = psiconv_write_u8(config,extra_buf,0x17))) |
406 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x17))) |
341 | goto ERROR; |
407 | goto ERROR2; |
342 | if ((res = psiconv_write_tab(config,extra_buf,tab))) |
408 | if ((res = psiconv_write_tab(config,extra_buf,lev+1,tab))) |
343 | goto ERROR; |
409 | goto ERROR2; |
344 | } |
410 | } |
345 | } |
411 | } |
346 | |
412 | |
347 | if ((res = psiconv_write_u32(config,buf,psiconv_buffer_length(extra_buf)))) |
413 | if ((res = psiconv_write_u32(config,buf,lev+1,psiconv_buffer_length(extra_buf)))) |
348 | goto ERROR; |
414 | goto ERROR2; |
349 | |
415 | |
350 | res = psiconv_buffer_concat(buf,extra_buf); |
416 | res = psiconv_buffer_concat(buf,extra_buf); |
351 | |
417 | |
352 | ERROR: |
418 | ERROR2: |
353 | psiconv_buffer_free(extra_buf); |
419 | psiconv_buffer_free(extra_buf); |
|
|
420 | ERROR1: |
|
|
421 | if (res) |
|
|
422 | psiconv_error(config,lev,0,"Writing of paragraph layout list failed"); |
|
|
423 | else |
|
|
424 | psiconv_progress(config,lev,0,"End of paragraph layout list"); |
354 | return res; |
425 | return res; |
355 | } |
426 | } |
356 | |
427 | |
357 | int psiconv_write_character_layout_list(const psiconv_config config, |
428 | int psiconv_write_character_layout_list(const psiconv_config config, |
358 | psiconv_buffer buf, |
429 | psiconv_buffer buf,int lev, |
359 | psiconv_character_layout value, |
430 | psiconv_character_layout value, |
360 | psiconv_character_layout base) |
431 | psiconv_character_layout base) |
361 | { |
432 | { |
362 | int res; |
433 | int res; |
363 | psiconv_buffer extra_buf; |
434 | psiconv_buffer extra_buf; |
|
|
435 | |
|
|
436 | psiconv_progress(config,lev,0,"Writing character layout list"); |
|
|
437 | |
364 | if (!value) { |
438 | if (!value) { |
365 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null character layout list"); |
439 | psiconv_error(config,lev,0,"Null character layout list"); |
366 | return -PSICONV_E_GENERATE; |
440 | res = -PSICONV_E_GENERATE; |
|
|
441 | goto ERROR1; |
367 | } |
442 | } |
368 | if (!(extra_buf = psiconv_buffer_new())) |
443 | if (!(extra_buf = psiconv_buffer_new())) { |
369 | return -PSICONV_E_NOMEM; |
444 | res = -PSICONV_E_NOMEM; |
|
|
445 | goto ERROR1; |
|
|
446 | } |
370 | |
447 | |
371 | if (!base || psiconv_compare_color(base->color,value->color)) { |
448 | if (!base || psiconv_compare_color(base->color,value->color)) { |
372 | if ((res = psiconv_write_u8(config,extra_buf,0x19))) |
449 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x19))) |
373 | goto ERROR; |
450 | goto ERROR2; |
374 | if ((res = psiconv_write_color(config,extra_buf,value->color))) |
451 | if ((res = psiconv_write_color(config,extra_buf,lev+1,value->color))) |
375 | goto ERROR; |
452 | goto ERROR2; |
376 | } |
453 | } |
377 | |
454 | |
378 | if (!base || psiconv_compare_color(base->back_color,value->back_color)) { |
455 | if (!base || psiconv_compare_color(base->back_color,value->back_color)) { |
379 | if ((res = psiconv_write_u8(config,extra_buf,0x1a))) |
456 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x1a))) |
380 | goto ERROR; |
457 | goto ERROR2; |
381 | if ((res = psiconv_write_color(config,extra_buf,value->back_color))) |
458 | if ((res = psiconv_write_color(config,extra_buf,lev+1,value->back_color))) |
382 | goto ERROR; |
459 | goto ERROR2; |
383 | } |
460 | } |
384 | |
461 | |
385 | if (!base || (value->font_size != base->font_size)) { |
462 | if (!base || (value->font_size != base->font_size)) { |
386 | if ((res = psiconv_write_u8(config,extra_buf,0x1c))) |
463 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x1c))) |
387 | goto ERROR; |
464 | goto ERROR2; |
388 | if ((res = psiconv_write_size(config,extra_buf,value->font_size))) |
465 | if ((res = psiconv_write_size(config,extra_buf,lev+1,value->font_size))) |
389 | goto ERROR; |
466 | goto ERROR2; |
390 | } |
467 | } |
391 | |
468 | |
392 | if (!base || (value->italic != base->italic)) { |
469 | if (!base || (value->italic != base->italic)) { |
393 | if ((res = psiconv_write_u8(config,extra_buf,0x1d))) |
470 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x1d))) |
394 | goto ERROR; |
471 | goto ERROR2; |
395 | if ((res = psiconv_write_bool(config,extra_buf,value->italic))) |
472 | if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->italic))) |
396 | goto ERROR; |
473 | goto ERROR2; |
397 | } |
474 | } |
398 | |
475 | |
399 | if (!base || (value->bold != base->bold)) { |
476 | if (!base || (value->bold != base->bold)) { |
400 | if ((res = psiconv_write_u8(config,extra_buf,0x1e))) |
477 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x1e))) |
401 | goto ERROR; |
478 | goto ERROR2; |
402 | if ((res = psiconv_write_bool(config,extra_buf,value->bold))) |
479 | if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->bold))) |
403 | goto ERROR; |
480 | goto ERROR2; |
404 | } |
481 | } |
405 | |
482 | |
406 | if (!base || (value->super_sub != base->super_sub)) { |
483 | if (!base || (value->super_sub != base->super_sub)) { |
407 | if ((value->super_sub != psiconv_superscript) && |
484 | if ((value->super_sub != psiconv_superscript) && |
408 | (value->super_sub != psiconv_subscript) && |
485 | (value->super_sub != psiconv_subscript) && |
409 | (value->super_sub != psiconv_normalscript)) |
486 | (value->super_sub != psiconv_normalscript)) |
410 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
487 | psiconv_warn(config,lev,0,"Unknown supersubscript (%d); assuming normal", |
411 | "Unknown supersubscript (%d); assuming normal", |
|
|
412 | value->super_sub); |
488 | value->super_sub); |
413 | if ((res = psiconv_write_u8(config,extra_buf,0x1f))) |
489 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x1f))) |
414 | goto ERROR; |
490 | goto ERROR2; |
415 | if ((res = psiconv_write_u8(config,extra_buf, |
491 | if ((res = psiconv_write_u8(config,extra_buf,lev+1, |
416 | value->super_sub == psiconv_superscript?1: |
492 | value->super_sub == psiconv_superscript?1: |
417 | value->super_sub == psiconv_subscript?2:0))) |
493 | value->super_sub == psiconv_subscript?2:0))) |
418 | goto ERROR; |
494 | goto ERROR2; |
419 | } |
495 | } |
420 | |
496 | |
421 | if (!base || (value->underline != base->underline)) { |
497 | if (!base || (value->underline != base->underline)) { |
422 | if ((res = psiconv_write_u8(config,extra_buf,0x20))) |
498 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x20))) |
423 | goto ERROR; |
499 | goto ERROR2; |
424 | if ((res = psiconv_write_bool(config,extra_buf,value->underline))) |
500 | if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->underline))) |
425 | goto ERROR; |
501 | goto ERROR2; |
426 | } |
502 | } |
427 | |
503 | |
428 | if (!base || (value->strikethrough != base->strikethrough)) { |
504 | if (!base || (value->strikethrough != base->strikethrough)) { |
429 | if ((res = psiconv_write_u8(config,extra_buf,0x21))) |
505 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x21))) |
430 | goto ERROR; |
506 | goto ERROR2; |
431 | if ((res = psiconv_write_bool(config,extra_buf,value->strikethrough))) |
507 | if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->strikethrough))) |
432 | goto ERROR; |
508 | goto ERROR2; |
433 | } |
509 | } |
434 | |
510 | |
435 | if (!base || psiconv_compare_font(base->font,value->font)) { |
511 | if (!base || psiconv_compare_font(base->font,value->font)) { |
436 | if ((res = psiconv_write_u8(config,extra_buf,0x22))) |
512 | if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x22))) |
437 | goto ERROR; |
513 | goto ERROR2; |
438 | if ((res = psiconv_write_font(config,extra_buf,value->font))) |
514 | if ((res = psiconv_write_font(config,extra_buf,lev+1,value->font))) |
439 | goto ERROR; |
515 | goto ERROR2; |
440 | } |
516 | } |
441 | |
517 | |
442 | if ((res = psiconv_write_u32(config,buf,psiconv_buffer_length(extra_buf)))) |
518 | if ((res = psiconv_write_u32(config,buf,lev+1,psiconv_buffer_length(extra_buf)))) |
443 | goto ERROR; |
519 | goto ERROR2; |
444 | |
520 | |
445 | res = psiconv_buffer_concat(buf,extra_buf); |
521 | res = psiconv_buffer_concat(buf,extra_buf); |
446 | |
522 | |
447 | ERROR: |
523 | ERROR2: |
448 | psiconv_buffer_free(extra_buf); |
524 | psiconv_buffer_free(extra_buf); |
|
|
525 | ERROR1: |
|
|
526 | if (res) |
|
|
527 | psiconv_error(config,lev,0,"Writing of character layout list failed"); |
|
|
528 | else |
|
|
529 | psiconv_progress(config,lev,0,"End of character layout list"); |
449 | return res; |
530 | return res; |
450 | } |
531 | } |