1%%	options
2
3copyright owner	=	Dirk Krause
4copyright year	=	2017-xxxx
5SPDX-License-Identifier:	BSD-3-Clause
6
7
8%%	header
9
10/**	@file dk4pppt.h	PGF/PDF+TeX/(E)PS+TeX output.
11*/
12
13#ifndef	DK4CONF_H_INCLUDED
14#if DK4_BUILDING_DKTOOLS4
15#include "dk4conf.h"
16#else
17#include <dktools-4/dk4conf.h>
18#endif
19#endif
20
21#ifndef	DK4FONT_H_INCLUDED
22#if DK4_BUILDING_DKTOOLS4
23#include <libdk4gra/dk4font.h>
24#else
25#include <dktools-4/dk4font.h>
26#endif
27#endif
28
29#ifndef	DK4ALIGN_H_INCLUDED
30#if DK4_BUILDING_DKTOOLS4
31#include <libdk4gra/dk4align.h>
32#else
33#include <dktools-4/dk4align.h>
34#endif
35#endif
36
37#ifndef	DK4ERROR_H_INCLUDED
38#if DK4_BUILDING_DKTOOLS4
39#include <libdk4base/dk4error.h>
40#else
41#include <dktools-4/dk4error.h>
42#endif
43#endif
44
45#ifndef	DK4MEMBF_H_INCLUDED
46#if DK4_BUILDING_DKTOOLS4
47#include <libdk4c/dk4membuf.h>
48#else
49#include <dktools-4/dk4membuf.h>
50#endif
51#endif
52
53#ifndef	DK4MBSTRM_H_INCLUDED
54#if DK4_BUILDING_DKTOOLS4
55#include <libdk4c/dk4mbstrm.h>
56#else
57#include <dktools-4/dk4mbstrm.h>
58#endif
59#endif
60
61#ifndef	DK4GRA_H_INCLUDED
62#if DK4_BUILDING_DKTOOLS4
63#include <libdk4gra/dk4gra.h>
64#else
65#include <dktools-4/dk4gra.h>
66#endif
67#endif
68
69#ifndef	DK4ENC_H_INCLUDED
70#if DK4_BUILDING_DKTOOLS4
71#include <libdk4c/dk4enc.h>
72#else
73#include <dktools-4/dk4enc.h>
74#endif
75#endif
76
77#ifndef	DK4REC25_H_INCLUDED
78#if DK4_BUILDING_DKTOOLS4
79#include <libdk4c/dk4rec25.h>
80#else
81#include <dktools-4/dk4rec25.h>
82#endif
83#endif
84
85/**	Output drivers.
86*/
87typedef enum {
88	DK4_PPPT_DR_PDF_TEX	= 0,	/**< Produce PDF+TeX file pair. */
89	DK4_PPPT_DR_EPS_TEX ,		/**< Produce EPS+TeX file pair. */
90	DK4_PPPT_DR_PGF				/**< Produce PGF file. */
91} dk4_pppt_driver_t;
92
93
94/**	Output structure for combined PDF+TeX/EPS+TeX output.
95*/
96typedef struct {
97	dkChar					*tfn;	/**< TeX file name. */
98	dk4_gra_t				*gra;	/**< Graphics structure. */
99	dk4_font_collector_t	*fc;	/**< Font collector. */
100	dk4_membuf_t			*tmb;	/**< TeX memory buffer. */
101	dk4_stream_t			*tms;	/**< TeX memory stream. */
102	dk4_sto_t				*s_f;	/**< Storage for font setup lines. */
103	dk4_sto_it_t			*i_f;	/**< Iterator for font setup lines. */
104	dk4_sto_t				*s_p;	/**< Storage for package setup lines. */
105	dk4_sto_it_t			*i_p;	/**< Iterator for package setup lines. */
106	dk4_sto_t				*s_o;	/**< Storage for other preamble lines. */
107	dk4_sto_it_t			*i_o;	/**< Iterator for other preamble lines. */
108	double					 dfs;	/**< Document font size. */
109	size_t					 n_f;	/**< Number of font setup lines. */
110	size_t					 n_p;	/**< Number of package setup lines. */
111	size_t					 n_o;	/**< Number of other setup lines. */
112} dk4_pppt_pdf_ps_t;
113
114
115
116/**	Details structure.
117*/
118typedef union {
119	dk4_gra_t			*pgf;		/**< PGF output structure. */
120	dk4_pppt_pdf_ps_t	 ppt;		/**< Output structure PDF+TeX/EPS+TeX. */
121} dk4_pppt_out_t;
122
123
124
125/**	Output structure.
126*/
127typedef struct {
128	dk4_pppt_out_t		 out;			/**< Output union. */
129	dk4_pppt_driver_t	 dr;			/**< Driver, dk4_pppt_driver_t value. */
130	int					 isdoc;			/**< Flag: Produce entire document. */
131	int					 flags;			/**< Document and page flags. */
132} dk4_pppt_t;
133
134
135#ifdef	__cplusplus
136extern "C" {
137#endif
138
139/**	Open an output structure.
140	@param	texname	Name of TeX output file.
141					The name ends on ".tex".
142					The name of the included *.eps or *.pdf file
143					is derived from this name.
144	@param	dr		Output driver.
145	@param	isdoc	Flag: Produce LaTeX document, not just image.
146	@param	flags	Additional flags for graphics.
147	@param	width	Image width in bp (PS point).
148	@param	height	Image height in bp.
149	@param	erp		Error report, may be NULL.
150	@return	Valid pointer to new output structure on success, NULL on error.
151*/
152dk4_pppt_t *
153dk4pppt_open(
154	const dkChar		*texname,
155	dk4_pppt_driver_t	 dr,
156	int					 isdoc,
157	int					 flags,
158	size_t				 width,
159	size_t				 height,
160	dk4_er_t			*erp
161);
162
163/**	Write output file(s) and close output structure.
164	@param	pppt	Output structure to write and close.
165	@param	erp		Error report, may be NULL.
166	@return	1 on success, 0 on error.
167*/
168int
169dk4pppt_write_and_close(
170	dk4_pppt_t			*pppt,
171	dk4_er_t			*erp
172);
173
174/**	Close output structure without writing.
175	This function can be used after errors to close the structure
176	without any attempt to overwrite existing files.
177	@param	pppt	Output structure to close.
178*/
179void
180dk4pppt_close(
181	dk4_pppt_t			*pppt
182);
183
184/**	Set flag for simplified gsave/grestore handling.
185	Set this flag, if you use gsave and grestore only to save and restore
186	the clip path for pattern filling.
187	@param	pppt	Output structure.
188	@param	val		Flag: Simplified gsave and grestore handling.
189	@param	erp		Error report, may be NULL.
190
191	Error codes:
192	- DK4_E_INVALID_ARGUMENTS<br>
193	  if gra is NULL.
194*/
195void
196dk4pppt_set_gs_for_pattern_only(
197	dk4_pppt_t		*pppt,
198	int				 val,
199	dk4_er_t		*erp
200);
201
202/**	Save current graphics state (especially clip path).
203	@param	pppt	Output structure.
204	@param	backptr	Address of success variable to reset on errors.
205	@param	erp		Error report, may be NULL.
206
207	Error codes:
208	- DK4_E_INVALID_ARGUMENTS<br>
209	  if gra is NULL,
210	- DK4_E_INVALID_ARGUMENTS<br>
211	  if gra is not in a state allowing this operation,
212	- DK4_E_MATH_OVERFLOW<br>
213	  on numeric overflow in memory size calculation,
214	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
215	  if there is not enough memory available,
216	- DK4_E_WRITE_FAILED<br>
217	  if writing one ore multiple bytes to the stream failed,
218	- DK4_E_FLUSH_FAILED<br>
219	  if flushing data downwards failed.
220*/
221void
222dk4pppt_gsave(
223	dk4_pppt_t			*pppt,
224	int					*backptr,
225	dk4_er_t			*erp
226);
227
228/**	Restore graphics state (especially clip path).
229	@param	pppt	Output structure.
230	@param	backptr	Address of success variable to reset on errors.
231	@param	erp		Error report, may be NULL.
232
233	Error codes:
234	- DK4_E_INVALID_ARGUMENTS<br>
235	  if gra is NULL,
236	- DK4_E_INVALID_ARGUMENTS<br>
237	  if gra is not in a state allowing this operation,
238	- DK4_E_MATH_OVERFLOW<br>
239	  on numeric overflow in memory size calculation,
240	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
241	  if there is not enough memory available,
242	- DK4_E_WRITE_FAILED<br>
243	  if writing one ore multiple bytes to the stream failed,
244	- DK4_E_FLUSH_FAILED<br>
245	  if flushing data downwards failed.
246*/
247void
248dk4pppt_grestore(
249	dk4_pppt_t			*pppt,
250	int					*backptr,
251	dk4_er_t			*erp
252);
253
254/**	Set line width.
255	@param	pppt	Output structure.
256	@param	lw		Line width in bp.
257	@param	backptr	Address of success variable to reset on errors.
258	@param	erp		Error report, may be NULL.
259
260	Error codes:
261	- DK4_E_INVALID_ARGUMENTS<br>
262	  if gra is NULL,
263	- DK4_E_INVALID_ARGUMENTS<br>
264	  if gra is not in a state allowing this operation.
265*/
266void
267dk4pppt_set_line_width(
268	dk4_pppt_t		*pppt,
269	double			 lw,
270	int				*backptr,
271	dk4_er_t		*erp
272);
273
274/**	Set line style.
275	@param	pppt	Output structure.
276	@param	ls		Line style.
277	@param	sv		Style value (dash length in bp).
278	@param	backptr	Address of success variable to reset on errors.
279	@param	erp		Error report, may be NULL.
280
281	Error codes:
282	- DK4_E_INVALID_ARGUMENTS<br>
283	  if gra is NULL,
284	- DK4_E_INVALID_ARGUMENTS<br>
285	  if gra is not in a state allowing this operation.
286*/
287void
288dk4pppt_set_line_style(
289	dk4_pppt_t		*pppt,
290	dk4_gra_ls_t	 ls,
291	double			 sv,
292	int				*backptr,
293	dk4_er_t		*erp
294);
295
296/**	Set line cap.
297	@param	pppt	Output structure.
298	@param	lc		Line cap type.
299	@param	backptr	Address of success variable to reset on errors.
300	@param	erp		Error report, may be NULL.
301
302	Error codes:
303	- DK4_E_INVALID_ARGUMENTS<br>
304	  if gra is NULL,
305	- DK4_E_INVALID_ARGUMENTS<br>
306	  if gra is not in a state allowing this operation.
307*/
308void
309dk4pppt_set_line_cap(
310	dk4_pppt_t		*pppt,
311	dk4_gra_lc_t	 lc,
312	int				*backptr,
313	dk4_er_t		*erp
314);
315
316/**	Set line join.
317	@param	pppt	Output structure.
318	@param	lj		Line join type.
319	@param	ml		Miter limit, only used if lj is DK4_GRA_LJ_MITERED.
320	@param	backptr	Address of success variable to reset on errors.
321	@param	erp		Error report, may be NULL.
322
323	Error codes:
324	- DK4_E_INVALID_ARGUMENTS<br>
325	  if gra is NULL,
326	- DK4_E_INVALID_ARGUMENTS<br>
327	  if gra is not in a state allowing this operation.
328*/
329void
330dk4pppt_set_line_join(
331	dk4_pppt_t		*pppt,
332	dk4_gra_lj_t	 lj,
333	double			 ml,
334	int				*backptr,
335	dk4_er_t		*erp
336);
337
338/**	Set fill color to gray.
339	@param	pppt	Output structure.
340	@param	g		Gray value in interval 0 to 1.
341	@param	backptr	Address of success variable to reset on errors.
342	@param	erp		Error report, may be NULL.
343
344	Error codes:
345	- DK4_E_INVALID_ARGUMENTS<br>
346	  if gra is NULL,
347	- DK4_E_INVALID_ARGUMENTS<br>
348	  if gra is not in a state allowing this operation.
349*/
350void
351dk4pppt_set_fill_gray(
352	dk4_pppt_t		*pppt,
353	double			 g,
354	int				*backptr,
355	dk4_er_t		*erp
356);
357
358/**	Set fill color to RGB.
359	@param	pppt	Output structure.
360	@param	r		Red value in interval 0 to 1.
361	@param	g		Green value in interval 0 to 1.
362	@param	b		Blue value in interval 0 to 1.
363	@param	backptr	Address of success variable to reset on errors.
364	@param	erp		Error report, may be NULL.
365
366	Error codes:
367	- DK4_E_INVALID_ARGUMENTS<br>
368	  if gra is NULL,
369	- DK4_E_INVALID_ARGUMENTS<br>
370	  if gra is not in a state allowing this operation.
371*/
372void
373dk4pppt_set_fill_rgb(
374	dk4_pppt_t		*pppt,
375	double			 r,
376	double			 g,
377	double			 b,
378	int				*backptr,
379	dk4_er_t		*erp
380);
381
382/**	Set fill color to CMYK.
383	@param	pppt	Output structure.
384	@param	c		Cyan value in interval 0 to 1.
385	@param	m		Magenta value in interval 0 to 1.
386	@param	y		Yellow value in interval 0 to 1.
387	@param	k		Black value in interval 0 to 1.
388	@param	backptr	Address of success variable to reset on errors.
389	@param	erp		Error report, may be NULL.
390
391	Error codes:
392	- DK4_E_INVALID_ARGUMENTS<br>
393	  if gra is NULL,
394	- DK4_E_INVALID_ARGUMENTS<br>
395	  if gra is not in a state allowing this operation.
396*/
397void
398dk4pppt_set_fill_cmyk(
399	dk4_pppt_t		*pppt,
400	double			 c,
401	double			 m,
402	double			 y,
403	double			 k,
404	int				*backptr,
405	dk4_er_t		*erp
406);
407
408/**	Set stroke color to gray.
409	@param	pppt	Output structure.
410	@param	g		Gray value in interval 0 to 1.
411	@param	backptr	Address of success variable to reset on errors.
412	@param	erp		Error report, may be NULL.
413
414	Error codes:
415	- DK4_E_INVALID_ARGUMENTS<br>
416	  if gra is NULL,
417	- DK4_E_INVALID_ARGUMENTS<br>
418	  if gra is not in a state allowing this operation.
419*/
420void
421dk4pppt_set_stroke_gray(
422	dk4_pppt_t		*pppt,
423	double			 g,
424	int				*backptr,
425	dk4_er_t		*erp
426);
427
428/**	Set stroke color to RGB.
429	@param	pppt	Output structure.
430	@param	r		Red value in interval 0 to 1.
431	@param	g		Green value in interval 0 to 1.
432	@param	b		Blue value in interval 0 to 1.
433	@param	backptr	Address of success variable to reset on errors.
434	@param	erp		Error report, may be NULL.
435
436	Error codes:
437	- DK4_E_INVALID_ARGUMENTS<br>
438	  if gra is NULL,
439	- DK4_E_INVALID_ARGUMENTS<br>
440	  if gra is not in a state allowing this operation.
441*/
442void
443dk4pppt_set_stroke_rgb(
444	dk4_pppt_t		*pppt,
445	double			 r,
446	double			 g,
447	double			 b,
448	int				*backptr,
449	dk4_er_t		*erp
450);
451
452/**	Set stroke color to CMYK.
453	@param	pppt	Output structure.
454	@param	c		Cyan value in interval 0 to 1.
455	@param	m		Magenta value in interval 0 to 1.
456	@param	y		Yellow value in interval 0 to 1.
457	@param	k		Black value in interval 0 to 1.
458	@param	backptr	Address of success variable to reset on errors.
459	@param	erp		Error report, may be NULL.
460
461	Error codes:
462	- DK4_E_INVALID_ARGUMENTS<br>
463	  if gra is NULL,
464	- DK4_E_INVALID_ARGUMENTS<br>
465	  if gra is not in a state allowing this operation.
466*/
467void
468dk4pppt_set_stroke_cmyk(
469	dk4_pppt_t		*pppt,
470	double			 c,
471	double			 m,
472	double			 y,
473	double			 k,
474	int				*backptr,
475	dk4_er_t		*erp
476);
477
478/**	Prepare output structure for a fill operation.
479	Use this function before you start to construct a path you plan to fill.
480	@param	pppt	Output structure.
481	@param	backptr	Address of success variable to reset on errors.
482	@param	erp		Error report, may be NULL.
483
484	Error codes:
485	- DK4_E_INVALID_ARGUMENTS<br>
486	  if gra is NULL,
487	- DK4_E_INVALID_ARGUMENTS<br>
488	  if gra is not in a state allowing this operation,
489	- DK4_E_MATH_OVERFLOW<br>
490	  on numeric overflow in memory size calculation,
491	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
492	  if there is not enough memory available,
493	- DK4_E_WRITE_FAILED<br>
494	  if writing one ore multiple bytes to the stream failed,
495	- DK4_E_FLUSH_FAILED<br>
496	  if flushing data downwards failed.
497*/
498void
499dk4pppt_prepare_fill(
500	dk4_pppt_t	*pppt,
501	int			*backptr,
502	dk4_er_t	*erp
503);
504
505/**	Prepare output structure for a stroke operation.
506	Use this function before you start to construct a path you plan to stroke.
507	@param	pppt	Output structure.
508	@param	backptr	Address of success variable to reset on errors.
509	@param	erp		Error report, may be NULL.
510
511	Error codes:
512	- DK4_E_INVALID_ARGUMENTS<br>
513	  if gra is NULL,
514	- DK4_E_INVALID_ARGUMENTS<br>
515	  if gra is not in a state allowing this operation,
516	- DK4_E_MATH_OVERFLOW<br>
517	  on numeric overflow in memory size calculation,
518	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
519	  if there is not enough memory available,
520	- DK4_E_WRITE_FAILED<br>
521	  if writing one ore multiple bytes to the stream failed,
522	- DK4_E_FLUSH_FAILED<br>
523	  if flushing data downwards failed.
524*/
525void
526dk4pppt_prepare_stroke(
527	dk4_pppt_t	*pppt,
528	int			*backptr,
529	dk4_er_t	*erp
530);
531
532/**	Prepare output structure for a combined fill and stroke operation.
533	Use this function before you start to construct a path you plan to
534	fill and stroke.
535	@param	pppt	Output structure.
536	@param	backptr	Address of success variable to reset on errors.
537	@param	erp		Error report, may be NULL.
538
539	Error codes:
540	- DK4_E_INVALID_ARGUMENTS<br>
541	  if gra is NULL,
542	- DK4_E_INVALID_ARGUMENTS<br>
543	  if gra is not in a state allowing this operation,
544	- DK4_E_MATH_OVERFLOW<br>
545	  on numeric overflow in memory size calculation,
546	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
547	  if there is not enough memory available,
548	- DK4_E_WRITE_FAILED<br>
549	  if writing one ore multiple bytes to the stream failed,
550	- DK4_E_FLUSH_FAILED<br>
551	  if flushing data downwards failed.
552*/
553void
554dk4pppt_prepare_fill_and_stroke(
555	dk4_pppt_t	*pppt,
556	int			*backptr,
557	dk4_er_t	*erp
558);
559
560/**	Check whether a combined fill and close operation is available
561	for an output structure.
562	@param	pppt	Output structure to test.
563	@return	1 if a fill-and-close operation is available, 0 otherwise.
564*/
565int
566dk4pppt_can_fill_and_stroke(
567	const dk4_pppt_t	*pppt
568);
569
570/**	Fill current path.
571	Note: Use dk4gra_prepare_fill() before you start to construct a path
572	you plan to fill.
573	@param	pppt	Output structure.
574	@param	backptr	Address of success variable to reset on errors.
575	@param	erp		Error report, may be NULL.
576
577	Error codes:
578	- DK4_E_INVALID_ARGUMENTS<br>
579	  if gra is NULL,
580	- DK4_E_INVALID_ARGUMENTS<br>
581	  if gra is not in a state allowing this operation,
582	- DK4_E_MATH_OVERFLOW<br>
583	  on numeric overflow in memory size calculation,
584	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
585	  if there is not enough memory available,
586	- DK4_E_WRITE_FAILED<br>
587	  if writing one ore multiple bytes to the stream failed,
588	- DK4_E_FLUSH_FAILED<br>
589	  if flushing data downwards failed.
590*/
591void
592dk4pppt_fill(
593	dk4_pppt_t	*pppt,
594	int			*backptr,
595	dk4_er_t	*erp
596);
597
598/**	Stroke current path.
599	Note: Use dk4gra_prepare_stroke() before you start to construct a path
600	you plan to stroke.
601	@param	pppt	Output structure.
602	@param	backptr	Address of success variable to reset on errors.
603	@param	erp		Error report, may be NULL.
604
605	Error codes:
606	- DK4_E_INVALID_ARGUMENTS<br>
607	  if gra is NULL,
608	- DK4_E_INVALID_ARGUMENTS<br>
609	  if gra is not in a state allowing this operation,
610	- DK4_E_MATH_OVERFLOW<br>
611	  on numeric overflow in memory size calculation,
612	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
613	  if there is not enough memory available,
614	- DK4_E_WRITE_FAILED<br>
615	  if writing one ore multiple bytes to the stream failed,
616	- DK4_E_FLUSH_FAILED<br>
617	  if flushing data downwards failed.
618*/
619void
620dk4pppt_stroke(
621	dk4_pppt_t	*pppt,
622	int			*backptr,
623	dk4_er_t	*erp
624);
625
626/**	Fill and stroke current path.
627	Note: Use dk4gra_prepare_fill_and_stroke() before you start to construct
628	a path you plan to fill and stroke.
629	@param	pppt	Output structure.
630	@param	backptr	Address of success variable to reset on errors.
631	@param	erp		Error report, may be NULL.
632
633	Error codes:
634	- DK4_E_INVALID_ARGUMENTS<br>
635	  if gra is NULL,
636	- DK4_E_INVALID_ARGUMENTS<br>
637	  if gra is not in a state allowing this operation,
638	- DK4_E_MATH_OVERFLOW<br>
639	  on numeric overflow in memory size calculation,
640	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
641	  if there is not enough memory available,
642	- DK4_E_WRITE_FAILED<br>
643	  if writing one ore multiple bytes to the stream failed,
644	- DK4_E_FLUSH_FAILED<br>
645	  if flushing data downwards failed.
646*/
647void
648dk4pppt_fill_and_stroke(
649	dk4_pppt_t	*pppt,
650	int			*backptr,
651	dk4_er_t	*erp
652);
653
654/**	Use current path for clipping.
655	@param	pppt	Output structure.
656	@param	backptr	Address of success variable to reset on errors.
657	@param	erp		Error report, may be NULL.
658
659	Error codes:
660	- DK4_E_INVALID_ARGUMENTS<br>
661	  if gra is NULL,
662	- DK4_E_INVALID_ARGUMENTS<br>
663	  if gra is not in a state allowing this operation,
664	- DK4_E_MATH_OVERFLOW<br>
665	  on numeric overflow in memory size calculation,
666	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
667	  if there is not enough memory available,
668	- DK4_E_WRITE_FAILED<br>
669	  if writing one ore multiple bytes to the stream failed,
670	- DK4_E_FLUSH_FAILED<br>
671	  if flushing data downwards failed.
672*/
673void
674dk4pppt_clip(
675	dk4_pppt_t	*pppt,
676	int			*backptr,
677	dk4_er_t	*erp
678);
679
680/**	Set line width to draw fill patterns.
681	The pattern line width should be in range 0 to 2bp,
682	default is 0.9bp.
683	@param	pppt	Output structure.
684	@param	plw		New pattern line width in bp.
685*/
686void
687dk4pppt_set_pattern_line_width(
688	dk4_pppt_t	*pppt,
689	double		 plw
690);
691
692/**	Pattern a region (clipping should be set to the path).
693	@param	pppt	Output structure.
694	@param	xl		Left y coordinate.
695	@param	xr		Right x coordinate.
696	@param	yb		Bottom y coordinate.
697	@param	yt		Top y coordinate.
698	@param	pn		Pattern number.
699	@param	backptr	Address of success variable to reset on errors.
700	@param	erp		Error report, may be NULL.
701
702	Error codes:
703	- DK4_E_INVALID_ARGUMENTS<br>
704	  if gra is NULL,
705	- DK4_E_INVALID_ARGUMENTS<br>
706	  if gra is not in a state allowing this operation,
707	- DK4_E_MATH_OVERFLOW<br>
708	  on numeric overflow in memory size calculation,
709	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
710	  if there is not enough memory available,
711	- DK4_E_WRITE_FAILED<br>
712	  if writing one ore multiple bytes to the stream failed,
713	- DK4_E_FLUSH_FAILED<br>
714	  if flushing data downwards failed.
715*/
716void
717dk4pppt_pattern(
718	dk4_pppt_t			*pppt,
719	double				 xl,
720	double				 xr,
721	double				 yb,
722	double				 yt,
723	dk4_gra_pattern_t	 pn,
724	int					*backptr,
725	dk4_er_t			*erp
726);
727
728/**	Start a new path and move to first point.
729	@param	pppt	Output structure.
730	@param	x		X coordinate of start point.
731	@param	y		Y coordinate of start point.
732	@param	bbptr	Bounding box, may be NULL.
733	@param	backptr	Address of success variable to reset on errors.
734	@param	erp		Error report, may be NULL.
735
736	Error codes:
737	- DK4_E_INVALID_ARGUMENTS<br>
738	  if gra is NULL,
739	- DK4_E_INVALID_ARGUMENTS<br>
740	  if gra is not in a state allowing this operation,
741	- DK4_E_MATH_OVERFLOW<br>
742	  on numeric overflow in memory size calculation,
743	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
744	  if there is not enough memory available,
745	- DK4_E_WRITE_FAILED<br>
746	  if writing one ore multiple bytes to the stream failed,
747	- DK4_E_FLUSH_FAILED<br>
748	  if flushing data downwards failed.
749*/
750void
751dk4pppt_newpath_moveto(
752	dk4_pppt_t	*pppt,
753	double		 x,
754	double		 y,
755	dk4_bb_t	*bbptr,
756	int			*backptr,
757	dk4_er_t	*erp
758);
759
760/**	Add line from current point to new point to path.
761	@param	pppt	Output structure.
762	@param	x		X coordinate of new point.
763	@param	y		Y coordinate of new point.
764	@param	bbptr	Bounding box, may be NULL.
765	@param	backptr	Address of success variable to reset on errors.
766	@param	erp		Error report, may be NULL.
767
768	Error codes:
769	- DK4_E_INVALID_ARGUMENTS<br>
770	  if gra is NULL,
771	- DK4_E_INVALID_ARGUMENTS<br>
772	  if gra is not in a state allowing this operation,
773	- DK4_E_MATH_OVERFLOW<br>
774	  on numeric overflow in memory size calculation,
775	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
776	  if there is not enough memory available,
777	- DK4_E_WRITE_FAILED<br>
778	  if writing one ore multiple bytes to the stream failed,
779	- DK4_E_FLUSH_FAILED<br>
780	  if flushing data downwards failed.
781*/
782void
783dk4pppt_lineto(
784	dk4_pppt_t	*pppt,
785	double		 x,
786	double		 y,
787	dk4_bb_t	*bbptr,
788	int			*backptr,
789	dk4_er_t	*erp
790);
791
792/**	Add Bezier curve segment from current point to new point in path.
793	@param	pppt	Output structure.
794	@param	xc1		X coordinate of first control point.
795	@param	yc1		Y coordinate of first control point.
796	@param	xc2		X coordinate of second control point.
797	@param	yc2		Y coordinate of second control point.
798	@param	x		X coordinate of new point.
799	@param	y		Y coordinate of new point.
800	@param	bbptr	Bounding box, may be NULL.
801	@param	backptr	Address of success variable to reset on errors.
802	@param	erp		Error report, may be NULL.
803
804	Error codes:
805	- DK4_E_INVALID_ARGUMENTS<br>
806	  if gra is NULL,
807	- DK4_E_INVALID_ARGUMENTS<br>
808	  if gra is not in a state allowing this operation,
809	- DK4_E_MATH_OVERFLOW<br>
810	  on numeric overflow in memory size calculation,
811	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
812	  if there is not enough memory available,
813	- DK4_E_WRITE_FAILED<br>
814	  if writing one ore multiple bytes to the stream failed,
815	- DK4_E_FLUSH_FAILED<br>
816	  if flushing data downwards failed.
817*/
818void
819dk4pppt_curveto(
820	dk4_pppt_t	*pppt,
821	double		 xc1,
822	double		 yc1,
823	double		 xc2,
824	double		 yc2,
825	double		 x,
826	double		 y,
827	dk4_bb_t	*bbptr,
828	int			*backptr,
829	dk4_er_t	*erp
830);
831
832/**	Close current path.
833	@param	pppt	Output structure.
834	@param	backptr	Address of success variable to reset on errors.
835	@param	erp		Error report, may be NULL.
836
837	Error codes:
838	- DK4_E_INVALID_ARGUMENTS<br>
839	  if gra is NULL,
840	- DK4_E_INVALID_ARGUMENTS<br>
841	  if gra is not in a state allowing this operation,
842	- DK4_E_MATH_OVERFLOW<br>
843	  on numeric overflow in memory size calculation,
844	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
845	  if there is not enough memory available,
846	- DK4_E_WRITE_FAILED<br>
847	  if writing one ore multiple bytes to the stream failed,
848	- DK4_E_FLUSH_FAILED<br>
849	  if flushing data downwards failed.
850*/
851void
852dk4pppt_closepath(
853	dk4_pppt_t	*pppt,
854	int			*backptr,
855	dk4_er_t	*erp
856);
857
858/**	Add bitmap image XFig style.
859	@param	pppt	Output structure.
860	@param	xl		Left x coordinate.
861	@param	xr		Right x coordinate.
862	@param	yb		Bottom y coordinate.
863	@param	yt		Top y coordinate.
864	@param	bif		Bitmap image file.
865	@param	fn		Image file name.
866	@param	fno		Frame number (0 for first frame).
867	@param	pos		Image positioning:
868	- 0 not rotated, not flipped,
869	- 1 rotated 90 degree counterclockwise, not flipped,
870	- 2 rotated 180 degree counterclockwise, not flipped,
871	- 3 rotated 270 degree counterclockwise, not flipped,
872	- 4 not rotated, flipped,
873	- 5 rotated 90 degree counterclockwise, flipped,
874	- 6 rotated 180 degree counterclockwise, flipped,
875	- 7 rotated 270 degree counterclockwise, flipped.
876	@param	ifl		Image flags.
877	@param	bbptr	Bounding box, may be NULL.
878	@param	backptr	Address of success variable to reset on errors.
879	@param	erp		Error report, may be NULL.
880
881	Error codes:
882	- DK4_E_INVALID_ARGUMENTS<br>
883	  if gra is NULL or bif is NULL or a frame number other than 0
884	  was specified for PGF output,
885	- DK4_E_INVALID_ARGUMENTS<br>
886	  if gra is not in a state allowing this operation,
887	- DK4_E_MATH_OVERFLOW<br>
888	  on numeric overflow in memory size calculation,
889	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
890	  if there is not enough memory available,
891	- DK4_E_WRITE_FAILED<br>
892	  if writing one ore multiple bytes to the stream failed,
893	- DK4_E_FLUSH_FAILED<br>
894	  if flushing data downwards failed.
895*/
896void
897dk4pppt_bif_fig_image(
898	dk4_pppt_t		*pppt,
899	double			 xl,
900	double			 xr,
901	double			 yb,
902	double			 yt,
903	dk4_bif_t		*bif,
904	const dkChar	*fn,
905	size_t			 fno,
906	int				 pos,
907	int				 ifl,
908	dk4_bb_t		*bbptr,
909	int				*backptr,
910	dk4_er_t		*erp
911);
912
913/**	Add bitmap image.
914	@param	pppt	Output structure.
915	@param	xl		Left x coordinate.
916	@param	xr		Right x coordinate.
917	@param	yb		Bottom y coordinate.
918	@param	yt		Top y coordinate.
919	@param	bif		Bitmap image file data.
920	@param	fn		Image file name.
921	@param	fno		Frame number (0 for first frame).
922	@param	ifl		Image flags.
923	@param	bbptr	Bounding box, may be NULL.
924	@param	backptr	Address of success variable to reset on errors.
925	@param	erp		Error report, may be NULL.
926
927	Error codes:
928	- DK4_E_INVALID_ARGUMENTS<br>
929	  if gra is NULL or bif is NULL,
930	- DK4_E_INVALID_ARGUMENTS<br>
931	  if gra is not in a state allowing this operation,
932	- DK4_E_MATH_OVERFLOW<br>
933	  on numeric overflow in memory size calculation,
934	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
935	  if there is not enough memory available,
936	- DK4_E_WRITE_FAILED<br>
937	  if writing one ore multiple bytes to the stream failed,
938	- DK4_E_FLUSH_FAILED<br>
939	  if flushing data downwards failed.
940*/
941void
942dk4pppt_bif_image(
943	dk4_pppt_t		*pppt,
944	double			 xl,
945	double			 xr,
946	double			 yb,
947	double			 yt,
948	dk4_bif_t		*bif,
949	const dkChar	*fn,
950	size_t			 fno,
951	int				 ifl,
952	dk4_bb_t		*bbptr,
953	int				*backptr,
954	dk4_er_t		*erp
955);
956
957/**	Add bitmap image.
958	@param	pppt	Output structure.
959	@param	xl		Left x coordinate.
960	@param	xr		Right x coordinate.
961	@param	yb		Bottom y coordinate.
962	@param	yt		Top y coordinate.
963	@param	fn		Image file name.
964	@param	fno		Frame number (0 for first frame).
965	@param	ctx		Bitmap image conversion context, may be NULL.
966	@param	ifl		Image flags.
967	@param	bbptr	Bounding box, may be NULL.
968	@param	backptr	Address of success variable to reset on errors.
969	@param	erp		Error report, may be NULL.
970
971	Error codes:
972	- DK4_E_INVALID_ARGUMENTS<br>
973	  if gra is NULL or bif is NULL,
974	- DK4_E_INVALID_ARGUMENTS<br>
975	  if gra is not in a state allowing this operation,
976	- DK4_E_MATH_OVERFLOW<br>
977	  on numeric overflow in memory size calculation,
978	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
979	  if there is not enough memory available,
980	- DK4_E_WRITE_FAILED<br>
981	  if writing one ore multiple bytes to the stream failed,
982	- DK4_E_FLUSH_FAILED<br>
983	  if flushing data downwards failed.
984*/
985void
986dk4pppt_image(
987	dk4_pppt_t			*pppt,
988	double				 xl,
989	double				 xr,
990	double				 yb,
991	double				 yt,
992	const dkChar		*fn,
993	size_t				 fno,
994	dk4_cs_conv_ctx_t	*ctx,
995	int					 ifl,
996	dk4_bb_t			*bbptr,
997	int					*backptr,
998	dk4_er_t			*erp
999);
1000
1001/**	Add bitmap image XFig style.
1002	@param	pppt	Output structure.
1003	@param	xl		Left x coordinate.
1004	@param	xr		Right x coordinate.
1005	@param	yb		Bottom y coordinate.
1006	@param	yt		Top y coordinate.
1007	@param	fn		Image file name.
1008	@param	fno		Frame number (0 for first frame).
1009	@param	ctx		Bitmap image conversion context, may be NULL.
1010	@param	pos		Image positioning:
1011	- 0 not rotated, not flipped,
1012	- 1 rotated 90 degree counterclockwise, not flipped,
1013	- 2 rotated 180 degree counterclockwise, not flipped,
1014	- 3 rotated 270 degree counterclockwise, not flipped,
1015	- 4 not rotated, flipped,
1016	- 5 rotated 90 degree counterclockwise, flipped,
1017	- 6 rotated 180 degree counterclockwise, flipped,
1018	- 7 rotated 270 degree counterclockwise, flipped.
1019	@param	ifl		Image flags.
1020	@param	bbptr	Bounding box, may be NULL.
1021	@param	backptr	Address of success variable to reset on errors.
1022	@param	erp		Error report, may be NULL.
1023
1024	Error codes:
1025	- DK4_E_INVALID_ARGUMENTS<br>
1026	  if gra is NULL or bif is NULL,
1027	- DK4_E_INVALID_ARGUMENTS<br>
1028	  if gra is not in a state allowing this operation,
1029	- DK4_E_MATH_OVERFLOW<br>
1030	  on numeric overflow in memory size calculation,
1031	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
1032	  if there is not enough memory available,
1033	- DK4_E_WRITE_FAILED<br>
1034	  if writing one ore multiple bytes to the stream failed,
1035	- DK4_E_FLUSH_FAILED<br>
1036	  if flushing data downwards failed.
1037*/
1038void
1039dk4pppt_fig_image(
1040	dk4_pppt_t			*pppt,
1041	double				 xl,
1042	double				 xr,
1043	double				 yb,
1044	double				 yt,
1045	const dkChar		*fn,
1046	size_t				 fno,
1047	dk4_cs_conv_ctx_t	*ctx,
1048	int					 pos,
1049	int					 ifl,
1050	dk4_bb_t			*bbptr,
1051	int					*backptr,
1052	dk4_er_t			*erp
1053);
1054
1055/**	Create path for a circle.
1056	@param	pppt	Output structure.
1057	@param	xc		Center point x coordinate.
1058	@param	yc		Center point y coordinate.
1059	@param	r		Radius.
1060	@param	bbptr	Bounding box, may be NULL.
1061	@param	backptr	Address of success variable to reset on errors.
1062	@param	erp		Error report, may be NULL.
1063
1064	Error codes:
1065	- DK4_E_INVALID_ARGUMENTS<br>
1066	  if gra is NULL,
1067	- DK4_E_INVALID_ARGUMENTS<br>
1068	  if gra is not in a state allowing this operation,
1069	- DK4_E_MATH_OVERFLOW<br>
1070	  on numeric overflow in memory size calculation,
1071	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
1072	  if there is not enough memory available,
1073	- DK4_E_WRITE_FAILED<br>
1074	  if writing one ore multiple bytes to the stream failed,
1075	- DK4_E_FLUSH_FAILED<br>
1076	  if flushing data downwards failed.
1077*/
1078void
1079dk4pppt_circle(
1080	dk4_pppt_t	*pppt,
1081	double		 xc,
1082	double		 yc,
1083	double		 r,
1084	dk4_bb_t	*bbptr,
1085	int			*backptr,
1086	dk4_er_t	*erp
1087);
1088
1089/**	Create path for rectangle parallel to axes, optionally with
1090	rounded corners.
1091	@param	pppt	Output structure.
1092	@param	xl		Left x coordinate.
1093	@param	xr		Right x coordinate.
1094	@param	yb		Bottom y coordinate.
1095	@param	yt		Top y coordinate.
1096	@param	r		Corner radius, maximum is a half of the smaller side length.
1097					Use negative values to avoid rounded corners.
1098	@param	bbptr	Bounding box, may be NULL.
1099	@param	backptr	Address of success variable to reset on errors.
1100	@param	erp		Error report, may be NULL.
1101
1102	Error codes:
1103	- DK4_E_INVALID_ARGUMENTS<br>
1104	  if gra is NULL,
1105	- DK4_E_INVALID_ARGUMENTS<br>
1106	  if gra is not in a state allowing this operation,
1107	- DK4_E_MATH_OVERFLOW<br>
1108	  on numeric overflow in memory size calculation,
1109	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
1110	  if there is not enough memory available,
1111	- DK4_E_WRITE_FAILED<br>
1112	  if writing one ore multiple bytes to the stream failed,
1113	- DK4_E_FLUSH_FAILED<br>
1114	  if flushing data downwards failed.
1115*/
1116void
1117dk4pppt_rectangle(
1118	dk4_pppt_t	*pppt,
1119	double		 xl,
1120	double		 xr,
1121	double		 yb,
1122	double		 yt,
1123	double		 r,
1124	dk4_bb_t	*bbptr,
1125	int			*backptr,
1126	dk4_er_t	*erp
1127);
1128
1129/**	Add path for an arc.
1130	@param	pppt	Output structure.
1131	@param	xc		Center point x coordinate.
1132	@param	yc		Center point y coordinate.
1133	@param	ra		Radius.
1134	@param	start	Start angle in degree.
1135	@param	end		End angle in degree.
1136	@param	cl		Flag: Draw closed arc (piece of cake) instead of simple arc.
1137	@param	bbptr	Bounding box, may be NULL.
1138	@param	backptr	Address of success variable to reset on errors.
1139	@param	erp		Error report, may be NULL.
1140
1141	Error codes:
1142	- DK4_E_INVALID_ARGUMENTS<br>
1143	  if gra is NULL,
1144	- DK4_E_INVALID_ARGUMENTS<br>
1145	  if gra is not in a state allowing this operation,
1146	- DK4_E_MATH_OVERFLOW<br>
1147	  on numeric overflow in memory size calculation,
1148	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
1149	  if there is not enough memory available,
1150	- DK4_E_WRITE_FAILED<br>
1151	  if writing one ore multiple bytes to the stream failed,
1152	- DK4_E_FLUSH_FAILED<br>
1153	  if flushing data downwards failed.
1154*/
1155void
1156dk4pppt_arc(
1157	dk4_pppt_t	*pppt,
1158	double		 xc,
1159	double		 yc,
1160	double		 ra,
1161	double		 start,
1162	double		 end,
1163	int			 cl,
1164	dk4_bb_t	*bbptr,
1165	int			*backptr,
1166	dk4_er_t	*erp
1167);
1168
1169/**	Create path for an ellipse.
1170	@param	pppt	Output structure.
1171	@param	xc		Center point x coordinate.
1172	@param	yc		Center point y coordinate.
1173	@param	rx		Radius in x direction.
1174	@param	ry		Radius in y direction.
1175	@param	rot		Rotation counterclockwise in degree.
1176	@param	bbptr	Bounding box, may be NULL.
1177	@param	backptr	Address of success variable to reset on errors.
1178	@param	erp		Error report, may be NULL.
1179
1180	Error codes:
1181	- DK4_E_INVALID_ARGUMENTS<br>
1182	  if gra is NULL,
1183	- DK4_E_INVALID_ARGUMENTS<br>
1184	  if gra is not in a state allowing this operation,
1185	- DK4_E_MATH_OVERFLOW<br>
1186	  on numeric overflow in memory size calculation,
1187	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
1188	  if there is not enough memory available,
1189	- DK4_E_WRITE_FAILED<br>
1190	  if writing one ore multiple bytes to the stream failed,
1191	- DK4_E_FLUSH_FAILED<br>
1192	  if flushing data downwards failed.
1193*/
1194void
1195dk4pppt_ellipse(
1196	dk4_pppt_t	*pppt,
1197	double		 xc,
1198	double		 yc,
1199	double		 rx,
1200	double		 ry,
1201	double		 rot,
1202	dk4_bb_t	*bbptr,
1203	int			*backptr,
1204	dk4_er_t	*erp
1205);
1206
1207/**	Add simple (non-special) text to PGF graphics.
1208	The text is shown in the current fill color (non-stroking color)
1209	unless colspec is used to specify a color.
1210	@param	pppt	Output structure, must be initialized for PGF.
1211	@param	x		X coordinate.
1212	@param	y		Y coordinate.
1213	@param	rot		Rotation counterclockwise in degree.
1214	@param	txt		Text to show.
1215	@param	colspec	Color specification, may be NULL to use fill color.
1216	@param	ie		Text encoding, only used for char text.
1217	@param	ha		Horizontal alignment.
1218	@param	va		Vertical alignment.
1219	@param	fno		Font number.
1220	@param	fsz		Font size in pt.
1221	@param	fex		Flag: Use exact font (1) or similar font (0).
1222	@param	uc2l	UC to LaTeX conversion structure.
1223	@param	flags	Text flags DK4_GRA_TEXT_FLAG_xxx, can be or-combined.
1224	@param	backptr	Address of success variable to reset on errors.
1225	@param	erp		Error report, may be NULL.
1226
1227	Error codes:
1228	- DK4_E_INVALID_ARGUMENTS<br>
1229	  if gra is NULL,
1230	- DK4_E_INVALID_ARGUMENTS<br>
1231	  if gra is not in a state allowing this operation,
1232	- DK4_E_MATH_OVERFLOW<br>
1233	  on numeric overflow in memory size calculation,
1234	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
1235	  if there is not enough memory available,
1236	- DK4_E_WRITE_FAILED<br>
1237	  if writing one ore multiple bytes to the stream failed,
1238	- DK4_E_FLUSH_FAILED<br>
1239	  if flushing data downwards failed.
1240*/
1241void
1242dk4pppt_simple_text(
1243	dk4_pppt_t			*pppt,
1244	double				 x,
1245	double				 y,
1246	double				 rot,
1247	const dkChar		*txt,
1248	const char			*colspec,
1249	int					 ie,
1250	dk4_text_align_h_t	 ha,
1251	dk4_text_align_v_t	 va,
1252	int					 fno,
1253	double				 fsz,
1254	dk4_gra_tf_t		 fex,
1255	dk4_uc2l_t			*uc2l,
1256	int					 flags,
1257	int					*backptr,
1258	dk4_er_t			*erp
1259);
1260
1261
1262/**	Add simple (non-special) text to PGF graphics.
1263	The text is shown in the current fill color (non-stroking color)
1264	unless colspec is used to specify a color.
1265	@param	pppt	Output structure, must be initialized for PGF.
1266	@param	x		X coordinate.
1267	@param	y		Y coordinate.
1268	@param	rot		Rotation counterclockwise in degree.
1269	@param	txt		Text to show.
1270	@param	colspec	Color specification, may be NULL to use fill color.
1271	@param	ha		Horizontal alignment.
1272	@param	va		Vertical alignment.
1273	@param	fno		Font number.
1274	@param	fsz		Font size in pt.
1275	@param	fex		Flag: Use exact font (1) or similar font (0).
1276	@param	uc2l	UC to LaTeX conversion structure.
1277	@param	flags	Text flags DK4_GRA_TEXT_FLAG_xxx, can be or-combined.
1278	@param	backptr	Address of success variable to reset on errors.
1279	@param	erp		Error report, may be NULL.
1280
1281	Error codes:
1282	- DK4_E_INVALID_ARGUMENTS<br>
1283	  if gra is NULL,
1284	- DK4_E_INVALID_ARGUMENTS<br>
1285	  if gra is not in a state allowing this operation,
1286	- DK4_E_MATH_OVERFLOW<br>
1287	  on numeric overflow in memory size calculation,
1288	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
1289	  if there is not enough memory available,
1290	- DK4_E_WRITE_FAILED<br>
1291	  if writing one ore multiple bytes to the stream failed,
1292	- DK4_E_FLUSH_FAILED<br>
1293	  if flushing data downwards failed.
1294*/
1295void
1296dk4pppt_simple_utf8_text(
1297	dk4_pppt_t			*pppt,
1298	double				 x,
1299	double				 y,
1300	double				 rot,
1301	const char			*txt,
1302	const char			*colspec,
1303	dk4_text_align_h_t	 ha,
1304	dk4_text_align_v_t	 va,
1305	int					 fno,
1306	double				 fsz,
1307	dk4_gra_tf_t		 fex,
1308	dk4_uc2l_t			*uc2l,
1309	int					 flags,
1310	int					*backptr,
1311	dk4_er_t			*erp
1312);
1313
1314
1315/**	Add special text to PGF graphics.
1316	The text is shown in the current fill color (non-stroking color)
1317	unless colspec is used to specify a color.
1318	@param	pppt	Output structure, must be initialized for PGF.
1319	@param	x		X coordinate.
1320	@param	y		Y coordinate.
1321	@param	rot		Rotation counterclockwise in degree.
1322	@param	txt		Text to show.
1323	@param	colspec	Color specification, may be NULL to use fill color.
1324	@param	ha		Horizontal alignment.
1325	@param	va		Vertical alignment.
1326	@param	fno		Font number.
1327	@param	fsz		Font size in pt.
1328	@param	fex		Flag: Use exact font.
1329	@param	flags	Text flags DK4_GRA_TEXT_FLAG_xxx, can be or-combined.
1330	@param	backptr	Address of success variable to reset on errors.
1331	@param	erp		Error report, may be NULL.
1332
1333	Error codes:
1334	- DK4_E_INVALID_ARGUMENTS<br>
1335	  if gra is NULL,
1336	- DK4_E_INVALID_ARGUMENTS<br>
1337	  if gra is not in a state allowing this operation,
1338	- DK4_E_MATH_OVERFLOW<br>
1339	  on numeric overflow in memory size calculation,
1340	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
1341	  if there is not enough memory available,
1342	- DK4_E_WRITE_FAILED<br>
1343	  if writing one ore multiple bytes to the stream failed,
1344	- DK4_E_FLUSH_FAILED<br>
1345	  if flushing data downwards failed.
1346*/
1347void
1348dk4pppt_special_text(
1349	dk4_pppt_t			*pppt,
1350	double				 x,
1351	double				 y,
1352	double				 rot,
1353	const char			*txt,
1354	const char			*colspec,
1355	dk4_text_align_h_t	 ha,
1356	dk4_text_align_v_t	 va,
1357	int					 fno,
1358	double				 fsz,
1359	dk4_gra_tf_t		 fex,
1360	int					 flags,
1361	int					*backptr,
1362	dk4_er_t			*erp
1363);
1364
1365
1366/**	Set flag for even-odd-rule.
1367	If this flag is on, the even-odd-rule is used for filling and
1368	clipping. Otherwise the nonzero-winding rule is used.
1369	By default this flag is turned on when creating a dk4_gra_t structure.
1370	@param	pppt	Output structure.
1371	@param	val		New flag value.
1372*/
1373void
1374dk4pppt_set_eorule(
1375	dk4_pppt_t	*pppt,
1376	int			 val
1377);
1378
1379
1380/**	Set document font size.
1381	@param	pppt	Output structure.
1382	@param	fs		New font size.
1383	@param	backptr	Address of success variable to reset on error.
1384	@param	erp		Error report, may be NULL.
1385*/
1386
1387void
1388dk4pppt_doc_font_size(
1389	dk4_pppt_t	*pppt,
1390	double		 fs,
1391	int			*backptr,
1392	dk4_er_t	*erp
1393);
1394
1395
1396/**	Add one preamble line.
1397	@param	pppt	Output structure.
1398	@param	line	Line to add without trailing newline.
1399	@param	tp		Preamble line type.
1400	@param	backptr	Address of success variable to reset on error.
1401	@param	erp		Error report, may be NULL.
1402*/
1403
1404void
1405dk4pppt_doc_preamble_line(
1406	dk4_pppt_t	*pppt,
1407	const char	*line,
1408	int			 tp,
1409	int			*backptr,
1410	dk4_er_t	*erp
1411);
1412
1413
1414
1415#ifdef	__cplusplus
1416}
1417#endif
1418
1419
1420/* vim: set ai sw=4 ts=4 : */
1421
1422%%	module
1423
1424#include "dk4conf.h"
1425
1426#ifdef	DK4_HAVE_MATH_H
1427#ifndef	MATH_H_INCLUDED
1428#define	_USE_MATH_DEFINES	1
1429#include <math.h>
1430#define	MATH_H_INCLUDED 1
1431#endif
1432#endif
1433
1434#ifndef	DK4PPPT_H_INCLUDED
1435#include <libdk4pppt/dk4pppt.h>
1436#endif
1437
1438#ifndef	GRA_H_INCLUDED
1439#include <libdk4gra/gra.h>
1440#endif
1441
1442#ifndef	DK4MEM_H_INCLUDED
1443#include <libdk4base/dk4mem.h>
1444#endif
1445
1446#ifndef	DK4ENC_H_INCLUDED
1447#include <libdk4c/dk4enc.h>
1448#endif
1449
1450#ifndef	DK4FOPD_H_INCLUDED
1451#include <libdk4c/dk4fopd.h>
1452#endif
1453
1454#ifndef	DK4STR8_H_INCLUDED
1455#include <libdk4base/dk4str8.h>
1456#endif
1457
1458#ifndef	DK4STRD_H_INCLUDED
1459#include <libdk4base/dk4strd.h>
1460#endif
1461
1462#ifndef	DK4STRMF_H_INCLUDED
1463#include <libdk4c/dk4strmf.h>
1464#endif
1465
1466#ifndef	DK4PATHD_H_INCLUDED
1467#include <libdk4c/dk4pathd.h>
1468#endif
1469
1470#ifndef	DK4MPL_H_INCLUDED
1471#include <libdk4base/dk4mpl.h>
1472#endif
1473
1474#ifndef	DK4ISADM_H_INCLUDED
1475#include <libdk4c/dk4isadm.h>
1476#endif
1477
1478#if DK4_HAVE_ASSERT_H
1479#ifndef	ASSERT_H_INCLUDED
1480#include <assert.h>
1481#define	ASSERT_H_INCLUDED 1
1482#endif
1483#endif
1484
1485
1486$!trace-include
1487
1488
1489
1490/**	Constant text fragments.
1491*/
1492static const dkChar * const	dk4pppt_dk_kw[] = {
1493$!string-table	macro=dkT
1494#
1495#	0-3		File name suffixes for graphics files.
1496#
1497-i.pdf
1498.pdf
1499.ps
1500.eps
1501$!end
1502};
1503
1504
1505
1506/**	Constant text fragments
1507*/
1508static const char * const	dk4pppt_c8_kw[] = {
1509$!string-table
1510#
1511#	0-3		Put instruction for text
1512#
1513\\put(
1514,
1515){
1516}%\n
1517#
1518#	4-12	makebox instructions with alignments
1519#
1520\\makebox(0,0)[lb]{
1521\\makebox(0,0)[b]{
1522\\makebox(0,0)[rb]{
1523\\makebox(0,0)[l]{
1524\\makebox(0,0){
1525\\makebox(0,0)[r]{
1526\\makebox(0,0)[lt]{
1527\\makebox(0,0)[t]{
1528\\makebox(0,0)[rt]{
1529#
1530#	13	Closing the makebox
1531#
1532}
1533#
1534#	14	Smash
1535#
1536\\smash{
1537#
1538#	15	Start group
1539#
1540{
1541#
1542#	16	Font command
1543#
1544\\PPPTfo
1545#
1546#	17-18	begin/end picture
1547#
1548\\begin{picture}(0,0)\n
1549\\end{picture}%\n\\setlength{\\unitlength}{1bp}%\n
1550#
1551#	19-20	Included image
1552#
1553\\includegraphics{
1554}\n
1555#
1556#	21		End picture
1557#
1558\\end{picture}%\n
1559#
1560#	22-23
1561#
1562\\begin{picture}(
1563)\n
1564#
1565#	24		Mark text as command
1566#
1567{}
1568#
1569#	25		Open white box
1570#
1571\\colorbox{white}{
1572#
1573#	26		Open oval box
1574#
1575\\ovalbox{
1576#
1577#	27		Rotatebox
1578#
1579\\rotatebox{
1580#
1581#	28		Separate degrees from text
1582#
1583}{
1584$!end
1585};
1586
1587
1588
1589/**	Reset a success variable.
1590	@param	backptr	Address of success variable to reset.
1591*/
1592static
1593void
1594dk4pppt_reset(int *backptr)
1595{
1596	if (NULL != backptr) {
1597		*backptr = 0;
1598	}
1599}
1600
1601
1602
1603/**	Check whether a value is within a specified range.
1604	@param	min	Minimum value (inclusive).
1605	@param	max	Maximum value (inclusive).
1606	@param	val	Value to check.
1607	@return	1 on success, 0 on error.
1608*/
1609static
1610int
1611dk4pppt_in_range(double min, double max, double val)
1612{
1613	int		 back = 0;
1614	if ((min <= val) && (max >= val)) {
1615		back = 1;
1616	}
1617	return back;
1618}
1619
1620
1621
1622/**	Release preamble lines.
1623	@param	ps	Preamble lines storage.
1624	@param	pi	Preamble lines iterator.
1625*/
1626static
1627void
1628dk4pppt_release_preamble_lines(
1629	dk4_sto_t		*ps,
1630	dk4_sto_it_t	*pi
1631)
1632{
1633	dk4_gra_preamble_line_t	*pl;
1634
1635	if (NULL != ps) {
1636		if (NULL != pi) {
1637			dk4sto_it_reset(pi);
1638			do {
1639				pl = (dk4_gra_preamble_line_t *)dk4sto_it_next(pi);
1640				if (NULL != pl) {
1641					dk4gratool_preamble_delete(pl);
1642				}
1643			} while (NULL != pl);
1644			dk4sto_it_close(pi);
1645		}
1646		dk4sto_close(ps);
1647	}
1648}
1649
1650
1651
1652void
1653dk4pppt_close(
1654	dk4_pppt_t			*pppt
1655)
1656{
1657	$? "+ dk4pppt_close"
1658#if	DK4_USE_ASSERT
1659	assert(NULL != pppt);
1660#endif
1661	if (NULL != pppt) {
1662		switch (pppt->dr) {
1663			case DK4_PPPT_DR_PGF : {
1664				if (NULL != pppt->out.pgf) {
1665					dk4gra_close(pppt->out.pgf);
1666					pppt->out.pgf = NULL;
1667				}
1668			} break;
1669			default : {		/* PDF+TeX or EPS+TeX */
1670				dk4pppt_release_preamble_lines(
1671					pppt->out.ppt.s_f, pppt->out.ppt.i_f
1672				);
1673				dk4pppt_release_preamble_lines(
1674					pppt->out.ppt.s_p, pppt->out.ppt.i_p
1675				);
1676				dk4pppt_release_preamble_lines(
1677					pppt->out.ppt.s_o, pppt->out.ppt.i_o
1678				);
1679				pppt->out.ppt.s_f =
1680				pppt->out.ppt.s_p =
1681				pppt->out.ppt.s_o = NULL;
1682				pppt->out.ppt.i_f =
1683				pppt->out.ppt.i_p =
1684				pppt->out.ppt.i_o = NULL;
1685				if (NULL != pppt->out.ppt.tms) {
1686					dk4stream_close(pppt->out.ppt.tms, NULL);
1687					pppt->out.ppt.tms = NULL;
1688				}
1689				if (NULL != pppt->out.ppt.tmb) {
1690					dk4membuf_close(pppt->out.ppt.tmb);
1691					pppt->out.ppt.tmb = NULL;
1692				}
1693				if (NULL != pppt->out.ppt.fc) {
1694					dk4fontc_close(pppt->out.ppt.fc);
1695					pppt->out.ppt.fc = NULL;
1696				}
1697				if (NULL != pppt->out.ppt.gra) {
1698					dk4gra_close(pppt->out.ppt.gra);
1699					pppt->out.ppt.gra = NULL;
1700				}
1701				if (NULL != pppt->out.ppt.tfn) {
1702					dk4mem_free(pppt->out.ppt.tfn);
1703					pppt->out.ppt.tfn = NULL;
1704				}
1705			} break;
1706		}
1707		dk4mem_free(pppt);
1708	}
1709	$? "- dk4pppt_close"
1710}
1711
1712
1713
1714/**	Open a PGF output structure.
1715	@param	texname	Name of TeX output file.
1716					The name ends on ".tex".
1717					The name of the included *.eps or *.pdf file
1718					is derived from this name.
1719	@param	dr		Output driver.
1720	@param	isdoc	Flag: Produce LaTeX document, not just image.
1721	@param	flags	Additional flags for graphics.
1722	@param	width	Image width in bp (PS point).
1723	@param	height	Image height in bp.
1724	@param	erp		Error report, may be NULL.
1725	@return	Valid pointer to new output structure on success, NULL on error.
1726*/
1727static
1728dk4_pppt_t *
1729dk4pppt_pgf_open(
1730	const dkChar		*texname,
1731	int					 isdoc,
1732	int					 flags,
1733	size_t				 width,
1734	size_t				 height,
1735	dk4_er_t			*erp
1736)
1737{
1738	dk4_pppt_t	*back	= NULL;
1739	$? "+ dk4pppt_pgf_open"
1740#if	DK4_USE_ASSERT
1741	assert(NULL != texname);
1742	assert(0 < width);
1743	assert(0 < height);
1744#endif
1745	back = dk4mem_new(dk4_pppt_t,1,erp);
1746	if (NULL != back) {
1747		DK4_MEMRES(back,sizeof(dk4_pppt_t));
1748		back->flags = flags;
1749		back->isdoc = isdoc;
1750		back->dr    = DK4_PPPT_DR_PGF;
1751		back->out.pgf = dk4gra_open_pgf(texname,width,height,flags,isdoc,erp);
1752		if (NULL == back->out.pgf) {
1753			dk4mem_free(back);
1754			back = NULL;
1755		}
1756	}
1757	$? "- dk4pppt_pgf_open %d", TR_IPTR(back)
1758	return back;
1759}
1760
1761
1762
1763/**	Construct output file name based on TeX file name.
1764	@param	obuf	Output buffer.
1765	@param	szobuf	Output buffer size (number of dkChar).
1766	@param	texname	TeX file name.
1767	@param	dr		Driver to produce name for.
1768	@param	flags	Document flags.
1769	@param	isdoc	Flag: Produce entire document.
1770	@param	erp		Error report, may be NULL.
1771	@return	1 on success, 0 on error (buffer too short).
1772*/
1773static
1774int
1775dk4pppt_construct_output_file_name(
1776	dkChar				*obuf,
1777	size_t				 szobuf,
1778	const dkChar 		*texname,
1779	dk4_pppt_driver_t	 dr,
1780	int					 flags,
1781	int					 isdoc,
1782	dk4_er_t			*erp
1783)
1784{
1785	dkChar	*psuffix	= NULL;		/* File name existing suffix */
1786	size_t	 kwi		= 0;		/* Keyword index for suffix to append */
1787	int		 back		= 0;
1788	$? "+ dk4pppt_construct_output_file_name"
1789#if	DK4_USE_ASSERT
1790	assert(NULL != obuf);
1791	assert(0 < szobuf);
1792	assert(NULL != texname);
1793#endif
1794	if (0 != dk4str_cpy_s(obuf, szobuf, texname, erp)) {
1795		psuffix = dk4path_get_suffix(obuf, NULL);
1796		if (NULL != psuffix) {
1797			*psuffix = dkT('\0');
1798		}
1799		kwi = 1;
1800		if (DK4_PPPT_DR_PDF_TEX == dr) {
1801			if (0 != isdoc) { kwi = 0; }
1802		}
1803		else {
1804			kwi = 2;
1805			if (0 != (DK4_GRA_DOC_FLAG_EPS & flags)) { kwi = 3; }
1806		}
1807		back = dk4str_cat_s(obuf, szobuf, dk4pppt_dk_kw[kwi], erp);
1808	}
1809	if (0 == back) { obuf[0] = dkT('\0'); }
1810	$? "- dk4pppt_construct_output_file_name %d \"%!ds\"", back, obuf
1811	return back;
1812}
1813
1814
1815
1816/**	Open a non-PGF output structure.
1817	@param	texname	Name of TeX output file.
1818					The name ends on ".tex".
1819					The name of the included *.eps or *.pdf file
1820					is derived from this name.
1821	@param	dr		Output driver.
1822	@param	isdoc	Flag: Produce LaTeX document, not just image.
1823	@param	flags	Additional flags for graphics.
1824	@param	width	Image width in bp (PS point).
1825	@param	height	Image height in bp.
1826	@param	erp		Error report, may be NULL.
1827	@return	Valid pointer to new output structure on success, NULL on error.
1828*/
1829static
1830dk4_pppt_t *
1831dk4pppt_ppt_open(
1832	const dkChar		*texname,
1833	dk4_pppt_driver_t	 dr,
1834	int					 isdoc,
1835	int					 flags,
1836	size_t				 width,
1837	size_t				 height,
1838	dk4_er_t			*erp
1839)
1840{
1841	dkChar				 ofnbuf[DK4_MAX_PATH];	/* Buffer to construct name */
1842#if DK4_CHAR_SIZE > 1
1843	char				 tb[DK4_MAX_PATH];		/* ANSI file name */
1844#endif
1845	dk4_pppt_t			*back	= NULL;			/* Function result */
1846	int					 res	= 0;			/* Operation result */
1847	int					 ok		= 0;			/* Flag: Everything ok */
1848	$? "+ dk4pppt_ppt_open"
1849#if	DK4_USE_ASSERT
1850	assert(NULL != texname);
1851#endif
1852	res = dk4pppt_construct_output_file_name(
1853		ofnbuf, DK4_SIZEOF(ofnbuf,dkChar), texname, dr, flags, isdoc, erp
1854	);
1855	if (0 != res) {
1856		back = dk4mem_new(dk4_pppt_t,1,erp);
1857		if (NULL != back) {
1858			DK4_MEMRES(back,sizeof(dk4_pppt_t));
1859			back->flags = flags;
1860			back->isdoc = isdoc;
1861			back->dr    = dr;
1862			back->out.ppt.tfn = NULL;
1863			back->out.ppt.gra = NULL;
1864			back->out.ppt.fc  = NULL;
1865			back->out.ppt.tmb = NULL;
1866			back->out.ppt.tms = NULL;
1867			back->out.ppt.s_f = NULL;
1868			back->out.ppt.i_f = NULL;
1869			back->out.ppt.s_p = NULL;
1870			back->out.ppt.i_p = NULL;
1871			back->out.ppt.s_o = NULL;
1872			back->out.ppt.i_o = NULL;
1873			back->out.ppt.dfs = -1.0;
1874			back->out.ppt.n_f = 0UL;
1875			back->out.ppt.n_p = 0UL;
1876			back->out.ppt.n_o = 0UL;
1877			back->out.ppt.tfn = dk4str_dup(texname, erp);
1878			if (NULL != back->out.ppt.tfn) {
1879				if (DK4_PPPT_DR_EPS_TEX == dr) {
1880					back->out.ppt.gra = dk4gra_open_ps(
1881						ofnbuf, width, height, flags, erp
1882					);
1883				}
1884				else {
1885					back->out.ppt.gra = dk4gra_open_pdf(
1886						ofnbuf, width, height, flags, erp
1887					);
1888				}
1889				if (NULL != back->out.ppt.gra) {
1890					back->out.ppt.fc = dk4fontc_open(erp);
1891					if (NULL != back->out.ppt.fc) {
1892						back->out.ppt.tmb = dk4membuf_open(erp);
1893						if (NULL != back->out.ppt.tmb) {
1894							back->out.ppt.tms = dk4stream_open_membuf_writer(
1895								back->out.ppt.tmb, erp
1896							);
1897							if (NULL != back->out.ppt.tms) {
1898#if DK4_CHAR_SIZE > 1
1899#if DK4_CHAR_SIZE > 2
1900								ok = dk4recode_dk_to_any(
1901									tb, sizeof(tb), DK4_FILE_ENCODING_WIN1252,
1902									ofnbuf, DK4_ENCODING_32, erp
1903								);
1904#else
1905								ok = dk4recode_dk_to_any(
1906									tb, sizeof(tb), DK4_FILE_ENCODING_WIN1252,
1907									ofnbuf, DK4_ENCODING_UTF16, erp
1908								);
1909#endif
1910#else
1911								ok = 1;
1912#endif
1913							}
1914						}
1915					}
1916				}
1917			}
1918			if (0 == ok) {
1919				dk4pppt_close(back);
1920				back = NULL;
1921			}
1922		}
1923	}
1924	$? "- dk4pppt_ppt_open"
1925	return back;
1926}
1927
1928
1929
1930dk4_pppt_t *
1931dk4pppt_open(
1932	const dkChar		*texname,
1933	dk4_pppt_driver_t	 dr,
1934	int					 isdoc,
1935	int					 flags,
1936	size_t				 width,
1937	size_t				 height,
1938	dk4_er_t			*erp
1939)
1940{
1941	dk4_pppt_t		*back	= NULL;
1942	int				 ok		= 1;
1943	$? "+ dk4pppt_open"
1944#if	DK4_USE_ASSERT
1945	assert(NULL != texname);
1946	assert(0 < width);
1947	assert(0 < height);
1948#endif
1949	if ((NULL != texname) && (0 < width) && (0 < height)) {
1950		switch (dr) {
1951			case DK4_PPPT_DR_PGF : {
1952				$? ". PGF"
1953				back = dk4pppt_pgf_open(
1954					texname, isdoc, flags, width, height, erp
1955				);
1956			} break;
1957			case DK4_PPPT_DR_EPS_TEX : {
1958				/*
1959					Cannot create document for PS output, check here
1960				*/
1961				$? ". not PGF (EPS/TeX)"
1962				if (0 == isdoc) {
1963					back = dk4pppt_ppt_open(
1964						texname, dr, isdoc, flags, width, height, erp
1965					);
1966				}
1967				else {
1968					dk4error_set_simple_error_code(erp,DK4_E_INVALID_ARGUMENTS);
1969				}
1970			} break;
1971			default : {		/* DK4_PPPT_DR_PDF_TEX */
1972				$? ". not PGF"
1973				back = dk4pppt_ppt_open(
1974					texname, dr, isdoc, flags, width, height, erp
1975				);
1976			} break;
1977		}
1978		if (NULL != back) {
1979			switch (dr) {
1980				case DK4_PPPT_DR_PGF : {
1981					dk4gra_page_with_flags(
1982						back->out.pgf, flags, &ok, erp
1983					);
1984				} break;
1985				default : {
1986					dk4gra_page_with_flags(
1987						back->out.ppt.gra, flags, &ok, erp
1988					);
1989				} break;
1990			}
1991			if (0 == ok) {
1992				dk4pppt_close(back);
1993				back = NULL;
1994			}
1995		}
1996	}
1997	else {
1998		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
1999	}
2000	$? "- dk4pppt_open %d", TR_IPTR(back)
2001	return back;
2002}
2003
2004
2005
2006/**	Check whether pppt object state grants graphics and text operations.
2007	@param	pppt	Structure to check.
2008	@return	1 on success, 0 on error.
2009*/
2010static
2011int
2012dk4pppt_is_state_ok(
2013	const dk4_pppt_t		*pppt
2014)
2015{
2016	int		 back	= 0;
2017
2018	/*	Check for valid pointer
2019	*/
2020	if (NULL == pppt) {
2021		goto finished;
2022	}
2023	/*	Remaining checks depend on driver
2024	*/
2025	switch (pppt->dr) {
2026		case DK4_PPPT_DR_PGF : {
2027			if (NULL != pppt->out.pgf) {
2028				back = 1;
2029			}
2030		} break;
2031		default : {
2032			if (NULL != pppt->out.ppt.gra) {
2033				if (NULL != pppt->out.ppt.fc) {
2034					if (NULL != pppt->out.ppt.tmb) {
2035						if (NULL != pppt->out.ppt.tms) {
2036							if (NULL != pppt->out.ppt.tfn) {
2037								back = 1;
2038							}
2039						}
2040					}
2041				}
2042			}
2043		} break;
2044	}
2045	finished:
2046	return back;
2047}
2048
2049
2050
2051/**	Convert backslashes to forward slashes for use of file name in LaTeX.
2052	@param	fn	String to correct.
2053*/
2054static
2055void
2056dk4pppt_to_slash(char *fn)
2057{
2058	while ('\0' != *fn) {
2059		if ('\\' == *fn) { *fn = '/'; }
2060		fn++;
2061	}
2062}
2063
2064
2065
2066/**	Write file name to includegraphics instruction.
2067	@param	ostrm	Destination output stream.
2068	@param	fn		File name to print.
2069	@param	backptr	Address of success variable to reset on error.
2070	@param	erp		Error report, may be NULL.
2071*/
2072static
2073void
2074dk4pppt_file_name_to_stream(
2075	dk4_stream_t	*ostrm,
2076	const dkChar	*fn,
2077	int				*backptr,
2078	dk4_er_t		*erp
2079)
2080{
2081	char		 buf[DK4_MAX_PATH];
2082	char		*p1		=	NULL;
2083	char		*p2		=	NULL;
2084	int			 res	=	0;
2085#if	DK4_USE_ASSERT
2086	assert(NULL != ostrm);
2087	assert(NULL != fn);
2088#endif
2089#if	DK4_CHAR_SIZE > 1
2090#if	DK4_CHAR_SIZE > 2
2091	res = dk4recode_dk_to_any(
2092		buf, sizeof(buf), DK4_FILE_ENCODING_WIN1252, fn, DK4_ENCODING_32, erp
2093	);
2094#else
2095	res = dk4recode_dk_to_any(
2096		buf, sizeof(buf), DK4_FILE_ENCODING_WIN1252, fn, DK4_ENCODING_UTF16, erp
2097	);
2098#endif
2099#else
2100	res = dk4str8_cpy_s(buf, sizeof(buf), fn, erp);
2101#endif
2102	if (0 != res) {
2103		dk4pppt_to_slash(buf);
2104		if (0 != dk4path_is_absolute(fn)) {
2105			res = dk4stream_write_char_string(ostrm, buf, erp);
2106			if (0 == res) {
2107				if (NULL != backptr) { *backptr = 0; }
2108			}
2109		}
2110		else {
2111			p2 = buf;
2112			while ('\0' != *p2) {
2113				if ('/' == *p2) { p1 = p2; }
2114				p2++;
2115			}
2116			if (NULL != p1) { p1++; }
2117			else { p1 = buf; }
2118			res = dk4stream_write_char_string(ostrm, p1, erp);
2119			if (0 == res) {
2120				if (NULL != backptr) { *backptr = 0; }
2121			}
2122		}
2123	}
2124	else {
2125		if (NULL != backptr) { *backptr = 0; }
2126	}
2127}
2128
2129
2130
2131/**	Write output data.
2132	@param	pppt	Output structure.
2133	@param	erp		Error report, may be NULL.
2134	@return	1 on success, 0 on error.
2135*/
2136static
2137int
2138dk4pppt_write(
2139	dk4_pppt_t			*pppt,
2140	dk4_er_t			*erp
2141)
2142{
2143	FILE			*fout	=	NULL;
2144	dk4_stream_t	*ostrm	=	NULL;
2145	int				 tests	=	DK4_FOPEN_SC_USER;
2146	int				 res	=	0;
2147	int				 back	=	0;
2148	$? "+ dk4pppt_write"
2149#if	DK4_USE_ASSERT
2150	assert(NULL != pppt);
2151#endif
2152	switch (pppt->dr) {
2153		case DK4_PPPT_DR_PGF : {
2154			back = 1;
2155			dk4gra_write_and_close(pppt->out.pgf, &back, erp);
2156			pppt->out.pgf = NULL;
2157		} break;
2158		default : {
2159			/*
2160				Write *.tex file first, as name of graphics file is in gra
2161			*/
2162			if (0 != dk4isadmin()) { tests = DK4_FOPEN_SC_PRIVILEGED; }
2163			fout = dk4fopen(pppt->out.ppt.tfn, dkT("wb"), tests, erp);
2164			if (NULL != fout) {
2165				ostrm = dk4stream_open_for_file(
2166					fout, DK4_STREAM_WRITE, 0, 0, erp
2167				);
2168				if (NULL != ostrm) {
2169					back = 1;
2170					if (0 != pppt->isdoc) {
2171						dk4gratool_start_standalone_document(
2172							ostrm, pppt->out.ppt.gra, 0, pppt->out.ppt.dfs,
2173							pppt->out.ppt.s_f, pppt->out.ppt.i_f,
2174							pppt->out.ppt.s_p, pppt->out.ppt.i_p,
2175							pppt->out.ppt.s_o, pppt->out.ppt.i_o,
2176							&back, erp
2177						);
2178					}
2179					dk4gratool_stream_string(
2180						ostrm, dk4pppt_c8_kw[17], &back, erp
2181					);
2182					dk4gratool_stream_string(
2183						ostrm, dk4pppt_c8_kw[19], &back, erp
2184					);
2185					dk4pppt_file_name_to_stream(
2186						ostrm, pppt->out.ppt.gra->fn, &back, erp
2187					);
2188					dk4gratool_stream_string(
2189						ostrm, dk4pppt_c8_kw[20], &back, erp
2190					);
2191					dk4gratool_stream_string(
2192						ostrm, dk4pppt_c8_kw[18], &back, erp
2193					);
2194					dk4gratool_font_definitions(
2195						ostrm, pppt->out.ppt.fc, &back, erp
2196					);
2197					dk4gratool_stream_string(
2198						ostrm, dk4pppt_c8_kw[22], &back, erp
2199					);
2200					dk4gratool_stream_uint(
2201						ostrm, pppt->out.ppt.gra->w, 0, &back, erp
2202					);
2203					dk4gratool_stream_string(
2204						ostrm, dk4pppt_c8_kw[1], &back, erp
2205					);
2206					dk4gratool_stream_uint(
2207						ostrm, pppt->out.ppt.gra->h, 0, &back, erp
2208					);
2209					dk4gratool_stream_string(
2210						ostrm, dk4pppt_c8_kw[23], &back, erp
2211					);
2212					if (NULL != pppt->out.ppt.tms) {
2213						if (0 == dk4stream_close(pppt->out.ppt.tms, erp)) {
2214							back = 0;
2215						}
2216						pppt->out.ppt.tms = NULL;
2217					}
2218					if (NULL != pppt->out.ppt.tmb) {
2219						res = dk4membuf_to_stream(ostrm,pppt->out.ppt.tmb,erp);
2220						if (0 == res) {
2221							back = 0;
2222						}
2223					}
2224					dk4gratool_stream_string(
2225						ostrm, dk4pppt_c8_kw[21], &back, erp
2226					);
2227					if (0 != pppt->isdoc) {
2228						dk4gratool_end_standalone_document(ostrm, &back, erp);
2229					}
2230					if (0 == dk4stream_close(ostrm, erp)) { back = 0; }
2231					/*
2232						Write and close the real graphics
2233					*/
2234					dk4gra_write_and_close(
2235						pppt->out.ppt.gra, &back, erp
2236					);
2237					pppt->out.ppt.gra = NULL;
2238				}
2239				if (0 != fclose(fout)) { back = 0; }
2240			}
2241		} break;
2242	}
2243	$? "- dk4pppt_write %d", back
2244	return back;
2245}
2246
2247
2248
2249int
2250dk4pppt_write_and_close(
2251	dk4_pppt_t			*pppt,
2252	dk4_er_t			*erp
2253)
2254{
2255	int			 back	= 0;
2256
2257	$? "+ dk4pppt_write_and_close"
2258#if	DK4_USE_ASSERT
2259	assert(NULL != pppt);
2260#endif
2261	if (NULL != pppt) {
2262		if (0 != dk4pppt_is_state_ok(pppt)) {
2263			back = dk4pppt_write(pppt, erp);
2264		}
2265		else {
2266			dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2267		}
2268		dk4pppt_close(pppt);
2269	}
2270	else {
2271		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2272	}
2273	$? "- dk4pppt_write_and_close %d", back
2274	return back;
2275}
2276
2277
2278
2279void
2280dk4pppt_set_gs_for_pattern_only(
2281	dk4_pppt_t		*pppt,
2282	int				 val,
2283	dk4_er_t		*erp
2284)
2285{
2286	$? "+ dk4pppt_set_gs_for_pattern_only"
2287#if	DK4_USE_ASSERT
2288	assert(NULL != pppt);
2289#endif
2290	if (0 != dk4pppt_is_state_ok(pppt)) {
2291		switch (pppt->dr) {
2292			case DK4_PPPT_DR_PGF : {
2293				dk4gra_set_gs_for_pattern_only(
2294					pppt->out.pgf, val, erp
2295				);
2296			} break;
2297			default : {
2298				dk4gra_set_gs_for_pattern_only(
2299					pppt->out.ppt.gra, val, erp
2300				);
2301			} break;
2302		}
2303	}
2304	else {
2305		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2306	}
2307	$? "- dk4pppt_set_gs_for_pattern_only"
2308}
2309
2310
2311
2312void
2313dk4pppt_gsave(
2314	dk4_pppt_t			*pppt,
2315	int					*backptr,
2316	dk4_er_t			*erp
2317)
2318{
2319	$? "+ dk4pppt_gsave"
2320#if	DK4_USE_ASSERT
2321	assert(NULL != pppt);
2322#endif
2323	if (0 != dk4pppt_is_state_ok(pppt)) {
2324		switch (pppt->dr) {
2325			case DK4_PPPT_DR_PGF : {
2326				dk4gra_gsave(pppt->out.pgf, backptr, erp);
2327			} break;
2328			default : {
2329				dk4gra_gsave(pppt->out.ppt.gra, backptr, erp);
2330			} break;
2331		}
2332	}
2333	else {
2334		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2335		dk4pppt_reset(backptr);
2336	}
2337	$? "- dk4pppt_gsave"
2338}
2339
2340
2341
2342void
2343dk4pppt_grestore(
2344	dk4_pppt_t			*pppt,
2345	int					*backptr,
2346	dk4_er_t			*erp
2347)
2348{
2349	$? "+ dk4pppt_grestore"
2350#if	DK4_USE_ASSERT
2351	assert(NULL != pppt);
2352#endif
2353	if (0 != dk4pppt_is_state_ok(pppt)) {
2354		switch (pppt->dr) {
2355			case DK4_PPPT_DR_PGF : {
2356				dk4gra_grestore(pppt->out.pgf, backptr, erp);
2357			} break;
2358			default : {
2359				dk4gra_grestore(pppt->out.ppt.gra, backptr, erp);
2360			} break;
2361		}
2362	}
2363	else {
2364		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2365		dk4pppt_reset(backptr);
2366	}
2367	$? "- dk4pppt_grestore"
2368}
2369
2370
2371
2372void
2373dk4pppt_set_line_width(
2374	dk4_pppt_t		*pppt,
2375	double			 lw,
2376	int				*backptr,
2377	dk4_er_t		*erp
2378)
2379{
2380	$? "+ dk4pppt_set_line_width"
2381#if	DK4_USE_ASSERT
2382	assert(NULL != pppt);
2383#endif
2384	if ((0 != dk4pppt_is_state_ok(pppt)) && (0.0 <= lw)) {
2385		switch (pppt->dr) {
2386			case DK4_PPPT_DR_PGF : {
2387				dk4gra_set_line_width(pppt->out.pgf, lw, backptr, erp);
2388			} break;
2389			default : {
2390				dk4gra_set_line_width(pppt->out.ppt.gra, lw, backptr, erp);
2391			} break;
2392		}
2393	}
2394	else {
2395		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2396		dk4pppt_reset(backptr);
2397	}
2398	$? "- dk4pppt_set_line_width"
2399}
2400
2401
2402
2403void
2404dk4pppt_set_line_style(
2405	dk4_pppt_t		*pppt,
2406	dk4_gra_ls_t	 ls,
2407	double			 sv,
2408	int				*backptr,
2409	dk4_er_t		*erp
2410)
2411{
2412	$? "+ dk4pppt_set_line_style"
2413#if	DK4_USE_ASSERT
2414	assert(NULL != pppt);
2415#endif
2416	if ((0 != dk4pppt_is_state_ok(pppt)) && (0.0 <= sv)) {
2417		switch (pppt->dr) {
2418			case DK4_PPPT_DR_PGF : {
2419				dk4gra_set_line_style(pppt->out.pgf, ls, sv, backptr, erp);
2420			} break;
2421			default : {
2422				dk4gra_set_line_style(pppt->out.ppt.gra, ls, sv, backptr, erp);
2423			} break;
2424		}
2425	}
2426	else {
2427		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2428		dk4pppt_reset(backptr);
2429	}
2430	$? "- dk4pppt_set_line_style"
2431}
2432
2433
2434
2435void
2436dk4pppt_set_line_cap(
2437	dk4_pppt_t		*pppt,
2438	dk4_gra_lc_t	 lc,
2439	int				*backptr,
2440	dk4_er_t		*erp
2441)
2442{
2443	$? "+ dk4pppt_set_line_cap"
2444#if	DK4_USE_ASSERT
2445	assert(NULL != pppt);
2446#endif
2447	if (0 != dk4pppt_is_state_ok(pppt)) {
2448		switch (pppt->dr) {
2449			case DK4_PPPT_DR_PGF : {
2450				dk4gra_set_line_cap(pppt->out.pgf, lc, backptr, erp);
2451			} break;
2452			default : {
2453				dk4gra_set_line_cap(pppt->out.ppt.gra, lc, backptr, erp);
2454			} break;
2455		}
2456	}
2457	else {
2458		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2459		dk4pppt_reset(backptr);
2460	}
2461	$? "- dk4pppt_set_line_cap"
2462}
2463
2464
2465
2466void
2467dk4pppt_set_line_join(
2468	dk4_pppt_t		*pppt,
2469	dk4_gra_lj_t	 lj,
2470	double			 ml,
2471	int				*backptr,
2472	dk4_er_t		*erp
2473)
2474{
2475	$? "+ dk4pppt_set_line_join"
2476#if	DK4_USE_ASSERT
2477	assert(NULL != pppt);
2478#endif
2479	if (0 != dk4pppt_is_state_ok(pppt)) {
2480		switch (pppt->dr) {
2481			case DK4_PPPT_DR_PGF : {
2482				dk4gra_set_line_join(pppt->out.pgf, lj, ml, backptr, erp);
2483			} break;
2484			default : {
2485				dk4gra_set_line_join(pppt->out.ppt.gra, lj, ml, backptr, erp);
2486			} break;
2487		}
2488	}
2489	else {
2490		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2491		dk4pppt_reset(backptr);
2492	}
2493	$? "- dk4pppt_set_line_join"
2494}
2495
2496
2497
2498void
2499dk4pppt_set_fill_gray(
2500	dk4_pppt_t		*pppt,
2501	double			 g,
2502	int				*backptr,
2503	dk4_er_t		*erp
2504)
2505{
2506	$? "+ dk4pppt_set_fill_gray"
2507#if	DK4_USE_ASSERT
2508	assert(NULL != pppt);
2509#endif
2510	if ((0 != dk4pppt_is_state_ok(pppt)) && (0.0 <= g) && (1.0 >= g)) {
2511		switch (pppt->dr) {
2512			case DK4_PPPT_DR_PGF : {
2513				dk4gra_set_fill_gray(pppt->out.pgf, g, backptr, erp);
2514			} break;
2515			default : {
2516				dk4gra_set_fill_gray(pppt->out.ppt.gra, g, backptr, erp);
2517			} break;
2518		}
2519	}
2520	else {
2521		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2522		dk4pppt_reset(backptr);
2523	}
2524	$? "- dk4pppt_set_fill_gray"
2525}
2526
2527
2528
2529void
2530dk4pppt_set_fill_rgb(
2531	dk4_pppt_t		*pppt,
2532	double			 r,
2533	double			 g,
2534	double			 b,
2535	int				*backptr,
2536	dk4_er_t		*erp
2537)
2538{
2539	$? "+ dk4pppt_set_fill_rgb"
2540#if	DK4_USE_ASSERT
2541	assert(NULL != pppt);
2542#endif
2543	if ((0 != dk4pppt_is_state_ok(pppt))
2544		&& (dk4pppt_in_range(0.0, 1.0, r))
2545		&& (dk4pppt_in_range(0.0, 1.0, g))
2546		&& (dk4pppt_in_range(0.0, 1.0, b))
2547	)
2548	{
2549		switch (pppt->dr) {
2550			case DK4_PPPT_DR_PGF : {
2551				$? ". PGF"
2552				dk4gra_set_fill_rgb(pppt->out.pgf, r, g, b, backptr, erp);
2553			} break;
2554			default : {
2555				$? ". not PGF"
2556				dk4gra_set_fill_rgb(pppt->out.ppt.gra, r, g, b, backptr, erp);
2557			} break;
2558		}
2559	}
2560	else {
2561		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2562		dk4pppt_reset(backptr);
2563	}
2564	$? "- dk4pppt_set_fill_rgb"
2565}
2566
2567
2568
2569void
2570dk4pppt_set_fill_cmyk(
2571	dk4_pppt_t		*pppt,
2572	double			 c,
2573	double			 m,
2574	double			 y,
2575	double			 k,
2576	int				*backptr,
2577	dk4_er_t		*erp
2578)
2579{
2580	$? "+ dk4pppt_set_fill_cmyk"
2581#if	DK4_USE_ASSERT
2582	assert(NULL != pppt);
2583#endif
2584	if ((0 != dk4pppt_is_state_ok(pppt))
2585		 && (dk4pppt_in_range(0.0, 1.0, c)) && (dk4pppt_in_range(0.0, 1.0, m))
2586		 && (dk4pppt_in_range(0.0, 1.0, y)) && (dk4pppt_in_range(0.0, 1.0, k))
2587	) {
2588		switch (pppt->dr) {
2589			case DK4_PPPT_DR_PGF : {
2590				dk4gra_set_fill_cmyk(pppt->out.pgf, c, m, y, k, backptr, erp);
2591			} break;
2592			default : {
2593				dk4gra_set_fill_cmyk(pppt->out.ppt.gra,c,m,y,k,backptr,erp);
2594			} break;
2595		}
2596	}
2597	else {
2598		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2599		dk4pppt_reset(backptr);
2600	}
2601	$? "- dk4pppt_set_fill_cmyk"
2602}
2603
2604
2605
2606void
2607dk4pppt_set_stroke_gray(
2608	dk4_pppt_t		*pppt,
2609	double			 g,
2610	int				*backptr,
2611	dk4_er_t		*erp
2612)
2613{
2614	$? "+ dk4pppt_set_stroke_gray"
2615#if	DK4_USE_ASSERT
2616	assert(NULL != pppt);
2617#endif
2618	if ((0 != dk4pppt_is_state_ok(pppt)) && (dk4pppt_in_range(0.0, 1.0, g))) {
2619		switch (pppt->dr) {
2620			case DK4_PPPT_DR_PGF : {
2621				dk4gra_set_stroke_gray(pppt->out.pgf, g, backptr, erp);
2622			} break;
2623			default : {
2624				dk4gra_set_stroke_gray(pppt->out.ppt.gra, g, backptr, erp);
2625			} break;
2626		}
2627	}
2628	else {
2629		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2630		dk4pppt_reset(backptr);
2631	}
2632	$? "- dk4pppt_set_stroke_gray"
2633}
2634
2635
2636
2637void
2638dk4pppt_set_stroke_rgb(
2639	dk4_pppt_t		*pppt,
2640	double			 r,
2641	double			 g,
2642	double			 b,
2643	int				*backptr,
2644	dk4_er_t		*erp
2645)
2646{
2647	$? "+ dk4pppt_set_stroke_rgb"
2648#if	DK4_USE_ASSERT
2649	assert(NULL != pppt);
2650#endif
2651	if (
2652		(0 != dk4pppt_is_state_ok(pppt)) && (dk4pppt_in_range(0.0, 1.0, r))
2653		&& (dk4pppt_in_range(0.0, 1.0, g)) && (dk4pppt_in_range(0.0, 1.0, b))
2654	) {
2655		switch (pppt->dr) {
2656			case DK4_PPPT_DR_PGF : {
2657				dk4gra_set_stroke_rgb(pppt->out.pgf, r, g, b, backptr, erp);
2658			} break;
2659			default : {
2660				dk4gra_set_stroke_rgb(pppt->out.ppt.gra, r, g, b, backptr, erp);
2661			} break;
2662		}
2663	}
2664	else {
2665		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2666		dk4pppt_reset(backptr);
2667	}
2668	$? "- dk4pppt_set_stroke_rgb"
2669}
2670
2671
2672
2673void
2674dk4pppt_set_stroke_cmyk(
2675	dk4_pppt_t		*pppt,
2676	double			 c,
2677	double			 m,
2678	double			 y,
2679	double			 k,
2680	int				*backptr,
2681	dk4_er_t		*erp
2682)
2683{
2684	$? "+ dk4pppt_set_stroke_cmyk"
2685#if	DK4_USE_ASSERT
2686	assert(NULL != pppt);
2687#endif
2688	if (
2689		(0 != dk4pppt_is_state_ok(pppt))
2690		&& (dk4pppt_in_range(0.0, 1.0, c)) && (dk4pppt_in_range(0.0, 1.0, m))
2691		&& (dk4pppt_in_range(0.0, 1.0, y)) && (dk4pppt_in_range(0.0, 1.0, k))
2692	) {
2693		switch (pppt->dr) {
2694			case DK4_PPPT_DR_PGF : {
2695				dk4gra_set_stroke_cmyk(pppt->out.pgf, c, m, y, k, backptr, erp);
2696			} break;
2697			default : {
2698				dk4gra_set_stroke_cmyk(pppt->out.ppt.gra,c,m,y,k,backptr,erp);
2699			} break;
2700		}
2701	}
2702	else {
2703		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2704		dk4pppt_reset(backptr);
2705	}
2706	$? "- dk4pppt_set_stroke_cmyk"
2707}
2708
2709
2710
2711void
2712dk4pppt_prepare_fill(
2713	dk4_pppt_t	*pppt,
2714	int			*backptr,
2715	dk4_er_t	*erp
2716)
2717{
2718	$? "+ dk4pppt_prepare_fill"
2719#if	DK4_USE_ASSERT
2720	assert(NULL != pppt);
2721#endif
2722	if (0 != dk4pppt_is_state_ok(pppt)) {
2723		switch (pppt->dr) {
2724			case DK4_PPPT_DR_PGF : {
2725				dk4gra_prepare_fill(pppt->out.pgf, backptr, erp);
2726			} break;
2727			default : {
2728				dk4gra_prepare_fill(pppt->out.ppt.gra, backptr, erp);
2729			} break;
2730		}
2731	}
2732	else {
2733		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2734		dk4pppt_reset(backptr);
2735	}
2736	$? "- dk4pppt_prepare_fill"
2737}
2738
2739
2740
2741void
2742dk4pppt_prepare_stroke(
2743	dk4_pppt_t	*pppt,
2744	int			*backptr,
2745	dk4_er_t	*erp
2746)
2747{
2748	$? "+ dk4pppt_prepare_stroke"
2749#if	DK4_USE_ASSERT
2750	assert(NULL != pppt);
2751#endif
2752	if (0 != dk4pppt_is_state_ok(pppt)) {
2753		switch (pppt->dr) {
2754			case DK4_PPPT_DR_PGF : {
2755				dk4gra_prepare_stroke(pppt->out.pgf, backptr, erp);
2756			} break;
2757			default : {
2758				dk4gra_prepare_stroke(pppt->out.ppt.gra, backptr, erp);
2759			} break;
2760		}
2761	}
2762	else {
2763		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2764		dk4pppt_reset(backptr);
2765	}
2766	$? "- dk4pppt_prepare_stroke"
2767}
2768
2769
2770
2771void
2772dk4pppt_prepare_fill_and_stroke(
2773	dk4_pppt_t	*pppt,
2774	int			*backptr,
2775	dk4_er_t	*erp
2776)
2777{
2778	$? "+ dk4pppt_prepare_fill_and_stroke"
2779#if	DK4_USE_ASSERT
2780	assert(NULL != pppt);
2781#endif
2782	if (0 != dk4pppt_is_state_ok(pppt)) {
2783		switch (pppt->dr) {
2784			case DK4_PPPT_DR_PGF : {
2785				dk4gra_prepare_fill_and_stroke(pppt->out.pgf, backptr, erp);
2786			} break;
2787			default : {
2788				dk4gra_prepare_fill_and_stroke(pppt->out.ppt.gra, backptr, erp);
2789			} break;
2790		}
2791	}
2792	else {
2793		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2794		dk4pppt_reset(backptr);
2795	}
2796	$? "- dk4pppt_prepare_fill_and_stroke"
2797}
2798
2799
2800
2801int
2802dk4pppt_can_fill_and_stroke(
2803	const dk4_pppt_t	*pppt
2804)
2805{
2806	int		 back	= 0;
2807	$? "+ dk4pppt_can_fill_and_stroke"
2808#if	DK4_USE_ASSERT
2809	assert(NULL != pppt);
2810#endif
2811	if (0 != dk4pppt_is_state_ok(pppt)) {
2812		switch (pppt->dr) {
2813			case DK4_PPPT_DR_PGF : {
2814				back = dk4gra_can_fill_and_stroke(pppt->out.pgf);
2815			} break;
2816			default : {
2817				back = dk4gra_can_fill_and_stroke(pppt->out.ppt.gra);
2818			} break;
2819		}
2820	}
2821	$? "- dk4pppt_can_fill_and_stroke %d", back
2822	return back;
2823}
2824
2825
2826
2827void
2828dk4pppt_fill(
2829	dk4_pppt_t	*pppt,
2830	int			*backptr,
2831	dk4_er_t	*erp
2832)
2833{
2834	$? "+ dk4pppt_fill"
2835#if	DK4_USE_ASSERT
2836	assert(NULL != pppt);
2837#endif
2838	if (0 != dk4pppt_is_state_ok(pppt)) {
2839		switch (pppt->dr) {
2840			case DK4_PPPT_DR_PGF : {
2841				dk4gra_fill(pppt->out.pgf, backptr, erp);
2842			} break;
2843			default : {
2844				dk4gra_fill(pppt->out.ppt.gra, backptr, erp);
2845			} break;
2846		}
2847	}
2848	else {
2849		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2850		dk4pppt_reset(backptr);
2851	}
2852	$? "- dk4pppt_fill"
2853}
2854
2855
2856
2857void
2858dk4pppt_stroke(
2859	dk4_pppt_t	*pppt,
2860	int			*backptr,
2861	dk4_er_t	*erp
2862)
2863{
2864	$? "+ dk4pppt_stroke"
2865#if	DK4_USE_ASSERT
2866	assert(NULL != pppt);
2867#endif
2868	if (0 != dk4pppt_is_state_ok(pppt)) {
2869		switch (pppt->dr) {
2870			case DK4_PPPT_DR_PGF : {
2871				dk4gra_stroke(pppt->out.pgf, backptr, erp);
2872			} break;
2873			default : {
2874				dk4gra_stroke(pppt->out.ppt.gra, backptr, erp);
2875			} break;
2876		}
2877	}
2878	else {
2879		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2880		dk4pppt_reset(backptr);
2881	}
2882	$? "- dk4pppt_stroke"
2883}
2884
2885
2886
2887void
2888dk4pppt_fill_and_stroke(
2889	dk4_pppt_t	*pppt,
2890	int			*backptr,
2891	dk4_er_t	*erp
2892)
2893{
2894	$? "+ dk4pppt_fill_and_stroke"
2895#if	DK4_USE_ASSERT
2896	assert(NULL != pppt);
2897#endif
2898	if (0 != dk4pppt_is_state_ok(pppt)) {
2899		switch (pppt->dr) {
2900			case DK4_PPPT_DR_PGF : {
2901				dk4gra_fill_and_stroke(pppt->out.pgf, backptr, erp);
2902			} break;
2903			default : {
2904				dk4gra_fill_and_stroke(pppt->out.ppt.gra, backptr, erp);
2905			} break;
2906		}
2907	}
2908	else {
2909		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2910		dk4pppt_reset(backptr);
2911	}
2912	$? "- dk4pppt_fill_and_stroke"
2913}
2914
2915
2916
2917void
2918dk4pppt_clip(
2919	dk4_pppt_t	*pppt,
2920	int			*backptr,
2921	dk4_er_t	*erp
2922)
2923{
2924	$? "+ dk4pppt_clip"
2925#if	DK4_USE_ASSERT
2926	assert(NULL != pppt);
2927#endif
2928	if (0 != dk4pppt_is_state_ok(pppt)) {
2929		switch (pppt->dr) {
2930			case DK4_PPPT_DR_PGF : {
2931				dk4gra_clip(pppt->out.pgf, backptr, erp);
2932			} break;
2933			default : {
2934				dk4gra_clip(pppt->out.ppt.gra, backptr, erp);
2935			} break;
2936		}
2937	}
2938	else {
2939		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2940		dk4pppt_reset(backptr);
2941	}
2942	$? "- dk4pppt_clip"
2943}
2944
2945
2946
2947void
2948dk4pppt_set_pattern_line_width(
2949	dk4_pppt_t	*pppt,
2950	double		 plw
2951)
2952{
2953#if	DK4_USE_ASSERT
2954	assert(NULL != pppt);
2955#endif
2956	if (NULL != pppt) {
2957		switch (pppt->dr) {
2958			case DK4_PPPT_DR_PGF : {
2959				dk4gra_set_pattern_line_width(pppt->out.pgf, plw);
2960			} break;
2961			default : {
2962				dk4gra_set_pattern_line_width(pppt->out.ppt.gra, plw);
2963			} break;
2964		}
2965	}
2966}
2967
2968
2969
2970void
2971dk4pppt_pattern(
2972	dk4_pppt_t			*pppt,
2973	double				 xl,
2974	double				 xr,
2975	double				 yb,
2976	double				 yt,
2977	dk4_gra_pattern_t	 pn,
2978	int					*backptr,
2979	dk4_er_t			*erp
2980)
2981{
2982	$? "+ dk4pppt_pattern"
2983#if	DK4_USE_ASSERT
2984	assert(NULL != pppt);
2985#endif
2986	if (0 != dk4pppt_is_state_ok(pppt)) {
2987		switch (pppt->dr) {
2988			case DK4_PPPT_DR_PGF : {
2989				dk4gra_pattern(pppt->out.pgf, xl, xr, yb, yt, pn, backptr, erp);
2990			} break;
2991			default : {
2992				dk4gra_pattern(pppt->out.ppt.gra,xl,xr,yb,yt,pn,backptr,erp);
2993			} break;
2994		}
2995	}
2996	else {
2997		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
2998		dk4pppt_reset(backptr);
2999	}
3000	$? "- dk4pppt_pattern"
3001}
3002
3003
3004
3005void
3006dk4pppt_newpath_moveto(
3007	dk4_pppt_t	*pppt,
3008	double		 x,
3009	double		 y,
3010	dk4_bb_t	*bbptr,
3011	int			*backptr,
3012	dk4_er_t	*erp
3013)
3014{
3015	$? "+ dk4pppt_newpath_moveto"
3016#if	DK4_USE_ASSERT
3017	assert(NULL != pppt);
3018#endif
3019	if (0 != dk4pppt_is_state_ok(pppt)) {
3020		switch (pppt->dr) {
3021			case DK4_PPPT_DR_PGF : {
3022				$? ". PGF"
3023				dk4gra_newpath_moveto(pppt->out.pgf, x, y, bbptr, backptr, erp);
3024			} break;
3025			default : {
3026				$? ". not PGF"
3027				dk4gra_newpath_moveto(pppt->out.ppt.gra,x,y,bbptr,backptr,erp);
3028			} break;
3029		}
3030	}
3031	else {
3032		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3033		dk4pppt_reset(backptr);
3034	}
3035	$? "- dk4pppt_newpath_moveto"
3036}
3037
3038
3039
3040void
3041dk4pppt_lineto(
3042	dk4_pppt_t	*pppt,
3043	double		 x,
3044	double		 y,
3045	dk4_bb_t	*bbptr,
3046	int			*backptr,
3047	dk4_er_t	*erp
3048)
3049{
3050	$? "+ dk4pppt_lineto"
3051#if	DK4_USE_ASSERT
3052	assert(NULL != pppt);
3053#endif
3054	if (0 != dk4pppt_is_state_ok(pppt)) {
3055		switch (pppt->dr) {
3056			case DK4_PPPT_DR_PGF : {
3057				dk4gra_lineto(pppt->out.pgf, x, y, bbptr, backptr, erp);
3058			} break;
3059			default : {
3060				dk4gra_lineto(pppt->out.ppt.gra, x, y, bbptr, backptr, erp);
3061			} break;
3062		}
3063	}
3064	else {
3065		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3066		dk4pppt_reset(backptr);
3067	}
3068	$? "- dk4pppt_lineto"
3069}
3070
3071
3072
3073void
3074dk4pppt_curveto(
3075	dk4_pppt_t	*pppt,
3076	double		 xc1,
3077	double		 yc1,
3078	double		 xc2,
3079	double		 yc2,
3080	double		 x,
3081	double		 y,
3082	dk4_bb_t	*bbptr,
3083	int			*backptr,
3084	dk4_er_t	*erp
3085)
3086{
3087	$? "+ dk4pppt_curveto"
3088#if	DK4_USE_ASSERT
3089	assert(NULL != pppt);
3090#endif
3091	if (0 != dk4pppt_is_state_ok(pppt)) {
3092		switch (pppt->dr) {
3093			case DK4_PPPT_DR_PGF : {
3094				dk4gra_curveto(
3095					pppt->out.pgf, xc1, yc1, xc2, yc2, x, y, bbptr, backptr, erp
3096				);
3097			} break;
3098			default : {
3099				dk4gra_curveto(
3100					pppt->out.ppt.gra,xc1,yc1,xc2,yc2,x,y,bbptr,backptr,erp
3101				);
3102			} break;
3103		}
3104	}
3105	else {
3106		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3107		dk4pppt_reset(backptr);
3108	}
3109	$? "- dk4pppt_curveto"
3110}
3111
3112
3113
3114void
3115dk4pppt_closepath(
3116	dk4_pppt_t	*pppt,
3117	int			*backptr,
3118	dk4_er_t	*erp
3119)
3120{
3121	$? "+ dk4pppt_closepath"
3122#if	DK4_USE_ASSERT
3123	assert(NULL != pppt);
3124#endif
3125	if (0 != dk4pppt_is_state_ok(pppt)) {
3126		switch (pppt->dr) {
3127			case DK4_PPPT_DR_PGF : {
3128				dk4gra_closepath(pppt->out.pgf, backptr, erp);
3129			} break;
3130			default : {
3131				dk4gra_closepath(pppt->out.ppt.gra, backptr, erp);
3132			} break;
3133		}
3134	}
3135	else {
3136		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3137		dk4pppt_reset(backptr);
3138	}
3139	$? "- dk4pppt_closepath"
3140}
3141
3142
3143
3144void
3145dk4pppt_bif_fig_image(
3146	dk4_pppt_t		*pppt,
3147	double			 xl,
3148	double			 xr,
3149	double			 yb,
3150	double			 yt,
3151	dk4_bif_t		*bif,
3152	const dkChar	*fn,
3153	size_t			 fno,
3154	int				 pos,
3155	int				 ifl,
3156	dk4_bb_t		*bbptr,
3157	int				*backptr,
3158	dk4_er_t		*erp
3159)
3160{
3161	$? "+ dk4pppt_bif_fig_image"
3162#if	DK4_USE_ASSERT
3163	assert(NULL != pppt);
3164	assert(NULL != bif);
3165#endif
3166	if (0 != dk4pppt_is_state_ok(pppt)) {
3167		switch (pppt->dr) {
3168			case DK4_PPPT_DR_PGF : {
3169				dk4gra_bif_fig_image(
3170					pppt->out.pgf, xl, xr, yb, yt, bif, fn, fno,
3171					pos, ifl, bbptr, backptr, erp
3172				);
3173			} break;
3174			default : {
3175				dk4gra_bif_fig_image(
3176					pppt->out.ppt.gra,
3177					xl, xr, yb, yt, bif, fn, fno,
3178					pos, ifl, bbptr, backptr, erp
3179				);
3180			} break;
3181		}
3182	}
3183	else {
3184		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3185		dk4pppt_reset(backptr);
3186	}
3187	$? "- dk4pppt_bif_fig_image"
3188}
3189
3190
3191void
3192dk4pppt_bif_image(
3193	dk4_pppt_t		*pppt,
3194	double			 xl,
3195	double			 xr,
3196	double			 yb,
3197	double			 yt,
3198	dk4_bif_t		*bif,
3199	const dkChar	*fn,
3200	size_t			 fno,
3201	int				 ifl,
3202	dk4_bb_t		*bbptr,
3203	int				*backptr,
3204	dk4_er_t		*erp
3205)
3206{
3207	$? "+ dk4pppt_bif_image"
3208#if	DK4_USE_ASSERT
3209	assert(NULL != pppt);
3210	assert(NULL != bif);
3211#endif
3212	if (0 != dk4pppt_is_state_ok(pppt)) {
3213		switch (pppt->dr) {
3214			case DK4_PPPT_DR_PGF : {
3215				dk4gra_bif_image(
3216					pppt->out.pgf, xl, xr, yb, yt, bif, fn, fno,
3217					ifl, bbptr, backptr, erp
3218				);
3219			} break;
3220			default : {
3221				dk4gra_bif_image(
3222					pppt->out.ppt.gra, xl, xr, yb, yt, bif, fn, fno,
3223					ifl, bbptr, backptr, erp
3224				);
3225			} break;
3226		}
3227	}
3228	else {
3229		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3230		dk4pppt_reset(backptr);
3231	}
3232	$? "- dk4pppt_bif_image"
3233}
3234
3235
3236
3237void
3238dk4pppt_image(
3239	dk4_pppt_t			*pppt,
3240	double				 xl,
3241	double				 xr,
3242	double				 yb,
3243	double				 yt,
3244	const dkChar		*fn,
3245	size_t				 fno,
3246	dk4_cs_conv_ctx_t	*ctx,
3247	int					 ifl,
3248	dk4_bb_t			*bbptr,
3249	int					*backptr,
3250	dk4_er_t			*erp
3251)
3252{
3253	$? "+ dk4pppt_image"
3254#if	DK4_USE_ASSERT
3255	assert(NULL != pppt);
3256	assert(NULL != fn);
3257#endif
3258	if (0 != dk4pppt_is_state_ok(pppt)) {
3259		switch (pppt->dr) {
3260			case DK4_PPPT_DR_PGF : {
3261				dk4gra_image(
3262					pppt->out.pgf, xl, xr, yb, yt, fn, fno, ctx,
3263					ifl, bbptr, backptr, erp
3264				);
3265			} break;
3266			default : {
3267				dk4gra_image(
3268					pppt->out.ppt.gra, xl, xr, yb, yt, fn, fno, ctx,
3269					ifl, bbptr, backptr, erp
3270				);
3271
3272			} break;
3273		}
3274	}
3275	else {
3276		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3277		dk4pppt_reset(backptr);
3278	}
3279	$? "- dk4pppt_image"
3280}
3281
3282
3283
3284void
3285dk4pppt_fig_image(
3286	dk4_pppt_t			*pppt,
3287	double				 xl,
3288	double				 xr,
3289	double				 yb,
3290	double				 yt,
3291	const dkChar		*fn,
3292	size_t				 fno,
3293	dk4_cs_conv_ctx_t	*ctx,
3294	int					 pos,
3295	int					 ifl,
3296	dk4_bb_t			*bbptr,
3297	int					*backptr,
3298	dk4_er_t			*erp
3299)
3300{
3301	$? "+ dk4pppt_fig_image"
3302#if	DK4_USE_ASSERT
3303	assert(NULL != pppt);
3304	assert(NULL != fn);
3305#endif
3306	if (0 != dk4pppt_is_state_ok(pppt)) {
3307		switch (pppt->dr) {
3308			case DK4_PPPT_DR_PGF : {
3309				dk4gra_fig_image(
3310					pppt->out.pgf, xl, xr, yb, yt, fn, fno, ctx,
3311					pos, ifl, bbptr, backptr, erp
3312				);
3313			} break;
3314			default : {
3315				dk4gra_fig_image(
3316					pppt->out.ppt.gra, xl, xr, yb, yt, fn, fno, ctx,
3317					pos, ifl, bbptr, backptr, erp
3318				);
3319			} break;
3320		}
3321	}
3322	else {
3323		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3324		dk4pppt_reset(backptr);
3325	}
3326	$? "- dk4pppt_fig_image"
3327}
3328
3329
3330
3331void
3332dk4pppt_circle(
3333	dk4_pppt_t	*pppt,
3334	double		 xc,
3335	double		 yc,
3336	double		 r,
3337	dk4_bb_t	*bbptr,
3338	int			*backptr,
3339	dk4_er_t	*erp
3340)
3341{
3342	$? "+ dk4pppt_circle"
3343#if	DK4_USE_ASSERT
3344	assert(NULL != pppt);
3345#endif
3346	if (0 != dk4pppt_is_state_ok(pppt)) {
3347		switch (pppt->dr) {
3348			case DK4_PPPT_DR_PGF : {
3349				dk4gra_circle(pppt->out.pgf, xc, yc, r, bbptr, backptr, erp);
3350			} break;
3351			default : {
3352				dk4gra_circle(pppt->out.ppt.gra,xc,yc,r,bbptr,backptr,erp);
3353			} break;
3354		}
3355	}
3356	else {
3357		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3358		dk4pppt_reset(backptr);
3359	}
3360	$? "- dk4pppt_circle"
3361}
3362
3363
3364
3365void
3366dk4pppt_rectangle(
3367	dk4_pppt_t	*pppt,
3368	double		 xl,
3369	double		 xr,
3370	double		 yb,
3371	double		 yt,
3372	double		 r,
3373	dk4_bb_t	*bbptr,
3374	int			*backptr,
3375	dk4_er_t	*erp
3376)
3377{
3378	$? "+ dk4pppt_rectangle"
3379#if	DK4_USE_ASSERT
3380	assert(NULL != pppt);
3381#endif
3382	if (0 != dk4pppt_is_state_ok(pppt)) {
3383		switch (pppt->dr) {
3384			case DK4_PPPT_DR_PGF : {
3385				dk4gra_rectangle(pppt->out.pgf,xl,xr,yb,yt,r,bbptr,backptr,erp);
3386			} break;
3387			default : {
3388				dk4gra_rectangle(
3389					pppt->out.ppt.gra, xl, xr, yb, yt, r, bbptr, backptr, erp
3390				);
3391			} break;
3392		}
3393	}
3394	else {
3395		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3396		dk4pppt_reset(backptr);
3397	}
3398	$? "- dk4pppt_rectangle"
3399}
3400
3401
3402
3403void
3404dk4pppt_arc(
3405	dk4_pppt_t	*pppt,
3406	double		 xc,
3407	double		 yc,
3408	double		 ra,
3409	double		 start,
3410	double		 end,
3411	int			 cl,
3412	dk4_bb_t	*bbptr,
3413	int			*backptr,
3414	dk4_er_t	*erp
3415)
3416{
3417	$? "+ dk4pppt_arc"
3418#if	DK4_USE_ASSERT
3419	assert(NULL != pppt);
3420#endif
3421	if (0 != dk4pppt_is_state_ok(pppt)) {
3422		switch (pppt->dr) {
3423			case DK4_PPPT_DR_PGF : {
3424				dk4gra_arc(
3425					pppt->out.pgf,
3426					xc, yc, ra, start, end, cl, bbptr, backptr, erp
3427				);
3428			} break;
3429			default : {
3430				dk4gra_arc(
3431					pppt->out.ppt.gra,
3432					xc, yc, ra, start, end, cl, bbptr, backptr, erp
3433				);
3434			} break;
3435		}
3436	}
3437	else {
3438		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3439		dk4pppt_reset(backptr);
3440	}
3441	$? "- dk4pppt_arc"
3442}
3443
3444
3445void
3446dk4pppt_ellipse(
3447	dk4_pppt_t	*pppt,
3448	double		 xc,
3449	double		 yc,
3450	double		 rx,
3451	double		 ry,
3452	double		 rot,
3453	dk4_bb_t	*bbptr,
3454	int			*backptr,
3455	dk4_er_t	*erp
3456)
3457{
3458	$? "+ dk4pppt_ellipse"
3459#if	DK4_USE_ASSERT
3460	assert(NULL != pppt);
3461#endif
3462	if (0 != dk4pppt_is_state_ok(pppt)) {
3463		switch (pppt->dr) {
3464			case DK4_PPPT_DR_PGF : {
3465				dk4gra_ellipse(
3466					pppt->out.pgf, xc, yc, rx, ry, rot, bbptr, backptr, erp
3467				);
3468			} break;
3469			default : {
3470				dk4gra_ellipse(
3471					pppt->out.ppt.gra, xc, yc, rx, ry, rot, bbptr, backptr, erp
3472				);
3473			} break;
3474		}
3475	}
3476	else {
3477		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3478		dk4pppt_reset(backptr);
3479	}
3480	$? "- dk4pppt_ellipse"
3481}
3482
3483
3484
3485static
3486void
3487dk4pppt_kw_out(
3488	dk4_pppt_t		*pppt,
3489	size_t			 kwi,
3490	int				*backptr,
3491	dk4_er_t		*erp
3492)
3493{
3494	dk4gratool_stream_string(
3495		pppt->out.ppt.tms, dk4pppt_c8_kw[kwi], backptr, erp
3496	);
3497}
3498
3499
3500
3501static
3502void
3503dk4pppt_double_out(
3504	dk4_pppt_t		*pppt,
3505	double			 val,
3506	int				*backptr,
3507	dk4_er_t		*erp
3508)
3509{
3510	dk4gratool_stream_double(
3511		pppt->out.ppt.tms, val, backptr, erp
3512	);
3513}
3514
3515
3516
3517/**	Handle one text piece, normal or special.
3518	@param	pppt	Output structure.
3519	@param	x		X position.
3520	@param	y		Y position.
3521	@param	rot		Rotation counterclockwise in degree.
3522	@param	txt		Text to write, dkChar for normal text, char for special.
3523	@param	colspec	Color specification, may be NULL to use fill color.
3524	@param	ie		Input encoding for normal text.
3525	@param	ha		Horizontal alignment.
3526	@param	va		Vertical alignment.
3527	@param	isnt	Flag: Normal text.
3528	@param	fno		Font id number.
3529	@param	fsz		Font size.
3530	@param	fex		Flag: Use font exactly as specified.
3531	@param	uc2l	Unicode to LaTeX converter, may be NULL for special text.
3532	@param	flags	Text flags.
3533	@param	backptr	Address of success variable to reset on error.
3534	@param	erp		Error report, may be NULL.
3535*/
3536static
3537void
3538dk4pppt_i_text(
3539	dk4_pppt_t		*pppt,
3540	double			 x,
3541	double			 y,
3542	double			 rot,
3543	const void		*txt,
3544	const char		*colspec,
3545	int				 ie,
3546	int				 ha,
3547	int				 va,
3548	int				 isnt,
3549	int				 fno,
3550	double			 fsz,
3551	dk4_gra_tf_t	 fex,
3552	dk4_uc2l_t		*uc2l,
3553	int				 flags,
3554	int				*backptr,
3555	dk4_er_t		*erp
3556)
3557{
3558	dk4gra_col_t		*pcolf	=	NULL;	/* Fill color */
3559	dk4_gra_ps_page_t	*pgps	=	NULL;	/* PS page */
3560	dk4_gra_pdf_page_t	*pgpdf	=	NULL;	/* PDF page */
3561	size_t				 fontno	=	0;		/* Font number */
3562	size_t				 kwi	=	4;		/* Keyword index */
3563	int					 res	=	0;		/* One operation result */
3564	int					 dorot	=	0;		/* Flag: Use rotatebox */
3565
3566	$? "+ dk4pppt_i_text"
3567	$? ". *backptr = %d", *backptr
3568	/*	Attempt to register font
3569	*/
3570	if (1.0e-8 < fabs(rot)) { dorot = 1; }
3571	if (0 != isnt) {					$? ". normal text"
3572	if (0 == dk4fontc_add_font(&fontno, pppt->out.ppt.fc, fno, fsz, fex, erp)) {
3573		$? "! failed to add font"
3574		goto finished;
3575	}
3576	}
3577	/*	Find non-stroking color
3578	*/
3579	switch (pppt->dr) {
3580		case DK4_PPPT_DR_PDF_TEX : {		$? ". pdf tex"
3581			pgpdf = (dk4_gra_pdf_page_t *)(pppt->out.ppt.gra->curpg);
3582			if (NULL != pgpdf) {
3583				pcolf = &(pgpdf->attr.col_fill_requested);
3584			}
3585			else {							$? "! curpg"
3586				goto finished;
3587			}
3588		} break;
3589		case DK4_PPPT_DR_EPS_TEX : {		$? ". eps tex"
3590			pgps  = (dk4_gra_ps_page_t *)(pppt->out.ppt.gra->curpg);
3591			if (NULL != pgps) {
3592				pcolf = &(pgps->attr.col_fill_requested);
3593			}
3594			else {							$? "! curpg"
3595				goto finished;
3596			}
3597		} break;
3598		default : {
3599			/* Empty by intent */
3600		} break;
3601	}
3602	if (NULL == pcolf) {					$? "! no current page"
3603		goto finished;
3604	}
3605	/*	put(
3606	*/
3607	dk4pppt_kw_out(pppt, 0, backptr, erp);
3608	$? ". *backptr = %d", *backptr
3609	/*	X
3610	*/
3611	dk4pppt_double_out(pppt, x, backptr, erp);
3612	$? ". *backptr = %d", *backptr
3613	/*	,
3614	*/
3615	dk4pppt_kw_out(pppt, 1, backptr, erp);
3616	$? ". *backptr = %d", *backptr
3617	/*	Y
3618	*/
3619	dk4pppt_double_out(pppt, y, backptr, erp);
3620	$? ". *backptr = %d", *backptr
3621	/*	){
3622	*/
3623	dk4pppt_kw_out(pppt, 2, backptr, erp);
3624	$? ". *backptr = %d", *backptr
3625	if (0 != dorot) {					$? ". open rotate box"
3626		/*
3627			Open rotatebox
3628		*/
3629		dk4pppt_kw_out(pppt, 27, backptr, erp);
3630		$? ". *backptr = %d", *backptr
3631		dk4pppt_double_out(pppt, rot, backptr, erp);
3632		$? ". *backptr = %d", *backptr
3633		dk4pppt_kw_out(pppt, 28, backptr, erp);
3634		$? ". *backptr = %d", *backptr
3635	}
3636	/*	Find index of makebox instruction depending on alignment
3637	*/
3638	switch (va) {
3639		case DK4_TEXT_ALIGN_V_TOP : {
3640			switch (ha) {
3641				case DK4_TEXT_ALIGN_H_CENTERED : {
3642					kwi = 11;
3643				} break;
3644				case DK4_TEXT_ALIGN_H_RIGHT : {
3645					kwi = 12;
3646				} break;
3647				default : {		/* left */
3648					kwi = 10;
3649				} break;
3650			}
3651		} break;
3652		case DK4_TEXT_ALIGN_V_CENTERED : {
3653			switch (ha) {
3654				case DK4_TEXT_ALIGN_H_CENTERED : {
3655					kwi = 8;
3656				} break;
3657				case DK4_TEXT_ALIGN_H_RIGHT : {
3658					kwi = 9;
3659				} break;
3660				default : {		/* left */
3661					kwi = 7;
3662				} break;
3663			}
3664		} break;
3665		default : {		/* base or bottom */
3666			switch (ha) {
3667				case DK4_TEXT_ALIGN_H_CENTERED : {
3668					kwi = 5;
3669				} break;
3670				case DK4_TEXT_ALIGN_H_RIGHT : {
3671					kwi = 6;
3672				} break;
3673				default : {		/* left */
3674					kwi = 4;
3675				} break;
3676			}
3677		} break;
3678	}
3679	/*	Start makebox
3680	*/
3681	dk4pppt_kw_out(pppt, kwi, backptr, erp);
3682	$? ". *backptr = %d", *backptr
3683	/*	Start smash
3684	*/
3685	if (DK4_TEXT_ALIGN_V_BASELINE == va) {
3686		dk4pppt_kw_out(pppt, 14, backptr, erp);
3687		$? ". *backptr = %d", *backptr
3688	}
3689	/*	Start group
3690	*/
3691	dk4pppt_kw_out(pppt, 15, backptr, erp);
3692	$? ". *backptr = %d", *backptr
3693	/*	Open white box
3694	*/
3695	if (0 != (DK4_GRA_TEXT_FLAG_WHITE_BOX & flags)) {
3696		dk4pppt_kw_out(pppt, 25, backptr, erp);
3697		$? ". *backptr = %d", *backptr
3698	}
3699	/*	Color
3700	*/
3701	if (NULL != colspec) {
3702		res = dk4stream_write_char_string(pppt->out.ppt.tms, colspec, erp);
3703		if (0 == res) {					$? "! backptr"
3704			dk4pppt_reset(backptr);
3705			$? ". *backptr = %d", *backptr
3706		}
3707	}
3708	else {
3709		dk4gratool_stream_color(pppt->out.ppt.tms, pcolf, backptr, erp);
3710		$? ". *backptr = %d", *backptr
3711	}
3712	/*	Open oval box
3713	*/
3714	if (0 != (DK4_GRA_TEXT_FLAG_OVAL_BOX & flags)) {
3715		dk4pppt_kw_out(pppt, 26, backptr, erp);
3716		$? ". *backptr = %d", *backptr
3717	}
3718	/*	Font
3719	*/
3720	if (0 != isnt) {
3721		dk4pppt_kw_out(pppt, 16, backptr, erp);
3722		$? ". *backptr = %d", *backptr
3723		dk4gratool_stream_num_alpha(pppt->out.ppt.tms, fontno, backptr, erp);
3724		$? ". *backptr = %d", *backptr
3725		dk4pppt_kw_out(pppt, 24, backptr, erp);
3726		$? ". *backptr = %d", *backptr
3727	}
3728	/*	Text
3729	*/
3730	if (0 != isnt) {	/* normal text */
3731		res = dk4uc2l_string_encoded(
3732			pppt->out.ppt.tms, uc2l, (const dkChar *)txt, ie, erp
3733		);
3734		if (0 == res) {					$? "! backptr"
3735			dk4pppt_reset(backptr);
3736			$? ". *backptr = %d", *backptr
3737		}
3738	}
3739	else {				/* special text */
3740		res = dk4stream_write_char_string(
3741			pppt->out.ppt.tms, (const char *)txt, erp
3742		);
3743		if (0 == res) {					$? "! backptr"
3744			dk4pppt_reset(backptr);
3745			$? ". *backptr = %d", *backptr
3746		}
3747	}
3748	/*	Close oval box
3749	*/
3750	if (0 != (DK4_GRA_TEXT_FLAG_OVAL_BOX & flags)) {
3751		dk4pppt_kw_out(pppt, 13, backptr, erp);
3752		$? ". *backptr = %d", *backptr
3753	}
3754	/*	Close white box
3755	*/
3756	if (0 != (DK4_GRA_TEXT_FLAG_WHITE_BOX & flags)) {
3757		dk4pppt_kw_out(pppt, 13, backptr, erp);
3758		$? ". *backptr = %d", *backptr
3759	}
3760	/*	End group
3761	*/
3762	dk4pppt_kw_out(pppt, 13, backptr, erp);
3763	$? ". *backptr = %d", *backptr
3764	/*	End smash
3765	*/
3766	if (DK4_TEXT_ALIGN_V_BASELINE == va) {
3767		dk4pppt_kw_out(pppt, 13, backptr, erp);
3768		$? ". *backptr = %d", *backptr
3769	}
3770	/*	End makebox
3771	*/
3772	dk4pppt_kw_out(pppt,  13, backptr, erp);
3773	$? ". *backptr = %d", *backptr
3774	if (0 != dorot) {
3775		/*
3776			End rotatebox
3777		*/
3778		dk4pppt_kw_out(pppt,  13, backptr, erp);
3779		$? ". *backptr = %d", *backptr
3780	}
3781	/*	} newline
3782	*/
3783	dk4pppt_kw_out(pppt, 3, backptr, erp);
3784	$? ". *backptr = %d", *backptr
3785
3786	finished:
3787	$? "- dk4pppt_i_text *backptr=%d", *backptr
3788	return;
3789}
3790
3791
3792
3793void
3794dk4pppt_simple_utf8_text(
3795	dk4_pppt_t			*pppt,
3796	double				 x,
3797	double				 y,
3798	double				 rot,
3799	const char			*txt,
3800	const char			*colspec,
3801	dk4_text_align_h_t	 ha,
3802	dk4_text_align_v_t	 va,
3803	int					 fno,
3804	double				 fsz,
3805	dk4_gra_tf_t		 fex,
3806	dk4_uc2l_t			*uc2l,
3807	int					 flags,
3808	int					*backptr,
3809	dk4_er_t			*erp
3810)
3811{
3812	$? "+ dk4pppt_simple_utf8_text"
3813#if	DK4_USE_ASSERT
3814	assert(NULL != pppt);
3815	assert(NULL != txt);
3816#endif
3817	if ((0 != dk4pppt_is_state_ok(pppt)) && (NULL != txt)) {
3818		switch (pppt->dr) {
3819			case DK4_PPPT_DR_PGF : {
3820				dk4gra_pgf_simple_utf8_text(
3821					pppt->out.pgf,
3822					x, y, rot, txt, colspec, ha, va, fno, fsz, fex, uc2l,
3823					flags, backptr, erp
3824				);
3825			} break;
3826			default : {
3827				dk4pppt_i_text(
3828					pppt,
3829					x, y, rot, txt, colspec, DK4_ENCODING_UTF8, ha, va, 1,
3830					fno, fsz, fex, uc2l, flags, backptr, erp
3831				);
3832			} break;
3833		}
3834	}
3835	else {
3836		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3837		dk4pppt_reset(backptr);
3838	}
3839	$? "- dk4pppt_simple_utf8_text"
3840}
3841
3842
3843
3844void
3845dk4pppt_simple_text(
3846	dk4_pppt_t			*pppt,
3847	double				 x,
3848	double				 y,
3849	double				 rot,
3850	const dkChar		*txt,
3851	const char			*colspec,
3852	int					 ie,
3853	dk4_text_align_h_t	 ha,
3854	dk4_text_align_v_t	 va,
3855	int					 fno,
3856	double				 fsz,
3857	dk4_gra_tf_t		 fex,
3858	dk4_uc2l_t			*uc2l,
3859	int					 flags,
3860	int					*backptr,
3861	dk4_er_t			*erp
3862)
3863{
3864	$? "+ dk4pppt_simple_text"
3865#if	DK4_USE_ASSERT
3866	assert(NULL != pppt);
3867	assert(NULL != txt);
3868#endif
3869	if ((0 != dk4pppt_is_state_ok(pppt)) && (NULL != txt)) {
3870		switch (pppt->dr) {
3871			case DK4_PPPT_DR_PGF : {		$? ". pgf output"
3872				dk4gra_pgf_simple_text(
3873					pppt->out.pgf,
3874					x, y, rot, txt, colspec, ie, ha, va, fno, fsz, fex, uc2l,
3875					flags, backptr, erp
3876				);
3877			} break;
3878			default : {						$? ". pdf/ps output"
3879				dk4pppt_i_text(
3880					pppt,
3881					x, y, rot, txt, colspec, ie, ha, va, 1,
3882					fno, fsz, fex, uc2l, flags, backptr, erp
3883				);
3884			} break;
3885		}
3886	}
3887	else {					$? "! invalid arguments"
3888		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3889		dk4pppt_reset(backptr);
3890	}
3891	$? "- dk4pppt_simple_text"
3892}
3893
3894
3895
3896void
3897dk4pppt_special_text(
3898	dk4_pppt_t			*pppt,
3899	double				 x,
3900	double				 y,
3901	double				 rot,
3902	const char			*txt,
3903	const char			*colspec,
3904	dk4_text_align_h_t	 ha,
3905	dk4_text_align_v_t	 va,
3906	int					 fno,
3907	double				 fsz,
3908	dk4_gra_tf_t		 fex,
3909	int					 flags,
3910	int					*backptr,
3911	dk4_er_t			*erp
3912)
3913{
3914	$? "+ dk4pppt_special_text"
3915#if	DK4_USE_ASSERT
3916	assert(NULL != pppt);
3917	assert(NULL != txt);
3918#endif
3919	if ((0 != dk4pppt_is_state_ok(pppt)) && (NULL != txt)) {
3920		switch (pppt->dr) {
3921			case DK4_PPPT_DR_PGF : {
3922				dk4gra_pgf_special_text(
3923					pppt->out.pgf,
3924					x, y, rot, txt, colspec, ha, va, fno, fsz, fex,
3925					flags, backptr, erp
3926				);
3927			} break;
3928			default : {
3929				dk4pppt_i_text(
3930					pppt,
3931					x, y, rot, txt, colspec, DK4_FILE_ENCODING_PLAIN, ha, va, 0,
3932					fno, fsz, fex, NULL, flags, backptr, erp
3933				);
3934			} break;
3935		}
3936	}
3937	else {
3938		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3939		dk4pppt_reset(backptr);
3940	}
3941	$? "- dk4pppt_special_text"
3942}
3943
3944
3945
3946void
3947dk4pppt_set_eorule(
3948	dk4_pppt_t	*pppt,
3949	int			 val
3950)
3951{
3952	$? "+ dk4pppt_set_eorule"
3953#if	DK4_USE_ASSERT
3954	assert(NULL != pppt);
3955#endif
3956	if (0 != dk4pppt_is_state_ok(pppt)) {
3957		switch (pppt->dr) {
3958			case DK4_PPPT_DR_PGF : {
3959				dk4gra_set_eorule(pppt->out.pgf, val);
3960			} break;
3961			default : {
3962				dk4gra_set_eorule(pppt->out.ppt.gra, val);
3963			} break;
3964		}
3965	}
3966	$? "- dk4pppt_set_eorule"
3967}
3968
3969
3970
3971void
3972dk4pppt_doc_font_size(
3973	dk4_pppt_t	*pppt,
3974	double		 fs,
3975	int			*backptr,
3976	dk4_er_t	*erp
3977)
3978{
3979	$? "+ dk4pppt_doc_font_size"
3980#if	DK4_USE_ASSERT
3981	assert(NULL != pppt);
3982	assert(0.0 < fs);
3983#endif
3984	if ((0 != dk4pppt_is_state_ok(pppt)) && (0.0 < fs)) {
3985		switch (pppt->dr) {
3986			case DK4_PPPT_DR_PGF : {
3987				dk4gra_pgf_doc_font_size(pppt->out.pgf , fs, backptr, erp);
3988			} break;
3989			default : {
3990				pppt->out.ppt.dfs = fs;
3991			} break;
3992		}
3993	}
3994	else {
3995		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
3996		dk4pppt_reset(backptr);
3997	}
3998	$? "- dk4pppt_doc_font_size"
3999}
4000
4001
4002
4003static
4004void
4005dk4pppt_one_preamble_line(
4006	dk4_sto_t		**ps,
4007	dk4_sto_it_t	**pi,
4008	size_t			 *pn,
4009	char const		 *pline,
4010	int				 *backptr,
4011	dk4_er_t		 *erp
4012)
4013{
4014	dk4_gra_preamble_line_t	*pl;
4015	int						 back	= 0;
4016
4017	if (SIZE_MAX > *pn) {
4018		if (NULL == *ps) {
4019			*ps = dk4sto_open(erp);
4020			if (NULL != *ps) {
4021				dk4sto_set_comp(*ps, dk4gratool_compare_preamble_lines, 0);
4022			}
4023		}
4024		if (NULL != *ps) {
4025			if (NULL == *pi) {
4026				*pi = dk4sto_it_open(*ps, erp);
4027			}
4028			if (NULL != *pi) {
4029				pl = dk4gratool_preamble_new(pline, *pn, erp);
4030				if (NULL != pl) {
4031					if (0 != dk4sto_add(*ps, pl, erp)) {
4032						back = 1;
4033					}
4034					else {
4035						dk4gratool_preamble_delete(pl);
4036					}
4037				}
4038			}
4039		}
4040	}
4041	else {
4042		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
4043	}
4044	if (0 == back) { dk4pppt_reset(backptr); }
4045}
4046
4047
4048
4049void
4050dk4pppt_doc_preamble_line(
4051	dk4_pppt_t	*pppt,
4052	const char	*line,
4053	int			 tp,
4054	int			*backptr,
4055	dk4_er_t	*erp
4056)
4057{
4058	$? "+ dk4pppt_doc_preamble_line"
4059#if	DK4_USE_ASSERT
4060	assert(NULL != pppt);
4061	assert(NULL != line);
4062#endif
4063	if ((0 != dk4pppt_is_state_ok(pppt)) && (NULL != line)) {
4064		switch (pppt->dr) {
4065			case DK4_PPPT_DR_PGF : {
4066				dk4gra_pgf_doc_preamble_line(pppt->out.pgf,line,tp,backptr,erp);
4067			} break;
4068			default : {
4069				switch (tp) {
4070					case DK4_GRA_PREAMBLE_FONT : {
4071						dk4pppt_one_preamble_line(
4072							&(pppt->out.ppt.s_f), &(pppt->out.ppt.i_f),
4073							&(pppt->out.ppt.n_f), line, backptr, erp
4074						);
4075					} break;
4076					case DK4_GRA_PREAMBLE_PACKAGE : {
4077						dk4pppt_one_preamble_line(
4078							&(pppt->out.ppt.s_p), &(pppt->out.ppt.i_p),
4079							&(pppt->out.ppt.n_p), line, backptr, erp
4080						);
4081					} break;
4082					case DK4_GRA_PREAMBLE_OTHER : {
4083						dk4pppt_one_preamble_line(
4084							&(pppt->out.ppt.s_o), &(pppt->out.ppt.i_o),
4085							&(pppt->out.ppt.n_o), line, backptr, erp
4086						);
4087					} break;
4088					default : {
4089						dk4error_set_simple_error_code(
4090							erp, DK4_E_INVALID_ARGUMENTS
4091						);
4092						dk4pppt_reset(backptr);
4093					} break;
4094				}
4095			} break;
4096		}
4097	}
4098	else {
4099		dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
4100		dk4pppt_reset(backptr);
4101	}
4102	$? "- dk4pppt_doc_preamble_line"
4103}
4104
4105
4106
4107/* vim: set ai sw=4 ts=4 : */
4108
4109