Coverage Report

Created: 2022-10-31 07:00

/src/ghostpdl/devices/vector/gdevpdfx.h
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2022 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,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
13
   CA 94945, U.S.A., +1(415)492-9861, for further information.
14
*/
15
16
17
/* Internal definitions for PDF-writing driver. */
18
19
#ifndef gdevpdfx_INCLUDED
20
#  define gdevpdfx_INCLUDED
21
22
#include "gsparam.h"
23
#include "gsuid.h"
24
#include "gxdevice.h"
25
#include "gxfont.h"
26
#include "gxline.h"
27
#include "stream.h"
28
#include "spprint.h"
29
#include "gdevpsdf.h"
30
#include "gxdevmem.h"
31
#include "sarc4.h"
32
#include "gsfunc.h"
33
34
#define FINE_GLYPH_USAGE 1 /* Old code = 0, new code = 1 */
35
36
/* ---------------- Acrobat limitations ---------------- */
37
38
/*
39
 * The PDF reference manual, 2nd ed., claims that the limit for coordinates
40
 * is +/- 32767. However, testing indicates that Acrobat Reader 4 for
41
 * Windows and Linux fail with coordinates outside +/- 16383. Hence, we
42
 * limit coordinates to 16k, with a little slop.
43
 */
44
/* 28/05/2020 This was only being applied to text and a subset of paths. Since
45
 * Acrobat 4 is now more than 20 years old, lets just drop support for it. The
46
 * PDF specification never had this limit, just Adobe's software.
47
 */
48
/* 31/05/2021 However, it transpires that the PDF/A-1 specification adopted the
49
 * implementation limits of Acrobat 5 as part of the specification. So we need
50
 * to handle that, but we don't need to limit ourselves to the more restrictive
51
 * Acrobat 4 limit of 16384 ( MAX_USER_COORD 16300), we can use 32767. THis is only
52
 * used when creating PDF/A-1 files.
53
 */
54
19.0M
#define MAX_USER_COORD 32700
55
56
/* ---------------- Statically allocated sizes ---------------- */
57
/* These should really be dynamic.... */
58
59
/* Define the maximum depth of an outline tree. */
60
/* Note that there is no limit on the breadth of the tree. */
61
32.1k
#define INITIAL_MAX_OUTLINE_DEPTH 32
62
63
/* Define the maximum size of a destination array string. */
64
14.2k
#define MAX_DEST_STRING 80
65
66
/* ================ Types and structures ================ */
67
68
typedef struct pdf_base_font_s pdf_base_font_t;
69
70
/* Define the possible contexts for the output stream. */
71
typedef enum {
72
    PDF_IN_NONE,
73
    PDF_IN_STREAM,
74
    PDF_IN_TEXT,
75
    PDF_IN_STRING
76
} pdf_context_t;
77
78
/* ---------------- Cos objects ---------------- */
79
80
/*
81
 * These are abstract types for cos objects.  The concrete types are in
82
 * gdevpdfo.h.
83
 */
84
typedef struct cos_object_s cos_object_t;
85
typedef struct cos_stream_s cos_stream_t;
86
typedef struct cos_dict_s cos_dict_t;
87
typedef struct cos_array_s cos_array_t;
88
typedef struct cos_value_s cos_value_t;
89
typedef struct cos_object_procs_s cos_object_procs_t;
90
typedef const cos_object_procs_t *cos_type_t;
91
#define cos_types_DEFINED
92
93
typedef struct pdf_text_state_s pdf_text_state_t;
94
95
typedef struct pdf_char_glyph_pairs_s pdf_char_glyph_pairs_t;
96
97
/* ---------------- Resources ---------------- */
98
99
typedef enum {
100
    /*
101
     * Standard PDF resources.  Font must be last, because resources
102
     * up to but not including Font are written page-by-page.
103
     */
104
    resourceColorSpace,
105
    resourceExtGState,
106
    resourcePattern,
107
    resourceShading,
108
    resourceXObject,
109
    resourceProperties,
110
    resourceOther, /* Anything else that needs to be stored for a time.
111
                    * Can be any of the types defined below NUM_RESOURCE_TYPES
112
                    * but this is the type used to identify the object.
113
                    */
114
    resourceFont,
115
    /*
116
     * Internally used (pseudo-)resources.
117
     */
118
    resourceCharProc,
119
    resourceCIDFont,
120
    resourceCMap,
121
    resourceFontDescriptor,
122
    resourceGroup,
123
    resourceSoftMaskDict,
124
    resourceFunction,
125
    resourcePage,
126
    NUM_RESOURCE_TYPES,
127
    /* These resource types were 'resourceOther', but we want to track them
128
     * for ps2write. They are not stored in the pdf device structure, unlike
129
     * the reource types above.
130
     */
131
    resourceEncoding,
132
    resourceCIDSystemInfo,
133
    resourceHalftone,
134
    resourceLength,
135
    resourceStream,
136
    resourceOutline,
137
    resourceArticle,
138
    resourceDests,
139
    resourceLabels,
140
    resourceThread,
141
    resourceCatalog,
142
    resourceEncrypt,
143
    resourcePagesTree,
144
    resourceMetadata,
145
    resourceICC,
146
    resourceAnnotation,
147
    resourceEmbeddedFiles,
148
    resourceFontFile,
149
    resourceNone        /* Special, used when this isn't a resource at all
150
                         * eg when we execute a resource we've just written, such as
151
                         * a Pattern.
152
                         */
153
} pdf_resource_type_t;
154
155
#define PDF_RESOURCE_TYPE_NAMES\
156
0
  "/ColorSpace", "/ExtGState", "/Pattern", "/Shading", "/XObject", "/Properties", 0, "/Font",\
157
0
  0, "/Font", "/CMap", "/FontDescriptor", "/Group", "/Mask", 0, 0, 0, 0, 0,\
158
0
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
159
#define PDF_RESOURCE_TYPE_STRUCTS\
160
  &st_pdf_color_space,                /* gdevpdfg.h / gdevpdfc.c */\
161
  &st_pdf_resource,                /* see below */\
162
  &st_pdf_pattern,\
163
  &st_pdf_resource,\
164
  &st_pdf_x_object,                /* see below */\
165
  &st_pdf_resource,\
166
  &st_pdf_resource,\
167
  &st_pdf_font_resource,        /* gdevpdff.h / gdevpdff.c */\
168
  &st_pdf_char_proc,                /* gdevpdff.h / gdevpdff.c */\
169
  &st_pdf_font_resource,        /* gdevpdff.h / gdevpdff.c */\
170
  &st_pdf_resource,\
171
  &st_pdf_font_descriptor,        /* gdevpdff.h / gdevpdff.c */\
172
  &st_pdf_resource,\
173
  &st_pdf_resource,\
174
  &st_pdf_resource,\
175
  &st_pdf_resource
176
177
/*
178
 * rname is currently R<id> for all resources other than synthesized fonts;
179
 * for synthesized fonts, rname is A, B, ....  The string is null-terminated.
180
 */
181
182
    /* WARNING WILL ROBINSON!
183
     * these 2 pointers may *look* like a double linked list but in fact these are pointers
184
     * to two *different* single-linked lists. 'next' points to the next resource
185
     * of this type, which is stored in the resource chains pointed to by the array
186
     * 'resources' in the device structure. 'prev' is a pointer
187
     * to the list of stored resources of all types, pointed to by the
188
     * 'last_resource' member of the device structure.
189
     */
190
#define pdf_resource_common(typ)\
191
    typ *next;                        /* next resource of this type */\
192
    pdf_resource_t *prev;        /* previously allocated resource */\
193
    gs_id rid;                        /* optional ID key */\
194
    bool named;\
195
    bool global;                /* ps2write only */\
196
    char rname[1/*R*/ + (sizeof(long) * 8 / 3 + 1) + 1/*\0*/];\
197
    ulong where_used;                /* 1 bit per level of content stream */\
198
    cos_object_t *object
199
typedef struct pdf_resource_s pdf_resource_t;
200
struct pdf_resource_s {
201
    pdf_resource_common(pdf_resource_t);
202
};
203
204
/* The descriptor is public for subclassing. */
205
extern_st(st_pdf_resource);
206
#define public_st_pdf_resource()  /* in gdevpdfu.c */\
207
  gs_public_st_ptrs3(st_pdf_resource, pdf_resource_t, "pdf_resource_t",\
208
    pdf_resource_enum_ptrs, pdf_resource_reloc_ptrs, next, prev, object)
209
210
/*
211
 * We define XObject resources here because they are used for Image,
212
 * Form, and PS XObjects, which are implemented in different files.
213
 */
214
typedef struct pdf_x_object_s pdf_x_object_t;
215
struct pdf_x_object_s {
216
    pdf_resource_common(pdf_x_object_t);
217
    int width, height;                /* specified width and height for images */
218
    int data_height;                /* actual data height for images */
219
};
220
#define private_st_pdf_x_object()  /* in gdevpdfu.c */\
221
  gs_private_st_suffix_add0(st_pdf_x_object, pdf_x_object_t,\
222
    "pdf_x_object_t", pdf_x_object_enum_ptrs, pdf_x_object_reloc_ptrs,\
223
    st_pdf_resource)
224
225
/* Define the mask for which procsets have been used on a page. */
226
typedef enum {
227
    NoMarks = 0,
228
    ImageB = 1,
229
    ImageC = 2,
230
    ImageI = 4,
231
    Text = 8
232
} pdf_procset_t;
233
234
/* ------ Fonts ------ */
235
236
/* Define abstract types. */
237
typedef struct pdf_char_proc_s pdf_char_proc_t;        /* gdevpdff.h */
238
typedef struct pdf_char_proc_ownership_s pdf_char_proc_ownership_t;        /* gdevpdff.h */
239
typedef struct pdf_font_s pdf_font_t;  /* gdevpdff.h */
240
typedef struct pdf_text_data_s pdf_text_data_t;  /* gdevpdft.h */
241
242
/* ---------------- Other auxiliary structures ---------------- */
243
244
/* Outline nodes and levels */
245
typedef struct pdf_outline_node_s {
246
    long id, parent_id, prev_id, first_id, last_id;
247
    int count;
248
    cos_dict_t *action;
249
} pdf_outline_node_t;
250
typedef struct pdf_outline_level_s {
251
    pdf_outline_node_t first;
252
    pdf_outline_node_t last;
253
    int left;
254
} pdf_outline_level_t;
255
/*
256
 * The GC descriptor is implicit, since outline levels occur only in an
257
 * embedded array in the gx_device_pdf structure.
258
 */
259
260
/* Articles */
261
typedef struct pdf_bead_s {
262
    long id, article_id, prev_id, next_id, page_id;
263
    gs_rect rect;
264
} pdf_bead_t;
265
typedef struct pdf_article_s pdf_article_t;
266
struct pdf_article_s {
267
    pdf_article_t *next;
268
    cos_dict_t *contents;
269
    pdf_bead_t first;
270
    pdf_bead_t last;
271
};
272
273
#define private_st_pdf_article()\
274
  gs_private_st_ptrs2(st_pdf_article, pdf_article_t,\
275
    "pdf_article_t", pdf_article_enum_ptrs, pdf_article_reloc_ptrs,\
276
    next, contents)
277
278
/* ---------------- The device structure ---------------- */
279
280
/* Resource lists */
281
/* We seem to split the resources up into 'NUM_RESOURCE_CHAINS' linked
282
 * lists purely as a performance boost. Presumably it save searching very
283
 * long lists.
284
 */
285
141M
#define NUM_RESOURCE_CHAINS 16
286
typedef struct pdf_resource_list_s {
287
    pdf_resource_t *chains[NUM_RESOURCE_CHAINS];
288
} pdf_resource_list_t;
289
290
/* Define the hash function for gs_ids. */
291
759k
#define gs_id_hash(rid) ((rid) + ((rid) / NUM_RESOURCE_CHAINS))
292
/* Define the accessor for the proper hash chain. */
293
#define PDF_RESOURCE_CHAIN(pdev, type, rid)\
294
699k
  (&(pdev)->resources[type].chains[gs_id_hash(rid) % NUM_RESOURCE_CHAINS])
295
296
/* Define the bookkeeping for an open stream. */
297
typedef struct pdf_stream_position_s {
298
    long length_id;
299
    gs_offset_t start_pos;
300
} pdf_stream_position_t;
301
302
/*
303
 * Define the structure for keeping track of text rotation.
304
 * There is one for the current page (for AutoRotate /PageByPage)
305
 * and one for the whole document (for AutoRotate /All).
306
 */
307
typedef struct pdf_text_rotation_s {
308
    long counts[5];                /* 0, 90, 180, 270, other */
309
    int Rotate;                        /* computed rotation, -1 means none */
310
} pdf_text_rotation_t;
311
24.7k
#define pdf_text_rotation_angle_values 0, 90, 180, 270, -1
312
313
/*
314
 * Define document and page information derived from DSC comments.
315
 */
316
typedef struct pdf_page_dsc_info_s {
317
    int orientation;                /* -1 .. 3 */
318
    int viewing_orientation;        /* -1 .. 3 */
319
    gs_rect bounding_box;
320
} pdf_page_dsc_info_t;
321
322
/*
323
 * Define the stored information for a page.  Because pdfmarks may add
324
 * information to any page anywhere in the document, we have to wait
325
 * until the end to write the page dictionaries.
326
 */
327
typedef struct pdf_page_s {
328
    cos_dict_t *Page;
329
    gs_point MediaBox;
330
    pdf_procset_t procsets;
331
    long contents_id;
332
    long resource_ids[resourceFont + 1]; /* resources thru Font, see above */
333
    long group_id;
334
    cos_array_t *Annots;
335
    pdf_text_rotation_t text_rotation;
336
    pdf_page_dsc_info_t dsc_info;
337
    bool NumCopies_set; /* ps2write only. */
338
    int NumCopies;      /* ps2write only. */
339
    float UserUnit;     /* pdfwrite only */
340
} pdf_page_t;
341
#define private_st_pdf_page()        /* in gdevpdf.c */\
342
  gs_private_st_ptrs2(st_pdf_page, pdf_page_t, "pdf_page_t",\
343
    pdf_page_enum_ptrs, pdf_page_reloc_ptrs, Page, Annots)
344
345
/*
346
 * Define the structure for the temporary files used while writing.
347
 * There are 4 of these, described below.
348
 */
349
typedef struct pdf_temp_file_s {
350
    char file_name[gp_file_name_sizeof];
351
    gp_file *file;
352
    stream *strm;
353
    byte *strm_buf;
354
    stream *save_strm;                /* save pdev->strm while writing here */
355
} pdf_temp_file_t;
356
357
typedef struct gx_device_pdf_s gx_device_pdf;
358
359
/* Structures and definitions for linearisation */
360
typedef struct linearisation_record_s {
361
    int PageUsage;
362
    int NumPagesUsing;
363
    int *PageList;
364
    uint NewObjectNumber;
365
    gs_offset_t OriginalOffset;
366
    gs_offset_t LinearisedOffset;
367
    gs_offset_t Length;
368
} pdf_linearisation_record_t;
369
370
#define private_st_pdf_linearisation_record()\
371
  gs_private_st_ptrs1(st_pdf_linearisation_record, pdf_linearisation_record_t,\
372
    "pdf_linearisation_record_t", pdf_linearisation_record_enum_ptrs, pdf_linearisation_record_reloc_ptrs,\
373
    PageList)
374
375
typedef struct page_hint_stream_header_s {
376
    unsigned int LeastObjectsPerPage;    /* Including the page object */
377
    /* Item 2 is already stored elsewhere */
378
    unsigned int MostObjectsPerPage;
379
    unsigned short ObjectNumBits;
380
    unsigned int LeastPageLength;        /* From beginning of page object to end of last object used by page */
381
    unsigned int MostPageLength;
382
    unsigned short PageLengthNumBits;
383
    unsigned int LeastPageOffset;
384
    unsigned int MostPageOffset;
385
    unsigned short PageOffsetNumBits;
386
    unsigned int LeastContentLength;
387
    unsigned int MostContentLength;
388
    unsigned short ContentLengthNumBits;
389
    unsigned int MostSharedObjects;
390
    unsigned int LargestSharedObject;
391
    unsigned short SharedObjectNumBits;
392
} page_hint_stream_header_t;
393
394
typedef struct page_hint_stream_s {
395
    unsigned int NumUniqueObjects; /* biased by the least number of objects on any page */
396
    unsigned int PageLength;       /* biased by the least page length*/
397
    unsigned int NumSharedObjects;
398
    unsigned int *SharedObjectRef; /* one for each shaed object on the page */
399
    /* Item 5 we invent */
400
    gs_offset_t ContentOffset; /* biased by the least offset to the conent stream for any page */
401
    gs_offset_t ContentLength;/* biased by the least content stream length */
402
} page_hint_stream_t;
403
404
typedef struct shared_hint_stream_header_s {
405
    unsigned int FirstSharedObject;
406
    gs_offset_t FirstObjectOffset;
407
    unsigned int FirstPageEntries;
408
    unsigned int NumSharedObjects;
409
    /* Item 5 is always 1 as far as we are concerned */
410
    unsigned int LeastObjectLength;
411
    unsigned int MostObjectLength;
412
    unsigned short LengthNumBits;
413
} shared_hint_stream_header_t;
414
415
typedef struct share_hint_stream_s {
416
    unsigned int ObjectNumber;
417
    gs_offset_t ObjectOffset;
418
    unsigned int ObjectLength;   /* biased by the LeastObjectLength */
419
    /* item 2 is always 0 */
420
    /* Which means that item 3 is never present */
421
    /* Finally item 4 is always 0 (1 less than the number of objects in the group, which is always 1) */
422
} shared_hint_stream_t;
423
424
typedef struct pdf_linearisation_s {
425
    gp_file *sfile;
426
    pdf_temp_file_t Lin_File;
427
    char HintBuffer[256];
428
    unsigned char HintBits;
429
    unsigned char HintByte;
430
    long Catalog_id;
431
    long Info_id;
432
    long Pages_id;
433
    long NumPage1Resources;
434
    long NumPart1StructureResources;
435
    long NumSharedResources;
436
    long NumUniquePageResources;
437
    long NumPart9Resources;
438
    long NumNonPageResources;
439
    long LastResource;
440
    long MainFileEnd;
441
    gs_offset_t *Offsets;
442
    gs_offset_t xref;
443
    gs_offset_t FirstxrefOffset;
444
    gs_offset_t FirsttrailerOffset;
445
    gs_offset_t LDictOffset;
446
    gs_offset_t FileLength;
447
    gs_offset_t T;
448
    gs_offset_t E;
449
    page_hint_stream_header_t PageHintHeader;
450
    int NumPageHints;
451
    page_hint_stream_t *PageHints;
452
    shared_hint_stream_header_t SharedHintHeader;
453
    int NumSharedHints;
454
    shared_hint_stream_t *SharedHints;
455
} pdf_linearisation_t;
456
457
/* These are the values for 'PageUsage' above, values > 0 indicate the page number that uses the resource */
458
0
#define resource_usage_not_referenced 0
459
0
#define resource_usage_page_shared -1
460
/* Thses need to be lower than the shared value */
461
11.2k
#define resource_usage_part1_structure -2
462
33.7k
#define resource_usage_part9_structure -3
463
#define resource_usage_written -4
464
465
/*
466
 * Define the structure for PDF font cache element.
467
 */
468
typedef struct pdf_font_cache_elem_s pdf_font_cache_elem_t;
469
struct pdf_font_cache_elem_s {
470
    pdf_font_cache_elem_t *next;
471
    gs_id font_id;
472
    int num_chars;                /* safety purpose only */
473
    int num_widths;                /* safety purpose only */
474
    struct pdf_font_resource_s *pdfont;
475
    byte *glyph_usage;
476
    double *real_widths;        /* [count] (not used for Type 0) */
477
};
478
479
#define private_st_pdf_font_cache_elem()\
480
    gs_private_st_ptrs4(st_pdf_font_cache_elem, pdf_font_cache_elem_t,\
481
        "pdf_font_cache_elem_t", pdf_font_cache_elem_enum,\
482
        pdf_font_cache_elem_reloc, next, pdfont,\
483
        glyph_usage, real_widths)
484
485
/*
486
 * pdf_viewer_state tracks the graphic state of a viewer,
487
 * which would interpret the generated PDF file
488
 * immediately when it is generated.
489
 */
490
typedef struct pdf_viewer_state_s {
491
    int transfer_not_identity;        /* bitmask */
492
    gs_id transfer_ids[4];
493
    float strokeconstantalpha;
494
    float fillconstantalpha;
495
    bool alphaisshape;
496
    gs_blend_mode_t blend_mode; /* state.blend_mode */
497
    gs_id halftone_id;
498
    gs_id black_generation_id;
499
    gs_id undercolor_removal_id;
500
    int overprint_mode;
501
    float smoothness; /* state.smoothness */
502
    float flatness;
503
    bool text_knockout; /* state.text_knockout */
504
    bool fill_overprint;
505
    bool stroke_overprint;
506
    bool stroke_adjust; /* state.stroke_adjust */
507
    bool fill_used_process_color;
508
    bool stroke_used_process_color;
509
    gx_hl_saved_color saved_fill_color;
510
    gx_hl_saved_color saved_stroke_color;
511
    gx_line_params line_params;
512
    float *dash_pattern;
513
    uint dash_pattern_size;
514
    gs_id soft_mask_id;
515
} pdf_viewer_state;
516
517
/*
518
 * Define a structure for saving context when entering
519
 * a contents stream accumulation mode (charproc, Type 1 pattern).
520
 */
521
typedef struct pdf_substream_save_s {
522
    pdf_context_t        context;
523
    pdf_text_state_t        *text_state;
524
    gx_path                *clip_path;
525
    gs_id                clip_path_id;
526
    int                        vgstack_bottom;
527
    stream                *strm;
528
    cos_dict_t                *substream_Resources;
529
    pdf_procset_t        procsets;
530
    bool                skip_colors;
531
    pdf_resource_t      *font3;
532
    pdf_resource_t        *accumulating_substream_resource;
533
    bool                charproc_just_accumulated;
534
    bool                accumulating_a_global_object;
535
    pdf_resource_t      *pres_soft_mask_dict;
536
    gs_const_string                objname;
537
    int                        last_charpath_op;
538
} pdf_substream_save;
539
540
#define private_st_pdf_substream_save()\
541
    gs_private_st_strings1_ptrs7(st_pdf_substream_save, pdf_substream_save,\
542
        "pdf_substream_save", pdf_substream_save_enum,\
543
        pdf_substream_save_reloc, objname, text_state, clip_path, strm, \
544
        substream_Resources, font3, accumulating_substream_resource, pres_soft_mask_dict)
545
#define private_st_pdf_substream_save_element()\
546
  gs_private_st_element(st_pdf_substream_save_element, pdf_substream_save,\
547
    "pdf_substream_save[]", pdf_substream_save_elt_enum_ptrs,\
548
    pdf_substream_save_elt_reloc_ptrs, st_pdf_substream_save)
549
550
typedef enum {
551
    pdf_compress_none,
552
    pdf_compress_LZW,        /* not currently used, thanks to Unisys */
553
    pdf_compress_Flate
554
} pdf_compression_type;
555
556
typedef enum {
557
    OCR_UnInit,
558
    OCR_Rendering,
559
    OCR_Rendered,
560
    OCR_UnicodeAvailable,
561
    OCR_Failed
562
} pdf_OCR_stage;
563
564
typedef enum {
565
    UseOCRNever,
566
    UseOCRAsNeeded,
567
    UseOCRAlways
568
} pdf_OCR_usage;
569
570
typedef struct ocr_glyph_s{
571
    byte *data;
572
    int x;
573
    int y;
574
    int width;
575
    int height;
576
    int raster;
577
    void *next;
578
    gs_char char_code;
579
    gs_glyph glyph;
580
    bool is_space;
581
} ocr_glyph_t;
582
583
/* Define the device structure. */
584
struct gx_device_pdf_s {
585
    gx_device_psdf_common;
586
    gs_font_dir *pdf_font_dir;  /* Our own font cache, so that PCL can free its own ones, we set our font copeis to use this */
587
                                /* see 'pdf_free_pdf_font_cache' in gdevpdf.c for more details. */
588
    bool is_ps2write;          /* ps2write (true) versus pdfwrite (false); never changed */
589
    /* PDF-specific distiller parameters */
590
    double CompatibilityLevel;
591
    int EndPage;
592
    int StartPage;
593
    bool Optimize;
594
    bool ParseDSCCommentsForDocInfo;
595
    bool ParseDSCComments;
596
    bool EmitDSCWarnings;
597
    bool CreateJobTicket;
598
    bool PreserveEPSInfo;
599
    bool AutoPositionEPSFiles;
600
    bool PreserveCopyPage;
601
    bool UsePrologue;
602
    int OffOptimizations;
603
    /* End of distiller parameters */
604
    /* PDF/X parameters */
605
    gs_param_float_array PDFXTrimBoxToMediaBoxOffset;
606
    gs_param_float_array PDFXBleedBoxToTrimBoxOffset;
607
    bool PDFXSetBleedBoxToMediaBox;
608
    /* OCR Parameters */
609
    char ocr_language[1024];
610
    int ocr_engine;
611
    /* Other parameters */
612
    bool ReAssignCharacters;
613
    bool ReEncodeCharacters;
614
    long FirstObjectNumber;
615
    bool CompressFonts;
616
    bool CompressStreams;
617
    bool PrintStatistics;
618
    gs_param_string DocumentUUID;
619
    gs_param_string InstanceUUID;
620
    int DocumentTimeSeq;
621
    bool ForOPDFRead;          /* PS2WRITE only. */
622
    bool Eps2Write;            /* EPS2WRITE only */
623
    bool CompressEntireFile;  /* PS2WRITE only. */
624
    bool ResourcesBeforeUsage; /* PS2WRITE only. */
625
    bool HavePDFWidths;        /* PS2WRITE only. */
626
    bool HaveStrokeColor;      /* PS2WRITE only. */
627
    bool ProduceDSC;               /* PS2WRITE only. */
628
    bool HaveTransparency;
629
    bool PatternImagemask; /* The target viewer|printer handles imagemask
630
                              with pattern color. */
631
    bool PDFX;                   /* Generate PDF/X */
632
    int PDFA;                   /* Generate PDF/A 0 = don't produce, otherwise level of PDF/A */
633
    bool AbortPDFAX;            /* Abort generation of PDFA or X, produce regular PDF */
634
    long MaxClipPathSize;  /* The maximal number of elements of a clipping path
635
                              that the target viewer|printer can handle. */
636
    long MaxShadingBitmapSize; /* The maximal number of bytes in
637
                              a bitmap representation of a shading.
638
                              (Bigger shadings to be downsampled). */
639
    long MaxInlineImageSize;
640
    /* Encryption parameters */
641
    gs_param_string OwnerPassword;
642
    gs_param_string UserPassword;
643
    uint KeyLength;
644
    int32_t Permissions;
645
    uint EncryptionR;
646
    gs_param_string NoEncrypt;
647
    bool EncryptMetadata;
648
    /* End of parameters */
649
    bool ComputeDocumentDigest; /* Developer needs only; Always true in production. */
650
    /* Encryption data */
651
    byte EncryptionO[32];
652
    byte EncryptionU[32];
653
    byte EncryptionKey[16];
654
    uint EncryptionV;
655
    /* Values derived from DSC comments */
656
    bool is_EPS;
657
    int AccumulatingBBox;
658
    gs_rect BBox;
659
    pdf_page_dsc_info_t doc_dsc_info; /* document default */
660
    pdf_page_dsc_info_t page_dsc_info; /* current page */
661
    /* Additional graphics state */
662
    bool fill_overprint, stroke_overprint;
663
    int rendering_intent;
664
    bool remap_fill_color, remap_stroke_color;
665
    gs_id halftone_id;
666
    gs_id transfer_ids[4];
667
    int transfer_not_identity;        /* bitmask */
668
    gs_id black_generation_id, undercolor_removal_id;
669
    /* Following are set when device is opened. */
670
    pdf_compression_type compression;
671
    pdf_compression_type compression_at_page_start;
672
    /* pdf_memory is 'stable' memory, it is not subject to save and restore
673
     * and is the allocator which should be used for pretty much ewverything
674
     */
675
2.67M
#define pdf_memory v_memory
676
    /*
677
     * The xref temporary file is logically an array of longs.
678
     * xref[id - FirstObjectNumber] is the position in the output file
679
     * of the object with the given id.
680
     *
681
     * Note that xref, unlike the other temporary files, does not have
682
     * an associated stream or stream buffer.
683
     */
684
    pdf_temp_file_t xref;
685
    /*
686
     * asides holds resources and other "aside" objects.  It is
687
     * copied verbatim to the output file at the end of the document.
688
     */
689
    pdf_temp_file_t asides;
690
    /*
691
     * streams holds data for stream-type Cos objects.  The data is
692
     * copied to the output file at the end of the document.
693
     *
694
     * Note that streams.save_strm is not used, since we don't interrupt
695
     * normal output when saving stream data.
696
     */
697
    pdf_temp_file_t streams;
698
    /*
699
     * pictures holds graphic objects being accumulated between BP and EP.
700
     * The object is moved to streams when the EP is reached: since BP and
701
     * EP nest, we delete the object from the pictures file at that time.
702
     */
703
    pdf_temp_file_t pictures;
704
    /* ................ */
705
    long next_id;
706
    /* The following 3 objects, and only these, are allocated */
707
    /* when the file is opened. */
708
    cos_dict_t *Catalog;
709
    cos_dict_t *Info;
710
    cos_dict_t *Pages;
711
0
#define pdf_num_initial_ids 3
712
    long outlines_id;
713
    int next_page;
714
    int max_referred_page;
715
    long contents_id;
716
    pdf_context_t context;
717
    long contents_length_id;
718
    gs_offset_t contents_pos;
719
    pdf_procset_t procsets;        /* used on this page */
720
    pdf_text_data_t *text;
721
    pdf_text_rotation_t text_rotation;
722
32.1k
#define initial_num_pages 50
723
    pdf_page_t *pages;
724
    int num_pages;
725
    ulong used_mask;                /* for where_used: page level = 1 */
726
    pdf_resource_list_t resources[NUM_RESOURCE_TYPES];
727
    /* cs_Patterns[0] is colored; 1,3,4 are uncolored + Gray,RGB,CMYK */
728
    pdf_resource_t *cs_Patterns[5];
729
    pdf_resource_t *Identity_ToUnicode_CMaps[2]; /* WMode = 0,1 */
730
    pdf_resource_t *last_resource;
731
    pdf_resource_t *OneByteIdentityH;
732
    gs_id IdentityCIDSystemInfo_id;
733
    pdf_outline_level_t *outline_levels;
734
    int outline_depth;
735
    int max_outline_depth;
736
    int closed_outline_depth;
737
    int outlines_open;
738
    pdf_article_t *articles;
739
    cos_dict_t *Dests;
740
    cos_dict_t *EmbeddedFiles;
741
    byte fileID[16];
742
    /* Use a single time moment for all UUIDs to minimize an indeterminizm. */
743
    long uuid_time[2];
744
    /*
745
     * global_named_objects holds named objects that are independent of
746
     * the current namespace: {Catalog}, {DocInfo}, {Page#}, {ThisPage},
747
     * {PrevPage}, {NextPage}.
748
     */
749
    cos_dict_t *global_named_objects;
750
    /*
751
     * local_named_objects holds named objects in the current namespace.
752
     */
753
    cos_dict_t *local_named_objects;
754
    /*
755
     * NI_stack is a last-in, first-out stack in which each element is a
756
     * (named) cos_stream_t object that eventually becomes the object of an
757
     * image XObject resource.
758
     */
759
    cos_array_t *NI_stack;
760
    /*
761
     * Namespace_stack is a last-in, first-out stack in which each pair of
762
     * elements is, respectively, a saved value of local_named_objects and
763
     * a saved value of NI_stack.  (The latter is not documented by Adobe,
764
     * but it was confirmed by them.)
765
     */
766
    cos_array_t *Namespace_stack;
767
    pdf_font_cache_elem_t *font_cache;
768
    /*
769
     * char_width is used by pdf_text_set_cache to communicate
770
     * with assign_char_code around gdev_pdf_fill_mask.
771
     */
772
    gs_point char_width;
773
    /*
774
     * We need a stable copy of clipping path to prevent writing
775
     * redundant clipping paths when PS document generates such ones.
776
     */
777
    gx_path *clip_path;
778
    /*
779
     * Page labels.
780
     */
781
    cos_array_t *PageLabels;
782
    int PageLabels_current_page;
783
    cos_dict_t *PageLabels_current_label;
784
    /*
785
     * The following is a dangerous pointer, which pdf_text_process
786
     * uses to communicate with assign_char_code.
787
     * It is a pointer from global memory to local memory.
788
     * The garbager must not proceess this pointer, and it must
789
     * not be listed in st_device_pdfwrite.
790
     * It's life time terminates on garbager invocation.
791
     */
792
    gs_text_enum_t *pte;
793
    /*
794
     * The viewer's graphic state stack.
795
     */
796
    pdf_viewer_state *vgstack;
797
    int vgstack_size;
798
    int vgstack_depth;
799
    int vgstack_bottom;                 /* Stack bottom for the current substream. */
800
    pdf_viewer_state vg_initial; /* Initial values for viewer's graphic state */
801
    bool vg_initial_set;
802
803
    /* The substream context stack. */
804
    int sbstack_size;
805
    int sbstack_depth;
806
    pdf_substream_save *sbstack;
807
808
    /* Temporary workaround. The only way to get forms out of pdfwrite at present
809
     * is via a transparency group or mask operation. Ordinarily we don't care
810
     * much about forms, but Patterns within forms need to be scaled to the
811
     * CTM of the Pattern, not the default page co-ordinate system. We use
812
     * this value to know if we are nested inside a form or not. If we are
813
     * we don't undo the resolution co-ordinate transform.
814
     */
815
    int FormDepth;
816
817
    /* Determine if we have a high level form. We want to do things differently
818
     * sometimes, if we are capturing a form
819
     */
820
    int HighLevelForm;
821
822
    /* Nasty hack. OPDFread.ps resets the graphics state to the identity before
823
     * replaying the Pattern PaintProc, but if the Pattern is nested inside a
824
     * previous pattern, this doesn't work. We use this to keep track of whether
825
     * we are nested, and if we are (and are ps2write, not pdfwrite) we track the
826
     * pattern CTM below.
827
     */
828
    int PatternDepth;
829
    gs_matrix AccumulatedPatternMatrix;
830
831
    /* Normally the PDF itnerpreter doesn't call execform to pass a From XObject to
832
     * pdfwrite, but it *does* create forms (and increment FormDepth) for transparent
833
     * Groups, which are handled as Form XObjects. Because of the way that Pattterns work,
834
     * the first pattern after a Form uses the Form co-ordinate system, but if the Pattern
835
     * itself uses Patterns, then the nested Pattern needs to use the co-ordinate system
836
     * of the parent Pattern. Unless, of course, we have another Form!
837
     * So essentially we need to know the Pattern depth, since the last form was executed.
838
     * If its 0, then we want to apply the current CTM, if its more than that then we want
839
     * to undo the pdfwrite scaling (see gdevpdfv.c, pdf_store_pattern1_params() at about line
840
     * 239.
841
     */
842
    int PatternsSinceForm;
843
844
    /* Accessories */
845
    cos_dict_t *substream_Resources;     /* Substream resources */
846
    gs_color_space_index pcm_color_info_index; /* Index of the ProcessColorModel space. */
847
    bool skip_colors; /* Skip colors while a pattern/charproc accumulation. */
848
    bool AR4_save_bug; /* See pdf_put_uncolored_pattern */
849
    pdf_resource_t *font3; /* The owner of the accumulated charstring. */
850
    pdf_resource_t *accumulating_substream_resource;
851
    gs_matrix_fixed charproc_ctm;
852
    bool accumulating_charproc;
853
    gs_rect charproc_BBox;
854
    bool charproc_just_accumulated; /* A flag for controlling
855
                        the glyph variation recognition.
856
                        Used only with uncached charprocs. */
857
    bool PS_accumulator; /* A flag to determine whether a given
858
                         accumulator is for a PostScript type 3 font or not. */
859
    bool Scaled_accumulator; /* We scale teh CTM when accumulating type 3 fonts */
860
    bool accumulating_a_global_object; /* ps2write only.
861
                        Accumulating a global object (such as a named Form,
862
                        so that resources used in it must also be global.
863
                        Important for viewers with small memory,
864
                        which drops resources per page. */
865
    const pdf_char_glyph_pairs_t *cgp; /* A temporary pointer
866
                        for pdf_is_same_charproc1.
867
                        Must be NULL when the garbager is invoked,
868
                        because it points from global to local memory. */
869
    int substituted_pattern_count;
870
    int substituted_pattern_drop_page;
871
    /* Temporary data for use_image_as_pattern,
872
       They pass an information about a mask of a masked image,
873
       (which is being converted into a pattern)
874
       between 2 consecutive calls to pdf_image_end_image_data. */
875
    gs_id     image_mask_id;
876
    bool      image_mask_is_SMask;
877
    bool      image_mask_skip; /* A flag for pdf_begin_transparency_mask */
878
    bool      smask_construction; /* True when pdfwrite is constructing a soft mask */
879
    uint      image_with_SMask; /* A flag for pdf_begin_transparency_group. In order to
880
                                 * deal with nested groups we set/test the bit according
881
                                 * to the FormDepth
882
                                 */
883
    gs_matrix converting_image_matrix;
884
    double    image_mask_scale;
885
    /* Temporary data for soft mask form. */
886
    pdf_resource_t *pres_soft_mask_dict;
887
    /* Temporary data for pdfmark_BP. */
888
    gs_const_string objname;
889
    int OPDFRead_procset_length;      /* PS2WRITE only. */
890
    void *find_resource_param; /* WARNING : not visible for garbager. */
891
    int last_charpath_op; /* true or false state of last charpath */
892
    bool type3charpath;
893
    bool SetPageSize;
894
    bool RotatePages;
895
    bool FitPages;
896
    bool CenterPages;
897
    bool DoNumCopies;
898
    bool PreserveSeparation;
899
    bool PreserveDeviceN;
900
    int PDFACompatibilityPolicy;
901
    bool DetectDuplicateImages;
902
    bool AllowIncrementalCFF;
903
    bool WantsToUnicode;
904
    bool PdfmarkCapable;
905
    bool WantsPageLabels;
906
    bool AllowPSRepeatFunctions;
907
    bool IsDistiller;
908
    bool PreserveSMask;
909
    bool PreserveTrMode;
910
    bool NoT3CCITT;                 /* A bug in Brother printers causes CCITTFaxDecode
911
                                     * to fail, especially with small amounts of data.
912
                                     * This parameter is present only to allow
913
                                     * ps2write output to work on those pritners.
914
                                     */
915
    bool Linearise;                 /* Whether to Linearizse the file, the next 2 parameter
916
                                     * are only used if this is true.
917
                                     */
918
    pdf_linearisation_record_t
919
        *ResourceUsage;             /* An array, one per resource defined to date, which
920
                                     * contains either -2 (shared on multiple pages), -1
921
                                     * (structure object, eg catalog), 0 (not used on a page
922
                                     * or the page number. This does limit us to a mere 2^31
923
                                     * pages
924
                                     */
925
    int ResourceUsageSize;          /* Size of the above array, currently */
926
    bool InOutputPage;              /* Used when closing the file, if this is true then we were
927
                                     * called from output_page and should emit a page even if there
928
                                     * are no marks. If false, then we probably were called from
929
                                     * closedevice and, if there are no marks, we should delete
930
                                     * the last file *if* we are emitting one file per page.
931
                                     */
932
    bool FlattenFonts;
933
    int LastFormID;
934
    char *ExtensionMetadata;        /* If present the non-standard pdfmark Extension_Metadata has been
935
                                     * used, the content of ths string is written out as part of the
936
                                     * metadata referenced by the Catalog.
937
                                     */
938
    char *PDFFormName;              /* If present, we are processing (or about to process) a Form XObject
939
                                     * which we wish to handle as a Form XObject, not flatten. Currently
940
                                     * this is only the case for Annotation Appearances. This must be NULL
941
                                     * after the form is processed. The name will be used to create a
942
                                     * local named object which pdfmark can reference.
943
                                     */
944
    stream *PassThroughWriter;      /* A copy of the stream that the image enumerator points to, if we are
945
                                     * doing JPEG pass through we write the JPEG data here, and don't write
946
                                     * anything in the image processing routines.
947
                                     */
948
    float UserUnit;
949
    pdf_OCR_usage UseOCR;           /* Never, AsNeeded or Always */
950
    gs_text_enum_t* OCRSaved;       /* Saved state of the text enumerator before rendering glyph bitmaps for later OCR */
951
    pdf_OCR_stage OCRStage;         /* Used to control a (sort of) state machine when using OCR to get a Unicode value for a glyph */
952
    int *OCRUnicode;                /* Used to pass back the Unicode value from the OCR engine to the text processing */
953
    gs_char OCR_char_code;          /* Passes the current character code from text processing to the image processing code when rendering glyph bitmaps for OCR */
954
    gs_glyph OCR_glyph;             /* Passes the current glyph code from text processing to the image processing code when rendering glyph bitmaps for OCR */
955
    ocr_glyph_t *ocr_glyphs;        /* Records bitmaps and other data from text processing when doing OCR */
956
    gs_gstate **initial_pattern_states;
957
    bool OmitInfoDate;              /* If true, do not emit CreationDate and ModDate in the Infor dictionary and XMP Metadata (must not be true for PDF/X support) */
958
    bool OmitXMP;                   /* If true, do not emit an XMP /Metadata block and do not reference it from the Catalog (must not be true for PDF/A output) */
959
    bool OmitID;                    /* If true, do not emit a /ID array in the trailer dicionary (must not be true for encrypted files or PDF 2.0) */
960
};
961
962
#define is_in_page(pdev)\
963
6.99M
  ((pdev)->contents_id != 0)
964
965
/* Enumerate the individual pointers in a gx_device_pdf.
966
   I disliked this macro and so its been removed, the pointers are
967
   enumerated/relocated in gdevpdf.c now. We still need the gx_device_pdf_num_ptrs
968
   though, so I'm maintaining this comment just to keep track of the number
969
   of pointers.
970
 */
971
/*#define gx_device_pdf_do_ptrs(m)\
972
 m(0,asides.strm) m(1,asides.strm_buf) m(2,asides.save_strm)\
973
 m(3,streams.strm) m(4,streams.strm_buf)\
974
 m(5,pictures.strm) m(6,pictures.strm_buf) m(7,pictures.save_strm)\
975
 m(8,Catalog) m(9,Info) m(10,Pages)\
976
 m(11,text) m(12,pages)\
977
 m(13,cs_Patterns[0])\
978
 m(14,cs_Patterns[1]) m(15,cs_Patterns[3]) m(16,cs_Patterns[4])\
979
 m(17,last_resource)\
980
 m(18,articles) m(19,Dests) m(20,global_named_objects)\
981
 m(21, local_named_objects) m(22,NI_stack) m(23,Namespace_stack)\
982
 m(24,font_cache) m(25,clip_path)\
983
 m(26,PageLabels) m(27,PageLabels_current_label)\
984
 m(28,sbstack) m(29,substream_Resources) m(30,font3)\
985
 m(31,accumulating_substream_resource) \
986
 m(32,pres_soft_mask_dict) m(33,PDFXTrimBoxToMediaBoxOffset.data)\
987
 m(34,PDFXBleedBoxToTrimBoxOffset.data)
988
 m(35,Identity_ToUnicode_CMaps[0]) m(36,Identity_ToUnicode_CMaps[1])\
989
 m(37,vgstack)\
990
 m(38, outline_levels)
991
 m(39, gx_device_pdf, EmbeddedFiles);
992
 m(40, gx_device_pdf, pdf_font_dir);
993
 m(41, gx_device_pdf, Extension_Metadata);*/
994
52.8M
#define gx_device_pdf_num_ptrs 43
995
#define gx_device_pdf_do_param_strings(m)\
996
384k
    m(0, OwnerPassword) m(1, UserPassword) m(2, NoEncrypt)\
997
384k
    m(3, DocumentUUID) m(4, InstanceUUID)
998
52.8M
#define gx_device_pdf_num_param_strings 5
999
#define gx_device_pdf_do_const_strings(m)\
1000
384k
    m(0, objname)
1001
#define gx_device_pdf_num_const_strings 1
1002
1003
#define private_st_device_pdfwrite()        /* in gdevpdf.c */\
1004
  gs_private_st_composite_final(st_device_pdfwrite, gx_device_pdf,\
1005
    "gx_device_pdf", device_pdfwrite_enum_ptrs, device_pdfwrite_reloc_ptrs,\
1006
    device_pdfwrite_finalize)
1007
1008
/* ================ Driver procedures ================ */
1009
1010
    /* In gdevpdfb.c */
1011
dev_proc_copy_mono(gdev_pdf_copy_mono);
1012
dev_proc_copy_color(gdev_pdf_copy_color);
1013
dev_proc_fill_mask(gdev_pdf_fill_mask);
1014
dev_proc_strip_tile_rectangle(gdev_pdf_strip_tile_rectangle);
1015
    /* In gdevpdfd.c */
1016
extern const gx_device_vector_procs pdf_vector_procs;
1017
dev_proc_fill_rectangle(gdev_pdf_fill_rectangle);
1018
dev_proc_fill_path(gdev_pdf_fill_path);
1019
dev_proc_stroke_path(gdev_pdf_stroke_path);
1020
dev_proc_fill_stroke_path(gdev_pdf_fill_stroke_path);
1021
dev_proc_fillpage(gdev_pdf_fillpage);
1022
    /* In gdevpdfi.c */
1023
dev_proc_begin_typed_image(gdev_pdf_begin_typed_image);
1024
    /* In gdevpdfp.c */
1025
dev_proc_get_params(gdev_pdf_get_params);
1026
dev_proc_put_params(gdev_pdf_put_params);
1027
    /* In gdevpdft.c */
1028
dev_proc_text_begin(gdev_pdf_text_begin);
1029
dev_proc_fill_rectangle_hl_color(gdev_pdf_fill_rectangle_hl_color);
1030
    /* In gdevpdfv.c */
1031
dev_proc_include_color_space(gdev_pdf_include_color_space);
1032
    /* In gdevpdft.c */
1033
dev_proc_composite(gdev_pdf_composite);
1034
dev_proc_begin_transparency_group(gdev_pdf_begin_transparency_group);
1035
dev_proc_end_transparency_group(gdev_pdf_end_transparency_group);
1036
dev_proc_begin_transparency_mask(gdev_pdf_begin_transparency_mask);
1037
dev_proc_end_transparency_mask(gdev_pdf_end_transparency_mask);
1038
dev_proc_dev_spec_op(gdev_pdf_dev_spec_op);
1039
1040
/* ================ Utility procedures ================ */
1041
1042
/* ---------------- Exported by gdevpdf.c ---------------- */
1043
1044
/* Initialize the IDs allocated at startup. */
1045
void pdf_initialize_ids(gx_device_pdf * pdev);
1046
1047
/* Update the color mapping procedures after setting ProcessColorModel. */
1048
void pdf_set_process_color_model(gx_device_pdf * pdev, int index);
1049
1050
/* Reset the text state parameters to initial values. */
1051
void pdf_reset_text(gx_device_pdf *pdev);
1052
1053
/* ---------------- Exported by gdevpdfu.c ---------------- */
1054
1055
/* ------ Document ------ */
1056
1057
/* Utility functions to write args into the file as comments */
1058
int pdfwrite_fwrite_args_comment(gx_device_pdf *pdev, gp_file *f);
1059
int pdfwrite_write_args_comment(gx_device_pdf *pdev, stream *s);
1060
1061
/* Write a DSC compliant header to the file */
1062
int ps2write_dsc_header(gx_device_pdf * pdev, int pages);
1063
1064
/* Open the document if necessary. */
1065
int pdfwrite_pdf_open_document(gx_device_pdf * pdev);
1066
1067
/* ------ Objects ------ */
1068
1069
/* Allocate an ID for a future object, set its pos=0 so we can tell if it is used */
1070
long pdf_obj_forward_ref(gx_device_pdf * pdev);
1071
1072
/* Allocate an ID for a future object. */
1073
long pdf_obj_ref(gx_device_pdf * pdev);
1074
1075
/* Remove an object from the xref table (mark as unused) */
1076
long pdf_obj_mark_unused(gx_device_pdf *pdev, long id);
1077
1078
/* Read the current position in the output stream. */
1079
gs_offset_t pdf_stell(gx_device_pdf * pdev);
1080
1081
/* Begin an object, optionally allocating an ID. */
1082
long pdf_open_obj(gx_device_pdf * pdev, long id, pdf_resource_type_t type);
1083
long pdf_begin_obj(gx_device_pdf * pdev, pdf_resource_type_t type);
1084
1085
/* End an object. */
1086
int pdf_end_obj(gx_device_pdf * pdev, pdf_resource_type_t type);
1087
1088
/* ------ Page contents ------ */
1089
1090
/* Open a page contents part. */
1091
/* Return an error if the page has too many contents parts. */
1092
int pdf_open_contents(gx_device_pdf * pdev, pdf_context_t context);
1093
1094
/* Close the current contents part if we are in one. */
1095
int pdf_close_contents(gx_device_pdf * pdev, bool last);
1096
1097
/* ------ Resources et al ------ */
1098
1099
extern const char *const pdf_resource_type_names[];
1100
extern const gs_memory_struct_type_t *const pdf_resource_type_structs[];
1101
1102
/* Record usage of resoruces by pages */
1103
int pdf_record_usage(gx_device_pdf *const pdev, long resource_id, int page_num);
1104
int pdf_record_usage_by_parent(gx_device_pdf *const pdev, long resource_id, long parent);
1105
1106
/*
1107
 * Define the offset that indicates that a file position is in the
1108
 * asides file rather than the main (contents) file.
1109
 * Must be a power of 2, and larger than the largest possible output file.
1110
 */
1111
983k
#define ASIDES_BASE_POSITION min_int64_t
1112
1113
/* Begin an object logically separate from the contents. */
1114
/* (I.e., an object in the resource file.) */
1115
long pdf_open_separate(gx_device_pdf * pdev, long id, pdf_resource_type_t type);
1116
long pdf_begin_separate(gx_device_pdf * pdev, pdf_resource_type_t type);
1117
1118
/* Reserve object id. */
1119
void pdf_reserve_object_id(gx_device_pdf * pdev, pdf_resource_t *ppres, long id);
1120
1121
/* Begin an aside (resource, annotation, ...). */
1122
int pdf_alloc_aside(gx_device_pdf * pdev, pdf_resource_t ** plist,
1123
                const gs_memory_struct_type_t * pst, pdf_resource_t **ppres,
1124
                long id);
1125
/* Begin an aside (resource, annotation, ...). */
1126
int pdf_begin_aside(gx_device_pdf * pdev, pdf_resource_t **plist,
1127
                    const gs_memory_struct_type_t * pst,
1128
                    pdf_resource_t **ppres, pdf_resource_type_t type);
1129
1130
/* Begin a resource of a given type. */
1131
int pdf_begin_resource(gx_device_pdf * pdev, pdf_resource_type_t rtype,
1132
                       gs_id rid, pdf_resource_t **ppres);
1133
1134
/* Begin a resource body of a given type. */
1135
int pdf_begin_resource_body(gx_device_pdf * pdev, pdf_resource_type_t rtype,
1136
                            gs_id rid, pdf_resource_t **ppres);
1137
1138
/* Allocate a resource, but don't open the stream. */
1139
int pdf_alloc_resource(gx_device_pdf * pdev, pdf_resource_type_t rtype,
1140
                       gs_id rid, pdf_resource_t **ppres, long id);
1141
1142
/* Find same resource. */
1143
int pdf_find_same_resource(gx_device_pdf * pdev,
1144
        pdf_resource_type_t rtype, pdf_resource_t **ppres,
1145
        int (*eq)(gx_device_pdf * pdev, pdf_resource_t *pres0, pdf_resource_t *pres1));
1146
1147
/* Find resource by resource id. */
1148
pdf_resource_t *pdf_find_resource_by_resource_id(gx_device_pdf * pdev,
1149
                                                pdf_resource_type_t rtype, gs_id id);
1150
1151
/* Find a resource of a given type by gs_id. */
1152
pdf_resource_t *pdf_find_resource_by_gs_id(gx_device_pdf * pdev,
1153
                                           pdf_resource_type_t rtype,
1154
                                           gs_id rid);
1155
1156
/* Remove a resource from a chain of resources but do not free it. The resource will
1157
 * have to be listed elsewhere. This is primarily useful for moving existing resources
1158
 * to local named resources.
1159
 */
1160
void
1161
pdf_drop_resource_from_chain(gx_device_pdf * pdev, pdf_resource_t *pres1, pdf_resource_type_t rtype);
1162
1163
void pdf_drop_resources(gx_device_pdf * pdev, pdf_resource_type_t rtype,
1164
        int (*cond)(gx_device_pdf * pdev, pdf_resource_t *pres));
1165
1166
/* Print resource statistics. */
1167
void pdf_print_resource_statistics(gx_device_pdf * pdev);
1168
1169
/* Cancel a resource (do not write it into PDF). */
1170
int pdf_cancel_resource(gx_device_pdf * pdev, pdf_resource_t *pres,
1171
        pdf_resource_type_t rtype);
1172
1173
/* Remove a resource. */
1174
void pdf_forget_resource(gx_device_pdf * pdev, pdf_resource_t *pres1,
1175
        pdf_resource_type_t rtype);
1176
1177
/* Substitute a resource with a same one. */
1178
int pdf_substitute_resource(gx_device_pdf *pdev, pdf_resource_t **ppres,
1179
            pdf_resource_type_t rtype,
1180
            int (*eq)(gx_device_pdf *pdev, pdf_resource_t *pres0, pdf_resource_t *pres1),
1181
            bool write);
1182
1183
/* Get the object id of a resource. */
1184
long pdf_resource_id(const pdf_resource_t *pres);
1185
1186
/* End a separate object. */
1187
int pdf_end_separate(gx_device_pdf * pdev, pdf_resource_type_t type);
1188
1189
/* End an aside. */
1190
int pdf_end_aside(gx_device_pdf * pdev, pdf_resource_type_t type);
1191
1192
/* End a resource. */
1193
int pdf_end_resource(gx_device_pdf * pdev, pdf_resource_type_t type);
1194
1195
/*
1196
 * Write the Cos objects for resources local to a content stream.
1197
 */
1198
int pdf_write_resource_objects(gx_device_pdf *pdev, pdf_resource_type_t rtype);
1199
1200
/*
1201
 * Reverse resource chains.
1202
 * ps2write uses it with page resources.
1203
 * Assuming only the 0th chain contauns something.
1204
 */
1205
void pdf_reverse_resource_chain(gx_device_pdf *pdev, pdf_resource_type_t rtype);
1206
1207
/*
1208
 * Free unnamed Cos objects for resources local to a content stream.
1209
 */
1210
int pdf_free_resource_objects(gx_device_pdf *pdev, pdf_resource_type_t rtype);
1211
1212
/*
1213
 * Store the resource sets for a content stream (page or XObject).
1214
 * Sets page->{procsets, resource_ids[], fonts_id}.
1215
 */
1216
int pdf_store_page_resources(gx_device_pdf *pdev, pdf_page_t *page, bool clear_usage);
1217
1218
/* Copy data from a temporary file to a stream. */
1219
int pdf_copy_data(stream *s, gp_file *file, gs_offset_t count, stream_arcfour_state *ss);
1220
int pdf_copy_data_safe(stream *s, gp_file *file, gs_offset_t position, long count);
1221
1222
/* Add the encryption filter. */
1223
int pdf_begin_encrypt(gx_device_pdf * pdev, stream **s, gs_id object_id);
1224
/* Remove the encryption filter. */
1225
static int inline pdf_end_encrypt(gx_device_pdf *pdev)
1226
39.1k
{
1227
39.1k
    if (pdev->KeyLength)
1228
0
        return 1;
1229
39.1k
    return 0;
1230
39.1k
}
Unexecuted instantiation: gdevpdf.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdfb.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdfc.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdfd.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdfe.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdfg.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdfi.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdfj.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdfk.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdfm.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdfo.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdfp.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdft.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdfr.c:pdf_end_encrypt
gdevpdfu.c:pdf_end_encrypt
Line
Count
Source
1226
13.5k
{
1227
13.5k
    if (pdev->KeyLength)
1228
0
        return 1;
1229
13.5k
    return 0;
1230
13.5k
}
Unexecuted instantiation: gdevpdfv.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdt.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdtd.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdtf.c:pdf_end_encrypt
gdevpdti.c:pdf_end_encrypt
Line
Count
Source
1226
25.6k
{
1227
25.6k
    if (pdev->KeyLength)
1228
0
        return 1;
1229
25.6k
    return 0;
1230
25.6k
}
Unexecuted instantiation: gdevpdts.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdtt.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdtw.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdtb.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdtc.c:pdf_end_encrypt
Unexecuted instantiation: gdevpdte.c:pdf_end_encrypt
1231
/* Initialize encryption. */
1232
int pdf_encrypt_init(const gx_device_pdf * pdev, gs_id object_id, stream_arcfour_state *psarc4);
1233
1234
/* ------ Pages ------ */
1235
1236
/* Get or assign the ID for a page. */
1237
/* Returns 0 if the page number is out of range. */
1238
long pdf_page_id(gx_device_pdf * pdev, int page_num);
1239
1240
/* Get the page structure for the current page. */
1241
pdf_page_t *pdf_current_page(gx_device_pdf *pdev);
1242
1243
/* Get the dictionary object for the current page. */
1244
cos_dict_t *pdf_current_page_dict(gx_device_pdf *pdev);
1245
1246
/* Open a page for writing. */
1247
int pdf_open_page(gx_device_pdf * pdev, pdf_context_t context);
1248
1249
/*  Go to the unclipped stream context. */
1250
int pdf_unclip(gx_device_pdf * pdev);
1251
1252
/* Write saved page- or document-level information. */
1253
int pdf_write_saved_string(gx_device_pdf * pdev, gs_string * pstr);
1254
1255
/* ------ Path drawing ------ */
1256
1257
/* Store a copy of clipping path. */
1258
int pdf_remember_clip_path(gx_device_pdf * pdev, const gx_clip_path * pcpath);
1259
1260
int pdf_check_soft_mask(gx_device_pdf * pdev, gs_gstate * pgs);
1261
1262
/* Test whether the clip path needs updating. */
1263
bool pdf_must_put_clip_path(gx_device_pdf * pdev, const gx_clip_path * pcpath);
1264
1265
/* Write and update the clip path. */
1266
int pdf_put_clip_path(gx_device_pdf * pdev, const gx_clip_path * pcpath);
1267
1268
/* ------ Masked image convertion ------ */
1269
1270
typedef struct pdf_lcvd_s {
1271
    gx_device_memory mdev;
1272
    gx_device_memory *mask;
1273
    gx_device_pdf *pdev;
1274
    dev_t_proc_copy_color((*std_copy_color), gx_device);
1275
    dev_t_proc_copy_mono((*std_copy_mono), gx_device);
1276
    dev_t_proc_fill_rectangle((*std_fill_rectangle), gx_device);
1277
    dev_t_proc_close_device((*std_close_device), gx_device);
1278
    dev_t_proc_get_clipping_box((*std_get_clipping_box), gx_device);
1279
    dev_t_proc_transform_pixel_region((*std_transform_pixel_region), gx_device);
1280
    bool mask_is_empty;
1281
    bool path_is_empty;
1282
    bool mask_is_clean;
1283
    bool write_matrix;
1284
    bool has_background;
1285
    gs_matrix m;
1286
    gs_point path_offset;
1287
} pdf_lcvd_t;
1288
1289
#define public_st_pdf_lcvd_t()\
1290
  gs_public_st_suffix_add2(st_pdf_lcvd_t, pdf_lcvd_t,\
1291
    "pdf_lcvd_t", pdf_lcvd_t_enum_ptrs,\
1292
    pdf_lcvd_t_reloc_ptrs, st_device_memory, mask, pdev)
1293
#define pdf_lcvd_t_max_ptrs (gx_device_memory_max_ptrs + 2)
1294
1295
int pdf_setup_masked_image_converter(gx_device_pdf *pdev, gs_memory_t *mem, const gs_matrix *m, pdf_lcvd_t **pcvd,
1296
                                 bool need_mask, int x, int y, int w, int h, bool write_on_close);
1297
int pdf_dump_converted_image(gx_device_pdf *pdev, pdf_lcvd_t *cvd, int for_pattern);
1298
void pdf_remove_masked_image_converter(gx_device_pdf *pdev, pdf_lcvd_t *cvd, bool need_mask);
1299
1300
/* ------ Miscellaneous output ------ */
1301
1302
16.0k
#define PDF_MAX_PRODUCER 200        /* adhoc */
1303
/* Generate the default Producer string. */
1304
void pdf_store_default_Producer(char buf[PDF_MAX_PRODUCER]);
1305
1306
/* Define the strings for filter names and parameters. */
1307
typedef struct pdf_filter_names_s {
1308
    const char *ASCII85Decode;
1309
    const char *ASCIIHexDecode;
1310
    const char *CCITTFaxDecode;
1311
    const char *DCTDecode;
1312
    const char *DecodeParms;
1313
    const char *Filter;
1314
    const char *FlateDecode;
1315
    const char *LZWDecode;
1316
    const char *RunLengthDecode;
1317
    const char *JBIG2Decode;
1318
    const char *JPXDecode;
1319
} pdf_filter_names_t;
1320
#define PDF_FILTER_NAMES\
1321
73.2k
  "/ASCII85Decode", "/ASCIIHexDecode", "/CCITTFaxDecode",\
1322
73.2k
  "/DCTDecode",  "/DecodeParms", "/Filter", "/FlateDecode",\
1323
73.2k
  "/LZWDecode", "/RunLengthDecode", "/JBIG2Decode", "/JPXDecode"
1324
#define PDF_FILTER_NAMES_SHORT\
1325
  "/A85", "/AHx", "/CCF", "/DCT", "/DP", "/F", "/Fl", "/LZW", "/RL", "/???", "/???"
1326
1327
/* Write matrix values. */
1328
void pdf_put_matrix(gx_device_pdf *pdev, const char *before,
1329
                    const gs_matrix *pmat, const char *after);
1330
1331
/* Write a name, with escapes for unusual characters. */
1332
typedef int (*pdf_put_name_chars_proc_t)(stream *, const byte *, uint);
1333
pdf_put_name_chars_proc_t
1334
    pdf_put_name_chars_proc(const gx_device_pdf *pdev);
1335
int pdf_put_name_chars(const gx_device_pdf *pdev, const byte *nstr,
1336
                        uint size);
1337
int pdf_put_name(const gx_device_pdf *pdev, const byte *nstr, uint size);
1338
1339
/* Write a string in its shortest form ( () or <> ). */
1340
int pdf_put_string(const gx_device_pdf *pdev, const byte *str, uint size);
1341
1342
/* Write a value, treating names specially. */
1343
int pdf_write_value(const gx_device_pdf *pdev, const byte *vstr, uint size, gs_id object_id);
1344
1345
/* Store filters for a stream. */
1346
int pdf_put_filters(cos_dict_t *pcd, gx_device_pdf *pdev, stream *s,
1347
                    const pdf_filter_names_t *pfn);
1348
1349
/* Define a possibly encoded and compressed data stream. */
1350
typedef struct pdf_data_writer_s {
1351
    psdf_binary_writer binary;
1352
    gs_offset_t start;
1353
    gs_offset_t length_pos;
1354
    pdf_resource_t *pres;
1355
    gx_device_pdf *pdev; /* temporary for backward compatibility of pdf_end_data prototype. */
1356
    long length_id;
1357
    bool encrypted;
1358
} pdf_data_writer_t;
1359
/*
1360
 * Begin a data stream.  The client has opened the object and written
1361
 * the << and any desired dictionary keys.
1362
 */
1363
11.6k
#define DATA_STREAM_NOT_BINARY 0  /* data are text, not binary */
1364
152k
#define DATA_STREAM_BINARY 1        /* data are binary */
1365
88.6k
#define DATA_STREAM_COMPRESS 2        /* OK to compress data */
1366
106k
#define DATA_STREAM_NOLENGTH 4        /* Skip the length reference and filter names writing. */
1367
64.3k
#define DATA_STREAM_ENCRYPT  8        /* Encrypt data. */
1368
int pdf_begin_data_stream(gx_device_pdf *pdev, pdf_data_writer_t *pdw,
1369
                          int options, gs_id object_id);
1370
int pdf_append_data_stream_filters(gx_device_pdf *pdev, pdf_data_writer_t *pdw,
1371
                      int orig_options, gs_id object_id);
1372
/* begin_data = begin_data_binary with both options = true. */
1373
int pdf_begin_data(gx_device_pdf *pdev, pdf_data_writer_t *pdw);
1374
1375
/* End a data stream. */
1376
int pdf_end_data(pdf_data_writer_t *pdw);
1377
1378
/* ------ Functions ------ */
1379
1380
/* Define the maximum size of a Function reference. */
1381
#define MAX_REF_CHARS ((sizeof(long) * 8 + 2) / 3)
1382
1383
/*
1384
 * Create a Function object with or without range scaling.  Scaling means
1385
 * that if x[i] is the i'th output value from the original Function,
1386
 * the i'th output value from the Function object will be (x[i] -
1387
 * ranges[i].rmin) / (ranges[i].rmax - ranges[i].rmin).  Note that this is
1388
 * the inverse of the scaling convention for Functions per se.
1389
 */
1390
int pdf_function(gx_device_pdf *pdev, const gs_function_t *pfn,
1391
                 cos_value_t *pvalue);
1392
int pdf_function_scaled(gx_device_pdf *pdev, const gs_function_t *pfn,
1393
                        const gs_range_t *pranges, cos_value_t *pvalue);
1394
1395
/* Write a Function object, returning its object ID. */
1396
int pdf_write_function(gx_device_pdf *pdev, const gs_function_t *pfn,
1397
                       long *pid);
1398
1399
/* If a stitching function references an array of other functions, we need
1400
 * to 'unreference' those before freeing the function. otherwise we end up
1401
 * trying to free the referenced functions twice.
1402
 */
1403
int free_function_refs(gx_device_pdf *pdev, cos_object_t *pco);
1404
/* ------ Fonts ------ */
1405
1406
/* Write a FontBBox dictionary element. */
1407
int pdf_write_font_bbox(gx_device_pdf *pdev, const gs_int_rect *pbox);
1408
int pdf_write_font_bbox_float(gx_device_pdf *pdev, const gs_rect *pbox);
1409
1410
/* ---------------- Exported by gdevpdfm.c ---------------- */
1411
1412
/*
1413
 * Define the type for a pdfmark-processing procedure.
1414
 * If nameable is false, the objname argument is always NULL.
1415
 */
1416
#define pdfmark_proc(proc)\
1417
  int proc(gx_device_pdf *pdev, gs_param_string *pairs, uint count,\
1418
           const gs_matrix *pctm, const gs_param_string *objname)
1419
1420
/* Compare a C string and a gs_param_string. */
1421
bool pdf_key_eq(const gs_param_string * pcs, const char *str);
1422
1423
/* Scan an integer out of a parameter string. */
1424
int pdfmark_scan_int(const gs_param_string * pstr, int *pvalue);
1425
1426
/* Process a pdfmark (called from pdf_put_params). */
1427
int pdfmark_process(gx_device_pdf * pdev, const gs_param_string_array * pma);
1428
1429
/* Close the current level of the outline tree. */
1430
int pdfmark_close_outline(gx_device_pdf * pdev);
1431
1432
/* Close the pagelabel numtree. */
1433
int pdfmark_end_pagelabels(gx_device_pdf * pdev);
1434
1435
/* Finish writing an article. */
1436
int pdfmark_write_article(gx_device_pdf * pdev, const pdf_article_t * part);
1437
1438
/* ---------------- Exported by gdevpdfr.c ---------------- */
1439
1440
/* Test whether an object name has valid syntax, {name}. */
1441
bool pdf_objname_is_valid(const byte *data, uint size);
1442
1443
/*
1444
 * Look up a named object.  Return_error(gs_error_rangecheck if the syntax is invalid,
1445
 * gs_error_undefined if no object by that name exists.
1446
 */
1447
int pdf_find_named(gx_device_pdf * pdev, const gs_param_string * pname,
1448
                   cos_object_t **ppco);
1449
1450
/*
1451
 * Create a named object.  id = -1L means do not assign an id.  pname = 0
1452
 * means just create the object, do not name it.
1453
 */
1454
int pdf_create_named(gx_device_pdf *pdev, const gs_param_string *pname,
1455
                     cos_type_t cotype, cos_object_t **ppco, long id);
1456
int pdf_create_named_dict(gx_device_pdf *pdev, const gs_param_string *pname,
1457
                          cos_dict_t **ppcd, long id);
1458
1459
/*
1460
 * Look up a named object as for pdf_find_named.  If the object does not
1461
 * exist, create it (as a dictionary if it is one of the predefined names
1462
 * {ThisPage}, {NextPage}, {PrevPage}, or {Page<#>}, otherwise as a
1463
 * generic object) and return 1.
1464
 */
1465
int pdf_refer_named(gx_device_pdf *pdev, const gs_param_string *pname,
1466
                    cos_object_t **ppco);
1467
1468
/*
1469
 * Look up a named object as for pdf_refer_named.  If the object already
1470
 * exists and is not simply a forward reference, return_error(gs_error_rangecheck);
1471
 * if it exists as a forward reference, set its type and return 0;
1472
 * otherwise, create the object with the given type and return 1.
1473
 * pname = 0 is allowed: in this case, simply create the object.
1474
 */
1475
int pdf_make_named(gx_device_pdf * pdev, const gs_param_string * pname,
1476
                   cos_type_t cotype, cos_object_t **ppco, bool assign_id);
1477
int pdf_make_named_dict(gx_device_pdf * pdev, const gs_param_string * pname,
1478
                        cos_dict_t **ppcd, bool assign_id);
1479
1480
/*
1481
 * Look up a named object as for pdf_refer_named.  If the object does not
1482
 * exist, or is a forward reference, return gs_error_undefined; if the object
1483
 * exists has the wrong type, return gs_error_typecheck.
1484
 */
1485
int pdf_get_named(gx_device_pdf * pdev, const gs_param_string * pname,
1486
                  cos_type_t cotype, cos_object_t **ppco);
1487
1488
/*
1489
 * Push the current local namespace onto the namespace stack, and reset it
1490
 * to an empty namespace.
1491
 */
1492
int pdf_push_namespace(gx_device_pdf *pdev);
1493
1494
/*
1495
 * Pop the top local namespace from the namespace stack.  Return an error if
1496
 * the stack is empty.
1497
 */
1498
int pdf_pop_namespace(gx_device_pdf *pdev);
1499
1500
/*
1501
 * Scan a string for a token.  <<, >>, [, and ] are treated as tokens.
1502
 * Return 1 if a token was scanned, 0 if we reached the end of the string,
1503
 * or an error.  On a successful return, the token extends from *ptoken up
1504
 * to but not including *pscan.
1505
 */
1506
int pdf_scan_token(const byte **pscan, const byte * end, const byte **ptoken);
1507
1508
/*
1509
 * Scan a possibly composite token: arrays and dictionaries are treated as
1510
 * single tokens.
1511
 */
1512
int pdf_scan_token_composite(const byte **pscan, const byte * end,
1513
                             const byte **ptoken);
1514
1515
/* Replace object names with object references in a (parameter) string. */
1516
int pdf_replace_names(gx_device_pdf *pdev, const gs_param_string *from,
1517
                      gs_param_string *to);
1518
1519
/* ================ Text module procedures ================ */
1520
1521
/* ---------------- Exported by gdevpdfw.c ---------------- */
1522
1523
/* For gdevpdf.c */
1524
1525
int write_font_resources(gx_device_pdf *pdev, pdf_resource_list_t *prlist);
1526
1527
/* ---------------- Exported by gdevpdft.c ---------------- */
1528
1529
/* For gdevpdf.c */
1530
1531
pdf_text_data_t *pdf_text_data_alloc(gs_memory_t *mem);
1532
void pdf_set_text_state_default(pdf_text_state_t *pts);
1533
void pdf_text_state_copy(pdf_text_state_t *pts_to, pdf_text_state_t *pts_from);
1534
void pdf_reset_text_page(pdf_text_data_t *ptd);
1535
void pdf_reset_text_state(pdf_text_data_t *ptd);
1536
void pdf_close_text_page(gx_device_pdf *pdev);
1537
1538
/* For gdevpdfb.c */
1539
1540
int pdf_char_image_y_offset(const gx_device_pdf *pdev, int x, int y, int h);
1541
1542
/* Begin a CharProc for an embedded (bitmap) font. */
1543
int pdf_begin_char_proc(gx_device_pdf * pdev, int w, int h, int x_width,
1544
                        int y_offset, int x_offset, gs_id id, pdf_char_proc_t **ppcp,
1545
                        pdf_stream_position_t * ppos);
1546
1547
/* End a CharProc. */
1548
int pdf_end_char_proc(gx_device_pdf * pdev, pdf_stream_position_t * ppos);
1549
1550
/* Put out a reference to an image as a character in an embedded font. */
1551
int pdf_do_char_image(gx_device_pdf * pdev, const pdf_char_proc_t * pcp,
1552
                      const gs_matrix * pimat);
1553
1554
/* Start charproc accumulation for a Type 3 font. */
1555
int pdf_start_charproc_accum(gx_device_pdf *pdev);
1556
/* Install charproc accumulator for a Type 3 font. */
1557
int pdf_set_charproc_attrs(gx_device_pdf *pdev, gs_font *font, double *pw, int narg,
1558
                gs_text_cache_control_t control, gs_char ch, bool scale_100);
1559
/* Complete charproc accumulation for aType 3 font. */
1560
int pdf_end_charproc_accum(gx_device_pdf *pdev, gs_font *font, const pdf_char_glyph_pairs_t *cgp,
1561
                       gs_glyph glyph, gs_char output_char_code, const gs_const_string *gnstr);
1562
/* Open a stream object in the temporary file. */
1563
int pdf_open_aside(gx_device_pdf *pdev, pdf_resource_type_t rtype,
1564
        gs_id id, pdf_resource_t **ppres, bool reserve_object_id, int options);
1565
1566
/* Close a stream object in the temporary file. */
1567
int pdf_close_aside(gx_device_pdf *pdev);
1568
1569
/* Enter the substream accumulation mode. */
1570
int pdf_enter_substream(gx_device_pdf *pdev, pdf_resource_type_t rtype,
1571
                gs_id id, pdf_resource_t **ppres, bool reserve_object_id, bool compress);
1572
1573
/* Exit the substream accumulation mode. */
1574
int pdf_exit_substream(gx_device_pdf *pdev);
1575
/* Add procsets to substream Resources. */
1576
int pdf_add_procsets(cos_dict_t *pcd, pdf_procset_t procsets);
1577
/* Add a resource to substream Resources. */
1578
int pdf_add_resource(gx_device_pdf *pdev, cos_dict_t *pcd, const char *key, pdf_resource_t *pres);
1579
1580
/* For gdevpdfu.c */
1581
1582
int pdf_from_stream_to_text(gx_device_pdf *pdev);
1583
int pdf_from_string_to_text(gx_device_pdf *pdev);
1584
void pdf_close_text_contents(gx_device_pdf *pdev);
1585
1586
int gdev_pdf_get_param(gx_device *dev, char *Param, void *list);
1587
#endif /* gdevpdfx_INCLUDED */