%% options copyright owner = Dirk Krause copyright year = 2018-xxxx SPDX-License-Identifier: BSD-3-Clause %% header /** @file dk4graa.h Graphics output (PS/EPS/PDF/PGF), application support. */ #ifndef DK4CONF_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4conf.h" #else #include #endif #endif #ifndef DK4GRA_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4gra.h" #else #include #endif #endif #ifndef DK4APP_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4app.h" #else #include #endif #endif #ifdef __cplusplus extern "C" { #endif /** Open output structure to create a PDF file. @param fn File name for output file, NULL for standard output. @param w Image width in bp. @param h Image height in bp. @param docfl Document flag set. @param app Application structure for diagnostics, may be NULL. @return Valid pointer to new structure on success, NULL on error. */ dk4_gra_t * dk4gra_app_open_pdf( const dkChar *fn, size_t w, size_t h, int docfl, dk4_app_t *app ); /** Open output structure to create a PS or EPS file. @param fn File name for output file, NULL for standard output. @param w Image width in bp. @param h Image height in bp. @param docfl Flag set, or combination of: - DK4_GRA_DOC_FLAG_PS2
to produce PS level 2 instead of level 3, - DK4_GRA_DOC_FLAG_EPS
to produce EPS instead of PS, - DK4_GRA_DOC_FLAG_PS_DSC
to write document structuring comments. @param app Application structure for diagnostics, may be NULL. @return Valid pointer to new structure on success, NULL on error. */ dk4_gra_t * dk4gra_app_open_ps( const dkChar *fn, size_t w, size_t h, int docfl, dk4_app_t *app ); /** Open output structure to create a PGF file. @param fn File name for output file, NULL for standard output. @param w Image width in bp. @param h Image height in bp. @param docfl Document flag set. @param sa Flag: Produce standalone TeX file. @param app Application structure for diagnostics, may be NULL. @return Valid pointer to new structure on success, NULL on error. */ dk4_gra_t * dk4gra_app_open_pgf( const dkChar *fn, size_t w, size_t h, int docfl, int sa, dk4_app_t *app ); /** Write output file and close output structure. @param gra Output structure. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_write_and_close( dk4_gra_t *gra, int *backptr, dk4_app_t *app ); /** Write output file and close output structure. @param fout Output file already opened. @param gra Output structure. @param app Application structure for diagnostics, may be NULL. @param backptr Address of success variable to reset on errors. */ void dk4gra_app_write_file_and_close( FILE *fout, dk4_gra_t *gra, int *backptr, dk4_app_t *app ); /** Set color space conversion context. @param gra Output structure. @param ctx Color space conversion context to copy. @param backptr Application structure for diagnostics, may be NULL. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_set_color_conversion( dk4_gra_t *gra, dk4_cs_conv_ctx_t const *ctx, int *backptr, dk4_app_t *app ); /** Start new page. Default flags are used for the page: - The clip path is set to the image dimensions. - Background is filled white. - For PDF the contents stream is compressed. To start a new page with different setup, use dk4gra_page_with_flags() instead and specify flags. @param gra Output structure. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_page( dk4_gra_t *gra, int *backptr, dk4_app_t *app ); /** Start new page with non-default setup. @param gra Output structure. @param flags Or-combined flags: - DK4_GRA_PAGE_FLAG_NO_CLIP
to avoid setting the clip path at start of page, - DK4_GRA_PAGE_FLAG_NO_BG
to avoid white background filling, - DK4_GRA_PAGE_FLAG_NOT_COMPRESSED
to avoid compression of page content stream in PDF. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_page_with_flags( dk4_gra_t *gra, int flags, int *backptr, dk4_app_t *app ); /** Set flag for simplified gsave/grestore handling. Set this flag, if you use gsave and grestore only when dealing with clip path for pattern filling. @param gra Output structure. @param val New flag value. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_set_gs_for_pattern_only( dk4_gra_t *gra, int val, dk4_app_t *app ); /** Save current graphics state (especially clip path). @param gra Output structure. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_gsave( dk4_gra_t *gra, int *backptr, dk4_app_t *app ); /** Restore graphics state (especially clip path). @param gra Output structure. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_grestore( dk4_gra_t *gra, int *backptr, dk4_app_t *app ); /** Set line width. @param gra Output structure. @param lw Line width in bp. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_set_line_width( dk4_gra_t *gra, double lw, int *backptr, dk4_app_t *app ); /** Set line style. @param gra Output structure. @param ls Line style. @param sv Style value (dash length in bp). @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_set_line_style( dk4_gra_t *gra, dk4_gra_ls_t ls, double sv, int *backptr, dk4_app_t *app ); /** Set line cap. @param gra Output structure. @param lc Line cap type. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_set_line_cap( dk4_gra_t *gra, dk4_gra_lc_t lc, int *backptr, dk4_app_t *app ); /** Set line join. @param gra Output structure. @param lj Line join type. @param ml Miter limit, only used if lj is DK4_GRA_LJ_MITERED. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_set_line_join( dk4_gra_t *gra, dk4_gra_lj_t lj, double ml, int *backptr, dk4_app_t *app ); /** Set fill color to gray. @param gra Output structure. @param g Gray value in interval 0 to 1. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_set_fill_gray( dk4_gra_t *gra, double g, int *backptr, dk4_app_t *app ); /** 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_set_fill_rgb( dk4_gra_t *gra, double r, double g, double b, int *backptr, dk4_app_t *app ); /** 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_set_fill_cmyk( dk4_gra_t *gra, double c, double m, double y, double k, int *backptr, dk4_app_t *app ); /** Set stroke color to gray. @param gra Output structure. @param g Gray value in interval 0 to 1. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_set_stroke_gray( dk4_gra_t *gra, double g, int *backptr, dk4_app_t *app ); /** 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_set_stroke_rgb( dk4_gra_t *gra, double r, double g, double b, int *backptr, dk4_app_t *app ); /** 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_set_stroke_cmyk( dk4_gra_t *gra, double c, double m, double y, double k, int *backptr, dk4_app_t *app ); /** 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_prepare_fill( dk4_gra_t *gra, int *backptr, dk4_app_t *app ); /** 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_prepare_stroke( dk4_gra_t *gra, int *backptr, dk4_app_t *app ); /** 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_prepare_fill_and_stroke( dk4_gra_t *gra, int *backptr, dk4_app_t *app ); /** Fill current path. Note: Use dk4gra_prepare_fill() before you start to construct a path you plan to fill. The value of the even-odd-rule flag is used to choose either even-odd-rule or nonzero-winding-rule, the dk4gra_set_eorule() function can be used to set the flag. @param gra Output structure. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_fill( dk4_gra_t *gra, int *backptr, dk4_app_t *app ); /** Stroke current path. Note: Use dk4gra_app_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 app Application structure for diagnostics, may be NULL. */ void dk4gra_app_stroke( dk4_gra_t *gra, int *backptr, dk4_app_t *app ); /** Fill and stroke current path. Note: Use dk4gra_app_prepare_fill_and_stroke() before you start to construct a path you plan to fill and stroke. The value of the even-odd-rule flag is used to choose either even-odd-rule or nonzero-winding-rule, the dk4gra_app_set_eorule() function can be used to set the flag. @param gra Output structure. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_fill_and_stroke( dk4_gra_t *gra, int *backptr, dk4_app_t *app ); /** Use current path for clipping. The value of the even-odd-rule flag is used to choose either even-odd-rule or nonzero-winding-rule, the dk4gra_app_set_eorule() function can be used to set the flag. @param gra Output structure. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_clip( dk4_gra_t *gra, int *backptr, dk4_app_t *app ); /** 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_pattern( dk4_gra_t *gra, double xl, double xr, double yb, double yt, dk4_gra_pattern_t pn, int *backptr, dk4_app_t *app ); /** 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_newpath_moveto( dk4_gra_t *gra, double x, double y, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ); /** 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_lineto( dk4_gra_t *gra, double x, double y, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ); /** Add Bezier curve segment from current point to new point in path. @param gra Output structure. @param xc1 X coordinate of first control point. @param yc1 Y coordinate of first control point. @param xc2 X coordinate of second control point. @param yc2 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_curveto( dk4_gra_t *gra, double xc1, double yc1, double xc2, double yc2, double x, double y, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ); /** Close current path. @param gra Output structure. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_closepath( dk4_gra_t *gra, int *backptr, dk4_app_t *app ); /** 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_circle( dk4_gra_t *gra, double xc, double yc, double r, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ); /** 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_rectangle( dk4_gra_t *gra, double xl, double xr, double yb, double yt, double r, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ); /** 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 backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_arc( dk4_gra_t *gra, double xc, double yc, double ra, double start, double end, int cl, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ); /** 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 degree. @param bbptr Bounding box, may be NULL. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_ellipse( dk4_gra_t *gra, double xc, double yc, double rx, double ry, double rot, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ); /** Add simple (non-special) text to PGF graphics. The text is shown in the current fill color (non-stroking color) unless colspec is used to specify a color. @param gra Output structure, must be initialized for PGF. @param x X coordinate. @param y Y coordinate. @param rot Rotation counterclockwise in degree. @param txt Text to show. @param colspec Color specification, may be NULL to use fill color. @param ie Text encoding, only used for char text. @param ha Horizontal alignment. @param va Vertical alignment. @param fno Font number. @param fsz Font size in pt. @param fex Flag: Use exact font (1) or similar font (0). @param uc2l UC to LaTeX conversion structure. @param flags Text flags DK4_GRA_TEXT_FLAG_xxx, can be or-combined. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_pgf_simple_text( dk4_gra_t *gra, double x, double y, double rot, const dkChar *txt, const char *colspec, int ie, dk4_text_align_h_t ha, dk4_text_align_v_t va, int fno, double fsz, dk4_gra_tf_t fex, dk4_uc2l_t *uc2l, int flags, int *backptr, dk4_app_t *app ); /** Add special text to PGF graphics. The text is shown in the current fill color (non-stroking color) unless colspec is used to specify a color. @param gra Output structure, must be initialized for PGF. @param x X coordinate. @param y Y coordinate. @param rot Rotation counterclockwise in degree. @param txt Text to show. @param colspec Color specification, may be NULL. @param ha Horizontal alignment. @param va Vertical alignment. @param fno Font number. @param fsz Font size in pt. @param fex Flag: Use exact font. @param flags Text flags DK4_GRA_TEXT_FLAG_xxx, can be or-combined. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_pgf_special_text( dk4_gra_t *gra, double x, double y, double rot, const char *txt, const char *colspec, dk4_text_align_h_t ha, dk4_text_align_v_t va, int fno, double fsz, dk4_gra_tf_t fex, int flags, int *backptr, dk4_app_t *app ); /** Add bitmap image with coordinate transformations already calculated. @param gra Output structure. @param cotra Array containing coordinate transformations. @param bif Bitmap image file. @param fn Image file name. @param fno Frame number. The frame number given here is used by the PDF output driver only. You must call dk4bif_set_current_frame() on the bitmap image file before calling this function. @param ifl Image flags. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_bif_cotra_image( dk4_gra_t *gra, double *cotra, dk4_bif_t *bif, const dkChar *fn, size_t fno, int ifl, int *backptr, dk4_app_t *app ); /** Add bitmap image XFig style. @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 bif Bitmap image file. @param fn Image file name. @param fno Frame number (0 for first frame). @param pos Image positioning: - 0 not rotated, not flipped, - 1 rotated 90 degree counterclockwise, not flipped, - 2 rotated 180 degree counterclockwise, not flipped, - 3 rotated 270 degree counterclockwise, not flipped, - 4 not rotated, flipped, - 5 rotated 90 degree counterclockwise, flipped, - 6 rotated 180 degree counterclockwise, flipped, - 7 rotated 270 degree counterclockwise, flipped. @param ifl Image flags. @param bbptr Bounding box, may be NULL. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_bif_fig_image( dk4_gra_t *gra, double xl, double xr, double yb, double yt, dk4_bif_t *bif, const dkChar *fn, size_t fno, int pos, int ifl, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ); /** Add bitmap image. @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 bif Bitmap image file data. @param fn Image file name. @param fno Frame number (0 for first frame). @param ifl Image flags. @param bbptr Bounding box, may be NULL. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_bif_image( dk4_gra_t *gra, double xl, double xr, double yb, double yt, dk4_bif_t *bif, const dkChar *fn, size_t fno, int ifl, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ); /** Add bitmap image. @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 fn Image file name. @param fno Frame number (0 for first frame). @param ctx Bitmap image conversion context, may be NULL. @param ifl Image flags. @param bbptr Bounding box, may be NULL. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_image( dk4_gra_t *gra, double xl, double xr, double yb, double yt, const dkChar *fn, size_t fno, dk4_cs_conv_ctx_t *ctx, int ifl, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ); /** Add bitmap image XFig style. @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 fn Image file name. @param fno Frame number (0 for first frame). @param ctx Bitmap image conversion context, may be NULL. @param pos Image positioning: - 0 not rotated, not flipped, - 1 rotated 90 degree counterclockwise, not flipped, - 2 rotated 180 degree counterclockwise, not flipped, - 3 rotated 270 degree counterclockwise, not flipped, - 4 not rotated, flipped, - 5 rotated 90 degree counterclockwise, flipped, - 6 rotated 180 degree counterclockwise, flipped, - 7 rotated 270 degree counterclockwise, flipped. @param ifl Image flags. @param bbptr Bounding box, may be NULL. @param backptr Address of success variable to reset on errors. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_fig_image( dk4_gra_t *gra, double xl, double xr, double yb, double yt, const dkChar *fn, size_t fno, dk4_cs_conv_ctx_t *ctx, int pos, int ifl, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ); /** Set the font size for the documentclass line. @param gra Output structure, must be initialized for PGF. @param fs Font size in pt. @param backptr Address of success variable to reset on error. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_pgf_doc_font_size( dk4_gra_t *gra, double fs, int *backptr, dk4_app_t *app ); /** Add a preamble line. For font setup and package setup the lines added by this function replace the default contents. For other setup the lines added by this function are appended after the default contents. @param gra Output structure, must be initialized for PGF. @param line Line text without trailing newline. @param tp Line type: DK4_GRA_PREAMBLE_FONT, DK4_GRA_PREAMBLE_PACKAGE, or DK4_GRA_PREAMBLE_OTHER. @param backptr Address of success variable to reset on error. @param app Application structure for diagnostics, may be NULL. */ void dk4gra_app_pgf_doc_preamble_line( dk4_gra_t *gra, const char *line, int tp, int *backptr, dk4_app_t *app ); #ifdef __cplusplus } #endif /* vim: set ai sw=4 ts=4 : */ %% module #include "dk4conf.h" #if DK4_HAVE_FCNTL_H #ifndef FCNTL_H_INCLUDED #include #define FCNTL_H_INCLUDED 1 #endif #endif #if DK4_HAVE_IO_H #ifndef IO_H_INCLUDED #include #define IO_H_INCLUDED 1 #endif #endif #ifndef DK4GRAA_H_INCLUDED #include "dk4graa.h" #endif #ifndef DK4GRALO_H_INCLUDED #include "dk4gralo.h" #endif #ifndef DK4BIF_H_INCLUDED #include "dk4bif.h" #endif #ifndef DK4BIFAP_H_INCLUDED #include "dk4bifap.h" #endif #ifndef DK4FOPDA_H_INCLUDED #include "dk4fopda.h" #endif #ifndef DK4ISADM_H_INCLUDED #include "dk4isadm.h" #endif #ifndef DK4_UNUSED_H_INCLUDED #include "dk4unused.h" #endif $!trace-include /** Error codes in error counting to avoid repeated error messages. */ enum { /** Failed to add graphics contents. */ E_ADD_CONTENTS = 1 , /** Failed to change graphics setup. */ E_CHANGE_SETUP , /** Failed to write graphics contents to file. */ E_WRITE_FILE , /** Image type not supported for PGF output. */ E_PGF_IMAGE_TYPE , }; /** Show error message. @param app Application structure. @param fn Name of file to print with error message. @param erp Error report, used for details. @param si Index of primary message text in dk4gra_app_kw array. */ static void dk4gra_app_error( dk4_app_t *app, dkChar const *fn, dk4_er_t const *erp, size_t si ) { const dkChar * const *msg = NULL; dkChar const *oldsourcefile = NULL; dk4_um_t oldsourceline = 0UL; size_t szmsg = 0; $? "+ dk4gra_app_error %u", (unsigned)si /* Find localized message texts */ szmsg = dk4gralog_sz_localized_texts(); msg = dk4gralog_localized_texts(app); /* Save source file and line */ oldsourcefile = dk4app_get_log_source_file(app); oldsourceline = dk4app_get_log_source_line(app); /* Set source file and line */ dk4app_set_log_source_file(app, fn); dk4app_set_log_source_line(app, (dk4_um_t)0UL); /* Show error message, provide details if possible */ dk4app_log_1(app, msg, szmsg, DK4_LL_ERROR, si); switch (erp->ec) { case DK4_E_INVALID_ARGUMENTS : { dk4app_log_1(app, msg, szmsg, DK4_LL_ERROR, 1); } break; case DK4_E_MATH_OVERFLOW : { dk4app_log_1(app, msg, szmsg, DK4_LL_ERROR, 2); } break; case DK4_E_MEMORY_ALLOCATION_FAILED : { dk4app_log_base1(app, DK4_LL_ERROR, 90); } break; case DK4_E_WRITE_FAILED : { dk4app_log_1(app, msg, szmsg, DK4_LL_ERROR, 3); } break; case DK4_E_FLUSH_FAILED : { dk4app_log_1(app, msg, szmsg, DK4_LL_ERROR, 4); } break; case DK4_E_CLOSE_FAILED : { dk4app_log_1(app, msg, szmsg, DK4_LL_ERROR, 4); } break; } /* Restore old source file and line */ dk4app_set_log_source_file(app, oldsourcefile); dk4app_set_log_source_line(app, oldsourceline); $? "- dk4gra_app_error" } /** Check whether or not to print current error message. We want to avoid repeating the same message again and again. */ static int dk4gra_app_check_error( dk4_gra_t *gra, int ce, int ec ) { int back = 0; $? "+ dk4gra_app_check_error" if (NULL != gra) { if ((gra->le == ce) && (gra->lec == ec)) { $? ". same error again" if (4 > gra->len) { $? ". repeat once more" back = 1; gra->len += 1; } } else { $? ". other error" back = 1; gra->le = ce; gra->lec = ec; gra->len = 0; } } else { $? ". no gra" back = 1; } $? "- dk4gra_app_check_error %d", back return back; } dk4_gra_t * dk4gra_app_open_pdf( const dkChar *fn, size_t w, size_t h, int docfl, dk4_app_t *app ) { dk4_er_t er; dk4_gra_t *back = NULL; $? "+ dk4gra_app_open_pdf \"%!ds\"", TR_STR(fn) dk4error_init(&er); back = dk4gra_open_pdf(fn, w, h, docfl, &er); if ((NULL == back) && (NULL != app)) { dk4gra_app_error(app, fn, &er, 52); } $? "- dk4gra_app_open_pdf %d", TR_IPTR(back) return back; } dk4_gra_t * dk4gra_app_open_ps( const dkChar *fn, size_t w, size_t h, int docfl, dk4_app_t *app ) { dk4_er_t er; dk4_gra_t *back = NULL; $? "+ dk4gra_app_open_ps \"%!ds\"", TR_STR(fn) dk4error_init(&er); back = dk4gra_open_ps(fn, w, h, docfl, &er); if ((NULL == back) && (NULL != app)) { dk4gra_app_error(app, fn, &er, 52); } $? "- dk4gra_app_open_ps %d", TR_IPTR(back) return back; } dk4_gra_t * dk4gra_app_open_pgf( const dkChar *fn, size_t w, size_t h, int docfl, int sa, dk4_app_t *app ) { dk4_er_t er; dk4_gra_t *back = NULL; $? "+ dk4gra_app_open_pgf \"%!ds\"", TR_STR(fn) dk4error_init(&er); back = dk4gra_open_pgf(fn, w, h, docfl, sa, &er); if ((NULL == back) && (NULL != app)) { dk4gra_app_error(app, fn, &er, 52); } $? "- dk4gra_app_open_pgf %d", TR_IPTR(back) return back; } void dk4gra_app_write_file_and_close( FILE *fout, dk4_gra_t *gra, int *backptr, dk4_app_t * DK4_ARG_UNUSED(app) ) { dk4_er_t er; #if 0 dkChar *fn = NULL; #endif int back = 1; DK4_UNUSED_ARG(app) $? "+ dk4gra_app_write_file_and_close" dk4error_init(&er); dk4gra_write_file_and_close(fout, gra, &back, &er); gra = NULL; if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } #if 0 if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_WRITE_FILE, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 59); } } #endif } $? "- dk4gra_app_write_file_and_close" } void dk4gra_app_write_and_close( dk4_gra_t *gra, int *backptr, dk4_app_t *app ) { dk4_er_t er; FILE *fout = NULL; int tests = DK4_FOPEN_SC_USER; int back = 0; int invala = 0; #if DK4_ON_WINDOWS int oldm = _O_TEXT; #endif $? "+ dk4gra_app_write_and_close" if (NULL != gra) { if ((NULL != gra->s_pages) && (NULL != gra->i_pages)) { if ((0 != gra->pages) && (NULL != gra->curpg)) { if (NULL != gra->fn) { $? ". have file name" if (0 != dk4isadmin()) { tests = DK4_FOPEN_SC_PRIVILEGED; } fout = dk4fopen_app(gra->fn, dkT("wb"), tests, app); if (NULL != fout) { $? ". fout" back = 1; dk4gra_app_write_file_and_close(fout, gra, &back, app); gra = NULL; dk4error_init(&er); if (0 != fclose(fout)) { dk4error_set_simple_error_code( &er, DK4_E_CLOSE_FAILED ); back = 0; #if 0 /* 2019-03-06 Graphics is closed, we can not access components. */ if (NULL != app) { if ( 0 != dk4gra_app_check_error( gra, E_WRITE_FILE, er.ec ) ) { dk4gra_app_error(app, gra->fn, &er, 59); } } #endif } } else { $? "! fout" dk4gra_close(gra); gra = NULL; } } else { $? ". writing to stdout" back = 1; #if DK4_ON_WINDOWS oldm = _setmode(_fileno(stdout), _O_BINARY); #endif dk4gra_app_write_file_and_close(stdout, gra, &back, app); gra = NULL; #if DK4_ON_WINDOWS _setmode(_fileno(stdout), oldm); #endif } } else { /* ERROR: Invalid arguments */ invala = 1; dk4gra_close(gra); gra = NULL; } } else { /* ERROR: Invalid arguments */ invala = 1; dk4gra_close(gra); gra = NULL; } } else { /* ERROR: Invalid arguments */ invala = 1; } if (0 != invala) { /* ERROR: Invalid arguments */ dk4error_init(&er); dk4error_set_simple_error_code(&er, DK4_E_INVALID_ARGUMENTS); if (NULL != app) { #if 0 /* 2019-03-06 Graphics is closed, we can no longer access components. */ if (0 != dk4gra_app_check_error(gra, E_WRITE_FILE, er.ec)) { dk4gra_app_error(app, gra->fn, &er, 59); } #endif } } $? "- dk4gra_app_write_and_close %d", back if ((NULL != backptr) && (0 == back)) { *backptr = 0; } } void dk4gra_app_set_color_conversion( dk4_gra_t *gra, dk4_cs_conv_ctx_t const *ctx, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_set_color_conversion" dk4error_init(&er); dk4gra_set_color_conversion(gra, ctx, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_CHANGE_SETUP, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 58); } } } $? "- dk4gra_app_set_color_conversion" } void dk4gra_app_page( dk4_gra_t *gra, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_page" dk4error_init(&er); dk4gra_page(gra, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_page" } void dk4gra_app_page_with_flags( dk4_gra_t *gra, int flags, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_page_with_flags" dk4error_init(&er); dk4gra_page_with_flags(gra, flags, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_page_with_flags" } void dk4gra_app_set_gs_for_pattern_only( dk4_gra_t *gra, int val, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; $? "+ dk4gra_app_set_gs_for_pattern_only" dk4error_init(&er); dk4gra_set_gs_for_pattern_only(gra, val, &er); if (0 != er.ec) { $? "! failed" if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_CHANGE_SETUP, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 58); } } } $? "- dk4gra_app_set_gs_for_pattern_only" } void dk4gra_app_gsave( dk4_gra_t *gra, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_gsave" dk4error_init(&er); dk4gra_gsave(gra, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_gsave" } void dk4gra_app_grestore( dk4_gra_t *gra, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_grestore" dk4error_init(&er); dk4gra_grestore(gra, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_grestore" } void dk4gra_app_set_line_width( dk4_gra_t *gra, double lw, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_set_line_width" dk4error_init(&er); dk4gra_set_line_width(gra, lw, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_set_line_width" } void dk4gra_app_set_line_style( dk4_gra_t *gra, dk4_gra_ls_t ls, double sv, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_set_line_style" dk4error_init(&er); dk4gra_set_line_style(gra, ls, sv, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_set_line_style" } void dk4gra_app_set_line_cap( dk4_gra_t *gra, dk4_gra_lc_t lc, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_set_line_cap" dk4error_init(&er); dk4gra_set_line_cap(gra, lc, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_set_line_cap" } void dk4gra_app_set_line_join( dk4_gra_t *gra, dk4_gra_lj_t lj, double ml, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_set_line_join" dk4error_init(&er); dk4gra_set_line_join(gra, lj, ml, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_set_line_join" } void dk4gra_app_set_fill_gray( dk4_gra_t *gra, double g, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_set_fill_gray" dk4error_init(&er); dk4gra_set_fill_gray(gra, g, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_set_fill_gray" } void dk4gra_app_set_fill_rgb( dk4_gra_t *gra, double r, double g, double b, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_set_fill_rgb" dk4error_init(&er); dk4gra_set_fill_rgb(gra, r, g, b, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_set_fill_rgb" } void dk4gra_app_set_fill_cmyk( dk4_gra_t *gra, double c, double m, double y, double k, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_set_fill_cmyk" dk4error_init(&er); dk4gra_set_fill_cmyk(gra, c, m, y, k, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_set_fill_cmyk" } void dk4gra_app_set_stroke_gray( dk4_gra_t *gra, double g, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_set_stroke_gray" dk4error_init(&er); dk4gra_set_stroke_gray(gra, g, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_set_stroke_gray" } void dk4gra_app_set_stroke_rgb( dk4_gra_t *gra, double r, double g, double b, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_set_stroke_rgb" dk4error_init(&er); dk4gra_set_stroke_rgb(gra, r, g, b, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_set_stroke_rgb" } void dk4gra_app_set_stroke_cmyk( dk4_gra_t *gra, double c, double m, double y, double k, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_set_stroke_cmyk" dk4error_init(&er); dk4gra_set_stroke_cmyk(gra, c, m, y, k, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_set_stroke_cmyk" } void dk4gra_app_prepare_fill( dk4_gra_t *gra, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_prepare_fill" dk4error_init(&er); dk4gra_prepare_fill(gra, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_prepare_fill" } void dk4gra_app_prepare_stroke( dk4_gra_t *gra, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_prepare_stroke" dk4error_init(&er); dk4gra_prepare_stroke(gra, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_prepare_stroke" } void dk4gra_app_prepare_fill_and_stroke( dk4_gra_t *gra, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_prepare_fill_and_stroke" dk4error_init(&er); dk4gra_prepare_fill_and_stroke(gra, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_prepare_fill_and_stroke" } void dk4gra_app_fill( dk4_gra_t *gra, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_fill" dk4error_init(&er); dk4gra_fill(gra, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_fill" } void dk4gra_app_stroke( dk4_gra_t *gra, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_stroke" dk4error_init(&er); dk4gra_stroke(gra, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_stroke" } void dk4gra_app_fill_and_stroke( dk4_gra_t *gra, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_fill_and_stroke" dk4error_init(&er); dk4gra_fill_and_stroke(gra, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_fill_and_stroke" } void dk4gra_app_clip( dk4_gra_t *gra, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_clip" dk4error_init(&er); dk4gra_clip(gra, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_clip" } void dk4gra_app_pattern( dk4_gra_t *gra, double xl, double xr, double yb, double yt, dk4_gra_pattern_t pn, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_pattern" dk4error_init(&er); dk4gra_pattern(gra, xl, xr, yb, yt, pn, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_pattern" } void dk4gra_app_newpath_moveto( dk4_gra_t *gra, double x, double y, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_newpath_moveto" dk4error_init(&er); dk4gra_newpath_moveto(gra, x, y, bbptr, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_newpath_moveto" } void dk4gra_app_lineto( dk4_gra_t *gra, double x, double y, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_lineto" dk4error_init(&er); dk4gra_lineto(gra, x, y, bbptr, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_lineto" } void dk4gra_app_curveto( dk4_gra_t *gra, double xc1, double yc1, double xc2, double yc2, double x, double y, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_curveto" dk4error_init(&er); dk4gra_curveto(gra, xc1, yc1, xc2, yc2, x, y, bbptr, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_curveto" } void dk4gra_app_closepath( dk4_gra_t *gra, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_curveto" dk4error_init(&er); dk4gra_closepath(gra, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_curveto" } void dk4gra_app_circle( dk4_gra_t *gra, double xc, double yc, double r, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_circle" dk4error_init(&er); dk4gra_circle(gra, xc, yc, r, bbptr, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_circle" } void dk4gra_app_rectangle( dk4_gra_t *gra, double xl, double xr, double yb, double yt, double r, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_rectangle" dk4error_init(&er); dk4gra_rectangle(gra, xl, xr, yb, yt, r, bbptr, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_rectangle" } void dk4gra_app_arc( dk4_gra_t *gra, double xc, double yc, double ra, double start, double end, int cl, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_arc" dk4error_init(&er); dk4gra_arc(gra, xc, yc, ra, start, end, cl, bbptr, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_arc" } void dk4gra_app_ellipse( dk4_gra_t *gra, double xc, double yc, double rx, double ry, double rot, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_ellipse" dk4error_init(&er); dk4gra_ellipse(gra, xc, yc, rx, ry, rot, bbptr, &back, &er); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_ellipse" } void dk4gra_app_pgf_simple_text( dk4_gra_t *gra, double x, double y, double rot, const dkChar *txt, const char *colspec, int ie, dk4_text_align_h_t ha, dk4_text_align_v_t va, int fno, double fsz, dk4_gra_tf_t fex, dk4_uc2l_t *uc2l, int flags, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_pgf_simple_text" dk4error_init(&er); dk4gra_pgf_simple_text( gra, x, y, rot, txt, colspec, ie, ha, va, fno, fsz, fex, uc2l, flags, &back, &er ); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_pgf_simple_text" } void dk4gra_app_pgf_special_text( dk4_gra_t *gra, double x, double y, double rot, const char *txt, const char *colspec, dk4_text_align_h_t ha, dk4_text_align_v_t va, int fno, double fsz, dk4_gra_tf_t fex, int flags, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_pgf_special_text" dk4error_init(&er); dk4gra_pgf_special_text( gra, x, y, rot, txt, colspec, ha, va, fno, fsz, fex, flags, &back, &er ); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_app_pgf_special_text" } /** Check whether the graphics driver supports the image type. @param gra Graphics output structure. @param bif Bitmap image file. @return 1 if image type is supported, 0 otherwise. */ static int dk4gra_app_check_driver_and_image_type( dk4_gra_t const *gra, dk4_bif_t const *bif ) { int back = 0; $? "+ dk4gra_app_check_driver_and_image_type" if ((NULL != gra) && (NULL != bif)) { back = 1; switch (gra->dr) { case DK4_GRA_DRIVER_PGF : { switch (dk4bif_get_image_type(bif)) { case DK4_BIF_TYPE_NETPBM : case DK4_BIF_TYPE_TIFF : { back = 0; } break; } } break; } } $? "- dk4gra_app_check_driver_and_image_type %d", back return back; } void dk4gra_app_bif_cotra_image( dk4_gra_t *gra, double *cotra, dk4_bif_t *bif, const dkChar *fn, size_t fno, int ifl, int *backptr, dk4_app_t *app ) { dk4_er_t er; int back = 1; $? "+ dk4gra_app_bif_cotra_image" dk4error_init(&er); if (0 != dk4gra_app_check_driver_and_image_type(gra, bif)) { dk4gra_bif_cotra_image( gra, cotra, bif, fn, fno, ifl, &back, &er ); if (0 == back) { $? "! failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } } else { $? "! driver / file type check failed" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_PGF_IMAGE_TYPE, 0)) { if (NULL != bif) { fn = bif->filename; } dk4gra_app_error(app, fn, &er, 60); } } } $? "- dk4gra_app_bif_cotra_image" } void dk4gra_app_bif_fig_image( dk4_gra_t *gra, double xl, double xr, double yb, double yt, dk4_bif_t *bif, const dkChar *fn, size_t fno, int pos, int ifl, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ) { dk4_er_t er; int back = 1; $? "+ dk4gra_app_bif_fig_image" dk4error_init(&er); if (0 != dk4gra_app_check_driver_and_image_type(gra, bif)) { dk4gra_bif_fig_image( gra, xl, xr, yb, yt, bif, fn, fno, pos, ifl, bbptr, &back, &er ); if (0 == back) { $? "! failed to apply image" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { $? ". have app" if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { $? ". must report" if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } } else { $? "! driver / image type problem" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { $? ". have app" if (0 != dk4gra_app_check_error(gra, E_PGF_IMAGE_TYPE, 0)) { $? ". must report" if (NULL != bif) { fn = bif->filename; } dk4gra_app_error(app, fn, &er, 60); } } } $? "- dk4gra_app_bif_fig_image" } void dk4gra_app_bif_image( dk4_gra_t *gra, double xl, double xr, double yb, double yt, dk4_bif_t *bif, const dkChar *fn, size_t fno, int ifl, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ) { dk4_er_t er; int back = 1; $? "+ dk4gra_app_bif_image" dk4error_init(&er); if (0 != dk4gra_app_check_driver_and_image_type(gra, bif)) { dk4gra_bif_image( gra, xl, xr, yb, yt, bif, fn, fno, ifl, bbptr, &back, &er ); if (0 == back) { $? "! failed to apply image" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { $? ". have app" if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { $? ". must report" if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 57); } } } } else { $? "! driver / image type problem" if (NULL != backptr) { *backptr = 0; } if (NULL != app) { $? ". have app" if (0 != dk4gra_app_check_error(gra, E_PGF_IMAGE_TYPE, 0)) { $? ". must report" if (NULL != bif) { fn = bif->filename; } dk4gra_app_error(app, fn, &er, 60); } } } $? "- dk4gra_app_bif_image" } void dk4gra_app_image( dk4_gra_t *gra, double xl, double xr, double yb, double yt, const dkChar *fn, size_t fno, dk4_cs_conv_ctx_t *ctx, int ifl, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ) { dk4_er_t er; dk4_bif_t *bifptr = NULL; /* Bitmap image */ int back = 0; /* Function result */ int ho = 0; /* Flag: Read image header only */ $? "+ dk4gra_app_image" $? ". xl = %lg", xl $? ". xr = %lg", xr $? ". yb = %lg", yb $? ". yt = %lg", yt $? ". fn = \"%!ds\"", TR_STR(fn) $? ". fno = %u", (unsigned)fno $? ". ctx = %i", TR_IPTR(ctx) $? ". ipol = %d", (DK4_GRA_IMG_FLAG_INTERPOLATION & ifl) $? ". ignres = %d", (DK4_GRA_IMG_FLAG_IGNORE_RESOLUTION & ifl) $? ". ignar = %d", (DK4_GRA_IMG_FLAG_IGNORE_ASPECT_RATIO & ifl) $? ". arot = %d", (DK4_GRA_IMG_FLAG_ALLOW_ROTATION & ifl) $? ". oiop = %d", (DK4_GRA_IMG_FLAG_ONLY_PAGE_CONTENTS & ifl) $? ". alzw = %d", (DK4_GRA_IMG_FLAG_LZW & ifl) $? ". ajpg = %d", (DK4_GRA_IMG_FLAG_DCT & ifl) $? ". ijpg = %d", (DK4_GRA_IMG_FLAG_DCT_INTERPOLATION & ifl) $? ". acol = %d", (DK4_GRA_IMG_FLAG_COLOR & ifl) $? ". anb = %d", (DK4_GRA_IMG_FLAG_ANALYZE_BPC & ifl) $? ". anc = %d", (DK4_GRA_IMG_FLAG_ANALYZE_COLOR & ifl) $? ". ana = %d", (DK4_GRA_IMG_FLAG_ANALYZE_ALPHA & ifl) $? ". fbgf = %d", (DK4_GRA_IMG_FLAG_FILL_BACKGROUND & ifl) if ((NULL != gra) && (NULL != fn) && (xr > xl) && (yt > yb)) { /* Register coordinates in bounding box */ if (NULL != bbptr) { dk4bb_add_x(bbptr, xl); dk4bb_add_x(bbptr, xr); dk4bb_add_y(bbptr, yb); dk4bb_add_y(bbptr, yt); } /* Set header-only flag for opening BIF */ if (DK4_GRA_DRIVER_PGF == gra->dr) { ho = 1; } if ( (0 != (DK4_GRA_IMG_FLAG_DCT & ifl)) && (DK4_BIF_TYPE_JPEG == dk4bif_type_for_suffix(fn)) ) { if (0 != (DK4_GRA_IMG_FLAG_COLOR & ifl)) { ho = 1; } } /* Open bitmap image file */ bifptr = dk4bif_open_app(fn, ho, ctx, app); if (NULL != bifptr) { back = 1; dk4gra_app_bif_image( gra, xl, xr, yb, yt, bifptr, fn, fno, ifl, bbptr, &back, app ); $? ". image was applied, close now" dk4bif_close(bifptr); } } else { /* ERROR: Invalid arguments */ dk4error_init(&er); dk4error_set_simple_error_code(&er, DK4_E_INVALID_ARGUMENTS); if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { dk4gra_app_error(app, fn, &er, 57); } } } if ((0 == back) && (NULL != backptr)) { *backptr = 0; } $? "- dk4gra_app_image %d", back } void dk4gra_app_fig_image( dk4_gra_t *gra, double xl, double xr, double yb, double yt, const dkChar *fn, size_t fno, dk4_cs_conv_ctx_t *ctx, int pos, int ifl, dk4_bb_t *bbptr, int *backptr, dk4_app_t *app ) { dk4_er_t er; dk4_bif_t *bifptr = NULL; int ho = 0; int back = 0; $? "+ dk4gra_fig_image" $? ". xl = %lg", xl $? ". xr = %lg", xr $? ". yb = %lg", yb $? ". yt = %lg", yt $? ". fn = \"%!ds\"", TR_STR(fn) $? ". fno = %u", (unsigned)fno $? ". ctx = %i", TR_IPTR(ctx) $? ". ipol = %d", (DK4_GRA_IMG_FLAG_INTERPOLATION & ifl) $? ". ignres = %d", (DK4_GRA_IMG_FLAG_IGNORE_RESOLUTION & ifl) $? ". ignar = %d", (DK4_GRA_IMG_FLAG_IGNORE_ASPECT_RATIO & ifl) $? ". pos = %d", pos $? ". oiop = %d", (DK4_GRA_IMG_FLAG_ONLY_PAGE_CONTENTS & ifl) $? ". alzw = %d", (DK4_GRA_IMG_FLAG_LZW & ifl) $? ". ajpg = %d", (DK4_GRA_IMG_FLAG_DCT & ifl) $? ". ijpg = %d", (DK4_GRA_IMG_FLAG_DCT_INTERPOLATION & ifl) $? ". acol = %d", (DK4_GRA_IMG_FLAG_COLOR & ifl) $? ". anb = %d", (DK4_GRA_IMG_FLAG_ANALYZE_BPC & ifl) $? ". anc = %d", (DK4_GRA_IMG_FLAG_ANALYZE_COLOR & ifl) $? ". ana = %d", (DK4_GRA_IMG_FLAG_ANALYZE_ALPHA & ifl) $? ". fbgf = %d", (DK4_GRA_IMG_FLAG_FILL_BACKGROUND & ifl) if ((NULL != gra) && (NULL != fn) && (xr > xl) && (yt > yb)) { if (NULL != bbptr) { dk4bb_add_x(bbptr, xl); dk4bb_add_x(bbptr, xr); dk4bb_add_y(bbptr, yb); dk4bb_add_y(bbptr, yt); } if (DK4_GRA_DRIVER_PGF == gra->dr) { ho = 1; } if ( (0 != (DK4_GRA_IMG_FLAG_DCT & ifl)) && (DK4_BIF_TYPE_JPEG == dk4bif_type_for_suffix(fn)) ) { if (0 != (DK4_GRA_IMG_FLAG_COLOR & ifl)) { ho = 1; } } bifptr = dk4bif_open_app(fn, ho, ctx, app); if (NULL != bifptr) { back = 1; dk4gra_app_bif_fig_image( gra, xl, xr, yb, yt, bifptr, fn, fno, pos, ifl, bbptr, &back, app ); $? ". image was applied, close now" dk4bif_close(bifptr); } } else { /* ERROR: Invalid arguments */ dk4error_init(&er); dk4error_set_simple_error_code(&er, DK4_E_INVALID_ARGUMENTS); if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_ADD_CONTENTS, er.ec)) { dk4gra_app_error(app, fn, &er, 57); } } } $? "- dk4gra_fig_image %d", back if ((NULL != backptr) && (0 == back)) { *backptr = 0; } } void dk4gra_app_pgf_doc_font_size( dk4_gra_t *gra, double fs, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_pgf_doc_font_size %lg", fs dk4error_init(&er); dk4gra_pgf_doc_font_size(gra, fs, &back, &er); if (0 == back) { if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_CHANGE_SETUP, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 58); } } } $? "- dk4gra_app_pgf_doc_font_size" } void dk4gra_app_pgf_doc_preamble_line( dk4_gra_t *gra, const char *line, int tp, int *backptr, dk4_app_t *app ) { dk4_er_t er; dkChar *fn = NULL; int back = 1; $? "+ dk4gra_app_pgf_doc_preamble_line" dk4error_init(&er); dk4gra_pgf_doc_preamble_line(gra, line, tp, &back, &er); if (0 == back) { if (NULL != backptr) { *backptr = 0; } if (NULL != app) { if (0 != dk4gra_app_check_error(gra, E_CHANGE_SETUP, er.ec)) { if (NULL != gra) { fn = gra->fn; } dk4gra_app_error(app, fn, &er, 58); } } } $? "- dk4gra_app_pgf_doc_preamble_line" } /* vim: set ai sw=4 ts=4 : */