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

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

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