1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
/* Copyright (C) 1996, 2000 Aladdin Enterprises. All rights reserved.
This file is part of AFPL Ghostscript.
AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
distributor accepts any responsibility for the consequences of using it, or
for whether it serves any particular purpose or works at all, unless he or
she says so in writing. Refer to the Aladdin Free Public License (the
"License") for full details.
Every copy of AFPL Ghostscript must include a copy of the License, normally
in a plain ASCII text file named PUBLIC. The License grants you the right
to copy, modify and redistribute AFPL Ghostscript, but only under certain
conditions described in the License. Among other things, the License
requires that the copyright notice and this notice be preserved on all
copies.
*/
/*$Id$ */
/* Get/put parameters for PDF-writing driver */
#include "memory_.h" /* should be first */
#include "gx.h"
#include "gserrors.h"
#include "gdevpdfx.h"
#include "gsparamx.h"
/*
* The pdfwrite device supports the following "real" parameters:
* OutputFile <string>
* all the Distiller parameters (also see gdevpsdp.c)
* Only some of the Distiller parameters actually have any effect.
*
* The device also supports the following write-only pseudo-parameters that
* serve only to communicate other information from the PostScript file.
* Their "value" is an array of strings, some of which may be the result
* of converting arbitrary PostScript objects to string form.
* pdfmark - see gdevpdfm.c
*/
private const int CoreDistVersion = 4000; /* Distiller 4.0 */
private const gs_param_item_t pdf_param_items[] = {
#define pi(key, type, memb) { key, type, offset_of(gx_device_pdf, memb) }
/* Acrobat Distiller 4 parameters */
/*
* EndPage and StartPage are renamed because EndPage collides with
* a page device parameter.
*/
pi("PDFEndPage", gs_param_type_int, EndPage),
pi("PDFStartPage", gs_param_type_int, StartPage),
pi("Optimize", gs_param_type_bool, Optimize),
pi("ParseDSCCommentsForDocInfo", gs_param_type_bool,
ParseDSCCommentsForDocInfo),
pi("ParseDSCComments", gs_param_type_bool, ParseDSCComments),
pi("EmitDSCWarnings", gs_param_type_bool, EmitDSCWarnings),
pi("CreateJobTicket", gs_param_type_bool, CreateJobTicket),
pi("PreserveEPSInfo", gs_param_type_bool, PreserveEPSInfo),
pi("AutoPositionEPSFiles", gs_param_type_bool, AutoPositionEPSFiles),
pi("PreserveCopyPage", gs_param_type_bool, PreserveCopyPage),
pi("UsePrologue", gs_param_type_bool, UsePrologue),
/* Ghostscript-specific parameters */
pi("ReAssignCharacters", gs_param_type_bool, ReAssignCharacters),
pi("ReEncodeCharacters", gs_param_type_bool, ReEncodeCharacters),
pi("FirstObjectNumber", gs_param_type_long, FirstObjectNumber),
#undef pi
gs_param_item_end
};
/*
Notes on implementing the remaining Distiller functionality
===========================================================
Architectural issues
--------------------
Must disable all color conversions, so that driver gets original color
and color space -- needs "protean" device color space
Must optionally disable application of TR, BG, UCR similarly. Affects:
PreserveHalftoneInfo
PreserveOverprintSettings
TransferFunctionInfo
UCRandBGInfo
* = requires architectural change to complete
Current limitations
-------------------
Non-primary elements in HalftoneType 5 are not written correctly
Doesn't recognize Default TR/HT/BG/UCR
Optimization is a separate program
Optimizations
-------------
Create shared resources for Indexed (and other) color spaces
Remember image XObject IDs for sharing
Remember image and pattern MD5 fingerprints for sharing -- see
CD-ROM from dhoff@margnat.com
Merge font subsets? (k/ricktest.ps, from rick@dgii.com re file output
size ps2pdf vs. pstoedit)
Minimize tables for embedded TT fonts (requires renumbering glyphs)
Clip off image data outside bbox of clip path?
Acrobat Distiller 3
-------------------
---- Other functionality ----
Embed CID fonts
Compress TT, CFF, CID/TT, and CID/CFF if CompressPages
Compress forms, Type 3 fonts, and Cos streams
---- Image parameters ----
AntiAlias{Color,Gray,Mono}Images
AutoFilter{Color,Gray}Images
Needs to scan image
Convert CIE images to Device if can't represent color space
---- Other parameters ----
CompressPages
Compress things other than page contents
* PreserveHalftoneInfo
PreserveOPIComments
? see OPI spec?
* PreserveOverprintSettings
* TransferFunctionInfo
* UCRandBGInfo
ColorConversionStrategy
Select color space for drawing commands
ConvertImagesToIndexed
Postprocess image data *after* downsampling (requires an extra pass)
Acrobat Distiller 4
-------------------
---- Other functionality ----
Document structure pdfmarks
---- Parameters ----
xxxDownsampleType = /Bicubic
Add new filter (or use siscale?) & to setup (gdevpsdi.c)
Binding
? not sure where this goes (check with AD4)
DetectBlends
Idiom recognition? PatternType 2 patterns / shfill? (see AD4)
DoThumbnails
Also output to memory device -- resolution issue
EndPage / StartPage
Only affects AR? -- see what AD4 produces
###Profile
Output in ICCBased color spaces
ColorConversionStrategy
* Requires suppressing CIE => Device color conversion
Convert other CIE spaces to ICCBased
CannotEmbedFontPolicy
Check when trying to embed font -- how to produce warning?
---- Job-level control ----
ParseDSCComments
ParseDSCCommentsForDocInfo
EmitDSCWarnings
Require DSC parser / interceptor
CreateJobTicket
?
PreserveEPSInfo
AutoPositionEPSFiles
Require DSC parsing
PreserveCopyPage
Concatenate Contents streams
UsePrologue
Needs hack in top-level control?
*/
/* ---------------- Get parameters ---------------- */
/* Get parameters. */
int
gdev_pdf_get_params(gx_device * dev, gs_param_list * plist)
{
gx_device_pdf *pdev = (gx_device_pdf *) dev;
float cl = (float)pdev->CompatibilityLevel;
int code = gdev_psdf_get_params(dev, plist);
int cdv = CoreDistVersion;
if (code < 0 ||
(code = param_write_int(plist, "CoreDistVersion", &cdv)) < 0 ||
(code = param_write_float(plist, "CompatibilityLevel", &cl)) < 0 ||
/* Indicate that we can process pdfmark. */
(param_requested(plist, "pdfmark") > 0 &&
(code = param_write_null(plist, "pdfmark")) < 0) ||
(code = gs_param_write_items(plist, pdev, NULL, pdf_param_items)) < 0
);
return code;
}
/* ---------------- Put parameters ---------------- */
/* Put parameters. */
int
gdev_pdf_put_params(gx_device * dev, gs_param_list * plist)
{
gx_device_pdf *pdev = (gx_device_pdf *) dev;
int ecode, code;
gx_device_pdf save_dev;
float cl = (float)pdev->CompatibilityLevel;
bool locked = pdev->params.LockDistillerParams;
gs_param_name param_name;
/*
* If this is a pseudo-parameter (show or pdfmark),
* don't bother checking for any real ones.
*/
{
gs_param_string_array ppa;
code = param_read_string_array(plist, (param_name = "pdfmark"), &ppa);
switch (code) {
case 0:
pdf_open_document(pdev);
code = pdfmark_process(pdev, &ppa);
if (code >= 0)
return code;
/* falls through for errors */
default:
param_signal_error(plist, param_name, code);
return code;
case 1:
break;
}
}
/* Check for LockDistillerParams before doing anything else. */
ecode = code = param_read_bool(plist, "LockDistillerParams", &locked);
if (locked && pdev->params.LockDistillerParams)
return ecode;
/* General parameters. */
{
int cdv = CoreDistVersion;
ecode = param_put_int(plist, (param_name = "CoreDistVersion"), &cdv, ecode);
if (cdv != CoreDistVersion)
param_signal_error(plist, param_name, ecode = gs_error_rangecheck);
}
save_dev = *pdev;
switch (code = param_read_float(plist, (param_name = "CompatibilityLevel"), &cl)) {
default:
ecode = code;
param_signal_error(plist, param_name, ecode);
case 0:
case 1:
break;
}
code = gs_param_read_items(plist, pdev, pdf_param_items);
if (code < 0)
ecode = code;
{
/*
* Setting FirstObjectNumber is only legal if the file
* has just been opened and nothing has been written,
* or if we are setting it to the same value.
*/
long fon = pdev->FirstObjectNumber;
if (fon != save_dev.FirstObjectNumber) {
if (fon <= 0 || fon > 0x7fff0000 ||
(pdev->next_id != 0 &&
pdev->next_id !=
save_dev.FirstObjectNumber + pdf_num_initial_ids)
) {
ecode = gs_error_rangecheck;
param_signal_error(plist, "FirstObjectNumber", ecode);
}
}
}
{
/*
* Set ProcessColorModel now, because gx_default_put_params checks
* it.
*/
static const char *const pcm_names[] = {
"DeviceGray", "DeviceRGB", "DeviceCMYK", 0
};
static const gx_device_color_info pcm_color_info[] = {
dci_values(1, 8, 255, 0, 256, 0),
dci_values(3, 24, 255, 255, 256, 256),
dci_values(4, 32, 255, 255, 256, 256)
};
int pcm = -1;
ecode = param_put_enum(plist, "ProcessColorModel", &pcm,
pcm_names, ecode);
if (pcm >= 0) {
pdev->color_info = pcm_color_info[pcm];
pdf_set_process_color_model(pdev);
}
}
if (ecode < 0)
goto fail;
/*
* We have to set version to the new value, because the set of
* legal parameter values for psdf_put_params varies according to
* the version.
*/
pdev->version = (cl < 1.2 ? psdf_version_level2 : psdf_version_ll3);
ecode = gdev_psdf_put_params(dev, plist);
if (ecode < 0)
goto fail;
/*
* Acrobat Reader 4.0 and earlier don't handle user-space coordinates
* larger than 32K. To compensate for this, reduce the resolution until
* the page size in device space (which we equate to user space) is
* significantly less than 32K. Note that this still does not protect
* us against input files that use coordinates far outside the page
* boundaries.
*/
/* Changing resolution or page size requires closing the device, */
while (dev->height > 16000 || dev->width > 16000) {
if (dev->is_open)
gs_closedevice(dev);
gx_device_set_resolution(dev, dev->HWResolution[0] / 2,
dev->HWResolution[1] / 2);
}
if (pdev->FirstObjectNumber != save_dev.FirstObjectNumber) {
if (pdev->xref.file != 0) {
fseek(pdev->xref.file, 0L, SEEK_SET);
pdf_initialize_ids(pdev);
}
}
/* Handle the float/double mismatch. */
pdev->CompatibilityLevel = (int)(cl * 10 + 0.5) / 10.0;
return 0;
fail:
/* Restore all the parameters to their original state. */
pdev->version = save_dev.version;
pdev->color_info = save_dev.color_info;
pdf_set_process_color_model(pdev);
{
const gs_param_item_t *ppi = pdf_param_items;
for (; ppi->key; ++ppi)
memcpy((char *)pdev + ppi->offset,
(char *)&save_dev + ppi->offset,
gs_param_type_sizes[ppi->type]);
}
return ecode;
}
|