Subversion Repositories Scribus

Rev

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