Subversion Repositories Scribus

Rev

Rev 24665 | 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
*/
12460 cbradney 7
#include <vector>
15431 craig 8
#include <iostream>
12460 cbradney 9
 
792 subik 10
#include "objprinter.h"
11
 
413 Franz 12
#include <structmember.h>
10223 cbradney 13
#include <QFileInfo>
14
#include <QDir>
23559 jghali 15
#include <QScopedPointer>
12460 cbradney 16
 
24049 jghali 17
#include "cmdutil.h"
18
#include "prefsmanager.h"
3136 fschmid 19
#include "pslib.h"
11605 jghali 20
#include "scpaths.h"
24049 jghali 21
#include "scprintengine_pdf.h"
22
#include "scprintengine_ps.h"
11605 jghali 23
#include "scribuscore.h"
13805 jghali 24
#include "scribusdoc.h"
11605 jghali 25
#include "util_file.h"
10212 cbradney 26
#include "util_ghostscript.h"
27
#include "util_printer.h"
413 Franz 28
 
24049 jghali 29
#if defined(_WIN32)
30
#include "scprintengine_gdi.h"
31
#endif
32
 
413 Franz 33
// these functions are located at utils.cpp
3819 subik 34
void SCRIBUS_API ReOrderText(ScribusDoc *doc, ScribusView *view);
413 Franz 35
// end of utils.cpp
36
 
733 subik 37
typedef struct
413 Franz 38
{
1745 subik 39
        PyObject_HEAD
40
        PyObject *allPrinters; // list of strings - names of installed printers
41
        PyObject *printer;  // string - selected printer
42
        PyObject *file;  // string - name of file to print into (eg. output.ps)
43
        PyObject *cmd; // string - if "" use standard command else use this as command (eg. "kprinter", "xpp" ...)
44
        PyObject *pages; // list of integers - pages to be printed
45
        int copies; // numer of printed copies
46
        PyObject *separation; // string - No; All; Cyan; Magenta; Yellow; Black
47
        int color; // bool - do we print in color=1 or greyscale=0
48
        int useICC; // bool - do we use ICC Profiles 0 = No 1 = Yes
24049 jghali 49
        int prnLang; // integer - print language
1745 subik 50
        int mph; // bool - mirror pages horizontally
51
        int mpv; // bool - mirror pages vertically
52
        int ucr; // bool - Under Color Removal
413 Franz 53
} Printer;
54
 
55
 
56
static void Printer_dealloc(Printer* self)
57
{
1745 subik 58
        Py_XDECREF(self->allPrinters);
59
        Py_XDECREF(self->printer);
60
        Py_XDECREF(self->file);
61
        Py_XDECREF(self->cmd);
62
        Py_XDECREF(self->pages);
63
        Py_XDECREF(self->separation);
23278 jghali 64
        Py_TYPE(self)->tp_free((PyObject *)self);
413 Franz 65
}
66
 
10778 craig 67
static PyObject * Printer_new(PyTypeObject *type, PyObject * /*args*/, PyObject * /*kwds*/)
413 Franz 68
{
69
// do not create new object if there is no opened document
21141 jghali 70
        if (!checkHaveDocument()) {
22537 craig 71
                return nullptr;
1745 subik 72
        }
413 Franz 73
 
22537 craig 74
        Printer *self = (Printer *)type->tp_alloc(type, 0);
75
        if (self != nullptr) {
413 Franz 76
// set allPrinters attribute
1745 subik 77
                self->allPrinters = PyList_New(0);
24049 jghali 78
                if (self->allPrinters == nullptr) {
1745 subik 79
                        Py_DECREF(self);
22537 craig 80
                        return nullptr;
1745 subik 81
                }
413 Franz 82
// set printer attribute
23278 jghali 83
                self->printer = PyUnicode_FromString("");
24049 jghali 84
                if (self->printer == nullptr) {
1745 subik 85
                        Py_DECREF(self);
22537 craig 86
                        return nullptr;
1745 subik 87
                }
413 Franz 88
// set file attribute
23278 jghali 89
                self->file = PyUnicode_FromString("");
24049 jghali 90
                if (self->file == nullptr) {
1745 subik 91
                        Py_DECREF(self);
22537 craig 92
                        return nullptr;
1745 subik 93
                }
413 Franz 94
// set cmd attribute
23278 jghali 95
                self->cmd = PyUnicode_FromString("");
24049 jghali 96
                if (self->cmd == nullptr) {
1745 subik 97
                        Py_DECREF(self);
22537 craig 98
                        return nullptr;
1745 subik 99
                }
413 Franz 100
// set pages attribute
1745 subik 101
                self->pages = PyList_New(0);
24049 jghali 102
                if (self->pages == nullptr) {
1745 subik 103
                        Py_DECREF(self);
22537 craig 104
                        return nullptr;
1745 subik 105
                }
413 Franz 106
// set separation attribute
23278 jghali 107
                self->separation = PyUnicode_FromString("No");
24049 jghali 108
                if (self->separation == nullptr) {
1745 subik 109
                        Py_DECREF(self);
22537 craig 110
                        return nullptr;
1745 subik 111
                }
413 Franz 112
// set color attribute
1745 subik 113
                self->color = 1;
413 Franz 114
// set useICC attribute
1745 subik 115
                self->useICC = 0;
24049 jghali 116
// set prnLanguage attribute
117
                self->prnLang = (int) PrintLanguage::PostScript3;
413 Franz 118
// set mph attribute
1745 subik 119
                self->mph = 0;
413 Franz 120
// set mpv attribute
1745 subik 121
                self->mpv = 0;
413 Franz 122
// set ucr attribute
1745 subik 123
                self->ucr = 1;
413 Franz 124
// set copies attribute
1745 subik 125
                self->copies = 1;
126
        }
127
        return (PyObject *) self;
413 Franz 128
}
129
 
10778 craig 130
static int Printer_init(Printer *self, PyObject * /*args*/, PyObject * /*kwds*/)
413 Franz 131
{
21141 jghali 132
        if (!checkHaveDocument()) {
133
                return -1;
134
        }
413 Franz 135
// pool system for installed printers
136
// most code is stolen and little adopted from druck.cpp
1745 subik 137
        PyObject *allPrinters = PyList_New(0);
24049 jghali 138
        if (allPrinters) {
1745 subik 139
                Py_DECREF(self->allPrinters);
140
                self->allPrinters = allPrinters;
141
        }
9699 jghali 142
        QStringList printers = PrinterUtil::getPrinterNames();
9702 jghali 143
        for (int i = 0; i < printers.count(); ++i)
1745 subik 144
        {
9699 jghali 145
                QString prn = printers[i];
146
                if (prn.isEmpty())
147
                        continue;
23278 jghali 148
                PyObject *tmppr = PyUnicode_FromString(prn.toUtf8().constData());
24049 jghali 149
                if (tmppr) {
9699 jghali 150
                        PyList_Append(self->allPrinters, tmppr);
151
                        Py_DECREF(tmppr);
1745 subik 152
                }
153
        }
23278 jghali 154
        PyObject *tmp2 = PyUnicode_FromString("File");
1745 subik 155
        PyList_Append(self->allPrinters, tmp2);
156
        Py_DECREF(tmp2);
24665 jghali 157
// as default set to print into file
22537 craig 158
        PyObject *printer = nullptr;
23278 jghali 159
        printer = PyUnicode_FromString("File");
24049 jghali 160
        if (printer) {
1745 subik 161
                Py_DECREF(self->printer);
162
                self->printer = printer;
163
        }
413 Franz 164
// set defaul name of file to print into
14925 cbradney 165
        QString tf(ScCore->primaryMainWindow()->doc->pdfOptions().fileName);
2877 cbradney 166
        if (tf.isEmpty()) {
22832 craig 167
                QFileInfo fi = QFileInfo(ScCore->primaryMainWindow()->doc->documentFileName());
24049 jghali 168
                tf = fi.path() + "/" + fi.baseName() + ".pdf";
1745 subik 169
        }
22537 craig 170
        PyObject *file = nullptr;
23278 jghali 171
        file = PyUnicode_FromString(tf.toUtf8());
24049 jghali 172
        if (file) {
1745 subik 173
                Py_DECREF(self->file);
174
                self->file = file;
175
        } else {
176
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'file' attribute");
177
                return -1;
178
        }
413 Franz 179
// alternative printer commands default to ""
22537 craig 180
        PyObject *cmd = nullptr;
23278 jghali 181
        cmd = PyUnicode_FromString("");
24049 jghali 182
        if (cmd) {
1745 subik 183
                Py_DECREF(self->cmd);
184
                self->cmd = cmd;
185
        }
413 Franz 186
// if document exist when created Printer instance
187
// set to print all pages
22537 craig 188
        PyObject *pages = nullptr;
21141 jghali 189
        int num = ScCore->primaryMainWindow()->doc->Pages->count();
1745 subik 190
        pages = PyList_New(num);
24049 jghali 191
        if (pages) {
1745 subik 192
                Py_DECREF(self->pages);
193
                self->pages = pages;
194
        }
24049 jghali 195
        for (int i = 0; i < num; i++) {
196
                PyObject *tmp = nullptr;
23278 jghali 197
                tmp = PyLong_FromLong((long)i+1L); // instead of 1 put here first page number
1745 subik 198
                if (tmp)
199
                        PyList_SetItem(self->pages, i, tmp);
200
        }
413 Franz 201
// do not print separation
22537 craig 202
        PyObject *separation = nullptr;
23278 jghali 203
        separation = PyUnicode_FromString("No");
24049 jghali 204
        if (separation) {
1745 subik 205
                Py_DECREF(self->separation);
206
                self->separation = separation;
207
        }
413 Franz 208
// print in color
1745 subik 209
        self->color = 1;
413 Franz 210
// do not use ICC Profile
1745 subik 211
        self->useICC = 0;
413 Franz 212
// use PostScrip level 3
24049 jghali 213
        self->prnLang = (int) PrintLanguage::PostScript3;
413 Franz 214
// do not mirror pages
1745 subik 215
        self->mph = 0;
413 Franz 216
// do not mirror pages
1745 subik 217
        self->mpv = 0;
413 Franz 218
// apply Under Color Removal as default
1745 subik 219
        self->ucr = 1;
413 Franz 220
// number of copies
1745 subik 221
        self->copies = 1;
222
        return 0;
413 Franz 223
}
224
 
225
static PyMemberDef Printer_members[] = {
1745 subik 226
        {const_cast<char*>("copies"), T_INT, offsetof(Printer, copies), 0, const_cast<char*>("Number of copies")},
227
        {const_cast<char*>("color"), T_INT, offsetof(Printer, color), 0, const_cast<char*>("Print in color.\n\t True - color  --  Default\n\t False - greyscale")},
228
        {const_cast<char*>("useICC"), T_INT, offsetof(Printer, useICC), 0, const_cast<char*>("Use ICC Profile\n\tTrue\n\tFalse  --  Default")},
24049 jghali 229
        {const_cast<char*>("pslevel"), T_INT, offsetof(Printer, prnLang), 0, const_cast<char*>("Deprecated, use prnLanguage instead.")}, // Deprecated
230
        {const_cast<char*>("prnLanguage"), T_INT, offsetof(Printer, prnLang), 0, const_cast<char*>("Print Language\nOne of PRNLANG_* constants  -- Default is PRNLANG_POSTSCRIPT3.")},
1745 subik 231
        {const_cast<char*>("mph"), T_INT, offsetof(Printer, mph), 0, const_cast<char*>("Mirror Pages Horizontal\n\tTrue\n\tFalse  --  Default")},
232
        {const_cast<char*>("mpv"), T_INT, offsetof(Printer, mpv), 0, const_cast<char*>("Mirror Pages Vertical\n\t True\n\tFalse  --  Default")},
233
        {const_cast<char*>("ucr"), T_INT, offsetof(Printer, ucr), 0, const_cast<char*>("Apply Under Color Removal\n\tTrue  --  Default\n\tFalse")},
22537 craig 234
        {nullptr, 0, 0, 0, nullptr} // sentinel
413 Franz 235
};
236
 
237
/* Here begins Getter & Setter functions */
238
 
10778 craig 239
static PyObject *Printer_getallPrinters(Printer *self, void * /*closure*/)
413 Franz 240
{
1745 subik 241
        Py_INCREF(self->allPrinters);
242
        return self->allPrinters;
413 Franz 243
}
244
 
10778 craig 245
static int Printer_setallPrinters(Printer * /*self*/, PyObject * /*value*/, void * /*closure*/)
413 Franz 246
{
1745 subik 247
        PyErr_SetString(PyExc_ValueError, "'allPrinters' attribute is READ-ONLY");
248
        return -1;
413 Franz 249
}
250
 
10778 craig 251
static PyObject *Printer_getprinter(Printer *self, void * /*closure*/)
413 Franz 252
{
1745 subik 253
        Py_INCREF(self->printer);
254
        return self->printer;
413 Franz 255
}
256
 
10778 craig 257
static int Printer_setprinter(Printer *self, PyObject *value, void * /*closure*/)
413 Franz 258
{
22537 craig 259
        if (value == nullptr) {
1745 subik 260
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'printer' attribute.");
261
                return -1;
262
        }
23278 jghali 263
        if (!PyUnicode_Check(value)) {
1745 subik 264
                PyErr_SetString(PyExc_TypeError, "The 'printer' attribute value must be string.");
265
                return -1;
266
        }
24049 jghali 267
 
1745 subik 268
        int n = PyList_Size(self->allPrinters);
269
        bool same = 0;
24049 jghali 270
        for (int i = 0; i < n; i++) {
271
                if (PyObject_RichCompareBool(value, PyList_GetItem(self->allPrinters, i), Py_EQ) == 1) {
1745 subik 272
                        same = true;
24049 jghali 273
                        break;
274
                }
275
        }
1745 subik 276
        if (!same) {
277
                PyErr_SetString(PyExc_ValueError, "'printer' value can be only one of string in 'allPrinters' attribute ");
278
                return -1;
279
        }
24049 jghali 280
 
1745 subik 281
        Py_DECREF(self->printer);
282
        Py_INCREF(value);
283
        self->printer = value;
284
        return 0;
413 Franz 285
}
286
 
10778 craig 287
static PyObject *Printer_getfile(Printer *self, void * /*closure*/)
413 Franz 288
{
1745 subik 289
        Py_INCREF(self->file);
290
        return self->file;
413 Franz 291
}
292
 
10778 craig 293
static int Printer_setfile(Printer *self, PyObject *value, void * /*closure*/)
413 Franz 294
{
22537 craig 295
        if (value == nullptr) {
1745 subik 296
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'file' attribute.");
297
                return -1;
298
        }
23278 jghali 299
        if (!PyUnicode_Check(value)) {
1745 subik 300
                PyErr_SetString(PyExc_TypeError, "The 'file' attribute value must be string.");
301
                return -1;
302
        }
303
        Py_DECREF(self->file);
304
        Py_INCREF(value);
305
        self->file = value;
306
        return 0;
413 Franz 307
}
308
 
10778 craig 309
static PyObject *Printer_getcmd(Printer *self, void * /*closure*/)
413 Franz 310
{
1745 subik 311
        Py_INCREF(self->cmd);
312
        return self->cmd;
413 Franz 313
}
314
 
10778 craig 315
static int Printer_setcmd(Printer *self, PyObject *value, void * /*closure*/)
413 Franz 316
{
22537 craig 317
        if (value == nullptr) {
1745 subik 318
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'cmd' attribute.");
319
                return -1;
320
        }
23278 jghali 321
        if (!PyUnicode_Check(value)) {
1745 subik 322
                PyErr_SetString(PyExc_TypeError, "The 'cmd' attribute value must be string.");
323
                return -1;
324
        }
325
        Py_DECREF(self->cmd);
326
        Py_INCREF(value);
327
        self->cmd = value;
328
        return 0;
413 Franz 329
}
330
 
10778 craig 331
static PyObject *Printer_getpages(Printer *self, void * /*closure*/)
413 Franz 332
{
1745 subik 333
        Py_INCREF(self->pages);
334
        return self->pages;
413 Franz 335
}
336
 
10778 craig 337
static int Printer_setpages(Printer *self, PyObject *value, void * /*closure*/)
413 Franz 338
{
22537 craig 339
        if (value == nullptr) {
1745 subik 340
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'pages' attribute.");
341
                return -1;
342
        }
343
        if (!PyList_Check(value)) {
344
                PyErr_SetString(PyExc_TypeError, "'pages' attribute value must be list of integers.");
345
                return -1;
346
        }
347
        int len = PyList_Size(value);
24049 jghali 348
        for (int i = 0; i < len; i++) {
1745 subik 349
                PyObject *tmp = PyList_GetItem(value, i);
24049 jghali 350
                if (!PyLong_Check(tmp)) {
1745 subik 351
                        PyErr_SetString(PyExc_TypeError, "'pages' attribute must be list containing only integers.");
352
                        return -1;
353
                }
23278 jghali 354
                if (PyLong_AsLong(tmp) > static_cast<int>(ScCore->primaryMainWindow()->doc->Pages->count()) || PyLong_AsLong(tmp) < 1) {
1745 subik 355
                        PyErr_SetString(PyExc_ValueError, "'pages' value out of range.");
356
                        return -1;
357
                }
358
        }
359
        Py_DECREF(self->pages);
360
        Py_INCREF(value);
361
        self->pages = value;
362
        return 0;
413 Franz 363
}
364
 
10778 craig 365
static PyObject *Printer_getseparation(Printer *self, void * /*closure*/)
413 Franz 366
{
1745 subik 367
        Py_INCREF(self->separation);
368
        return self->separation;
413 Franz 369
}
370
 
10778 craig 371
static int Printer_setseparation(Printer *self, PyObject *value, void * /*closure*/)
413 Franz 372
{
22537 craig 373
        if (value == nullptr) {
1745 subik 374
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'separation' attribute.");
375
                return -1;
376
        }
23278 jghali 377
        if (!PyUnicode_Check(value)) {
1745 subik 378
                PyErr_SetString(PyExc_TypeError, "The 'separation' attribute value must be string.");
379
                return -1;
380
        }
381
        Py_DECREF(self->separation);
382
        Py_INCREF(value);
383
        self->separation = value;
384
        return 0;
413 Franz 385
}
386
 
387
 
388
static PyGetSetDef Printer_getseters [] = {
22537 craig 389
        {const_cast<char*>("allPrinters"), (getter)Printer_getallPrinters, (setter)Printer_setallPrinters, const_cast<char*>("List of installed printers  --  read only"), nullptr},
390
        {const_cast<char*>("printer"), (getter)Printer_getprinter, (setter)Printer_setprinter, const_cast<char*>("Name of printer to use.\nDefault is 'File' for printing into file"), nullptr},
391
        {const_cast<char*>("file"), (getter)Printer_getfile, (setter)Printer_setfile, const_cast<char*>("Name of file to print into"), nullptr},
392
        {const_cast<char*>("cmd"), (getter)Printer_getcmd, (setter)Printer_setcmd, const_cast<char*>("Alternative Printer Command"), nullptr},
393
        {const_cast<char*>("pages"), (getter)Printer_getpages, (setter)Printer_setpages, const_cast<char*>("List of pages to be printed"), nullptr},
394
        {const_cast<char*>("separation"), (getter)Printer_getseparation, (setter)Printer_setseparation, const_cast<char*>("Print separationl\n\t 'No'  -- Default\n\t 'All'\n\t 'Cyan'\n\t 'Magenta'\n\t 'Yellow'\n\t 'Black'\nBeware of misspelling because check is not performed"), nullptr},
395
        {nullptr, nullptr, nullptr, nullptr, nullptr}  // sentinel
413 Franz 396
};
397
 
733 subik 398
// Here we actually print
413 Franz 399
static PyObject *Printer_print(Printer *self)
400
{
21141 jghali 401
        if (!checkHaveDocument()) {
22537 craig 402
                return nullptr;
1745 subik 403
        }
413 Franz 404
 
24049 jghali 405
//      ReOrderText(ScCore->primaryMainWindow()->doc, ScCore->primaryMainWindow()->view);
406
        QString prn = PyUnicode_asQString(self->printer);
407
        QString fna = PyUnicode_asQString(self->file);
408
        bool    fil = PyUnicode_asQString(self->printer) == QString("File");
409
        QString sepName = PyUnicode_asQString(self->separation);
410
 
6954 fschmid 411
        PrintOptions options;
1745 subik 412
        for (int i = 0; i < PyList_Size(self->pages); ++i) {
23278 jghali 413
                options.pageNumbers.push_back((int) PyLong_AsLong(PyList_GetItem(self->pages, i)));
1745 subik 414
        }
10947 jghali 415
        options.printer   = prn;
24049 jghali 416
        options.prnLanguage = (PrintLanguage) self->prnLang;
417
        options.copies    = (self->copies < 1) ? 1 : self->copies;
10947 jghali 418
        options.toFile    = fil;
24049 jghali 419
        options.filename  = fil ? fna : QString();
420
        options.separationName = sepName;
421
        options.outputSeparations = sepName != QString("No");
23557 jghali 422
        options.useSpotColors = true;
6954 fschmid 423
        options.useColor = self->color;
10947 jghali 424
        options.mirrorH  = self->mph;
425
        options.mirrorV  = self->mpv;
426
        options.doGCR    = self->ucr;
23559 jghali 427
        options.doClip = false;
428
        options.setDevParam = false;
10947 jghali 429
        options.cropMarks  = false;
6954 fschmid 430
        options.bleedMarks = false;
431
        options.registrationMarks = false;
432
        options.colorMarks = false;
23557 jghali 433
        options.includePDFMarks = false;
6954 fschmid 434
        options.markOffset = 0.0;
19831 craig 435
        options.bleeds.set(0, 0, 0, 0);
24049 jghali 436
        if (!PrinterUtil::checkPrintLanguageSupport(options.printer, options.prnLanguage, options.toFile))
437
                options.prnLanguage = PrinterUtil::getDefaultPrintLanguage(options.printer, options.toFile);
438
        if (options.prnLanguage == PrintLanguage::PDF || options.prnLanguage == PrintLanguage::WindowsGDI)
439
        {
440
                options.separationName = "All";
441
                options.outputSeparations = false;
442
        }
443
        options.printerCommand = PyUnicode_asQString(self->cmd);
9702 jghali 444
 
23557 jghali 445
        ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
446
 
9702 jghali 447
#if defined(_WIN32)
10947 jghali 448
        if (!options.toFile)
9702 jghali 449
        {
450
                QByteArray devMode;
451
                bool printDone = false;
23559 jghali 452
                if (PrinterUtil::getDefaultSettings(prn, options.devMode))
9702 jghali 453
                {
23873 jghali 454
                        ScPrintEngine_GDI winPrint(*currentDoc);
455
                        printDone = winPrint.print(options);
9702 jghali 456
                }
457
                if (!printDone)
458
                        PyErr_SetString(PyExc_SystemError, "Printing failed");
459
                Py_RETURN_NONE;
460
        }
461
#endif
462
 
24049 jghali 463
        if (options.prnLanguage == PrintLanguage::PostScript1 || options.prnLanguage == PrintLanguage::PostScript2)
1745 subik 464
        {
24049 jghali 465
                if (!ScCore->haveGS())
1745 subik 466
                {
23559 jghali 467
                        PyErr_SetString(PyExc_SystemError, "Printing failed : GhostScript is needed to print to PostScript Level 1 or Level 2");
468
                        Py_RETURN_NONE;
1745 subik 469
                }
470
        }
23559 jghali 471
 
24049 jghali 472
        QScopedPointer<ScPrintEngine> printEngine;
473
        if (options.prnLanguage == PrintLanguage::PDF)
474
                printEngine.reset(new ScPrintEngine_PDF(*currentDoc));
475
        else
476
                printEngine.reset(new ScPrintEngine_PS(*currentDoc));
477
 
478
        bool printDone = printEngine->print(options);
479
        if (!printDone)
23559 jghali 480
        {
24049 jghali 481
                QString error = printEngine->errorMessage();
482
                PyErr_SetString(PyExc_SystemError, error.toLocal8Bit().constData());
23559 jghali 483
        }
484
 
8319 fschmid 485
        Py_RETURN_NONE;
413 Franz 486
}
487
 
488
static PyMethodDef Printer_methods[] = {
23980 jghali 489
        {const_cast<char*>("printNow"), (PyCFunction)Printer_print, METH_NOARGS, printer_printnow__doc__},
22606 craig 490
        {nullptr, (PyCFunction)(nullptr), 0, nullptr} // sentinel
413 Franz 491
};
492
 
493
PyTypeObject Printer_Type = {
23278 jghali 494
        PyVarObject_HEAD_INIT(nullptr, 0)   // PyObject_VAR_HEAD         //
19456 jghali 495
        const_cast<char*>("scribus.Printer"), // char *tp_name; /* For printing, in format "<module>.<name>" */
1745 subik 496
        sizeof(Printer),   // int tp_basicsize, /* For allocation */
497
        0,                     // int tp_itemsize; /* For allocation */
413 Franz 498
 
499
        /* Methods to implement standard operations */
500
 
1745 subik 501
        (destructor) Printer_dealloc, //     destructor tp_dealloc;
23314 jghali 502
#if PY_VERSION_HEX >= 0x03080000
503
        0,       //     Py_ssize_t tp_vectorcall_offset
504
#else
22606 craig 505
        nullptr, //     printfunc tp_print;
23314 jghali 506
#endif
22606 craig 507
        nullptr, //     getattrfunc tp_getattr;
508
        nullptr, //     setattrfunc tp_setattr;
23314 jghali 509
        nullptr, //     cmpfunc tp_as_async;
22606 craig 510
        nullptr, //     reprfunc tp_repr;
413 Franz 511
 
512
        /* Method suites for standard classes */
513
 
22606 craig 514
        nullptr, //     PyNumberMethods *tp_as_number;
515
        nullptr, //     PySequenceMethods *tp_as_sequence;
516
        nullptr, //     PyMappingMethods *tp_as_mapping;
413 Franz 517
 
518
        /* More standard operations (here for binary compatibility) */
519
 
22606 craig 520
        nullptr, //     hashfunc tp_hash;
521
        nullptr, //     ternaryfunc tp_call;
522
        nullptr, //     reprfunc tp_str;
523
        nullptr, //     getattrofunc tp_getattro;
524
        nullptr, //     setattrofunc tp_setattro;
413 Franz 525
 
526
        /* Functions to access object as input/output buffer */
22606 craig 527
        nullptr, //     PyBufferProcs *tp_as_buffer;
413 Franz 528
 
529
        /* Flags to define presence of optional/expanded features */
1745 subik 530
        Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,    // long tp_flags;
413 Franz 531
 
1745 subik 532
        printer__doc__,      // char *tp_doc; /* Documentation string */
733 subik 533
 
413 Franz 534
        /* Assigned meaning in release 2.0 */
535
        /* call function for all accessible objects */
22606 craig 536
        nullptr, //     traverseproc tp_traverse;
413 Franz 537
 
538
        /* delete references to contained objects */
22606 craig 539
        nullptr, //     inquiry tp_clear;
413 Franz 540
 
541
        /* Assigned meaning in release 2.1 */
542
        /* rich comparisons */
22606 craig 543
        nullptr, //     richcmpfunc tp_richcompare;
413 Franz 544
 
545
        /* weak reference enabler */
1745 subik 546
        0, //     long tp_weaklistoffset;
413 Franz 547
 
548
        /* Added in release 2.2 */
549
        /* Iterators */
22606 craig 550
        nullptr, //     getiterfunc tp_iter;
551
        nullptr, //     iternextfunc tp_iternext;
413 Franz 552
 
553
        /* Attribute descriptor and subclassing stuff */
1745 subik 554
        Printer_methods, //     struct PyMethodDef *tp_methods;
555
        Printer_members, //     struct PyMemberDef *tp_members;
556
        Printer_getseters, //     struct PyGetSetDef *tp_getset;
22606 craig 557
        nullptr, //     struct _typeobject *tp_base;
558
        nullptr, //     PyObject *tp_dict;
559
        nullptr, //     descrgetfunc tp_descr_get;
560
        nullptr, //     descrsetfunc tp_descr_set;
1745 subik 561
        0, //     long tp_dictoffset;
562
        (initproc)Printer_init, //     initproc tp_init;
22606 craig 563
        nullptr, //     allocfunc tp_alloc;
1745 subik 564
        Printer_new, //     newfunc tp_new;
22606 craig 565
        nullptr, //     freefunc tp_free; /* Low-level free-memory routine */
566
        nullptr, //     inquiry tp_is_gc; /* For PyObject_IS_GC */
567
        nullptr, //     PyObject *tp_bases;
568
        nullptr, //     PyObject *tp_mro; /* method resolution order */
569
        nullptr, //     PyObject *tp_cache;
570
        nullptr, //     PyObject *tp_subclasses;
571
        nullptr, //     PyObject *tp_weaklist;
572
        nullptr, //     destructor tp_del;
23278 jghali 573
        0, //    unsigned int tp_version_tag;
574
        0, //    destructor tp_finalize;
23314 jghali 575
#if PY_VERSION_HEX >= 0x03080000
576
        nullptr, // tp_vectorcall
577
#endif
578
#if PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000
579
        nullptr, //deprecated tp_print
580
#endif
413 Franz 581
 
582
#ifdef COUNT_ALLOCS
583
        /* these must be last and never explicitly initialized */
1745 subik 584
        //    int tp_allocs;
585
        //    int tp_frees;
586
        //    int tp_maxalloc;
23314 jghali 587
        //    struct _typeobject *tp_prev;
1745 subik 588
        //    struct _typeobject *tp_next;
413 Franz 589
#endif
590
};
24674 jghali 591
 
592
/*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
593
with header files structure untouched (docstrings are kept near declarations)
594
PV */
595
void objprinterwarnings()
596
{
597
        QStringList s;
598
        s << printer__doc__
599
          << printer_printnow__doc__;
600
}