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

Legend:
Removed from v.76  
changed lines
  Added in v.351

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