%% options copyright owner = Dirk Krause copyright year = 2018-xxxx SPDX-License-Identifier: BSD-3-Clause %% header /** @file dk4grco.h Graphics configuration. */ #ifndef DK4CONF_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4conf.h" #else #include #endif #endif #ifndef DK4PAPER_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4paper.h" #else #include #endif #endif #ifndef DK4CS_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4cs.h" #else #include #endif #endif #ifndef DK4GRA_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4gra.h" #else #include #endif #endif /** Scopes for configuration entries */ enum { /** Base setup like choosing a driver, PS language level. */ DK4_GRA_CONF_SCOPE_SETUP = 0x0001 , /** Setup tasks related to bitmap images. */ DK4_GRA_CONF_SCOPE_IMAGE = 0x0002 , /** Setup tasks related to drawing operations. */ DK4_GRA_CONF_SCOPE_DRAW = 0x0004 , /** Setup tasks related to text typesetting. */ DK4_GRA_CONF_SCOPE_TEXT = 0x0008 , /* ----- Combinations for some programs ----- */ /** The bmpp program only uses base setup and bitmap image setup. */ DK4_GRA_CONF_SCOPE_BMPP = ( DK4_GRA_CONF_SCOPE_SETUP | DK4_GRA_CONF_SCOPE_IMAGE ) , /** The fig2lat program uses all setup features. */ DK4_GRA_CONF_SCOPE_FIG2LAT = ( DK4_GRA_CONF_SCOPE_BMPP | DK4_GRA_CONF_SCOPE_DRAW | DK4_GRA_CONF_SCOPE_TEXT ) }; /** Graphics configuration. */ typedef struct { dk4_paper_size_t media; /**< Paper size to use. */ dk4_cs_conv_ctx_t ctx; /**< Color space conversion context. */ double xres; /**< X resolution. */ double yres; /**< Y resolution. */ double xslp; /**< X-spline length precision. */ double xspp; /**< X-spline parameter precision. */ size_t psi; /**< Paper size index in collection. */ unsigned xsss; /**< X-spline sub segments. */ int driver; /**< Graphics output driver. */ int purpose; /**< Intended output purpose. */ int color; /**< Flag: Colored output. */ int ps_level; /**< PS level, 2 or 3. */ int ps_lzw; /**< Flag: Allow LZW. */ int ps_dsc; /**< Flag: Write DSC comments. */ int img_bg_r; /**< Image background red. */ int img_bg_g; /**< Image background green. */ int img_bg_b; /**< Image background blue. */ int img_bg_f; /**< Flag: Force specified bg. */ int img_dct; /**< Flag: Directly use DCT data. */ int img_int; /**< Flag: Use image interpolation. */ int img_dct_int; /**< Flag: Interpolation for DCT. */ int img_an_bpc; /**< Flag: Analyse bits per sample. */ int img_an_color; /**< Flag: Analyse color usage. */ int img_an_alpha; /**< Flag: Analyse alpha channel use. */ int img_rot; /**< Flag: Allow rotation. */ int img_ign_res; /**< Flag: Ignore resolution chunk. */ int img_ign_asp; /**< Flag: Ignore aspect ratio. */ int use_media; /**< Flag: Fit to paper size. */ int doc_duplex; /**< Flag: Use duplex printing. */ int doc_tumble; /**< Flag: Use duplex and tumble. */ int have_psi; /**< Flag: Have psi number. */ } dk4_gra_conf_t; #ifdef __cplusplus extern "C" { #endif /** Initialize configuration structure. @param conf Configuration structure to initialize. */ void dk4gra_conf_init( dk4_gra_conf_t *conf ); /** Retrieve flags for applying an image from the configuration. @param conf Configuration structure to obtain values from. @return Or-combined set of flags. */ int dk4gra_conf_flags_image( dk4_gra_conf_t const *conf ); /** Retrieve document flags for opening a graphics output structure from the configuration. @param conf Configuration structure to obtain values from. @return Or-combined set of flags. */ int dk4gra_conf_flags_document( dk4_gra_conf_t const *conf ); #ifdef __cplusplus } #endif /* vim: set ai sw=4 ts=4 : */ %% module #include "dk4conf.h" #ifndef DK4GRCO_H_INCLUDED #include "dk4grco.h" #endif #ifndef DK4GRA_H_INCLUDED #include "dk4gra.h" #endif #if DK4_HAVE_ASSERT_H #ifndef ASSERT_H_INCLUDED #include #define ASSERT_H_INCLUDED 1 #endif #endif $!trace-include void dk4gra_conf_init( dk4_gra_conf_t *conf ) { #if DK4_USE_ASSERT assert(NULL != conf); #endif if (NULL != conf) { conf->media.name = NULL; conf->media.w = 595.0; conf->media.h = 842.0; conf->media.i = 56.0; conf->media.o = 28.0; conf->media.b = 14.0; conf->media.t = 14.0; dk4cs_context_init(&(conf->ctx), NULL); conf->xres = -1.0; /* Not specified */ conf->yres = -1.0; /* Not specified */ conf->xslp = 1.0e-3; conf->xspp = 4.0e-3; conf->psi = 0; conf->xsss = 8U; conf->driver = DK4_GRA_DRIVER_PDF; conf->purpose = DK4_GRA_PURPOSE_OBJECT; conf->color = 1; conf->ps_level = 3; conf->ps_lzw = 0; conf->ps_dsc = 0; conf->img_bg_r = 255; conf->img_bg_g = 255; conf->img_bg_b = 255; conf->img_bg_f = 0; conf->img_dct = 1; conf->img_int = 1; conf->img_dct_int = 0; conf->img_an_bpc = 1; conf->img_an_color = 1; conf->img_an_alpha = 1; conf->img_rot = 0; conf->img_ign_res = 0; conf->img_ign_asp = 0; conf->use_media = 0; conf->doc_duplex = 1; conf->doc_tumble = 0; conf->have_psi = 0; } } int dk4gra_conf_flags_document( dk4_gra_conf_t const *conf ) { int back = 0; #if DK4_USE_ASSERT assert(NULL != conf); #endif if (NULL != conf) { if (DK4_GRA_DRIVER_EPS == conf->driver) { back |= DK4_GRA_DOC_FLAG_EPS; } if (0 == conf->color) { back |= DK4_GRA_DOC_FLAG_FORCE_GRAY; } if (2 == conf->ps_level) { back |= DK4_GRA_DOC_FLAG_PS2; } if (0 != conf->ps_dsc) { back |= DK4_GRA_DOC_FLAG_PS_DSC; } if (0 != conf->doc_tumble) { back |= DK4_GRA_DOC_FLAG_TUMBLE; } else { if (0 != conf->doc_duplex) { back |= DK4_GRA_DOC_FLAG_DUPLEX; } } } return back; } int dk4gra_conf_flags_image( dk4_gra_conf_t const *conf ) { int back = 0; #if DK4_USE_ASSERT assert(NULL != conf); #endif if (NULL != conf) { if (0 != conf->color) { back |= DK4_GRA_IMG_FLAG_COLOR; } if (0 != conf->ps_lzw) { back |= DK4_GRA_IMG_FLAG_LZW; } if (0 != conf->img_dct) { back |= DK4_GRA_IMG_FLAG_DCT; } if (0 != conf->img_int) { back |= DK4_GRA_IMG_FLAG_INTERPOLATION; } if (0 != conf->img_dct_int) { back |= DK4_GRA_IMG_FLAG_DCT_INTERPOLATION; } if (0 != conf->img_an_bpc) { back |= DK4_GRA_IMG_FLAG_ANALYZE_BPC; } if (0 != conf->img_an_color) { back |= DK4_GRA_IMG_FLAG_ANALYZE_COLOR; } if (0 != conf->img_an_alpha) { back |= DK4_GRA_IMG_FLAG_ANALYZE_ALPHA; } if (0 != conf->img_rot) { back |= DK4_GRA_IMG_FLAG_ALLOW_ROTATION; } if (0 != conf->img_ign_res) { back |= DK4_GRA_IMG_FLAG_IGNORE_RESOLUTION; } if (0 != conf->img_ign_asp) { back |= DK4_GRA_IMG_FLAG_IGNORE_ASPECT_RATIO; } } return back; } /* vim: set ai sw=4 ts=4 : */