~ubuntu-branches/ubuntu/jaunty/ghostscript/jaunty-updates

« back to all changes in this revision

Viewing changes to src/gdevpdfg.h

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2009-01-20 16:40:45 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120164045-lnfhi0n30o5lwhwa
Tags: 8.64.dfsg.1~svn9377-0ubuntu1
* New upstream release (SVN rev 9377)
   o Fixes many bugs concerning PDF rendering, to make the PDF printing
     workflow correctly working.
   o Fixes long-standing bugs in many drivers, like input paper tray and
     duplex options not working for the built-in PCL 4, 5, 5c, 5e, and
     6/XL drivers, PDF input not working for bjc600, bjc800, and cups
     output devices, several options not working and uninitialized
     memory with cups output device.
   o Merged nearly all patches of the Ubuntu and Debian packages upstream.
   o Fixes LP: #317810, LP: #314439, LP: #314018.
* debian/patches/03_libpaper_support.dpatch,
  debian/patches/11_gs-cjk_font_glyph_handling_fix.dpatch,
  debian/patches/12_gs-cjk_vertical_writing_metrics_fix.dpatch,
  debian/patches/13_gs-cjk_cjkps_examples.dpatch,
  debian/patches/20_bbox_segv_fix.dpatch,
  debian/patches/21_brother_7x0_gdi_fix.dpatch,
  debian/patches/22_epsn_margin_workaround.dpatch,
  debian/patches/24_gs_man_fix.dpatch,
  debian/patches/25_toolbin_insecure_tmp_usage_fix.dpatch,
  debian/patches/26_assorted_script_fixes.dpatch,
  debian/patches/29_gs_css_fix.dpatch,
  debian/patches/30_ps2pdf_man_improvement.dpatch,
  debian/patches/31_fix-gc-sigbus.dpatch,
  debian/patches/34_ftbfs-on-hurd-fix.dpatch,
  debian/patches/35_disable_libcairo.dpatch,
  debian/patches/38_pxl-duplex.dpatch,
  debian/patches/39_pxl-resolution.dpatch,
  debian/patches/42_gs-init-ps-delaybind-fix.dpatch,
  debian/patches/45_bjc600-bjc800-pdf-input.dpatch,
  debian/patches/48_cups-output-device-pdf-duplex-uninitialized-memory-fix.dpatch,
  debian/patches/50_lips4-floating-point-exception.dpatch,
  debian/patches/52_cups-device-logging.dpatch,
  debian/patches/55_pcl-input-slot-fix.dpatch,
  debian/patches/57_pxl-input-slot-fix.dpatch,
  debian/patches/60_pxl-cups-driver-pdf.dpatch,
  debian/patches/62_onebitcmyk-pdf.dpatch,
  debian/patches/65_too-big-temp-files-1.dpatch,
  debian/patches/67_too-big-temp-files-2.dpatch,
  debian/patches/70_take-into-account-data-in-stream-buffer-before-refill.dpatch:
  Removed, applied upstream.
* debian/patches/01_docdir_fix_for_debian.dpatch,
  debian/patches/02_gs_man_fix_debian.dpatch,
  debian/patches/01_docdir-fix-for-debian.dpatch,
  debian/patches/02_docdir-fix-for-debian.dpatch: Renamed patches to
  make merging with Debian easier.
* debian/patches/32_improve-handling-of-media-size-changes-from-gv.dpatch, 
  debian/patches/33_bad-params-to-xinitimage-on-large-bitmaps.dpatch:
  regenerated for new source directory structure.
* debian/rules: Corrected paths to remove cidfmap (it is in Resource/Init/
  in GS 8.64) and to install headers (source paths are psi/ and base/ now).
* debian/rules: Remove all fontmaps, as DeFoMa replaces them.
* debian/local/pdftoraster/pdftoraster.c,
  debian/local/pdftoraster/pdftoraster.convs, debian/rules: Removed
  added pdftoraster filter and use the one which comes with Ghostscript.
* debian/ghostscript.links: s/8.63/8.64/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2001-2006 Artifex Software, Inc.
2
 
   All Rights Reserved.
3
 
  
4
 
   This software is provided AS-IS with no warranty, either express or
5
 
   implied.
6
 
 
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.
12
 
*/
13
 
 
14
 
/* $Id: gdevpdfg.h 8265 2007-10-02 07:31:58Z ken $ */
15
 
/* Internal graphics interfaces for PDF-writing driver. */
16
 
 
17
 
#ifndef gdevpdfg_INCLUDED
18
 
#  define gdevpdfg_INCLUDED
19
 
 
20
 
#include "gscspace.h"           /* for gs_separation_name */
21
 
 
22
 
#ifndef pdf_base_font_DEFINED
23
 
#  define pdf_base_font_DEFINED
24
 
typedef struct pdf_base_font_s pdf_base_font_t;
25
 
#endif
26
 
 
27
 
/* ---------------- Exported by gdevpdfc.c ---------------- */
28
 
 
29
 
/* Define standard and short color space names. */
30
 
/*
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)!
34
 
 */
35
 
typedef struct pdf_color_space_names_s {
36
 
    const char *DeviceCMYK;
37
 
    const char *DeviceGray;
38
 
    const char *DeviceRGB;
39
 
    const char *Indexed;
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;
48
 
 
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;
53
 
#endif
54
 
 
55
 
/*
56
 
 * Define a ColorSpace resource.  We need to retain the range scaling
57
 
 * information (if any).
58
 
 */
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;
63
 
    uint serialized_size;
64
 
    byte *serialized;
65
 
};
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)
71
 
 
72
 
/*
73
 
 * Create a local Device{Gray,RGB,CMYK} color space corresponding to the
74
 
 * given number of components.
75
 
 */
76
 
int pdf_cspace_init_Device(gs_memory_t *mem, gs_color_space **ppcs, int num_components);
77
 
 
78
 
/*
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
84
 
 * the actual object.
85
 
 *
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.
89
 
 */
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,
94
 
                    bool by_name);
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);
100
 
 
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);
106
 
 
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);
110
 
 
111
 
/* ---------------- Exported by gdevpdfg.c ---------------- */
112
 
 
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);
116
 
 
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);
119
 
 
120
 
/* Reset the graphics state parameters to initial values. */
121
 
void pdf_reset_graphics(gx_device_pdf *pdev);
122
 
 
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);
127
 
 
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);
143
 
/*
144
 
 * Bring the graphics state up to date for a drawing operation.
145
 
 * (Text uses either fill or stroke.)
146
 
 */
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);
157
 
 
158
 
/*
159
 
 * Convert a string into cos name.
160
 
 */
161
 
int pdf_string_to_cos_name(gx_device_pdf *pdev, const byte *str, uint len, 
162
 
                       cos_value_t *pvalue);
163
 
 
164
 
/* ---------------- Exported by gdevpdfi.c ---------------- */
165
 
 
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;
170
 
};
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)
176
 
 
177
 
pdf_resource_t *pdf_substitute_pattern(pdf_resource_t *pres);
178
 
 
179
 
/* ---------------- Exported by gdevpdfj.c ---------------- */
180
 
 
181
 
/* ------ Image stream dictionaries ------ */
182
 
 
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;
190
 
    const char *Decode;
191
 
    const char *Height;
192
 
    const char *ImageMask;
193
 
    const char *Interpolate;
194
 
    const char *Width;
195
 
} pdf_image_names_t;
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;
202
 
 
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);
210
 
 
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);
216
 
 
217
 
/* ------ Image writing ------ */
218
 
 
219
 
/*
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.
223
 
 */
224
 
void pdf_make_bitmap_matrix(gs_matrix * pmat, int x, int y, int w, int h,
225
 
                            int h_actual);
226
 
 
227
 
/* Put out the gsave and matrix for an image. */
228
 
void pdf_put_image_matrix(gx_device_pdf * pdev, const gs_matrix * pmat,
229
 
                          floatp y_scale);
230
 
 
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);
236
 
 
237
 
#define pdf_image_writer_num_alt_streams 4
238
 
 
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 */
246
 
    cos_stream_t *data;
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 */
250
 
} pdf_image_writer;
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)
256
 
 
257
 
/* Initialize image writer. */
258
 
void pdf_image_writer_init(pdf_image_writer * piw);
259
 
 
260
 
/*
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
263
 
 * by a NI pdfmark.
264
 
 */
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);
268
 
 
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);
274
 
 
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);
278
 
 
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);
282
 
 
283
 
/* Complete image data. */
284
 
int
285
 
pdf_complete_image_data(gx_device_pdf *pdev, pdf_image_writer *piw, int data_h,
286
 
                        int width, int bits_per_pixel);
287
 
 
288
 
/* Finish writing the binary image data. */
289
 
int pdf_end_image_binary(gx_device_pdf *pdev, pdf_image_writer *piw,
290
 
                         int data_h);
291
 
 
292
 
/*
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.
295
 
 */
296
 
int pdf_end_write_image(gx_device_pdf * pdev, pdf_image_writer * piw);
297
 
 
298
 
/*
299
 
 *  Make alternative stream for image compression choice.
300
 
 */
301
 
int pdf_make_alt_stream(gx_device_pdf * pdev, psdf_binary_writer * piw);
302
 
 
303
 
/* 
304
 
 * End binary with choosing image compression. 
305
 
 */
306
 
int pdf_choose_compression(pdf_image_writer * piw, bool end_binary);
307
 
 
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);
310
 
 
311
 
/* ---------------- Exported by gdevpdfv.c ---------------- */
312
 
 
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);
316
 
 
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);
322
 
 
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);
328
 
 
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);
333
 
 
334
 
/* ---------------- Exported by gdevpdfb.c ---------------- */
335
 
 
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,
341
 
                    int for_pattern);
342
 
 
343
 
#endif /* gdevpdfg_INCLUDED */
344
 
 
345
 
/* ---------------- Exported by gdevpdfe.c ---------------- */
346
 
 
347
 
/* Write metadata */
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);