Subversion Repositories Scribus

Rev

Rev 20092 | Rev 20267 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
792 subik 7
#include "objpdffile.h"
14491 jghali 8
#include "colormgmt/sccolormgmtengine.h"
792 subik 9
#include "cmdutil.h"
2834 cbradney 10
#include "prefsmanager.h"
2960 cbradney 11
#include "scribusdoc.h"
5243 cbradney 12
#include "scribuscore.h"
19093 craig 13
#include "scribusview.h"
14170 jghali 14
#include <structmember.h>
15
#include "ui/bookmarkpalette.h"
792 subik 16
 
10223 cbradney 17
#include <QFileInfo>
9803 fschmid 18
#include <QList>
8501 cbradney 19
#include <QPixmap>
792 subik 20
#include <vector>
418 Franz 21
 
22
// these functions are located at utils.cpp
3819 subik 23
void SCRIBUS_API ReOrderText(ScribusDoc *doc, ScribusView *view);
418 Franz 24
// end of utils.cpp
25
//this is in file scribus.cpp
420 Franz 26
 
418 Franz 27
 
420 Franz 28
static int minmaxi(int val, int min, int max)
29
{
1745 subik 30
        if (val < min)
31
                return min;
32
        else if (val > max)
33
                return max;
34
        else return val;
420 Franz 35
}
36
 
37
static double minmaxd(double val, double min, double max)
38
{
1745 subik 39
        if (val < min)
40
                return min;
41
        else if (val > max)
42
                return max;
43
        else return val;
420 Franz 44
}
45
 
733 subik 46
typedef struct
418 Franz 47
{
1745 subik 48
        PyObject_HEAD
49
        PyObject *file; // string - file to save into
20126 jghali 50
        PyObject *fontEmbedding; // int - 0: Embed fonts, 1:Outline fonts, 2:Dont embed any font
1745 subik 51
        PyObject *fonts; // list of string - fonts to  embed
20092 jghali 52
        PyObject *subsetList; // list of string - fonts to outline
1745 subik 53
        PyObject *pages; // list of int - pages to print
54
        int thumbnails; // bool -
19704 jghali 55
        int cropMarks; // bool -
56
        int bleedMarks; // bool -
57
        int registrationMarks; // bool -
58
        int colorMarks; // bool -
59
        int docInfoMarks; // bool -
60
        double markOffset; // double -
19746 jghali 61
        double markLength; // double -
1745 subik 62
        int compress; // bool -
63
        int compressmtd; // int - 0=automatic 1=jpeg 2=zip 3=none
64
        int quality; // int - 0=Maximum 4=minimum
65
        PyObject *resolution; // int - 35 - 4000 default=300 dpi
66
        PyObject *downsample; // int - 35 - 4000 default=0 do not downsample ; other downsample to this resolution
67
        int bookmarks; // bool -
68
        int binding; // bool - 0 -left margin 1 -right margin
69
        int presentation; // bool -
70
        PyObject *effval; // list of list of 5 int - effect to apply to each page during presentation
71
        int article; // bool -
72
        int encrypt; // bool -
73
        int uselpi; // bool -
3079 fschmid 74
        int usespot;
75
        int domulti;
1745 subik 76
        PyObject *lpival; // list of elements which has structure [siii]
77
        PyObject *owner; // string - owner's password
78
        PyObject *user; // string - user's password
20092 jghali 79
        int allowPrinting; // bool -  allow printing
80
        int allowChange; // bool - allow changing
81
        int allowCopy; // bool - allow copying
82
        int allowAnnots; // bool - allow adding annotation and fields
83
        int version; // int - version of pdf (12=1.2; 13=1.3; 14=1.4; 15=1.5)
1745 subik 84
        int outdst; // int - output destination 0 - screen, 1 - printer
418 Franz 85
 
1745 subik 86
        int profiles; // bool
87
        int profilei; // bool
88
        int intents; // int - 0 - 3 QString tmp_ip[] = { tr("Perceptual"), tr("Relative Colorimetric"), tr("Saturation"), tr("Absolute Colorimetric")};
89
        int intenti; // int - 0 - 3 QString tmp_ip[] = { tr("Perceptual"), tr("Relative Colorimetric"), tr("Saturation"), tr("Absolute Colorimetric")};
90
        int noembicc; // bool - "Don't use embedded ICC profiles"
91
        PyObject *solidpr; // string
92
        PyObject *imagepr; // string
93
        PyObject *printprofc; // string
94
        PyObject *info; // string
20092 jghali 95
        double bleedt; // double - 0 to height of page
1745 subik 96
        double bleedl; // double - 0 to width of page
97
        double bleedr; // double - 0 to width of page
20092 jghali 98
        double bleedb; // double - 0 to height of page
99
        int useDocBleeds; // bool
19699 jghali 100
        int useLayers;
101
        int embedPDF;
19704 jghali 102
        int mirrorH;
103
        int mirrorV;
19699 jghali 104
        int doClip;
20092 jghali 105
        PyObject * rotateDeg; // int
19699 jghali 106
        int isGrayscale;
19704 jghali 107
        int pageLayout;
19699 jghali 108
        int displayBookmarks;
109
        int displayThumbs;
110
        int displayLayers;
111
        int displayFullscreen;
112
        int hideToolBar;
113
        int hideMenuBar;
114
        int fitWindow;
115
        PyObject *openAction;
733 subik 116
 
418 Franz 117
} PDFfile;
118
 
119
static void PDFfile_dealloc(PDFfile *self)
120
{
1745 subik 121
        Py_XDECREF(self->file);
20126 jghali 122
        Py_XDECREF(self->fontEmbedding);
1745 subik 123
        Py_XDECREF(self->fonts);
20092 jghali 124
        Py_XDECREF(self->subsetList);
1745 subik 125
        Py_XDECREF(self->pages);
126
        Py_XDECREF(self->resolution);
127
        Py_XDECREF(self->downsample);
128
        Py_XDECREF(self->effval);
129
        Py_XDECREF(self->lpival);
130
        Py_XDECREF(self->owner);
131
        Py_XDECREF(self->user);
132
        Py_XDECREF(self->solidpr);
133
        Py_XDECREF(self->imagepr);
134
        Py_XDECREF(self->printprofc);
135
        Py_XDECREF(self->info);
20092 jghali 136
        Py_XDECREF(self->rotateDeg);
19699 jghali 137
        Py_XDECREF(self->openAction);
1745 subik 138
        self->ob_type->tp_free((PyObject *)self);
418 Franz 139
}
140
 
10778 craig 141
static PyObject * PDFfile_new(PyTypeObject *type, PyObject * /*args*/, PyObject * /*kwds*/)
418 Franz 142
{
143
// do not create new object if there is no opened document
5781 cbradney 144
        if (!ScCore->primaryMainWindow()->HaveDoc) {
1745 subik 145
                PyErr_SetString(PyExc_SystemError, "Need to open document first");
146
                return NULL;
147
        }
733 subik 148
 
1745 subik 149
        PDFfile *self;
733 subik 150
 
1745 subik 151
        self = (PDFfile *)type->tp_alloc(type, 0);
152
        if (self) {
418 Franz 153
// set file attribute
1745 subik 154
                self->file = PyString_FromString("");
20126 jghali 155
                if (!self->file) {
1745 subik 156
                        Py_DECREF(self);
157
                        return NULL;
158
                }
20126 jghali 159
// set font embedding mode attribute
160
                self->fontEmbedding = PyInt_FromLong(0);
161
                if (!self->fontEmbedding) {
162
                        Py_DECREF(self);
163
                        return NULL;
164
                }
418 Franz 165
// set fonts attribute
1745 subik 166
                self->fonts = PyList_New(0);
167
                if (!self->fonts){
168
                        Py_DECREF(self);
169
                        return NULL;
170
                }
20092 jghali 171
                self->subsetList = PyList_New(0);
172
                if (!self->subsetList){
19699 jghali 173
                        Py_DECREF(self);
174
                        return NULL;
175
                }
418 Franz 176
// set pages attribute
1745 subik 177
                self->pages = PyList_New(0);
178
                if (self->pages == NULL){
179
                        Py_DECREF(self);
180
                        return NULL;
181
                }
418 Franz 182
// set thumbnails attribute
1745 subik 183
                self->thumbnails = 0;
19704 jghali 184
// set cropMarks attribute
185
                self->cropMarks = 0;
186
// set bleedMarks attribute
187
                self->bleedMarks = 0;
188
// set registrationMarks attribute
189
                self->registrationMarks = 0;
190
// set colorMarks attribute
191
                self->colorMarks = 0;
192
// set docInfoMarks attribute
193
                self->docInfoMarks = 0;
194
// set mark offset attribute
195
                self->markOffset = 0;
19746 jghali 196
// set mark length attribute
197
                self->markLength = 0;
418 Franz 198
// set compress attribute
1745 subik 199
                self->compress = 0;
420 Franz 200
// set compressmtd attribute
1745 subik 201
                self->compressmtd = 0;
418 Franz 202
// set quality attribute
1745 subik 203
                self->quality = 0;
418 Franz 204
// set resolution attribute
1745 subik 205
                self->resolution = PyInt_FromLong(300);
206
                if (!self->resolution){
207
                        Py_DECREF(self);
208
                        return NULL;
209
                }
418 Franz 210
// set downsample attribute
1745 subik 211
                self->downsample = PyInt_FromLong(0);
212
                if (!self->downsample){
213
                        Py_DECREF(self);
214
                        return NULL;
215
                }
418 Franz 216
// set bookmarks attribute
1745 subik 217
                self->bookmarks = 0;
418 Franz 218
// set binding attribute
1745 subik 219
                self->binding = 0;
418 Franz 220
// set presentation attribute
1745 subik 221
                self->presentation = 0;
418 Franz 222
// set effval attribute
1745 subik 223
                self->effval = PyList_New(0);
224
                if (!self->effval){
225
                        Py_DECREF(self);
226
                        return NULL;
227
                }
420 Franz 228
// set article attribute
1745 subik 229
                self->article = 0;
420 Franz 230
// set encrypt attribute
1745 subik 231
                self->encrypt = 0;
420 Franz 232
// set uselpi attribute
1745 subik 233
                self->uselpi = 0;
3079 fschmid 234
                self->usespot = 1;
235
                self->domulti = 0;
418 Franz 236
// set lpival attribute
1745 subik 237
                self->lpival = PyList_New(0);
238
                if (!self->lpival){
239
                        Py_DECREF(self);
240
                        return NULL;
241
                }
418 Franz 242
// set owner attribute
1745 subik 243
                self->owner = PyString_FromString("");
244
                if (!self->owner){
245
                        Py_DECREF(self);
246
                        return NULL;
247
                }
418 Franz 248
// set user attribute
1745 subik 249
                self->user = PyString_FromString("");
250
                if (!self->user){
251
                        Py_DECREF(self);
252
                        return NULL;
253
                }
20092 jghali 254
// set allowPrinting attribute
255
                self->allowPrinting = 1;
256
// set allowChange attribute
257
                self->allowChange = 1;
258
// set allowCopy attribute
259
                self->allowCopy = 1;
260
// set allowAnnots attribute
261
                self->allowAnnots = 1;
418 Franz 262
// set version attribute
1745 subik 263
                self->version = 14;
418 Franz 264
// set output attribute
1745 subik 265
                self->outdst = 0;
418 Franz 266
 
267
 
1745 subik 268
                self->profiles = 0; // bool
269
                self->profilei = 0; // bool
270
                self->intents = 0; // int - 0 - ?
271
                self->intenti = 0; // int - 0 - ?
272
                self->noembicc = 0; // bool
273
                self->solidpr = PyString_FromString("");
274
                if (!self->solidpr){
275
                        Py_DECREF(self);
276
                        return NULL;
277
                }
278
                self->imagepr = PyString_FromString("");
279
                if (!self->imagepr){
280
                        Py_DECREF(self);
281
                        return NULL;
282
                }
283
                self->printprofc = PyString_FromString("");
284
                if (!self->printprofc){
285
                        Py_DECREF(self);
286
                        return NULL;
287
                }
288
                self->info = PyString_FromString("");
289
                if (!self->info){
290
                        Py_DECREF(self);
291
                        return NULL;
292
                }
293
                self->bleedt = 0; // double -
294
                self->bleedl = 0; // double -
295
                self->bleedr = 0; // double -
296
                self->bleedb = 0; // double -
20092 jghali 297
                self->useDocBleeds = 1; // bool
19699 jghali 298
                self->useLayers = 0;
299
                self->embedPDF = 0;
19704 jghali 300
                self->mirrorH = 0;
301
                self->mirrorV = 0;
19699 jghali 302
                self->doClip = 0;
20092 jghali 303
                self->rotateDeg = PyInt_FromLong(0);
304
                if (!self->rotateDeg){
19699 jghali 305
                        Py_DECREF(self);
306
                        return NULL;
307
                }
308
                self->isGrayscale = 0;
19704 jghali 309
                self->pageLayout = 0;
19699 jghali 310
                self->displayBookmarks = 0;
311
                self->displayThumbs = 0;
312
                self->displayLayers = 0;
313
                self->displayFullscreen = 0;
314
                self->hideToolBar = 0;
315
                self->hideMenuBar = 0;
316
                self->fitWindow = 0;
317
                self->openAction = PyString_FromString("");
318
                if (!self->openAction){
319
                        Py_DECREF(self);
320
                        return NULL;
321
                }
1745 subik 322
        }
323
        return (PyObject *) self;
418 Franz 324
}
325
 
10778 craig 326
static int PDFfile_init(PDFfile *self, PyObject * /*args*/, PyObject * /*kwds*/)
418 Franz 327
{
3819 subik 328
        int i;
5781 cbradney 329
        if (!ScCore->primaryMainWindow()->HaveDoc) {
1745 subik 330
                PyErr_SetString(PyExc_SystemError, "Must open doc first");
331
                return -1;
332
        }
19710 jghali 333
 
334
        ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
335
        PDFOptions& pdfOptions = currentDoc->pdfOptions();
336
 
420 Franz 337
// defaut save into file
19710 jghali 338
        QString tf = pdfOptions.fileName;
2877 cbradney 339
        if (tf.isEmpty()) {
19710 jghali 340
                QFileInfo fi = QFileInfo(currentDoc->DocName);
10598 cbradney 341
                tf = fi.path()+"/"+fi.baseName()+".pdf";
1745 subik 342
        }
343
        PyObject *file = NULL;
18194 fschmid 344
        file = PyString_FromString(tf.toLatin1());
1745 subik 345
        if (file){
346
                Py_DECREF(self->file);
347
                self->file = file;
348
        } else {
349
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'file' attribute");
350
                return -1;
351
        }
20126 jghali 352
// font embedding mode
353
        PyObject *embeddingMode = NULL;
354
        embeddingMode = PyInt_FromLong(0);
355
        if (embeddingMode){
356
                Py_DECREF(self->fontEmbedding);
357
                self->fontEmbedding = embeddingMode;
358
        } else {
359
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'fontEmbedding' attribute");
360
                return -1;
361
        }
418 Franz 362
// embed all used fonts
1745 subik 363
        PyObject *fonts = NULL;
364
        fonts = PyList_New(0);
365
        if (fonts){
366
                Py_DECREF(self->fonts);
367
                self->fonts = fonts;
368
        } else {
369
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'fonts' attribute");
370
                return -1;
371
        }
372
        // get all used fonts
19710 jghali 373
        QMap<QString,int> ReallyUsed = currentDoc->UsedFonts;
1745 subik 374
        // create list of all used fonts
20126 jghali 375
        QList<QString> tmpEm = ReallyUsed.keys();
376
        for (int i = 0; i < tmpEm.count(); ++i)
377
        {
378
                QString fontName = tmpEm.at(i);
379
                PyObject *tmp= NULL;
380
                tmp = PyString_FromString(fontName.toLatin1());
381
                if (tmp) {
382
                        PyList_Append(self->fonts, tmp);
418 Franz 383
// do i need Py_DECREF(tmp) here?
384
// Does PyList_Append increase reference or 'steal' one from provided argument
420 Franz 385
// If it 'steal' reference comment next line
20126 jghali 386
                        Py_DECREF(tmp);
387
                }
388
                else {
389
                        PyErr_SetString(PyExc_SystemError, "Can not initialize 'fonts' attribute");
390
                        return -1;
391
                }
1745 subik 392
        }
20092 jghali 393
// init subsetList
19699 jghali 394
        fonts = PyList_New(0);
395
        if (fonts){
20092 jghali 396
                Py_DECREF(self->subsetList);
397
                self->subsetList = fonts;
19699 jghali 398
        } else {
20092 jghali 399
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'subsetList' attribute");
19699 jghali 400
                return -1;
401
        }
402
// copied from TabPDFOptions::restoreDefaults()
19710 jghali 403
        for (int fe = 0; fe < pdfOptions.SubsetList.count(); ++fe)
19699 jghali 404
        {
405
                PyObject *tmp= NULL;
19710 jghali 406
                tmp = PyString_FromString(pdfOptions.SubsetList[fe].toLatin1().data());
19699 jghali 407
                if (tmp) {
20092 jghali 408
                        PyList_Append(self->subsetList, tmp);
19699 jghali 409
                        Py_DECREF(tmp);
410
                }
411
                else {
20092 jghali 412
                        PyErr_SetString(PyExc_SystemError, "Can not initialize 'subsetList' attribute");
19699 jghali 413
                        return -1;
414
                }
415
        }
416
 
418 Franz 417
// set to print all pages
1745 subik 418
        PyObject *pages = NULL;
419
        int num = 0;
420
        // which one should I use ???
5781 cbradney 421
        // new = ScCore->primaryMainWindow()->view->Pages.count()
19710 jghali 422
        num = currentDoc->Pages->count();
1745 subik 423
        pages = PyList_New(num);
424
        if (!pages){
425
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'pages' attribute");
426
                return -1;
427
        }
3819 subik 428
        for (i = 0; i<num; ++i) {
1745 subik 429
                PyObject *tmp;
430
                tmp = PyInt_FromLong((long)i+1L);
431
                if (tmp)
432
                        PyList_SetItem(pages, i, tmp);
433
                else {
434
                        PyErr_SetString(PyExc_SystemError, "Can not initialize 'pages' attribute");
435
                        return -1;
436
                }
437
        }
438
        Py_DECREF(self->pages);
439
        self->pages = pages;
14805 jghali 440
// print thumbnails ?
19710 jghali 441
        self->thumbnails = pdfOptions.Thumbnails;
14805 jghali 442
// output crop marks ?
19710 jghali 443
        self->cropMarks = pdfOptions.cropMarks;
14805 jghali 444
// output bleed marks ?
19710 jghali 445
        self->bleedMarks = pdfOptions.bleedMarks;
14805 jghali 446
// output registration marks ?
19710 jghali 447
        self->registrationMarks = pdfOptions.registrationMarks;
14805 jghali 448
// output color bars ?
19710 jghali 449
        self->colorMarks = pdfOptions.colorMarks;
19704 jghali 450
// output doc info marks ?
19710 jghali 451
        self->docInfoMarks = pdfOptions.docInfoMarks;
19704 jghali 452
// cropmarks offset 
19746 jghali 453
        self->markOffset = pdfOptions.markOffset * currentDoc->unitRatio();
454
// cropmarks length 
455
        self->markLength = pdfOptions.markLength * currentDoc->unitRatio();
418 Franz 456
// set automatic compression
19710 jghali 457
        self->compress = pdfOptions.Compress;
458
        self->compressmtd = pdfOptions.CompressMethod;
420 Franz 459
// use maximum image quality
19710 jghali 460
        self->quality = pdfOptions.Quality;
418 Franz 461
// default resolution
1745 subik 462
        PyObject *resolution = NULL;
463
        resolution = PyInt_FromLong(300);
464
        if (resolution){
465
                Py_DECREF(self->resolution);
466
                self->resolution = resolution;
467
        } else {
20126 jghali 468
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'resolution' attribute");
1745 subik 469
                return -1;
470
        }
418 Franz 471
// do not downsample images
19710 jghali 472
        int down = pdfOptions.RecalcPic ? pdfOptions.PicRes : 0;
1745 subik 473
        PyObject *downsample = NULL;
474
        downsample = PyInt_FromLong(down);
475
        if (downsample){
476
                Py_DECREF(self->downsample);
477
                self->downsample = downsample;
478
        } else {
479
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'downsamle' attribute");
480
                return -1;
481
        }
482
        // no bookmarks
19710 jghali 483
        self->bookmarks = pdfOptions.Bookmarks;
1745 subik 484
        // left margin binding
19710 jghali 485
        self->binding = pdfOptions.Binding;
1745 subik 486
        // do not enable presentation effects
19710 jghali 487
        self->presentation = pdfOptions.PresentMode;
1745 subik 488
        // set effects values for all pages
489
        PyObject *effval = NULL;
490
        num = 0;
491
        // which one should I use ???
5781 cbradney 492
        // new = ScCore->primaryMainWindow()->view->Pages.count();
19710 jghali 493
        num = currentDoc->Pages->count();
1745 subik 494
        effval = PyList_New(num);
495
        if (!effval){
496
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'effval' attribute");
497
                return -1;
498
        }
18394 fschmid 499
        for (i = 0; i < num; ++i)
500
        {
1745 subik 501
                PyObject *tmp;
19710 jghali 502
                PDFPresentationData t = currentDoc->Pages->at(i)->PresentVals;
1745 subik 503
                tmp = Py_BuildValue(const_cast<char*>("[iiiiii]"), t.pageEffectDuration, t.pageViewDuration, t.effectType, t.Dm, t.M, t.Di );
504
                if (tmp)
505
                        PyList_SetItem(effval, i, tmp);
506
                else {
507
                        PyErr_SetString(PyExc_SystemError, "Can not initialize 'effval' attribute");
508
                        return -1;
509
                }
510
                for (; i<num; ++i) {
511
                        PyObject *tmp;
512
                        tmp = Py_BuildValue(const_cast<char*>("[iiiiii]"), 1, 1, 0, 0, 0, 0);
513
                        if (tmp)
514
                                PyList_SetItem(effval, i, tmp);
515
                        else {
516
                                PyErr_SetString(PyExc_SystemError, "Can not initialize 'effval' attribute");
517
                                return -1;
518
                        }
519
                }
520
        }
521
        Py_DECREF(self->effval);
522
        self->effval = effval;
420 Franz 523
// do not save linked text frames as PDF article
19710 jghali 524
        self->article = pdfOptions.Articles;
420 Franz 525
// do not encrypt file
19710 jghali 526
        self->encrypt = pdfOptions.Encrypt;
420 Franz 527
// do not Use Custom Rendering Settings
19710 jghali 528
        self->uselpi = pdfOptions.UseLPI;
529
        self->usespot = pdfOptions.UseSpotColors;
530
        self->domulti = pdfOptions.doMultiFile;
418 Franz 531
// get default values for lpival
19710 jghali 532
        int n = pdfOptions.LPISettings.size();
1745 subik 533
        PyObject *lpival=PyList_New(n);
534
        if (!lpival){
535
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'lpival' attribute");
536
                return -1;
537
        }
19710 jghali 538
        QMap<QString,LPIData>::Iterator it = pdfOptions.LPISettings.begin();
539
        while (it != pdfOptions.LPISettings.end()) {
1745 subik 540
                PyObject *tmp;
18194 fschmid 541
                tmp = Py_BuildValue(const_cast<char*>("[siii]"), it.key().toLatin1().constData(), it.value().Frequency, it.value().Angle, it.value().SpotFunc);
1745 subik 542
                if (!tmp) {
543
                        PyErr_SetString(PyExc_SystemError, "Can not initialize 'lpival' attribute");
544
                        return -1;
545
                }
546
                PyList_SetItem(lpival, --n, tmp);
547
                ++it;
548
        }
549
        PyList_Reverse(lpival);
550
        Py_DECREF(self->lpival);
551
        self->lpival = lpival;
418 Franz 552
// set owner's password
1745 subik 553
        PyObject *owner = NULL;
19710 jghali 554
        owner = PyString_FromString(pdfOptions.PassOwner.toLatin1());
1745 subik 555
        if (owner){
556
                Py_DECREF(self->owner);
557
                self->owner = owner;
558
        } else {
559
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'owner' attribute");
560
                return -1;
561
        }
418 Franz 562
// set user'a password
1745 subik 563
        PyObject *user = NULL;
19710 jghali 564
        user = PyString_FromString(pdfOptions.PassUser.toLatin1());
1745 subik 565
        if (user){
566
                Py_DECREF(self->user);
567
                self->user = user;
568
        } else {
569
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'user' attribute");
570
                return -1;
571
        }
418 Franz 572
// allow printing document
20092 jghali 573
        self->allowPrinting = pdfOptions.Permissions & 4;
418 Franz 574
// allow changing document
20092 jghali 575
        self->allowChange = pdfOptions.Permissions & 8;
418 Franz 576
// allow copying document
20092 jghali 577
        self->allowCopy = pdfOptions.Permissions & 16;
418 Franz 578
// allow adding annotation and fields
20092 jghali 579
        self->allowAnnots = pdfOptions.Permissions & 32;
418 Franz 580
// use 1.4 pdf version *aka. Acrobat 5)
19710 jghali 581
        self->version = pdfOptions.Version;
418 Franz 582
// output destination is screen
19710 jghali 583
        self->outdst = pdfOptions.UseRGB ? 0 : 1;
420 Franz 584
 
19710 jghali 585
        self->profiles = pdfOptions.UseProfiles; // bool
586
        self->profilei = pdfOptions.UseProfiles2; // bool
587
        self->noembicc = pdfOptions.EmbeddedI; // bool
588
        self->intents = pdfOptions.Intent; // int - 0 - 3
589
        self->intenti = pdfOptions.Intent2; // int - 0 - 3
590
        QString tp = pdfOptions.SolidProf;
5243 cbradney 591
        if (!ScCore->InputProfiles.contains(tp))
19710 jghali 592
                tp = currentDoc->cmsSettings().DefaultSolidColorRGBProfile;
1745 subik 593
        PyObject *solidpr = NULL;
18194 fschmid 594
        solidpr = PyString_FromString(tp.toLatin1());
1745 subik 595
        if (solidpr){
596
                Py_DECREF(self->solidpr);
597
                self->solidpr = solidpr;
598
        } else {
599
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'solidpr' attribute");
600
                return -1;
601
        }
19710 jghali 602
        QString tp2 = pdfOptions.ImageProf;
5243 cbradney 603
        if (!ScCore->InputProfiles.contains(tp2))
19710 jghali 604
                tp2 = currentDoc->cmsSettings().DefaultSolidColorRGBProfile;
1745 subik 605
        PyObject *imagepr = NULL;
18194 fschmid 606
        imagepr = PyString_FromString(tp2.toLatin1());
1745 subik 607
        if (imagepr){
608
                Py_DECREF(self->imagepr);
609
                self->imagepr = imagepr;
610
        } else {
611
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'imagepr' attribute");
612
                return -1;
613
        }
19710 jghali 614
        QString tp3 = pdfOptions.PrintProf;
5243 cbradney 615
        if (!ScCore->PDFXProfiles.contains(tp3))
19710 jghali 616
                tp3 = currentDoc->cmsSettings().DefaultPrinterProfile;
1745 subik 617
        PyObject *printprofc = NULL;
18194 fschmid 618
        printprofc = PyString_FromString(tp3.toLatin1());
1745 subik 619
        if (printprofc){
620
                Py_DECREF(self->printprofc);
621
                self->printprofc = printprofc;
622
        } else {
623
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'printprofc' attribute");
624
                return -1;
625
        }
19710 jghali 626
        QString tinfo = pdfOptions.Info;
1745 subik 627
        PyObject *info = NULL;
18194 fschmid 628
        info = PyString_FromString(tinfo.toLatin1());
1745 subik 629
        if (info){
630
                Py_DECREF(self->info);
631
                self->info = info;
632
        } else {
633
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'info' attribute");
634
                return -1;
635
        }
19831 craig 636
        self->bleedt = pdfOptions.bleeds.top() * currentDoc->unitRatio(); // double -
637
        self->bleedl = pdfOptions.bleeds.left() * currentDoc->unitRatio(); // double -
638
        self->bleedr = pdfOptions.bleeds.right() * currentDoc->unitRatio(); // double -
639
        self->bleedb = pdfOptions.bleeds.bottom() * currentDoc->unitRatio(); // double -
20092 jghali 640
        self->useDocBleeds = pdfOptions.useDocBleeds; // bool
19710 jghali 641
        self->useLayers = pdfOptions.useLayers; // bool
642
        self->embedPDF = pdfOptions.embedPDF; // bool
643
        self->mirrorH = pdfOptions.MirrorH; // bool
644
        self->mirrorV = pdfOptions.MirrorV; // bool
645
        self->doClip = pdfOptions.doClip; // bool
20092 jghali 646
        PyObject *rotateDeg = NULL;
647
        rotateDeg = PyInt_FromLong(0);
648
        if (rotateDeg){
649
                Py_DECREF(self->rotateDeg);
650
                self->rotateDeg = rotateDeg;
19699 jghali 651
        } else {
20092 jghali 652
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'rotateDeg' attribute");
19699 jghali 653
                return -1;
654
        }
19710 jghali 655
        self->isGrayscale = pdfOptions.isGrayscale; // bool
656
        self->pageLayout = pdfOptions.PageLayout; // int
657
        self->displayBookmarks = pdfOptions.displayBookmarks; // bool
658
        self->displayThumbs = pdfOptions.displayThumbs; // bool
659
        self->displayLayers = pdfOptions.displayLayers; // bool
660
        self->displayFullscreen = pdfOptions.displayFullscreen; // bool
661
        self->hideToolBar = pdfOptions.hideToolBar; // bool
662
        self->hideMenuBar = pdfOptions.hideMenuBar; // bool
663
        self->fitWindow = pdfOptions.fitWindow; // bool
420 Franz 664
 
19699 jghali 665
        PyObject *openAction = NULL;
19710 jghali 666
        openAction = PyString_FromString(pdfOptions.openAction.toLatin1().data());
19699 jghali 667
        if (openAction){
668
                Py_DECREF(self->openAction);
669
                self->openAction = openAction;
670
        } else {
671
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'openAction' attribute");
672
                return -1;
673
        }
674
 
1745 subik 675
        return 0;
418 Franz 676
}
677
 
678
static PyMemberDef PDFfile_members[] = {
1745 subik 679
        {const_cast<char*>("thumbnails"), T_INT, offsetof(PDFfile, thumbnails), 0, const_cast<char*>("Generate thumbnails. Bool value.")},
19710 jghali 680
        {const_cast<char*>("cropMarks"), T_INT, offsetof(PDFfile, cropMarks), 0, const_cast<char*>("Create crop marks in the PDF indicating where the paper should be cut or trimmed after printing.")},
19704 jghali 681
        {const_cast<char*>("bleedMarks"), T_INT, offsetof(PDFfile, bleedMarks), 0, const_cast<char*>("Create marks delimiting the bleed area.")},
682
        {const_cast<char*>("registrationMarks"), T_INT, offsetof(PDFfile, registrationMarks), 0, const_cast<char*>("Add registration marks to each separation.")},
683
        {const_cast<char*>("colorMarks"), T_INT, offsetof(PDFfile, colorMarks), 0, const_cast<char*>("Add color calibration bars.")},
684
        {const_cast<char*>("docInfoMarks"), T_INT, offsetof(PDFfile, docInfoMarks), 0, const_cast<char*>("Add document information which includes the document title and page numbers.")},
685
        {const_cast<char*>("markOffset"), T_DOUBLE, offsetof(PDFfile, markOffset), 0, const_cast<char*>("Indicate the distance offset between mark and page area.")},
19746 jghali 686
        {const_cast<char*>("markLength"), T_DOUBLE, offsetof(PDFfile, markLength), 0, const_cast<char*>("Indicate the length of crop and bleed marks.")},
1745 subik 687
        {const_cast<char*>("compress"), T_INT, offsetof(PDFfile, compress), 0, const_cast<char*>("Compression switch. Bool value.")},
688
        {const_cast<char*>("compressmtd"), T_INT, offsetof(PDFfile, compressmtd), 0, const_cast<char*>("Compression method.\n\t0 - Automatic\n\t1 - JPEG\n\t2 - zip\n\t3 - None.")},
689
        {const_cast<char*>("quality"), T_INT, offsetof(PDFfile, quality), 0, const_cast<char*>("Image quality\n\t0 - Maximum\n\t1 - High\n\t2 - Medium\n\t3 - Low\n\t4 - Minimum")},
690
        {const_cast<char*>("bookmarks"), T_INT, offsetof(PDFfile, bookmarks), 0, const_cast<char*>("Embed the bookmarks you created in your document.\nThese are useful for navigating long PDF documents.\nBool value")},
691
        {const_cast<char*>("binding"), T_INT, offsetof(PDFfile, binding), 0, const_cast<char*>("Choose binding.\n\t0 - Left binding\n\t1 - Right binding")},
692
        {const_cast<char*>("presentation"), T_INT, offsetof(PDFfile, presentation), 0, const_cast<char*>("Enable Presentation Effects.Bool value")},
693
        {const_cast<char*>("article"), T_INT, offsetof(PDFfile, article), 0, const_cast<char*>("Save Linked Text Frames as PDF Articles\n\tBool value")},
694
        {const_cast<char*>("encrypt"), T_INT, offsetof(PDFfile, encrypt), 0, const_cast<char*>("Use Encription. Bool value")},
695
        {const_cast<char*>("uselpi"), T_INT, offsetof(PDFfile, uselpi), 0, const_cast<char*>("Use Custom Rendering Settings. Bool value")},
3079 fschmid 696
        {const_cast<char*>("usespot"), T_INT, offsetof(PDFfile, usespot), 0, const_cast<char*>("Use Spot Colors. Bool value")},
697
        {const_cast<char*>("domulti"), T_INT, offsetof(PDFfile, domulti), 0, const_cast<char*>("Produce a PDF File for every Page. Bool value")},
20092 jghali 698
        {const_cast<char*>("allowPrinting"), T_INT, offsetof(PDFfile, allowPrinting), 0, const_cast<char*>("Allow Printing the Document. Bool value")},
699
        {const_cast<char*>("allowChange"), T_INT, offsetof(PDFfile, allowChange), 0, const_cast<char*>("Allow Changing the Document. Bool value")},
700
        {const_cast<char*>("allowCopy"), T_INT, offsetof(PDFfile, allowCopy), 0, const_cast<char*>("Allow Copying Text and Graphics. Bool value")},
701
        {const_cast<char*>("allowAnnots"), T_INT, offsetof(PDFfile, allowAnnots), 0, const_cast<char*>("Allow Adding Annotations and Fields. Bool value")},
19463 jghali 702
        {const_cast<char*>("version"), T_INT, offsetof(PDFfile, version), 0, const_cast<char*>("Choose PDF version to use:\n\t10 = PDF/X4\n\t11 = PDF/X1a\n\t12 = PDF/X-3\n\t13 = PDF 1.3 (Acrobat 4)\n\t14 = PDF 1.4 (Acrobat 5)\n\t15 = PDF 1.5 (Acrobat 6)")},
1745 subik 703
        {const_cast<char*>("outdst"), T_INT, offsetof(PDFfile, outdst), 0, const_cast<char*>("Output destination.\n\t0 - screen\n\t1 - printer")},
704
        {const_cast<char*>("profiles"), T_INT, offsetof(PDFfile, profiles), 0, const_cast<char*>("Embed a color profile for solid colors. Bool value.")},
705
        {const_cast<char*>("profilei"), T_INT, offsetof(PDFfile, profilei), 0, const_cast<char*>("Embed a color profile for images. Bool value.")},
706
        {const_cast<char*>("intents"), T_INT, offsetof(PDFfile, intents), 0, const_cast<char*>("Rendering intent for solid colors\n\t0 - Perceptual\n\t1 - Relative Colorimetric\n\t2 - Saturation\n\t3 - Absolute Colorimetric")},
707
        {const_cast<char*>("intenti"), T_INT, offsetof(PDFfile, intenti), 0, const_cast<char*>("Rendering intent for images\n\t0 - Perceptual\n\t1 - Relative Colorimetric\n\t2 - Saturation\n\t3 - Absolute Colorimetric")},
708
        {const_cast<char*>("noembicc"), T_INT, offsetof(PDFfile, noembicc), 0, const_cast<char*>("Don't use embedded ICC profiles. Bool value")},
709
        {const_cast<char*>("bleedt"), T_DOUBLE, offsetof(PDFfile, bleedt), 0, const_cast<char*>("Bleed Top\n""Distance for bleed from the top of the physical page")},
710
        {const_cast<char*>("bleedl"), T_DOUBLE, offsetof(PDFfile, bleedl), 0, const_cast<char*>("Bleed Left\n""Distance for bleed from the left of the physical page")},
711
        {const_cast<char*>("bleedr"), T_DOUBLE, offsetof(PDFfile, bleedr), 0, const_cast<char*>("Bleed Right\n""Distance for bleed from the right of the physical page")},
712
        {const_cast<char*>("bleedb"), T_DOUBLE, offsetof(PDFfile, bleedb), 0, const_cast<char*>("Bleed Bottom\n""Distance for bleed from the bottom of the physical page")},
20092 jghali 713
        {const_cast<char*>("useDocBleeds"), T_INT, offsetof(PDFfile, useDocBleeds), 0, const_cast<char*>("Use the existing bleed settings from the document preferences. Bool value")},
19699 jghali 714
        {const_cast<char*>("useLayers"), T_INT, offsetof(PDFfile, useLayers), 0, const_cast<char*>("Layers in your document are exported to the PDF Only available if PDF 1.5 is chosen.")},
19704 jghali 715
        {const_cast<char*>("embedPDF"), T_INT, offsetof(PDFfile, embedPDF), 0, const_cast<char*>("Export EPS and PDFs in image frames as embedded PDFs. This does *not* yet take care of colorspaces, so you should know what you are doing before setting this to 'true'.")},
716
        {const_cast<char*>("mirrorH"), T_INT, offsetof(PDFfile, mirrorH), 0, const_cast<char*>("Mirror Page(s) horizontally")},
717
        {const_cast<char*>("mirrorV"), T_INT, offsetof(PDFfile, mirrorV), 0, const_cast<char*>("Mirror Page(s) vertically")},
19699 jghali 718
        {const_cast<char*>("doClip"), T_INT, offsetof(PDFfile, doClip), 0, const_cast<char*>("Do not show objects outside the margins in the exported file")},
719
        {const_cast<char*>("isGrayscale"), T_INT, offsetof(PDFfile, isGrayscale), 0, const_cast<char*>("Export PDF in grayscale")},
19704 jghali 720
        {const_cast<char*>("pageLayout"), T_INT, offsetof(PDFfile, pageLayout), 0, const_cast<char*>("Document layout in PDF viewer:\n"
19699 jghali 721
                                                                                                     "\t0 - Show the document in single page mode\n"
722
                                                                                                     "\t1 - Show the document in single page mode with the pages displayed continuously end to end like a scroll\n"
723
                                                                                                     "\t2 - Show the document with facing pages, starting with the first page displayed on the left\n"
724
                                                                                                     "\t3 - Show the document with facing pages, starting with the first page displayed on the right"
725
                                                                                                     )},
726
        {const_cast<char*>("displayBookmarks"), T_INT, offsetof(PDFfile, displayBookmarks), 0, const_cast<char*>("Display the bookmarks upon opening")},
727
        {const_cast<char*>("displayThumbs"), T_INT, offsetof(PDFfile, displayThumbs), 0, const_cast<char*>("Display the page thumbnails upon opening")},
19704 jghali 728
        {const_cast<char*>("displayLayers"), T_INT, offsetof(PDFfile, displayLayers), 0, const_cast<char*>("Display the layer list upon opening. Useful only for PDF 1.5+.")},
729
        {const_cast<char*>("displayFullscreen"), T_INT, offsetof(PDFfile, displayFullscreen), 0, const_cast<char*>("Display the document in full screen mode upon opening.")},
19710 jghali 730
        {const_cast<char*>("hideToolBar"), T_INT, offsetof(PDFfile, hideToolBar), 0, const_cast<char*>("Hide the viewer toolbar. The toolbar has usually selection and other editing capabilities.")},
731
        {const_cast<char*>("hideMenuBar"), T_INT, offsetof(PDFfile, hideMenuBar), 0, const_cast<char*>("Hide the viewer menu bar, the PDF will display in a plain window.")},
19699 jghali 732
        {const_cast<char*>("fitWindow"), T_INT, offsetof(PDFfile, fitWindow), 0, const_cast<char*>("Fit the document page or pages to the available space in the viewer window.")},
20092 jghali 733
        /** Deprecated members */
734
        {const_cast<char*>("aprint"), T_INT, offsetof(PDFfile, allowPrinting), 0, const_cast<char*>("Deprecated. Use 'allowPrinting' instead.")},
735
        {const_cast<char*>("achange"), T_INT, offsetof(PDFfile, allowChange), 0, const_cast<char*>("Deprecated. Use 'allowChange' instead.")},
736
        {const_cast<char*>("acopy"), T_INT, offsetof(PDFfile, allowCopy), 0, const_cast<char*>("Deprecated. Use 'allowCopy' instead.")},
737
        {const_cast<char*>("aanot"), T_INT, offsetof(PDFfile, allowAnnots), 0, const_cast<char*>("Deprecated. Use 'allowAnnots' instead.")},
1745 subik 738
        {NULL, 0, 0, 0, NULL} // sentinel
418 Franz 739
};
740
 
741
 
742
/* Here begins Getter & Setter functions */
743
 
10778 craig 744
static PyObject *PDFfile_getfile(PDFfile *self, void * /*closure*/)
418 Franz 745
{
1745 subik 746
        Py_INCREF(self->file);
747
        return self->file;
418 Franz 748
}
749
 
10778 craig 750
static int PDFfile_setfile(PDFfile *self, PyObject *value, void * /*closure*/)
418 Franz 751
{
1745 subik 752
        if (value == NULL) {
753
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'file' attribute.");
754
                return -1;
755
        }
756
        if (!PyString_Check(value)) {
757
                PyErr_SetString(PyExc_TypeError, "The 'file' attribute value must be string.");
758
                return -1;
759
        }
760
        Py_DECREF(self->file);
761
        Py_INCREF(value);
762
        self->file = value;
763
        return 0;
418 Franz 764
}
765
 
20126 jghali 766
static PyObject *PDFfile_getFontEmbeddingMode(PDFfile *self, void * /*closure*/)
767
{
768
        Py_INCREF(self->fontEmbedding);
769
        return self->fontEmbedding;
770
}
771
 
772
static int PDFfile_setFontEmbeddingMode(PDFfile *self, PyObject *value, void * /*closure*/)
773
{
774
        if (value == NULL) {
775
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'fontEmbedding' attribute.");
776
                return -1;
777
        }
778
        if (!PyInt_Check(value)) {
779
                PyErr_SetString(PyExc_TypeError, "'fontEmbedding' attribute value must be integer.");
780
                return -1;
781
        }
782
        int n = PyInt_AsLong(value);
783
        if (n < 0 || n > 2) {
784
                PyErr_SetString(PyExc_ValueError, "'fontEmbedding' value must be an integer between 0 and 2");
785
                return -1;
786
        }
787
        Py_DECREF(self->fontEmbedding);
788
        Py_INCREF(value);
789
        self->fontEmbedding = value;
790
        return 0;
791
}
792
 
10778 craig 793
static PyObject *PDFfile_getfonts(PDFfile *self, void * /*closure*/)
418 Franz 794
{
1745 subik 795
        Py_INCREF(self->fonts);
796
        return self->fonts;
418 Franz 797
}
798
 
10778 craig 799
static int PDFfile_setfonts(PDFfile *self, PyObject *value, void * /*closure*/)
418 Franz 800
{
1745 subik 801
        if (value == NULL) {
802
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'fonts' attribute.");
803
                return -1;
804
        }
805
        if (!PyList_Check(value)) {
806
                PyErr_SetString(PyExc_TypeError, "The 'fonts' attribute value must be list of strings.");
807
                return -1;
808
        }
809
        int n;
810
        n = PyList_Size(value);
811
        for (int i=0; i<n; ++i)
812
                if (!PyString_Check(PyList_GetItem(value, i))) {
813
                        PyErr_SetString(PyExc_TypeError, "The 'fonts' list must contain only strings.");
814
                        return -1;
815
                }
418 Franz 816
// Do I need to check if supplied string is really
817
// name of available font???
818
// this is not implemented yet
1745 subik 819
        Py_DECREF(self->fonts);
820
        Py_INCREF(value);
821
        self->fonts = value;
822
        PyList_Sort(self->fonts);
823
        return 0;
418 Franz 824
}
825
 
19699 jghali 826
static PyObject *PDFfile_getSubsetList(PDFfile *self, void * /*closure*/)
827
{
20092 jghali 828
        Py_INCREF(self->subsetList);
829
        return self->subsetList;
19699 jghali 830
}
831
 
832
static int PDFfile_setSubsetList(PDFfile *self, PyObject *value, void * /*closure*/)
833
{
834
        if (value == NULL) {
20092 jghali 835
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'subsetList' attribute.");
19699 jghali 836
                return -1;
837
        }
838
        if (!PyList_Check(value)) {
20092 jghali 839
                PyErr_SetString(PyExc_TypeError, "The 'subsetList' attribute value must be list of strings.");
19699 jghali 840
                return -1;
841
        }
842
        int n;
843
        n = PyList_Size(value);
844
        for (int i=0; i<n; ++i)
845
                if (!PyString_Check(PyList_GetItem(value, i))) {
20092 jghali 846
                        PyErr_SetString(PyExc_TypeError, "The 'subsetList' list must contain only strings.");
19699 jghali 847
                        return -1;
848
                }
20092 jghali 849
        Py_DECREF(self->subsetList);
19699 jghali 850
        Py_INCREF(value);
20092 jghali 851
        self->subsetList = value;
852
        PyList_Sort(self->subsetList);
19699 jghali 853
        return 0;
854
}
855
 
10778 craig 856
static PyObject *PDFfile_getpages(PDFfile *self, void * /*closure*/)
418 Franz 857
{
1745 subik 858
        Py_INCREF(self->pages);
859
        return self->pages;
418 Franz 860
}
861
 
10778 craig 862
static int PDFfile_setpages(PDFfile *self, PyObject *value, void * /*closure*/)
418 Franz 863
{
1745 subik 864
        if (value == NULL) {
865
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'pages' attribute.");
866
                return -1;
867
        }
868
        if (!PyList_Check(value)) {
869
                PyErr_SetString(PyExc_TypeError, "'pages' attribute value must be list of integers.");
870
                return -1;
871
        }
872
        int len = PyList_Size(value);
873
        for (int i = 0; i<len; i++){
874
                PyObject *tmp = PyList_GetItem(value, i);
875
                // I did not check if tmp is NULL
876
                // how can PyList_GetItem fail in this case (my guess: short of available memory?)
877
                // Also do I need Py_INCREF or Py_DECREF here?
878
                if (!PyInt_Check(tmp)){
879
                        PyErr_SetString(PyExc_TypeError, "'pages' list must contain only integers.");
880
                        return -1;
881
                }
5781 cbradney 882
                if (PyInt_AsLong(tmp) > static_cast<int>(ScCore->primaryMainWindow()->doc->Pages->count()) || PyInt_AsLong(tmp) < 1) {
1745 subik 883
                        PyErr_SetString(PyExc_ValueError, "'pages' value out of range.");
884
                        return -1;
885
                }
886
        }
887
        Py_DECREF(self->pages);
888
        Py_INCREF(value);
889
        self->pages = value;
890
        return 0;
418 Franz 891
}
892
 
893
 
10778 craig 894
static PyObject *PDFfile_getresolution(PDFfile *self, void * /*closure*/)
418 Franz 895
{
1745 subik 896
        Py_INCREF(self->resolution);
897
        return self->resolution;
418 Franz 898
}
899
 
10778 craig 900
static int PDFfile_setresolution(PDFfile *self, PyObject *value, void * /*closure*/)
418 Franz 901
{
1745 subik 902
        if (value == NULL) {
903
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'resolution' attribute.");
904
                return -1;
905
        }
906
        if (!PyInt_Check(value)) {
907
                PyErr_SetString(PyExc_TypeError, "'resolution' attribute value must be integer.");
908
                return -1;
909
        }
910
        int n = PyInt_AsLong(value);
911
        if (n<35 || n>4000) {
19574 jghali 912
                PyErr_SetString(PyExc_ValueError, "'resolution' value must be in interval from 35 to 4000");
1745 subik 913
                return -1;
914
        }
915
        Py_DECREF(self->resolution);
916
        Py_INCREF(value);
917
        self->resolution = value;
918
        return 0;
418 Franz 919
}
920
 
10778 craig 921
static PyObject *PDFfile_getdownsample(PDFfile *self, void * /*closure*/)
418 Franz 922
{
1745 subik 923
        Py_INCREF(self->downsample);
924
        return self->downsample;
418 Franz 925
}
926
 
10778 craig 927
static int PDFfile_setdownsample(PDFfile *self, PyObject *value, void * /*closure*/)
418 Franz 928
{
1745 subik 929
        if (value == NULL) {
930
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'downsample' attribute.");
931
                return -1;
932
        }
933
        if (!PyInt_Check(value)) {
934
                PyErr_SetString(PyExc_TypeError, "'downsample' attribute value must be integer.");
935
                return -1;
936
        }
937
        int n = PyInt_AsLong(value);
938
        if (n!=0 && (n<35 || n>PyInt_AsLong(self->resolution))) {
20126 jghali 939
                PyErr_SetString(PyExc_TypeError, "'downsample' value must be 0 or in interval from 35 to value of 'resolution'");
1745 subik 940
                return -1;
941
        }
942
        Py_DECREF(self->downsample);
943
        Py_INCREF(value);
944
        self->downsample = value;
945
        return 0;
418 Franz 946
}
947
 
10778 craig 948
static PyObject *PDFfile_geteffval(PDFfile *self, void * /*closure*/)
418 Franz 949
{
1745 subik 950
        Py_INCREF(self->effval);
951
        return self->effval;
418 Franz 952
}
953
 
10778 craig 954
static int PDFfile_seteffval(PDFfile *self, PyObject *value, void * /*closure*/)
418 Franz 955
{
1745 subik 956
        if (value == NULL) {
957
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'effval' attribute.");
958
                return -1;
959
        }
960
        if (!PyList_Check(value)) {
961
                PyErr_SetString(PyExc_TypeError, "'effval' must be list.");
962
                return -1;
963
        }
964
        int n = PyList_Size(value);
965
        for (int i=0; i<n; ++i) {
966
                PyObject *tmp = PyList_GetItem(value, i);
967
                if (!PyList_Check(tmp)) {
968
                        PyErr_SetString(PyExc_TypeError, "elemets of 'effval' must be list of five integers.");
969
                        return -1;
970
                }
971
                int j = PyList_Size(tmp);
972
                if (j != 6) {
973
                        PyErr_SetString(PyExc_TypeError, "elemets of 'effval' must have exactly six integers.");
974
                        return -1;
975
                }
976
                for ( --j; j > -1; --j) {
977
                        if (!PyInt_Check(PyList_GetItem(tmp, j))) {
978
                                PyErr_SetString(PyExc_TypeError, "innermost element of 'effval' must be integers.");
979
                                return -1;
980
                        }
981
                }
982
        }
983
        Py_DECREF(self->effval);
984
        Py_INCREF(value);
985
        self->effval = value;
986
        return 0;
418 Franz 987
}
988
 
10778 craig 989
static PyObject *PDFfile_getlpival(PDFfile *self, void * /*closure*/)
418 Franz 990
{
1745 subik 991
        Py_INCREF(self->lpival);
992
        return self->lpival;
418 Franz 993
}
994
 
10778 craig 995
static int PDFfile_setlpival(PDFfile *self, PyObject *value, void * /*closure*/)
418 Franz 996
{
1745 subik 997
        if (value == NULL) {
998
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'lpival' attribute.");
999
                return -1;
1000
        }
1001
        if (!PyList_Check(value)) {
1002
                PyErr_SetString(PyExc_TypeError, "'lpival' must be list.");
1003
                return -1;
1004
        }
1005
        // Do I need Py_INCREF or Py_DECREF here?
1006
        int n = PyList_Size(value);
1007
        for (int i=0; i<n; ++i) {
1008
                PyObject *tmp = PyList_GetItem(value, i);
1009
                if (!PyList_Check(tmp)) {
1010
                        PyErr_SetString(PyExc_TypeError, "elemets of 'lpival' must be list of five integers.");
1011
                        return -1;
1012
                }
1013
                int j = PyList_Size(tmp);
1014
                if (j != 4) {
1015
                        PyErr_SetString(PyExc_TypeError, "elemets of 'lpival' must have exactly four members.");
1016
                        return -1;
1017
                }
1018
                for ( --j; j > 0; --j) {
1019
                        if (!PyInt_Check(PyList_GetItem(tmp, j))) {
1020
                                PyErr_SetString(PyExc_TypeError, "'lpival'elements must have structure [siii]");
1021
                                return -1;
1022
                        }
1023
                }
1024
                if (!PyString_Check(PyList_GetItem(tmp, 0))) {
1025
                        PyErr_SetString(PyExc_TypeError, "'lpival'elements must have structure [siii]");
1026
                        return -1;
1027
                }
1028
        }
1029
        Py_DECREF(self->lpival);
1030
        Py_INCREF(value);
1031
        self->lpival = value;
1032
        return 0;
418 Franz 1033
}
1034
 
10778 craig 1035
static PyObject *PDFfile_getowner(PDFfile *self, void * /*closure*/)
418 Franz 1036
{
1745 subik 1037
        Py_INCREF(self->owner);
1038
        return self->owner;
418 Franz 1039
}
1040
 
10778 craig 1041
static int PDFfile_setowner(PDFfile *self, PyObject *value, void * /*closure*/)
418 Franz 1042
{
1745 subik 1043
        if (value == NULL) {
1044
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'owner' attribute.");
1045
                return -1;
1046
        }
1047
        if (!PyString_Check(value)) {
1048
                PyErr_SetString(PyExc_TypeError, "'owner' attribute value must be string.");
1049
                return -1;
1050
        }
1051
        Py_DECREF(self->owner);
1052
        Py_INCREF(value);
1053
        self->owner = value;
1054
        return 0;
418 Franz 1055
}
1056
 
10778 craig 1057
static PyObject *PDFfile_getuser(PDFfile *self, void * /*closure*/)
418 Franz 1058
{
1745 subik 1059
        Py_INCREF(self->user);
1060
        return self->user;
418 Franz 1061
}
1062
 
10778 craig 1063
static int PDFfile_setuser(PDFfile *self, PyObject *value, void * /*closure*/)
418 Franz 1064
{
1745 subik 1065
        if (value == NULL) {
1066
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'user' attribute.");
1067
                return -1;
1068
        }
1069
        if (!PyString_Check(value)) {
1070
                PyErr_SetString(PyExc_TypeError, "'user' attribute value must be string.");
1071
                return -1;
1072
        }
1073
        Py_DECREF(self->user);
1074
        Py_INCREF(value);
1075
        self->user = value;
1076
        return 0;
418 Franz 1077
}
1078
 
10778 craig 1079
static PyObject *PDFfile_getsolidpr(PDFfile *self, void * /*closure*/)
418 Franz 1080
{
1745 subik 1081
        Py_INCREF(self->solidpr);
1082
        return self->solidpr;
418 Franz 1083
}
1084
 
10778 craig 1085
static int PDFfile_setsolidpr(PDFfile *self, PyObject *value, void * /*closure*/)
418 Franz 1086
{
1745 subik 1087
        if (value == NULL) {
1088
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'solidpr' attribute.");
1089
                return -1;
1090
        }
1091
        if (!PyString_Check(value)) {
1092
                PyErr_SetString(PyExc_TypeError, "The 'solidpr' attribute value must be string.");
1093
                return -1;
1094
        }
1095
        Py_DECREF(self->solidpr);
1096
        Py_INCREF(value);
1097
        self->solidpr = value;
1098
        return 0;
418 Franz 1099
}
1100
 
10778 craig 1101
static PyObject *PDFfile_getimagepr(PDFfile *self, void * /*closure*/)
418 Franz 1102
{
1745 subik 1103
        Py_INCREF(self->imagepr);
1104
        return self->imagepr;
418 Franz 1105
}
1106
 
10778 craig 1107
static int PDFfile_setimagepr(PDFfile *self, PyObject *value, void * /*closure*/)
418 Franz 1108
{
1745 subik 1109
        if (value == NULL) {
1110
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'imagepr' attribute.");
1111
                return -1;
1112
        }
1113
        if (!PyString_Check(value)) {
1114
                PyErr_SetString(PyExc_TypeError, "The 'imagepr' attribute value must be string.");
1115
                return -1;
1116
        }
1117
        Py_DECREF(self->imagepr);
1118
        Py_INCREF(value);
1119
        self->imagepr = value;
1120
        return 0;
418 Franz 1121
}
1122
 
10778 craig 1123
static PyObject *PDFfile_getprintprofc(PDFfile *self, void * /*closure*/)
418 Franz 1124
{
1745 subik 1125
        Py_INCREF(self->printprofc);
1126
        return self->printprofc;
418 Franz 1127
}
1128
 
10778 craig 1129
static int PDFfile_setprintprofc(PDFfile *self, PyObject *value, void * /*closure*/)
418 Franz 1130
{
1745 subik 1131
        if (value == NULL) {
1132
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'printprofc' attribute.");
1133
                return -1;
1134
        }
1135
        if (!PyString_Check(value)) {
1136
                PyErr_SetString(PyExc_TypeError, "The 'printprofc' attribute value must be string.");
1137
                return -1;
1138
        }
1139
        Py_DECREF(self->printprofc);
1140
        Py_INCREF(value);
1141
        self->printprofc = value;
1142
        return 0;
418 Franz 1143
}
1144
 
10778 craig 1145
static PyObject *PDFfile_getinfo(PDFfile *self, void * /*closure*/)
418 Franz 1146
{
1745 subik 1147
        Py_INCREF(self->info);
1148
        return self->info;
418 Franz 1149
}
1150
 
10778 craig 1151
static int PDFfile_setinfo(PDFfile *self, PyObject *value, void * /*closure*/)
418 Franz 1152
{
1745 subik 1153
        if (value == NULL) {
1154
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'info' attribute.");
1155
                return -1;
1156
        }
1157
        if (!PyString_Check(value)) {
1158
                PyErr_SetString(PyExc_TypeError, "The 'info' attribute value must be string.");
1159
                return -1;
1160
        }
1161
        Py_DECREF(self->info);
1162
        Py_INCREF(value);
1163
        self->info = value;
1164
        return 0;
418 Franz 1165
}
1166
 
19699 jghali 1167
static PyObject *PDFfile_getRotateDeg(PDFfile *self, void * /*closure*/)
1168
{
20092 jghali 1169
        Py_INCREF(self->rotateDeg);
1170
        return self->rotateDeg;
19699 jghali 1171
}
1172
 
1173
static int PDFfile_setRotateDeg(PDFfile *self, PyObject *value, void * /*closure*/)
1174
{
1175
        if (value == NULL) {
20092 jghali 1176
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'rotateDeg' attribute.");
19699 jghali 1177
                return -1;
1178
        }
1179
        if (!PyInt_Check(value)) {
20092 jghali 1180
                PyErr_SetString(PyExc_TypeError, "'rotateDeg' attribute value must be integer.");
19699 jghali 1181
                return -1;
1182
        }
1183
        int n = PyInt_AsLong(value);
1184
        if (n!=0 && n!=90 && n!=180 && n!=270) {
20092 jghali 1185
                PyErr_SetString(PyExc_TypeError, "'rotateDeg' value must be 0 or 90 or 180 or 270");
19699 jghali 1186
                return -1;
1187
        }
20092 jghali 1188
        Py_DECREF(self->rotateDeg);
19699 jghali 1189
        Py_INCREF(value);
20092 jghali 1190
        self->rotateDeg = value;
19699 jghali 1191
        return 0;
1192
}
1193
 
1194
static PyObject *PDFfile_getopenAction(PDFfile *self, void * /*closure*/)
1195
{
1196
        Py_INCREF(self->openAction);
1197
        return self->openAction;
1198
}
1199
 
1200
static int PDFfile_setopenAction(PDFfile *self, PyObject *value, void * /*closure*/)
1201
{
1202
        if (value == NULL) {
1203
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'openAction' attribute.");
1204
                return -1;
1205
        }
1206
        if (!PyString_Check(value)) {
1207
                PyErr_SetString(PyExc_TypeError, "'openAction' attribute value must be string.");
1208
                return -1;
1209
        }
1210
        Py_DECREF(self->openAction);
1211
        Py_INCREF(value);
1212
        self->openAction = value;
1213
        return 0;
1214
}
1215
 
1745 subik 1216
static char *effval_doc = const_cast<char*>(
420 Franz 1217
"List of effection values for each saved page.\n"
1218
"It is list of list of six integers. Those int has followin meaning:\n\t"
1219
"- Length of time the page is shown before the presentation\n\tstarts on the selected page. (1-3600)\n\t"
1220
"- Length of time the effect runs. (1 - 3600)\n\t\tA shorter time will speed up the effect,\n\t\ta longer one will slow it down\n\t"
1221
"- Type of the display effect\n\t\t0 - No Effect\n\t\t1 - Blinds\n\t\t2 - Box\n\t\t3 - Dissolve\n\t\t4 - Glitter\n\t\t5 - Split\n\t\t6 - Wipe\n\t"
1222
"- Direction of the effect of moving lines\n\tfor the split and blind effects.\n\t\t0 - Horizontal\n\t\t1 - Vertical\n\t"
1223
"- Starting position for the box and split effects.\n\t\t0 - Inside\n\t\t1 - Outside\n\t"
1745 subik 1224
"- Direction of the glitter or wipe effects.\n\t\t0 - Left to Right\n\t\t1 - Top to Bottom\n\t\t2 - Bottom to Top\n\t\t3 - Right to Left\n\t\t4 - Top-left to Bottom-Right");
418 Franz 1225
 
1745 subik 1226
static char *lpival_doc = const_cast<char*>(
418 Franz 1227
"Rendering Settings for individual colors.\n\n"
1228
"This is list of values for each color\n"
1229
"Color values have structure [siii] which stand for:\n\t"
420 Franz 1230
"s - Color name ('Black', 'Cyan', 'Magenta', 'Yellow')\n\t"
418 Franz 1231
"i - Frequency (10 to 1000)\n\t"
1232
"i - Angle (-180 to 180)\n\t"
420 Franz 1233
"i - Spot Function\n\t\t0 - Simple Dot\n\t\t1 - Line\n\t\t2 - Round\n\t\t3 - Ellipse\n"
1745 subik 1234
"Be carefull when supplying these values as they\nare not checked for validity.");
418 Franz 1235
 
1236
static PyGetSetDef PDFfile_getseters [] = {
1745 subik 1237
        {const_cast<char*>("file"), (getter)PDFfile_getfile, (setter)PDFfile_setfile, const_cast<char*>("Name of file to save into"), NULL},
20126 jghali 1238
        {const_cast<char*>("fontEmbedding"), (getter)PDFfile_getFontEmbeddingMode, (setter)PDFfile_setFontEmbeddingMode, const_cast<char*>("Font embedding mode.\n\tValue must be one of integers: 0 (Embed), 1 (Outline), 2 (No embedding)."), NULL},
1745 subik 1239
        {const_cast<char*>("fonts"), (getter)PDFfile_getfonts, (setter)PDFfile_setfonts, const_cast<char*>("List of fonts to embed."), NULL},
20126 jghali 1240
        {const_cast<char*>("subsetList"), (getter)PDFfile_getSubsetList, (setter)PDFfile_setSubsetList, const_cast<char*>("List of fonts to subsetted."), NULL},
1745 subik 1241
        {const_cast<char*>("pages"), (getter)PDFfile_getpages, (setter)PDFfile_setpages, const_cast<char*>("List of pages to print"), NULL},
1242
        {const_cast<char*>("resolution"), (getter)PDFfile_getresolution, (setter)PDFfile_setresolution, const_cast<char*>("Resolution of output file. Values from 35 to 4000."), NULL},
1243
        {const_cast<char*>("downsample"), (getter)PDFfile_getdownsample, (setter)PDFfile_setdownsample, const_cast<char*>("Downsample image resolusion to this value. Values from 35 to 4000\nSet 0 for not to downsample"), NULL},
1244
        {const_cast<char*>("effval"), (getter)PDFfile_geteffval, (setter)PDFfile_seteffval, effval_doc, NULL},
1245
        {const_cast<char*>("lpival"), (getter)PDFfile_getlpival, (setter)PDFfile_setlpival, lpival_doc, NULL},
1246
        {const_cast<char*>("owner"), (getter)PDFfile_getowner, (setter)PDFfile_setowner, const_cast<char*>("Owner's password"), NULL},
1247
        {const_cast<char*>("user"), (getter)PDFfile_getuser, (setter)PDFfile_setuser, const_cast<char*>("User's password"), NULL},
1248
        {const_cast<char*>("solidpr"), (getter)PDFfile_getsolidpr, (setter)PDFfile_setsolidpr, const_cast<char*>("Color profile for solid colors"), NULL},
1249
        {const_cast<char*>("imagepr"), (getter)PDFfile_getimagepr, (setter)PDFfile_setimagepr, const_cast<char*>("Color profile for images"), NULL},
1250
        {const_cast<char*>("printprofc"), (getter)PDFfile_getprintprofc, (setter)PDFfile_setprintprofc, const_cast<char*>("Output profile for printing. If possible, get some guidance from your printer on profile selection."), NULL},
1251
        {const_cast<char*>("info"), (getter)PDFfile_getinfo, (setter)PDFfile_setinfo, const_cast<char*>("Mandatory string for PDF/X-3 or the PDF will fail\nPDF/X-3 conformance. We recommend you use the title of the document."), NULL},
20092 jghali 1252
        {const_cast<char*>("rotateDeg"), (getter)PDFfile_getRotateDeg, (setter)PDFfile_setRotateDeg, const_cast<char*>("Automatically rotate the exported pages\n\tValue must be one of integers: 0, 90, 180 or 270"), NULL},
19699 jghali 1253
        {const_cast<char*>("openAction"), (getter)PDFfile_getopenAction, (setter)PDFfile_setopenAction, const_cast<char*>("Javascript to be executed when PDF document is opened."), NULL},
1745 subik 1254
        {NULL, NULL, NULL, NULL, NULL}  // sentinel
418 Franz 1255
};
1256
 
1257
static PyObject *PDFfile_save(PDFfile *self)
1258
{
5781 cbradney 1259
        if (!ScCore->primaryMainWindow()->HaveDoc) {
1745 subik 1260
                PyErr_SetString(PyExc_SystemError, "Need to open document first");
1261
                return NULL;
1262
        };
733 subik 1263
 
19710 jghali 1264
        ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
1265
        PDFOptions& pdfOptions = currentDoc->pdfOptions();
1266
 
418 Franz 1267
// copied from file scribus.cpp
4026 craig 1268
//void ScribusMainWindow::SaveAsPDF()
1745 subik 1269
        int Components = 3;
1270
        QString nam = "";
10428 subik 1271
        if (ScCore->primaryMainWindow()->bookmarkPalette->BView->topLevelItemCount() == 0)
19710 jghali 1272
                pdfOptions.Bookmarks = false;
733 subik 1273
 
20126 jghali 1274
// get PDF version
1275
        self->version = minmaxi(self->version, PDFOptions::PDFVersion_Min, PDFOptions::PDFVersion_Max);
1276
        pdfOptions.Version = (PDFOptions::PDFVersion) self->version;
1277
 
418 Franz 1278
// apply fonts attribute
19710 jghali 1279
        pdfOptions.EmbedList.clear();
1745 subik 1280
        int n = PyList_Size(self->fonts);
20126 jghali 1281
        for ( int i=0; i<n; ++i)
1282
        {
1745 subik 1283
                QString tmpFon;
1284
                tmpFon = QString(PyString_AsString(PyList_GetItem(self->fonts, i)));
19710 jghali 1285
                pdfOptions.EmbedList.append(tmpFon);
1745 subik 1286
        }
19699 jghali 1287
// apply SubsetList attribute
19710 jghali 1288
        pdfOptions.SubsetList.clear();
20092 jghali 1289
        n = PyList_Size(self->subsetList);
20126 jghali 1290
        for (int i = 0; i < n; ++i)
1291
        {
19699 jghali 1292
                QString tmpFon;
20092 jghali 1293
                tmpFon = QString(PyString_AsString(PyList_GetItem(self->subsetList, i)));
19710 jghali 1294
                pdfOptions.SubsetList.append(tmpFon);
19699 jghali 1295
        }
20126 jghali 1296
// apply font embedding mode
1297
        pdfOptions.FontEmbedding = (PDFOptions::PDFFontEmbedding) PyInt_AsLong(self->fontEmbedding);
1298
        if (pdfOptions.Version == PDFOptions::PDFVersion_X1a ||
1299
            pdfOptions.Version == PDFOptions::PDFVersion_X3 ||
1300
            pdfOptions.Version == PDFOptions::PDFVersion_X4)
1301
        {
1302
                pdfOptions.FontEmbedding = PDFOptions::EmbedFonts;
1303
        }
1304
        if (pdfOptions.FontEmbedding == PDFOptions::EmbedFonts)
1305
        {
1306
                QStringList docFonts = currentDoc->UsedFonts.keys();
1307
                for (int i = 0; i < docFonts.count(); ++i)
1308
                {
1309
                        QString fontName = docFonts.at(i);
1310
                        if (pdfOptions.SubsetList.contains(fontName))
1311
                                continue;
1312
                        if (pdfOptions.EmbedList.contains(fontName))
1313
                                continue;
1314
                        pdfOptions.SubsetList.append(fontName);
1315
                }
1316
                pdfOptions.OutlineList = QStringList();
1317
        }
1318
        else if (pdfOptions.FontEmbedding == PDFOptions::OutlineFonts)
1319
        {
1320
                pdfOptions.EmbedList   = QStringList();
1321
                pdfOptions.SubsetList  = QStringList();
1322
                pdfOptions.OutlineList = currentDoc->UsedFonts.keys();
1323
        }
1324
        else
1325
        {
1326
                pdfOptions.EmbedList   = QStringList();
1327
                pdfOptions.SubsetList  = QStringList();
1328
                pdfOptions.OutlineList = QStringList();
1329
        }
418 Franz 1330
// apply file attribute
1745 subik 1331
        QString fn;
1332
        fn = QString(PyString_AsString(self->file));
19710 jghali 1333
        pdfOptions.fileName = fn;
418 Franz 1334
// apply pages attribute
1745 subik 1335
        std::vector<int> pageNs;
1336
        int nn=PyList_Size(self->pages);
1337
        for (int i = 0; i < nn; ++i) {
1338
                pageNs.push_back((int)PyInt_AsLong(PyList_GetItem(self->pages, i)));
1339
        }
418 Franz 1340
// apply thumbnails attribute
19710 jghali 1341
        pdfOptions.Thumbnails = self->thumbnails;
14805 jghali 1342
// apply cropmarks attribute
19710 jghali 1343
        pdfOptions.cropMarks = self->cropMarks;
14805 jghali 1344
// apply bleedmarks attribute
19710 jghali 1345
        pdfOptions.bleedMarks = self->bleedMarks;
14805 jghali 1346
// apply registrationmarks attribute
19710 jghali 1347
        pdfOptions.registrationMarks = self->registrationMarks;
14805 jghali 1348
// apply colormarks attribute
19710 jghali 1349
        pdfOptions.colorMarks = self->colorMarks;
19704 jghali 1350
// apply docInfoMark attribute
19710 jghali 1351
        pdfOptions.docInfoMarks = self->docInfoMarks;
19704 jghali 1352
// apply mark offset attribute
19746 jghali 1353
        pdfOptions.markOffset = qMax(0.0, self->markOffset / currentDoc->unitRatio());
1354
// apply mark length attribute
1355
        pdfOptions.markLength = qMax(0.0, self->markLength / currentDoc->unitRatio());
418 Franz 1356
// apply compress attribute
1745 subik 1357
        self->compressmtd = minmaxi(self->compressmtd, 0, 3);
19710 jghali 1358
        pdfOptions.Compress = self->compress;
1359
        pdfOptions.CompressMethod = (PDFOptions::PDFCompression) self->compressmtd;
418 Franz 1360
// apply quality attribute
1745 subik 1361
        self->quality = minmaxi(self->quality, 0, 4);
19710 jghali 1362
        pdfOptions.Quality = self->quality;
418 Franz 1363
// apply resolusion attribute
19710 jghali 1364
        pdfOptions.Resolution = PyInt_AsLong(self->resolution);
418 Franz 1365
// apply downsample attribute
19710 jghali 1366
        pdfOptions.RecalcPic = PyInt_AsLong(self->downsample);
1367
        if (pdfOptions.RecalcPic)
1368
                pdfOptions.PicRes = PyInt_AsLong(self->downsample);
1745 subik 1369
        else
19710 jghali 1370
                pdfOptions.PicRes = pdfOptions.Resolution;
418 Franz 1371
// apply bookmarks attribute
19710 jghali 1372
        pdfOptions.Bookmarks = self->bookmarks;
418 Franz 1373
// apply binding attribute
19710 jghali 1374
        pdfOptions.Binding = self->binding;
418 Franz 1375
// apply presentation attribute
19710 jghali 1376
        pdfOptions.PresentMode = self->presentation;
733 subik 1377
 
9803 fschmid 1378
        QList<PDFPresentationData> PresentVals;
1745 subik 1379
        PresentVals.clear();
20126 jghali 1380
        int tmpnum = PyList_Size(self->effval);
1381
        for (int i = 0; i < tmpnum; ++i)
1382
        {
1745 subik 1383
                PDFPresentationData t;
1384
                PyObject *ti = PyList_GetItem(self->effval, i);
20126 jghali 1385
                if (!ti)
1386
                        continue;
1387
                // Do I Need to check if every PyInt_AsLong and PyList_GetItem funtion succeed???
1388
                t.pageEffectDuration = PyInt_AsLong(PyList_GetItem(ti, 0));
1389
                t.pageViewDuration = PyInt_AsLong(PyList_GetItem(ti, 1));
1390
                t.effectType = PyInt_AsLong(PyList_GetItem(ti, 2));
1391
                t.Dm = PyInt_AsLong(PyList_GetItem(ti, 3));
1392
                t.M = PyInt_AsLong(PyList_GetItem(ti, 4));
1393
                t.Di = PyInt_AsLong(PyList_GetItem(ti, 5));
1394
                //      PresentVals.append(t);
1745 subik 1395
        }
418 Franz 1396
 
19710 jghali 1397
//      pdfOptions.PresentVals = PresentVals;
418 Franz 1398
// apply lpival
1745 subik 1399
        int n2 = PyList_Size(self->lpival);
20126 jghali 1400
        for (int i = 0; i < n2; ++i)
1401
        {
1745 subik 1402
                LPIData lpi;
1403
                PyObject *t = PyList_GetItem(self->lpival, i);
418 Franz 1404
// This code always raise exception - WHY???
1745 subik 1405
//              char *s;
20126 jghali 1406
//              if (!PyArg_ParseTuple(t, "[siii]", &s, &lpi.Frequency,
1407
//                               &lpi.Angle, &lpi.SpotFunc)) {
1408
//                      PyErr_SetString(PyExc_SystemError, "while parsing 'lpival'. WHY THIS HAPPENED????");
1409
//                      return NULL;
1410
//              }
1411
//              pdfOptions.LPISettings[QString(s)]=lpi;
1745 subik 1412
                QString st;
1413
                st = QString(PyString_AsString(PyList_GetItem(t,0)));
1414
                lpi.Frequency = PyInt_AsLong(PyList_GetItem(t, 1));
1415
                lpi.Angle = PyInt_AsLong(PyList_GetItem(t, 2));
1416
                lpi.SpotFunc = PyInt_AsLong(PyList_GetItem(t, 3));
20126 jghali 1417
                pdfOptions.LPISettings[st] = lpi;
1745 subik 1418
        }
733 subik 1419
 
19710 jghali 1420
        pdfOptions.Articles = self->article;
1421
        pdfOptions.Encrypt = self->encrypt;
1422
        pdfOptions.UseLPI = self->uselpi;
1423
        pdfOptions.UseSpotColors = self->usespot;
1424
        pdfOptions.doMultiFile = self->domulti;
20126 jghali 1425
 
1745 subik 1426
        if (self->encrypt)
1427
        {
1428
                int Perm = -64;
19710 jghali 1429
                if (pdfOptions.Version == PDFOptions::PDFVersion_14)
1745 subik 1430
                        Perm &= ~0x00240000;
20092 jghali 1431
                if (self->allowPrinting)
1745 subik 1432
                        Perm += 4;
20092 jghali 1433
                if (self->allowChange)
1745 subik 1434
                        Perm += 8;
20092 jghali 1435
                if (self->allowCopy)
1745 subik 1436
                        Perm += 16;
20092 jghali 1437
                if (self->allowAnnots)
1745 subik 1438
                        Perm += 32;
19710 jghali 1439
                pdfOptions.Permissions = Perm;
1440
                pdfOptions.PassOwner = QString(PyString_AsString(self->owner));
1441
                pdfOptions.PassUser = QString(PyString_AsString(self->user));
1745 subik 1442
        }
1443
        if (self->outdst == 0)
1444
        {
19710 jghali 1445
                pdfOptions.UseRGB = true;
1446
                pdfOptions.UseProfiles = false;
1447
                pdfOptions.UseProfiles2 = false;
1745 subik 1448
        }
1449
        else
1450
        {
19710 jghali 1451
                pdfOptions.UseRGB = false;
5880 jghali 1452
                if (ScCore->primaryMainWindow()->doc->HasCMS)
1745 subik 1453
                {
19710 jghali 1454
                        pdfOptions.UseProfiles = self->profiles;
1455
                        pdfOptions.UseProfiles2 = self->profilei;
1745 subik 1456
                        self->intents = minmaxi(self->intents, 0, 3);
19710 jghali 1457
                        pdfOptions.Intent = self->intents;
1745 subik 1458
                        self->intenti = minmaxi(self->intenti, 0, 3);
19710 jghali 1459
                        pdfOptions.Intent2 = self->intenti;
1460
                        pdfOptions.EmbeddedI = self->noembicc;
1461
                        pdfOptions.SolidProf = PyString_AsString(self->solidpr);
1462
                        pdfOptions.ImageProf = PyString_AsString(self->imagepr);
1463
                        pdfOptions.PrintProf = PyString_AsString(self->printprofc);
1464
                        if (pdfOptions.Version == PDFOptions::PDFVersion_X1a ||
1465
                                pdfOptions.Version == PDFOptions::PDFVersion_X3 ||
1466
                                pdfOptions.Version == PDFOptions::PDFVersion_X4)
1745 subik 1467
                        {
14170 jghali 1468
                                ScColorProfile profile;
19710 jghali 1469
                                profile = ScCore->defaultEngine.openProfileFromFile(ScCore->PrinterProfiles[pdfOptions.PrintProf]);
14170 jghali 1470
                                nam = profile.productDescription();
14772 jghali 1471
                                if (profile.colorSpace() == ColorSpace_Rgb)
1745 subik 1472
                                        Components = 3;
14772 jghali 1473
                                if (profile.colorSpace() == ColorSpace_Cmyk)
1745 subik 1474
                                        Components = 4;
14772 jghali 1475
                                if (profile.colorSpace() == ColorSpace_Cmy)
1745 subik 1476
                                        Components = 3;
19710 jghali 1477
                                pdfOptions.Info = PyString_AsString(self->info);
1478
                                pdfOptions.Encrypt = false;
1479
                                pdfOptions.PresentMode = false;
1745 subik 1480
                        }
1481
                }
1482
                else
1483
                {
19710 jghali 1484
                        pdfOptions.UseProfiles = false;
1485
                        pdfOptions.UseProfiles2 = false;
1745 subik 1486
                }
1487
        }
1488
        QMap<int,QPixmap> thumbs;
1489
        for (uint ap = 0; ap < pageNs.size(); ++ap)
1490
        {
1491
                QPixmap pm(10,10);
19710 jghali 1492
                if (pdfOptions.Thumbnails)
10598 cbradney 1493
                        pm = QPixmap::fromImage(ScCore->primaryMainWindow()->view->PageToPixmap(pageNs[ap]-1, 100));
1745 subik 1494
                thumbs.insert(pageNs[ap], pm);
1495
        }
5781 cbradney 1496
        ReOrderText(ScCore->primaryMainWindow()->doc, ScCore->primaryMainWindow()->view);
19693 jghali 1497
 
19710 jghali 1498
        MarginStruct optBleeds(pdfOptions.bleeds);
20092 jghali 1499
        pdfOptions.useDocBleeds = self->useDocBleeds;
1500
        if (self->useDocBleeds)
19710 jghali 1501
                pdfOptions.bleeds = ScCore->primaryMainWindow()->doc->bleedsVal();
19693 jghali 1502
        else {
19710 jghali 1503
                self->bleedt = minmaxd(self->bleedt, 0, currentDoc->pageHeight() * currentDoc->unitRatio());
19831 craig 1504
                pdfOptions.bleeds.setTop(self->bleedt / currentDoc->unitRatio());
19710 jghali 1505
                self->bleedl = minmaxd(self->bleedl, 0, currentDoc->pageWidth() * currentDoc->unitRatio());
19831 craig 1506
                pdfOptions.bleeds.setLeft(self->bleedl / currentDoc->unitRatio());
19710 jghali 1507
                self->bleedr = minmaxd(self->bleedr, 0, currentDoc->pageWidth() * currentDoc->unitRatio());
19831 craig 1508
                pdfOptions.bleeds.setRight(self->bleedr / currentDoc->unitRatio());
19710 jghali 1509
                self->bleedb = minmaxd(self->bleedb, 0, currentDoc->pageHeight() * currentDoc->unitRatio());
19831 craig 1510
                pdfOptions.bleeds.setBottom(self->bleedb / currentDoc->unitRatio());
19693 jghali 1511
        }
19710 jghali 1512
        pdfOptions.useLayers = self->useLayers;
1513
        pdfOptions.embedPDF = self->embedPDF;
1514
        pdfOptions.MirrorH = self->mirrorH;
1515
        pdfOptions.MirrorV = self->mirrorV;
1516
        pdfOptions.doClip = self->doClip;
20092 jghali 1517
        pdfOptions.RotateDeg = PyInt_AsLong(self->rotateDeg);
19710 jghali 1518
        pdfOptions.isGrayscale = self->isGrayscale;
1519
        pdfOptions.PageLayout = minmaxi(self->pageLayout, 0, 3);
1520
        pdfOptions.displayBookmarks = self->displayBookmarks;
1521
        pdfOptions.displayThumbs = self->displayThumbs;
1522
        pdfOptions.displayLayers = self->displayLayers;
1523
        pdfOptions.displayFullscreen = self->displayFullscreen;
1524
        pdfOptions.hideToolBar = self->hideToolBar;
1525
        pdfOptions.hideMenuBar = self->hideMenuBar;
1526
        pdfOptions.fitWindow = self->fitWindow;
1527
        pdfOptions.openAction = QString(PyString_AsString(self->openAction));
1528
        pdfOptions.firstUse = false;
19693 jghali 1529
 
11060 jghali 1530
        QString errorMessage;
19693 jghali 1531
        bool success = ScCore->primaryMainWindow()->getPDFDriver(fn, nam, Components, pageNs, thumbs, errorMessage);
1532
        if (!success) {
11060 jghali 1533
                fn  = "Cannot write the File: " + fn;
1534
                if (!errorMessage.isEmpty())
1535
                        fn += QString("\n%1").arg(errorMessage);
18194 fschmid 1536
                PyErr_SetString(PyExc_SystemError, fn.toLatin1());
1745 subik 1537
        }
19693 jghali 1538
 
20092 jghali 1539
        if (self->useDocBleeds)
19710 jghali 1540
                pdfOptions.bleeds = optBleeds;
19693 jghali 1541
 
1542
        if (success)
1543
                Py_RETURN_NONE;
1544
        return NULL;
418 Franz 1545
}
1546
 
1547
static PyMethodDef PDFfile_methods[] = {
1745 subik 1548
        {const_cast<char*>("save"), (PyCFunction)PDFfile_save, METH_NOARGS, const_cast<char*>("Save selected pages to pdf file")},
1549
        {NULL, (PyCFunction)(0), 0, NULL} // sentinel
418 Franz 1550
};
1551
 
1552
PyTypeObject PDFfile_Type = {
1745 subik 1553
        PyObject_HEAD_INIT(NULL) // PyObject_VAR_HEAD
1554
        0,                    //
19456 jghali 1555
        const_cast<char*>("scribus.PDFfile"), // char *tp_name; /* For printing, in format "<module>.<name>" */
1745 subik 1556
        sizeof(PDFfile),     // int tp_basicsize, /* For allocation */
1557
        0,                  // int tp_itemsize; /* For allocation */
418 Franz 1558
 
1559
        /* Methods to implement standard operations */
1560
 
1745 subik 1561
        (destructor) PDFfile_dealloc, //     destructor tp_dealloc;
1562
        0, //     printfunc tp_print;
1563
        0, //     getattrfunc tp_getattr;
1564
        0, //     setattrfunc tp_setattr;
1565
        0, //     cmpfunc tp_compare;
1566
        0, //     reprfunc tp_repr;
418 Franz 1567
 
1568
        /* Method suites for standard classes */
1569
 
1745 subik 1570
        0, //     PyNumberMethods *tp_as_number;
1571
        0, //     PySequenceMethods *tp_as_sequence;
1572
        0, //     PyMappingMethods *tp_as_mapping;
418 Franz 1573
 
1574
        /* More standard operations (here for binary compatibility) */
1575
 
1745 subik 1576
        0, //     hashfunc tp_hash;
1577
        0, //     ternaryfunc tp_call;
1578
        0, //     reprfunc tp_str;
1579
        0, //     getattrofunc tp_getattro;
1580
        0, //     setattrofunc tp_setattro;
418 Franz 1581
 
1582
        /* Functions to access object as input/output buffer */
1745 subik 1583
        0, //     PyBufferProcs *tp_as_buffer;
418 Franz 1584
 
1585
        /* Flags to define presence of optional/expanded features */
1745 subik 1586
        Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,    // long tp_flags;
418 Franz 1587
 
1745 subik 1588
        pdffile__doc__,      // char *tp_doc; /* Documentation string */
733 subik 1589
 
418 Franz 1590
        /* Assigned meaning in release 2.0 */
1591
        /* call function for all accessible objects */
1745 subik 1592
        0, //     traverseproc tp_traverse;
418 Franz 1593
 
1594
        /* delete references to contained objects */
1745 subik 1595
        0, //     inquiry tp_clear;
418 Franz 1596
 
1597
        /* Assigned meaning in release 2.1 */
1598
        /* rich comparisons */
1745 subik 1599
        0, //     richcmpfunc tp_richcompare;
418 Franz 1600
 
1601
        /* weak reference enabler */
1745 subik 1602
        0, //     long tp_weaklistoffset;
418 Franz 1603
 
1604
        /* Added in release 2.2 */
1605
        /* Iterators */
1745 subik 1606
        0, //     getiterfunc tp_iter;
1607
        0, //     iternextfunc tp_iternext;
418 Franz 1608
 
1609
        /* Attribute descriptor and subclassing stuff */
1745 subik 1610
        PDFfile_methods, //     struct PyMethodDef *tp_methods;
1611
        PDFfile_members, //     struct PyMemberDef *tp_members;
1612
        PDFfile_getseters, //     struct PyGetSetDef *tp_getset;
1613
        0, //     struct _typeobject *tp_base;
1614
        0, //     PyObject *tp_dict;
1615
        0, //     descrgetfunc tp_descr_get;
1616
        0, //     descrsetfunc tp_descr_set;
1617
        0, //     long tp_dictoffset;
1618
        (initproc)PDFfile_init, //     initproc tp_init;
1619
        0, //     allocfunc tp_alloc;
1620
        PDFfile_new, //     newfunc tp_new;
1621
        0, //     freefunc tp_free; /* Low-level free-memory routine */
1622
        0, //     inquiry tp_is_gc; /* For PyObject_IS_GC */
1623
        0, //     PyObject *tp_bases;
1624
        0, //     PyObject *tp_mro; /* method resolution order */
1625
        0, //     PyObject *tp_cache;
1626
        0, //     PyObject *tp_subclasses;
1627
        0, //     PyObject *tp_weaklist;
1628
        0, //     destructor tp_del;
418 Franz 1629
 
1630
#ifdef COUNT_ALLOCS
1631
        /* these must be last and never explicitly initialized */
1745 subik 1632
        //    int tp_allocs;
1633
        //    int tp_frees;
1634
        //    int tp_maxalloc;
1635
        //    struct _typeobject *tp_next;
418 Franz 1636
#endif
1637
};