gdevpsdf.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /* Copyright (C) 1997, 2000 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: gdevpsdf.h,v 1.9 2000/11/02 00:23:56 lpd Exp $ */
  16. /* Common output syntax and parameters for PostScript and PDF writers */
  17. #ifndef gdevpsdf_INCLUDED
  18. # define gdevpsdf_INCLUDED
  19. /*
  20. * This file should really be named gdevpsd.h or gdevpsdx.h, but we're
  21. * keeping its current name for backward compatibility.
  22. */
  23. #include "gdevvec.h"
  24. #include "gsparam.h"
  25. #include "strimpl.h"
  26. #include "sa85x.h"
  27. #include "scfx.h"
  28. #include "spsdf.h"
  29. extern const stream_template s_DCTE_template; /* don't want all of sdct.h */
  30. /*
  31. * NOTE: the default filter for color and gray images should be DCTEncode.
  32. * We don't currently set this, because the management of the parameters
  33. * for this filter simply doesn't work.
  34. */
  35. /* ---------------- Distiller parameters ---------------- */
  36. /* Parameters for controlling distillation of images. */
  37. typedef struct psdf_image_params_s {
  38. gs_c_param_list *ACSDict; /* JPEG */
  39. bool AntiAlias;
  40. bool AutoFilter;
  41. int Depth;
  42. gs_c_param_list *Dict; /* JPEG or CCITTFax */
  43. bool Downsample;
  44. float DownsampleThreshold;
  45. enum psdf_downsample_type {
  46. ds_Average,
  47. ds_Bicubic,
  48. ds_Subsample
  49. } DownsampleType;
  50. #define psdf_ds_names\
  51. "Average", "Bicubic", "Subsample"
  52. bool Encode;
  53. const char *Filter;
  54. int Resolution;
  55. const stream_template *filter_template;
  56. } psdf_image_params;
  57. #define psdf_image_param_defaults(af, res, dst, f, ft)\
  58. NULL/*ACSDict*/, 0/*false*/, af, -1, NULL/*Dict*/, 1/*true*/,\
  59. dst, ds_Subsample, 1/*true*/, f, res, ft
  60. /* Declare templates for default image compression filters. */
  61. extern const stream_template s_CFE_template;
  62. /* Complete distiller parameters. */
  63. typedef struct psdf_distiller_params_s {
  64. /* General parameters */
  65. bool ASCII85EncodePages;
  66. enum psdf_auto_rotate_pages {
  67. arp_None,
  68. arp_All,
  69. arp_PageByPage
  70. } AutoRotatePages;
  71. #define psdf_arp_names\
  72. "None", "All", "PageByPage"
  73. enum psdf_binding {
  74. binding_Left,
  75. binding_Right
  76. } Binding;
  77. #define psdf_binding_names\
  78. "Left", "Right"
  79. bool CompressPages;
  80. enum psdf_default_rendering_intent {
  81. ri_Default,
  82. ri_Perceptual,
  83. ri_Saturation,
  84. ri_RelativeColorimetric,
  85. ri_AbsoluteColorimetric
  86. } DefaultRenderingIntent;
  87. #define psdf_ri_names\
  88. "Default", "Perceptual", "Saturation", "RelativeColorimetric",\
  89. "AbsoluteColorimetric"
  90. bool DetectBlends;
  91. bool DoThumbnails;
  92. long ImageMemory;
  93. bool LockDistillerParams;
  94. bool LZWEncodePages;
  95. int OPM;
  96. bool PreserveOPIComments;
  97. bool UseFlateCompression;
  98. /* Color processing parameters */
  99. gs_const_string CalCMYKProfile;
  100. gs_const_string CalGrayProfile;
  101. gs_const_string CalRGBProfile;
  102. gs_const_string sRGBProfile;
  103. enum psdf_color_conversion_strategy {
  104. ccs_LeaveColorUnchanged,
  105. ccs_UseDeviceDependentColor, /* not in Acrobat Distiller 4.0 */
  106. ccs_UseDeviceIndependentColor,
  107. ccs_UseDeviceIndependentColorForImages,
  108. ccs_sRGB
  109. } ColorConversionStrategy;
  110. #define psdf_ccs_names\
  111. "LeaveColorUnchanged", "UseDeviceDependentColor",\
  112. "UseDeviceIndependentColor", "UseDeviceIndependentColorForImages",\
  113. "sRGB"
  114. bool PreserveHalftoneInfo;
  115. bool PreserveOverprintSettings;
  116. enum psdf_transfer_function_info {
  117. tfi_Preserve,
  118. tfi_Apply,
  119. tfi_Remove
  120. } TransferFunctionInfo;
  121. #define psdf_tfi_names\
  122. "Preserve", "Apply", "Remove"
  123. enum psdf_ucr_and_bg_info {
  124. ucrbg_Preserve,
  125. ucrbg_Remove
  126. } UCRandBGInfo;
  127. #define psdf_ucrbg_names\
  128. "Preserve", "Remove"
  129. #define psdf_general_param_defaults(ascii)\
  130. ascii, arp_None, binding_Left, 1/*true*/,\
  131. ri_Default, 1 /*true*/, 0 /*false*/,\
  132. 500000, 0 /*false*/, 0/*false*/, 1,\
  133. 0 /*false*/, 1 /*true*/,\
  134. /* Color processing parameters */\
  135. {0}, {0}, {0}, {0},\
  136. ccs_LeaveColorUnchanged, 0/*false*/, 0/*false*/, tfi_Preserve, ucrbg_Remove
  137. /* Color sampled image parameters */
  138. psdf_image_params ColorImage;
  139. bool ConvertCMYKImagesToRGB;
  140. bool ConvertImagesToIndexed;
  141. #define psdf_color_image_param_defaults\
  142. { psdf_image_param_defaults(1/*true*/, 72, 1.5, 0/*"DCTEncode"*/, 0/*&s_DCTE_template*/) },\
  143. 0/*false*/, 1/*true*/
  144. /* Grayscale sampled image parameters */
  145. psdf_image_params GrayImage;
  146. #define psdf_gray_image_param_defaults\
  147. { psdf_image_param_defaults(1/*true*/, 72, 1.5, 0/*"DCTEncode"*/, 0/*&s_DCTE_template*/) }
  148. /* Monochrome sampled image parameters */
  149. psdf_image_params MonoImage;
  150. #define psdf_mono_image_param_defaults\
  151. { psdf_image_param_defaults(0/*false*/, 300, 2.0, "CCITTFaxEncode", &s_CFE_template) }
  152. /* Font embedding parameters */
  153. gs_param_string_array AlwaysEmbed;
  154. gs_param_string_array NeverEmbed;
  155. enum psdf_cannot_embed_font_policy {
  156. cefp_OK,
  157. cefp_Warning,
  158. cefp_Error
  159. } CannotEmbedFontPolicy;
  160. #define psdf_cefp_names\
  161. "OK", "Warning", "Error"
  162. bool EmbedAllFonts;
  163. int MaxSubsetPct;
  164. bool SubsetFonts;
  165. #define psdf_font_param_defaults\
  166. {0}, {0}, cefp_Warning, 1/*true*/, 100, 1/*true*/
  167. } psdf_distiller_params;
  168. /* Define PostScript/PDF versions, corresponding roughly to Adobe versions. */
  169. typedef enum {
  170. psdf_version_level1 = 1000, /* Red Book Level 1 */
  171. psdf_version_level1_color = 1100, /* Level 1 + colorimage + CMYK color */
  172. psdf_version_level2 = 2000, /* Red Book Level 2 */
  173. psdf_version_level2_plus = 2017, /* Adobe release 2017 */
  174. psdf_version_ll3 = 3010 /* LanguageLevel 3, release 3010 */
  175. } psdf_version;
  176. /* Define the extended device structure. */
  177. #define gx_device_psdf_common\
  178. gx_device_vector_common;\
  179. psdf_version version;\
  180. bool binary_ok; /* derived from ASCII85EncodePages */\
  181. psdf_distiller_params params
  182. typedef struct gx_device_psdf_s {
  183. gx_device_psdf_common;
  184. } gx_device_psdf;
  185. #define psdf_initial_values(version, ascii)\
  186. vector_initial_values,\
  187. version,\
  188. !(ascii),\
  189. { psdf_general_param_defaults(ascii),\
  190. psdf_color_image_param_defaults,\
  191. psdf_gray_image_param_defaults,\
  192. psdf_mono_image_param_defaults,\
  193. psdf_font_param_defaults\
  194. }
  195. /* st_device_psdf is never instantiated per se, but we still need to */
  196. /* extern its descriptor for the sake of subclasses. */
  197. extern_st(st_device_psdf);
  198. #define public_st_device_psdf() /* in gdevpsdu.c */\
  199. BASIC_PTRS(device_psdf_ptrs) {\
  200. GC_OBJ_ELT2(gx_device_psdf, params.ColorImage.ACSDict,\
  201. params.ColorImage.Dict),\
  202. GC_CONST_STRING_ELT(gx_device_psdf, params.CalCMYKProfile),\
  203. GC_CONST_STRING_ELT(gx_device_psdf, params.CalGrayProfile),\
  204. GC_CONST_STRING_ELT(gx_device_psdf, params.CalRGBProfile),\
  205. GC_CONST_STRING_ELT(gx_device_psdf, params.sRGBProfile),\
  206. GC_OBJ_ELT2(gx_device_psdf, params.GrayImage.ACSDict,\
  207. params.GrayImage.Dict),\
  208. GC_OBJ_ELT2(gx_device_psdf, params.MonoImage.ACSDict,\
  209. params.MonoImage.Dict),\
  210. GC_OBJ_ELT2(gx_device_psdf, params.AlwaysEmbed.data,\
  211. params.NeverEmbed.data)\
  212. };\
  213. gs_public_st_basic_super_final(st_device_psdf, gx_device_psdf,\
  214. "gx_device_psdf", device_psdf_ptrs, device_psdf_data,\
  215. &st_device_vector, 0, gx_device_finalize)
  216. #define st_device_psdf_max_ptrs (st_device_vector_max_ptrs + 12)
  217. /* Get/put parameters. */
  218. dev_proc_get_params(gdev_psdf_get_params);
  219. dev_proc_put_params(gdev_psdf_put_params);
  220. /* ---------------- Vector implementation procedures ---------------- */
  221. /* Imager state */
  222. int psdf_setlinewidth(P2(gx_device_vector * vdev, floatp width));
  223. int psdf_setlinecap(P2(gx_device_vector * vdev, gs_line_cap cap));
  224. int psdf_setlinejoin(P2(gx_device_vector * vdev, gs_line_join join));
  225. int psdf_setmiterlimit(P2(gx_device_vector * vdev, floatp limit));
  226. int psdf_setdash(P4(gx_device_vector * vdev, const float *pattern,
  227. uint count, floatp offset));
  228. int psdf_setflat(P2(gx_device_vector * vdev, floatp flatness));
  229. int psdf_setlogop(P3(gx_device_vector * vdev, gs_logical_operation_t lop,
  230. gs_logical_operation_t diff));
  231. /* Other state */
  232. int psdf_setfillcolor(P2(gx_device_vector * vdev, const gx_drawing_color * pdc));
  233. int psdf_setstrokecolor(P2(gx_device_vector * vdev, const gx_drawing_color * pdc));
  234. /* Paths */
  235. #define psdf_dopath gdev_vector_dopath
  236. int psdf_dorect(P6(gx_device_vector * vdev, fixed x0, fixed y0, fixed x1,
  237. fixed y1, gx_path_type_t type));
  238. int psdf_beginpath(P2(gx_device_vector * vdev, gx_path_type_t type));
  239. int psdf_moveto(P6(gx_device_vector * vdev, floatp x0, floatp y0,
  240. floatp x, floatp y, gx_path_type_t type));
  241. int psdf_lineto(P6(gx_device_vector * vdev, floatp x0, floatp y0,
  242. floatp x, floatp y, gx_path_type_t type));
  243. int psdf_curveto(P10(gx_device_vector * vdev, floatp x0, floatp y0,
  244. floatp x1, floatp y1, floatp x2,
  245. floatp y2, floatp x3, floatp y3, gx_path_type_t type));
  246. int psdf_closepath(P6(gx_device_vector * vdev, floatp x0, floatp y0,
  247. floatp x_start, floatp y_start, gx_path_type_t type));
  248. /* ---------------- Binary (image) data procedures ---------------- */
  249. /* Define the structure for writing binary data. */
  250. typedef struct psdf_binary_writer_s {
  251. gs_memory_t *memory;
  252. stream *A85E; /* optional ASCII85Encode stream */
  253. stream *target; /* underlying stream */
  254. stream *strm; /* may point to A85E.s */
  255. gx_device_psdf *dev; /* may be unused */
  256. } psdf_binary_writer;
  257. extern_st(st_psdf_binary_writer);
  258. #define public_st_psdf_binary_writer() /* in gdevpsdu.c */\
  259. gs_public_st_ptrs4(st_psdf_binary_writer, psdf_binary_writer,\
  260. "psdf_binary_writer", psdf_binary_writer_enum_ptrs,\
  261. psdf_binary_writer_reloc_ptrs, A85E, target, strm, dev)
  262. #define psdf_binary_writer_max_ptrs 4
  263. /* Begin writing binary data. */
  264. int psdf_begin_binary(P2(gx_device_psdf * pdev, psdf_binary_writer * pbw));
  265. /* Add an encoding filter. The client must have allocated the stream state, */
  266. /* if any, using pdev->v_memory. */
  267. int psdf_encode_binary(P3(psdf_binary_writer * pbw,
  268. const stream_template * template, stream_state * ss));
  269. /* Add a 2-D CCITTFax encoding filter. */
  270. /* Set EndOfBlock iff the stream is not ASCII85 encoded. */
  271. int psdf_CFE_binary(P4(psdf_binary_writer * pbw, int w, int h, bool invert));
  272. /*
  273. * Acquire parameters, and optionally set up the filter for, a DCTEncode
  274. * filter. This is a separate procedure so it can be used to validate
  275. * filter parameters when they are set, rather than waiting until they are
  276. * used. pbw = NULL means just set up the stream state.
  277. */
  278. int psdf_DCT_filter(P6(gs_param_list *plist /* may be NULL */,
  279. stream_state /*stream_DCTE_state*/ *st,
  280. int Columns, int Rows, int Colors,
  281. psdf_binary_writer *pbw /* may be NULL */));
  282. /* Set up compression and downsampling filters for an image. */
  283. /* Note that this may modify the image parameters. */
  284. /* If pctm is NULL, downsampling is not used. */
  285. /* pis only provides UCR and BG information for CMYK => RGB conversion. */
  286. int psdf_setup_image_filters(P5(gx_device_psdf *pdev, psdf_binary_writer *pbw,
  287. gs_pixel_image_t *pim, const gs_matrix *pctm,
  288. const gs_imager_state * pis));
  289. /* Set up compression filters for a lossless image, with no downsampling, */
  290. /* no color space conversion, and only lossless filters. */
  291. /* Note that this may modify the image parameters. */
  292. int psdf_setup_lossless_filters(P3(gx_device_psdf *pdev,
  293. psdf_binary_writer *pbw,
  294. gs_pixel_image_t *pim));
  295. /* Finish writing binary data. */
  296. int psdf_end_binary(P1(psdf_binary_writer * pbw));
  297. /* ---------------- Symbolic data printing ---------------- */
  298. /* Backward compatibility definitions. */
  299. #define psdf_write_string(s, str, size, print_ok)\
  300. s_write_ps_string(s, str, size, print_ok)
  301. #define psdf_alloc_position_stream(ps, mem)\
  302. s_alloc_position_stream(ps, mem)
  303. #define psdf_alloc_param_printer(pplist, ppp, s, mem)\
  304. s_alloc_param_printer(pplist, ppp, s, mem)
  305. #define psdf_free_param_printer(plist)\
  306. s_free_param_printer(plist)
  307. /* ---------------- Other procedures ---------------- */
  308. /* Define the commands for setting the fill or stroke color. */
  309. typedef struct psdf_set_color_commands_s {
  310. const char *setgray;
  311. const char *setrgbcolor;
  312. const char *setcmykcolor;
  313. const char *setcolorspace;
  314. const char *setcolor;
  315. const char *setcolorn;
  316. } psdf_set_color_commands_t;
  317. /* Define the standard color-setting commands (with PDF names). */
  318. extern const psdf_set_color_commands_t
  319. psdf_set_fill_color_commands, psdf_set_stroke_color_commands;
  320. /*
  321. * Adjust a gx_color_index to compensate for the fact that the bit pattern
  322. * of gx_color_index isn't representable.
  323. */
  324. gx_color_index psdf_adjust_color_index(P2(gx_device_vector *vdev,
  325. gx_color_index color));
  326. /* Set the fill or stroke color. */
  327. int psdf_set_color(P3(gx_device_vector *vdev, const gx_drawing_color *pdc,
  328. const psdf_set_color_commands_t *ppscc));
  329. #endif /* gdevpsdf_INCLUDED */