/[public]/psiconv/trunk/lib/psiconv/generate_layout.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/generate_layout.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.80  
changed lines
  Added in v.182

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26