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

Legend:
Removed from v.168  
changed lines
  Added in v.233

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