/* Copyright 2020, Dirk Krause. All rights reserved. SPDX-License-Identifier: BSD-3-Clause */ #ifndef GRA_H_INCLUDED /** Protection against multiple inclusions. */ #define GRA_H_INCLUDED 1 /** @file gra.h Library-internal function prototypes. This header contains data types and functions used cross-module within the library but not part of the API and thus not intended for use by a library consumer. Consequently this file is not installed to /usr/include or some similar directory. */ #ifndef DK4CONF_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4conf.h" #else #include #endif #endif #ifndef DK4MEMBUF_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4membuf.h" #else #include #endif #endif #ifndef DK4MEMBS_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4membs.h" #else #include #endif #endif #ifndef DK4UFIT_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4ufit.h" #else #include #endif #endif #ifndef DK4BITSH_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4bitsh.h" #else #include #endif #endif #ifndef DK4GRA_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4gra.h" #else #include #endif #endif /** Circle approximation by 4 Bezier spline segments. */ #define KAPPA_4 0.5522847498307943 /** Circle approximation by 8 Bezier spline segments. */ #define KAPPA_8 0.2652164898395453 /** Color specification in RGB color space. */ typedef struct { double r; /**< Red. */ double g; /**< Green. */ double b; /**< Blue. */ } dk4_gra_col_rgb_t; /** Color specification in CMYK color space. */ typedef struct { double c; /**< Cyan. */ double m; /**< Magenta. */ double y; /**< Yellow. */ double k; /**< Black. */ } dk4gra_col_cmyk_t; /** Union of colors in all supported color spaces. */ typedef union { double gray; /**< Gray value. */ dk4_gra_col_rgb_t rgb; /**< Color specified in RGB. */ dk4gra_col_cmyk_t cmyk; /**< Color specified in CMYK. */ } dk4gra_col_all_t; /** Colors specified by user or active. */ typedef struct { dk4gra_col_all_t data; /**< Color data. */ int what; /**< Specified color type. */ } dk4gra_col_t; /** Values for what component in dk4gra_col_t structure. */ enum { DK4_GRA_COL_SPEC_NONE = 0, /**< No color specified yet. */ DK4_GRA_COL_SPEC_GRAY , /**< Gray specified. */ DK4_GRA_COL_SPEC_RGB , /**< RGB specified. */ DK4_GRA_COL_SPEC_CMYK /**< CMYK specified. */ }; /** Compression/encoding combinations for bitmap images. */ enum { DK4_GRA_COE_DCT_ASCII85 = 0 , DK4_GRA_COE_FLATE_ASCII85 , DK4_GRA_COE_LZW_ASCII85 , DK4_GRA_COE_RUNLENGTH_ASCII85 , DK4_GRA_COE_ASCII85 }; /** Saved and current graphics attributes. For each attribute there is the active value value currently set in the data stream and a requested value to use for the next graphics elements. When preparing for an element (i.e. to stroke a line) and the active value differs from the requested value (i.e. stroke color), we have activate the requested value in the preparation function before starting to construct the path. */ typedef struct { dk4gra_col_t col_stroke_active; /**< Current (stroke) color. */ dk4gra_col_t col_fill_active; /**< Current fill color. */ dk4gra_col_t col_stroke_requested; /**< Requested stroke color. */ dk4gra_col_t col_fill_requested; /**< Requested fill color. */ double lw_active; /**< Active line width. */ double lw_requested; /**< Requested line width. */ double sv_active; /**< Active style value. */ double sv_requested; /**< Requested style value. */ double ml_active; /**< Active miter limit. */ double ml_requested; /**< Requested miter limit. */ int lc_active; /**< Active line cap. */ int lc_requested; /**< Requested line cap. */ int lj_active; /**< Active line join. */ int lj_requested; /**< Requested line join. */ int ls_active; /**< Active line style. */ int ls_requested; /**< Requested line style. */ int eor_active; /**< Active even-odd-rule flag. */ int eor_requested; /**< Requested even-odd-rule. */ } dk4gra_attributes_t; /** PS/EPS page. All graphics instructions go through the memory stream into the memory buffer first. When writing the output file, we might want to place other contents - i.e. document structuring comments - before and after the page contents. */ typedef struct { dk4gra_attributes_t attr; /**< Graphics attributes. */ dk4gra_attributes_t catt; /**< Copy of graphics attributes. */ dk4_membuf_t *membuf; /**< Memory buffer. */ dk4_stream_t *memstrm; /**< Stream writing to mem buffer. */ unsigned char patu[DK4_GRA_PATTERN_MAX+1]; /**< Pat used. */ size_t pageno; /**< Page number. */ int spip; /**< Flag: Showpage in image proc */ int cont; /**< Flag: Already contents on page. */ int flags; /**< Page flags. */ } dk4_gra_ps_page_t; /** Image XObject type. When including a bitmap image multiple times, we reuse the XObject to save memory. */ typedef struct { dk4_ufi_t ufi; /**< Unique file identifier. */ const dkChar *fn; /**< File name. */ dk4_membuf_t *i_mb; /**< Image data. */ dk4_membuf_t *m_mb; /**< Mask data. */ size_t fno; /**< Frame number. */ size_t objno; /**< Object number for image itself. */ size_t mobjno; /**< Object number for mask (0=unused). */ size_t unxon; /**< Unnamed XObject number. */ dk4_bif_dim_t width; /**< Image width (number of pixels). */ dk4_bif_dim_t height; /**< Image height (number of pixels). */ int dct; /**< Flag: Stored in DCTDecode. */ int ipol; /**< Flag: Interpolation used. */ int cs; /**< Color space. */ int hufi; /**< Flag: Valid UFI. */ int deci; /**< Flag: Decoding inverted. */ dk4_px_bit_depth_t bpc; /**< Number of bits per component. */ } dk4_gra_pdf_img_xo_t; /** PDF page. Page contents is stored in a memory buffer named membuf. The memstrm stream provides a stream API to write to the buffer. Graphics instructions are written to the compressing stream costrm, which flate-compresses the data and writes to memstrm which in turn writes to membuf. */ typedef struct { dk4gra_attributes_t attr; /**< Graphics attributes. */ dk4gra_attributes_t catt; /**< Copy of graphics attributes. */ dk4_membuf_t *membuf; /**< Memory buffer. */ dk4_stream_t *memstrm; /**< Stream writing to mem buffer. */ dk4_stream_t *costrm; /**< Compressed stream. */ dk4_stream_t *outstrm; /**< Output stream to use. */ dk4_sto_t *s_uxo; /**< Used XObjects container. */ dk4_sto_it_t *i_uxo; /**< Used XObjects iterator. */ size_t pageno; /**< Page number. */ size_t objno; /**< Object number. */ int flags; /**< Flags specified when opening. */ } dk4_gra_pdf_page_t; /** PGF image file. */ typedef struct { dk4_ufi_t ufi; /**< Unique file identifier. */ dkChar *fn; /**< File name. */ size_t imgno; /**< Image number, 0 for first image. */ int hufi; /**< Flag: Valid UFI. */ int intp; /**< Flag: Image interpolation. */ } dk4_gra_pgf_img_no_t; /** PGF page. Page contents is written through the memory stream into the memory buffer. When writing the output file we place additional contents before and after the buffered contents (i.e. font definitions and image declarations). */ typedef struct { dk4gra_attributes_t attr; /**< Graphics attributes. */ dk4gra_attributes_t catt; /**< Copy of graphics attributes. */ dk4_membuf_t *membuf; /**< Memory buffer. */ dk4_stream_t *memstrm; /**< Stream writing to mem buffer. */ size_t pageno; /**< Page number. */ int flags; /**< Page flags. */ } dk4_gra_pgf_page_t; /** Store one preamble line. */ typedef struct { char *text; /**< Line text. */ size_t lineno; /**< Line number. */ } dk4_gra_preamble_line_t; #ifdef __cplusplus extern "C" { #endif /* Module dk4grat - Graphics tool functions for all output drivers --------------------------------------------------------------- */ /** Open output structure and initialize base components. Note: s_pages and i_pages are not initialized, the dr component is set to PDF. @param fn Output file name. @param w Image width in bp. @param h Image height in bp. @param docfl Document flag set. @param erp Error report, may be NULL. @return Valid pointer to new output structure on success, NULL on error. Error codes: - DK4_E_MATH_OVERFLOW
on numeric overflow when calculating memory size to allocate, - DK4_E_MEMORY_ALLOCATION_FAILED
if a memory allocation failed. */ dk4_gra_t * dk4gratool_open( const dkChar *fn, size_t w, size_t h, int docfl, dk4_er_t *erp ); /** Close output structure, release memory. @param gptr Output structure to close. */ void dk4gratool_close( dk4_gra_t *gptr ); /** Initialize attributes set. @param pattr Attributes set to initialize. */ void dk4gratool_initialize_attributes( dk4gra_attributes_t *pattr ); /** Reset active attributes after grestore operation. @param pattr Attributes set to reset. */ void dk4gratool_reset_active_attributes( dk4gra_attributes_t *pattr ); /** Set a color. @param pcol Color to set up. @param colsp Color space. @param c1 First component (gray, red or cyan). @param c2 Second component (green or magenta). @param c3 Third component (blue or yellow). @param c4 Fourth component (black). */ void dk4gratool_set_color_requested( dk4gra_col_t *pcol, int colsp, double c1, double c2, double c3, double c4 ); /** Compare two colors. @param p1 First color. @param p2 Second color. @return 1 if the colors differ, 0 otherwise. */ int dk4gratool_colors_differ( dk4gra_col_t *p1, dk4gra_col_t *p2 ); /** Check whether two line styles differ. @param ls_a Active line style. @param ls_r Requested line style. @param sv_a Active style value (dash length in bp). @param sv_r Requested style value. @param lwc Flag: Line width was changed. @return 1 if the line style setup must be written, 0 otherwise. */ int dk4gratool_line_style_differs( int ls_a, int ls_r, double sv_a, double sv_r, int lwc ); /** Calculate coordinates systems transformations. @param dst Destination array consisting of 5 elements: - x translation, - y translation, - rotation counterclockwise in degree, - x scale factor (resulting image width) and - y scale factor (resulting image height). @param xl Left x coordinate. @param xr Right x coordinate. @param yb Bottom y coordinate. @param yt Top y coordinate. @param w Image width in bp. @param h Image height in bp. @param kar Flag: Keep aspect ratio. @param pos Positioning choice. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if coordinates are incorrect or image dimensions are not positive, - DK4_E_MATH_OVERFLOW
if a numeric problem occured in calculations. */ int dk4gratool_calculate_transformations( double *dst, double xl, double xr, double yb, double yt, double w, double h, int kar, int pos, dk4_er_t *erp ); /** Write char string to output stream. @param os Output stream. @param str String to write. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed. */ void dk4gratool_stream_string( dk4_stream_t *os, const char *str, int *backptr, dk4_er_t *erp ); /** Write double value to stream without scientific notation. @param os Output stream. @param val Value to write. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if os is NULL. - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values,
- DK4_E_SYNTAX
if input contains invalid characters. */ void dk4gratool_stream_double( dk4_stream_t *os, double val, int *backptr, dk4_er_t *erp ); /** Write unsigned integer value to stream. @param os Output stream. @param val Value to write. @param padsz Required minimum string size, 0 for no minimum. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if os is NULL, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed. - DK4_E_BUFFER_TOO_SMALL
if the destination buffer size is too small for the result, - DK4_E_BUG
if an internal buffer is too small (should not happen). */ void dk4gratool_stream_uint( dk4_stream_t *os, dk4_um_t val, size_t padsz, int *backptr, dk4_er_t *erp ); /** Retrieve a bit value. @param i Bit index (0 to 11, 0 is least significant bit). @return Bit value. */ dk4_px_t dk4gratool_bit( size_t i ); /** Write a pixel component value to compressed/encoded stream. @param strm Stream to write to. @param bs Bit shifter to use. @param pixval Value to write. @param bpc Number of bits in value. @param backptr Address of success variable to reset on error. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if strm is NULL or not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flusing data downwards failed. */ void dk4gratool_put_pixel_value( dk4_stream_t *strm, dk4_bit_shift_t *bs, dk4_px_t pixval, dk4_px_bit_depth_t bpc, int *backptr, dk4_er_t *erp ); /** Write start of standalone document @param ostrm Output stream. @param gra Graphics output structure. @param pgf Flag: Produce PGF, include pgfcore package. @param dfs Document font size (negative to use default). @param s_f Storage for font setup lines. @param i_f Iterator for font setup lines. @param s_p Storage for package lines. @param i_p Iterator for package lines. @param s_o Storage for other lines. @param i_o Iterator for other lines. @param bptr Address of success variable to reset on error. @param erp Error report, may be NULL. */ void dk4gratool_start_standalone_document( dk4_stream_t *ostrm, dk4_gra_t *gra, int pgf, double dfs, dk4_sto_t *s_f, dk4_sto_it_t *i_f, dk4_sto_t *s_p, dk4_sto_it_t *i_p, dk4_sto_t *s_o, dk4_sto_it_t *i_o, int *bptr, dk4_er_t *erp ); /** Write end of standalone document @param ostrm Output stream. @param bptr Address of success variable to reset on error. @param erp Error report, may be NULL. */ void dk4gratool_end_standalone_document( dk4_stream_t *ostrm, int *bptr, dk4_er_t *erp ); /** Write font number as unique name. @param os Stream to write to. @param val Value to write. @param backptr Address of success variable to reset on error. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed. */ void dk4gratool_stream_num_alpha( dk4_stream_t *os, size_t val, int *backptr, dk4_er_t *erp ); /** Write instruction to change color to stream. @param os Output stream. @param col Color to write. @param backptr Address of success variable to reset on error. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if os is NULL. - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values,
- DK4_E_SYNTAX
if input contains invalid characters. */ void dk4gratool_stream_color( dk4_stream_t *os, dk4gra_col_t const *col, int *backptr, dk4_er_t *erp ); /** Write font definitions from font collector to stream. @param ostrm Output stream. @param fontc Font collector to write. @param bptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing or if input contains invalid characters, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values.
*/ void dk4gratool_font_definitions( dk4_stream_t *ostrm, dk4_font_collector_t *fontc, int *bptr, dk4_er_t *erp ); /** Create preamble line structure for given text line and line number. @param textline Text line to store. @param lineno Line number. @param erp Error report, may be NULL. @return Valid pointer on success, NULL on error. */ dk4_gra_preamble_line_t * dk4gratool_preamble_new( char const *textline, size_t lineno, dk4_er_t *erp ); /** Destroy preamble line structure, release ressources. @param ptr Structure to destroy. */ void dk4gratool_preamble_delete( dk4_gra_preamble_line_t *ptr ); /** Compare two preamble line structures. @param l Left structure. @param r Right structure. @param cr Comparison criteria, ignored. @return Comparison result: 1=l>l, 0=l==r, -1=l if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_gsave( dk4_gra_t *gra, int *backptr, dk4_er_t *erp ); /** Restore graphics state (especially clip path). This function does not check arguments, it is intended for library-internal use from functions having done the checks! @param gra Output structure. @param res Flag: Reset attributes. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_grestore( dk4_gra_t *gra, int res, int *backptr, dk4_er_t *erp ); /** Prepare output structure for a fill operation. This function does not check arguments, it is intended for library-internal use from functions having done the checks! Use this function before you start to construct a path you plan to fill. @param gra Output structure. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_prepare_fill( dk4_gra_t *gra, int *backptr, dk4_er_t *erp ); /** Prepare output structure for a stroke operation. This function does not check arguments, it is intended for library-internal use from functions having done the checks! Use this function before you start to construct a path you plan to stroke. @param gra Output structure. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_prepare_stroke( dk4_gra_t *gra, int *backptr, dk4_er_t *erp ); /** Prepare output structure for a combined fill and stroke operation. This function does not check arguments, it is intended for library-internal use from functions having done the checks! Use this function before you start to construct a path you plan to fill and stroke. @param gra Output structure. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_prepare_fill_and_stroke( dk4_gra_t *gra, int *backptr, dk4_er_t *erp ); /** Fill current path. This function does not check arguments, it is intended for library-internal use from functions having done the checks! Note: Use dk4gra_prepare_fill() before you start to construct a path you plan to fill. @param gra Output structure. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_fill( dk4_gra_t *gra, int *backptr, dk4_er_t *erp ); /** Stroke current path. This function does not check arguments, it is intended for library-internal use from functions having done the checks! Note: Use dk4gra_prepare_stroke() before you start to construct a path you plan to stroke. @param gra Output structure. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_stroke( dk4_gra_t *gra, int *backptr, dk4_er_t *erp ); /** Fill and stroke current path. This function does not check arguments, it is intended for library-internal use from functions having done the checks! Note: Use dk4gra_prepare_fill_and_stroke() before you start to construct a path you plan to fill and stroke. @param gra Output structure. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_fill_and_stroke( dk4_gra_t *gra, int *backptr, dk4_er_t *erp ); /** Use current path for clipping. This function does not check arguments, it is intended for library-internal use from functions having done the checks! @param gra Output structure. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_clip( dk4_gra_t *gra, int *backptr, dk4_er_t *erp ); /** Start a new path and move to first point. No argument checking, for internal use (pattern filling) only. @param gra Output structure. @param x X coordinate of start point. @param y Y coordinate of start point. @param bbptr Bounding box, may be NULL. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_newpath_moveto( dk4_gra_t *gra, double x, double y, int *backptr, dk4_er_t *erp ); /** Add line from current point to new point to path. No argument checking, for internal use (pattern filling) only. @param gra Output structure. @param x X coordinate of new point. @param y Y coordinate of new point. @param bbptr Bounding box, may be NULL. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_lineto( dk4_gra_t *gra, double x, double y, int *backptr, dk4_er_t *erp ); /** Add Bezier curve segment from current point to new point in path. No argument checking, for internal use (pattern filling) only. @param gra Output structure. @param x1c X coordinate of first control point. @param y1c Y coordinate of first control point. @param x2c X coordinate of second control point. @param y2c Y coordinate of second control point. @param x X coordinate of new point. @param y Y coordinate of new point. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_curveto( dk4_gra_t *gra, double xc1, double yc1, double xc2, double yc2, double x, double y, int *backptr, dk4_er_t *erp ); /** Close current path. No argument checking, for internal use (pattern filling) only. @param gra Output structure. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_closepath( dk4_gra_t *gra, int *backptr, dk4_er_t *erp ); /** Create path for a circle. No argument checking, for internal use (pattern filling) only. @param gra Output structure. @param xc Center point x coordinate. @param yc Center point y coordinate. @param r Radius. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_circle( dk4_gra_t *gra, double xc, double yc, double r, int *backptr, dk4_er_t *erp ); /** Create path for rectangle parallel to axes, optionally with rounded corners. No argument checking, for internal use (pattern filling) only. @param gra Output structure. @param xl Left x coordinate. @param xr Right x coordinate. @param yb Bottom y coordinate. @param yt Top y coordinate. @param r Corner radius, maximum is a half of the smaller side length. Use negative values to avoid rounded corners. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_rectangle( dk4_gra_t *gra, double xl, double xr, double yb, double yt, double r, int *backptr, dk4_er_t *erp ); /** Add path for an arc. No argument checking, for internal use (pattern filling) only. @param gra Output structure. @param xc Center point x coordinate. @param yc Center point y coordinate. @param ra Radius. @param start Start angle in degree. @param end End angle in degree. @param cl Flag: Draw closed arc (piece of cake) instead of simple arc. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_arc( dk4_gra_t *gra, double xc, double yc, double ra, double start, double end, int cl, int *backptr, dk4_er_t *erp ); /** Create path for an ellipse. @param gra Output structure. @param xc Center point x coordinate. @param yc Center point y coordinate. @param rx Radius in x direction. @param ry Radius in y direction. @param rot Rotation counterclockwise in radians. @param bbptr Bounding box, may be NULL. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation. */ void dk4gra_i_ellipse( dk4_gra_t *gra, double xc, double yc, double rx, double ry, double rot, dk4_bb_t *bbptr, int *backptr, dk4_er_t *erp ); /** Pattern a region (clipping should be set to the path). @param gra Output structure. @param xl Left y coordinate. @param xr Right x coordinate. @param yb Bottom y coordinate. @param yt Top y coordinate. @param pn Pattern number. @param val Pre-calculated coordinates. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ void dk4gra_i_pattern( dk4_gra_t *gra, double xl, double xr, double yb, double yt, int pn, const double *val, int *backptr, dk4_er_t *erp ); /* Module dk4greps - EPS output module ----------------------------------- */ /** Open output structure to create a PS or EPS file. @param fn File name for output file. @param w Image width in bp. @param h Image height in bp. @param docfl Document flag set. @param erp Error report, may be NULL. @return Valid pointer to new structure on success, NULL on error. Error codes: - DK4_E_MATH_OVERFLOW
on numeric overflow when calculating object sizes in memory, - DK4_E_MEMORY_ALLOCATION_FAILED
with mem.elsize and mem.nelem set if there is not enough memory available. */ dk4_gra_t * dk4gra_eps_open( const dkChar *fn, size_t w, size_t h, int docfl, dk4_er_t *erp ); /** Close output structure without writing an output file. @param gra Output structure. */ void dk4gra_eps_close( dk4_gra_t *gra ); /** Write output file and close output structure. @param fout Output file. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flusing data downwards failed. */ int dk4gra_eps_write_file_and_close( FILE *fout, dk4_gra_t *gra, dk4_er_t *erp ); /** Start new page. @param gra Output structure. @param flags Flags for new page. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL. - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
on numeric overflow when calculating the product of elsize and nelem, - DK4_E_MEMORY_ALLOCATION_FAILED
with mem.elsize and mem.nelem set if there is not enough memory available. */ int dk4gra_eps_page( dk4_gra_t *gra, int flags, dk4_er_t *erp ); /** Save current graphics state (especially clip path). @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL o not in a state allowing this operation, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed - DK4_E_FLUSH_FAILED
if flushing data downwards failed. */ int dk4gra_eps_gsave( dk4_gra_t *gra, dk4_er_t *erp ); /** Restore graphics state (especially clip path). @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed - DK4_E_FLUSH_FAILED
if flushing data downwards failed. */ int dk4gra_eps_grestore( dk4_gra_t *gra, dk4_er_t *erp ); /** Set line width. @param gra Output structure. @param lw Line width in bp. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if gra is NULL or not in a state allowing this operation, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed - DK4_E_FLUSH_FAILED
if flushing data downwards failed. */ int dk4gra_eps_set_line_width( dk4_gra_t *gra, double lw, dk4_er_t *erp ); /** Set line style. @param gra Output structure. @param ls Line style. @param sv Style value (dash length in bp). @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_set_line_style( dk4_gra_t *gra, int ls, double sv, dk4_er_t *erp ); /** Set line cap. @param gra Output structure. @param lc Line cap type. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_set_line_cap( dk4_gra_t *gra, int lc, dk4_er_t *erp ); /** Set line join. @param gra Output structure. @param lj Line join type. @param ml Miter limit. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_set_line_join( dk4_gra_t *gra, int lj, double ml, dk4_er_t *erp ); /** Set fill color to gray. @param gra Output structure. @param g Gray value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_set_fill_gray( dk4_gra_t *gra, double g, dk4_er_t *erp ); /** Set fill color to RGB. @param gra Output structure. @param r Red value in interval 0 to 1. @param g Green value in interval 0 to 1. @param b Blue value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_set_fill_rgb( dk4_gra_t *gra, double r, double g, double b, dk4_er_t *erp ); /** Set fill color to CMYK. @param gra Output structure. @param c Cyan value in interval 0 to 1. @param m Magenta value in interval 0 to 1. @param y Yellow value in interval 0 to 1. @param k Black value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_set_fill_cmyk( dk4_gra_t *gra, double c, double m, double y, double k, dk4_er_t *erp ); /** Set stroke color to gray. @param gra Output structure. @param g Gray value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_set_stroke_gray( dk4_gra_t *gra, double g, dk4_er_t *erp ); /** Set stroke color to RGB. @param gra Output structure. @param r Red value in interval 0 to 1. @param g Green value in interval 0 to 1. @param b Blue value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_set_stroke_rgb( dk4_gra_t *gra, double r, double g, double b, dk4_er_t *erp ); /** Set stroke color to CMYK. @param gra Output structure. @param c Cyan value in interval 0 to 1. @param m Magenta value in interval 0 to 1. @param y Yellow value in interval 0 to 1. @param k Black value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_set_stroke_cmyk( dk4_gra_t *gra, double c, double m, double y, double k, dk4_er_t *erp ); /** Prepare output structure for a fill operation. Use this function before you start to construct a path you plan to fill. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_prepare_fill( dk4_gra_t *gra, dk4_er_t *erp ); /** Prepare output structure for a stroke operation. Use this function before you start to construct a path you plan to stroke. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_prepare_stroke( dk4_gra_t *gra, dk4_er_t *erp ); /** Fill current path. Note: Use dk4gra_eps_prepare_fill() before you start to construct a path you plan to fill. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_fill( dk4_gra_t *gra, dk4_er_t *erp ); /** Stroke current path. Note: Use dk4gra_eps_prepare_stroke() before you start to construct a path you plan to stroke. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_stroke( dk4_gra_t *gra, dk4_er_t *erp ); /** Use current path for clipping. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_clip( dk4_gra_t *gra, dk4_er_t *erp ); /** Pattern a region (clipping should be set to the path). @param gra Output structure. @param pn Pattern number. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_pattern( dk4_gra_t *gra, int pn, double *xval, dk4_er_t *erp ); /** Start a new path and move to first point. @param gra Output structure. @param x X coordinate of start point. @param y Y coordinate of start point. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_newpath_moveto( dk4_gra_t *gra, double x, double y, dk4_er_t *erp ); /** Add line from current point to new point to path. @param gra Output structure. @param x X coordinate of new point. @param y Y coordinate of new point. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_lineto( dk4_gra_t *gra, double x, double y, dk4_er_t *erp ); /** Add Bezier curve segment from current point to new point in path. @param gra Output structure. @param x1c X coordinate of first control point. @param y1c Y coordinate of first control point. @param x2c X coordinate of second control point. @param y2c Y coordinate of second control point. @param x X coordinate of new point. @param y Y coordinate of new point. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_curveto( dk4_gra_t *gra, double xc1, double yc1, double xc2, double yc2, double x, double y, dk4_er_t *erp ); /** Close current path. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_closepath( dk4_gra_t *gra, dk4_er_t *erp ); /** Create path for a circle. @param gra Output structure. @param xc Center point x coordinate. @param yc Center point y coordinate. @param r Radius. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_circle( dk4_gra_t *gra, double xc, double yc, double r, dk4_er_t *erp ); /** Create path for rectangle parallel to axes, optionally with rounded corners. @param gra Output structure. @param xl Left x coordinate. @param xr Right x coordinate. @param yb Bottom y coordinate. @param yt Top y coordinate. @param r Corner radius, maximum is a half of the smaller side length. Use negative values to avoid rounded corners. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_rectangle( dk4_gra_t *gra, double xl, double xr, double yb, double yt, double r, dk4_er_t *erp ); /** Add path for an arc. @param gra Output structure. @param xc Center point x coordinate. @param yc Center point y coordinate. @param ra Radius. @param start Start angle in degree. @param end End angle in degree. @param cl Flag: Draw closed arc (piece of cake) instead of simple arc. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. */ int dk4gra_eps_arc( dk4_gra_t *gra, double xc, double yc, double ra, double start, double end, int cl, dk4_er_t *erp ); /** Add bitmap image. @param gra Output structure. @param cotra Coordinates transformation values. @param bif Bitmap image. @param fn Bitmap image file name. @param fno Frame number. @param ifl Image flags. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_eps_bif_fig_image( dk4_gra_t *gra, double *cotra, dk4_bif_t *bif, const dkChar *fn, int ifl, dk4_er_t *erp ); /** Save current graphics states attributes to internal copy. @param gra Output structure. */ void dk4gra_eps_save_attributes( dk4_gra_t *gra ); /** Restore current graphics states attributes from internal copy. @param gra Output structure. */ void dk4gra_eps_restore_attributes( dk4_gra_t *gra ); /** Reset used attributes. @param gra Output structure. */ void dk4gra_eps_reset_attributes( dk4_gra_t *gra ); /* Module dk4grpgf - PDF output module ----------------------------------- */ /** Open output structure to create a PS or EPS file. @param fn File name for output file. @param w Image width in bp. @param h Image height in bp. @param eps Flag: Produce EPS. @return Valid pointer to new structure on success, NULL on error. */ dk4_gra_t * dk4gra_pdf_open( const dkChar *fn, size_t w, size_t h, int docfl, dk4_er_t *erp ); /** Close output structure without writing an output file. @param gra Output structure. */ void dk4gra_pdf_close( dk4_gra_t *gra ); /** Write output file and close output structure. @param fout Output file. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_write_file_and_close( FILE *fout, dk4_gra_t *gra, dk4_er_t *erp ); /** Start new page. @param gra Output structure. @param flags Flags for new page. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_page( dk4_gra_t *gra, int flags, dk4_er_t *erp ); /** Save current graphics state (especially clip path). @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_gsave( dk4_gra_t *gra, dk4_er_t *erp ); /** Save current graphics state (especially clip path). @param gra Output structure. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. */ void dk4gra_pdf_i_gsave( dk4_gra_t *gra, int *backptr, dk4_er_t *erp ); /** Restore graphics state (especially clip path). @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_grestore( dk4_gra_t *gra, dk4_er_t *erp ); /** Restore graphics state (especially clip path). @param gra Output structure. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. */ void dk4gra_pdf_i_grestore( dk4_gra_t *gra, int *backptr, dk4_er_t *erp ); /** Set line width. @param gra Output structure. @param lw Line width in bp. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_set_line_width( dk4_gra_t *gra, double lw, dk4_er_t *erp ); /** Set line style. @param gra Output structure. @param ls Line style. @param sv Style value (dash length in bp). @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_set_line_style( dk4_gra_t *gra, int ls, double sv, dk4_er_t *erp ); /** Set line cap. @param gra Output structure. @param lc Line cap type. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_set_line_cap( dk4_gra_t *gra, int lc, dk4_er_t *erp ); /** Set line join. @param gra Output structure. @param lj Line join type. @param ml Miter limit. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_set_line_join( dk4_gra_t *gra, int lj, double ml, dk4_er_t *erp ); /** Set fill color to gray. @param gra Output structure. @param g Gray value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_set_fill_gray( dk4_gra_t *gra, double g, dk4_er_t *erp ); /** Set fill color to RGB. @param gra Output structure. @param r Red value in interval 0 to 1. @param g Green value in interval 0 to 1. @param b Blue value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_set_fill_rgb( dk4_gra_t *gra, double r, double g, double b, dk4_er_t *erp ); /** Set fill color to CMYK. @param gra Output structure. @param c Cyan value in interval 0 to 1. @param m Magenta value in interval 0 to 1. @param y Yellow value in interval 0 to 1. @param k Black value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_set_fill_cmyk( dk4_gra_t *gra, double c, double m, double y, double k, dk4_er_t *erp ); /** Set stroke color to gray. @param gra Output structure. @param g Gray value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_set_stroke_gray( dk4_gra_t *gra, double g, dk4_er_t *erp ); /** Set stroke color to RGB. @param gra Output structure. @param r Red value in interval 0 to 1. @param g Green value in interval 0 to 1. @param b Blue value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_set_stroke_rgb( dk4_gra_t *gra, double r, double g, double b, dk4_er_t *erp ); /** Set stroke color to CMYK. @param gra Output structure. @param c Cyan value in interval 0 to 1. @param m Magenta value in interval 0 to 1. @param y Yellow value in interval 0 to 1. @param k Black value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_set_stroke_cmyk( dk4_gra_t *gra, double c, double m, double y, double k, dk4_er_t *erp ); /** Prepare output structure for a fill operation. Use this function before you start to construct a path you plan to fill. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_prepare_fill( dk4_gra_t *gra, dk4_er_t *erp ); /** Prepare output structure for a stroke operation. Use this function before you start to construct a path you plan to stroke. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_prepare_stroke( dk4_gra_t *gra, dk4_er_t *erp ); /** Prepare output structure for a combined fill and stroke operation. Use this function before you start to construct a path you plan to fill and stroke. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_prepare_fill_and_stroke( dk4_gra_t *gra, dk4_er_t *erp ); /** Fill current path. Note: Use dk4gra_pdf_prepare_fill() before you start to construct a path you plan to fill. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_fill( dk4_gra_t *gra, dk4_er_t *erp ); /** Stroke current path. Note: Use dk4gra_pdf_prepare_stroke() before you start to construct a path you plan to stroke. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_stroke( dk4_gra_t *gra, dk4_er_t *erp ); /** Fill and stroke current path. Note: Use dk4gra_pdf_prepare_fill_and_stroke() before you start to construct a path you plan to fill and stroke. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_fill_and_stroke( dk4_gra_t *gra, dk4_er_t *erp ); /** Use current path for clipping. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_clip( dk4_gra_t *gra, dk4_er_t *erp ); /** Start a new path and move to first point. @param gra Output structure. @param x X coordinate of start point. @param y Y coordinate of start point. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_newpath_moveto( dk4_gra_t *gra, double x, double y, dk4_er_t *erp ); /** Add line from current point to new point to path. @param gra Output structure. @param x X coordinate of new point. @param y Y coordinate of new point. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_lineto( dk4_gra_t *gra, double x, double y, dk4_er_t *erp ); /** Add Bezier curve segment from current point to new point in path. @param gra Output structure. @param x1c X coordinate of first control point. @param y1c Y coordinate of first control point. @param x2c X coordinate of second control point. @param y2c Y coordinate of second control point. @param x X coordinate of new point. @param y Y coordinate of new point. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_curveto( dk4_gra_t *gra, double xc1, double yc1, double xc2, double yc2, double x, double y, dk4_er_t *erp ); /** Close current path. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_closepath( dk4_gra_t *gra, dk4_er_t *erp ); /** Create path for rectangle parallel to axes, optionally with rounded corners. @param gra Output structure. @param xl Left x coordinate. @param xr Right x coordinate. @param yb Bottom y coordinate. @param yt Top y coordinate. @param r Corner radius, maximum is a half of the smaller side length. Use negative values to avoid rounded corners. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_rectangle( dk4_gra_t *gra, double xl, double xr, double yb, double yt, double r, dk4_er_t *erp ); /** Add path for an arc. @param gra Output structure. @param xc Center point x coordinate. @param yc Center point y coordinate. @param ra Radius. @param start Start angle in degree. @param end End angle in degree. @param cl Flag: Draw closed arc (piece of cake) instead of simple arc. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. */ int dk4gra_pdf_arc( dk4_gra_t *gra, double xc, double yc, double ra, double start, double end, int cl, dk4_er_t *erp ); /** Add bitmap image. @param gra Output structure. @param cotra Coordinates transformation values. @param bif Bitmap image. @param fn Bitmap image file name. @param fno Frame number. @param ifl Image flags. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pdf_bif_fig_image( dk4_gra_t *gra, double *cotra, dk4_bif_t *bif, const dkChar *fn, size_t fno, int ifl, dk4_er_t *erp ); /** Save current graphics states attributes to internal copy. @param gra Output structure. */ void dk4gra_pdf_save_attributes( dk4_gra_t *gra ); /** Restore current graphics states attributes from internal copy. @param gra Output structure. */ void dk4gra_pdf_restore_attributes( dk4_gra_t *gra ); /** Reset used attributes. @param gra Output structure. */ void dk4gra_pdf_reset_attributes( dk4_gra_t *gra ); /** Write one static keyword to stream. @param os Output stream to write to. @param kwi Index of keyword in dk4_gra_pdf_c8_kw array. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. */ void dk4gra_pdf_i_outstream_kw( dk4_stream_t *os, size_t kwi, int *backptr, dk4_er_t *erp ); /** Write a number of values and one static keyword to stream. @param os Output stream to write to. @param da Values array. @param szda Size of da (number of elements). @param kwi Index of keyword in dk4_gra_pdf_c8_kw array. @param backptr Address of success variable to reset on errors. @param erp Error report, may be NULL. */ void dk4gra_pdf_i_values_and_kw( dk4_stream_t *os, double *da, size_t szda, size_t kwi, int *backptr, dk4_er_t *erp ); /** Compare two used XObject entries by object number. This function is used to build the storage sorted by object numbers. @param l Left object. @param r Right object. @param cr Comparison criteria (ignored). @return Comparison result. */ int dk4gra_pdf_compare_used_xo( const void *l, const void *r, int cr ); /** Destroy XObject structure, release resources. @param puxo XObject structure to destroy. */ void dk4gra_pdf_xo_delete( dk4_gra_pdf_img_xo_t *puxo ); /* Module dk4grpgf - PGF output module ----------------------------------- */ /** Open output structure to create a PS or EPS file. @param fn File name for output file. @param w Image width in bp. @param h Image height in bp. @param sa Flag: Produce standalone TeX file. @param erp Error report, may be NULL. @return Valid pointer to new structure on success, NULL on error. Error codes: - DK4_E_MATH_OVERFLOW
on numeric overflow when calculating memory size to allocate, - DK4_E_MEMORY_ALLOCATION_FAILED
if a memory allocation failed. */ dk4_gra_t * dk4gra_pgf_open( const dkChar *fn, size_t w, size_t h, int docfl, int sa, dk4_er_t *erp ); /** Close output structure without writing an output file. @param gra Output structure. */ void dk4gra_pgf_close( dk4_gra_t *gra ); /** Write output file and close output structure. @param fout Output file. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if any argument is insufficient, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_CLOSE_FAILED
if closing downward data failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values,
- DK4_E_SYNTAX
if input contains invalid characters, - DK4_E_BUFFER_TOO_SMALL
if the destination buffer size is too small for the result, - DK4_E_BUG
if an internal buffer is too small (should not happen). */ int dk4gra_pgf_write_file_and_close( FILE *fout, dk4_gra_t *gra, dk4_er_t *erp ); /** Start new page. @param gra Output structure. @param flags Flags for new page. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_MATH_OVERFLOW
if there are too many pages in the graphics or there is a numeric overflow in allocation size calculation, - DK4_E_MEMORY_ALLOCATION_FAILED
with mem.elsize and mem.nelem set if there is not enough memory available. */ int dk4gra_pgf_page( dk4_gra_t *gra, int flags, dk4_er_t *erp ); /** Save current graphics state (especially clip path). @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed. */ int dk4gra_pgf_gsave( dk4_gra_t *gra, dk4_er_t *erp ); /** Restore graphics state (especially clip path). @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed. */ int dk4gra_pgf_grestore( dk4_gra_t *gra, dk4_er_t *erp ); /** Set line width. @param gra Output structure. @param lw Line width in bp. @param erp Error report, may be NULL. @return 1 on success, 0 on error. - DK4_E_SYNTAX
on internal errors. */ int dk4gra_pgf_set_line_width( dk4_gra_t *gra, double lw, dk4_er_t *erp ); /** Set line style. @param gra Output structure. @param ls Line style. @param sv Style value (dash length in bp). @param erp Error report, may be NULL. @return 1 on success, 0 on error. - DK4_E_SYNTAX
on internal errors. */ int dk4gra_pgf_set_line_style( dk4_gra_t *gra, int ls, double sv, dk4_er_t *erp ); /** Set line cap. @param gra Output structure. @param lc Line cap type. @param erp Error report, may be NULL. @return 1 on success, 0 on error. - DK4_E_SYNTAX
on internal errors. */ int dk4gra_pgf_set_line_cap( dk4_gra_t *gra, int lc, dk4_er_t *erp ); /** Set line join. @param gra Output structure. @param lj Line join type. @param ml Miter limit. @param erp Error report, may be NULL. @return 1 on success, 0 on error. - DK4_E_SYNTAX
on internal errors. - DK4_E_INVALID_ARGUMENTS
if any argument is invalid. */ int dk4gra_pgf_set_line_join( dk4_gra_t *gra, int lj, double ml, dk4_er_t *erp ); /** Set fill color to gray. @param gra Output structure. @param g Gray value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. - DK4_E_SYNTAX
on internal errors. */ int dk4gra_pgf_set_fill_gray( dk4_gra_t *gra, double g, dk4_er_t *erp ); /** Set fill color to RGB. @param gra Output structure. @param r Red value in interval 0 to 1. @param g Green value in interval 0 to 1. @param b Blue value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. - DK4_E_SYNTAX
on internal errors. */ int dk4gra_pgf_set_fill_rgb( dk4_gra_t *gra, double r, double g, double b, dk4_er_t *erp ); /** Set fill color to CMYK. @param gra Output structure. @param c Cyan value in interval 0 to 1. @param m Magenta value in interval 0 to 1. @param y Yellow value in interval 0 to 1. @param k Black value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. - DK4_E_SYNTAX
on internal errors. */ int dk4gra_pgf_set_fill_cmyk( dk4_gra_t *gra, double c, double m, double y, double k, dk4_er_t *erp ); /** Set stroke color to gray. @param gra Output structure. @param g Gray value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. - DK4_E_SYNTAX
on internal errors. */ int dk4gra_pgf_set_stroke_gray( dk4_gra_t *gra, double g, dk4_er_t *erp ); /** Set stroke color to RGB. @param gra Output structure. @param r Red value in interval 0 to 1. @param g Green value in interval 0 to 1. @param b Blue value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. - DK4_E_SYNTAX
on internal errors. */ int dk4gra_pgf_set_stroke_rgb( dk4_gra_t *gra, double r, double g, double b, dk4_er_t *erp ); /** Set stroke color to CMYK. @param gra Output structure. @param c Cyan value in interval 0 to 1. @param m Magenta value in interval 0 to 1. @param y Yellow value in interval 0 to 1. @param k Black value in interval 0 to 1. @param erp Error report, may be NULL. @return 1 on success, 0 on error. - DK4_E_SYNTAX
on internal errors. */ int dk4gra_pgf_set_stroke_cmyk( dk4_gra_t *gra, double c, double m, double y, double k, dk4_er_t *erp ); /** Prepare output structure for a fill operation. Use this function before you start to construct a path you plan to fill. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values. */ int dk4gra_pgf_prepare_fill( dk4_gra_t *gra, dk4_er_t *erp ); /** Prepare output structure for a stroke operation. Use this function before you start to construct a path you plan to stroke. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values. */ int dk4gra_pgf_prepare_stroke( dk4_gra_t *gra, dk4_er_t *erp ); /** Prepare output structure for a combined fill and stroke operation. Use this function before you start to construct a path you plan to fill and stroke. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values. */ int dk4gra_pgf_prepare_fill_and_stroke( dk4_gra_t *gra, dk4_er_t *erp ); /** Fill current path. Note: Use dk4gra_pgf_prepare_fill() before you start to construct a path you plan to fill. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values. */ int dk4gra_pgf_fill( dk4_gra_t *gra, dk4_er_t *erp ); /** Stroke current path. Note: Use dk4gra_pgf_prepare_stroke() before you start to construct a path you plan to stroke. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values. */ int dk4gra_pgf_stroke( dk4_gra_t *gra, dk4_er_t *erp ); /** Fill and stroke current path. Note: Use dk4gra_pgf_prepare_fill_and_stroke() before you start to construct a path you plan to fill and stroke. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values. */ int dk4gra_pgf_fill_and_stroke( dk4_gra_t *gra, dk4_er_t *erp ); /** Use current path for clipping. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values. */ int dk4gra_pgf_clip( dk4_gra_t *gra, dk4_er_t *erp ); /** Start a new path and move to first point. @param gra Output structure. @param x X coordinate of start point. @param y Y coordinate of start point. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values. */ int dk4gra_pgf_newpath_moveto( dk4_gra_t *gra, double x, double y, dk4_er_t *erp ); /** Add line from current point to new point to path. @param gra Output structure. @param x X coordinate of new point. @param y Y coordinate of new point. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values. */ int dk4gra_pgf_lineto( dk4_gra_t *gra, double x, double y, dk4_er_t *erp ); /** Add Bezier curve segment from current point to new point in path. @param gra Output structure. @param x1c X coordinate of first control point. @param y1c Y coordinate of first control point. @param x2c X coordinate of second control point. @param y2c Y coordinate of second control point. @param x X coordinate of new point. @param y Y coordinate of new point. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values. */ int dk4gra_pgf_curveto( dk4_gra_t *gra, double xc1, double yc1, double xc2, double yc2, double x, double y, dk4_er_t *erp ); /** Close current path. @param gra Output structure. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values. */ int dk4gra_pgf_closepath( dk4_gra_t *gra, dk4_er_t *erp ); /** Create path for a circle. @param gra Output structure. @param xc Center point x coordinate. @param yc Center point y coordinate. @param r Radius. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_SYNTAX
on internal errors, - DK4_E_INVALID_ARGUMENTS
if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values. */ int dk4gra_pgf_circle( dk4_gra_t *gra, double xc, double yc, double r, dk4_er_t *erp ); /** Create path for rectangle parallel to axes, optionally with rounded corners. @param gra Output structure. @param xl Left x coordinate. @param xr Right x coordinate. @param yb Bottom y coordinate. @param yt Top y coordinate. @param r Corner radius, maximum is a half of the smaller side length. Use negative values to avoid rounded corners. @param bbptr Bounding box, may be NULL. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
on internal errors, if str is NULL or the stream is not opened for writing, - DK4_E_WRITE_FAILED
if writing one ore multiple bytes to the stream failed, - DK4_E_FLUSH_FAILED
if flushing data downwards failed, - DK4_E_MATH_OVERFLOW
if the exponent is out of range for integer values. */ int dk4gra_pgf_rectangle( dk4_gra_t *gra, double xl, double xr, double yb, double yt, double r, dk4_er_t *erp ); /** Add bitmap image. @param gra Output structure. @param cotra Coordinates transformation values. @param bif Bitmap image. @param fn Bitmap image file name. @param ifl Image flags. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4gra_pgf_bif_fig_image( dk4_gra_t *gra, double *cotra, dk4_bif_t *bif, const dkChar *fn, int ifl, dk4_er_t *erp ); /** Save current graphics states attributes to internal copy. @param gra Output structure. */ void dk4gra_pgf_save_attributes( dk4_gra_t *gra ); /** Restore current graphics states attributes from internal copy. @param gra Output structure. */ void dk4gra_pgf_restore_attributes( dk4_gra_t *gra ); /** Reset used attributes. @param gra Output structure. */ void dk4gra_pgf_reset_attributes( dk4_gra_t *gra ); /** Close image record, release resources. @param imgptr Image record to close. */ void dk4gra_pgf_img_close(dk4_gra_pgf_img_no_t *imgptr); /** Create image record, allocate resources. @param fn File name for image file. @param imgno Image number. @param ii Flag: Use image interpolation. @param erp Error report. @return Valid pointer to new record on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if src is a NULL pointer, - DK4_E_MATH_OVERFLOW
on mathematical overflow in size calculation, - DK4_E_MEMORY_ALLOCATION_FAILED
with mem.elsize and mem.nelem set if no memory is available. */ dk4_gra_pgf_img_no_t * dk4gra_pgf_img_open(const dkChar *fn, size_t imgno, int ii, dk4_er_t *erp); /* Module dk4grepp - EPS patterns ------------------------------ */ /** Obtain pattern procedure name. @param i Index of pattern procedure. @return Valid pointer to name on success, NULL on error. */ const char * dk4gra_eps_pattern_name(size_t i); /** Obtain pattern procedure definition. @param i Index of pattern procedure. @return Valid pointer to array of strings on success, NULL on error. */ const char * const * dk4gra_eps_pattern_procedure(size_t i); /* Module dk4grpdt - Timestamp for PDF ----------------------------------- */ /** Obtain current timestamp, write as text to buffer. @param buf Destination buffer. @param szbuf Size of destination buffer. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if buf is NULL or szbuf is less than 15, - DK4_E_NOT_SUPPORTED
if localtime_r is not present on the system. */ int dk4gra_pdf_timestamp(char *buf, size_t szbuf, dk4_er_t *erp); #ifdef __cplusplus } #endif /* vim: set ai sw=4 ts=4 : */ #endif