1 /*
2 Copyright (C) 2020-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5 
6 /*
7 	WARNING: This file was generated by the dkct program (see
8 	http://dktools.sourceforge.net/ for details).
9 	Changes you make here will be lost if dkct is run again!
10 	You should modify the original source and run dkct on it.
11 	Original source: WxdkdrawWrite.cpt
12 */
13 
14 /**	@file WxdkdrawWrite.cpp The WxdkdrawWrite module.
15 */
16 
17 
18 #include <wxdkdraw/wxdkdraw.h>
19 
20 
21 
22 
23 
24 
25 
26 /**	Contant text fragments, not localized.
27 */
28 static char const * const	wxdwr_c8_kw[] = {
29 /* 0 */
30 "\n",
31 
32 /* 1 */
33 " ",
34 
35 /* 2 */
36 "WXD",
37 
38 /* 3 */
39 "0",
40 
41 /* 4 */
42 "1",
43 
44 /* 5 */
45 "0 2 ",
46 
47 /* 6 */
48 "0 4 ",
49 
50 /* 7 */
51 "0 5 1\n",
52 
53 /* 8 */
54 "0 6 1\n",
55 
56 NULL
57 
58 };
59 
60 
61 
62 /**	Indicate error condition in a status structure.
63 	The function does not overwrite existing error conditions,
64 	so the status reports the first error found.
65 	@param	pstat	Status structure to modify.
66 	@param	ec		Error code.
67 	@param	s		String we can not handle.
68 */
69 static
70 void
wxdwr_status_set_error(wxdwr_status_t * pstat,int ec,wxChar * s)71 wxdwr_status_set_error(wxdwr_status_t *pstat, int ec, wxChar *s)
72 {
73 	if (NULL != pstat) {
74 		if (WXDWR_E_NONE == pstat->ec) {
75 			pstat->ec	= ec;
76 			pstat->str	= s;
77 		}
78 	}
79 }
80 
81 
82 
83 /**	Write char string to output file.
84 	@param	fout	Output file.
85 	@param	str		String to write.
86 	@param	bptr	Address of success variable to reset on error.
87 	@param	pstat	Status structure for error notification.
88 */
89 static
90 void
wxdwr_out_string_c8(FILE * fout,char const * str,int * bptr,wxdwr_status_t * pstat)91 wxdwr_out_string_c8(
92 	FILE			*fout,
93 	char const		*str,
94 	int				*bptr,
95 	wxdwr_status_t	*pstat
96 )
97 {
98 	if (EOF == fputs(str, fout)) {
99 		*bptr = 0;
100 		wxdwr_status_set_error(pstat, WXDWR_E_WRITE, NULL);
101 	}
102 }
103 
104 
105 
106 /**	Write unsigned number to output file.
107 	@param	fout	Output file.
108 	@param	um		Unsigned value to write.
109 	@param	bptr	Address of success variable to reset on error.
110 	@param	pstat	Status structure for error notification.
111 */
112 static
113 void
wxdwr_out_unsigned(FILE * fout,dk4_um_t um,int * bptr,wxdwr_status_t * pstat)114 wxdwr_out_unsigned(
115 	FILE			*fout,
116 	dk4_um_t		 um,
117 	int				*bptr,
118 	wxdwr_status_t	*pstat
119 )
120 {
121 	char			buf[16*sizeof(dk4_um_t)];
122 	size_t const	szbuf	= DK4_SIZEOF(buf,char);
123 
124 	(void)dk4ma_write_c8_decimal_unsigned(buf, szbuf, um, 0, NULL);
125 	wxdwr_out_string_c8(fout, buf, bptr, pstat);
126 }
127 
128 
129 
130 /**	Write signed integer value to output file.
131 	@param	fout	Output file.
132 	@param	im		Integer value to write.
133 	@param	bptr	Address of success variable to reset on error.
134 	@param	pstat	Status structure for error notification.
135 */
136 static
137 void
wxdwr_out_signed(FILE * fout,dk4_im_t im,int * bptr,wxdwr_status_t * pstat)138 wxdwr_out_signed(
139 	FILE			*fout,
140 	dk4_im_t		 im,
141 	int				*bptr,
142 	wxdwr_status_t	*pstat
143 )
144 {
145 	char			buf[16*sizeof(dk4_um_t)];
146 	size_t const	szbuf	= DK4_SIZEOF(buf,char);
147 
148 	(void)dk4ma_write_c8_decimal_signed(buf, szbuf, im, 0, NULL);
149 	wxdwr_out_string_c8(fout, buf, bptr, pstat);
150 }
151 
152 
153 
154 /**	Write double value to output file.
155 	@param	fout	Output file.
156 	@param	dbl		Value to write.
157 	@param	bptr	Address of success variable to reset on error.
158 	@param	pstat	Status structure for error notification.
159 */
160 static
161 void
wxdwr_out_double(FILE * fout,double dbl,int * bptr,wxdwr_status_t * pstat)162 wxdwr_out_double(
163 	FILE			*fout,
164 	double			 dbl,
165 	int				*bptr,
166 	wxdwr_status_t	*pstat
167 )
168 {
169 	char			buf[32*sizeof(double)];
170 	size_t const	szbuf	= DK4_SIZEOF(buf,char);
171 
172 	(void)dk4ma_write_c8_double(buf, szbuf, dbl, 0, 1, NULL);
173 	wxdwr_out_string_c8(fout, buf, bptr, pstat);
174 }
175 
176 
177 
178 /**	Write first line for a drawing to output file.
179 	@param	fout	Output file.
180 	@param	pdrw	Drawing.
181 	@param	bptr	Address of success variable to reset on error.
182 	@param	pstat	Status structure for error notification.
183 */
184 static
185 void
wxdwr_write_first_line(FILE * fout,Wxd_drawing_t * pdrw,int * bptr,wxdwr_status_t * pstat)186 wxdwr_write_first_line(
187 	FILE *fout, Wxd_drawing_t *pdrw, int *bptr, wxdwr_status_t *pstat
188 )
189 {
190 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[2], bptr, pstat);
191 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
192 	wxdwr_out_unsigned(fout, pdrw->fv_maj, bptr, pstat);
193 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
194 	wxdwr_out_unsigned(fout, pdrw->fv_min, bptr, pstat);
195 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
196 }
197 
198 
199 
200 /**	Write bounding box for a drawing to output file.
201 	@param	fout	Output file.
202 	@param	pdrw	Drawing.
203 	@param	bptr	Address of success variable to reset on error.
204 	@param	pstat	Status structure for error notification.
205 */
206 static
207 void
wxdwr_write_bounding_box(FILE * fout,Wxd_drawing_t * pdrw,int * bptr,wxdwr_status_t * pstat)208 wxdwr_write_bounding_box(
209 	FILE			*fout,
210 	Wxd_drawing_t	*pdrw,
211 	int				*bptr,
212 	wxdwr_status_t	*pstat
213 )
214 {
215 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[3], bptr, pstat);
216 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
217 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[3], bptr, pstat);
218 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
219 	wxdwr_out_signed(fout, (pdrw->bb).xl, bptr, pstat);
220 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
221 	wxdwr_out_signed(fout, (pdrw->bb).xr, bptr, pstat);
222 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
223 	wxdwr_out_signed(fout, (pdrw->bb).yb, bptr, pstat);
224 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
225 	wxdwr_out_signed(fout, (pdrw->bb).yt, bptr, pstat);
226 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
227 }
228 
229 
230 
231 /**	Write base line width for a drawing to output file if necessary.
232 	@param	fout	Output file.
233 	@param	pdrw	Drawing.
234 	@param	bptr	Address of success variable to reset on error.
235 	@param	pstat	Status structure for error notification.
236 */
237 static
238 void
wxdwr_write_base_line_width(FILE * fout,Wxd_drawing_t * pdrw,int * bptr,wxdwr_status_t * pstat)239 wxdwr_write_base_line_width(
240 	FILE			*fout,
241 	Wxd_drawing_t	*pdrw,
242 	int				*bptr,
243 	wxdwr_status_t	*pstat
244 )
245 {
246 	if (101600UL != (unsigned long)(pdrw->baselw)) {
247 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[3], bptr, pstat);
248 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
249 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[4], bptr, pstat);
250 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
251 		wxdwr_out_unsigned(fout, pdrw->baselw, bptr, pstat);
252 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
253 	}
254 }
255 
256 
257 
258 /**	Write zoom level for a drawing to output file if necessary.
259 	@param	fout	Output file.
260 	@param	pdrw	Drawing.
261 	@param	bptr	Address of success variable to reset on error.
262 	@param	pstat	Status structure for error notification.
263 */
264 static
265 void
wxdwr_write_zoom_level(FILE * fout,Wxd_drawing_t * pdrw,int * bptr,wxdwr_status_t * pstat)266 wxdwr_write_zoom_level(
267 	FILE			*fout,
268 	Wxd_drawing_t	*pdrw,
269 	int				*bptr,
270 	wxdwr_status_t	*pstat
271 )
272 {
273 	if (0 != (int)(pdrw->zl)) {
274 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[5], bptr, pstat);
275 		wxdwr_out_signed(fout, pdrw->zl, bptr, pstat);
276 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
277 	}
278 }
279 
280 
281 
282 /**	Write grid unit and grid base for a drawing to output file if necessary.
283 	@param	fout	Output file.
284 	@param	pdrw	Drawing.
285 	@param	bptr	Address of success variable to reset on error.
286 	@param	pstat	Status structure for error notification.
287 */
288 static
289 void
wxdwr_write_grid_unit_and_base(FILE * fout,Wxd_drawing_t * pdrw,int * bptr,wxdwr_status_t * pstat)290 wxdwr_write_grid_unit_and_base(
291 	FILE			*fout,
292 	Wxd_drawing_t	*pdrw,
293 	int				*bptr,
294 	wxdwr_status_t	*pstat
295 )
296 {
297 	if ((uint8_t)0U != pdrw->gridunit) {
298 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[7], bptr, pstat);
299 	}
300 	if ((uint8_t)0U != pdrw->gridbase) {
301 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[8], bptr, pstat);
302 	}
303 }
304 
305 
306 
307 /**	Write 5 style attributes for a graphics object to file.
308 	@param	fout	Output file.
309 	@param	pdrw	Drawing.
310 	@param	pobj	Object to handle.
311 	@param	bptr	Address of success variable to reset on error.
312 	@param	pstat	Status structure for error notification.
313 */
314 static
315 void
wxdwr_write_elements_05(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)316 wxdwr_write_elements_05(
317 	FILE			*fout,
318 	Wxd_object_t	*pobj,
319 	int				*bptr,
320 	wxdwr_status_t	*pstat
321 )
322 {
323 	wxdwr_out_signed(fout, pobj->ot, bptr, pstat);
324 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
325 	wxdwr_out_signed(fout, pobj->lay, bptr, pstat);
326 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
327 	switch ( (int)(pobj->ot) ) {
328 		case WXD_OT_DOT_WHITE :
329 		case WXD_OT_DOT_FILLED :
330 		case WXD_OT_TEXT :
331 		{
332 			wxdwr_out_unsigned(fout, pobj->sc[0], bptr, pstat);
333 			wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
334 			wxdwr_out_unsigned(fout, pobj->sc[1], bptr, pstat);
335 			wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
336 			wxdwr_out_unsigned(fout, pobj->sc[2], bptr, pstat);
337 		} break;
338 		default : {
339 			wxdwr_out_unsigned(fout, pobj->fc[0], bptr, pstat);
340 			wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
341 			wxdwr_out_unsigned(fout, pobj->fc[1], bptr, pstat);
342 			wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
343 			wxdwr_out_unsigned(fout, pobj->fc[2], bptr, pstat);
344 		} break;
345 	}
346 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
347 }
348 
349 
350 
351 /**	Write 12 style attributes for a graphics object to file.
352 	@param	fout	Output file.
353 	@param	pdrw	Drawing.
354 	@param	pobj	Object to handle.
355 	@param	bptr	Address of success variable to reset on error.
356 	@param	pstat	Status structure for error notification.
357 */
358 static
359 void
wxdwr_write_elements_12(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)360 wxdwr_write_elements_12(
361 	FILE			*fout,
362 	Wxd_object_t	*pobj,
363 	int				*bptr,
364 	wxdwr_status_t	*pstat
365 )
366 {
367 	/* object type */
368 	wxdwr_out_signed(fout, pobj->ot, bptr, pstat);
369 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
370 	/* layer */
371 	wxdwr_out_signed(fout, pobj->lay, bptr, pstat);
372 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
373 	/* stroke red */
374 	wxdwr_out_unsigned(fout, pobj->sc[0], bptr, pstat);
375 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
376 	/* stroke green */
377 	wxdwr_out_unsigned(fout, pobj->sc[1], bptr, pstat);
378 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
379 	/* stroke blue */
380 	wxdwr_out_unsigned(fout, pobj->sc[2], bptr, pstat);
381 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
382 	/* fill red */
383 	wxdwr_out_unsigned(fout, pobj->fc[0], bptr, pstat);
384 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
385 	/* fill green */
386 	wxdwr_out_unsigned(fout, pobj->fc[1], bptr, pstat);
387 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
388 	/* fill blue */
389 	wxdwr_out_unsigned(fout, pobj->fc[2], bptr, pstat);
390 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
391 	/* line width */
392 	wxdwr_out_unsigned(fout, pobj->lw, bptr, pstat);
393 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
394 	/* line style */
395 	wxdwr_out_unsigned(fout, pobj->ls, bptr, pstat);
396 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
397 	/* style value */
398 	wxdwr_out_unsigned(fout, pobj->sl, bptr, pstat);
399 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
400 	/* fill style */
401 	wxdwr_out_unsigned(fout, pobj->fs, bptr, pstat);
402 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
403 }
404 
405 
406 
407 /**	Write 15 style attributes for a graphics object to file.
408 	@param	fout	Output file.
409 	@param	pdrw	Drawing.
410 	@param	pobj	Object to handle.
411 	@param	bptr	Address of success variable to reset on error.
412 	@param	pstat	Status structure for error notification.
413 */
414 static
415 void
wxdwr_write_elements_15(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)416 wxdwr_write_elements_15(
417 	FILE			*fout,
418 	Wxd_object_t	*pobj,
419 	int				*bptr,
420 	wxdwr_status_t	*pstat
421 )
422 {
423 	/* object type */
424 	wxdwr_out_signed(fout, pobj->ot, bptr, pstat);
425 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
426 	/* number of points */
427 	switch ( (int)(pobj->ot) ) {
428 		case WXD_OT_POLYLINE : case WXD_OT_POLYGON : {
429 			wxdwr_out_unsigned(fout, (pobj->det).p.n, bptr, pstat);
430 		} break;
431 		default : {
432 			wxdwr_out_unsigned(fout, (pobj->det).s.n, bptr, pstat);
433 		} break;
434 	}
435 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
436 	/* layer */
437 	wxdwr_out_signed(fout, pobj->lay, bptr, pstat);
438 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
439 	/* stroke red */
440 	wxdwr_out_unsigned(fout, pobj->sc[0], bptr, pstat);
441 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
442 	/* stroke green */
443 	wxdwr_out_unsigned(fout, pobj->sc[1], bptr, pstat);
444 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
445 	/* stroke blue */
446 	wxdwr_out_unsigned(fout, pobj->sc[2], bptr, pstat);
447 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
448 	/* fill red */
449 	wxdwr_out_unsigned(fout, pobj->fc[0], bptr, pstat);
450 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
451 	/* fill green */
452 	wxdwr_out_unsigned(fout, pobj->fc[1], bptr, pstat);
453 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
454 	/* fill blue */
455 	wxdwr_out_unsigned(fout, pobj->fc[2], bptr, pstat);
456 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
457 	/* line width */
458 	wxdwr_out_unsigned(fout, pobj->lw, bptr, pstat);
459 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
460 	/* line style */
461 	wxdwr_out_unsigned(fout, pobj->ls, bptr, pstat);
462 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
463 	/* style value */
464 	wxdwr_out_unsigned(fout, pobj->sl, bptr, pstat);
465 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
466 	/* join style */
467 	wxdwr_out_unsigned(fout, pobj->js, bptr, pstat);
468 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
469 	/* miter limit */
470 	wxdwr_out_unsigned(fout, pobj->ml, bptr, pstat);
471 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
472 	/* fill style */
473 	wxdwr_out_unsigned(fout, pobj->fs, bptr, pstat);
474 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
475 }
476 
477 
478 
479 /**	Write 18 style attributes for a graphics object to file.
480 	@param	fout	Output file.
481 	@param	pdrw	Drawing.
482 	@param	pobj	Object to handle.
483 	@param	bptr	Address of success variable to reset on error.
484 	@param	pstat	Status structure for error notification.
485 */
486 static
487 void
wxdwr_write_elements_18(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)488 wxdwr_write_elements_18(
489 	FILE			*fout,
490 	Wxd_object_t	*pobj,
491 	int				*bptr,
492 	wxdwr_status_t	*pstat
493 )
494 {
495 	/* object type */
496 	wxdwr_out_signed(fout, pobj->ot, bptr, pstat);
497 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
498 	/* number of points */
499 	switch ( (int)(pobj->ot) ) {
500 		case WXD_OT_POLYLINE : case WXD_OT_POLYGON : {
501 			wxdwr_out_unsigned(fout, (pobj->det).p.n, bptr, pstat);
502 		} break;
503 		default : {
504 			wxdwr_out_unsigned(fout, (pobj->det).s.n, bptr, pstat);
505 		} break;
506 	}
507 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
508 	/* layer */
509 	wxdwr_out_signed(fout, pobj->lay, bptr, pstat);
510 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
511 	/* stroke red */
512 	wxdwr_out_unsigned(fout, pobj->sc[0], bptr, pstat);
513 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
514 	/* stroke green */
515 	wxdwr_out_unsigned(fout, pobj->sc[1], bptr, pstat);
516 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
517 	/* stroke blue */
518 	wxdwr_out_unsigned(fout, pobj->sc[2], bptr, pstat);
519 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
520 	/* line width */
521 	wxdwr_out_unsigned(fout, pobj->lw, bptr, pstat);
522 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
523 	/* line style */
524 	wxdwr_out_unsigned(fout, pobj->ls, bptr, pstat);
525 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
526 	/* style value */
527 	wxdwr_out_unsigned(fout, pobj->sl, bptr, pstat);
528 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
529 	/* cap style */
530 	wxdwr_out_unsigned(fout, pobj->cs, bptr, pstat);
531 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
532 	/* join style */
533 	wxdwr_out_unsigned(fout, pobj->js, bptr, pstat);
534 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
535 	/* miter limit */
536 	wxdwr_out_unsigned(fout, pobj->ml, bptr, pstat);
537 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
538 	/* arrow type */
539 	wxdwr_out_unsigned(fout, pobj->aft, bptr, pstat);
540 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
541 	/* arrow length */
542 	wxdwr_out_unsigned(fout, pobj->afl, bptr, pstat);
543 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
544 	/* arrow width */
545 	wxdwr_out_unsigned(fout, pobj->afw, bptr, pstat);
546 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
547 	/* arrow type */
548 	wxdwr_out_unsigned(fout, pobj->abt, bptr, pstat);
549 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
550 	/* arrow length */
551 	wxdwr_out_unsigned(fout, pobj->abl, bptr, pstat);
552 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
553 	/* arrow width */
554 	wxdwr_out_unsigned(fout, pobj->abw, bptr, pstat);
555 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
556 }
557 
558 
559 
560 /**	Write text label to output file.
561 	@param	fout	Output file.
562 	@param	pdrw	Drawing.
563 	@param	pobj	Object to handle.
564 	@param	bptr	Address of success variable to reset on error.
565 	@param	pstat	Status structure for error notification.
566 */
567 static
568 void
wxdwr_write_text_label(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)569 wxdwr_write_text_label(
570 	FILE			*fout,
571 	Wxd_object_t	*pobj,
572 	int				*bptr,
573 	wxdwr_status_t	*pstat
574 )
575 {
576 	char			bte[1024];
577 	char			bts[1024];
578 	size_t const	szbte	= DK4_SIZEOF(bte,char);
579 	size_t const	szbts	= DK4_SIZEOF(bts,char);
580 	int				canrun	=	1;
581 	int				res;
582 
583 #if	0
584 	/*	2020-03-24	Modification
585 		Turned into an initialization due to clang static analyzers
586 		complaints about dead assignment.
587 	*/
588 	canrun = 1;
589 #endif
590 	bte[0] = '\0';
591 	bts[0] = '\0';
592 	if (NULL != (pobj->det).t.t) {
593 		res = dk4recwx_wxchar_to_char(
594 			bte, szbte, DK4_ENCODING_UTF8, (pobj->det).t.t, pstat->wxe, NULL
595 		);
596 		if (0 != res) {
597 			if (1022 > strlen(bte)) {
598 				canrun = 1;
599 				if (NULL != (pobj->det).t.tsc) {
600 					res = dk4recwx_wxchar_to_char(
601 						bts, szbts, DK4_ENCODING_UTF8, (pobj->det).t.tsc,
602 						pstat->wxe, NULL
603 					);
604 					if (0 != res) {
605 						if (1021 < strlen(bts)) {
606 							canrun = 0;
607 							/* ERROR: String too long */
608 							wxdwr_status_set_error(
609 								pstat, WXDWR_E_STRING_TOO_LONG, (pobj->det).t.t
610 							);
611 						}
612 					}
613 					else {
614 						canrun = 0;
615 						/* ERROR: Encoding failed */
616 						wxdwr_status_set_error(
617 							pstat, WXDWR_E_RECODE_TEXT, (pobj->det).t.t
618 						);
619 					}
620 				}
621 				if (0 != canrun) {
622 					wxdwr_write_elements_05(fout, pobj, bptr, pstat);
623 					wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
624 					wxdwr_out_unsigned(fout, (pobj->det).t.find, bptr, pstat);
625 					wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
626 					wxdwr_out_unsigned(fout, (pobj->det).t.fsz, bptr, pstat);
627 					wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
628 					wxdwr_out_unsigned(fout, (pobj->det).t.al, bptr, pstat);
629 					wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
630 					wxdwr_out_unsigned(fout, (pobj->det).t.fl, bptr, pstat);
631 					wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
632 					wxdwr_out_signed(fout, (pobj->det).t.x, bptr, pstat);
633 					wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
634 					wxdwr_out_signed(fout, (pobj->det).t.y, bptr, pstat);
635 					wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
636 					wxdwr_out_signed(fout, (pobj->det).t.a, bptr, pstat);
637 					wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
638 					wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
639 					wxdwr_out_string_c8(fout, bte, bptr, pstat);
640 					wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
641 					wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
642 					if (NULL != (pobj->det).t.tsc) {
643 						wxdwr_out_string_c8(fout, bts, bptr, pstat);
644 					}
645 					wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
646 				}
647 			}
648 			else {
649 				/* ERROR: String too long */
650 				wxdwr_status_set_error(
651 					pstat, WXDWR_E_STRING_TOO_LONG, (pobj->det).t.t
652 				);
653 			}
654 		}
655 		else {
656 			/* ERROR: Encoding failed */
657 			wxdwr_status_set_error(pstat, WXDWR_E_RECODE_TEXT, (pobj->det).t.t);
658 		}
659 	}
660 	else {
661 		/* ERROR: No text. */
662 		wxdwr_status_set_error(pstat, WXDWR_E_STRING_EMPTY, NULL);
663 	}
664 }
665 
666 
667 
668 /**	Write polygon or polyline to output file.
669 	@param	fout	Output file.
670 	@param	pdrw	Drawing.
671 	@param	pobj	Object to handle.
672 	@param	bptr	Address of success variable to reset on error.
673 	@param	pstat	Status structure for error notification.
674 */
675 static
676 void
wxdwr_write_polyline(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)677 wxdwr_write_polyline(
678 	FILE			*fout,
679 	Wxd_object_t	*pobj,
680 	int				*bptr,
681 	wxdwr_status_t	*pstat
682 )
683 {
684 	uint16_t	u;
685 	if (WXD_OT_POLYLINE == pobj->ot) {
686 		wxdwr_write_elements_18(fout, pobj, bptr, pstat);
687 	}
688 	else {
689 		wxdwr_write_elements_15(fout, pobj, bptr, pstat);
690 	}
691 	for (u = 0; u < (pobj->det).p.n; u++) {
692 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
693 		wxdwr_out_signed(fout, ((pobj->det).p.p)[u].x, bptr, pstat);
694 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
695 		wxdwr_out_signed(fout, ((pobj->det).p.p)[u].y, bptr, pstat);
696 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
697 	}
698 }
699 
700 
701 
702 /**	Write spline to output file.
703 	@param	fout	Output file.
704 	@param	pdrw	Drawing.
705 	@param	pobj	Object to handle.
706 	@param	bptr	Address of success variable to reset on error.
707 	@param	pstat	Status structure for error notification.
708 */
709 static
710 void
wxdwr_write_spline(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)711 wxdwr_write_spline(
712 	FILE			*fout,
713 	Wxd_object_t	*pobj,
714 	int				*bptr,
715 	wxdwr_status_t	*pstat
716 )
717 {
718 	uint16_t	u;
719 	if (WXD_OT_O_SPLINE == pobj->ot) {
720 		wxdwr_write_elements_18(fout, pobj, bptr, pstat);
721 	}
722 	else {
723 		wxdwr_write_elements_15(fout, pobj, bptr, pstat);
724 	}
725 	for (u = 0; u < (pobj->det).s.n; u++) {
726 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
727 		wxdwr_out_signed(fout, ((pobj->det).s.p)[u].x, bptr, pstat);
728 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
729 		wxdwr_out_signed(fout, ((pobj->det).s.p)[u].y, bptr, pstat);
730 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
731 		wxdwr_out_double(fout, ((pobj->det).s.p)[u].s, bptr, pstat);
732 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
733 	}
734 }
735 
736 
737 
738 /**	Write arc to output file.
739 	@param	fout	Output file.
740 	@param	pdrw	Drawing.
741 	@param	pobj	Object to handle.
742 	@param	bptr	Address of success variable to reset on error.
743 	@param	pstat	Status structure for error notification.
744 */
745 static
746 void
wxdwr_write_arc(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)747 wxdwr_write_arc(
748 	FILE			*fout,
749 	Wxd_object_t	*pobj,
750 	int				*bptr,
751 	wxdwr_status_t	*pstat
752 )
753 {
754 	/* object type */
755 	wxdwr_out_signed(fout, pobj->ot, bptr, pstat);
756 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
757 	/* layer */
758 	wxdwr_out_signed(fout, pobj->lay, bptr, pstat);
759 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
760 	/* stroke red */
761 	wxdwr_out_unsigned(fout, pobj->sc[0], bptr, pstat);
762 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
763 	/* stroke green */
764 	wxdwr_out_unsigned(fout, pobj->sc[1], bptr, pstat);
765 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
766 	/* stroke blue */
767 	wxdwr_out_unsigned(fout, pobj->sc[2], bptr, pstat);
768 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
769 	if (WXD_OT_O_ARC == pobj->ot) {
770 		/* line width */
771 		wxdwr_out_unsigned(fout, pobj->lw, bptr, pstat);
772 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
773 		/* line style */
774 		wxdwr_out_unsigned(fout, pobj->ls, bptr, pstat);
775 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
776 		/* style value */
777 		wxdwr_out_unsigned(fout, pobj->sl, bptr, pstat);
778 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
779 		/* cap style */
780 		wxdwr_out_unsigned(fout, pobj->cs, bptr, pstat);
781 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
782 		/* arrow type */
783 		wxdwr_out_unsigned(fout, pobj->aft, bptr, pstat);
784 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
785 		/* arrow length */
786 		wxdwr_out_unsigned(fout, pobj->afl, bptr, pstat);
787 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
788 		/* arrow width */
789 		wxdwr_out_unsigned(fout, pobj->afw, bptr, pstat);
790 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
791 		/* arrow type */
792 		wxdwr_out_unsigned(fout, pobj->abt, bptr, pstat);
793 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
794 		/* arrow length */
795 		wxdwr_out_unsigned(fout, pobj->abl, bptr, pstat);
796 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
797 		/* arrow width */
798 		wxdwr_out_unsigned(fout, pobj->abw, bptr, pstat);
799 	}
800 	else {
801 		/* fill red */
802 		wxdwr_out_unsigned(fout, pobj->fc[0], bptr, pstat);
803 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
804 		/* fill green */
805 		wxdwr_out_unsigned(fout, pobj->fc[1], bptr, pstat);
806 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
807 		/* fill blue */
808 		wxdwr_out_unsigned(fout, pobj->fc[2], bptr, pstat);
809 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
810 		/* line width */
811 		wxdwr_out_unsigned(fout, pobj->lw, bptr, pstat);
812 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
813 		/* line style */
814 		wxdwr_out_unsigned(fout, pobj->ls, bptr, pstat);
815 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
816 		/* style value */
817 		wxdwr_out_unsigned(fout, pobj->sl, bptr, pstat);
818 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
819 		/* join style */
820 		wxdwr_out_unsigned(fout, pobj->js, bptr, pstat);
821 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
822 		/* miter limit */
823 		wxdwr_out_unsigned(fout, pobj->ml, bptr, pstat);
824 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
825 		/* fill style */
826 		wxdwr_out_unsigned(fout, pobj->fs, bptr, pstat);
827 	}
828 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
829 	/* second line: 3 point coordinates */
830 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
831 	wxdwr_out_signed(fout, (pobj->det).a.x1, bptr, pstat);
832 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
833 	wxdwr_out_signed(fout, (pobj->det).a.y1, bptr, pstat);
834 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
835 	wxdwr_out_signed(fout, (pobj->det).a.x2, bptr, pstat);
836 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
837 	wxdwr_out_signed(fout, (pobj->det).a.y2, bptr, pstat);
838 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
839 	wxdwr_out_signed(fout, (pobj->det).a.x3, bptr, pstat);
840 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
841 	wxdwr_out_signed(fout, (pobj->det).a.y3, bptr, pstat);
842 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
843 }
844 
845 
846 
847 /**	Write circle to output file.
848 	@param	fout	Output file.
849 	@param	pdrw	Drawing.
850 	@param	pobj	Object to handle.
851 	@param	bptr	Address of success variable to reset on error.
852 	@param	pstat	Status structure for error notification.
853 */
854 static
855 void
wxdwr_write_circle(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)856 wxdwr_write_circle(
857 	FILE			*fout,
858 	Wxd_object_t	*pobj,
859 	int				*bptr,
860 	wxdwr_status_t	*pstat
861 )
862 {
863 	wxdwr_write_elements_12(fout, pobj, bptr, pstat);
864 	/* Second line */
865 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
866 	wxdwr_out_signed(fout, (pobj->det).e.x, bptr, pstat);
867 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
868 	wxdwr_out_signed(fout, (pobj->det).e.y, bptr, pstat);
869 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
870 	wxdwr_out_unsigned(fout, (pobj->det).e.rx, bptr, pstat);
871 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
872 }
873 
874 
875 
876 /**	Write ellipse to output file.
877 	@param	fout	Output file.
878 	@param	pdrw	Drawing.
879 	@param	pobj	Object to handle.
880 	@param	bptr	Address of success variable to reset on error.
881 	@param	pstat	Status structure for error notification.
882 */
883 static
884 void
wxdwr_write_ellipse(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)885 wxdwr_write_ellipse(
886 	FILE			*fout,
887 	Wxd_object_t	*pobj,
888 	int				*bptr,
889 	wxdwr_status_t	*pstat
890 )
891 {
892 	wxdwr_write_elements_12(fout, pobj, bptr, pstat);
893 	/* Second line */
894 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
895 	wxdwr_out_signed(fout, (pobj->det).e.x, bptr, pstat);
896 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
897 	wxdwr_out_signed(fout, (pobj->det).e.y, bptr, pstat);
898 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
899 	wxdwr_out_unsigned(fout, (pobj->det).e.rx, bptr, pstat);
900 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
901 	wxdwr_out_unsigned(fout, (pobj->det).e.ry, bptr, pstat);
902 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
903 	wxdwr_out_signed(fout, (pobj->det).e.a, bptr, pstat);
904 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
905 }
906 
907 
908 
909 /**	Write box to output file.
910 	@param	fout	Output file.
911 	@param	pdrw	Drawing.
912 	@param	pobj	Object to handle.
913 	@param	bptr	Address of success variable to reset on error.
914 	@param	pstat	Status structure for error notification.
915 */
916 static
917 void
wxdwr_write_box(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)918 wxdwr_write_box(
919 	FILE			*fout,
920 	Wxd_object_t	*pobj,
921 	int				*bptr,
922 	wxdwr_status_t	*pstat
923 )
924 {
925 	wxdwr_write_elements_12(fout, pobj, bptr, pstat);
926 	/* Second line */
927 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
928 	wxdwr_out_signed(fout, (pobj->det).b.b.xl, bptr, pstat);
929 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
930 	wxdwr_out_signed(fout, (pobj->det).b.b.xr, bptr, pstat);
931 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
932 	wxdwr_out_signed(fout, (pobj->det).b.b.yb, bptr, pstat);
933 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
934 	wxdwr_out_signed(fout, (pobj->det).b.b.yt, bptr, pstat);
935 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
936 	wxdwr_out_unsigned(fout, (pobj->det).b.r, bptr, pstat);
937 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
938 }
939 
940 
941 
942 /**	Calculate difference of 2 int32_t values as uint32_t value.
943 	@param	xl	Smaller number.
944 	@param	xr	Larger number.
945 	@return	Result (large - small number).
946 */
947 static
948 uint32_t
wxdwr_diff_signed(int32_t xl,int32_t xr)949 wxdwr_diff_signed(int32_t xl, int32_t xr)
950 {
951 	dk4_er_t		 er;
952 	uint32_t		 back = 0UL;
953 	int32_t			 axl;
954 	if (0L <= xr) {
955 		if (0L <= xl) {
956 			back = (uint32_t)(xr - xl);
957 		}
958 		else {
959 			dk4error_init(&er);
960 			axl = dk4ma_int32_t_abs(xl, &er);
961 			if (DK4_E_NONE == er.ec) {
962 				back = (uint32_t)xr + (uint32_t)axl;
963 			}
964 			else {
965 				back = (uint32_t)xr + (uint32_t)(DK4_I32_MAX) + (uint32_t)1UL;
966 			}
967 		}
968 	}
969 	else {
970 		if (0L <= xl) {
971 			back = wxdwr_diff_signed(xr, xl);
972 		}
973 		else {
974 			back = (uint32_t)(xr - xl);
975 		}
976 	}
977 	return back;
978 }
979 
980 
981 
982 /**	Write image object to output file.
983 	@param	fout	Output file.
984 	@param	pdrw	Drawing.
985 	@param	pobj	Object to handle.
986 	@param	bptr	Address of success variable to reset on error.
987 	@param	pstat	Status structure for error notification.
988 */
989 static
990 void
wxdwr_write_image(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)991 wxdwr_write_image(
992 	FILE			*fout,
993 	Wxd_object_t	*pobj,
994 	int				*bptr,
995 	wxdwr_status_t	*pstat
996 )
997 {
998 	char			 bfn[1024];
999 	wxChar			*fnco;			/* File name to convert */
1000 	size_t const	 szbfn	= DK4_SIZEOF(bfn,char);
1001 	int32_t			 x;
1002 	int32_t			 y;
1003 	uint32_t		 w;
1004 	uint32_t		 h;
1005 	int				 res;
1006 
1007 	if (NULL != (pobj->det).i.fn) {
1008 		fnco = (pobj->det).i.fn;
1009 #if	TRACE_DEBUG
1010 #if	DK4_SIZEOF_WXCHAR > 1
1011 
1012 #else
1013 
1014 #endif
1015 #endif
1016 		if (NULL != pstat->dirn) {
1017 			if (0 != dk4strx_path_is_in_subdir(fnco, pstat->dirn, NULL)) {
1018 				fnco = &(fnco[dk4strx_len(pstat->dirn) + (size_t)1U]);
1019 			}
1020 		}
1021 #if	TRACE_DEBUG
1022 #if	DK4_SIZEOF_WXCHAR > 1
1023 
1024 #else
1025 
1026 #endif
1027 #endif
1028 		res = dk4recwx_wxchar_to_char(
1029 			bfn, szbfn, DK4_ENCODING_UTF8, fnco, pstat->wxe, NULL
1030 		);
1031 		if (0 != res) {
1032 			if (1022 > strlen(bfn)) {
1033 				if ((pobj->det).i.br.xr >= (pobj->det).i.br.xl) {
1034 					x = (pobj->det).i.br.xl;
1035 					w = wxdwr_diff_signed(
1036 						(pobj->det).i.br.xl, (pobj->det).i.br.xr
1037 					);
1038 				}
1039 				else {
1040 					x = (pobj->det).i.br.xr;
1041 					w = wxdwr_diff_signed(
1042 						(pobj->det).i.br.xr, (pobj->det).i.br.xl
1043 					);
1044 				}
1045 				if ((pobj->det).i.br.yt >= (pobj->det).i.br.yb) {
1046 					y = (pobj->det).i.br.yb;
1047 					h = wxdwr_diff_signed(
1048 						(pobj->det).i.br.yb, (pobj->det).i.br.yt
1049 					);
1050 				}
1051 				else {
1052 					y = (pobj->det).i.br.yt;
1053 					h = wxdwr_diff_signed(
1054 						(pobj->det).i.br.yt, (pobj->det).i.br.yb
1055 					);
1056 				}
1057 				/* First line */
1058 				wxdwr_write_elements_05(fout, pobj, bptr, pstat);
1059 				/* Second line */
1060 				wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
1061 				/* flags */
1062 				wxdwr_out_unsigned(fout, (pobj->det).i.fl, bptr, pstat);
1063 				wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
1064 				/* rgb2gray */
1065 				wxdwr_out_signed(fout, (pobj->det).i.r2g, bptr, pstat);
1066 				wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
1067 				/* rgb2cmyk */
1068 				wxdwr_out_signed(fout, (pobj->det).i.r2c, bptr, pstat);
1069 				wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
1070 				/* x */
1071 				wxdwr_out_signed(fout, x, bptr, pstat);
1072 				wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
1073 				/* y */
1074 				wxdwr_out_signed(fout, y, bptr, pstat);
1075 				wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
1076 				/* w */
1077 				wxdwr_out_signed(fout, w, bptr, pstat);
1078 				wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
1079 				/* h */
1080 				wxdwr_out_signed(fout, h, bptr, pstat);
1081 				wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
1082 				/* Third line */
1083 				wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
1084 				wxdwr_out_string_c8(fout, bfn, bptr, pstat);
1085 				wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
1086 			}
1087 			else {
1088 				wxdwr_status_set_error(
1089 					pstat, WXDWR_E_STRING_TOO_LONG, (pobj->det).i.fn
1090 				);
1091 			}
1092 		}
1093 		else {
1094 			wxdwr_status_set_error(
1095 				pstat, WXDWR_E_RECODE_FILENAME, (pobj->det).i.fn
1096 			);
1097 		}
1098 	}
1099 	else {
1100 	}
1101 
1102 }
1103 
1104 
1105 
1106 /**	Write dot to output file.
1107 	@param	fout	Output file.
1108 	@param	pdrw	Drawing.
1109 	@param	pobj	Object to handle.
1110 	@param	bptr	Address of success variable to reset on error.
1111 	@param	pstat	Status structure for error notification.
1112 */
1113 static
1114 void
wxdwr_write_dot(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)1115 wxdwr_write_dot(
1116 	FILE			*fout,
1117 	Wxd_object_t	*pobj,
1118 	int				*bptr,
1119 	wxdwr_status_t	*pstat
1120 )
1121 {
1122 	wxdwr_write_elements_05(fout, pobj, bptr, pstat);
1123 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
1124 	/* x */
1125 	wxdwr_out_signed(fout, (pobj->det).d.x, bptr, pstat);
1126 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
1127 	/* y */
1128 	wxdwr_out_signed(fout, (pobj->det).d.y, bptr, pstat);
1129 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
1130 	/* d */
1131 	wxdwr_out_unsigned(fout, (pobj->det).d.d, bptr, pstat);
1132 	if (WXD_OT_DOT_WHITE == pobj->ot) {
1133 		/* l */
1134 		wxdwr_out_string_c8(fout, wxdwr_c8_kw[1], bptr, pstat);
1135 		wxdwr_out_unsigned(fout, pobj->lw, bptr, pstat);
1136 	}
1137 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
1138 }
1139 
1140 
1141 
1142 /**	Write graphics object to output file.
1143 	@param	fout	Output file.
1144 	@param	pdrw	Drawing.
1145 	@param	pobj	Object to handle.
1146 	@param	bptr	Address of success variable to reset on error.
1147 	@param	pstat	Status structure for error notification.
1148 */
1149 static
1150 void
wxdwr_write_object(FILE * fout,Wxd_object_t * pobj,int * bptr,wxdwr_status_t * pstat)1151 wxdwr_write_object(
1152 	FILE			*fout,
1153 	Wxd_object_t	*pobj,
1154 	int				*bptr,
1155 	wxdwr_status_t	*pstat
1156 )
1157 {
1158 	switch ( (int)(pobj->ot) ) {
1159 		case WXD_OT_TEXT : {
1160 			wxdwr_write_text_label(fout, pobj, bptr, pstat);
1161 		} break;
1162 		case WXD_OT_POLYLINE : case WXD_OT_POLYGON : {
1163 			wxdwr_write_polyline(fout, pobj, bptr, pstat);
1164 		} break;
1165 		case WXD_OT_O_SPLINE : case WXD_OT_C_SPLINE : {
1166 			wxdwr_write_spline(fout, pobj, bptr, pstat);
1167 		} break;
1168 		case WXD_OT_O_ARC : case WXD_OT_C_ARC : {
1169 			wxdwr_write_arc(fout, pobj, bptr, pstat);
1170 		} break;
1171 		case WXD_OT_CIRCLE : {
1172 			wxdwr_write_circle(fout, pobj, bptr, pstat);
1173 		} break;
1174 		case WXD_OT_ELLIPSE : {
1175 			wxdwr_write_ellipse(fout, pobj, bptr, pstat);
1176 		} break;
1177 		case WXD_OT_BOX : {
1178 			wxdwr_write_box(fout, pobj, bptr, pstat);
1179 		} break;
1180 		case WXD_OT_IMAGE : {
1181 			wxdwr_write_image(fout, pobj, bptr, pstat);
1182 		} break;
1183 		case WXD_OT_DOT_FILLED : {
1184 			wxdwr_write_dot(fout, pobj, bptr, pstat);
1185 		} break;
1186 		case WXD_OT_DOT_WHITE : {
1187 			wxdwr_write_dot(fout, pobj, bptr, pstat);
1188 		} break;
1189 	}
1190 }
1191 
1192 
1193 
1194 static
1195 void
wxdwr_write_group_structure(FILE * fout,Wxd_object_t * proot,int * bptr,wxdwr_status_t * pstat)1196 wxdwr_write_group_structure(
1197 	FILE			*fout,
1198 	Wxd_object_t	*proot,
1199 	int				*bptr,
1200 	wxdwr_status_t	*pstat
1201 )
1202 {
1203 	Wxd_object_t	*pgrp;
1204 	Wxd_object_t	*pobj;
1205 
1206 	pgrp = proot;
1207 	dk4sto_it_reset((pgrp->det).g.i_e);
1208 	wxdwr_out_signed(fout, WXD_OT_GROUP_BEGIN, bptr, pstat);
1209 	wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
1210 	while (NULL != pgrp) {
1211 		pobj = (Wxd_object_t *)dk4sto_it_next((pgrp->det).g.i_e);
1212 		if (NULL != pobj) {
1213 			if (WXD_OT_GROUP_BEGIN == pobj->ot) {
1214 				if (NULL != (pobj->det).g.i_e) {
1215 					dk4sto_it_reset((pobj->det).g.i_e);
1216 					pgrp = pobj;
1217 					wxdwr_out_signed(fout, WXD_OT_GROUP_BEGIN, bptr, pstat);
1218 					wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
1219 				}
1220 			}
1221 			else {
1222 				wxdwr_write_object(fout, pobj, bptr, pstat);
1223 			}
1224 		}
1225 		else {
1226 			pgrp = pgrp->pa;
1227 			wxdwr_out_signed(fout, WXD_OT_GROUP_END, bptr, pstat);
1228 			wxdwr_out_string_c8(fout, wxdwr_c8_kw[0], bptr, pstat);
1229 		}
1230 	}
1231 }
1232 
1233 
1234 
1235 int
wxdwr_write_file(FILE * fout,Wxd_drawing_t * pdrw,wxdwr_status_t * pstat)1236 wxdwr_write_file(FILE *fout, Wxd_drawing_t *pdrw, wxdwr_status_t *pstat)
1237 {
1238 	Wxd_object_t	*pgrp;
1239 	int		 		 back	= 1;
1240 
1241 	if ((NULL != fout) && (NULL != pdrw)) {
1242 		wxdwr_write_first_line(fout, pdrw, &back, pstat);
1243 		wxdwr_write_bounding_box(fout, pdrw, &back, pstat);
1244 		wxdwr_write_base_line_width(fout, pdrw, &back, pstat);
1245 		wxdwr_write_zoom_level(fout, pdrw, &back, pstat);
1246 		wxdwr_write_grid_unit_and_base(fout, pdrw, &back, pstat);
1247 		dk4sto_it_reset(pdrw->i_stru);
1248 		do {
1249 			pgrp = (Wxd_object_t *)dk4sto_it_next(pdrw->i_stru);
1250 			if (NULL != pgrp) {
1251 				if (WXD_OT_GROUP_BEGIN == pgrp->ot) {
1252 					wxdwr_write_group_structure(fout, pgrp, &back, pstat);
1253 				}
1254 				else {
1255 					wxdwr_write_object(fout, pgrp, &back, pstat);
1256 				}
1257 			}
1258 		} while (NULL != pgrp);
1259 	}
1260 	return back;
1261 }
1262 
1263 
1264 
1265 void
wxdwr_status_init(wxdwr_status_t * pstat,int wxe)1266 wxdwr_status_init(wxdwr_status_t *pstat, int wxe)
1267 {
1268 	if (NULL != pstat) {
1269 		pstat->ec	= WXDWR_E_NONE;
1270 		pstat->wxe	= wxe;
1271 		pstat->str	= NULL;
1272 		pstat->dirn	= NULL;
1273 	}
1274 }
1275 
1276 
1277 
1278 /* vim: set ai sw=4 ts=4 : */
1279 
1280