1%% options 2 3 4copyright owner = Dirk Krause 5copyright year = 2018-xxxx 6SPDX-License-Identifier: BSD-3-Clause 7 8 9%% header 10 11/** @file dk4grco.h Graphics configuration. 12*/ 13 14#ifndef DK4CONF_H_INCLUDED 15#if DK4_BUILDING_DKTOOLS4 16#include "dk4conf.h" 17#else 18#include <dktools-4/dk4conf.h> 19#endif 20#endif 21 22#ifndef DK4PAPER_H_INCLUDED 23#if DK4_BUILDING_DKTOOLS4 24#include <libdk4gra/dk4paper.h> 25#else 26#include <dktools-4/dk4paper.h> 27#endif 28#endif 29 30#ifndef DK4CS_H_INCLUDED 31#if DK4_BUILDING_DKTOOLS4 32#include <libdk4bif/dk4cs.h> 33#else 34#include <dktools-4/dk4cs.h> 35#endif 36#endif 37 38#ifndef DK4GRA_H_INCLUDED 39#if DK4_BUILDING_DKTOOLS4 40#include <libdk4gra/dk4gra.h> 41#else 42#include <dktools-4/dk4gra.h> 43#endif 44#endif 45 46/** Scopes for configuration entries 47*/ 48enum { 49 /** Base setup like choosing a driver, 50 PS language level. 51 */ 52 DK4_GRA_CONF_SCOPE_SETUP = 0x0001 , 53 54 /** Setup tasks related to bitmap images. 55 */ 56 DK4_GRA_CONF_SCOPE_IMAGE = 0x0002 , 57 58 /** Setup tasks related to drawing operations. 59 */ 60 DK4_GRA_CONF_SCOPE_DRAW = 0x0004 , 61 62 /** Setup tasks related to text typesetting. 63 */ 64 DK4_GRA_CONF_SCOPE_TEXT = 0x0008 , 65 66 /* ----- Combinations for some programs ----- */ 67 68 /** The bmpp program only uses base 69 setup and bitmap image setup. 70 */ 71 DK4_GRA_CONF_SCOPE_BMPP = ( 72 DK4_GRA_CONF_SCOPE_SETUP 73 | DK4_GRA_CONF_SCOPE_IMAGE 74 ) , 75 76 /** The fig2lat program uses all setup 77 features. 78 */ 79 DK4_GRA_CONF_SCOPE_FIG2LAT = ( 80 DK4_GRA_CONF_SCOPE_BMPP 81 | DK4_GRA_CONF_SCOPE_DRAW 82 | DK4_GRA_CONF_SCOPE_TEXT 83 ) 84 85}; 86 87/** Graphics configuration. 88*/ 89typedef struct { 90 dk4_paper_size_t media; /**< Paper size to use. */ 91 dk4_cs_conv_ctx_t ctx; /**< Color space conversion context. */ 92 double xres; /**< X resolution. */ 93 double yres; /**< Y resolution. */ 94 double xslp; /**< X-spline length precision. */ 95 double xspp; /**< X-spline parameter precision. */ 96 size_t psi; /**< Paper size index in collection. */ 97 unsigned xsss; /**< X-spline sub segments. */ 98 int driver; /**< Graphics output driver. */ 99 int purpose; /**< Intended output purpose. */ 100 int color; /**< Flag: Colored output. */ 101 int ps_level; /**< PS level, 2 or 3. */ 102 int ps_lzw; /**< Flag: Allow LZW. */ 103 int ps_dsc; /**< Flag: Write DSC comments. */ 104 int img_bg_r; /**< Image background red. */ 105 int img_bg_g; /**< Image background green. */ 106 int img_bg_b; /**< Image background blue. */ 107 int img_bg_f; /**< Flag: Force specified bg. */ 108 int img_dct; /**< Flag: Directly use DCT data. */ 109 int img_int; /**< Flag: Use image interpolation. */ 110 int img_dct_int; /**< Flag: Interpolation for DCT. */ 111 int img_an_bpc; /**< Flag: Analyse bits per sample. */ 112 int img_an_color; /**< Flag: Analyse color usage. */ 113 int img_an_alpha; /**< Flag: Analyse alpha channel use. */ 114 int img_rot; /**< Flag: Allow rotation. */ 115 int img_ign_res; /**< Flag: Ignore resolution chunk. */ 116 int img_ign_asp; /**< Flag: Ignore aspect ratio. */ 117 int use_media; /**< Flag: Fit to paper size. */ 118 int doc_duplex; /**< Flag: Use duplex printing. */ 119 int doc_tumble; /**< Flag: Use duplex and tumble. */ 120 int have_psi; /**< Flag: Have psi number. */ 121 int restrict_size; /**< Flag: Restrict image size. */ 122 int img_dct_rs; /**< Flag: DCT data when shrinked. */ 123} dk4_gra_conf_t; 124 125#ifdef __cplusplus 126extern "C" { 127#endif 128 129/** Initialize configuration structure. 130 @param conf Configuration structure to initialize. 131*/ 132void 133dk4gra_conf_init( 134 dk4_gra_conf_t *conf 135); 136 137 138/** Retrieve flags for applying an image from the configuration. 139 @param conf Configuration structure to obtain values from. 140 @return Or-combined set of flags. 141*/ 142int 143dk4gra_conf_flags_image( 144 dk4_gra_conf_t const *conf 145); 146 147 148/** Retrieve document flags for opening a graphics output structure 149 from the configuration. 150 @param conf Configuration structure to obtain values from. 151 @return Or-combined set of flags. 152*/ 153int 154dk4gra_conf_flags_document( 155 dk4_gra_conf_t const *conf 156); 157 158 159/** Retrieve "restrict size" setting. 160 @param conf Configuration structure to obtain values from. 161 @return 1 to restrict size, 0 to not restrict size. 162*/ 163int 164dk4gra_conf_get_restrict_size( 165 dk4_gra_conf_t const *conf 166); 167 168 169#ifdef __cplusplus 170} 171#endif 172 173/* vim: set ai sw=4 ts=4 : */ 174 175 176%% module 177 178#include "dk4conf.h" 179 180#ifndef DK4GRCO_H_INCLUDED 181#include <libdk4gra/dk4grco.h> 182#endif 183 184#ifndef DK4GRA_H_INCLUDED 185#include <libdk4gra/dk4gra.h> 186#endif 187 188#if DK4_HAVE_ASSERT_H 189#ifndef ASSERT_H_INCLUDED 190#include <assert.h> 191#define ASSERT_H_INCLUDED 1 192#endif 193#endif 194 195 196 197$!trace-include 198 199 200 201void 202dk4gra_conf_init( 203 dk4_gra_conf_t *conf 204) 205{ 206#if DK4_USE_ASSERT 207 assert(NULL != conf); 208#endif 209 if (NULL != conf) { 210 conf->media.name = NULL; 211 conf->media.w = 595.0; 212 conf->media.h = 842.0; 213 conf->media.i = 56.0; 214 conf->media.o = 28.0; 215 conf->media.b = 14.0; 216 conf->media.t = 14.0; 217 dk4cs_context_init(&(conf->ctx), NULL); 218 conf->xres = -1.0; /* Not specified */ 219 conf->yres = -1.0; /* Not specified */ 220 conf->xslp = 1.0e-3; 221 conf->xspp = 4.0e-3; 222 conf->psi = 0; 223 conf->xsss = 8U; 224 conf->driver = DK4_GRA_DRIVER_PDF; 225 conf->purpose = DK4_GRA_PURPOSE_OBJECT; 226 conf->color = 1; 227 conf->ps_level = 3; 228 conf->ps_lzw = 0; 229 conf->ps_dsc = 0; 230 conf->img_bg_r = 255; 231 conf->img_bg_g = 255; 232 conf->img_bg_b = 255; 233 conf->img_bg_f = 0; 234 conf->img_dct = 1; 235 conf->img_int = 1; 236 conf->img_dct_int = 0; 237 conf->img_an_bpc = 1; 238 conf->img_an_color = 1; 239 conf->img_an_alpha = 1; 240 conf->img_rot = 0; 241 conf->img_ign_res = 0; 242 conf->img_ign_asp = 0; 243 conf->use_media = 0; 244 conf->doc_duplex = 1; 245 conf->doc_tumble = 0; 246 conf->have_psi = 0; 247 conf->restrict_size = 1; 248 conf->img_dct_rs = 1; 249 } 250} 251 252 253 254int 255dk4gra_conf_flags_document( 256 dk4_gra_conf_t const *conf 257) 258{ 259 int back = 0; 260#if DK4_USE_ASSERT 261 assert(NULL != conf); 262#endif 263 if (NULL != conf) { 264 if (DK4_GRA_DRIVER_EPS == conf->driver) { 265 back |= DK4_GRA_DOC_FLAG_EPS; 266 } 267 if (0 == conf->color) { 268 back |= DK4_GRA_DOC_FLAG_FORCE_GRAY; 269 } 270 if (2 == conf->ps_level) { 271 back |= DK4_GRA_DOC_FLAG_PS2; 272 } 273 if (0 != conf->ps_dsc) { 274 back |= DK4_GRA_DOC_FLAG_PS_DSC; 275 } 276 if (0 != conf->doc_tumble) { 277 back |= DK4_GRA_DOC_FLAG_TUMBLE; 278 } 279 else { 280 if (0 != conf->doc_duplex) { 281 back |= DK4_GRA_DOC_FLAG_DUPLEX; 282 } 283 } 284 } 285 return back; 286} 287 288 289 290int 291dk4gra_conf_flags_image( 292 dk4_gra_conf_t const *conf 293) 294{ 295 int back = 0; 296#if DK4_USE_ASSERT 297 assert(NULL != conf); 298#endif 299 if (NULL != conf) { 300 if (0 != conf->color) { 301 back |= DK4_GRA_IMG_FLAG_COLOR; 302 } 303 if (0 != conf->ps_lzw) { 304 back |= DK4_GRA_IMG_FLAG_LZW; 305 } 306 if (0 != conf->img_dct) { 307 back |= DK4_GRA_IMG_FLAG_DCT; 308 } 309 if (0 != conf->img_int) { 310 back |= DK4_GRA_IMG_FLAG_INTERPOLATION; 311 } 312 if (0 != conf->img_dct_int) { 313 back |= DK4_GRA_IMG_FLAG_DCT_INTERPOLATION; 314 } 315 if (0 != conf->img_an_bpc) { 316 back |= DK4_GRA_IMG_FLAG_ANALYZE_BPC; 317 } 318 if (0 != conf->img_an_color) { 319 back |= DK4_GRA_IMG_FLAG_ANALYZE_COLOR; 320 } 321 if (0 != conf->img_an_alpha) { 322 back |= DK4_GRA_IMG_FLAG_ANALYZE_ALPHA; 323 } 324 if (0 != conf->img_rot) { 325 back |= DK4_GRA_IMG_FLAG_ALLOW_ROTATION; 326 } 327 if (0 != conf->img_ign_res) { 328 back |= DK4_GRA_IMG_FLAG_IGNORE_RESOLUTION; 329 } 330 if (0 != conf->img_ign_asp) { 331 back |= DK4_GRA_IMG_FLAG_IGNORE_ASPECT_RATIO; 332 } 333 if (0 != conf->img_dct_rs) { 334 back |= DK4_GRA_IMG_FLAG_DCT_RS; 335 } 336 } 337 return back; 338} 339 340 341 342int 343dk4gra_conf_get_restrict_size( 344 dk4_gra_conf_t const *conf 345) 346{ 347 int back = 0; 348 if (NULL != conf) { 349 if (0 != conf->restrict_size) { 350 back = 1; 351 } 352 } 353 return back; 354} 355 356 357/* vim: set ai sw=4 ts=4 : */ 358