1 /* Copyright (C) 1997, 2000 Aladdin Enterprises. All rights reserved. 2 3 This software is provided AS-IS with no warranty, either express or 4 implied. 5 6 This software is distributed under license and may not be copied, 7 modified or distributed except as expressly authorized under the terms 8 of the license contained in the file LICENSE in this distribution. 9 10 For more information about licensing, please refer to 11 http://www.ghostscript.com/licensing/. For information on 12 commercial licensing, go to http://www.artifex.com/licensing/ or 13 contact Artifex Software, Inc., 101 Lucas Valley Road #110, 14 San Rafael, CA 94903, U.S.A., +1(415)492-9861. 15 */ 16 17 /* $Id: gdevpsdf.h,v 1.32 2005/04/04 20:28:27 igor Exp $ */ 18 /* Common output syntax and parameters for PostScript and PDF writers */ 19 20 #ifndef gdevpsdf_INCLUDED 21 # define gdevpsdf_INCLUDED 22 23 /* 24 * This file should really be named gdevpsd.h or gdevpsdx.h, but we're 25 * keeping its current name for backward compatibility. 26 */ 27 28 #include "gdevvec.h" 29 #include "gsparam.h" 30 #include "strimpl.h" 31 #include "sa85x.h" 32 #include "scfx.h" 33 #include "spsdf.h" 34 35 extern const stream_template s_DCTE_template; /* don't want all of sdct.h */ 36 37 /* 38 * NOTE: the default filter for color and gray images should be DCTEncode. 39 * We don't currently set this, because the management of the parameters 40 * for this filter simply doesn't work. 41 */ 42 43 /* ---------------- Distiller parameters ---------------- */ 44 45 /* Parameters for controlling distillation of images. */ 46 typedef struct psdf_image_params_s { 47 gs_c_param_list *ACSDict; /* JPEG */ 48 bool AntiAlias; 49 bool AutoFilter; 50 int Depth; 51 gs_c_param_list *Dict; /* JPEG or CCITTFax */ 52 bool Downsample; 53 float DownsampleThreshold; 54 enum psdf_downsample_type { 55 ds_Average, 56 ds_Bicubic, 57 ds_Subsample 58 } DownsampleType; 59 #define psdf_ds_names\ 60 "Average", "Bicubic", "Subsample" 61 bool Encode; 62 const char *Filter; 63 int Resolution; 64 const stream_template *filter_template; 65 } psdf_image_params; 66 67 #define psdf_image_param_defaults(af, res, dst, f, ft)\ 68 NULL/*ACSDict*/, 0/*false*/, af, -1, NULL/*Dict*/, 1/*true*/,\ 69 dst, ds_Subsample, 1/*true*/, f, res, ft 70 71 /* Declare templates for default image compression filters. */ 72 extern const stream_template s_CFE_template; 73 74 /* Complete distiller parameters. */ 75 typedef struct psdf_distiller_params_s { 76 77 /* General parameters */ 78 79 bool ASCII85EncodePages; 80 enum psdf_auto_rotate_pages { 81 arp_None, 82 arp_All, 83 arp_PageByPage 84 } AutoRotatePages; 85 #define psdf_arp_names\ 86 "None", "All", "PageByPage" 87 enum psdf_binding { 88 binding_Left, 89 binding_Right 90 } Binding; 91 #define psdf_binding_names\ 92 "Left", "Right" 93 bool CompressPages; 94 enum psdf_default_rendering_intent { 95 ri_Default, 96 ri_Perceptual, 97 ri_Saturation, 98 ri_RelativeColorimetric, 99 ri_AbsoluteColorimetric 100 } DefaultRenderingIntent; 101 #define psdf_ri_names\ 102 "Default", "Perceptual", "Saturation", "RelativeColorimetric",\ 103 "AbsoluteColorimetric" 104 bool DetectBlends; 105 bool DoThumbnails; 106 long ImageMemory; 107 bool LockDistillerParams; 108 bool LZWEncodePages; 109 int OPM; 110 bool PreserveOPIComments; 111 bool UseFlateCompression; 112 113 /* Color processing parameters */ 114 115 gs_const_string CalCMYKProfile; 116 gs_const_string CalGrayProfile; 117 gs_const_string CalRGBProfile; 118 gs_const_string sRGBProfile; 119 enum psdf_color_conversion_strategy { 120 ccs_LeaveColorUnchanged, 121 ccs_UseDeviceDependentColor, /* not in Acrobat Distiller 4.0 */ 122 ccs_UseDeviceIndependentColor, 123 ccs_UseDeviceIndependentColorForImages, 124 ccs_sRGB 125 } ColorConversionStrategy; 126 #define psdf_ccs_names\ 127 "LeaveColorUnchanged", "UseDeviceDependentColor",\ 128 "UseDeviceIndependentColor", "UseDeviceIndependentColorForImages",\ 129 "sRGB" 130 bool PreserveHalftoneInfo; 131 bool PreserveOverprintSettings; 132 enum psdf_transfer_function_info { 133 tfi_Preserve, 134 tfi_Apply, 135 tfi_Remove 136 } TransferFunctionInfo; 137 #define psdf_tfi_names\ 138 "Preserve", "Apply", "Remove" 139 enum psdf_ucr_and_bg_info { 140 ucrbg_Preserve, 141 ucrbg_Remove 142 } UCRandBGInfo; 143 #define psdf_ucrbg_names\ 144 "Preserve", "Remove" 145 146 #define psdf_general_param_defaults(ascii)\ 147 ascii, arp_None, binding_Left, 1/*true*/,\ 148 ri_Default, 1 /*true*/, 0 /*false*/,\ 149 500000, 0 /*false*/, 0/*false*/, 1,\ 150 0 /*false*/, 1 /*true*/,\ 151 /* Color processing parameters */\ 152 {0}, {0}, {0}, {0},\ 153 ccs_LeaveColorUnchanged, 0/*false*/, 0/*false*/, tfi_Preserve, ucrbg_Remove 154 155 /* Color sampled image parameters */ 156 157 psdf_image_params ColorImage; 158 bool ConvertCMYKImagesToRGB; 159 bool ConvertImagesToIndexed; 160 161 #define psdf_color_image_param_defaults\ 162 { psdf_image_param_defaults(1/*true*/, 72, 1.5, 0/*"DCTEncode"*/, 0/*&s_DCTE_template*/) },\ 163 0/*false*/, 1/*true*/ 164 165 /* Grayscale sampled image parameters */ 166 167 psdf_image_params GrayImage; 168 169 #define psdf_gray_image_param_defaults\ 170 { psdf_image_param_defaults(1/*true*/, 72, 1.5, 0/*"DCTEncode"*/, 0/*&s_DCTE_template*/) } 171 172 /* Monochrome sampled image parameters */ 173 174 psdf_image_params MonoImage; 175 176 #define psdf_mono_image_param_defaults\ 177 { psdf_image_param_defaults(0/*false*/, 300, 2.0, "CCITTFaxEncode", &s_CFE_template) } 178 179 /* Font embedding parameters */ 180 181 gs_param_string_array AlwaysEmbed; 182 gs_param_string_array NeverEmbed; 183 enum psdf_cannot_embed_font_policy { 184 cefp_OK, 185 cefp_Warning, 186 cefp_Error 187 } CannotEmbedFontPolicy; 188 #define psdf_cefp_names\ 189 "OK", "Warning", "Error" 190 bool EmbedAllFonts; 191 int MaxSubsetPct; 192 bool SubsetFonts; 193 194 #define psdf_font_param_defaults\ 195 {0}, {0}, cefp_Warning, 1/*true*/, 100, 1/*true*/ 196 197 } psdf_distiller_params; 198 199 /* Define PostScript/PDF versions, corresponding roughly to Adobe versions. */ 200 typedef enum { 201 psdf_version_level1 = 1000, /* Red Book Level 1 */ 202 psdf_version_level1_color = 1100, /* Level 1 + colorimage + CMYK color */ 203 psdf_version_level2 = 2000, /* Red Book Level 2 */ 204 psdf_version_level2_with_TT = 2010, /* Adobe release 2010 with Type 42 fonts */ 205 psdf_version_level2_plus = 2017, /* Adobe release 2017 */ 206 psdf_version_ll3 = 3010 /* LanguageLevel 3, release 3010 */ 207 } psdf_version; 208 209 /* Define the extended device structure. */ 210 #define gx_device_psdf_common\ 211 gx_device_vector_common;\ 212 psdf_version version;\ 213 bool binary_ok; /* derived from ASCII85EncodePages */\ 214 bool HaveCFF;\ 215 bool HaveTrueTypes;\ 216 bool HaveCIDSystem;\ 217 psdf_distiller_params params 218 219 typedef struct gx_device_psdf_s { 220 gx_device_psdf_common; 221 } gx_device_psdf; 222 223 #define psdf_initial_values(version, ascii)\ 224 vector_initial_values,\ 225 version,\ 226 !(ascii),\ 227 true,\ 228 true,\ 229 false,\ 230 { psdf_general_param_defaults(ascii),\ 231 psdf_color_image_param_defaults,\ 232 psdf_gray_image_param_defaults,\ 233 psdf_mono_image_param_defaults,\ 234 psdf_font_param_defaults\ 235 } 236 /* st_device_psdf is never instantiated per se, but we still need to */ 237 /* extern its descriptor for the sake of subclasses. */ 238 extern_st(st_device_psdf); 239 #define public_st_device_psdf() /* in gdevpsdu.c */\ 240 BASIC_PTRS(device_psdf_ptrs) {\ 241 GC_OBJ_ELT2(gx_device_psdf, params.ColorImage.ACSDict,\ 242 params.ColorImage.Dict),\ 243 GC_CONST_STRING_ELT(gx_device_psdf, params.CalCMYKProfile),\ 244 GC_CONST_STRING_ELT(gx_device_psdf, params.CalGrayProfile),\ 245 GC_CONST_STRING_ELT(gx_device_psdf, params.CalRGBProfile),\ 246 GC_CONST_STRING_ELT(gx_device_psdf, params.sRGBProfile),\ 247 GC_OBJ_ELT2(gx_device_psdf, params.GrayImage.ACSDict,\ 248 params.GrayImage.Dict),\ 249 GC_OBJ_ELT2(gx_device_psdf, params.MonoImage.ACSDict,\ 250 params.MonoImage.Dict),\ 251 GC_OBJ_ELT2(gx_device_psdf, params.AlwaysEmbed.data,\ 252 params.NeverEmbed.data)\ 253 };\ 254 gs_public_st_basic_super_final(st_device_psdf, gx_device_psdf,\ 255 "gx_device_psdf", device_psdf_ptrs, device_psdf_data,\ 256 &st_device_vector, 0, gx_device_finalize) 257 #define st_device_psdf_max_ptrs (st_device_vector_max_ptrs + 12) 258 259 /* Get/put parameters. */ 260 dev_proc_get_params(gdev_psdf_get_params); 261 dev_proc_put_params(gdev_psdf_put_params); 262 263 /* ---------------- Vector implementation procedures ---------------- */ 264 265 /* Imager state */ 266 int psdf_setlinewidth(gx_device_vector * vdev, floatp width); 267 int psdf_setlinecap(gx_device_vector * vdev, gs_line_cap cap); 268 int psdf_setlinejoin(gx_device_vector * vdev, gs_line_join join); 269 int psdf_setmiterlimit(gx_device_vector * vdev, floatp limit); 270 int psdf_setdash(gx_device_vector * vdev, const float *pattern, 271 uint count, floatp offset); 272 int psdf_setflat(gx_device_vector * vdev, floatp flatness); 273 int psdf_setlogop(gx_device_vector * vdev, gs_logical_operation_t lop, 274 gs_logical_operation_t diff); 275 276 /* Paths */ 277 #define psdf_dopath gdev_vector_dopath 278 int psdf_dorect(gx_device_vector * vdev, fixed x0, fixed y0, fixed x1, 279 fixed y1, gx_path_type_t type); 280 int psdf_beginpath(gx_device_vector * vdev, gx_path_type_t type); 281 int psdf_moveto(gx_device_vector * vdev, floatp x0, floatp y0, 282 floatp x, floatp y, gx_path_type_t type); 283 int psdf_lineto(gx_device_vector * vdev, floatp x0, floatp y0, 284 floatp x, floatp y, gx_path_type_t type); 285 int psdf_curveto(gx_device_vector * vdev, floatp x0, floatp y0, 286 floatp x1, floatp y1, floatp x2, 287 floatp y2, floatp x3, floatp y3, gx_path_type_t type); 288 int psdf_closepath(gx_device_vector * vdev, floatp x0, floatp y0, 289 floatp x_start, floatp y_start, gx_path_type_t type); 290 291 /* ---------------- Binary (image) data procedures ---------------- */ 292 293 /* Define the structure for writing binary data. */ 294 typedef struct psdf_binary_writer_s { 295 gs_memory_t *memory; 296 stream *target; /* underlying stream */ 297 stream *strm; 298 gx_device_psdf *dev; /* may be unused */ 299 /* Due to recently introduced field cos_object_t::input_strm 300 * the binary writer may be simplified significantly. 301 * Keeping the old structure until we have time 302 * for this optimization. 303 */ 304 } psdf_binary_writer; 305 extern_st(st_psdf_binary_writer); 306 #define public_st_psdf_binary_writer() /* in gdevpsdu.c */\ 307 gs_public_st_ptrs3(st_psdf_binary_writer, psdf_binary_writer,\ 308 "psdf_binary_writer", psdf_binary_writer_enum_ptrs,\ 309 psdf_binary_writer_reloc_ptrs, target, strm, dev) 310 #define psdf_binary_writer_max_ptrs 3 311 312 /* Begin writing binary data. */ 313 int psdf_begin_binary(gx_device_psdf * pdev, psdf_binary_writer * pbw); 314 315 /* Add an encoding filter. The client must have allocated the stream state, */ 316 /* if any, using pdev->v_memory. */ 317 int psdf_encode_binary(psdf_binary_writer * pbw, 318 const stream_template * template, stream_state * ss); 319 320 /* Add a 2-D CCITTFax encoding filter. */ 321 /* Set EndOfBlock iff the stream is not ASCII85 encoded. */ 322 int psdf_CFE_binary(psdf_binary_writer * pbw, int w, int h, bool invert); 323 324 /* 325 * Acquire parameters, and optionally set up the filter for, a DCTEncode 326 * filter. This is a separate procedure so it can be used to validate 327 * filter parameters when they are set, rather than waiting until they are 328 * used. pbw = NULL means just set up the stream state. 329 */ 330 int psdf_DCT_filter(gs_param_list *plist /* may be NULL */, 331 stream_state /*stream_DCTE_state*/ *st, 332 int Columns, int Rows, int Colors, 333 psdf_binary_writer *pbw /* may be NULL */); 334 335 /* Decive whether to convert an image to RGB. */ 336 bool psdf_is_converting_image_to_RGB(const gx_device_psdf * pdev, 337 const gs_imager_state * pis, const gs_pixel_image_t * pim); 338 339 /* Set up compression and downsampling filters for an image. */ 340 /* Note that this may modify the image parameters. */ 341 /* If pctm is NULL, downsampling is not used. */ 342 /* pis only provides UCR and BG information for CMYK => RGB conversion. */ 343 int psdf_setup_image_filters(gx_device_psdf *pdev, psdf_binary_writer *pbw, 344 gs_pixel_image_t *pim, const gs_matrix *pctm, 345 const gs_imager_state * pis, bool lossless); 346 347 /* Set up compression filters for a lossless image, with no downsampling, */ 348 /* no color space conversion, and only lossless filters. */ 349 /* Note that this may modify the image parameters. */ 350 int psdf_setup_lossless_filters(gx_device_psdf *pdev, psdf_binary_writer *pbw, 351 gs_pixel_image_t *pim); 352 353 /* Finish writing binary data. */ 354 int psdf_end_binary(psdf_binary_writer * pbw); 355 356 /* Set up image compression chooser. */ 357 int psdf_setup_compression_chooser(psdf_binary_writer *pbw, 358 gx_device_psdf *pdev, 359 int width, int height, int depth, 360 int bits_per_sample); 361 362 /* Set up an "image to mask" filter. */ 363 int psdf_setup_image_to_mask_filter(psdf_binary_writer *pbw, gx_device_psdf *pdev, 364 int width, int height, int depth, int bits_per_sample, uint *MaskColor); 365 366 /* Set up an image colors filter. */ 367 int psdf_setup_image_colors_filter(psdf_binary_writer *pbw, 368 gx_device_psdf *pdev, gs_pixel_image_t * pim, 369 const gs_imager_state *pis, 370 gs_color_space_index output_cspace_index); 371 372 /* ---------------- Symbolic data printing ---------------- */ 373 374 /* Backward compatibility definitions. */ 375 #define psdf_write_string(s, str, size, print_ok)\ 376 s_write_ps_string(s, str, size, print_ok) 377 #define psdf_alloc_position_stream(ps, mem)\ 378 s_alloc_position_stream(ps, mem) 379 #define psdf_alloc_param_printer(pplist, ppp, s, mem)\ 380 s_alloc_param_printer(pplist, ppp, s, mem) 381 #define psdf_free_param_printer(plist)\ 382 s_free_param_printer(plist) 383 384 /* ---------------- Other procedures ---------------- */ 385 386 /* Define the commands for setting the fill or stroke color. */ 387 typedef struct psdf_set_color_commands_s { 388 const char *setgray; 389 const char *setrgbcolor; 390 const char *setcmykcolor; 391 const char *setcolorspace; 392 const char *setcolor; 393 const char *setcolorn; 394 } psdf_set_color_commands_t; 395 /* Define the standard color-setting commands (with PDF names). */ 396 extern const psdf_set_color_commands_t 397 psdf_set_fill_color_commands, psdf_set_stroke_color_commands; 398 399 /* 400 * Adjust a gx_color_index to compensate for the fact that the bit pattern 401 * of gx_color_index isn't representable. 402 */ 403 gx_color_index psdf_adjust_color_index(gx_device_vector *vdev, 404 gx_color_index color); 405 406 /* Set the fill or stroke color. */ 407 int psdf_set_color(gx_device_vector *vdev, const gx_drawing_color *pdc, 408 const psdf_set_color_commands_t *ppscc); 409 /* Round a double value to a specified precision. */ 410 double psdf_round(double v, int precision, int radix); 411 412 /* stubs to disable get_bits, get_bits_rectangle */ 413 dev_proc_get_bits(psdf_get_bits); 414 dev_proc_get_bits_rectangle(psdf_get_bits_rectangle); 415 416 /* intercept and ignore overprint compositor creation */ 417 dev_proc_create_compositor(psdf_create_compositor); 418 419 #endif /* gdevpsdf_INCLUDED */ 420