1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: gdevpdfg.h 8265 2007-10-02 07:31:58Z ken $ */
15
/* Internal graphics interfaces for PDF-writing driver. */
17
#ifndef gdevpdfg_INCLUDED
18
# define gdevpdfg_INCLUDED
20
#include "gscspace.h" /* for gs_separation_name */
22
#ifndef pdf_base_font_DEFINED
23
# define pdf_base_font_DEFINED
24
typedef struct pdf_base_font_s pdf_base_font_t;
27
/* ---------------- Exported by gdevpdfc.c ---------------- */
29
/* Define standard and short color space names. */
31
* Based on Adobe's published PDF documentation, it appears that the
32
* abbreviations for the calibrated color spaces were introduced in
33
* PDF 1.1 (added to Table 7.3) and removed in PDF 1.2 (Table 8.1)!
35
typedef struct pdf_color_space_names_s {
36
const char *DeviceCMYK;
37
const char *DeviceGray;
38
const char *DeviceRGB;
40
} pdf_color_space_names_t;
41
#define PDF_COLOR_SPACE_NAMES\
42
"/DeviceCMYK", "/DeviceGray", "/DeviceRGB", "/Indexed"
43
#define PDF_COLOR_SPACE_NAMES_SHORT\
44
"/CMYK", "/G", "/RGB", "/I"
45
extern const pdf_color_space_names_t
46
pdf_color_space_names,
47
pdf_color_space_names_short;
49
/* Define an abstract color space type. */
50
#ifndef gs_color_space_DEFINED
51
# define gs_color_space_DEFINED
52
typedef struct gs_color_space_s gs_color_space;
56
* Define a ColorSpace resource. We need to retain the range scaling
57
* information (if any).
59
typedef struct pdf_color_space_s pdf_color_space_t;
60
struct pdf_color_space_s {
61
pdf_resource_common(pdf_color_space_t);
62
const gs_range_t *ranges;
66
/* The descriptor is public because it is for a resource type. */
67
#define public_st_pdf_color_space() /* in gdevpdfc.c */\
68
gs_public_st_suffix_add2(st_pdf_color_space, pdf_color_space_t,\
69
"pdf_color_space_t", pdf_color_space_enum_ptrs,\
70
pdf_color_space_reloc_ptrs, st_pdf_resource, ranges, serialized)
73
* Create a local Device{Gray,RGB,CMYK} color space corresponding to the
74
* given number of components.
76
int pdf_cspace_init_Device(gs_memory_t *mem, gs_color_space **ppcs, int num_components);
79
* Create a PDF color space corresponding to a PostScript color space.
80
* For parameterless color spaces, set *pvalue to a (literal) string with
81
* the color space name; for other color spaces, create a cos_array_t if
82
* necessary and set *pvalue to refer to it. In the latter case, if
83
* by_name is true, return a string /Rxxxx rather than a reference to
86
* If ppranges is not NULL, then if the domain of the color space had
87
* to be scaled (to convert a CIEBased space to ICCBased), store a pointer
88
* to the ranges in *ppranges, otherwise set *ppranges to 0.
90
int pdf_color_space(gx_device_pdf *pdev, cos_value_t *pvalue,
91
const gs_range_t **ppranges,
92
const gs_color_space *pcs,
93
const pdf_color_space_names_t *pcsn,
95
int pdf_color_space_named(gx_device_pdf *pdev, cos_value_t *pvalue,
96
const gs_range_t **ppranges,
97
const gs_color_space *pcs,
98
const pdf_color_space_names_t *pcsn,
99
bool by_name, const byte *res_name, int name_length);
101
/* Create colored and uncolored Pattern color spaces. */
102
int pdf_cs_Pattern_colored(gx_device_pdf *pdev, cos_value_t *pvalue);
103
int pdf_cs_Pattern_uncolored(gx_device_pdf *pdev, cos_value_t *pvalue);
104
int pdf_cs_Pattern_uncolored_hl(gx_device_pdf *pdev,
105
const gs_color_space *pcs, cos_value_t *pvalue);
107
/* Set the ProcSets bits corresponding to an image color space. */
108
void pdf_color_space_procsets(gx_device_pdf *pdev,
109
const gs_color_space *pcs);
111
/* ---------------- Exported by gdevpdfg.c ---------------- */
113
/* Copy viewer state from images state. */
114
void pdf_viewer_state_from_imager_state(gx_device_pdf * pdev,
115
const gs_imager_state *pis, const gx_device_color *pdevc);
117
/* Prepare intitial values for viewer's graphics state parameters. */
118
void pdf_prepare_initial_viewer_state(gx_device_pdf * pdev, const gs_imager_state *pis);
120
/* Reset the graphics state parameters to initial values. */
121
void pdf_reset_graphics(gx_device_pdf *pdev);
123
/* Set initial color. */
124
void pdf_set_initial_color(gx_device_pdf * pdev, gx_hl_saved_color *saved_fill_color,
125
gx_hl_saved_color *saved_stroke_color,
126
bool *fill_used_process_color, bool *stroke_used_process_color);
128
/* Set the fill or stroke color. */
129
int pdf_reset_color(gx_device_pdf * pdev, const gs_imager_state * pis,
130
const gx_drawing_color *pdc, gx_hl_saved_color * psc,
131
bool *used_process_color,
132
const psdf_set_color_commands_t *ppscc);
133
/* pdecolor is &pdev->fill_color or &pdev->stroke_color. */
134
int pdf_set_pure_color(gx_device_pdf * pdev, gx_color_index color,
135
gx_hl_saved_color * psc,
136
bool *used_process_color,
137
const psdf_set_color_commands_t *ppscc);
138
int pdf_set_drawing_color(gx_device_pdf * pdev, const gs_imager_state * pis,
139
const gx_drawing_color *pdc,
140
gx_hl_saved_color * psc,
141
bool *used_process_color,
142
const psdf_set_color_commands_t *ppscc);
144
* Bring the graphics state up to date for a drawing operation.
145
* (Text uses either fill or stroke.)
147
int pdf_try_prepare_fill(gx_device_pdf *pdev, const gs_imager_state *pis);
148
int pdf_prepare_drawing(gx_device_pdf *pdev, const gs_imager_state *pis, pdf_resource_t **ppres);
149
int pdf_prepare_fill(gx_device_pdf *pdev, const gs_imager_state *pis);
150
int pdf_prepare_stroke(gx_device_pdf *pdev, const gs_imager_state *pis);
151
int pdf_prepare_image(gx_device_pdf *pdev, const gs_imager_state *pis);
152
int pdf_prepare_imagemask(gx_device_pdf *pdev, const gs_imager_state *pis,
153
const gx_drawing_color *pdcolor);
154
int pdf_save_viewer_state(gx_device_pdf *pdev, stream *s);
155
int pdf_restore_viewer_state(gx_device_pdf *pdev, stream *s);
156
int pdf_end_gstate(gx_device_pdf *pdev, pdf_resource_t *pres);
159
* Convert a string into cos name.
161
int pdf_string_to_cos_name(gx_device_pdf *pdev, const byte *str, uint len,
162
cos_value_t *pvalue);
164
/* ---------------- Exported by gdevpdfi.c ---------------- */
166
typedef struct pdf_pattern_s pdf_pattern_t;
167
struct pdf_pattern_s {
168
pdf_resource_common(pdf_pattern_t);
169
pdf_pattern_t *substitute;
171
/* The descriptor is public because it is for a resource type. */
172
#define private_st_pdf_pattern() /* in gdevpdfc.c */\
173
gs_private_st_suffix_add1(st_pdf_pattern, pdf_pattern_t,\
174
"pdf_pattern_t", pdf_pattern_enum_ptrs,\
175
pdf_pattern_reloc_ptrs, st_pdf_resource, substitute)
177
pdf_resource_t *pdf_substitute_pattern(pdf_resource_t *pres);
179
/* ---------------- Exported by gdevpdfj.c ---------------- */
181
/* ------ Image stream dictionaries ------ */
183
/* Define the long and short versions of the keys in an image dictionary, */
184
/* and other strings for images. */
185
typedef struct pdf_image_names_s {
186
pdf_color_space_names_t color_spaces;
187
pdf_filter_names_t filter_names;
188
const char *BitsPerComponent;
189
const char *ColorSpace;
192
const char *ImageMask;
193
const char *Interpolate;
196
#define PDF_IMAGE_PARAM_NAMES\
197
"/BitsPerComponent", "/ColorSpace", "/Decode",\
198
"/Height", "/ImageMask", "/Interpolate", "/Width"
199
#define PDF_IMAGE_PARAM_NAMES_SHORT\
200
"/BPC", "/CS", "/D", "/H", "/IM", "/I", "/W"
201
extern const pdf_image_names_t pdf_image_names_full, pdf_image_names_short;
203
/* Store the values of image parameters other than filters. */
204
/* pdev is used only for updating procsets. */
205
/* pcsvalue is not used for masks. */
206
int pdf_put_image_values(cos_dict_t *pcd, gx_device_pdf *pdev,
207
const gs_pixel_image_t *pic,
208
const pdf_image_names_t *pin,
209
const cos_value_t *pcsvalue);
211
/* Store filters for an image. */
212
/* Currently this only saves parameters for CCITTFaxDecode. */
213
int pdf_put_image_filters(cos_dict_t *pcd, gx_device_pdf *pdev,
214
const psdf_binary_writer * pbw,
215
const pdf_image_names_t *pin);
217
/* ------ Image writing ------ */
220
* Fill in the image parameters for a device space bitmap.
221
* PDF images are always specified top-to-bottom.
222
* data_h is the actual number of data rows, which may be less than h.
224
void pdf_make_bitmap_matrix(gs_matrix * pmat, int x, int y, int w, int h,
227
/* Put out the gsave and matrix for an image. */
228
void pdf_put_image_matrix(gx_device_pdf * pdev, const gs_matrix * pmat,
231
/* Put out a reference to an image resource. */
232
int pdf_do_image_by_id(gx_device_pdf * pdev, double scale,
233
const gs_matrix * pimat, bool in_contents, gs_id id);
234
int pdf_do_image(gx_device_pdf * pdev, const pdf_resource_t * pres,
235
const gs_matrix * pimat, bool in_contents);
237
#define pdf_image_writer_num_alt_streams 4
239
/* Define the structure for writing an image. */
240
typedef struct pdf_image_writer_s {
241
psdf_binary_writer binary[pdf_image_writer_num_alt_streams];
242
int alt_writer_count; /* no. of active elements in writer[] (1,2,3) */
243
const pdf_image_names_t *pin;
244
pdf_resource_t *pres; /* XObject resource iff not in-line */
245
int height; /* initially specified image height */
247
const char *end_string; /* string to write after EI if in-line */
248
cos_dict_t *named; /* named dictionary from NI */
249
pdf_resource_t *pres_mask; /* PS2WRITE only : XObject resource for mask */
251
extern_st(st_pdf_image_writer); /* public for gdevpdfi.c */
252
#define public_st_pdf_image_writer() /* in gdevpdfj.c */\
253
gs_public_st_composite(st_pdf_image_writer, pdf_image_writer,\
254
"pdf_image_writer", pdf_image_writer_enum_ptrs, pdf_image_writer_reloc_ptrs)
255
#define pdf_image_writer_max_ptrs (psdf_binary_writer_max_ptrs * pdf_image_writer_num_alt_streams + 4)
257
/* Initialize image writer. */
258
void pdf_image_writer_init(pdf_image_writer * piw);
261
* Begin writing an image, creating the resource if not in-line, and setting
262
* up the binary writer. If pnamed != 0, it is a dictionary object created
265
int pdf_begin_write_image(gx_device_pdf * pdev, pdf_image_writer * piw,
266
gx_bitmap_id id, int w, int h,
267
cos_dict_t *pnamed, bool in_line);
269
/* Begin writing the image data, setting up the dictionary and filters. */
270
int pdf_begin_image_data(gx_device_pdf * pdev, pdf_image_writer * piw,
271
const gs_pixel_image_t * pim,
272
const cos_value_t *pcsvalue,
273
int alt_writer_index);
275
/* Copy the data for a mask or monobit bitmap. */
276
int pdf_copy_mask_bits(stream *s, const byte *base, int sourcex,
277
int raster, int w, int h, byte invert);
279
/* Copy the data for a colored image (device pixels). */
280
int pdf_copy_color_bits(stream *s, const byte *base, int sourcex,
281
int raster, int w, int h, int bytes_per_pixel);
283
/* Complete image data. */
285
pdf_complete_image_data(gx_device_pdf *pdev, pdf_image_writer *piw, int data_h,
286
int width, int bits_per_pixel);
288
/* Finish writing the binary image data. */
289
int pdf_end_image_binary(gx_device_pdf *pdev, pdf_image_writer *piw,
293
* Finish writing an image. If in-line, write the BI/dict/ID/data/EI and
294
* return 1; if a resource, write the resource definition and return 0.
296
int pdf_end_write_image(gx_device_pdf * pdev, pdf_image_writer * piw);
299
* Make alternative stream for image compression choice.
301
int pdf_make_alt_stream(gx_device_pdf * pdev, psdf_binary_writer * piw);
304
* End binary with choosing image compression.
306
int pdf_choose_compression(pdf_image_writer * piw, bool end_binary);
308
/* If the current substream is a charproc, register a font used in it. */
309
int pdf_register_charproc_resource(gx_device_pdf *pdev, gs_id id, pdf_resource_type_t type);
311
/* ---------------- Exported by gdevpdfv.c ---------------- */
313
/* Store pattern 1 parameters to cos dictionary. */
314
int pdf_store_pattern1_params(gx_device_pdf *pdev, pdf_resource_t *pres,
315
gs_pattern1_instance_t *pinst);
317
/* Write a colored Pattern color. */
318
int pdf_put_colored_pattern(gx_device_pdf *pdev, const gx_drawing_color *pdc,
319
const gs_color_space *pcs,
320
const psdf_set_color_commands_t *ppscc,
321
bool have_pattern_streams, pdf_resource_t **ppres);
323
/* Write an uncolored Pattern color. */
324
int pdf_put_uncolored_pattern(gx_device_pdf *pdev, const gx_drawing_color *pdc,
325
const gs_color_space *pcs,
326
const psdf_set_color_commands_t *ppscc,
327
bool have_pattern_streams, pdf_resource_t **ppres);
329
/* Write a PatternType 2 (shading pattern) color. */
330
int pdf_put_pattern2(gx_device_pdf *pdev, const gx_drawing_color *pdc,
331
const psdf_set_color_commands_t *ppscc,
332
pdf_resource_t **ppres);
334
/* ---------------- Exported by gdevpdfb.c ---------------- */
336
/* Copy a color bitmap. for_pattern = -1 means put the image in-line, */
337
/* 1 means put the image in a resource. */
338
int pdf_copy_color_data(gx_device_pdf * pdev, const byte * base, int sourcex,
339
int raster, gx_bitmap_id id, int x, int y, int w, int h,
340
gs_image_t *pim, pdf_image_writer *piw,
343
#endif /* gdevpdfg_INCLUDED */
345
/* ---------------- Exported by gdevpdfe.c ---------------- */
348
int pdf_document_metadata(gx_device_pdf *pdev);
349
int pdf_font_metadata(gx_device_pdf *pdev, const pdf_base_font_t *pbfont,
350
const byte *digest, int digest_length, gs_id *metadata_object_id);