1 /*
2 Copyright 2020, Dirk Krause. All rights reserved.
3 SPDX-License-Identifier:	BSD-3-Clause
4 */
5 
6 #ifndef	GRA_H_INCLUDED
7 /**	Protection against multiple inclusions.
8 */
9 #define	GRA_H_INCLUDED 1
10 
11 /**	@file gra.h Library-internal function prototypes.
12 
13 This header contains data types and functions used cross-module within
14 the library but not part of the API and thus not intended for use by a
15 library consumer.
16 
17 Consequently this file is not installed to /usr/include or some similar
18 directory.
19 */
20 
21 #ifndef	DK4CONF_H_INCLUDED
22 #if DK4_BUILDING_DKTOOLS4
23 #include "dk4conf.h"
24 #else
25 #include <dktools-4/dk4conf.h>
26 #endif
27 #endif
28 
29 #ifndef	DK4MEMBUF_H_INCLUDED
30 #if DK4_BUILDING_DKTOOLS4
31 #include <libdk4c/dk4membuf.h>
32 #else
33 #include <dktools-4/dk4membuf.h>
34 #endif
35 #endif
36 
37 #ifndef	DK4MEMBS_H_INCLUDED
38 #if DK4_BUILDING_DKTOOLS4
39 #include <libdk4c/dk4membs.h>
40 #else
41 #include <dktools-4/dk4membs.h>
42 #endif
43 #endif
44 
45 #ifndef	DK4UFIT_H_INCLUDED
46 #if DK4_BUILDING_DKTOOLS4
47 #include <libdk4c/dk4ufit.h>
48 #else
49 #include <dktools-4/dk4ufit.h>
50 #endif
51 #endif
52 
53 #ifndef	DK4BITSH_H_INCLUDED
54 #if DK4_BUILDING_DKTOOLS4
55 #include <libdk4c/dk4bitsh.h>
56 #else
57 #include <dktools-4/dk4bitsh.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 
70 /**	Circle approximation by 4 Bezier spline segments.
71 */
72 #define	KAPPA_4	0.5522847498307943
73 
74 
75 /**	Circle approximation by 8 Bezier spline segments.
76 */
77 #define	KAPPA_8	0.2652164898395453
78 
79 
80 /**	Color specification in RGB color space.
81 */
82 typedef struct {
83 	double	r;	/**< Red. */
84 	double	g;	/**< Green. */
85 	double	b;	/**< Blue. */
86 } dk4_gra_col_rgb_t;
87 
88 
89 /**	Color specification in CMYK color space.
90 */
91 typedef struct {
92 	double	c;	/**< Cyan. */
93 	double	m;	/**< Magenta. */
94 	double	y;	/**< Yellow. */
95 	double	k;	/**< Black. */
96 } dk4gra_col_cmyk_t;
97 
98 
99 /**	Union of colors in all supported color spaces.
100 */
101 typedef union {
102 	double				gray;	/**< Gray value. */
103 	dk4_gra_col_rgb_t	rgb;	/**< Color specified in RGB. */
104 	dk4gra_col_cmyk_t	cmyk;	/**< Color specified in CMYK. */
105 } dk4gra_col_all_t;
106 
107 
108 /**	Colors specified by user or active.
109 */
110 typedef struct {
111 	dk4gra_col_all_t	data;	/**< Color data. */
112 	int					what;	/**< Specified color type. */
113 } dk4gra_col_t;
114 
115 
116 /**	Values for what component in dk4gra_col_t structure.
117 */
118 enum {
119 	DK4_GRA_COL_SPEC_NONE	= 0,	/**< No color specified yet. */
120 	DK4_GRA_COL_SPEC_GRAY ,			/**< Gray specified. */
121 	DK4_GRA_COL_SPEC_RGB ,			/**< RGB specified. */
122 	DK4_GRA_COL_SPEC_CMYK			/**< CMYK specified. */
123 };
124 
125 
126 /**	Compression/encoding combinations for bitmap images.
127 */
128 enum {
129 	DK4_GRA_COE_DCT_ASCII85	= 0 ,
130 	DK4_GRA_COE_FLATE_ASCII85 ,
131 	DK4_GRA_COE_LZW_ASCII85 ,
132 	DK4_GRA_COE_RUNLENGTH_ASCII85 ,
133 	DK4_GRA_COE_ASCII85
134 };
135 
136 
137 /**	Saved and current graphics attributes.
138 	For each attribute there is the active value value currently set
139 	in the data stream and a requested value to use for the next
140 	graphics elements.
141 	When preparing for an element (i.e. to stroke a line) and
142 	the active value differs from the requested value (i.e. stroke color),
143 	we have activate the requested value in the preparation function
144 	before starting to construct the path.
145 */
146 typedef struct {
147 	dk4gra_col_t	col_stroke_active;		/**< Current (stroke) color. */
148 	dk4gra_col_t	col_fill_active;		/**< Current fill color. */
149 	dk4gra_col_t	col_stroke_requested;	/**< Requested stroke color. */
150 	dk4gra_col_t	col_fill_requested;		/**< Requested fill color. */
151 	double			lw_active;				/**< Active line width. */
152 	double			lw_requested;			/**< Requested line width. */
153 	double			sv_active;				/**< Active style value. */
154 	double			sv_requested;			/**< Requested style value. */
155 	double			ml_active;				/**< Active miter limit. */
156 	double			ml_requested;			/**< Requested miter limit. */
157 	int				lc_active;				/**< Active line cap. */
158 	int				lc_requested;			/**< Requested line cap. */
159 	int				lj_active;				/**< Active line join. */
160 	int				lj_requested;			/**< Requested line join. */
161 	int				ls_active;				/**< Active line style. */
162 	int				ls_requested;			/**< Requested line style. */
163 	int				eor_active;				/**< Active even-odd-rule flag. */
164 	int				eor_requested;			/**< Requested even-odd-rule. */
165 } dk4gra_attributes_t;
166 
167 
168 /**	PS/EPS page.
169 	All graphics instructions go through the memory stream into the
170 	memory buffer first.
171 	When writing the output file, we might want to place other
172 	contents - i.e. document structuring comments - before and after
173 	the page contents.
174 */
175 typedef struct {
176 	dk4gra_attributes_t		 attr;		/**< Graphics attributes. */
177 	dk4gra_attributes_t		 catt;		/**< Copy of graphics attributes. */
178 	dk4_membuf_t			*membuf;	/**< Memory buffer. */
179 	dk4_stream_t			*memstrm;	/**< Stream writing to mem buffer. */
180 	unsigned char			 patu[DK4_GRA_PATTERN_MAX+1];	/**< Pat used. */
181 	size_t					 pageno;	/**< Page number. */
182 	int						 spip;		/**< Flag: Showpage in image proc */
183 	int						 cont;		/**< Flag: Already contents on page. */
184 	int						 flags;		/**< Page flags. */
185 } dk4_gra_ps_page_t;
186 
187 
188 
189 /**	Image XObject type.
190 	When including a bitmap image multiple times, we reuse the
191 	XObject to save memory.
192 */
193 typedef struct {
194 	dk4_ufi_t			 ufi;		/**< Unique file identifier. */
195 	const dkChar		*fn;		/**< File name. */
196 	dk4_membuf_t		*i_mb;		/**< Image data. */
197 	dk4_membuf_t		*m_mb;		/**< Mask data. */
198 	size_t				 fno;		/**< Frame number. */
199 	size_t				 objno;		/**< Object number for image itself. */
200 	size_t				 mobjno;	/**< Object number for mask (0=unused). */
201 	size_t				 unxon;		/**< Unnamed XObject number. */
202 	dk4_bif_dim_t		 width;		/**< Image width (number of pixels). */
203 	dk4_bif_dim_t		 height;	/**< Image height (number of pixels). */
204 	int					 dct;		/**< Flag: Stored in DCTDecode. */
205 	int					 ipol;		/**< Flag: Interpolation used. */
206 	int					 cs;		/**< Color space. */
207 	int					 hufi;		/**< Flag: Valid UFI. */
208 	int					 deci;		/**< Flag: Decoding inverted. */
209 	dk4_px_bit_depth_t	 bpc;		/**< Number of bits per component. */
210 } dk4_gra_pdf_img_xo_t;
211 
212 
213 
214 /**	PDF page.
215 	Page contents is stored in a memory buffer named membuf.
216 	The memstrm stream provides a stream API to write to the buffer.
217 	Graphics instructions are written to the compressing stream costrm,
218 	which flate-compresses the data and writes to memstrm which in turn
219 	writes to membuf.
220 */
221 typedef struct {
222 	dk4gra_attributes_t		 attr;		/**< Graphics attributes. */
223 	dk4gra_attributes_t		 catt;		/**< Copy of graphics attributes. */
224 	dk4_membuf_t			*membuf;	/**< Memory buffer. */
225 	dk4_stream_t			*memstrm;	/**< Stream writing to mem buffer. */
226 	dk4_stream_t			*costrm;	/**< Compressed stream. */
227 	dk4_stream_t			*outstrm;	/**< Output stream to use. */
228 	dk4_sto_t				*s_uxo;		/**< Used XObjects container. */
229 	dk4_sto_it_t			*i_uxo;		/**< Used XObjects iterator. */
230 	size_t					 pageno;	/**< Page number. */
231 	size_t					 objno;		/**< Object number. */
232 	int						 flags;		/**< Flags specified when opening. */
233 } dk4_gra_pdf_page_t;
234 
235 
236 
237 /**	PGF image file.
238 */
239 typedef struct {
240 	dk4_ufi_t			 ufi;		/**< Unique file identifier. */
241 	dkChar				*fn;		/**< File name. */
242 	size_t				 imgno;		/**< Image number, 0 for first image. */
243 	int					 hufi;		/**< Flag: Valid UFI. */
244 	int					 intp;		/**< Flag: Image interpolation. */
245 } dk4_gra_pgf_img_no_t;
246 
247 
248 
249 /**	PGF page.
250 	Page contents is written through the memory stream into the
251 	memory buffer.
252 	When writing the output file we place additional contents before
253 	and after the buffered contents (i.e. font definitions and
254 	image declarations).
255 */
256 typedef struct {
257 	dk4gra_attributes_t		 attr;		/**< Graphics attributes. */
258 	dk4gra_attributes_t		 catt;		/**< Copy of graphics attributes. */
259 	dk4_membuf_t			*membuf;	/**< Memory buffer. */
260 	dk4_stream_t			*memstrm;	/**< Stream writing to mem buffer. */
261 	size_t					 pageno;	/**< Page number. */
262 	int						 flags;		/**< Page flags. */
263 } dk4_gra_pgf_page_t;
264 
265 
266 
267 /**	Store one preamble line.
268 */
269 typedef struct {
270 	char		*text;		/**< Line text. */
271 	size_t		 lineno;	/**< Line number. */
272 } dk4_gra_preamble_line_t;
273 
274 
275 
276 #ifdef	__cplusplus
277 extern "C" {
278 #endif
279 
280 /*
281 	Module dk4grat - Graphics tool functions for all output drivers
282 	---------------------------------------------------------------
283 */
284 
285 /**	Open output structure and initialize base components.
286 	Note: s_pages and i_pages are not initialized, the dr component
287 	is set to PDF.
288 	@param	fn		Output file name.
289 	@param	w		Image width in bp.
290 	@param	h		Image height in bp.
291 	@param	docfl	Document flag set.
292 	@param	erp		Error report, may be NULL.
293 	@return	Valid pointer to new output structure on success, NULL on error.
294 
295 	Error codes:
296 	- DK4_E_MATH_OVERFLOW<br>
297 	  on numeric overflow when calculating memory size to allocate,
298 	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
299 	  if a memory allocation failed.
300 */
301 
302 dk4_gra_t *
303 dk4gratool_open(
304 	const dkChar	*fn,
305 	size_t			 w,
306 	size_t			 h,
307 	int				 docfl,
308 	dk4_er_t		*erp
309 );
310 
311 
312 /**	Close output structure, release memory.
313 	@param	gptr	Output structure to close.
314 */
315 
316 void
317 dk4gratool_close(
318 	dk4_gra_t *gptr
319 );
320 
321 
322 /**	Initialize attributes set.
323 	@param	pattr	Attributes set to initialize.
324 */
325 
326 void
327 dk4gratool_initialize_attributes(
328 	dk4gra_attributes_t *pattr
329 );
330 
331 
332 /**	Reset active attributes after grestore operation.
333 	@param	pattr	Attributes set to reset.
334 */
335 
336 void
337 dk4gratool_reset_active_attributes(
338 	dk4gra_attributes_t *pattr
339 );
340 
341 
342 /**	Set a color.
343 	@param	pcol	Color to set up.
344 	@param	colsp	Color space.
345 	@param	c1		First component (gray, red or cyan).
346 	@param	c2		Second component (green or magenta).
347 	@param	c3		Third component (blue or yellow).
348 	@param	c4		Fourth component (black).
349 */
350 void
351 dk4gratool_set_color_requested(
352 	dk4gra_col_t	*pcol,
353 	int				 colsp,
354 	double			 c1,
355 	double			 c2,
356 	double			 c3,
357 	double			 c4
358 );
359 
360 
361 /**	Compare two colors.
362 	@param	p1	First color.
363 	@param	p2	Second color.
364 	@return	1 if the colors differ, 0 otherwise.
365 */
366 
367 int
368 dk4gratool_colors_differ(
369 	dk4gra_col_t	*p1,
370 	dk4gra_col_t	*p2
371 );
372 
373 
374 /**	Check whether two line styles differ.
375 	@param	ls_a	Active line style.
376 	@param	ls_r	Requested line style.
377 	@param	sv_a	Active style value (dash length in bp).
378 	@param	sv_r	Requested style value.
379 	@param	lwc		Flag: Line width was changed.
380 	@return	1 if the line style setup must be written, 0 otherwise.
381 */
382 
383 int
384 dk4gratool_line_style_differs(
385 	int		ls_a,
386 	int		ls_r,
387 	double	sv_a,
388 	double	sv_r,
389 	int		lwc
390 );
391 
392 
393 /**	Calculate coordinates systems transformations.
394 	@param	dst	Destination array consisting of 5 elements:
395 	-	x translation,
396 	-	y translation,
397 	-	rotation counterclockwise in degree,
398 	-	x scale factor (resulting image width) and
399 	-	y scale factor (resulting image height).
400 	@param	xl	Left x coordinate.
401 	@param	xr	Right x coordinate.
402 	@param	yb	Bottom y coordinate.
403 	@param	yt	Top y coordinate.
404 	@param	w	Image width in bp.
405 	@param	h	Image height in bp.
406 	@param	kar	Flag: Keep aspect ratio.
407 	@param	pos	Positioning choice.
408 	@param	erp	Error report, may be NULL.
409 	@return	1 on success, 0 on error.
410 
411 	Error codes:
412 	- DK4_E_INVALID_ARGUMENTS<br>
413 	  if coordinates are incorrect or image dimensions are not positive,
414 	- DK4_E_MATH_OVERFLOW<br>
415 	  if a numeric problem occured in calculations.
416 */
417 
418 int
419 dk4gratool_calculate_transformations(
420 	double		*dst,
421 	double	 	 xl,
422 	double	 	 xr,
423 	double	 	 yb,
424 	double	 	 yt,
425 	double	 	 w,
426 	double	 	 h,
427 	int		 	 kar,
428 	int		 	 pos,
429 	dk4_er_t	*erp
430 );
431 
432 
433 /**	Write char string to output stream.
434 	@param	os		Output stream.
435 	@param	str		String to write.
436 	@param	backptr	Address of success variable to reset on errors.
437 	@param	erp		Error report, may be NULL.
438 
439 	Error codes:
440 	- DK4_E_INVALID_ARGUMENTS<br>
441 	  if str is NULL or the stream is not opened for writing,
442 	- DK4_E_WRITE_FAILED<br>
443 	  if writing one ore multiple bytes to the stream failed,
444 	- DK4_E_FLUSH_FAILED<br>
445 	  if flushing data downwards failed.
446 */
447 
448 void
449 dk4gratool_stream_string(
450 	dk4_stream_t	*os,
451 	const char		*str,
452 	int				*backptr,
453 	dk4_er_t		*erp
454 );
455 
456 
457 /**	Write double value to stream without scientific notation.
458 	@param	os		Output stream.
459 	@param	val		Value to write.
460 	@param	backptr	Address of success variable to reset on errors.
461 	@param	erp		Error report, may be NULL.
462 
463 	Error codes:
464 	- DK4_E_INVALID_ARGUMENTS<br>
465 	  if os is NULL.
466 	- DK4_E_WRITE_FAILED<br>
467 	  if writing one ore multiple bytes to the stream failed,
468 	- DK4_E_FLUSH_FAILED<br>
469 	  if flushing data downwards failed,
470 	- DK4_E_MATH_OVERFLOW<br>
471 	  if the exponent is out of range for integer values,<br>
472 	- DK4_E_SYNTAX<br>
473 	  if input contains invalid characters.
474 */
475 
476 void
477 dk4gratool_stream_double(
478 	dk4_stream_t	*os,
479 	double			 val,
480 	int				*backptr,
481 	dk4_er_t		*erp
482 );
483 
484 
485 /**	Write unsigned integer value to stream.
486 	@param	os		Output stream.
487 	@param	val		Value to write.
488 	@param	padsz	Required minimum string size, 0 for no minimum.
489 	@param	backptr	Address of success variable to reset on errors.
490 	@param	erp		Error report, may be NULL.
491 
492 	Error codes:
493 	- DK4_E_INVALID_ARGUMENTS<br>
494 	  if os is NULL,
495 	- DK4_E_WRITE_FAILED<br>
496 	  if writing one ore multiple bytes to the stream failed,
497 	- DK4_E_FLUSH_FAILED<br>
498 	  if flushing data downwards failed.
499 	- DK4_E_BUFFER_TOO_SMALL<br>
500 	  if the destination buffer size is too small for the result,
501 	- DK4_E_BUG<br>
502 	  if an internal buffer is too small (should not happen).
503 */
504 
505 void
506 dk4gratool_stream_uint(
507 	dk4_stream_t	*os,
508 	dk4_um_t		 val,
509 	size_t			 padsz,
510 	int				*backptr,
511 	dk4_er_t		*erp
512 );
513 
514 
515 /**	Retrieve a bit value.
516 	@param	i	Bit index (0 to 11, 0 is least significant bit).
517 	@return	Bit value.
518 */
519 
520 dk4_px_t
521 dk4gratool_bit(
522 	size_t	i
523 );
524 
525 
526 /**	Write a pixel component value to compressed/encoded stream.
527 	@param	strm	Stream to write to.
528 	@param	bs		Bit shifter to use.
529 	@param	pixval	Value to write.
530 	@param	bpc		Number of bits in value.
531 	@param	backptr	Address of success variable to reset on error.
532 	@param	erp		Error report, may be NULL.
533 
534 	Error codes:
535 	- DK4_E_INVALID_ARGUMENTS<br>
536 	  if strm is NULL or not opened for writing,
537 	- DK4_E_WRITE_FAILED<br>
538 	  if writing one ore multiple bytes to the stream failed,
539 	- DK4_E_FLUSH_FAILED<br>
540 	  if flusing data downwards failed.
541 */
542 
543 void
544 dk4gratool_put_pixel_value(
545 	dk4_stream_t		*strm,
546 	dk4_bit_shift_t		*bs,
547 	dk4_px_t			 pixval,
548 	dk4_px_bit_depth_t	 bpc,
549 	int					*backptr,
550 	dk4_er_t			*erp
551 );
552 
553 
554 /**	Write start of standalone document
555 	@param	ostrm	Output stream.
556 	@param	gra		Graphics output structure.
557 	@param	pgf		Flag: Produce PGF, include pgfcore package.
558 	@param	dfs		Document font size (negative to use default).
559 	@param	s_f		Storage for font setup lines.
560 	@param	i_f		Iterator for font setup lines.
561 	@param	s_p		Storage for package lines.
562 	@param	i_p		Iterator for package lines.
563 	@param	s_o		Storage for other lines.
564 	@param	i_o		Iterator for other lines.
565 	@param	bptr	Address of success variable to reset on error.
566 	@param	erp		Error report, may be NULL.
567 */
568 void
569 dk4gratool_start_standalone_document(
570 	dk4_stream_t		*ostrm,
571 	dk4_gra_t			*gra,
572 	int					 pgf,
573 	double				 dfs,
574 	dk4_sto_t			*s_f,
575 	dk4_sto_it_t		*i_f,
576 	dk4_sto_t			*s_p,
577 	dk4_sto_it_t		*i_p,
578 	dk4_sto_t			*s_o,
579 	dk4_sto_it_t		*i_o,
580 	int					*bptr,
581 	dk4_er_t			*erp
582 );
583 
584 /**	Write end of standalone document
585 	@param	ostrm	Output stream.
586 	@param	bptr	Address of success variable to reset on error.
587 	@param	erp		Error report, may be NULL.
588 */
589 void
590 dk4gratool_end_standalone_document(
591 	dk4_stream_t		*ostrm,
592 	int					*bptr,
593 	dk4_er_t			*erp
594 );
595 
596 /**	Write font number as unique name.
597 	@param	os		Stream to write to.
598 	@param	val		Value to write.
599 	@param	backptr	Address of success variable to reset on error.
600 	@param	erp		Error report, may be NULL.
601 
602 	Error codes:
603 	- DK4_E_INVALID_ARGUMENTS<br>
604 	  if str is NULL or the stream is not opened for writing,
605 	- DK4_E_WRITE_FAILED<br>
606 	  if writing one ore multiple bytes to the stream failed,
607 	- DK4_E_FLUSH_FAILED<br>
608 	  if flushing data downwards failed.
609 */
610 void
611 dk4gratool_stream_num_alpha(
612 	dk4_stream_t	*os,
613 	size_t			 val,
614 	int				*backptr,
615 	dk4_er_t		*erp
616 );
617 
618 /**	Write instruction to change color to stream.
619 	@param	os		Output stream.
620 	@param	col		Color to write.
621 	@param	backptr	Address of success variable to reset on error.
622 	@param	erp		Error report, may be NULL.
623 
624 	Error codes:
625 	- DK4_E_INVALID_ARGUMENTS<br>
626 	  if os is NULL.
627 	- DK4_E_WRITE_FAILED<br>
628 	  if writing one ore multiple bytes to the stream failed,
629 	- DK4_E_FLUSH_FAILED<br>
630 	  if flushing data downwards failed,
631 	- DK4_E_MATH_OVERFLOW<br>
632 	  if the exponent is out of range for integer values,<br>
633 	- DK4_E_SYNTAX<br>
634 	  if input contains invalid characters.
635 */
636 void
637 dk4gratool_stream_color(
638 	dk4_stream_t		*os,
639 	dk4gra_col_t const	*col,
640 	int					*backptr,
641 	dk4_er_t			*erp
642 );
643 
644 /**	Write font definitions from font collector to stream.
645 	@param	ostrm	Output stream.
646 	@param	fontc	Font collector to write.
647 	@param	bptr	Address of success variable to reset on errors.
648 	@param	erp		Error report, may be NULL.
649 
650 	Error codes:
651 	- DK4_E_INVALID_ARGUMENTS<br>
652 	  if str is NULL or the stream is not opened for writing
653 	  or if input contains invalid characters,
654 	- DK4_E_WRITE_FAILED<br>
655 	  if writing one ore multiple bytes to the stream failed,
656 	- DK4_E_FLUSH_FAILED<br>
657 	  if flushing data downwards failed,
658 	- DK4_E_MATH_OVERFLOW<br>
659 	  if the exponent is out of range for integer values.<br>
660 */
661 void
662 dk4gratool_font_definitions(
663 	dk4_stream_t			*ostrm,
664 	dk4_font_collector_t	*fontc,
665 	int						*bptr,
666 	dk4_er_t				*erp
667 );
668 
669 /**	Create preamble line structure for given text line and line number.
670 	@param	textline	Text line to store.
671 	@param	lineno		Line number.
672 	@param	erp			Error report, may be NULL.
673 	@return	Valid pointer on success, NULL on error.
674 */
675 dk4_gra_preamble_line_t *
676 dk4gratool_preamble_new(
677 	char const	*textline,
678 	size_t		 lineno,
679 	dk4_er_t	*erp
680 );
681 
682 /**	Destroy preamble line structure, release ressources.
683 	@param	ptr	Structure to destroy.
684 */
685 void
686 dk4gratool_preamble_delete(
687 	dk4_gra_preamble_line_t	*ptr
688 );
689 
690 /**	Compare two preamble line structures.
691 	@param	l	Left structure.
692 	@param	r	Right structure.
693 	@param	cr	Comparison criteria, ignored.
694 	@return	Comparison result: 1=l>l, 0=l==r, -1=l<r.
695 */
696 int
697 dk4gratool_compare_preamble_lines(
698 	void const	*l,
699 	void const	*r,
700 	int			 cr
701 );
702 
703 /*
704 	Module dk4gra - General graphics module, library internal functions
705 	-------------------------------------------------------------------
706 */
707 
708 /**	Save current graphics state (especially clip path).
709 	This function does not check arguments, it is intended for
710 	library-internal use from functions having done the checks!
711 	@param	gra	Output structure.
712 	@param	backptr	Address of success variable to reset on error.
713 	@param	erp	Error report, may be NULL.
714 
715 	Error codes:
716 	- DK4_E_INVALID_ARGUMENTS<br>
717 	  if gra is NULL or not in a state allowing this operation.
718 */
719 
720 void
721 dk4gra_i_gsave(
722 	dk4_gra_t		*gra,
723 	int				*backptr,
724 	dk4_er_t		*erp
725 );
726 
727 
728 /**	Restore graphics state (especially clip path).
729 	This function does not check arguments, it is intended for
730 	library-internal use from functions having done the checks!
731 	@param	gra	Output structure.
732 	@param	res	Flag: Reset attributes.
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 or not in a state allowing this operation.
739 */
740 
741 void
742 dk4gra_i_grestore(
743 	dk4_gra_t		*gra,
744 	int				 res,
745 	int				*backptr,
746 	dk4_er_t		*erp
747 );
748 
749 
750 /**	Prepare output structure for a fill operation.
751 	This function does not check arguments, it is intended for
752 	library-internal use from functions having done the checks!
753 	Use this function before you start to construct a path you plan to fill.
754 	@param	gra	Output structure.
755 	@param	backptr	Address of success variable to reset on errors.
756 	@param	erp	Error report, may be NULL.
757 
758 	Error codes:
759 	- DK4_E_INVALID_ARGUMENTS<br>
760 	  if gra is NULL or not in a state allowing this operation.
761 */
762 
763 void
764 dk4gra_i_prepare_fill(
765 	dk4_gra_t	*gra,
766 	int			*backptr,
767 	dk4_er_t	*erp
768 );
769 
770 
771 /**	Prepare output structure for a stroke operation.
772 	This function does not check arguments, it is intended for
773 	library-internal use from functions having done the checks!
774 	Use this function before you start to construct a path you plan to stroke.
775 	@param	gra	Output structure.
776 	@param	backptr	Address of success variable to reset on errors.
777 	@param	erp	Error report, may be NULL.
778 
779 	Error codes:
780 	- DK4_E_INVALID_ARGUMENTS<br>
781 	  if gra is NULL or not in a state allowing this operation.
782 */
783 
784 void
785 dk4gra_i_prepare_stroke(
786 	dk4_gra_t	*gra,
787 	int			*backptr,
788 	dk4_er_t	*erp
789 );
790 
791 
792 /**	Prepare output structure for a combined fill and stroke operation.
793 	This function does not check arguments, it is intended for
794 	library-internal use from functions having done the checks!
795 	Use this function before you start to construct a path you plan to
796 	fill and stroke.
797 	@param	gra	Output structure.
798 	@param	backptr	Address of success variable to reset on errors.
799 	@param	erp	Error report, may be NULL.
800 
801 	Error codes:
802 	- DK4_E_INVALID_ARGUMENTS<br>
803 	  if gra is NULL or not in a state allowing this operation.
804 */
805 
806 void
807 dk4gra_i_prepare_fill_and_stroke(
808 	dk4_gra_t	*gra,
809 	int			*backptr,
810 	dk4_er_t	*erp
811 );
812 
813 
814 /**	Fill current path.
815 	This function does not check arguments, it is intended for
816 	library-internal use from functions having done the checks!
817 	Note: Use dk4gra_prepare_fill() before you start to construct a path
818 	you plan to fill.
819 	@param	gra	Output structure.
820 	@param	backptr	Address of success variable to reset on errors.
821 	@param	erp	Error report, may be NULL.
822 
823 	Error codes:
824 	- DK4_E_INVALID_ARGUMENTS<br>
825 	  if gra is NULL or not in a state allowing this operation.
826 */
827 
828 void
829 dk4gra_i_fill(
830 	dk4_gra_t		*gra,
831 	int				*backptr,
832 	dk4_er_t		*erp
833 );
834 
835 
836 /**	Stroke current path.
837 	This function does not check arguments, it is intended for
838 	library-internal use from functions having done the checks!
839 	Note: Use dk4gra_prepare_stroke() before you start to construct a path
840 	you plan to stroke.
841 	@param	gra	Output structure.
842 	@param	backptr	Address of success variable to reset on errors.
843 	@param	erp	Error report, may be NULL.
844 
845 	Error codes:
846 	- DK4_E_INVALID_ARGUMENTS<br>
847 	  if gra is NULL or not in a state allowing this operation.
848 */
849 
850 void
851 dk4gra_i_stroke(
852 	dk4_gra_t		*gra,
853 	int				*backptr,
854 	dk4_er_t		*erp
855 );
856 
857 
858 
859 /**	Fill and stroke current path.
860 	This function does not check arguments, it is intended for
861 	library-internal use from functions having done the checks!
862 	Note: Use dk4gra_prepare_fill_and_stroke() before you start to construct
863 	a path you plan to fill and stroke.
864 	@param	gra	Output structure.
865 	@param	backptr	Address of success variable to reset on errors.
866 	@param	erp	Error report, may be NULL.
867 
868 	Error codes:
869 	- DK4_E_INVALID_ARGUMENTS<br>
870 	  if gra is NULL or not in a state allowing this operation.
871 */
872 
873 void
874 dk4gra_i_fill_and_stroke(
875 	dk4_gra_t		*gra,
876 	int				*backptr,
877 	dk4_er_t		*erp
878 );
879 
880 
881 /**	Use current path for clipping.
882 	This function does not check arguments, it is intended for
883 	library-internal use from functions having done the checks!
884 	@param	gra	Output structure.
885 	@param	backptr	Address of success variable to reset on errors.
886 	@param	erp	Error report, may be NULL.
887 	@return	1 on success, 0 on error.
888 
889 	Error codes:
890 	- DK4_E_INVALID_ARGUMENTS<br>
891 	  if gra is NULL or not in a state allowing this operation.
892 */
893 
894 void
895 dk4gra_i_clip(
896 	dk4_gra_t		*gra,
897 	int				*backptr,
898 	dk4_er_t		*erp
899 );
900 
901 
902 /**	Start a new path and move to first point.
903 	No argument checking, for internal use (pattern filling) only.
904 	@param	gra		Output structure.
905 	@param	x		X coordinate of start point.
906 	@param	y		Y coordinate of start point.
907 	@param	bbptr	Bounding box, may be NULL.
908 	@param	backptr	Address of success variable to reset on errors.
909 	@param	erp		Error report, may be NULL.
910 
911 	Error codes:
912 	- DK4_E_INVALID_ARGUMENTS<br>
913 	  if gra is NULL or not in a state allowing this operation.
914 */
915 
916 void
917 dk4gra_i_newpath_moveto(
918 	dk4_gra_t		*gra,
919 	double			 x,
920 	double			 y,
921 	int				*backptr,
922 	dk4_er_t		*erp
923 );
924 
925 
926 /**	Add line from current point to new point to path.
927 	No argument checking, for internal use (pattern filling) only.
928 	@param	gra		Output structure.
929 	@param	x		X coordinate of new point.
930 	@param	y		Y coordinate of new point.
931 	@param	bbptr	Bounding box, may be NULL.
932 	@param	backptr	Address of success variable to reset on errors.
933 	@param	erp		Error report, may be NULL.
934 
935 	Error codes:
936 	- DK4_E_INVALID_ARGUMENTS<br>
937 	  if gra is NULL or not in a state allowing this operation.
938 */
939 
940 void
941 dk4gra_i_lineto(
942 	dk4_gra_t		*gra,
943 	double			 x,
944 	double			 y,
945 	int				*backptr,
946 	dk4_er_t		*erp
947 );
948 
949 
950 /**	Add Bezier curve segment from current point to new point in path.
951 	No argument checking, for internal use (pattern filling) only.
952 	@param	gra		Output structure.
953 	@param	x1c		X coordinate of first control point.
954 	@param	y1c		Y coordinate of first control point.
955 	@param	x2c		X coordinate of second control point.
956 	@param	y2c		Y coordinate of second control point.
957 	@param	x		X coordinate of new point.
958 	@param	y		Y coordinate of new point.
959 	@param	backptr	Address of success variable to reset on errors.
960 	@param	erp		Error report, may be NULL.
961 
962 	Error codes:
963 	- DK4_E_INVALID_ARGUMENTS<br>
964 	  if gra is NULL or not in a state allowing this operation.
965 */
966 
967 void
968 dk4gra_i_curveto(
969 	dk4_gra_t		*gra,
970 	double			 xc1,
971 	double			 yc1,
972 	double			 xc2,
973 	double			 yc2,
974 	double			 x,
975 	double			 y,
976 	int				*backptr,
977 	dk4_er_t		*erp
978 );
979 
980 
981 /**	Close current path.
982 	No argument checking, for internal use (pattern filling) only.
983 	@param	gra	Output structure.
984 	@param	backptr	Address of success variable to reset on errors.
985 	@param	erp	Error report, may be NULL.
986 
987 	Error codes:
988 	- DK4_E_INVALID_ARGUMENTS<br>
989 	  if gra is NULL or not in a state allowing this operation.
990 */
991 
992 void
993 dk4gra_i_closepath(
994 	dk4_gra_t		*gra,
995 	int				*backptr,
996 	dk4_er_t		*erp
997 );
998 
999 
1000 /**	Create path for a circle.
1001 	No argument checking, for internal use (pattern filling) only.
1002 	@param	gra		Output structure.
1003 	@param	xc		Center point x coordinate.
1004 	@param	yc		Center point y coordinate.
1005 	@param	r		Radius.
1006 	@param	backptr	Address of success variable to reset on errors.
1007 	@param	erp		Error report, may be NULL.
1008 
1009 	Error codes:
1010 	- DK4_E_INVALID_ARGUMENTS<br>
1011 	  if gra is NULL or not in a state allowing this operation.
1012 */
1013 
1014 void
1015 dk4gra_i_circle(
1016 	dk4_gra_t		*gra,
1017 	double			 xc,
1018 	double			 yc,
1019 	double			 r,
1020 	int				*backptr,
1021 	dk4_er_t		*erp
1022 );
1023 
1024 
1025 /**	Create path for rectangle parallel to axes, optionally with
1026 	rounded corners.
1027 	No argument checking, for internal use (pattern filling) only.
1028 	@param	gra		Output structure.
1029 	@param	xl		Left x coordinate.
1030 	@param	xr		Right x coordinate.
1031 	@param	yb		Bottom y coordinate.
1032 	@param	yt		Top y coordinate.
1033 	@param	r		Corner radius, maximum is a half of the smaller side length.
1034 					Use negative values to avoid rounded corners.
1035 	@param	backptr	Address of success variable to reset on errors.
1036 	@param	erp		Error report, may be NULL.
1037 
1038 	Error codes:
1039 	- DK4_E_INVALID_ARGUMENTS<br>
1040 	  if gra is NULL or not in a state allowing this operation.
1041 */
1042 
1043 void
1044 dk4gra_i_rectangle(
1045 	dk4_gra_t		*gra,
1046 	double			 xl,
1047 	double			 xr,
1048 	double			 yb,
1049 	double			 yt,
1050 	double			 r,
1051 	int				*backptr,
1052 	dk4_er_t		*erp
1053 );
1054 
1055 
1056 /**	Add path for an arc.
1057 	No argument checking, for internal use (pattern filling) only.
1058 	@param	gra		Output structure.
1059 	@param	xc		Center point x coordinate.
1060 	@param	yc		Center point y coordinate.
1061 	@param	ra		Radius.
1062 	@param	start	Start angle in degree.
1063 	@param	end		End angle in degree.
1064 	@param	cl		Flag: Draw closed arc (piece of cake) instead of simple arc.
1065 	@param	backptr	Address of success variable to reset on errors.
1066 	@param	erp		Error report, may be NULL.
1067 
1068 	Error codes:
1069 	- DK4_E_INVALID_ARGUMENTS<br>
1070 	  if gra is NULL or not in a state allowing this operation.
1071 */
1072 
1073 void
1074 dk4gra_i_arc(
1075 	dk4_gra_t		*gra,
1076 	double			 xc,
1077 	double			 yc,
1078 	double			 ra,
1079 	double			 start,
1080 	double			 end,
1081 	int				 cl,
1082 	int				*backptr,
1083 	dk4_er_t		*erp
1084 );
1085 
1086 
1087 /**	Create path for an ellipse.
1088 	@param	gra		Output structure.
1089 	@param	xc		Center point x coordinate.
1090 	@param	yc		Center point y coordinate.
1091 	@param	rx		Radius in x direction.
1092 	@param	ry		Radius in y direction.
1093 	@param	rot		Rotation counterclockwise in radians.
1094 	@param	bbptr	Bounding box, may be NULL.
1095 	@param	backptr	Address of success variable to reset on errors.
1096 	@param	erp		Error report, may be NULL.
1097 
1098 	Error codes:
1099 	- DK4_E_INVALID_ARGUMENTS<br>
1100 	  if gra is NULL or not in a state allowing this operation.
1101 */
1102 
1103 void
1104 dk4gra_i_ellipse(
1105 	dk4_gra_t		*gra,
1106 	double			 xc,
1107 	double			 yc,
1108 	double			 rx,
1109 	double			 ry,
1110 	double			 rot,
1111 	dk4_bb_t		*bbptr,
1112 	int				*backptr,
1113 	dk4_er_t		*erp
1114 );
1115 
1116 
1117 /**	Pattern a region (clipping should be set to the path).
1118 	@param	gra		Output structure.
1119 	@param	xl		Left y coordinate.
1120 	@param	xr		Right x coordinate.
1121 	@param	yb		Bottom y coordinate.
1122 	@param	yt		Top y coordinate.
1123 	@param	pn		Pattern number.
1124 	@param	val		Pre-calculated coordinates.
1125 	@param	backptr	Address of success variable to reset on errors.
1126 	@param	erp		Error report, may be NULL.
1127 	@return	1 on success, 0 on error.
1128 */
1129 
1130 void
1131 dk4gra_i_pattern(
1132 	dk4_gra_t		*gra,
1133 	double			 xl,
1134 	double			 xr,
1135 	double			 yb,
1136 	double			 yt,
1137 	int				 pn,
1138 	const double	*val,
1139 	int				*backptr,
1140 	dk4_er_t		*erp
1141 );
1142 
1143 
1144 /*
1145 	Module dk4greps - EPS output module
1146 	-----------------------------------
1147 */
1148 
1149 /**	Open output structure to create a PS or EPS file.
1150 	@param	fn		File name for output file.
1151 	@param	w		Image width in bp.
1152 	@param	h		Image height in bp.
1153 	@param	docfl	Document flag set.
1154 	@param	erp		Error report, may be NULL.
1155 	@return	Valid pointer to new structure on success, NULL on error.
1156 
1157 	Error codes:
1158 	- DK4_E_MATH_OVERFLOW<br>
1159 	  on numeric overflow when calculating object sizes in memory,
1160 	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
1161 	  with mem.elsize and mem.nelem set if there is not enough memory
1162 	  available.
1163 */
1164 
1165 dk4_gra_t *
1166 dk4gra_eps_open(
1167 	const dkChar	*fn,
1168 	size_t			 w,
1169 	size_t			 h,
1170 	int				 docfl,
1171 	dk4_er_t		*erp
1172 );
1173 
1174 
1175 /**	Close output structure without writing an output file.
1176 	@param	gra	Output structure.
1177 */
1178 void
1179 dk4gra_eps_close(
1180 	dk4_gra_t		*gra
1181 );
1182 
1183 
1184 /**	Write output file and close output structure.
1185 	@param	fout	Output file.
1186 	@param	gra		Output structure.
1187 	@param	erp		Error report, may be NULL.
1188 	@return	1 on success, 0 on error.
1189 
1190 	Error codes:
1191 	- DK4_E_WRITE_FAILED<br>
1192 	  if writing one ore multiple bytes to the stream failed,
1193 	- DK4_E_FLUSH_FAILED<br>
1194 	  if flusing data downwards failed.
1195 */
1196 
1197 int
1198 dk4gra_eps_write_file_and_close(
1199 	FILE			*fout,
1200 	dk4_gra_t		*gra,
1201 	dk4_er_t		*erp
1202 );
1203 
1204 
1205 /**	Start new page.
1206 	@param	gra		Output structure.
1207 	@param	flags	Flags for new page.
1208 	@param	erp		Error report, may be NULL.
1209 	@return	1 on success, 0 on error.
1210 
1211 	Error codes:
1212 	- DK4_E_INVALID_ARGUMENTS<br>
1213 	  if gra is NULL.
1214 	- DK4_E_WRITE_FAILED<br>
1215 	  if writing one ore multiple bytes to the stream failed
1216 	- DK4_E_FLUSH_FAILED<br>
1217 	  if flushing data downwards failed,
1218 	- DK4_E_MATH_OVERFLOW<br>
1219 	  on numeric overflow when calculating the product of elsize and nelem,
1220 	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
1221 	  with mem.elsize and mem.nelem set if there is not enough memory
1222 	  available.
1223 */
1224 
1225 int
1226 dk4gra_eps_page(
1227 	dk4_gra_t		*gra,
1228 	int				 flags,
1229 	dk4_er_t		*erp
1230 );
1231 
1232 
1233 /**	Save current graphics state (especially clip path).
1234 	@param	gra	Output structure.
1235 	@param	erp	Error report, may be NULL.
1236 	@return	1 on success, 0 on error.
1237 
1238 	Error codes:
1239 	- DK4_E_INVALID_ARGUMENTS<br>
1240 	  if gra is NULL o not in a state allowing this
1241 	  operation,
1242 	- DK4_E_WRITE_FAILED<br>
1243 	  if writing one ore multiple bytes to the stream failed
1244 	- DK4_E_FLUSH_FAILED<br>
1245 	  if flushing data downwards failed.
1246 */
1247 
1248 int
1249 dk4gra_eps_gsave(
1250 	dk4_gra_t		*gra,
1251 	dk4_er_t		*erp
1252 );
1253 
1254 
1255 /**	Restore graphics state (especially clip path).
1256 	@param	gra	Output structure.
1257 	@param	erp	Error report, may be NULL.
1258 	@return	1 on success, 0 on error.
1259 
1260 	Error codes:
1261 	- DK4_E_INVALID_ARGUMENTS<br>
1262 	  if gra is NULL or not in a state allowing this
1263 	  operation,
1264 	- DK4_E_WRITE_FAILED<br>
1265 	  if writing one ore multiple bytes to the stream failed
1266 	- DK4_E_FLUSH_FAILED<br>
1267 	  if flushing data downwards failed.
1268 */
1269 
1270 int
1271 dk4gra_eps_grestore(
1272 	dk4_gra_t		*gra,
1273 	dk4_er_t		*erp
1274 );
1275 
1276 
1277 /**	Set line width.
1278 	@param	gra	Output structure.
1279 	@param	lw	Line width in bp.
1280 	@param	erp	Error report, may be NULL.
1281 	@return	1 on success, 0 on error.
1282 
1283 	Error codes:
1284 	- DK4_E_INVALID_ARGUMENTS<br>
1285 	  if gra is NULL or not in a state allowing this
1286 	  operation,
1287 	- DK4_E_WRITE_FAILED<br>
1288 	  if writing one ore multiple bytes to the stream failed
1289 	- DK4_E_FLUSH_FAILED<br>
1290 	  if flushing data downwards failed.
1291 */
1292 
1293 int
1294 dk4gra_eps_set_line_width(
1295 	dk4_gra_t		*gra,
1296 	double			 lw,
1297 	dk4_er_t		*erp
1298 );
1299 
1300 
1301 /**	Set line style.
1302 	@param	gra	Output structure.
1303 	@param	ls	Line style.
1304 	@param	sv	Style value (dash length in bp).
1305 	@param	erp	Error report, may be NULL.
1306 	@return	1 on success, 0 on error.
1307 */
1308 
1309 int
1310 dk4gra_eps_set_line_style(
1311 	dk4_gra_t		*gra,
1312 	int				 ls,
1313 	double			 sv,
1314 	dk4_er_t		*erp
1315 );
1316 
1317 
1318 /**	Set line cap.
1319 	@param	gra	Output structure.
1320 	@param	lc	Line cap type.
1321 	@param	erp	Error report, may be NULL.
1322 	@return	1 on success, 0 on error.
1323 */
1324 
1325 int
1326 dk4gra_eps_set_line_cap(
1327 	dk4_gra_t		*gra,
1328 	int				 lc,
1329 	dk4_er_t		*erp
1330 );
1331 
1332 
1333 /**	Set line join.
1334 	@param	gra	Output structure.
1335 	@param	lj	Line join type.
1336 	@param	ml	Miter limit.
1337 	@param	erp	Error report, may be NULL.
1338 	@return	1 on success, 0 on error.
1339 */
1340 
1341 int
1342 dk4gra_eps_set_line_join(
1343 	dk4_gra_t		*gra,
1344 	int				 lj,
1345 	double			 ml,
1346 	dk4_er_t		*erp
1347 );
1348 
1349 
1350 /**	Set fill color to gray.
1351 	@param	gra	Output structure.
1352 	@param	g	Gray value in interval 0 to 1.
1353 	@param	erp	Error report, may be NULL.
1354 	@return	1 on success, 0 on error.
1355 */
1356 
1357 int
1358 dk4gra_eps_set_fill_gray(
1359 	dk4_gra_t		*gra,
1360 	double			 g,
1361 	dk4_er_t		*erp
1362 );
1363 
1364 
1365 /**	Set fill color to RGB.
1366 	@param	gra	Output structure.
1367 	@param	r	Red value in interval 0 to 1.
1368 	@param	g	Green value in interval 0 to 1.
1369 	@param	b	Blue value in interval 0 to 1.
1370 	@param	erp	Error report, may be NULL.
1371 	@return	1 on success, 0 on error.
1372 */
1373 
1374 int
1375 dk4gra_eps_set_fill_rgb(
1376 	dk4_gra_t		*gra,
1377 	double			 r,
1378 	double			 g,
1379 	double			 b,
1380 	dk4_er_t		*erp
1381 );
1382 
1383 
1384 /**	Set fill color to CMYK.
1385 	@param	gra	Output structure.
1386 	@param	c	Cyan value in interval 0 to 1.
1387 	@param	m	Magenta value in interval 0 to 1.
1388 	@param	y	Yellow value in interval 0 to 1.
1389 	@param	k	Black value in interval 0 to 1.
1390 	@param	erp	Error report, may be NULL.
1391 	@return	1 on success, 0 on error.
1392 */
1393 
1394 int
1395 dk4gra_eps_set_fill_cmyk(
1396 	dk4_gra_t		*gra,
1397 	double			 c,
1398 	double			 m,
1399 	double			 y,
1400 	double			 k,
1401 	dk4_er_t		*erp
1402 );
1403 
1404 
1405 /**	Set stroke color to gray.
1406 	@param	gra	Output structure.
1407 	@param	g	Gray value in interval 0 to 1.
1408 	@param	erp	Error report, may be NULL.
1409 	@return	1 on success, 0 on error.
1410 */
1411 
1412 int
1413 dk4gra_eps_set_stroke_gray(
1414 	dk4_gra_t		*gra,
1415 	double			 g,
1416 	dk4_er_t		*erp
1417 );
1418 
1419 
1420 /**	Set stroke color to RGB.
1421 	@param	gra	Output structure.
1422 	@param	r	Red value in interval 0 to 1.
1423 	@param	g	Green value in interval 0 to 1.
1424 	@param	b	Blue value in interval 0 to 1.
1425 	@param	erp	Error report, may be NULL.
1426 	@return	1 on success, 0 on error.
1427 */
1428 
1429 int
1430 dk4gra_eps_set_stroke_rgb(
1431 	dk4_gra_t		*gra,
1432 	double			 r,
1433 	double			 g,
1434 	double			 b,
1435 	dk4_er_t		*erp
1436 );
1437 
1438 
1439 /**	Set stroke color to CMYK.
1440 	@param	gra	Output structure.
1441 	@param	c	Cyan value in interval 0 to 1.
1442 	@param	m	Magenta value in interval 0 to 1.
1443 	@param	y	Yellow value in interval 0 to 1.
1444 	@param	k	Black value in interval 0 to 1.
1445 	@param	erp	Error report, may be NULL.
1446 	@return	1 on success, 0 on error.
1447 */
1448 
1449 int
1450 dk4gra_eps_set_stroke_cmyk(
1451 	dk4_gra_t		*gra,
1452 	double			 c,
1453 	double			 m,
1454 	double			 y,
1455 	double			 k,
1456 	dk4_er_t		*erp
1457 );
1458 
1459 
1460 
1461 /**	Prepare output structure for a fill operation.
1462 	Use this function before you start to construct a path you plan to fill.
1463 	@param	gra	Output structure.
1464 	@param	erp	Error report, may be NULL.
1465 	@return	1 on success, 0 on error.
1466 */
1467 
1468 int
1469 dk4gra_eps_prepare_fill(
1470 	dk4_gra_t	*gra,
1471 	dk4_er_t	*erp
1472 );
1473 
1474 
1475 /**	Prepare output structure for a stroke operation.
1476 	Use this function before you start to construct a path you plan to stroke.
1477 	@param	gra	Output structure.
1478 	@param	erp	Error report, may be NULL.
1479 	@return	1 on success, 0 on error.
1480 */
1481 
1482 int
1483 dk4gra_eps_prepare_stroke(
1484 	dk4_gra_t	*gra,
1485 	dk4_er_t	*erp
1486 );
1487 
1488 
1489 /**	Fill current path.
1490 	Note: Use dk4gra_eps_prepare_fill() before you start to construct a path
1491 	you plan to fill.
1492 	@param	gra	Output structure.
1493 	@param	erp	Error report, may be NULL.
1494 	@return	1 on success, 0 on error.
1495 */
1496 
1497 int
1498 dk4gra_eps_fill(
1499 	dk4_gra_t		*gra,
1500 	dk4_er_t		*erp
1501 );
1502 
1503 
1504 /**	Stroke current path.
1505 	Note: Use dk4gra_eps_prepare_stroke() before you start to construct a path
1506 	you plan to stroke.
1507 	@param	gra	Output structure.
1508 	@param	erp	Error report, may be NULL.
1509 	@return	1 on success, 0 on error.
1510 */
1511 
1512 int
1513 dk4gra_eps_stroke(
1514 	dk4_gra_t		*gra,
1515 	dk4_er_t		*erp
1516 );
1517 
1518 
1519 
1520 /**	Use current path for clipping.
1521 	@param	gra	Output structure.
1522 	@param	erp	Error report, may be NULL.
1523 	@return	1 on success, 0 on error.
1524 */
1525 
1526 int
1527 dk4gra_eps_clip(
1528 	dk4_gra_t		*gra,
1529 	dk4_er_t		*erp
1530 );
1531 
1532 
1533 /**	Pattern a region (clipping should be set to the path).
1534 	@param	gra	Output structure.
1535 	@param	pn	Pattern number.
1536 	@param	erp	Error report, may be NULL.
1537 	@return	1 on success, 0 on error.
1538 */
1539 
1540 int
1541 dk4gra_eps_pattern(
1542 	dk4_gra_t		*gra,
1543 	int				 pn,
1544 	double			*xval,
1545 	dk4_er_t		*erp
1546 );
1547 
1548 
1549 /**	Start a new path and move to first point.
1550 	@param	gra		Output structure.
1551 	@param	x		X coordinate of start point.
1552 	@param	y		Y coordinate of start point.
1553 	@param	bbptr	Bounding box, may be NULL.
1554 	@param	erp		Error report, may be NULL.
1555 	@return	1 on success, 0 on error.
1556 */
1557 
1558 int
1559 dk4gra_eps_newpath_moveto(
1560 	dk4_gra_t		*gra,
1561 	double			 x,
1562 	double			 y,
1563 	dk4_er_t		*erp
1564 );
1565 
1566 
1567 /**	Add line from current point to new point to path.
1568 	@param	gra		Output structure.
1569 	@param	x		X coordinate of new point.
1570 	@param	y		Y coordinate of new point.
1571 	@param	bbptr	Bounding box, may be NULL.
1572 	@param	erp		Error report, may be NULL.
1573 	@return	1 on success, 0 on error.
1574 */
1575 
1576 int
1577 dk4gra_eps_lineto(
1578 	dk4_gra_t		*gra,
1579 	double			 x,
1580 	double			 y,
1581 	dk4_er_t		*erp
1582 );
1583 
1584 
1585 /**	Add Bezier curve segment from current point to new point in path.
1586 	@param	gra		Output structure.
1587 	@param	x1c		X coordinate of first control point.
1588 	@param	y1c		Y coordinate of first control point.
1589 	@param	x2c		X coordinate of second control point.
1590 	@param	y2c		Y coordinate of second control point.
1591 	@param	x		X coordinate of new point.
1592 	@param	y		Y coordinate of new point.
1593 	@param	bbptr	Bounding box, may be NULL.
1594 	@param	erp		Error report, may be NULL.
1595 	@return	1 on success, 0 on error.
1596 */
1597 
1598 int
1599 dk4gra_eps_curveto(
1600 	dk4_gra_t		*gra,
1601 	double			 xc1,
1602 	double			 yc1,
1603 	double			 xc2,
1604 	double			 yc2,
1605 	double			 x,
1606 	double			 y,
1607 	dk4_er_t		*erp
1608 );
1609 
1610 
1611 /**	Close current path.
1612 	@param	gra	Output structure.
1613 	@param	erp	Error report, may be NULL.
1614 	@return	1 on success, 0 on error.
1615 */
1616 
1617 int
1618 dk4gra_eps_closepath(
1619 	dk4_gra_t		*gra,
1620 	dk4_er_t		*erp
1621 );
1622 
1623 
1624 
1625 /**	Create path for a circle.
1626 	@param	gra		Output structure.
1627 	@param	xc		Center point x coordinate.
1628 	@param	yc		Center point y coordinate.
1629 	@param	r		Radius.
1630 	@param	bbptr	Bounding box, may be NULL.
1631 	@param	erp		Error report, may be NULL.
1632 	@return	1 on success, 0 on error.
1633 */
1634 
1635 int
1636 dk4gra_eps_circle(
1637 	dk4_gra_t		*gra,
1638 	double			 xc,
1639 	double			 yc,
1640 	double			 r,
1641 	dk4_er_t		*erp
1642 );
1643 
1644 
1645 /**	Create path for rectangle parallel to axes, optionally with
1646 	rounded corners.
1647 	@param	gra		Output structure.
1648 	@param	xl		Left x coordinate.
1649 	@param	xr		Right x coordinate.
1650 	@param	yb		Bottom y coordinate.
1651 	@param	yt		Top y coordinate.
1652 	@param	r		Corner radius, maximum is a half of the smaller side length.
1653 					Use negative values to avoid rounded corners.
1654 	@param	bbptr	Bounding box, may be NULL.
1655 	@param	erp		Error report, may be NULL.
1656 	@return	1 on success, 0 on error.
1657 */
1658 
1659 int
1660 dk4gra_eps_rectangle(
1661 	dk4_gra_t		*gra,
1662 	double			 xl,
1663 	double			 xr,
1664 	double			 yb,
1665 	double			 yt,
1666 	double			 r,
1667 	dk4_er_t		*erp
1668 );
1669 
1670 
1671 /**	Add path for an arc.
1672 	@param	gra		Output structure.
1673 	@param	xc		Center point x coordinate.
1674 	@param	yc		Center point y coordinate.
1675 	@param	ra		Radius.
1676 	@param	start	Start angle in degree.
1677 	@param	end		End angle in degree.
1678 	@param	cl		Flag: Draw closed arc (piece of cake) instead of simple arc.
1679 	@param	bbptr	Bounding box, may be NULL.
1680 	@param	erp		Error report, may be NULL.
1681 */
1682 
1683 int
1684 dk4gra_eps_arc(
1685 	dk4_gra_t		*gra,
1686 	double			 xc,
1687 	double			 yc,
1688 	double			 ra,
1689 	double			 start,
1690 	double			 end,
1691 	int				 cl,
1692 	dk4_er_t		*erp
1693 );
1694 
1695 
1696 /**	Add bitmap image.
1697 	@param	gra		Output structure.
1698 	@param	cotra	Coordinates transformation values.
1699 	@param	bif		Bitmap image.
1700 	@param	fn		Bitmap image file name.
1701 	@param	fno		Frame number.
1702 	@param	ifl		Image flags.
1703 	@param	erp		Error report, may be NULL.
1704 	@return	1 on success, 0 on error.
1705 */
1706 
1707 int
1708 dk4gra_eps_bif_fig_image(
1709 	dk4_gra_t		*gra,
1710 	double			*cotra,
1711 	dk4_bif_t		*bif,
1712 	const dkChar	*fn,
1713 	int				 ifl,
1714 	dk4_er_t		*erp
1715 );
1716 
1717 
1718 /**	Save current graphics states attributes to internal copy.
1719 	@param	gra	Output structure.
1720 */
1721 
1722 void
1723 dk4gra_eps_save_attributes(
1724 	dk4_gra_t	*gra
1725 );
1726 
1727 
1728 /**	Restore current graphics states attributes from internal copy.
1729 	@param	gra	Output structure.
1730 */
1731 
1732 void
1733 dk4gra_eps_restore_attributes(
1734 	dk4_gra_t	*gra
1735 );
1736 
1737 
1738 /**	Reset used attributes.
1739 	@param	gra	Output structure.
1740 */
1741 void
1742 dk4gra_eps_reset_attributes(
1743 	dk4_gra_t	*gra
1744 );
1745 
1746 
1747 /*
1748 	Module dk4grpgf - PDF output module
1749 	-----------------------------------
1750 */
1751 
1752 /**	Open output structure to create a PS or EPS file.
1753 	@param	fn	File name for output file.
1754 	@param	w	Image width in bp.
1755 	@param	h	Image height in bp.
1756 	@param	eps	Flag: Produce EPS.
1757 	@return	Valid pointer to new structure on success, NULL on error.
1758 */
1759 
1760 dk4_gra_t *
1761 dk4gra_pdf_open(
1762 	const dkChar	*fn,
1763 	size_t			 w,
1764 	size_t			 h,
1765 	int				 docfl,
1766 	dk4_er_t		*erp
1767 );
1768 
1769 
1770 /**	Close output structure without writing an output file.
1771 	@param	gra	Output structure.
1772 */
1773 void
1774 dk4gra_pdf_close(
1775 	dk4_gra_t		*gra
1776 );
1777 
1778 
1779 /**	Write output file and close output structure.
1780 	@param	fout	Output file.
1781 	@param	gra		Output structure.
1782 	@param	erp		Error report, may be NULL.
1783 	@return	1 on success, 0 on error.
1784 */
1785 
1786 int
1787 dk4gra_pdf_write_file_and_close(
1788 	FILE			*fout,
1789 	dk4_gra_t		*gra,
1790 	dk4_er_t		*erp
1791 );
1792 
1793 
1794 /**	Start new page.
1795 	@param	gra		Output structure.
1796 	@param	flags	Flags for new page.
1797 	@param	erp		Error report, may be NULL.
1798 	@return	1 on success, 0 on error.
1799 */
1800 
1801 int
1802 dk4gra_pdf_page(
1803 	dk4_gra_t		*gra,
1804 	int				 flags,
1805 	dk4_er_t		*erp
1806 );
1807 
1808 
1809 /**	Save current graphics state (especially clip path).
1810 	@param	gra	Output structure.
1811 	@param	erp	Error report, may be NULL.
1812 	@return	1 on success, 0 on error.
1813 */
1814 
1815 int
1816 dk4gra_pdf_gsave(
1817 	dk4_gra_t		*gra,
1818 	dk4_er_t		*erp
1819 );
1820 
1821 
1822 /**	Save current graphics state (especially clip path).
1823 	@param	gra		Output structure.
1824 	@param	backptr	Address of success variable to reset on errors.
1825 	@param	erp		Error report, may be NULL.
1826 */
1827 
1828 void
1829 dk4gra_pdf_i_gsave(
1830 	dk4_gra_t		*gra,
1831 	int				*backptr,
1832 	dk4_er_t		*erp
1833 );
1834 
1835 
1836 /**	Restore graphics state (especially clip path).
1837 	@param	gra	Output structure.
1838 	@param	erp	Error report, may be NULL.
1839 	@return	1 on success, 0 on error.
1840 */
1841 
1842 int
1843 dk4gra_pdf_grestore(
1844 	dk4_gra_t		*gra,
1845 	dk4_er_t		*erp
1846 );
1847 
1848 
1849 /**	Restore graphics state (especially clip path).
1850 	@param	gra		Output structure.
1851 	@param	backptr	Address of success variable to reset on errors.
1852 	@param	erp		Error report, may be NULL.
1853 */
1854 
1855 void
1856 dk4gra_pdf_i_grestore(
1857 	dk4_gra_t		*gra,
1858 	int				*backptr,
1859 	dk4_er_t		*erp
1860 );
1861 
1862 
1863 /**	Set line width.
1864 	@param	gra	Output structure.
1865 	@param	lw	Line width in bp.
1866 	@param	erp	Error report, may be NULL.
1867 	@return	1 on success, 0 on error.
1868 */
1869 
1870 int
1871 dk4gra_pdf_set_line_width(
1872 	dk4_gra_t		*gra,
1873 	double			 lw,
1874 	dk4_er_t		*erp
1875 );
1876 
1877 
1878 /**	Set line style.
1879 	@param	gra	Output structure.
1880 	@param	ls	Line style.
1881 	@param	sv	Style value (dash length in bp).
1882 	@param	erp	Error report, may be NULL.
1883 	@return	1 on success, 0 on error.
1884 */
1885 
1886 int
1887 dk4gra_pdf_set_line_style(
1888 	dk4_gra_t		*gra,
1889 	int				 ls,
1890 	double			 sv,
1891 	dk4_er_t		*erp
1892 );
1893 
1894 
1895 /**	Set line cap.
1896 	@param	gra	Output structure.
1897 	@param	lc	Line cap type.
1898 	@param	erp	Error report, may be NULL.
1899 	@return	1 on success, 0 on error.
1900 */
1901 
1902 int
1903 dk4gra_pdf_set_line_cap(
1904 	dk4_gra_t		*gra,
1905 	int				 lc,
1906 	dk4_er_t		*erp
1907 );
1908 
1909 
1910 /**	Set line join.
1911 	@param	gra	Output structure.
1912 	@param	lj	Line join type.
1913 	@param	ml	Miter limit.
1914 	@param	erp	Error report, may be NULL.
1915 	@return	1 on success, 0 on error.
1916 */
1917 
1918 int
1919 dk4gra_pdf_set_line_join(
1920 	dk4_gra_t		*gra,
1921 	int				 lj,
1922 	double			 ml,
1923 	dk4_er_t		*erp
1924 );
1925 
1926 
1927 /**	Set fill color to gray.
1928 	@param	gra	Output structure.
1929 	@param	g	Gray value in interval 0 to 1.
1930 	@param	erp	Error report, may be NULL.
1931 	@return	1 on success, 0 on error.
1932 */
1933 
1934 int
1935 dk4gra_pdf_set_fill_gray(
1936 	dk4_gra_t		*gra,
1937 	double			 g,
1938 	dk4_er_t		*erp
1939 );
1940 
1941 
1942 /**	Set fill color to RGB.
1943 	@param	gra	Output structure.
1944 	@param	r	Red value in interval 0 to 1.
1945 	@param	g	Green value in interval 0 to 1.
1946 	@param	b	Blue value in interval 0 to 1.
1947 	@param	erp	Error report, may be NULL.
1948 	@return	1 on success, 0 on error.
1949 */
1950 
1951 int
1952 dk4gra_pdf_set_fill_rgb(
1953 	dk4_gra_t		*gra,
1954 	double			 r,
1955 	double			 g,
1956 	double			 b,
1957 	dk4_er_t		*erp
1958 );
1959 
1960 
1961 /**	Set fill color to CMYK.
1962 	@param	gra	Output structure.
1963 	@param	c	Cyan value in interval 0 to 1.
1964 	@param	m	Magenta value in interval 0 to 1.
1965 	@param	y	Yellow value in interval 0 to 1.
1966 	@param	k	Black value in interval 0 to 1.
1967 	@param	erp	Error report, may be NULL.
1968 	@return	1 on success, 0 on error.
1969 */
1970 
1971 int
1972 dk4gra_pdf_set_fill_cmyk(
1973 	dk4_gra_t		*gra,
1974 	double			 c,
1975 	double			 m,
1976 	double			 y,
1977 	double			 k,
1978 	dk4_er_t		*erp
1979 );
1980 
1981 
1982 /**	Set stroke color to gray.
1983 	@param	gra	Output structure.
1984 	@param	g	Gray value in interval 0 to 1.
1985 	@param	erp	Error report, may be NULL.
1986 	@return	1 on success, 0 on error.
1987 */
1988 
1989 int
1990 dk4gra_pdf_set_stroke_gray(
1991 	dk4_gra_t		*gra,
1992 	double			 g,
1993 	dk4_er_t		*erp
1994 );
1995 
1996 
1997 /**	Set stroke color to RGB.
1998 	@param	gra	Output structure.
1999 	@param	r	Red value in interval 0 to 1.
2000 	@param	g	Green value in interval 0 to 1.
2001 	@param	b	Blue value in interval 0 to 1.
2002 	@param	erp	Error report, may be NULL.
2003 	@return	1 on success, 0 on error.
2004 */
2005 
2006 int
2007 dk4gra_pdf_set_stroke_rgb(
2008 	dk4_gra_t		*gra,
2009 	double			 r,
2010 	double			 g,
2011 	double			 b,
2012 	dk4_er_t		*erp
2013 );
2014 
2015 
2016 /**	Set stroke color to CMYK.
2017 	@param	gra	Output structure.
2018 	@param	c	Cyan value in interval 0 to 1.
2019 	@param	m	Magenta value in interval 0 to 1.
2020 	@param	y	Yellow value in interval 0 to 1.
2021 	@param	k	Black value in interval 0 to 1.
2022 	@param	erp	Error report, may be NULL.
2023 	@return	1 on success, 0 on error.
2024 */
2025 
2026 int
2027 dk4gra_pdf_set_stroke_cmyk(
2028 	dk4_gra_t		*gra,
2029 	double			 c,
2030 	double			 m,
2031 	double			 y,
2032 	double			 k,
2033 	dk4_er_t		*erp
2034 );
2035 
2036 
2037 
2038 /**	Prepare output structure for a fill operation.
2039 	Use this function before you start to construct a path you plan to fill.
2040 	@param	gra	Output structure.
2041 	@param	erp	Error report, may be NULL.
2042 	@return	1 on success, 0 on error.
2043 */
2044 
2045 int
2046 dk4gra_pdf_prepare_fill(
2047 	dk4_gra_t	*gra,
2048 	dk4_er_t	*erp
2049 );
2050 
2051 
2052 /**	Prepare output structure for a stroke operation.
2053 	Use this function before you start to construct a path you plan to stroke.
2054 	@param	gra	Output structure.
2055 	@param	erp	Error report, may be NULL.
2056 	@return	1 on success, 0 on error.
2057 */
2058 
2059 int
2060 dk4gra_pdf_prepare_stroke(
2061 	dk4_gra_t	*gra,
2062 	dk4_er_t	*erp
2063 );
2064 
2065 
2066 /**	Prepare output structure for a combined fill and stroke operation.
2067 	Use this function before you start to construct a path you plan to
2068 	fill and stroke.
2069 	@param	gra	Output structure.
2070 	@param	erp	Error report, may be NULL.
2071 	@return	1 on success, 0 on error.
2072 */
2073 
2074 int
2075 dk4gra_pdf_prepare_fill_and_stroke(
2076 	dk4_gra_t	*gra,
2077 	dk4_er_t	*erp
2078 );
2079 
2080 
2081 
2082 /**	Fill current path.
2083 	Note: Use dk4gra_pdf_prepare_fill() before you start to construct a path
2084 	you plan to fill.
2085 	@param	gra	Output structure.
2086 	@param	erp	Error report, may be NULL.
2087 	@return	1 on success, 0 on error.
2088 */
2089 
2090 int
2091 dk4gra_pdf_fill(
2092 	dk4_gra_t		*gra,
2093 	dk4_er_t		*erp
2094 );
2095 
2096 
2097 /**	Stroke current path.
2098 	Note: Use dk4gra_pdf_prepare_stroke() before you start to construct a path
2099 	you plan to stroke.
2100 	@param	gra	Output structure.
2101 	@param	erp	Error report, may be NULL.
2102 	@return	1 on success, 0 on error.
2103 */
2104 
2105 int
2106 dk4gra_pdf_stroke(
2107 	dk4_gra_t		*gra,
2108 	dk4_er_t		*erp
2109 );
2110 
2111 
2112 /**	Fill and stroke current path.
2113 	Note: Use dk4gra_pdf_prepare_fill_and_stroke() before you start to construct
2114 	a path you plan to fill and stroke.
2115 	@param	gra	Output structure.
2116 	@param	erp	Error report, may be NULL.
2117 	@return	1 on success, 0 on error.
2118 */
2119 
2120 int
2121 dk4gra_pdf_fill_and_stroke(
2122 	dk4_gra_t		*gra,
2123 	dk4_er_t		*erp
2124 );
2125 
2126 
2127 /**	Use current path for clipping.
2128 	@param	gra	Output structure.
2129 	@param	erp	Error report, may be NULL.
2130 	@return	1 on success, 0 on error.
2131 */
2132 
2133 int
2134 dk4gra_pdf_clip(
2135 	dk4_gra_t		*gra,
2136 	dk4_er_t		*erp
2137 );
2138 
2139 
2140 /**	Start a new path and move to first point.
2141 	@param	gra		Output structure.
2142 	@param	x		X coordinate of start point.
2143 	@param	y		Y coordinate of start point.
2144 	@param	bbptr	Bounding box, may be NULL.
2145 	@param	erp		Error report, may be NULL.
2146 	@return	1 on success, 0 on error.
2147 */
2148 
2149 int
2150 dk4gra_pdf_newpath_moveto(
2151 	dk4_gra_t		*gra,
2152 	double			 x,
2153 	double			 y,
2154 	dk4_er_t		*erp
2155 );
2156 
2157 
2158 /**	Add line from current point to new point to path.
2159 	@param	gra		Output structure.
2160 	@param	x		X coordinate of new point.
2161 	@param	y		Y coordinate of new point.
2162 	@param	bbptr	Bounding box, may be NULL.
2163 	@param	erp		Error report, may be NULL.
2164 	@return	1 on success, 0 on error.
2165 */
2166 
2167 int
2168 dk4gra_pdf_lineto(
2169 	dk4_gra_t		*gra,
2170 	double			 x,
2171 	double			 y,
2172 	dk4_er_t		*erp
2173 );
2174 
2175 
2176 /**	Add Bezier curve segment from current point to new point in path.
2177 	@param	gra		Output structure.
2178 	@param	x1c		X coordinate of first control point.
2179 	@param	y1c		Y coordinate of first control point.
2180 	@param	x2c		X coordinate of second control point.
2181 	@param	y2c		Y coordinate of second control point.
2182 	@param	x		X coordinate of new point.
2183 	@param	y		Y coordinate of new point.
2184 	@param	bbptr	Bounding box, may be NULL.
2185 	@param	erp		Error report, may be NULL.
2186 	@return	1 on success, 0 on error.
2187 */
2188 
2189 int
2190 dk4gra_pdf_curveto(
2191 	dk4_gra_t		*gra,
2192 	double			 xc1,
2193 	double			 yc1,
2194 	double			 xc2,
2195 	double			 yc2,
2196 	double			 x,
2197 	double			 y,
2198 	dk4_er_t		*erp
2199 );
2200 
2201 
2202 /**	Close current path.
2203 	@param	gra	Output structure.
2204 	@param	erp	Error report, may be NULL.
2205 	@return	1 on success, 0 on error.
2206 */
2207 
2208 int
2209 dk4gra_pdf_closepath(
2210 	dk4_gra_t		*gra,
2211 	dk4_er_t		*erp
2212 );
2213 
2214 
2215 /**	Create path for rectangle parallel to axes, optionally with
2216 	rounded corners.
2217 	@param	gra		Output structure.
2218 	@param	xl		Left x coordinate.
2219 	@param	xr		Right x coordinate.
2220 	@param	yb		Bottom y coordinate.
2221 	@param	yt		Top y coordinate.
2222 	@param	r		Corner radius, maximum is a half of the smaller side length.
2223 					Use negative values to avoid rounded corners.
2224 	@param	bbptr	Bounding box, may be NULL.
2225 	@param	erp		Error report, may be NULL.
2226 	@return	1 on success, 0 on error.
2227 */
2228 
2229 int
2230 dk4gra_pdf_rectangle(
2231 	dk4_gra_t		*gra,
2232 	double			 xl,
2233 	double			 xr,
2234 	double			 yb,
2235 	double			 yt,
2236 	double			 r,
2237 	dk4_er_t		*erp
2238 );
2239 
2240 
2241 /**	Add path for an arc.
2242 	@param	gra		Output structure.
2243 	@param	xc		Center point x coordinate.
2244 	@param	yc		Center point y coordinate.
2245 	@param	ra		Radius.
2246 	@param	start	Start angle in degree.
2247 	@param	end		End angle in degree.
2248 	@param	cl		Flag: Draw closed arc (piece of cake) instead of simple arc.
2249 	@param	bbptr	Bounding box, may be NULL.
2250 	@param	erp		Error report, may be NULL.
2251 */
2252 
2253 int
2254 dk4gra_pdf_arc(
2255 	dk4_gra_t		*gra,
2256 	double			 xc,
2257 	double			 yc,
2258 	double			 ra,
2259 	double			 start,
2260 	double			 end,
2261 	int				 cl,
2262 	dk4_er_t		*erp
2263 );
2264 
2265 
2266 /**	Add bitmap image.
2267 	@param	gra		Output structure.
2268 	@param	cotra	Coordinates transformation values.
2269 	@param	bif		Bitmap image.
2270 	@param	fn		Bitmap image file name.
2271 	@param	fno		Frame number.
2272 	@param	ifl		Image flags.
2273 	@param	erp		Error report, may be NULL.
2274 	@return	1 on success, 0 on error.
2275 */
2276 
2277 int
2278 dk4gra_pdf_bif_fig_image(
2279 	dk4_gra_t			*gra,
2280 	double				*cotra,
2281 	dk4_bif_t			*bif,
2282 	const dkChar		*fn,
2283 	size_t				 fno,
2284 	int					 ifl,
2285 	dk4_er_t			*erp
2286 );
2287 
2288 
2289 /**	Save current graphics states attributes to internal copy.
2290 	@param	gra	Output structure.
2291 */
2292 
2293 void
2294 dk4gra_pdf_save_attributes(
2295 	dk4_gra_t	*gra
2296 );
2297 
2298 
2299 /**	Restore current graphics states attributes from internal copy.
2300 	@param	gra	Output structure.
2301 */
2302 
2303 void
2304 dk4gra_pdf_restore_attributes(
2305 	dk4_gra_t	*gra
2306 );
2307 
2308 
2309 /**	Reset used attributes.
2310 	@param	gra	Output structure.
2311 */
2312 void
2313 dk4gra_pdf_reset_attributes(
2314 	dk4_gra_t	*gra
2315 );
2316 
2317 
2318 /**	Write one static keyword to stream.
2319 	@param	os		Output stream to write to.
2320 	@param	kwi		Index of keyword in dk4_gra_pdf_c8_kw array.
2321 	@param	backptr	Address of success variable to reset on errors.
2322 	@param	erp		Error report, may be NULL.
2323 */
2324 
2325 void
2326 dk4gra_pdf_i_outstream_kw(
2327 	dk4_stream_t		*os,
2328 	size_t				 kwi,
2329 	int					*backptr,
2330 	dk4_er_t			*erp
2331 );
2332 
2333 
2334 /**	Write a number of values and one static keyword to stream.
2335 	@param	os		Output stream to write to.
2336 	@param	da		Values array.
2337 	@param	szda	Size of da (number of elements).
2338 	@param	kwi		Index of keyword in dk4_gra_pdf_c8_kw array.
2339 	@param	backptr	Address of success variable to reset on errors.
2340 	@param	erp		Error report, may be NULL.
2341 */
2342 
2343 void
2344 dk4gra_pdf_i_values_and_kw(
2345 	dk4_stream_t		*os,
2346 	double				*da,
2347 	size_t				 szda,
2348 	size_t				 kwi,
2349 	int					*backptr,
2350 	dk4_er_t			*erp
2351 );
2352 
2353 
2354 /**	Compare two used XObject entries by object number.
2355 	This function is used to build the storage sorted by object
2356 	numbers.
2357 	@param	l	Left object.
2358 	@param	r	Right object.
2359 	@param	cr	Comparison criteria (ignored).
2360 	@return	Comparison result.
2361 */
2362 int
2363 dk4gra_pdf_compare_used_xo(
2364 	const void *l,
2365 	const void *r,
2366 	int			cr
2367 );
2368 
2369 
2370 /**	Destroy XObject structure, release resources.
2371 	@param	puxo	XObject structure to destroy.
2372 */
2373 
2374 void
2375 dk4gra_pdf_xo_delete(
2376 	dk4_gra_pdf_img_xo_t	*puxo
2377 );
2378 
2379 
2380 /*
2381 	Module dk4grpgf - PGF output module
2382 	-----------------------------------
2383 */
2384 
2385 /**	Open output structure to create a PS or EPS file.
2386 	@param	fn	File name for output file.
2387 	@param	w	Image width in bp.
2388 	@param	h	Image height in bp.
2389 	@param	sa	Flag: Produce standalone TeX file.
2390 	@param	erp	Error report, may be NULL.
2391 	@return	Valid pointer to new structure on success, NULL on error.
2392 
2393 	Error codes:
2394 	- DK4_E_MATH_OVERFLOW<br>
2395 	  on numeric overflow when calculating memory size to allocate,
2396 	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
2397 	  if a memory allocation failed.
2398 */
2399 
2400 dk4_gra_t *
2401 dk4gra_pgf_open(
2402 	const dkChar	*fn,
2403 	size_t			 w,
2404 	size_t			 h,
2405 	int				 docfl,
2406 	int				 sa,
2407 	dk4_er_t		*erp
2408 );
2409 
2410 
2411 /**	Close output structure without writing an output file.
2412 	@param	gra	Output structure.
2413 */
2414 void
2415 dk4gra_pgf_close(
2416 	dk4_gra_t		*gra
2417 );
2418 
2419 
2420 /**	Write output file and close output structure.
2421 	@param	fout	Output file.
2422 	@param	gra		Output structure.
2423 	@param	erp		Error report, may be NULL.
2424 	@return	1 on success, 0 on error.
2425 
2426 	Error codes:
2427 	- DK4_E_INVALID_ARGUMENTS<br>
2428 	  if any argument is insufficient,
2429 	- DK4_E_WRITE_FAILED<br>
2430 	  if writing one ore multiple bytes to the stream failed,
2431 	- DK4_E_FLUSH_FAILED<br>
2432 	  if flushing data downwards failed,
2433 	- DK4_E_CLOSE_FAILED<br>
2434 	  if closing downward data failed,
2435 	- DK4_E_MATH_OVERFLOW<br>
2436 	  if the exponent is out of range for integer values,<br>
2437 	- DK4_E_SYNTAX<br>
2438 	  if input contains invalid characters,
2439 	- DK4_E_BUFFER_TOO_SMALL<br>
2440 	  if the destination buffer size is too small for the result,
2441 	- DK4_E_BUG<br>
2442 	  if an internal buffer is too small (should not happen).
2443 */
2444 
2445 int
2446 dk4gra_pgf_write_file_and_close(
2447 	FILE			*fout,
2448 	dk4_gra_t		*gra,
2449 	dk4_er_t		*erp
2450 );
2451 
2452 
2453 /**	Start new page.
2454 	@param	gra		Output structure.
2455 	@param	flags	Flags for new page.
2456 	@param	erp		Error report, may be NULL.
2457 	@return	1 on success, 0 on error.
2458 
2459 	Error codes:
2460 	- DK4_E_MATH_OVERFLOW<br>
2461 	  if there are too many pages in the graphics or there is a numeric
2462 	  overflow in allocation size calculation,
2463 	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
2464 	  with mem.elsize and mem.nelem set if there is not enough memory
2465 	  available.
2466 */
2467 
2468 int
2469 dk4gra_pgf_page(
2470 	dk4_gra_t		*gra,
2471 	int				 flags,
2472 	dk4_er_t		*erp
2473 );
2474 
2475 
2476 /**	Save current graphics state (especially clip path).
2477 	@param	gra	Output structure.
2478 	@param	erp	Error report, may be NULL.
2479 	@return	1 on success, 0 on error.
2480 
2481 	Error codes:
2482 	- DK4_E_SYNTAX<br>
2483 	  on internal errors,
2484 	- DK4_E_INVALID_ARGUMENTS<br>
2485 	  if str is NULL or the stream is not opened for writing,
2486 	- DK4_E_WRITE_FAILED<br>
2487 	  if writing one ore multiple bytes to the stream failed,
2488 	- DK4_E_FLUSH_FAILED<br>
2489 	  if flushing data downwards failed.
2490 */
2491 
2492 int
2493 dk4gra_pgf_gsave(
2494 	dk4_gra_t		*gra,
2495 	dk4_er_t		*erp
2496 );
2497 
2498 
2499 /**	Restore graphics state (especially clip path).
2500 	@param	gra	Output structure.
2501 	@param	erp	Error report, may be NULL.
2502 	@return	1 on success, 0 on error.
2503 
2504 	Error codes:
2505 	- DK4_E_SYNTAX<br>
2506 	  on internal errors,
2507 	- DK4_E_INVALID_ARGUMENTS<br>
2508 	  if str is NULL or the stream is not opened for writing,
2509 	- DK4_E_WRITE_FAILED<br>
2510 	  if writing one ore multiple bytes to the stream failed,
2511 	- DK4_E_FLUSH_FAILED<br>
2512 	  if flushing data downwards failed.
2513 */
2514 
2515 int
2516 dk4gra_pgf_grestore(
2517 	dk4_gra_t		*gra,
2518 	dk4_er_t		*erp
2519 );
2520 
2521 
2522 /**	Set line width.
2523 	@param	gra	Output structure.
2524 	@param	lw	Line width in bp.
2525 	@param	erp	Error report, may be NULL.
2526 	@return	1 on success, 0 on error.
2527 
2528 	- DK4_E_SYNTAX<br>
2529 	  on internal errors.
2530 */
2531 
2532 int
2533 dk4gra_pgf_set_line_width(
2534 	dk4_gra_t		*gra,
2535 	double			 lw,
2536 	dk4_er_t		*erp
2537 );
2538 
2539 
2540 /**	Set line style.
2541 	@param	gra	Output structure.
2542 	@param	ls	Line style.
2543 	@param	sv	Style value (dash length in bp).
2544 	@param	erp	Error report, may be NULL.
2545 	@return	1 on success, 0 on error.
2546 
2547 	- DK4_E_SYNTAX<br>
2548 	  on internal errors.
2549 */
2550 
2551 int
2552 dk4gra_pgf_set_line_style(
2553 	dk4_gra_t		*gra,
2554 	int				 ls,
2555 	double			 sv,
2556 	dk4_er_t		*erp
2557 );
2558 
2559 
2560 /**	Set line cap.
2561 	@param	gra	Output structure.
2562 	@param	lc	Line cap type.
2563 	@param	erp	Error report, may be NULL.
2564 	@return	1 on success, 0 on error.
2565 
2566 	- DK4_E_SYNTAX<br>
2567 	  on internal errors.
2568 */
2569 
2570 int
2571 dk4gra_pgf_set_line_cap(
2572 	dk4_gra_t		*gra,
2573 	int				 lc,
2574 	dk4_er_t		*erp
2575 );
2576 
2577 
2578 /**	Set line join.
2579 	@param	gra	Output structure.
2580 	@param	lj	Line join type.
2581 	@param	ml	Miter limit.
2582 	@param	erp	Error report, may be NULL.
2583 	@return	1 on success, 0 on error.
2584 
2585 	- DK4_E_SYNTAX<br>
2586 	  on internal errors.
2587 	- DK4_E_INVALID_ARGUMENTS<br>
2588 	  if any argument is invalid.
2589 */
2590 
2591 int
2592 dk4gra_pgf_set_line_join(
2593 	dk4_gra_t		*gra,
2594 	int				 lj,
2595 	double			 ml,
2596 	dk4_er_t		*erp
2597 );
2598 
2599 
2600 /**	Set fill color to gray.
2601 	@param	gra	Output structure.
2602 	@param	g	Gray value in interval 0 to 1.
2603 	@param	erp	Error report, may be NULL.
2604 	@return	1 on success, 0 on error.
2605 
2606 	- DK4_E_SYNTAX<br>
2607 	  on internal errors.
2608 */
2609 
2610 int
2611 dk4gra_pgf_set_fill_gray(
2612 	dk4_gra_t		*gra,
2613 	double			 g,
2614 	dk4_er_t		*erp
2615 );
2616 
2617 
2618 /**	Set fill color to RGB.
2619 	@param	gra	Output structure.
2620 	@param	r	Red value in interval 0 to 1.
2621 	@param	g	Green value in interval 0 to 1.
2622 	@param	b	Blue value in interval 0 to 1.
2623 	@param	erp	Error report, may be NULL.
2624 	@return	1 on success, 0 on error.
2625 
2626 	- DK4_E_SYNTAX<br>
2627 	  on internal errors.
2628 */
2629 
2630 int
2631 dk4gra_pgf_set_fill_rgb(
2632 	dk4_gra_t		*gra,
2633 	double			 r,
2634 	double			 g,
2635 	double			 b,
2636 	dk4_er_t		*erp
2637 );
2638 
2639 
2640 /**	Set fill color to CMYK.
2641 	@param	gra	Output structure.
2642 	@param	c	Cyan value in interval 0 to 1.
2643 	@param	m	Magenta value in interval 0 to 1.
2644 	@param	y	Yellow value in interval 0 to 1.
2645 	@param	k	Black value in interval 0 to 1.
2646 	@param	erp	Error report, may be NULL.
2647 	@return	1 on success, 0 on error.
2648 
2649 	- DK4_E_SYNTAX<br>
2650 	  on internal errors.
2651 */
2652 
2653 int
2654 dk4gra_pgf_set_fill_cmyk(
2655 	dk4_gra_t		*gra,
2656 	double			 c,
2657 	double			 m,
2658 	double			 y,
2659 	double			 k,
2660 	dk4_er_t		*erp
2661 );
2662 
2663 
2664 /**	Set stroke color to gray.
2665 	@param	gra	Output structure.
2666 	@param	g	Gray value in interval 0 to 1.
2667 	@param	erp	Error report, may be NULL.
2668 	@return	1 on success, 0 on error.
2669 
2670 	- DK4_E_SYNTAX<br>
2671 	  on internal errors.
2672 */
2673 
2674 int
2675 dk4gra_pgf_set_stroke_gray(
2676 	dk4_gra_t		*gra,
2677 	double			 g,
2678 	dk4_er_t		*erp
2679 );
2680 
2681 
2682 /**	Set stroke color to RGB.
2683 	@param	gra	Output structure.
2684 	@param	r	Red value in interval 0 to 1.
2685 	@param	g	Green value in interval 0 to 1.
2686 	@param	b	Blue value in interval 0 to 1.
2687 	@param	erp	Error report, may be NULL.
2688 	@return	1 on success, 0 on error.
2689 
2690 	- DK4_E_SYNTAX<br>
2691 	  on internal errors.
2692 */
2693 
2694 int
2695 dk4gra_pgf_set_stroke_rgb(
2696 	dk4_gra_t		*gra,
2697 	double			 r,
2698 	double			 g,
2699 	double			 b,
2700 	dk4_er_t		*erp
2701 );
2702 
2703 
2704 /**	Set stroke color to CMYK.
2705 	@param	gra	Output structure.
2706 	@param	c	Cyan value in interval 0 to 1.
2707 	@param	m	Magenta value in interval 0 to 1.
2708 	@param	y	Yellow value in interval 0 to 1.
2709 	@param	k	Black value in interval 0 to 1.
2710 	@param	erp	Error report, may be NULL.
2711 	@return	1 on success, 0 on error.
2712 
2713 	- DK4_E_SYNTAX<br>
2714 	  on internal errors.
2715 */
2716 
2717 int
2718 dk4gra_pgf_set_stroke_cmyk(
2719 	dk4_gra_t		*gra,
2720 	double			 c,
2721 	double			 m,
2722 	double			 y,
2723 	double			 k,
2724 	dk4_er_t		*erp
2725 );
2726 
2727 
2728 
2729 /**	Prepare output structure for a fill operation.
2730 	Use this function before you start to construct a path you plan to fill.
2731 	@param	gra	Output structure.
2732 	@param	erp	Error report, may be NULL.
2733 	@return	1 on success, 0 on error.
2734 
2735 	Error codes:
2736 	- DK4_E_SYNTAX<br>
2737 	  on internal errors,
2738 	- DK4_E_INVALID_ARGUMENTS<br>
2739 	  if str is NULL or the stream is not opened for writing,
2740 	- DK4_E_WRITE_FAILED<br>
2741 	  if writing one ore multiple bytes to the stream failed,
2742 	- DK4_E_FLUSH_FAILED<br>
2743 	  if flushing data downwards failed,
2744 	- DK4_E_MATH_OVERFLOW<br>
2745 	  if the exponent is out of range for integer values.
2746 */
2747 
2748 int
2749 dk4gra_pgf_prepare_fill(
2750 	dk4_gra_t	*gra,
2751 	dk4_er_t	*erp
2752 );
2753 
2754 
2755 /**	Prepare output structure for a stroke operation.
2756 	Use this function before you start to construct a path you plan to stroke.
2757 	@param	gra	Output structure.
2758 	@param	erp	Error report, may be NULL.
2759 	@return	1 on success, 0 on error.
2760 
2761 	Error codes:
2762 	- DK4_E_SYNTAX<br>
2763 	  on internal errors,
2764 	- DK4_E_INVALID_ARGUMENTS<br>
2765 	  if str is NULL or the stream is not opened for writing,
2766 	- DK4_E_WRITE_FAILED<br>
2767 	  if writing one ore multiple bytes to the stream failed,
2768 	- DK4_E_FLUSH_FAILED<br>
2769 	  if flushing data downwards failed,
2770 	- DK4_E_MATH_OVERFLOW<br>
2771 	  if the exponent is out of range for integer values.
2772 */
2773 
2774 int
2775 dk4gra_pgf_prepare_stroke(
2776 	dk4_gra_t	*gra,
2777 	dk4_er_t	*erp
2778 );
2779 
2780 
2781 /**	Prepare output structure for a combined fill and stroke operation.
2782 	Use this function before you start to construct a path you plan to
2783 	fill and stroke.
2784 	@param	gra	Output structure.
2785 	@param	erp	Error report, may be NULL.
2786 	@return	1 on success, 0 on error.
2787 
2788 	Error codes:
2789 	- DK4_E_SYNTAX<br>
2790 	  on internal errors,
2791 	- DK4_E_INVALID_ARGUMENTS<br>
2792 	  if str is NULL or the stream is not opened for writing,
2793 	- DK4_E_WRITE_FAILED<br>
2794 	  if writing one ore multiple bytes to the stream failed,
2795 	- DK4_E_FLUSH_FAILED<br>
2796 	  if flushing data downwards failed,
2797 	- DK4_E_MATH_OVERFLOW<br>
2798 	  if the exponent is out of range for integer values.
2799 */
2800 
2801 int
2802 dk4gra_pgf_prepare_fill_and_stroke(
2803 	dk4_gra_t	*gra,
2804 	dk4_er_t	*erp
2805 );
2806 
2807 
2808 
2809 /**	Fill current path.
2810 	Note: Use dk4gra_pgf_prepare_fill() before you start to construct a path
2811 	you plan to fill.
2812 	@param	gra	Output structure.
2813 	@param	erp	Error report, may be NULL.
2814 	@return	1 on success, 0 on error.
2815 
2816 	Error codes:
2817 	- DK4_E_SYNTAX<br>
2818 	  on internal errors,
2819 	- DK4_E_INVALID_ARGUMENTS<br>
2820 	  if str is NULL or the stream is not opened for writing,
2821 	- DK4_E_WRITE_FAILED<br>
2822 	  if writing one ore multiple bytes to the stream failed,
2823 	- DK4_E_FLUSH_FAILED<br>
2824 	  if flushing data downwards failed,
2825 	- DK4_E_MATH_OVERFLOW<br>
2826 	  if the exponent is out of range for integer values.
2827 */
2828 
2829 int
2830 dk4gra_pgf_fill(
2831 	dk4_gra_t		*gra,
2832 	dk4_er_t		*erp
2833 );
2834 
2835 
2836 /**	Stroke current path.
2837 	Note: Use dk4gra_pgf_prepare_stroke() before you start to construct a path
2838 	you plan to stroke.
2839 	@param	gra	Output structure.
2840 	@param	erp	Error report, may be NULL.
2841 	@return	1 on success, 0 on error.
2842 
2843 	Error codes:
2844 	- DK4_E_SYNTAX<br>
2845 	  on internal errors,
2846 	- DK4_E_INVALID_ARGUMENTS<br>
2847 	  if str is NULL or the stream is not opened for writing,
2848 	- DK4_E_WRITE_FAILED<br>
2849 	  if writing one ore multiple bytes to the stream failed,
2850 	- DK4_E_FLUSH_FAILED<br>
2851 	  if flushing data downwards failed,
2852 	- DK4_E_MATH_OVERFLOW<br>
2853 	  if the exponent is out of range for integer values.
2854 */
2855 
2856 int
2857 dk4gra_pgf_stroke(
2858 	dk4_gra_t		*gra,
2859 	dk4_er_t		*erp
2860 );
2861 
2862 
2863 /**	Fill and stroke current path.
2864 	Note: Use dk4gra_pgf_prepare_fill_and_stroke() before you start to construct
2865 	a path you plan to fill and stroke.
2866 	@param	gra	Output structure.
2867 	@param	erp	Error report, may be NULL.
2868 	@return	1 on success, 0 on error.
2869 
2870 	Error codes:
2871 	- DK4_E_SYNTAX<br>
2872 	  on internal errors,
2873 	- DK4_E_INVALID_ARGUMENTS<br>
2874 	  if str is NULL or the stream is not opened for writing,
2875 	- DK4_E_WRITE_FAILED<br>
2876 	  if writing one ore multiple bytes to the stream failed,
2877 	- DK4_E_FLUSH_FAILED<br>
2878 	  if flushing data downwards failed,
2879 	- DK4_E_MATH_OVERFLOW<br>
2880 	  if the exponent is out of range for integer values.
2881 */
2882 
2883 int
2884 dk4gra_pgf_fill_and_stroke(
2885 	dk4_gra_t		*gra,
2886 	dk4_er_t		*erp
2887 );
2888 
2889 
2890 /**	Use current path for clipping.
2891 	@param	gra	Output structure.
2892 	@param	erp	Error report, may be NULL.
2893 	@return	1 on success, 0 on error.
2894 
2895 	Error codes:
2896 	- DK4_E_SYNTAX<br>
2897 	  on internal errors,
2898 	- DK4_E_INVALID_ARGUMENTS<br>
2899 	  if str is NULL or the stream is not opened for writing,
2900 	- DK4_E_WRITE_FAILED<br>
2901 	  if writing one ore multiple bytes to the stream failed,
2902 	- DK4_E_FLUSH_FAILED<br>
2903 	  if flushing data downwards failed,
2904 	- DK4_E_MATH_OVERFLOW<br>
2905 	  if the exponent is out of range for integer values.
2906 */
2907 
2908 int
2909 dk4gra_pgf_clip(
2910 	dk4_gra_t		*gra,
2911 	dk4_er_t		*erp
2912 );
2913 
2914 
2915 /**	Start a new path and move to first point.
2916 	@param	gra		Output structure.
2917 	@param	x		X coordinate of start point.
2918 	@param	y		Y coordinate of start point.
2919 	@param	bbptr	Bounding box, may be NULL.
2920 	@param	erp		Error report, may be NULL.
2921 	@return	1 on success, 0 on error.
2922 
2923 	Error codes:
2924 	- DK4_E_SYNTAX<br>
2925 	  on internal errors,
2926 	- DK4_E_INVALID_ARGUMENTS<br>
2927 	  if str is NULL or the stream is not opened for writing,
2928 	- DK4_E_WRITE_FAILED<br>
2929 	  if writing one ore multiple bytes to the stream failed,
2930 	- DK4_E_FLUSH_FAILED<br>
2931 	  if flushing data downwards failed,
2932 	- DK4_E_MATH_OVERFLOW<br>
2933 	  if the exponent is out of range for integer values.
2934 */
2935 
2936 int
2937 dk4gra_pgf_newpath_moveto(
2938 	dk4_gra_t		*gra,
2939 	double			 x,
2940 	double			 y,
2941 	dk4_er_t		*erp
2942 );
2943 
2944 
2945 /**	Add line from current point to new point to path.
2946 	@param	gra		Output structure.
2947 	@param	x		X coordinate of new point.
2948 	@param	y		Y coordinate of new point.
2949 	@param	bbptr	Bounding box, may be NULL.
2950 	@param	erp		Error report, may be NULL.
2951 	@return	1 on success, 0 on error.
2952 
2953 	Error codes:
2954 	- DK4_E_SYNTAX<br>
2955 	  on internal errors,
2956 	- DK4_E_INVALID_ARGUMENTS<br>
2957 	  if str is NULL or the stream is not opened for writing,
2958 	- DK4_E_WRITE_FAILED<br>
2959 	  if writing one ore multiple bytes to the stream failed,
2960 	- DK4_E_FLUSH_FAILED<br>
2961 	  if flushing data downwards failed,
2962 	- DK4_E_MATH_OVERFLOW<br>
2963 	  if the exponent is out of range for integer values.
2964 */
2965 
2966 int
2967 dk4gra_pgf_lineto(
2968 	dk4_gra_t		*gra,
2969 	double			 x,
2970 	double			 y,
2971 	dk4_er_t		*erp
2972 );
2973 
2974 
2975 /**	Add Bezier curve segment from current point to new point in path.
2976 	@param	gra		Output structure.
2977 	@param	x1c		X coordinate of first control point.
2978 	@param	y1c		Y coordinate of first control point.
2979 	@param	x2c		X coordinate of second control point.
2980 	@param	y2c		Y coordinate of second control point.
2981 	@param	x		X coordinate of new point.
2982 	@param	y		Y coordinate of new point.
2983 	@param	bbptr	Bounding box, may be NULL.
2984 	@param	erp		Error report, may be NULL.
2985 	@return	1 on success, 0 on error.
2986 
2987 	Error codes:
2988 	- DK4_E_SYNTAX<br>
2989 	  on internal errors,
2990 	- DK4_E_INVALID_ARGUMENTS<br>
2991 	  if str is NULL or the stream is not opened for writing,
2992 	- DK4_E_WRITE_FAILED<br>
2993 	  if writing one ore multiple bytes to the stream failed,
2994 	- DK4_E_FLUSH_FAILED<br>
2995 	  if flushing data downwards failed,
2996 	- DK4_E_MATH_OVERFLOW<br>
2997 	  if the exponent is out of range for integer values.
2998 */
2999 
3000 int
3001 dk4gra_pgf_curveto(
3002 	dk4_gra_t		*gra,
3003 	double			 xc1,
3004 	double			 yc1,
3005 	double			 xc2,
3006 	double			 yc2,
3007 	double			 x,
3008 	double			 y,
3009 	dk4_er_t		*erp
3010 );
3011 
3012 
3013 /**	Close current path.
3014 	@param	gra	Output structure.
3015 	@param	erp	Error report, may be NULL.
3016 	@return	1 on success, 0 on error.
3017 
3018 	Error codes:
3019 	- DK4_E_SYNTAX<br>
3020 	  on internal errors,
3021 	- DK4_E_INVALID_ARGUMENTS<br>
3022 	  if str is NULL or the stream is not opened for writing,
3023 	- DK4_E_WRITE_FAILED<br>
3024 	  if writing one ore multiple bytes to the stream failed,
3025 	- DK4_E_FLUSH_FAILED<br>
3026 	  if flushing data downwards failed,
3027 	- DK4_E_MATH_OVERFLOW<br>
3028 	  if the exponent is out of range for integer values.
3029 */
3030 
3031 int
3032 dk4gra_pgf_closepath(
3033 	dk4_gra_t		*gra,
3034 	dk4_er_t		*erp
3035 );
3036 
3037 
3038 
3039 /**	Create path for a circle.
3040 	@param	gra		Output structure.
3041 	@param	xc		Center point x coordinate.
3042 	@param	yc		Center point y coordinate.
3043 	@param	r		Radius.
3044 	@param	bbptr	Bounding box, may be NULL.
3045 	@param	erp		Error report, may be NULL.
3046 	@return	1 on success, 0 on error.
3047 
3048 	Error codes:
3049 	- DK4_E_SYNTAX<br>
3050 	  on internal errors,
3051 	- DK4_E_INVALID_ARGUMENTS<br>
3052 	  if str is NULL or the stream is not opened for writing,
3053 	- DK4_E_WRITE_FAILED<br>
3054 	  if writing one ore multiple bytes to the stream failed,
3055 	- DK4_E_FLUSH_FAILED<br>
3056 	  if flushing data downwards failed,
3057 	- DK4_E_MATH_OVERFLOW<br>
3058 	  if the exponent is out of range for integer values.
3059 */
3060 
3061 int
3062 dk4gra_pgf_circle(
3063 	dk4_gra_t		*gra,
3064 	double			 xc,
3065 	double			 yc,
3066 	double			 r,
3067 	dk4_er_t		*erp
3068 );
3069 
3070 
3071 /**	Create path for rectangle parallel to axes, optionally with
3072 	rounded corners.
3073 	@param	gra		Output structure.
3074 	@param	xl		Left x coordinate.
3075 	@param	xr		Right x coordinate.
3076 	@param	yb		Bottom y coordinate.
3077 	@param	yt		Top y coordinate.
3078 	@param	r		Corner radius, maximum is a half of the smaller side length.
3079 					Use negative values to avoid rounded corners.
3080 	@param	bbptr	Bounding box, may be NULL.
3081 	@param	erp		Error report, may be NULL.
3082 	@return	1 on success, 0 on error.
3083 
3084 	Error codes:
3085 	- DK4_E_INVALID_ARGUMENTS<br>
3086 	  on internal errors, if str is NULL or the stream is not opened
3087 	  for writing,
3088 	- DK4_E_WRITE_FAILED<br>
3089 	  if writing one ore multiple bytes to the stream failed,
3090 	- DK4_E_FLUSH_FAILED<br>
3091 	  if flushing data downwards failed,
3092 	- DK4_E_MATH_OVERFLOW<br>
3093 	  if the exponent is out of range for integer values.
3094 */
3095 
3096 int
3097 dk4gra_pgf_rectangle(
3098 	dk4_gra_t		*gra,
3099 	double			 xl,
3100 	double			 xr,
3101 	double			 yb,
3102 	double			 yt,
3103 	double			 r,
3104 	dk4_er_t		*erp
3105 );
3106 
3107 
3108 /**	Add bitmap image.
3109 	@param	gra		Output structure.
3110 	@param	cotra	Coordinates transformation values.
3111 	@param	bif		Bitmap image.
3112 	@param	fn		Bitmap image file name.
3113 	@param	ifl		Image flags.
3114 	@param	erp		Error report, may be NULL.
3115 	@return	1 on success, 0 on error.
3116 */
3117 
3118 int
3119 dk4gra_pgf_bif_fig_image(
3120 	dk4_gra_t			*gra,
3121 	double				*cotra,
3122 	dk4_bif_t			*bif,
3123 	const dkChar		*fn,
3124 	int					 ifl,
3125 	dk4_er_t			*erp
3126 );
3127 
3128 
3129 /**	Save current graphics states attributes to internal copy.
3130 	@param	gra	Output structure.
3131 */
3132 
3133 void
3134 dk4gra_pgf_save_attributes(
3135 	dk4_gra_t	*gra
3136 );
3137 
3138 
3139 /**	Restore current graphics states attributes from internal copy.
3140 	@param	gra	Output structure.
3141 */
3142 
3143 void
3144 dk4gra_pgf_restore_attributes(
3145 	dk4_gra_t	*gra
3146 );
3147 
3148 
3149 /**	Reset used attributes.
3150 	@param	gra	Output structure.
3151 */
3152 void
3153 dk4gra_pgf_reset_attributes(
3154 	dk4_gra_t	*gra
3155 );
3156 
3157 /**	Close image record, release resources.
3158 	@param	imgptr	Image record to close.
3159 */
3160 void
3161 dk4gra_pgf_img_close(dk4_gra_pgf_img_no_t *imgptr);
3162 
3163 /**	Create image record, allocate resources.
3164 	@param	fn		File name for image file.
3165 	@param	imgno	Image number.
3166 	@param	ii		Flag: Use image interpolation.
3167 	@param	erp		Error report.
3168 	@return	Valid pointer to new record on success, NULL on error.
3169 
3170 	Error codes:
3171 	- DK4_E_INVALID_ARGUMENTS<br>
3172 	  if src is a NULL pointer,
3173 	- DK4_E_MATH_OVERFLOW<br>
3174 	  on mathematical overflow in size calculation,
3175 	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
3176 	  with mem.elsize and mem.nelem set if no memory is available.
3177 */
3178 dk4_gra_pgf_img_no_t *
3179 dk4gra_pgf_img_open(const dkChar *fn, size_t imgno, int ii, dk4_er_t *erp);
3180 
3181 /*
3182 	Module dk4grepp - EPS patterns
3183 	------------------------------
3184 */
3185 
3186 /**	Obtain pattern procedure name.
3187 	@param	i	Index of pattern procedure.
3188 	@return	Valid pointer to name on success, NULL on error.
3189 */
3190 const char *
3191 dk4gra_eps_pattern_name(size_t i);
3192 
3193 /**	Obtain pattern procedure definition.
3194 	@param	i	Index of pattern procedure.
3195 	@return	Valid pointer to array of strings on success, NULL on error.
3196 */
3197 const char * const *
3198 dk4gra_eps_pattern_procedure(size_t i);
3199 
3200 
3201 /*
3202  	Module dk4grpdt - Timestamp for PDF
3203 	-----------------------------------
3204 */
3205 
3206 /**	Obtain current timestamp, write as text to buffer.
3207 	@param	buf		Destination buffer.
3208 	@param	szbuf	Size of destination buffer.
3209 	@param	erp		Error report, may be NULL.
3210 	@return	1 on success, 0 on error.
3211 
3212 	Error codes:
3213 	- DK4_E_INVALID_ARGUMENTS<br>
3214 	  if buf is NULL or szbuf is less than 15,
3215 	- DK4_E_NOT_SUPPORTED<br>
3216 	  if localtime_r is not present on the system.
3217 */
3218 int
3219 dk4gra_pdf_timestamp(char *buf, size_t szbuf, dk4_er_t *erp);
3220 
3221 
3222 #ifdef	__cplusplus
3223 }
3224 #endif
3225 
3226 
3227 /* vim: set ai sw=4 ts=4 : */
3228 #endif
3229