~ubuntu-branches/ubuntu/quantal/ghostscript/quantal-proposed

« back to all changes in this revision

Viewing changes to .pc/020120319-d6f83df-ps2write-not3ccitt-option.patch/base/gdevpdfx.h

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-06-08 11:06:51 UTC
  • mfrom: (14.1.36 sid)
  • Revision ID: package-import@ubuntu.com-20120608110651-hetjpmtjru0xtxj2
Tags: 9.05~dfsg-6ubuntu1
* Merge with Debian; remaining changes:
  - debian/patches/020120329-be64563-pdfwrite-when-a-charstring-is-not-found-for-a-glyph-use-the-notdef-width-instead-of-0.patch:
    The "pdfwrite" output device uses zero and not the width of /.notdef when
    using /.notdef for a glyph not found in an embedded font. This leads to
    wrong spacing in a PostScript file missing a space glyph.
  - debian/ghostscript-cups.postinst: Removed the post-install script which
    was only there to update the PPDs of existing print queues.
  - debian/rules, debian/ghostscript-cups.ppd-updater: Added data file to
    trigger the update of the PPD files of existing print queues by CUPS and
    to tell CUPS which PPD files to use for the update and how to match them
    with the PPDs of the existing queues.
  - debian/ghostscript-doc.install, debian/ghostscript-doc.doc-base: Install
    the Ghostscript documentation into /usr/share/doc/ghostscript-doc instead
    of /usr/share/doc/ghostscript.
  - debian/control, debian/rules, debian/libgs__VER__.install.in,
    debian/libgs-dev.install: Stop using d-shlibmove, it is not compatible
    with liblcms2.
  - debian/libgs__VER__-common.postinst.in,
    debian/libgs__VER__-common.prerm.in: Create a symlink
    /usr/share/ghostscript/current to the /usr/share/ghostscript/<version>
    directory of the newest installed libgs<version>-common package, to have
    version-independent access to the Ghostscript files.
  - debian/rules: Generate ABI version number (variable "abi") correctly,
    cutting off repackaging and pre-release parts.
  - debian/rules: update tarball MD5 value to what we already have uploaded
    in Ubuntu.
  - debian/rules, debian/control: Removed build dependency on liblcms1-dev,
    icc34.h is shipped with Ghostscript now.
  - debian/rules: Install ghostscript-cups.ppd-updater and remove the
    dependency on cups-client from ghostscript-cups.
  - debian/rules: clean up after leftover gstoraster/gstopxl instead of the
    pstoraster/pstopxl old names.
  - debian/rules, debian/ubuntu/apport-hook.py: Apport hook.
  - debian/symbols.common: added DoubleGlyphList@Base.
* debian/rules: remove the ./Resource/CMap/Identity-UTF16-H files from the
  DEB_UPSTREAM_REPACKAGE_EXCLUDES list. Due to an error in the previous
  upload it found its way in the source tarball.

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$ */
15
 
/* Internal definitions for PDF-writing driver. */
16
 
 
17
 
#ifndef gdevpdfx_INCLUDED
18
 
#  define gdevpdfx_INCLUDED
19
 
 
20
 
#include "gsparam.h"
21
 
#include "gsuid.h"
22
 
#include "gxdevice.h"
23
 
#include "gxfont.h"
24
 
#include "gxline.h"
25
 
#include "stream.h"
26
 
#include "spprint.h"
27
 
#include "gdevpsdf.h"
28
 
#include "gxdevmem.h"
29
 
#include "sarc4.h"
30
 
 
31
 
#define FINE_GLYPH_USAGE 1 /* Old code = 0, new code = 1 */
32
 
 
33
 
/* ---------------- Acrobat limitations ---------------- */
34
 
 
35
 
/*
36
 
 * The PDF reference manual, 2nd ed., claims that the limit for coordinates
37
 
 * is +/- 32767. However, testing indicates that Acrobat Reader 4 for
38
 
 * Windows and Linux fail with coordinates outside +/- 16383. Hence, we
39
 
 * limit coordinates to 16k, with a little slop.
40
 
 */
41
 
#define MAX_USER_COORD 16300
42
 
 
43
 
/* ---------------- Statically allocated sizes ---------------- */
44
 
/* These should really be dynamic.... */
45
 
 
46
 
/* Define the maximum depth of an outline tree. */
47
 
/* Note that there is no limit on the breadth of the tree. */
48
 
#define MAX_OUTLINE_DEPTH 32
49
 
 
50
 
/* Define the maximum size of a destination array string. */
51
 
#define MAX_DEST_STRING 80
52
 
 
53
 
/* ================ Types and structures ================ */
54
 
 
55
 
/* Define the possible contexts for the output stream. */
56
 
typedef enum {
57
 
    PDF_IN_NONE,
58
 
    PDF_IN_STREAM,
59
 
    PDF_IN_TEXT,
60
 
    PDF_IN_STRING
61
 
} pdf_context_t;
62
 
 
63
 
/* ---------------- Cos objects ---------------- */
64
 
 
65
 
/*
66
 
 * These are abstract types for cos objects.  The concrete types are in
67
 
 * gdevpdfo.h.
68
 
 */
69
 
typedef struct cos_object_s cos_object_t;
70
 
typedef struct cos_stream_s cos_stream_t;
71
 
typedef struct cos_dict_s cos_dict_t;
72
 
typedef struct cos_array_s cos_array_t;
73
 
typedef struct cos_value_s cos_value_t;
74
 
typedef struct cos_object_procs_s cos_object_procs_t;
75
 
typedef const cos_object_procs_t *cos_type_t;
76
 
#define cos_types_DEFINED
77
 
 
78
 
#ifndef pdf_text_state_DEFINED
79
 
#  define pdf_text_state_DEFINED
80
 
typedef struct pdf_text_state_s pdf_text_state_t;
81
 
#endif
82
 
 
83
 
#ifndef pdf_char_glyph_pairs_DEFINED
84
 
#  define pdf_char_glyph_pairs_DEFINED
85
 
typedef struct pdf_char_glyph_pairs_s pdf_char_glyph_pairs_t;
86
 
#endif
87
 
 
88
 
/* ---------------- Resources ---------------- */
89
 
 
90
 
typedef enum {
91
 
    /*
92
 
     * Standard PDF resources.  Font must be last, because resources
93
 
     * up to but not including Font are written page-by-page.
94
 
     */
95
 
    resourceColorSpace,
96
 
    resourceExtGState,
97
 
    resourcePattern,
98
 
    resourceShading,
99
 
    resourceXObject,
100
 
    resourceOther, /* Anything else that needs to be stored for a time.
101
 
                    * Can be any of the types defined below NUM_RESOURCE_TYPES
102
 
                    * but this is the type used to identify the object.
103
 
                    */
104
 
    resourceFont,
105
 
    /*
106
 
     * Internally used (pseudo-)resources.
107
 
     */
108
 
    resourceCharProc,
109
 
    resourceCIDFont,
110
 
    resourceCMap,
111
 
    resourceFontDescriptor,
112
 
    resourceGroup,
113
 
    resourceSoftMaskDict,
114
 
    resourceFunction,
115
 
    resourcePage,
116
 
    NUM_RESOURCE_TYPES,
117
 
    /* These resource types were 'resourceOther', but we want to track them
118
 
     * for ps2write. They are not stored in the pdf device structure, unlike
119
 
     * the reource types above.
120
 
     */
121
 
    resourceEncoding,
122
 
    resourceCIDSystemInfo,
123
 
    resourceHalftone,
124
 
    resourceLength,
125
 
    resourceStream,
126
 
    resourceOutline,
127
 
    resourceArticle,
128
 
    resourceDests,
129
 
    resourceLabels,
130
 
    resourceThread,
131
 
    resourceCatalog,
132
 
    resourceEncrypt,
133
 
    resourcePagesTree,
134
 
    resourceMetadata,
135
 
    resourceICC,
136
 
    resourceAnnotation,
137
 
    resourceNone        /* Special, used when this isn't a resource at all
138
 
                         * eg when we execute a resource we've just written, such as
139
 
                         * a Pattern.
140
 
                         */
141
 
} pdf_resource_type_t;
142
 
 
143
 
#define PDF_RESOURCE_TYPE_NAMES\
144
 
  "/ColorSpace", "/ExtGState", "/Pattern", "/Shading", "/XObject", 0, "/Font",\
145
 
  0, "/Font", "/CMap", "/FontDescriptor", "/Group", "/Mask", 0, 0, 0, 0, 0,\
146
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
147
 
#define PDF_RESOURCE_TYPE_STRUCTS\
148
 
  &st_pdf_color_space,                /* gdevpdfg.h / gdevpdfc.c */\
149
 
  &st_pdf_resource,                /* see below */\
150
 
  &st_pdf_pattern,\
151
 
  &st_pdf_resource,\
152
 
  &st_pdf_x_object,                /* see below */\
153
 
  &st_pdf_resource,\
154
 
  &st_pdf_font_resource,        /* gdevpdff.h / gdevpdff.c */\
155
 
  &st_pdf_char_proc,                /* gdevpdff.h / gdevpdff.c */\
156
 
  &st_pdf_font_resource,        /* gdevpdff.h / gdevpdff.c */\
157
 
  &st_pdf_resource,\
158
 
  &st_pdf_font_descriptor,        /* gdevpdff.h / gdevpdff.c */\
159
 
  &st_pdf_resource,\
160
 
  &st_pdf_resource,\
161
 
  &st_pdf_resource,\
162
 
  &st_pdf_resource
163
 
 
164
 
/*
165
 
 * rname is currently R<id> for all resources other than synthesized fonts;
166
 
 * for synthesized fonts, rname is A, B, ....  The string is null-terminated.
167
 
 */
168
 
 
169
 
#define pdf_resource_common(typ)\
170
 
    typ *next;                        /* next resource of this type */\
171
 
    pdf_resource_t *prev;        /* previously allocated resource */\
172
 
    gs_id rid;                        /* optional ID key */\
173
 
    bool named;\
174
 
    bool global;                /* ps2write only */\
175
 
    char rname[1/*R*/ + (sizeof(long) * 8 / 3 + 1) + 1/*\0*/];\
176
 
    ulong where_used;                /* 1 bit per level of content stream */\
177
 
    cos_object_t *object
178
 
typedef struct pdf_resource_s pdf_resource_t;
179
 
struct pdf_resource_s {
180
 
    pdf_resource_common(pdf_resource_t);
181
 
};
182
 
 
183
 
/* The descriptor is public for subclassing. */
184
 
extern_st(st_pdf_resource);
185
 
#define public_st_pdf_resource()  /* in gdevpdfu.c */\
186
 
  gs_public_st_ptrs3(st_pdf_resource, pdf_resource_t, "pdf_resource_t",\
187
 
    pdf_resource_enum_ptrs, pdf_resource_reloc_ptrs, next, prev, object)
188
 
 
189
 
/*
190
 
 * We define XObject resources here because they are used for Image,
191
 
 * Form, and PS XObjects, which are implemented in different files.
192
 
 */
193
 
typedef struct pdf_x_object_s pdf_x_object_t;
194
 
struct pdf_x_object_s {
195
 
    pdf_resource_common(pdf_x_object_t);
196
 
    int width, height;                /* specified width and height for images */
197
 
    int data_height;                /* actual data height for images */
198
 
};
199
 
#define private_st_pdf_x_object()  /* in gdevpdfu.c */\
200
 
  gs_private_st_suffix_add0(st_pdf_x_object, pdf_x_object_t,\
201
 
    "pdf_x_object_t", pdf_x_object_enum_ptrs, pdf_x_object_reloc_ptrs,\
202
 
    st_pdf_resource)
203
 
 
204
 
/* Define the mask for which procsets have been used on a page. */
205
 
typedef enum {
206
 
    NoMarks = 0,
207
 
    ImageB = 1,
208
 
    ImageC = 2,
209
 
    ImageI = 4,
210
 
    Text = 8
211
 
} pdf_procset_t;
212
 
 
213
 
/* ------ Fonts ------ */
214
 
 
215
 
/* Define abstract types. */
216
 
typedef struct pdf_char_proc_s pdf_char_proc_t;        /* gdevpdff.h */
217
 
typedef struct pdf_char_proc_ownership_s pdf_char_proc_ownership_t;        /* gdevpdff.h */
218
 
typedef struct pdf_font_s pdf_font_t;  /* gdevpdff.h */
219
 
typedef struct pdf_text_data_s pdf_text_data_t;  /* gdevpdft.h */
220
 
 
221
 
/* ---------------- Other auxiliary structures ---------------- */
222
 
 
223
 
/* Outline nodes and levels */
224
 
typedef struct pdf_outline_node_s {
225
 
    long id, parent_id, prev_id, first_id, last_id;
226
 
    int count;
227
 
    cos_dict_t *action;
228
 
} pdf_outline_node_t;
229
 
typedef struct pdf_outline_level_s {
230
 
    pdf_outline_node_t first;
231
 
    pdf_outline_node_t last;
232
 
    int left;
233
 
} pdf_outline_level_t;
234
 
/*
235
 
 * The GC descriptor is implicit, since outline levels occur only in an
236
 
 * embedded array in the gx_device_pdf structure.
237
 
 */
238
 
 
239
 
/* Articles */
240
 
typedef struct pdf_bead_s {
241
 
    long id, article_id, prev_id, next_id, page_id;
242
 
    gs_rect rect;
243
 
} pdf_bead_t;
244
 
typedef struct pdf_article_s pdf_article_t;
245
 
struct pdf_article_s {
246
 
    pdf_article_t *next;
247
 
    cos_dict_t *contents;
248
 
    pdf_bead_t first;
249
 
    pdf_bead_t last;
250
 
};
251
 
 
252
 
#define private_st_pdf_article()\
253
 
  gs_private_st_ptrs2(st_pdf_article, pdf_article_t,\
254
 
    "pdf_article_t", pdf_article_enum_ptrs, pdf_article_reloc_ptrs,\
255
 
    next, contents)
256
 
 
257
 
/* ---------------- The device structure ---------------- */
258
 
 
259
 
/* Resource lists */
260
 
#define NUM_RESOURCE_CHAINS 16
261
 
typedef struct pdf_resource_list_s {
262
 
    pdf_resource_t *chains[NUM_RESOURCE_CHAINS];
263
 
} pdf_resource_list_t;
264
 
 
265
 
/* Define the hash function for gs_ids. */
266
 
#define gs_id_hash(rid) ((rid) + ((rid) / NUM_RESOURCE_CHAINS))
267
 
/* Define the accessor for the proper hash chain. */
268
 
#define PDF_RESOURCE_CHAIN(pdev, type, rid)\
269
 
  (&(pdev)->resources[type].chains[gs_id_hash(rid) % NUM_RESOURCE_CHAINS])
270
 
 
271
 
/* Define the bookkeeping for an open stream. */
272
 
typedef struct pdf_stream_position_s {
273
 
    long length_id;
274
 
    long start_pos;
275
 
} pdf_stream_position_t;
276
 
 
277
 
/*
278
 
 * Define the structure for keeping track of text rotation.
279
 
 * There is one for the current page (for AutoRotate /PageByPage)
280
 
 * and one for the whole document (for AutoRotate /All).
281
 
 */
282
 
typedef struct pdf_text_rotation_s {
283
 
    long counts[5];                /* 0, 90, 180, 270, other */
284
 
    int Rotate;                        /* computed rotation, -1 means none */
285
 
} pdf_text_rotation_t;
286
 
#define pdf_text_rotation_angle_values 0, 90, 180, 270, -1
287
 
 
288
 
/*
289
 
 * Define document and page information derived from DSC comments.
290
 
 */
291
 
typedef struct pdf_page_dsc_info_s {
292
 
    int orientation;                /* -1 .. 3 */
293
 
    int viewing_orientation;        /* -1 .. 3 */
294
 
    gs_rect bounding_box;
295
 
} pdf_page_dsc_info_t;
296
 
 
297
 
/*
298
 
 * Define the stored information for a page.  Because pdfmarks may add
299
 
 * information to any page anywhere in the document, we have to wait
300
 
 * until the end to write the page dictionaries.
301
 
 */
302
 
typedef struct pdf_page_s {
303
 
    cos_dict_t *Page;
304
 
    gs_point MediaBox;
305
 
    pdf_procset_t procsets;
306
 
    long contents_id;
307
 
    long resource_ids[resourceFont + 1]; /* resources thru Font, see above */
308
 
    long group_id;
309
 
    cos_array_t *Annots;
310
 
    pdf_text_rotation_t text_rotation;
311
 
    pdf_page_dsc_info_t dsc_info;
312
 
    bool NumCopies_set; /* ps2write only. */
313
 
    int NumCopies;      /* ps2write only. */
314
 
} pdf_page_t;
315
 
#define private_st_pdf_page()        /* in gdevpdf.c */\
316
 
  gs_private_st_ptrs2(st_pdf_page, pdf_page_t, "pdf_page_t",\
317
 
    pdf_page_enum_ptrs, pdf_page_reloc_ptrs, Page, Annots)
318
 
 
319
 
/*
320
 
 * Define the structure for the temporary files used while writing.
321
 
 * There are 4 of these, described below.
322
 
 */
323
 
typedef struct pdf_temp_file_s {
324
 
    char file_name[gp_file_name_sizeof];
325
 
    FILE *file;
326
 
    stream *strm;
327
 
    byte *strm_buf;
328
 
    stream *save_strm;                /* save pdev->strm while writing here */
329
 
} pdf_temp_file_t;
330
 
 
331
 
#ifndef gx_device_pdf_DEFINED
332
 
#  define gx_device_pdf_DEFINED
333
 
typedef struct gx_device_pdf_s gx_device_pdf;
334
 
#endif
335
 
 
336
 
/*
337
 
 * Define the structure for PDF font cache element.
338
 
 */
339
 
typedef struct pdf_font_cache_elem_s pdf_font_cache_elem_t;
340
 
struct pdf_font_cache_elem_s {
341
 
    pdf_font_cache_elem_t *next;
342
 
    gs_id font_id;
343
 
    int num_chars;                /* safety purpose only */
344
 
    int num_widths;                /* safety purpose only */
345
 
    struct pdf_font_resource_s *pdfont;
346
 
    byte *glyph_usage;
347
 
    double *real_widths;        /* [count] (not used for Type 0) */
348
 
    gx_device_pdf *pdev;        /* For pdf_remove_font_cache_elem */
349
 
};
350
 
 
351
 
#define private_st_pdf_font_cache_elem()\
352
 
    gs_private_st_ptrs5(st_pdf_font_cache_elem, pdf_font_cache_elem_t,\
353
 
        "pdf_font_cache_elem_t", pdf_font_cache_elem_enum,\
354
 
        pdf_font_cache_elem_reloc, next, pdfont,\
355
 
        glyph_usage, real_widths, pdev)
356
 
 
357
 
/*
358
 
 * pdf_viewer_state tracks the graphic state of a viewer,
359
 
 * which would interpret the generated PDF file
360
 
 * immediately when it is generated.
361
 
 */
362
 
typedef struct pdf_viewer_state_s {
363
 
    int transfer_not_identity;        /* bitmask */
364
 
    gs_id transfer_ids[4];
365
 
    float opacity_alpha; /* state.opacity.alpha */
366
 
    float shape_alpha; /* state.shape.alpha */
367
 
    gs_blend_mode_t blend_mode; /* state.blend_mode */
368
 
    gs_id halftone_id;
369
 
    gs_id black_generation_id;
370
 
    gs_id undercolor_removal_id;
371
 
    int overprint_mode;
372
 
    float smoothness; /* state.smoothness */
373
 
    float flatness;
374
 
    bool text_knockout; /* state.text_knockout */
375
 
    bool fill_overprint;
376
 
    bool stroke_overprint;
377
 
    bool stroke_adjust; /* state.stroke_adjust */
378
 
    bool fill_used_process_color;
379
 
    bool stroke_used_process_color;
380
 
    gx_hl_saved_color saved_fill_color;
381
 
    gx_hl_saved_color saved_stroke_color;
382
 
    gx_line_params line_params;
383
 
    float dash_pattern[max_dash];
384
 
    gs_id soft_mask_id;
385
 
} pdf_viewer_state;
386
 
 
387
 
/*
388
 
 * Define a structure for saving context when entering
389
 
 * a contents stream accumulation mode (charproc, Type 1 pattern).
390
 
 */
391
 
typedef struct pdf_substream_save_s {
392
 
    pdf_context_t        context;
393
 
    pdf_text_state_t        *text_state;
394
 
    gx_path                *clip_path;
395
 
    gs_id                clip_path_id;
396
 
    int                        vgstack_bottom;
397
 
    stream                *strm;
398
 
    cos_dict_t                *substream_Resources;
399
 
    pdf_procset_t        procsets;
400
 
    bool                skip_colors;
401
 
    pdf_resource_t      *font3;
402
 
    pdf_resource_t        *accumulating_substream_resource;
403
 
    bool                charproc_just_accumulated;
404
 
    bool                accumulating_a_global_object;
405
 
    pdf_resource_t      *pres_soft_mask_dict;
406
 
    gs_const_string                objname;
407
 
    int                        last_charpath_op;
408
 
} pdf_substream_save;
409
 
 
410
 
#define private_st_pdf_substream_save()\
411
 
    gs_private_st_strings1_ptrs7(st_pdf_substream_save, pdf_substream_save,\
412
 
        "pdf_substream_save", pdf_substream_save_enum,\
413
 
        pdf_substream_save_reloc, objname, text_state, clip_path, strm, \
414
 
        substream_Resources, font3, accumulating_substream_resource, pres_soft_mask_dict)
415
 
#define private_st_pdf_substream_save_element()\
416
 
  gs_private_st_element(st_pdf_substream_save_element, pdf_substream_save,\
417
 
    "pdf_substream_save[]", pdf_substream_save_elt_enum_ptrs,\
418
 
    pdf_substream_save_elt_reloc_ptrs, st_pdf_substream_save)
419
 
 
420
 
typedef enum {
421
 
    pdf_compress_none,
422
 
    pdf_compress_LZW,        /* not currently used, thanks to Unisys */
423
 
    pdf_compress_Flate
424
 
} pdf_compression_type;
425
 
 
426
 
/* Define the device structure. */
427
 
struct gx_device_pdf_s {
428
 
    gx_device_psdf_common;
429
 
    bool is_ps2write;          /* ps2write (true) versus pdfwrite (false); never changed */
430
 
    /* PDF-specific distiller parameters */
431
 
    double CompatibilityLevel;
432
 
    int EndPage;
433
 
    int StartPage;
434
 
    bool Optimize;
435
 
    bool ParseDSCCommentsForDocInfo;
436
 
    bool ParseDSCComments;
437
 
    bool EmitDSCWarnings;
438
 
    bool CreateJobTicket;
439
 
    bool PreserveEPSInfo;
440
 
    bool AutoPositionEPSFiles;
441
 
    bool PreserveCopyPage;
442
 
    bool UsePrologue;
443
 
    int OffOptimizations;
444
 
    /* End of distiller parameters */
445
 
    /* PDF/X parameters */
446
 
    gs_param_float_array PDFXTrimBoxToMediaBoxOffset;
447
 
    gs_param_float_array PDFXBleedBoxToTrimBoxOffset;
448
 
    bool PDFXSetBleedBoxToMediaBox;
449
 
    /* Other parameters */
450
 
    bool ReAssignCharacters;
451
 
    bool ReEncodeCharacters;
452
 
    long FirstObjectNumber;
453
 
    bool CompressFonts;
454
 
    bool PrintStatistics;
455
 
    gs_param_string DocumentUUID;
456
 
    gs_param_string InstanceUUID;
457
 
    int DocumentTimeSeq;
458
 
    bool ForOPDFRead;          /* PS2WRITE only. */
459
 
    bool CompressEntireFile;  /* PS2WRITE only. */
460
 
    bool ResourcesBeforeUsage; /* PS2WRITE only. */
461
 
    bool HavePDFWidths;        /* PS2WRITE only. */
462
 
    bool HaveStrokeColor;      /* PS2WRITE only. */
463
 
    bool ProduceDSC;               /* PS2WRITE only. */
464
 
    bool HaveTransparency;
465
 
    bool PatternImagemask; /* The target viewer|printer handles imagemask
466
 
                              with pattern color. */
467
 
    bool PDFX;                   /* Generate PDF/X */
468
 
    bool PDFA;                   /* Generate PDF/A */
469
 
    bool AbortPDFAX;            /* Abort generation of PDFA or X, produce regular PDF */
470
 
    long MaxClipPathSize;  /* The maximal number of elements of a clipping path
471
 
                              that the target viewer|printer can handle. */
472
 
    long MaxViewerMemorySize;
473
 
    long MaxShadingBitmapSize; /* The maximal number of bytes in
474
 
                              a bitmap representation of a shading.
475
 
                              (Bigger shadings to be downsampled). */
476
 
    long MaxInlineImageSize;
477
 
    gs_param_int_array DSCEncodingToUnicode;
478
 
    /* Encryption parameters */
479
 
    gs_param_string OwnerPassword;
480
 
    gs_param_string UserPassword;
481
 
    uint KeyLength;
482
 
    uint Permissions;
483
 
    uint EncryptionR;
484
 
    gs_param_string NoEncrypt;
485
 
    bool EncryptMetadata;
486
 
    /* End of parameters */
487
 
    bool ComputeDocumentDigest; /* Developer needs only; Always true in production. */
488
 
    /* Encryption data */
489
 
    byte EncryptionO[32];
490
 
    byte EncryptionU[32];
491
 
    byte EncryptionKey[16];
492
 
    uint EncryptionV;
493
 
    /* Values derived from DSC comments */
494
 
    bool is_EPS;
495
 
    pdf_page_dsc_info_t doc_dsc_info; /* document default */
496
 
    pdf_page_dsc_info_t page_dsc_info; /* current page */
497
 
    /* Additional graphics state */
498
 
    bool fill_overprint, stroke_overprint;
499
 
    bool remap_fill_color, remap_stroke_color;
500
 
    int overprint_mode;
501
 
    gs_id halftone_id;
502
 
    gs_id transfer_ids[4];
503
 
    int transfer_not_identity;        /* bitmask */
504
 
    gs_id black_generation_id, undercolor_removal_id;
505
 
    /* Following are set when device is opened. */
506
 
    pdf_compression_type compression;
507
 
    pdf_compression_type compression_at_page_start;
508
 
#define pdf_memory v_memory
509
 
    /*
510
 
     * The xref temporary file is logically an array of longs.
511
 
     * xref[id - FirstObjectNumber] is the position in the output file
512
 
     * of the object with the given id.
513
 
     *
514
 
     * Note that xref, unlike the other temporary files, does not have
515
 
     * an associated stream or stream buffer.
516
 
     */
517
 
    pdf_temp_file_t xref;
518
 
    /*
519
 
     * asides holds resources and other "aside" objects.  It is
520
 
     * copied verbatim to the output file at the end of the document.
521
 
     */
522
 
    pdf_temp_file_t asides;
523
 
    /*
524
 
     * streams holds data for stream-type Cos objects.  The data is
525
 
     * copied to the output file at the end of the document.
526
 
     *
527
 
     * Note that streams.save_strm is not used, since we don't interrupt
528
 
     * normal output when saving stream data.
529
 
     */
530
 
    pdf_temp_file_t streams;
531
 
    /*
532
 
     * pictures holds graphic objects being accumulated between BP and EP.
533
 
     * The object is moved to streams when the EP is reached: since BP and
534
 
     * EP nest, we delete the object from the pictures file at that time.
535
 
     */
536
 
    pdf_temp_file_t pictures;
537
 
    /* ................ */
538
 
    long next_id;
539
 
    /* The following 3 objects, and only these, are allocated */
540
 
    /* when the file is opened. */
541
 
    cos_dict_t *Catalog;
542
 
    cos_dict_t *Info;
543
 
    cos_dict_t *Pages;
544
 
#define pdf_num_initial_ids 3
545
 
    long outlines_id;
546
 
    int next_page;
547
 
    int max_referred_page;
548
 
    long contents_id;
549
 
    pdf_context_t context;
550
 
    long contents_length_id;
551
 
    long contents_pos;
552
 
    pdf_procset_t procsets;        /* used on this page */
553
 
    pdf_text_data_t *text;
554
 
    pdf_text_rotation_t text_rotation;
555
 
#define initial_num_pages 50
556
 
    pdf_page_t *pages;
557
 
    int num_pages;
558
 
    ulong used_mask;                /* for where_used: page level = 1 */
559
 
    pdf_resource_list_t resources[NUM_RESOURCE_TYPES];
560
 
    /* cs_Patterns[0] is colored; 1,3,4 are uncolored + Gray,RGB,CMYK */
561
 
    pdf_resource_t *cs_Patterns[5];
562
 
    pdf_resource_t *Identity_ToUnicode_CMaps[2]; /* WMode = 0,1 */
563
 
    pdf_resource_t *last_resource;
564
 
    pdf_resource_t *OneByteIdentityH;
565
 
    gs_id IdentityCIDSystemInfo_id;
566
 
    pdf_outline_level_t outline_levels[MAX_OUTLINE_DEPTH];
567
 
    int outline_depth;
568
 
    int closed_outline_depth;
569
 
    int outlines_open;
570
 
    pdf_article_t *articles;
571
 
    cos_dict_t *Dests;
572
 
    byte fileID[16];
573
 
    /* Use a single time moment for all UUIDs to minimize an indeterminizm. */
574
 
    long uuid_time[2];
575
 
    /*
576
 
     * global_named_objects holds named objects that are independent of
577
 
     * the current namespace: {Catalog}, {DocInfo}, {Page#}, {ThisPage},
578
 
     * {PrevPage}, {NextPage}.
579
 
     */
580
 
    cos_dict_t *global_named_objects;
581
 
    /*
582
 
     * local_named_objects holds named objects in the current namespace.
583
 
     */
584
 
    cos_dict_t *local_named_objects;
585
 
    /*
586
 
     * NI_stack is a last-in, first-out stack in which each element is a
587
 
     * (named) cos_stream_t object that eventually becomes the object of an
588
 
     * image XObject resource.
589
 
     */
590
 
    cos_array_t *NI_stack;
591
 
    /*
592
 
     * Namespace_stack is a last-in, first-out stack in which each pair of
593
 
     * elements is, respectively, a saved value of local_named_objects and
594
 
     * a saved value of NI_stack.  (The latter is not documented by Adobe,
595
 
     * but it was confirmed by them.)
596
 
     */
597
 
    cos_array_t *Namespace_stack;
598
 
    pdf_font_cache_elem_t *font_cache;
599
 
    /*
600
 
     * char_width is used by pdf_text_set_cache to communicate
601
 
     * with assign_char_code around gdev_pdf_fill_mask.
602
 
     */
603
 
    gs_point char_width;
604
 
    /*
605
 
     * We need a stable copy of clipping path to prevent writing
606
 
     * redundant clipping paths when PS document generates such ones.
607
 
     */
608
 
    gx_path *clip_path;
609
 
    /*
610
 
     * Page labels.
611
 
     */
612
 
    cos_array_t *PageLabels;
613
 
    int PageLabels_current_page;
614
 
    cos_dict_t *PageLabels_current_label;
615
 
    /*
616
 
     * The following is a dangerous pointer, which pdf_text_process
617
 
     * uses to communicate with assign_char_code.
618
 
     * It is a pointer from global memory to local memory.
619
 
     * The garbager must not proceess this pointer, and it must
620
 
     * not be listed in st_device_pdfwrite.
621
 
     * It's life time terminates on garbager invocation.
622
 
     */
623
 
    gs_text_enum_t *pte;
624
 
    /*
625
 
     * The viewer's graphic state stack.
626
 
     * We restrict its length with the strongest PDF spec limitation.
627
 
     * Usually 5 levels is enough, but patterns and charprocs may be nested recursively.
628
 
     */
629
 
    pdf_viewer_state vgstack[11];
630
 
    int vgstack_depth;
631
 
    int vgstack_bottom;                 /* Stack bottom for the current substream. */
632
 
    pdf_viewer_state vg_initial; /* Initial values for viewer's graphic state */
633
 
    bool vg_initial_set;
634
 
 
635
 
    /* The substream context stack. */
636
 
    int sbstack_size;
637
 
    int sbstack_depth;
638
 
    pdf_substream_save *sbstack;
639
 
 
640
 
    /* Temporary workaround. The only way to get forms out of pdfwrite at present
641
 
     * is via a transparency group or mask operation. Ordinarily we don't care
642
 
     * much about forms, but Patterns within forms need to be scaled to the
643
 
     * CTM of the Pattern, not the default page co-ordinate system. We use
644
 
     * this value to know if we are nested inside a form or not. If we are
645
 
     * we don't undo the resolution co-ordinate transform.
646
 
     */
647
 
    int FormDepth;
648
 
 
649
 
    /* Accessories */
650
 
    cos_dict_t *substream_Resources;     /* Substream resources */
651
 
    gs_color_space_index pcm_color_info_index; /* Index of the ProcessColorModel space. */
652
 
    bool skip_colors; /* Skip colors while a pattern/charproc accumulation. */
653
 
    bool AR4_save_bug; /* See pdf_put_uncolored_pattern */
654
 
    pdf_resource_t *font3; /* The owner of the accumulated charstring. */
655
 
    pdf_resource_t *accumulating_substream_resource;
656
 
    gs_matrix_fixed charproc_ctm;
657
 
    bool charproc_just_accumulated; /* A flag for controlling
658
 
                        the glyph variation recognition.
659
 
                        Used only with uncached charprocs. */
660
 
    bool PS_accumulator; /* A flag to determine whether a given
661
 
                         accumulator is for a PostScript type 3 font or not. */
662
 
    bool accumulating_a_global_object; /* ps2write only.
663
 
                        Accumulating a global object (such as a named Form,
664
 
                        so that resources used in it must also be global.
665
 
                        Important for viewers with small memory,
666
 
                        which drops resources per page. */
667
 
    const pdf_char_glyph_pairs_t *cgp; /* A temporary pointer
668
 
                        for pdf_is_same_charproc1.
669
 
                        Must be NULL when the garbager is invoked,
670
 
                        because it points from global to local memory. */
671
 
    int substituted_pattern_count;
672
 
    int substituted_pattern_drop_page;
673
 
    /* Temporary data for use_image_as_pattern,
674
 
       They pass an information about a mask of a masked image,
675
 
       (which is being converted into a pattern)
676
 
       between 2 consecutive calls to pdf_image_end_image_data. */
677
 
    gs_id     image_mask_id;
678
 
    bool      image_mask_is_SMask;
679
 
    bool      image_mask_skip; /* A flag for pdf_begin_transparency_mask */
680
 
    bool      image_with_SMask; /* A flag for pdf_begin_transparency_group. */
681
 
    gs_matrix converting_image_matrix;
682
 
    double    image_mask_scale;
683
 
    /* Temporary data for soft mask form. */
684
 
    pdf_resource_t *pres_soft_mask_dict;
685
 
    /* Temporary data for pdfmark_BP. */
686
 
    gs_const_string objname;
687
 
    int OPDFRead_procset_length;      /* PS2WRITE only. */
688
 
    void *find_resource_param; /* WARNING : not visible for garbager. */
689
 
    int last_charpath_op; /* true or false state of last charpath */
690
 
    bool type3charpath;
691
 
    bool SetPageSize;
692
 
    bool RotatePages;
693
 
    bool FitPages;
694
 
    bool CenterPages;
695
 
    bool DoNumCopies;
696
 
    bool PreserveSeparation;
697
 
    bool PreserveDeviceN;
698
 
    int PDFACompatibilityPolicy;
699
 
    bool DetectDuplicateImages;
700
 
    bool AllowIncrementalCFF;
701
 
    bool HighLevelDevice;
702
 
    bool WantsToUnicode;
703
 
    bool AllowPSRepeatFunctions;
704
 
    bool IsDistiller;
705
 
    bool PreserveSMask;
706
 
    bool PreserveTrMode;
707
 
};
708
 
 
709
 
#define is_in_page(pdev)\
710
 
  ((pdev)->contents_id != 0)
711
 
#define is_in_document(pdev)\
712
 
  (is_in_page(pdev) || (pdev)->last_resource != 0)
713
 
 
714
 
/* Enumerate the individual pointers in a gx_device_pdf. */
715
 
#define gx_device_pdf_do_ptrs(m)\
716
 
 m(0,asides.strm) m(1,asides.strm_buf) m(2,asides.save_strm)\
717
 
 m(3,streams.strm) m(4,streams.strm_buf)\
718
 
 m(5,pictures.strm) m(6,pictures.strm_buf) m(7,pictures.save_strm)\
719
 
 m(8,Catalog) m(9,Info) m(10,Pages)\
720
 
 m(11,text) m(12,pages)\
721
 
 m(13,cs_Patterns[0])\
722
 
 m(14,cs_Patterns[1]) m(15,cs_Patterns[3]) m(16,cs_Patterns[4])\
723
 
 m(17,last_resource)\
724
 
 m(18,articles) m(19,Dests) m(20,global_named_objects)\
725
 
 m(21, local_named_objects) m(22,NI_stack) m(23,Namespace_stack)\
726
 
 m(24,font_cache) m(25,clip_path)\
727
 
 m(26,PageLabels) m(27,PageLabels_current_label)\
728
 
 m(28,sbstack) m(29,substream_Resources) m(30,font3)\
729
 
 m(31,accumulating_substream_resource) \
730
 
 m(32,pres_soft_mask_dict) m(33,PDFXTrimBoxToMediaBoxOffset.data)\
731
 
 m(34,PDFXBleedBoxToTrimBoxOffset.data) m(35, DSCEncodingToUnicode.data)\
732
 
 m(36,Identity_ToUnicode_CMaps[0]) m(37,Identity_ToUnicode_CMaps[1])
733
 
#define gx_device_pdf_num_ptrs 38
734
 
#define gx_device_pdf_do_param_strings(m)\
735
 
    m(0, OwnerPassword) m(1, UserPassword) m(2, NoEncrypt)\
736
 
    m(3, DocumentUUID) m(4, InstanceUUID)
737
 
#define gx_device_pdf_num_param_strings 5
738
 
#define gx_device_pdf_do_const_strings(m)\
739
 
    m(0, objname)
740
 
#define gx_device_pdf_num_const_strings 1
741
 
#define st_device_pdf_max_ptrs\
742
 
  (st_device_psdf_max_ptrs + gx_device_pdf_num_ptrs +\
743
 
   gx_device_pdf_num_param_strings + gx_device_pdf_num_const_strings +\
744
 
   NUM_RESOURCE_TYPES * NUM_RESOURCE_CHAINS /* resources[].chains[] */ +\
745
 
   MAX_OUTLINE_DEPTH * 2 /* outline_levels[].{first,last}.action */
746
 
 
747
 
#define private_st_device_pdfwrite()        /* in gdevpdf.c */\
748
 
  gs_private_st_composite_final(st_device_pdfwrite, gx_device_pdf,\
749
 
    "gx_device_pdf", device_pdfwrite_enum_ptrs, device_pdfwrite_reloc_ptrs,\
750
 
    device_pdfwrite_finalize)
751
 
 
752
 
/* ================ Driver procedures ================ */
753
 
 
754
 
    /* In gdevpdfb.c */
755
 
dev_proc_copy_mono(gdev_pdf_copy_mono);
756
 
dev_proc_copy_color(gdev_pdf_copy_color);
757
 
dev_proc_fill_mask(gdev_pdf_fill_mask);
758
 
dev_proc_strip_tile_rectangle(gdev_pdf_strip_tile_rectangle);
759
 
    /* In gdevpdfd.c */
760
 
extern const gx_device_vector_procs pdf_vector_procs;
761
 
dev_proc_fill_rectangle(gdev_pdf_fill_rectangle);
762
 
dev_proc_fill_path(gdev_pdf_fill_path);
763
 
dev_proc_stroke_path(gdev_pdf_stroke_path);
764
 
dev_proc_fillpage(gdev_pdf_fillpage);
765
 
    /* In gdevpdfi.c */
766
 
dev_proc_begin_typed_image(gdev_pdf_begin_typed_image);
767
 
    /* In gdevpdfp.c */
768
 
dev_proc_get_params(gdev_pdf_get_params);
769
 
dev_proc_put_params(gdev_pdf_put_params);
770
 
    /* In gdevpdft.c */
771
 
dev_proc_text_begin(gdev_pdf_text_begin);
772
 
dev_proc_fill_rectangle_hl_color(gdev_pdf_fill_rectangle_hl_color);
773
 
    /* In gdevpdfv.c */
774
 
dev_proc_include_color_space(gdev_pdf_include_color_space);
775
 
    /* In gdevpdft.c */
776
 
dev_proc_create_compositor(gdev_pdf_create_compositor);
777
 
dev_proc_begin_transparency_group(gdev_pdf_begin_transparency_group);
778
 
dev_proc_end_transparency_group(gdev_pdf_end_transparency_group);
779
 
dev_proc_begin_transparency_mask(gdev_pdf_begin_transparency_mask);
780
 
dev_proc_end_transparency_mask(gdev_pdf_end_transparency_mask);
781
 
dev_proc_discard_transparency_layer(gdev_pdf_discard_transparency_layer);
782
 
dev_proc_dev_spec_op(gdev_pdf_dev_spec_op);
783
 
 
784
 
/* ================ Utility procedures ================ */
785
 
 
786
 
/* ---------------- Exported by gdevpdf.c ---------------- */
787
 
 
788
 
/* Initialize the IDs allocated at startup. */
789
 
void pdf_initialize_ids(gx_device_pdf * pdev);
790
 
 
791
 
/* Update the color mapping procedures after setting ProcessColorModel. */
792
 
void pdf_set_process_color_model(gx_device_pdf * pdev, int index);
793
 
 
794
 
/* Reset the text state parameters to initial values. */
795
 
void pdf_reset_text(gx_device_pdf *pdev);
796
 
 
797
 
/* ---------------- Exported by gdevpdfu.c ---------------- */
798
 
 
799
 
/* ------ Document ------ */
800
 
 
801
 
/* Write a DSC compliant header to the file */
802
 
int ps2write_dsc_header(gx_device_pdf * pdev, int pages);
803
 
 
804
 
/* Open the document if necessary. */
805
 
int pdf_open_document(gx_device_pdf * pdev);
806
 
 
807
 
/* ------ Objects ------ */
808
 
 
809
 
/* Allocate an ID for a future object, set its pos=0 so we can tell if it is used */
810
 
long pdf_obj_forward_ref(gx_device_pdf * pdev);
811
 
 
812
 
/* Allocate an ID for a future object. */
813
 
long pdf_obj_ref(gx_device_pdf * pdev);
814
 
 
815
 
/* Read the current position in the output stream. */
816
 
long pdf_stell(gx_device_pdf * pdev);
817
 
 
818
 
/* Begin an object, optionally allocating an ID. */
819
 
long pdf_open_obj(gx_device_pdf * pdev, long id, pdf_resource_type_t type);
820
 
long pdf_begin_obj(gx_device_pdf * pdev, pdf_resource_type_t type);
821
 
 
822
 
/* End an object. */
823
 
int pdf_end_obj(gx_device_pdf * pdev, pdf_resource_type_t type);
824
 
 
825
 
/* ------ Page contents ------ */
826
 
 
827
 
/* Open a page contents part. */
828
 
/* Return an error if the page has too many contents parts. */
829
 
int pdf_open_contents(gx_device_pdf * pdev, pdf_context_t context);
830
 
 
831
 
/* Close the current contents part if we are in one. */
832
 
int pdf_close_contents(gx_device_pdf * pdev, bool last);
833
 
 
834
 
/* ------ Resources et al ------ */
835
 
 
836
 
extern const char *const pdf_resource_type_names[];
837
 
extern const gs_memory_struct_type_t *const pdf_resource_type_structs[];
838
 
 
839
 
/*
840
 
 * Define the offset that indicates that a file position is in the
841
 
 * asides file rather than the main (contents) file.
842
 
 * Must be a power of 2, and larger than the largest possible output file.
843
 
 */
844
 
#define ASIDES_BASE_POSITION min_long
845
 
 
846
 
/* Begin an object logically separate from the contents. */
847
 
/* (I.e., an object in the resource file.) */
848
 
long pdf_open_separate(gx_device_pdf * pdev, long id, pdf_resource_type_t type);
849
 
long pdf_begin_separate(gx_device_pdf * pdev, pdf_resource_type_t type);
850
 
 
851
 
/* Reserve object id. */
852
 
void pdf_reserve_object_id(gx_device_pdf * pdev, pdf_resource_t *ppres, long id);
853
 
 
854
 
/* Begin an aside (resource, annotation, ...). */
855
 
int pdf_alloc_aside(gx_device_pdf * pdev, pdf_resource_t ** plist,
856
 
                const gs_memory_struct_type_t * pst, pdf_resource_t **ppres,
857
 
                long id);
858
 
/* Begin an aside (resource, annotation, ...). */
859
 
int pdf_begin_aside(gx_device_pdf * pdev, pdf_resource_t **plist,
860
 
                    const gs_memory_struct_type_t * pst,
861
 
                    pdf_resource_t **ppres, pdf_resource_type_t type);
862
 
 
863
 
/* Begin a resource of a given type. */
864
 
int pdf_begin_resource(gx_device_pdf * pdev, pdf_resource_type_t rtype,
865
 
                       gs_id rid, pdf_resource_t **ppres);
866
 
 
867
 
/* Begin a resource body of a given type. */
868
 
int pdf_begin_resource_body(gx_device_pdf * pdev, pdf_resource_type_t rtype,
869
 
                            gs_id rid, pdf_resource_t **ppres);
870
 
 
871
 
/* Allocate a resource, but don't open the stream. */
872
 
int pdf_alloc_resource(gx_device_pdf * pdev, pdf_resource_type_t rtype,
873
 
                       gs_id rid, pdf_resource_t **ppres, long id);
874
 
 
875
 
/* Find same resource. */
876
 
int pdf_find_same_resource(gx_device_pdf * pdev,
877
 
        pdf_resource_type_t rtype, pdf_resource_t **ppres,
878
 
        int (*eq)(gx_device_pdf * pdev, pdf_resource_t *pres0, pdf_resource_t *pres1));
879
 
 
880
 
/* Find resource by resource id. */
881
 
pdf_resource_t *pdf_find_resource_by_resource_id(gx_device_pdf * pdev,
882
 
                                                pdf_resource_type_t rtype, gs_id id);
883
 
 
884
 
/* Find a resource of a given type by gs_id. */
885
 
pdf_resource_t *pdf_find_resource_by_gs_id(gx_device_pdf * pdev,
886
 
                                           pdf_resource_type_t rtype,
887
 
                                           gs_id rid);
888
 
 
889
 
void pdf_drop_resources(gx_device_pdf * pdev, pdf_resource_type_t rtype,
890
 
        int (*cond)(gx_device_pdf * pdev, pdf_resource_t *pres));
891
 
 
892
 
/* Print resource statistics. */
893
 
void pdf_print_resource_statistics(gx_device_pdf * pdev);
894
 
 
895
 
/* Cancel a resource (do not write it into PDF). */
896
 
int pdf_cancel_resource(gx_device_pdf * pdev, pdf_resource_t *pres,
897
 
        pdf_resource_type_t rtype);
898
 
 
899
 
/* Remove a resource. */
900
 
void pdf_forget_resource(gx_device_pdf * pdev, pdf_resource_t *pres1,
901
 
        pdf_resource_type_t rtype);
902
 
 
903
 
/* Substitute a resource with a same one. */
904
 
int pdf_substitute_resource(gx_device_pdf *pdev, pdf_resource_t **ppres,
905
 
            pdf_resource_type_t rtype,
906
 
            int (*eq)(gx_device_pdf *pdev, pdf_resource_t *pres0, pdf_resource_t *pres1),
907
 
            bool write);
908
 
 
909
 
/* Get the object id of a resource. */
910
 
long pdf_resource_id(const pdf_resource_t *pres);
911
 
 
912
 
/* End a separate object. */
913
 
int pdf_end_separate(gx_device_pdf * pdev, pdf_resource_type_t type);
914
 
 
915
 
/* End an aside. */
916
 
int pdf_end_aside(gx_device_pdf * pdev, pdf_resource_type_t type);
917
 
 
918
 
/* End a resource. */
919
 
int pdf_end_resource(gx_device_pdf * pdev, pdf_resource_type_t type);
920
 
 
921
 
/*
922
 
 * Write the Cos objects for resources local to a content stream.
923
 
 */
924
 
int pdf_write_resource_objects(gx_device_pdf *pdev, pdf_resource_type_t rtype);
925
 
 
926
 
/*
927
 
 * Reverse resource chains.
928
 
 * ps2write uses it with page resources.
929
 
 * Assuming only the 0th chain contauns something.
930
 
 */
931
 
void pdf_reverse_resource_chain(gx_device_pdf *pdev, pdf_resource_type_t rtype);
932
 
 
933
 
/*
934
 
 * Free unnamed Cos objects for resources local to a content stream.
935
 
 */
936
 
int pdf_free_resource_objects(gx_device_pdf *pdev, pdf_resource_type_t rtype);
937
 
 
938
 
/* Write and free all resource objects. */
939
 
 
940
 
int pdf_write_and_free_all_resource_objects(gx_device_pdf *pdev);
941
 
 
942
 
/*
943
 
 * Store the resource sets for a content stream (page or XObject).
944
 
 * Sets page->{procsets, resource_ids[], fonts_id}.
945
 
 */
946
 
int pdf_store_page_resources(gx_device_pdf *pdev, pdf_page_t *page, bool clear_usage);
947
 
 
948
 
/* Copy data from a temporary file to a stream. */
949
 
void pdf_copy_data(stream *s, FILE *file, long count, stream_arcfour_state *ss);
950
 
void pdf_copy_data_safe(stream *s, FILE *file, int64_t position, long count);
951
 
 
952
 
/* Add the encryption filter. */
953
 
int pdf_begin_encrypt(gx_device_pdf * pdev, stream **s, gs_id object_id);
954
 
/* Remove the encryption filter. */
955
 
void pdf_end_encrypt(gx_device_pdf * pdev);
956
 
/* Initialize encryption. */
957
 
int pdf_encrypt_init(const gx_device_pdf * pdev, gs_id object_id, stream_arcfour_state *psarc4);
958
 
 
959
 
/* ------ Pages ------ */
960
 
 
961
 
/* Get or assign the ID for a page. */
962
 
/* Returns 0 if the page number is out of range. */
963
 
long pdf_page_id(gx_device_pdf * pdev, int page_num);
964
 
 
965
 
/* Get the page structure for the current page. */
966
 
pdf_page_t *pdf_current_page(gx_device_pdf *pdev);
967
 
 
968
 
/* Get the dictionary object for the current page. */
969
 
cos_dict_t *pdf_current_page_dict(gx_device_pdf *pdev);
970
 
 
971
 
/* Open a page for writing. */
972
 
int pdf_open_page(gx_device_pdf * pdev, pdf_context_t context);
973
 
 
974
 
/*  Go to the unclipped stream context. */
975
 
int pdf_unclip(gx_device_pdf * pdev);
976
 
 
977
 
/* Write saved page- or document-level information. */
978
 
int pdf_write_saved_string(gx_device_pdf * pdev, gs_string * pstr);
979
 
 
980
 
/* ------ Path drawing ------ */
981
 
 
982
 
/* Store a copy of clipping path. */
983
 
int pdf_remember_clip_path(gx_device_pdf * pdev, const gx_clip_path * pcpath);
984
 
 
985
 
/* Test whether the clip path needs updating. */
986
 
bool pdf_must_put_clip_path(gx_device_pdf * pdev, const gx_clip_path * pcpath);
987
 
 
988
 
/* Write and update the clip path. */
989
 
int pdf_put_clip_path(gx_device_pdf * pdev, const gx_clip_path * pcpath);
990
 
 
991
 
/* ------ Masked image convertion ------ */
992
 
 
993
 
typedef struct pdf_lcvd_s {
994
 
    gx_device_memory mdev;
995
 
    gx_device_memory *mask;
996
 
    gx_device_pdf *pdev;
997
 
    dev_t_proc_copy_color((*std_copy_color), gx_device);
998
 
    dev_t_proc_fill_rectangle((*std_fill_rectangle), gx_device);
999
 
    dev_t_proc_close_device((*std_close_device), gx_device);
1000
 
    dev_t_proc_get_clipping_box((*std_get_clipping_box), gx_device);
1001
 
    bool mask_is_empty;
1002
 
    bool path_is_empty;
1003
 
    bool mask_is_clean;
1004
 
    bool write_matrix;
1005
 
    bool has_background;
1006
 
    gs_matrix m;
1007
 
    gs_point path_offset;
1008
 
} pdf_lcvd_t;
1009
 
 
1010
 
#define public_st_pdf_lcvd_t()\
1011
 
  gs_public_st_suffix_add2(st_pdf_lcvd_t, pdf_lcvd_t,\
1012
 
    "pdf_lcvd_t", pdf_lcvd_t_enum_ptrs,\
1013
 
    pdf_lcvd_t_reloc_ptrs, st_device_memory, mask, pdev)
1014
 
#define pdf_lcvd_t_max_ptrs (gx_device_memory_max_ptrs + 2)
1015
 
 
1016
 
int pdf_setup_masked_image_converter(gx_device_pdf *pdev, gs_memory_t *mem, const gs_matrix *m, pdf_lcvd_t **pcvd,
1017
 
                                 bool need_mask, int x, int y, int w, int h, bool write_on_close);
1018
 
int pdf_dump_converted_image(gx_device_pdf *pdev, pdf_lcvd_t *cvd);
1019
 
void pdf_remove_masked_image_converter(gx_device_pdf *pdev, pdf_lcvd_t *cvd, bool need_mask);
1020
 
 
1021
 
/* ------ Miscellaneous output ------ */
1022
 
 
1023
 
#define PDF_MAX_PRODUCER 200        /* adhoc */
1024
 
/* Generate the default Producer string. */
1025
 
void pdf_store_default_Producer(char buf[PDF_MAX_PRODUCER]);
1026
 
 
1027
 
/* Define the strings for filter names and parameters. */
1028
 
typedef struct pdf_filter_names_s {
1029
 
    const char *ASCII85Decode;
1030
 
    const char *ASCIIHexDecode;
1031
 
    const char *CCITTFaxDecode;
1032
 
    const char *DCTDecode;
1033
 
    const char *DecodeParms;
1034
 
    const char *Filter;
1035
 
    const char *FlateDecode;
1036
 
    const char *LZWDecode;
1037
 
    const char *RunLengthDecode;
1038
 
    const char *JBIG2Decode;
1039
 
    const char *JPXDecode;
1040
 
} pdf_filter_names_t;
1041
 
#define PDF_FILTER_NAMES\
1042
 
  "/ASCII85Decode", "/ASCIIHexDecode", "/CCITTFaxDecode",\
1043
 
  "/DCTDecode",  "/DecodeParms", "/Filter", "/FlateDecode",\
1044
 
  "/LZWDecode", "/RunLengthDecode", "/JBIG2Decode", "/JPXDecode"
1045
 
#define PDF_FILTER_NAMES_SHORT\
1046
 
  "/A85", "/AHx", "/CCF", "/DCT", "/DP", "/F", "/Fl", "/LZW", "/RL", "/???", "/???"
1047
 
 
1048
 
/* Write matrix values. */
1049
 
void pdf_put_matrix(gx_device_pdf *pdev, const char *before,
1050
 
                    const gs_matrix *pmat, const char *after);
1051
 
 
1052
 
/* Write a name, with escapes for unusual characters. */
1053
 
typedef int (*pdf_put_name_chars_proc_t)(stream *, const byte *, uint);
1054
 
pdf_put_name_chars_proc_t
1055
 
    pdf_put_name_chars_proc(const gx_device_pdf *pdev);
1056
 
int pdf_put_name_chars(const gx_device_pdf *pdev, const byte *nstr,
1057
 
                        uint size);
1058
 
int pdf_put_name(const gx_device_pdf *pdev, const byte *nstr, uint size);
1059
 
 
1060
 
/* Write a string in its shortest form ( () or <> ). */
1061
 
int pdf_put_string(const gx_device_pdf *pdev, const byte *str, uint size);
1062
 
 
1063
 
/* Write a value, treating names specially. */
1064
 
int pdf_write_value(const gx_device_pdf *pdev, const byte *vstr, uint size, gs_id object_id);
1065
 
 
1066
 
/* Store filters for a stream. */
1067
 
int pdf_put_filters(cos_dict_t *pcd, gx_device_pdf *pdev, stream *s,
1068
 
                    const pdf_filter_names_t *pfn);
1069
 
 
1070
 
/* Define a possibly encoded and compressed data stream. */
1071
 
typedef struct pdf_data_writer_s {
1072
 
    psdf_binary_writer binary;
1073
 
    long start;
1074
 
    long length_pos;
1075
 
    pdf_resource_t *pres;
1076
 
    gx_device_pdf *pdev; /* temporary for backward compatibility of pdf_end_data prototype. */
1077
 
    long length_id;
1078
 
    bool encrypted;
1079
 
} pdf_data_writer_t;
1080
 
/*
1081
 
 * Begin a data stream.  The client has opened the object and written
1082
 
 * the << and any desired dictionary keys.
1083
 
 */
1084
 
#define DATA_STREAM_NOT_BINARY 0  /* data are text, not binary */
1085
 
#define DATA_STREAM_BINARY 1        /* data are binary */
1086
 
#define DATA_STREAM_COMPRESS 2        /* OK to compress data */
1087
 
#define DATA_STREAM_NOLENGTH 4        /* Skip the length reference and filter names writing. */
1088
 
#define DATA_STREAM_ENCRYPT  8        /* Encrypt data. */
1089
 
int pdf_begin_data_stream(gx_device_pdf *pdev, pdf_data_writer_t *pdw,
1090
 
                          int options, gs_id object_id);
1091
 
int pdf_append_data_stream_filters(gx_device_pdf *pdev, pdf_data_writer_t *pdw,
1092
 
                      int orig_options, gs_id object_id);
1093
 
/* begin_data = begin_data_binary with both options = true. */
1094
 
int pdf_begin_data(gx_device_pdf *pdev, pdf_data_writer_t *pdw);
1095
 
 
1096
 
/* End a data stream. */
1097
 
int pdf_end_data(pdf_data_writer_t *pdw);
1098
 
 
1099
 
/* ------ Functions ------ */
1100
 
 
1101
 
/* Define the maximum size of a Function reference. */
1102
 
#define MAX_REF_CHARS ((sizeof(long) * 8 + 2) / 3)
1103
 
 
1104
 
/*
1105
 
 * Create a Function object with or without range scaling.  Scaling means
1106
 
 * that if x[i] is the i'th output value from the original Function,
1107
 
 * the i'th output value from the Function object will be (x[i] -
1108
 
 * ranges[i].rmin) / (ranges[i].rmax - ranges[i].rmin).  Note that this is
1109
 
 * the inverse of the scaling convention for Functions per se.
1110
 
 */
1111
 
#ifndef gs_function_DEFINED
1112
 
typedef struct gs_function_s gs_function_t;
1113
 
#  define gs_function_DEFINED
1114
 
#endif
1115
 
int pdf_function(gx_device_pdf *pdev, const gs_function_t *pfn,
1116
 
                 cos_value_t *pvalue);
1117
 
int pdf_function_scaled(gx_device_pdf *pdev, const gs_function_t *pfn,
1118
 
                        const gs_range_t *pranges, cos_value_t *pvalue);
1119
 
 
1120
 
/* Write a Function object, returning its object ID. */
1121
 
int pdf_write_function(gx_device_pdf *pdev, const gs_function_t *pfn,
1122
 
                       long *pid);
1123
 
 
1124
 
/* ------ Fonts ------ */
1125
 
 
1126
 
/* Write a FontBBox dictionary element. */
1127
 
int pdf_write_font_bbox(gx_device_pdf *pdev, const gs_int_rect *pbox);
1128
 
int pdf_write_font_bbox_float(gx_device_pdf *pdev, const gs_rect *pbox);
1129
 
 
1130
 
/* ---------------- Exported by gdevpdfm.c ---------------- */
1131
 
 
1132
 
/*
1133
 
 * Define the type for a pdfmark-processing procedure.
1134
 
 * If nameable is false, the objname argument is always NULL.
1135
 
 */
1136
 
#define pdfmark_proc(proc)\
1137
 
  int proc(gx_device_pdf *pdev, gs_param_string *pairs, uint count,\
1138
 
           const gs_matrix *pctm, const gs_param_string *objname)
1139
 
 
1140
 
/* Compare a C string and a gs_param_string. */
1141
 
bool pdf_key_eq(const gs_param_string * pcs, const char *str);
1142
 
 
1143
 
/* Scan an integer out of a parameter string. */
1144
 
int pdfmark_scan_int(const gs_param_string * pstr, int *pvalue);
1145
 
 
1146
 
/* Process a pdfmark (called from pdf_put_params). */
1147
 
int pdfmark_process(gx_device_pdf * pdev, const gs_param_string_array * pma);
1148
 
 
1149
 
/* Close the current level of the outline tree. */
1150
 
int pdfmark_close_outline(gx_device_pdf * pdev);
1151
 
 
1152
 
/* Close the pagelabel numtree. */
1153
 
int pdfmark_end_pagelabels(gx_device_pdf * pdev);
1154
 
 
1155
 
/* Finish writing an article. */
1156
 
int pdfmark_write_article(gx_device_pdf * pdev, const pdf_article_t * part);
1157
 
 
1158
 
/* ---------------- Exported by gdevpdfr.c ---------------- */
1159
 
 
1160
 
/* Test whether an object name has valid syntax, {name}. */
1161
 
bool pdf_objname_is_valid(const byte *data, uint size);
1162
 
 
1163
 
/*
1164
 
 * Look up a named object.  Return e_rangecheck if the syntax is invalid,
1165
 
 * e_undefined if no object by that name exists.
1166
 
 */
1167
 
int pdf_find_named(gx_device_pdf * pdev, const gs_param_string * pname,
1168
 
                   cos_object_t **ppco);
1169
 
 
1170
 
/*
1171
 
 * Create a named object.  id = -1L means do not assign an id.  pname = 0
1172
 
 * means just create the object, do not name it.
1173
 
 */
1174
 
int pdf_create_named(gx_device_pdf *pdev, const gs_param_string *pname,
1175
 
                     cos_type_t cotype, cos_object_t **ppco, long id);
1176
 
int pdf_create_named_dict(gx_device_pdf *pdev, const gs_param_string *pname,
1177
 
                          cos_dict_t **ppcd, long id);
1178
 
 
1179
 
/*
1180
 
 * Look up a named object as for pdf_find_named.  If the object does not
1181
 
 * exist, create it (as a dictionary if it is one of the predefined names
1182
 
 * {ThisPage}, {NextPage}, {PrevPage}, or {Page<#>}, otherwise as a
1183
 
 * generic object) and return 1.
1184
 
 */
1185
 
int pdf_refer_named(gx_device_pdf *pdev, const gs_param_string *pname,
1186
 
                    cos_object_t **ppco);
1187
 
 
1188
 
/*
1189
 
 * Look up a named object as for pdf_refer_named.  If the object already
1190
 
 * exists and is not simply a forward reference, return e_rangecheck;
1191
 
 * if it exists as a forward reference, set its type and return 0;
1192
 
 * otherwise, create the object with the given type and return 1.
1193
 
 * pname = 0 is allowed: in this case, simply create the object.
1194
 
 */
1195
 
int pdf_make_named(gx_device_pdf * pdev, const gs_param_string * pname,
1196
 
                   cos_type_t cotype, cos_object_t **ppco, bool assign_id);
1197
 
int pdf_make_named_dict(gx_device_pdf * pdev, const gs_param_string * pname,
1198
 
                        cos_dict_t **ppcd, bool assign_id);
1199
 
 
1200
 
/*
1201
 
 * Look up a named object as for pdf_refer_named.  If the object does not
1202
 
 * exist, or is a forward reference, return e_undefined; if the object
1203
 
 * exists has the wrong type, return e_typecheck.
1204
 
 */
1205
 
int pdf_get_named(gx_device_pdf * pdev, const gs_param_string * pname,
1206
 
                  cos_type_t cotype, cos_object_t **ppco);
1207
 
 
1208
 
/*
1209
 
 * Push the current local namespace onto the namespace stack, and reset it
1210
 
 * to an empty namespace.
1211
 
 */
1212
 
int pdf_push_namespace(gx_device_pdf *pdev);
1213
 
 
1214
 
/*
1215
 
 * Pop the top local namespace from the namespace stack.  Return an error if
1216
 
 * the stack is empty.
1217
 
 */
1218
 
int pdf_pop_namespace(gx_device_pdf *pdev);
1219
 
 
1220
 
/*
1221
 
 * Scan a string for a token.  <<, >>, [, and ] are treated as tokens.
1222
 
 * Return 1 if a token was scanned, 0 if we reached the end of the string,
1223
 
 * or an error.  On a successful return, the token extends from *ptoken up
1224
 
 * to but not including *pscan.
1225
 
 */
1226
 
int pdf_scan_token(const byte **pscan, const byte * end, const byte **ptoken);
1227
 
 
1228
 
/*
1229
 
 * Scan a possibly composite token: arrays and dictionaries are treated as
1230
 
 * single tokens.
1231
 
 */
1232
 
int pdf_scan_token_composite(const byte **pscan, const byte * end,
1233
 
                             const byte **ptoken);
1234
 
 
1235
 
/* Replace object names with object references in a (parameter) string. */
1236
 
int pdf_replace_names(gx_device_pdf *pdev, const gs_param_string *from,
1237
 
                      gs_param_string *to);
1238
 
 
1239
 
/* ================ Text module procedures ================ */
1240
 
 
1241
 
/* ---------------- Exported by gdevpdfw.c ---------------- */
1242
 
 
1243
 
/* For gdevpdf.c */
1244
 
 
1245
 
/*
1246
 
 * Close the text-related parts of a document, including writing out font
1247
 
 * and related resources.
1248
 
 */
1249
 
int pdf_close_text_document(gx_device_pdf *pdev);
1250
 
 
1251
 
/* ---------------- Exported by gdevpdft.c ---------------- */
1252
 
 
1253
 
/* For gdevpdf.c */
1254
 
 
1255
 
pdf_text_data_t *pdf_text_data_alloc(gs_memory_t *mem);
1256
 
void pdf_set_text_state_default(pdf_text_state_t *pts);
1257
 
void pdf_text_state_copy(pdf_text_state_t *pts_to, pdf_text_state_t *pts_from);
1258
 
void pdf_reset_text_page(pdf_text_data_t *ptd);
1259
 
void pdf_reset_text_state(pdf_text_data_t *ptd);
1260
 
void pdf_close_text_page(gx_device_pdf *pdev);
1261
 
int  pdf_get_stoted_text_size(pdf_text_state_t *state);
1262
 
 
1263
 
/* For gdevpdfb.c */
1264
 
 
1265
 
int pdf_char_image_y_offset(const gx_device_pdf *pdev, int x, int y, int h);
1266
 
 
1267
 
/* Begin a CharProc for an embedded (bitmap) font. */
1268
 
int pdf_begin_char_proc(gx_device_pdf * pdev, int w, int h, int x_width,
1269
 
                        int y_offset, int x_offset, gs_id id, pdf_char_proc_t **ppcp,
1270
 
                        pdf_stream_position_t * ppos);
1271
 
 
1272
 
/* End a CharProc. */
1273
 
int pdf_end_char_proc(gx_device_pdf * pdev, pdf_stream_position_t * ppos);
1274
 
 
1275
 
/* Put out a reference to an image as a character in an embedded font. */
1276
 
int pdf_do_char_image(gx_device_pdf * pdev, const pdf_char_proc_t * pcp,
1277
 
                      const gs_matrix * pimat);
1278
 
 
1279
 
/* Start charproc accumulation for a Type 3 font. */
1280
 
int pdf_start_charproc_accum(gx_device_pdf *pdev);
1281
 
/* Install charproc accumulator for a Type 3 font. */
1282
 
int pdf_set_charproc_attrs(gx_device_pdf *pdev, gs_font *font, double *pw, int narg,
1283
 
                gs_text_cache_control_t control, gs_char ch, bool scale_100);
1284
 
/* Complete charproc accumulation for aType 3 font. */
1285
 
int pdf_end_charproc_accum(gx_device_pdf *pdev, gs_font *font, const pdf_char_glyph_pairs_t *cgp,
1286
 
                       gs_glyph glyph, gs_char output_char_code, const gs_const_string *gnstr);
1287
 
/* Open a stream object in the temporary file. */
1288
 
int pdf_open_aside(gx_device_pdf *pdev, pdf_resource_type_t rtype,
1289
 
        gs_id id, pdf_resource_t **ppres, bool reserve_object_id, int options);
1290
 
 
1291
 
/* Close a stream object in the temporary file. */
1292
 
int pdf_close_aside(gx_device_pdf *pdev);
1293
 
 
1294
 
/* Enter the substream accumulation mode. */
1295
 
int pdf_enter_substream(gx_device_pdf *pdev, pdf_resource_type_t rtype,
1296
 
                gs_id id, pdf_resource_t **ppres, bool reserve_object_id, bool compress);
1297
 
 
1298
 
/* Exit the substream accumulation mode. */
1299
 
int pdf_exit_substream(gx_device_pdf *pdev);
1300
 
/* Add procsets to substream Resources. */
1301
 
int pdf_add_procsets(cos_dict_t *pcd, pdf_procset_t procsets);
1302
 
/* Add a resource to substream Resources. */
1303
 
int pdf_add_resource(gx_device_pdf *pdev, cos_dict_t *pcd, const char *key, pdf_resource_t *pres);
1304
 
 
1305
 
/* For gdevpdfu.c */
1306
 
 
1307
 
int pdf_from_stream_to_text(gx_device_pdf *pdev);
1308
 
int pdf_from_string_to_text(gx_device_pdf *pdev);
1309
 
void pdf_close_text_contents(gx_device_pdf *pdev);
1310
 
 
1311
 
#endif /* gdevpdfx_INCLUDED */