| … | |
… | |
| 25 | |
25 | |
| 26 | int psiconv_write_color(psiconv_buffer buf, const psiconv_color value) |
26 | int psiconv_write_color(psiconv_buffer buf, const psiconv_color value) |
| 27 | { |
27 | { |
| 28 | int res; |
28 | int res; |
| 29 | if (!value) { |
29 | if (!value) { |
| 30 | psiconv_warn(0,psiconv_list_length(buf),"Null color"); |
30 | psiconv_warn(0,psiconv_buffer_length(buf),"Null color"); |
| 31 | return -PSICONV_E_GENERATE; |
31 | return -PSICONV_E_GENERATE; |
| 32 | } |
32 | } |
| 33 | if ((res = psiconv_write_u8(buf,value->red))) |
33 | if ((res = psiconv_write_u8(buf,value->red))) |
| 34 | return res; |
34 | return res; |
| 35 | if ((res = psiconv_write_u8(buf,value->green))) |
35 | if ((res = psiconv_write_u8(buf,value->green))) |
| … | |
… | |
| 37 | return psiconv_write_u8(buf,value->blue); |
37 | return psiconv_write_u8(buf,value->blue); |
| 38 | } |
38 | } |
| 39 | |
39 | |
| 40 | int psiconv_write_font(psiconv_buffer buf, const psiconv_font value) |
40 | int psiconv_write_font(psiconv_buffer buf, const psiconv_font value) |
| 41 | { |
41 | { |
|
|
42 | int res,i; |
|
|
43 | if (!value) { |
|
|
44 | psiconv_warn(0,psiconv_buffer_length(buf),"Null font"); |
|
|
45 | return -PSICONV_E_GENERATE; |
|
|
46 | } |
|
|
47 | if ((res = psiconv_write_u8(buf,strlen(value->name)+1))) |
|
|
48 | return res; |
|
|
49 | for (i = 0; i < strlen(value->name); i++) |
|
|
50 | if ((res = psiconv_write_u8(buf,value->name[i]))) |
|
|
51 | return res; |
|
|
52 | return psiconv_write_u8(buf,value->screenfont); |
|
|
53 | } |
|
|
54 | |
|
|
55 | int psiconv_write_border(psiconv_buffer buf, const psiconv_border value) |
|
|
56 | { |
| 42 | int res; |
57 | int res; |
| 43 | if (!value) { |
|
|
| 44 | psiconv_warn(0,psiconv_list_length(buf),"Null font"); |
|
|
| 45 | return -PSICONV_E_GENERATE; |
|
|
| 46 | } |
|
|
| 47 | if ((res = psiconv_write_string(buf,value->name))) |
|
|
| 48 | return res; |
|
|
| 49 | return psiconv_write_u8(buf,value->screenfont); |
|
|
| 50 | } |
|
|
| 51 | |
58 | |
| 52 | int psiconv_write_border(psiconv_buffer buf, const psiconv_border value) |
|
|
| 53 | { |
|
|
| 54 | int res; |
|
|
| 55 | |
|
|
| 56 | if (!value) { |
59 | if (!value) { |
| 57 | psiconv_warn(0,psiconv_list_length(buf),"Null border"); |
60 | psiconv_warn(0,psiconv_buffer_length(buf),"Null border"); |
| 58 | return -PSICONV_E_GENERATE; |
61 | return -PSICONV_E_GENERATE; |
| 59 | } |
62 | } |
| 60 | if (value->kind > psiconv_border_dotdotdashed) |
63 | if (value->kind > psiconv_border_dotdotdashed) |
| 61 | psiconv_warn(0,psiconv_list_length(buf), |
64 | psiconv_warn(0,psiconv_buffer_length(buf), |
| 62 | "Unknown border kind (%d); assuming none",value->kind); |
65 | "Unknown border kind (%d); assuming none",value->kind); |
| 63 | if ((res =psiconv_write_u8(buf,value->kind == psiconv_border_none?0: |
66 | if ((res =psiconv_write_u8(buf,value->kind == psiconv_border_none?0: |
| 64 | value->kind == psiconv_border_solid?1: |
67 | value->kind == psiconv_border_solid?1: |
| 65 | value->kind == psiconv_border_double?2: |
68 | value->kind == psiconv_border_double?2: |
| 66 | value->kind == psiconv_border_dotted?3: |
69 | value->kind == psiconv_border_dotted?3: |
| … | |
… | |
| 82 | int psiconv_write_bullet(psiconv_buffer buf, const psiconv_bullet value) |
85 | int psiconv_write_bullet(psiconv_buffer buf, const psiconv_bullet value) |
| 83 | { |
86 | { |
| 84 | int res; |
87 | int res; |
| 85 | psiconv_buffer extra_buf; |
88 | psiconv_buffer extra_buf; |
| 86 | if (!value) { |
89 | if (!value) { |
| 87 | psiconv_warn(0,psiconv_list_length(buf),"Null bullet"); |
90 | psiconv_warn(0,psiconv_buffer_length(buf),"Null bullet"); |
| 88 | return -PSICONV_E_GENERATE; |
91 | return -PSICONV_E_GENERATE; |
| 89 | } |
92 | } |
| 90 | |
93 | |
| 91 | if (!(extra_buf = psiconv_new_buffer())) |
94 | if (!(extra_buf = psiconv_buffer_new())) |
| 92 | return -PSICONV_E_NOMEM; |
95 | return -PSICONV_E_NOMEM; |
| 93 | if ((res = psiconv_write_size(extra_buf,value->font_size))) |
96 | if ((res = psiconv_write_size(extra_buf,value->font_size))) |
| 94 | goto ERROR; |
97 | goto ERROR; |
| 95 | if ((res = psiconv_write_u8(extra_buf,value->character))) |
98 | if ((res = psiconv_write_u8(extra_buf,value->character))) |
| 96 | goto ERROR; |
99 | 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))) |
100 | if ((res = psiconv_write_bool(extra_buf,value->indent))) |
| 100 | goto ERROR; |
101 | goto ERROR; |
| 101 | if ((res = psiconv_write_color(extra_buf,value->color))) |
102 | if ((res = psiconv_write_color(extra_buf,value->color))) |
| 102 | goto ERROR; |
103 | goto ERROR; |
| 103 | if ((res = psiconv_write_font(extra_buf,value->font))) |
104 | if ((res = psiconv_write_font(extra_buf,value->font))) |
| 104 | goto ERROR; |
105 | goto ERROR; |
| 105 | |
106 | |
| 106 | if ((res = psiconv_write_u8(buf,psiconv_list_length(extra_buf)))) |
107 | if ((res = psiconv_write_u8(buf,psiconv_buffer_length(extra_buf)))) |
| 107 | goto ERROR; |
108 | goto ERROR; |
| 108 | res = psiconv_list_concat(buf,extra_buf); |
109 | res = psiconv_buffer_concat(buf,extra_buf); |
| 109 | |
110 | |
| 110 | ERROR: |
111 | ERROR: |
| 111 | psiconv_free_buffer(extra_buf); |
112 | psiconv_buffer_free(extra_buf); |
| 112 | return res; |
113 | return res; |
| 113 | } |
114 | } |
| 114 | |
115 | |
| 115 | int psiconv_write_tab(psiconv_buffer buf,psiconv_tab value) |
116 | int psiconv_write_tab(psiconv_buffer buf,psiconv_tab value) |
| 116 | { |
117 | { |
| 117 | int res; |
118 | int res; |
| 118 | if (!value) { |
119 | if (!value) { |
| 119 | psiconv_warn(0,psiconv_list_length(buf),"Null tab"); |
120 | psiconv_warn(0,psiconv_buffer_length(buf),"Null tab"); |
| 120 | return -PSICONV_E_GENERATE; |
121 | return -PSICONV_E_GENERATE; |
| 121 | } |
122 | } |
| 122 | if ((res = psiconv_write_length(buf,value->location))) |
123 | if ((res = psiconv_write_length(buf,value->location))) |
| 123 | return res; |
124 | return res; |
| 124 | if ((value->kind != psiconv_tab_left) && |
125 | if ((value->kind != psiconv_tab_left) && |
| 125 | (value->kind != psiconv_tab_right) && |
126 | (value->kind != psiconv_tab_right) && |
| 126 | (value->kind != psiconv_tab_centre)) |
127 | (value->kind != psiconv_tab_centre)) |
| 127 | psiconv_warn(0,psiconv_list_length(buf), |
128 | psiconv_warn(0,psiconv_buffer_length(buf), |
| 128 | "Unknown tab kind (%d); assuming left",value->kind); |
129 | "Unknown tab kind (%d); assuming left",value->kind); |
| 129 | return psiconv_write_u8(buf, value->kind == psiconv_tab_right?2: |
130 | return psiconv_write_u8(buf, value->kind == psiconv_tab_right?2: |
| 130 | value->kind == psiconv_tab_centre?3:1); |
131 | value->kind == psiconv_tab_centre?3:1); |
| 131 | } |
132 | } |
| 132 | |
133 | |
| 133 | int psiconv_write_paragraph_layout_list(psiconv_buffer buf, |
134 | int psiconv_write_paragraph_layout_list(psiconv_buffer buf, |
| 134 | psiconv_paragraph_layout value, |
135 | psiconv_paragraph_layout value, |
| 135 | psiconv_paragraph_layout base) |
136 | psiconv_paragraph_layout base) |
| 136 | { |
137 | { |
| 137 | int res,i,tabs_different; |
138 | int res,i; |
| 138 | psiconv_buffer extra_buf; |
139 | psiconv_buffer extra_buf; |
| 139 | psiconv_tab value_tab,base_tab; |
140 | psiconv_tab tab; |
| 140 | |
141 | |
| 141 | if (!value) { |
142 | if (!value) { |
| 142 | psiconv_warn(0,psiconv_list_length(buf),"Null paragraph layout list"); |
143 | psiconv_warn(0,psiconv_buffer_length(buf),"Null paragraph layout list"); |
| 143 | return -PSICONV_E_GENERATE; |
144 | return -PSICONV_E_GENERATE; |
| 144 | } |
145 | } |
| 145 | if (!(extra_buf = psiconv_new_buffer())) |
146 | if (!(extra_buf = psiconv_buffer_new())) |
| 146 | return -PSICONV_E_NOMEM; |
147 | return -PSICONV_E_NOMEM; |
| 147 | |
148 | |
| 148 | if (!base || !base->back_color || !value->back_color || |
149 | if (!base || psiconv_compare_color(base->back_color,value->back_color)) { |
| 149 | (value->back_color->red != base->back_color->red) || |
|
|
| 150 | (value->back_color->green != base->back_color->green) || |
|
|
| 151 | (value->back_color->blue != base->back_color->blue)) { |
|
|
| 152 | if ((res = psiconv_write_u8(extra_buf,0x01))) |
150 | if ((res = psiconv_write_u8(extra_buf,0x01))) |
| 153 | goto ERROR; |
151 | goto ERROR; |
| 154 | if ((res = psiconv_write_color(extra_buf,value->back_color))) |
152 | if ((res = psiconv_write_color(extra_buf,value->back_color))) |
| 155 | goto ERROR; |
153 | goto ERROR; |
| 156 | } |
154 | } |
| … | |
… | |
| 179 | if (!base || (value->justify_hor != base->justify_hor)) { |
177 | if (!base || (value->justify_hor != base->justify_hor)) { |
| 180 | if ((res = psiconv_write_u8(extra_buf,0x05))) |
178 | if ((res = psiconv_write_u8(extra_buf,0x05))) |
| 181 | goto ERROR; |
179 | goto ERROR; |
| 182 | if ((value->justify_hor < psiconv_justify_left) || |
180 | if ((value->justify_hor < psiconv_justify_left) || |
| 183 | (value->justify_hor > psiconv_justify_full)) |
181 | (value->justify_hor > psiconv_justify_full)) |
| 184 | psiconv_warn(0,psiconv_list_length(buf), |
182 | psiconv_warn(0,psiconv_buffer_length(buf), |
| 185 | "Unknown horizontal justify (%d); assuming left", |
183 | "Unknown horizontal justify (%d); assuming left", |
| 186 | value->justify_hor); |
184 | value->justify_hor); |
| 187 | if ((res = psiconv_write_u8(extra_buf, |
185 | if ((res = psiconv_write_u8(extra_buf, |
| 188 | value->justify_hor == psiconv_justify_centre?1: |
186 | value->justify_hor == psiconv_justify_centre?1: |
| 189 | value->justify_hor == psiconv_justify_right?2: |
187 | value->justify_hor == psiconv_justify_right?2: |
| … | |
… | |
| 194 | if (!base || (value->justify_ver != base->justify_ver)) { |
192 | if (!base || (value->justify_ver != base->justify_ver)) { |
| 195 | if ((res = psiconv_write_u8(extra_buf,0x06))) |
193 | if ((res = psiconv_write_u8(extra_buf,0x06))) |
| 196 | goto ERROR; |
194 | goto ERROR; |
| 197 | if ((value->justify_ver < psiconv_justify_top) || |
195 | if ((value->justify_ver < psiconv_justify_top) || |
| 198 | (value->justify_ver > psiconv_justify_bottom)) |
196 | (value->justify_ver > psiconv_justify_bottom)) |
| 199 | psiconv_warn(0,psiconv_list_length(buf), |
197 | psiconv_warn(0,psiconv_buffer_length(buf), |
| 200 | "Unknown vertical justify (%d); assuming middle", |
198 | "Unknown vertical justify (%d); assuming middle", |
| 201 | value->justify_ver); |
199 | value->justify_ver); |
| 202 | if ((res = psiconv_write_u8(extra_buf, |
200 | if ((res = psiconv_write_u8(extra_buf, |
| 203 | value->justify_ver == psiconv_justify_centre?1: |
201 | value->justify_ver == psiconv_justify_centre?1: |
| 204 | value->justify_ver == psiconv_justify_right?2:0))) |
202 | value->justify_ver == psiconv_justify_right?2:0))) |
| … | |
… | |
| 259 | goto ERROR; |
257 | goto ERROR; |
| 260 | if ((res = psiconv_write_bool(extra_buf,value->no_widow_protection))) |
258 | if ((res = psiconv_write_bool(extra_buf,value->no_widow_protection))) |
| 261 | goto ERROR; |
259 | goto ERROR; |
| 262 | } |
260 | } |
| 263 | |
261 | |
|
|
262 | if (!base || (value->wrap_to_fit_cell != base->wrap_to_fit_cell)) { |
|
|
263 | if ((res = psiconv_write_u8(extra_buf,0x0f))) |
|
|
264 | goto ERROR; |
|
|
265 | if ((res = psiconv_write_bool(extra_buf,value->wrap_to_fit_cell))) |
|
|
266 | goto ERROR; |
|
|
267 | } |
|
|
268 | |
| 264 | if (!base || (value->border_distance != base->border_distance)) { |
269 | if (!base || (value->border_distance != base->border_distance)) { |
| 265 | if ((res = psiconv_write_u8(extra_buf,0x10))) |
270 | if ((res = psiconv_write_u8(extra_buf,0x10))) |
| 266 | goto ERROR; |
271 | goto ERROR; |
| 267 | if ((res = psiconv_write_length(extra_buf,value->border_distance))) |
272 | if ((res = psiconv_write_length(extra_buf,value->border_distance))) |
| 268 | goto ERROR; |
273 | goto ERROR; |
| 269 | } |
274 | } |
| 270 | |
275 | |
| 271 | if (!base || !value->top_border || !base->top_border || |
276 | if (!base || psiconv_compare_border(value->top_border,base->top_border)) { |
| 272 | !value->top_border->color || !base->top_border->color || |
|
|
| 273 | (value->top_border->kind != base->top_border->kind) || |
|
|
| 274 | (value->top_border->thickness != base->top_border->thickness) || |
|
|
| 275 | (value->top_border->color->red != base->top_border->color->red) || |
|
|
| 276 | (value->top_border->color->green != base->top_border->color->green) || |
|
|
| 277 | (value->top_border->color->blue != base->top_border->color->blue)) { |
|
|
| 278 | if ((res = psiconv_write_u8(extra_buf,0x11))) |
277 | if ((res = psiconv_write_u8(extra_buf,0x11))) |
| 279 | goto ERROR; |
278 | goto ERROR; |
| 280 | if ((res = psiconv_write_border(extra_buf,value->top_border))) |
279 | if ((res = psiconv_write_border(extra_buf,value->top_border))) |
| 281 | goto ERROR; |
280 | goto ERROR; |
| 282 | } |
281 | } |
| 283 | |
282 | |
| 284 | if (!base || !value->top_border || !base->top_border || |
283 | if (!base || psiconv_compare_border(value->bottom_border, |
| 285 | !value->top_border->color || !base->top_border->color || |
284 | base->bottom_border)) { |
| 286 | (value->top_border->kind != base->top_border->kind) || |
|
|
| 287 | (value->top_border->thickness != base->top_border->thickness) || |
|
|
| 288 | (value->top_border->color->red != base->top_border->color->red) || |
|
|
| 289 | (value->top_border->color->green != base->top_border->color->green) || |
|
|
| 290 | (value->top_border->color->blue != base->top_border->color->blue)) { |
|
|
| 291 | if ((res = psiconv_write_u8(extra_buf,0x12))) |
285 | if ((res = psiconv_write_u8(extra_buf,0x12))) |
| 292 | goto ERROR; |
286 | goto ERROR; |
| 293 | if ((res = psiconv_write_border(extra_buf,value->top_border))) |
287 | if ((res = psiconv_write_border(extra_buf,value->bottom_border))) |
| 294 | goto ERROR; |
288 | goto ERROR; |
| 295 | } |
289 | } |
| 296 | |
290 | |
| 297 | if (!base || !value->left_border || !base->left_border || |
291 | if (!base || psiconv_compare_border(value->left_border, |
| 298 | !value->left_border->color || !base->left_border->color || |
292 | base->left_border)) { |
| 299 | (value->left_border->kind != base->left_border->kind) || |
|
|
| 300 | (value->left_border->thickness != base->left_border->thickness) || |
|
|
| 301 | (value->left_border->color->red != base->left_border->color->red) || |
|
|
| 302 | (value->left_border->color->green != base->left_border->color->green) || |
|
|
| 303 | (value->left_border->color->blue != base->left_border->color->blue)) { |
|
|
| 304 | if ((res = psiconv_write_u8(extra_buf,0x13))) |
293 | if ((res = psiconv_write_u8(extra_buf,0x13))) |
| 305 | goto ERROR; |
294 | goto ERROR; |
| 306 | if ((res = psiconv_write_border(extra_buf,value->left_border))) |
295 | if ((res = psiconv_write_border(extra_buf,value->left_border))) |
| 307 | goto ERROR; |
296 | goto ERROR; |
| 308 | } |
297 | } |
| 309 | |
298 | |
| 310 | if (!base || !value->right_border || !base->right_border || |
299 | if (!base || psiconv_compare_border(value->right_border, |
| 311 | !value->right_border->color || !base->right_border->color || |
|
|
| 312 | (value->right_border->kind != base->right_border->kind) || |
|
|
| 313 | (value->right_border->thickness != base->right_border->thickness) || |
|
|
| 314 | (value->right_border->color->red != base->right_border->color->red) || |
|
|
| 315 | (value->right_border->color->green != |
|
|
| 316 | base->right_border->color->green) || |
300 | base->right_border)) { |
| 317 | (value->right_border->color->blue != base->right_border->color->blue)) { |
|
|
| 318 | if ((res = psiconv_write_u8(extra_buf,0x14))) |
301 | if ((res = psiconv_write_u8(extra_buf,0x14))) |
| 319 | goto ERROR; |
302 | goto ERROR; |
| 320 | if ((res = psiconv_write_border(extra_buf,value->right_border))) |
303 | if ((res = psiconv_write_border(extra_buf,value->right_border))) |
| 321 | goto ERROR; |
304 | goto ERROR; |
| 322 | } |
305 | } |
| 323 | |
306 | |
| 324 | if (!base || !value->bullet || !base->bullet || |
307 | if (!base || psiconv_compare_bullet(value->bullet, |
| 325 | !value->bullet->color || !base->bullet->color || |
308 | base->bullet)) { |
| 326 | !value->bullet->font || !base->bullet->font || |
|
|
| 327 | !value->bullet->font->name || !base->bullet->font->name || |
|
|
| 328 | (value->bullet->on != base->bullet->on) || |
|
|
| 329 | (value->bullet->font_size != base->bullet->font_size) || |
|
|
| 330 | (value->bullet->character != base->bullet->character) || |
|
|
| 331 | (value->bullet->indent != base->bullet->indent) || |
|
|
| 332 | (value->bullet->color->red != base->bullet->color->red) || |
|
|
| 333 | (value->bullet->color->green != base->bullet->color->green) || |
|
|
| 334 | (value->bullet->color->blue != base->bullet->color->blue) || |
|
|
| 335 | (value->bullet->font->screenfont != base->bullet->font->screenfont) || |
|
|
| 336 | strcmp(value->bullet->font->name,base->bullet->font->name)) { |
|
|
| 337 | if ((res = psiconv_write_u8(extra_buf,0x15))) |
309 | if ((res = psiconv_write_u8(extra_buf,0x15))) |
| 338 | goto ERROR; |
310 | goto ERROR; |
| 339 | if ((res = psiconv_write_bullet(extra_buf,value->bullet))) |
311 | if ((res = psiconv_write_bullet(extra_buf,value->bullet))) |
| 340 | goto ERROR; |
312 | goto ERROR; |
| 341 | } |
313 | } |
| 342 | |
314 | |
| 343 | if (!value->tabs || !value->tabs->extras) { |
315 | if (!value->tabs || !value->tabs->extras) { |
| 344 | psiconv_warn(0,psiconv_list_length(buf),"Null tabs"); |
316 | psiconv_warn(0,psiconv_buffer_length(buf),"Null tabs"); |
| 345 | res = -PSICONV_E_GENERATE; |
317 | res = -PSICONV_E_GENERATE; |
| 346 | goto ERROR; |
318 | goto ERROR; |
| 347 | } |
319 | } |
|
|
320 | |
| 348 | /* It is not entirely clear how tabs are inherited. For now, I assume |
321 | /* It is not entirely clear how tabs are inherited. For now, I assume |
| 349 | if there is any difference at all, we will have to generate both |
322 | if there is any difference at all, we will have to generate both |
| 350 | the normal tab-interval, and all specific tabs */ |
323 | the normal tab-interval, and all specific tabs */ |
| 351 | tabs_different = 0; |
324 | if (!base || psiconv_compare_all_tabs(value->tabs,base->tabs)) { |
| 352 | if (!base || !base->tabs || !base->tabs->extras || |
325 | if ((res = psiconv_write_u8(extra_buf,0x16))) |
| 353 | (value->tabs->normal != base->tabs->normal) || |
326 | goto ERROR; |
| 354 | (psiconv_list_length(value->tabs->extras) != |
327 | if ((res = psiconv_write_length(extra_buf,value->tabs->normal))) |
| 355 | psiconv_list_length(base->tabs->extras))) |
328 | goto ERROR; |
| 356 | tabs_different = 1; |
|
|
| 357 | else { |
|
|
| 358 | for (i = 0; i < psiconv_list_length(value->tabs->extras); i++) { |
329 | for (i = 0; i < psiconv_list_length(value->tabs->extras); i++) { |
| 359 | value_tab = psiconv_list_get(value->tabs->extras,i); |
|
|
| 360 | base_tab = psiconv_list_get(base->tabs->extras,i); |
|
|
| 361 | if (!value_tab || !base_tab) { |
|
|
| 362 | psiconv_warn(0,psiconv_list_length(buf),"Massive memory corruption"); |
|
|
| 363 | res = -PSICONV_E_NOMEM; |
|
|
| 364 | goto ERROR; |
|
|
| 365 | } |
|
|
| 366 | if ((value_tab->kind != base_tab->kind) || |
|
|
| 367 | (value_tab->location != base_tab->location)) { |
|
|
| 368 | tabs_different = 1; |
|
|
| 369 | break; |
|
|
| 370 | } |
|
|
| 371 | } |
|
|
| 372 | } |
|
|
| 373 | |
|
|
| 374 | if (tabs_different) { |
|
|
| 375 | if ((res = psiconv_write_u8(extra_buf,0x16))) |
|
|
| 376 | goto ERROR; |
|
|
| 377 | if ((res = psiconv_write_length(extra_buf,value->tabs->normal))) |
|
|
| 378 | goto ERROR; |
|
|
| 379 | for (i = 0; i < psiconv_list_length(value->tabs->extras); i++) { |
|
|
| 380 | if (!(value_tab = psiconv_list_get(value->tabs->extras,i))) { |
330 | if (!(tab = psiconv_list_get(value->tabs->extras,i))) { |
| 381 | psiconv_warn(0,psiconv_list_length(buf),"Massive memory corruption"); |
331 | psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); |
| 382 | res = -PSICONV_E_NOMEM; |
332 | res = -PSICONV_E_NOMEM; |
| 383 | goto ERROR; |
333 | goto ERROR; |
| 384 | } |
334 | } |
| 385 | if ((res = psiconv_write_u8(extra_buf,0x17))) |
335 | if ((res = psiconv_write_u8(extra_buf,0x17))) |
| 386 | goto ERROR; |
336 | goto ERROR; |
| 387 | if ((res = psiconv_write_tab(extra_buf,value_tab))) |
337 | if ((res = psiconv_write_tab(extra_buf,tab))) |
| 388 | goto ERROR; |
338 | goto ERROR; |
| 389 | } |
339 | } |
| 390 | } |
340 | } |
| 391 | |
341 | |
| 392 | if ((res = psiconv_write_u32(buf,psiconv_list_length(extra_buf)))) |
342 | if ((res = psiconv_write_u32(buf,psiconv_buffer_length(extra_buf)))) |
| 393 | goto ERROR; |
343 | goto ERROR; |
| 394 | |
344 | |
| 395 | res = psiconv_list_concat(buf,extra_buf); |
345 | res = psiconv_buffer_concat(buf,extra_buf); |
| 396 | |
346 | |
| 397 | ERROR: |
347 | ERROR: |
| 398 | psiconv_free_buffer(extra_buf); |
348 | psiconv_buffer_free(extra_buf); |
| 399 | return res; |
349 | return res; |
| 400 | } |
350 | } |
| 401 | |
351 | |
| 402 | int psiconv_write_character_layout_list(psiconv_buffer buf, |
352 | int psiconv_write_character_layout_list(psiconv_buffer buf, |
| 403 | psiconv_character_layout value, |
353 | psiconv_character_layout value, |
| 404 | psiconv_character_layout base) |
354 | psiconv_character_layout base) |
| 405 | { |
355 | { |
| 406 | int res; |
356 | int res; |
| 407 | psiconv_buffer extra_buf; |
357 | psiconv_buffer extra_buf; |
| 408 | if (!value) { |
358 | if (!value) { |
| 409 | psiconv_warn(0,psiconv_list_length(buf),"Null character layout list"); |
359 | psiconv_warn(0,psiconv_buffer_length(buf),"Null character layout list"); |
| 410 | return -PSICONV_E_GENERATE; |
360 | return -PSICONV_E_GENERATE; |
| 411 | } |
361 | } |
| 412 | if (!(extra_buf = psiconv_new_buffer())) |
362 | if (!(extra_buf = psiconv_buffer_new())) |
| 413 | return -PSICONV_E_NOMEM; |
363 | return -PSICONV_E_NOMEM; |
| 414 | |
364 | |
| 415 | if (!base || !base->color || !value->color || |
365 | if (!base || psiconv_compare_color(base->color,value->color)) { |
| 416 | (value->color->red != base->color->red) || |
|
|
| 417 | (value->color->green != base->color->green) || |
|
|
| 418 | (value->color->blue != base->color->blue)) { |
|
|
| 419 | if ((res = psiconv_write_u8(extra_buf,0x19))) |
366 | if ((res = psiconv_write_u8(extra_buf,0x19))) |
| 420 | goto ERROR; |
367 | goto ERROR; |
| 421 | if ((res = psiconv_write_color(extra_buf,value->color))) |
368 | if ((res = psiconv_write_color(extra_buf,value->color))) |
| 422 | goto ERROR; |
369 | goto ERROR; |
| 423 | } |
370 | } |
| 424 | |
371 | |
| 425 | if (!base || !base->back_color || !value->back_color || |
372 | if (!base || psiconv_compare_color(base->back_color,value->back_color)) { |
| 426 | (value->back_color->red != base->back_color->red) || |
|
|
| 427 | (value->back_color->green != base->back_color->green) || |
|
|
| 428 | (value->back_color->blue != base->back_color->blue)) { |
|
|
| 429 | if ((res = psiconv_write_u8(extra_buf,0x1a))) |
373 | if ((res = psiconv_write_u8(extra_buf,0x1a))) |
| 430 | goto ERROR; |
374 | goto ERROR; |
| 431 | if ((res = psiconv_write_color(extra_buf,value->back_color))) |
375 | if ((res = psiconv_write_color(extra_buf,value->back_color))) |
| 432 | goto ERROR; |
376 | goto ERROR; |
| 433 | } |
377 | } |
| … | |
… | |
| 455 | |
399 | |
| 456 | if (!base || (value->super_sub != base->super_sub)) { |
400 | if (!base || (value->super_sub != base->super_sub)) { |
| 457 | if ((value->super_sub != psiconv_superscript) && |
401 | if ((value->super_sub != psiconv_superscript) && |
| 458 | (value->super_sub != psiconv_subscript) && |
402 | (value->super_sub != psiconv_subscript) && |
| 459 | (value->super_sub != psiconv_normalscript)) |
403 | (value->super_sub != psiconv_normalscript)) |
| 460 | psiconv_warn(0,psiconv_list_length(buf), |
404 | psiconv_warn(0,psiconv_buffer_length(buf), |
| 461 | "Unknown supersubscript (%d); assuming normal", |
405 | "Unknown supersubscript (%d); assuming normal", |
| 462 | value->super_sub); |
406 | value->super_sub); |
| 463 | if ((res = psiconv_write_u8(extra_buf,0x1f))) |
407 | if ((res = psiconv_write_u8(extra_buf,0x1f))) |
| 464 | goto ERROR; |
408 | goto ERROR; |
| 465 | if ((res = psiconv_write_u8(extra_buf, |
409 | if ((res = psiconv_write_u8(extra_buf, |
| 466 | base->super_sub == psiconv_superscript?1: |
410 | value->super_sub == psiconv_superscript?1: |
| 467 | base->super_sub == psiconv_superscript?2:0))) |
411 | value->super_sub == psiconv_subscript?2:0))) |
| 468 | goto ERROR; |
412 | goto ERROR; |
| 469 | } |
413 | } |
| 470 | |
414 | |
| 471 | if (!base || (value->underline != base->underline)) { |
415 | if (!base || (value->underline != base->underline)) { |
| 472 | if ((res = psiconv_write_u8(extra_buf,0x20))) |
416 | if ((res = psiconv_write_u8(extra_buf,0x20))) |
| … | |
… | |
| 480 | goto ERROR; |
424 | goto ERROR; |
| 481 | if ((res = psiconv_write_bool(extra_buf,value->strikethrough))) |
425 | if ((res = psiconv_write_bool(extra_buf,value->strikethrough))) |
| 482 | goto ERROR; |
426 | goto ERROR; |
| 483 | } |
427 | } |
| 484 | |
428 | |
| 485 | if (!base || !value->font || !base->font || |
429 | if (!base || psiconv_compare_font(base->font,value->font)) { |
| 486 | (value->font->screenfont != base->font->screenfont) || |
|
|
| 487 | strcmp(value->font->name,base->font->name)) { |
|
|
| 488 | if ((res = psiconv_write_u8(extra_buf,0x22))) |
430 | if ((res = psiconv_write_u8(extra_buf,0x22))) |
| 489 | goto ERROR; |
431 | goto ERROR; |
| 490 | if ((res = psiconv_write_font(extra_buf,value->font))) |
432 | if ((res = psiconv_write_font(extra_buf,value->font))) |
| 491 | goto ERROR; |
433 | goto ERROR; |
| 492 | } |
434 | } |
| 493 | |
435 | |
| 494 | if ((res = psiconv_write_u32(buf,psiconv_list_length(extra_buf)))) |
436 | if ((res = psiconv_write_u32(buf,psiconv_buffer_length(extra_buf)))) |
| 495 | goto ERROR; |
437 | goto ERROR; |
| 496 | |
438 | |
| 497 | res = psiconv_list_concat(buf,extra_buf); |
439 | res = psiconv_buffer_concat(buf,extra_buf); |
| 498 | |
440 | |
| 499 | ERROR: |
441 | ERROR: |
| 500 | psiconv_free_buffer(extra_buf); |
442 | psiconv_buffer_free(extra_buf); |
| 501 | return res; |
443 | return res; |
| 502 | } |
444 | } |