Subversion Repositories Scribus

Rev

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