Rev 9698 | 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 "objprinter.h" |
8 | #include "cmdutil.h" |
||
2834 | cbradney | 9 | #include "prefsmanager.h" |
792 | subik | 10 | |
413 | Franz | 11 | #include <structmember.h> |
420 | Franz | 12 | #include <qfileinfo.h> |
2921 | fschmid | 13 | #include <qdir.h> |
413 | Franz | 14 | #include <vector> |
3136 | fschmid | 15 | #include "pslib.h" |
4506 | cbradney | 16 | #include "gsutil.h" |
9698 | jghali | 17 | #include "printerutil.h" |
4194 | fschmid | 18 | #include "util.h" |
413 | Franz | 19 | |
20 | #ifdef HAVE_CUPS |
||
21 | #include <cups/cups.h> |
||
22 | #endif |
||
23 | #ifdef HAVE_CMS |
||
3819 | subik | 24 | extern bool SCRIBUS_API CMSuse; |
413 | Franz | 25 | #endif |
26 | // these functions are located at utils.cpp |
||
3819 | subik | 27 | bool SCRIBUS_API loadText(QString nam, QString *Buffer); |
28 | void SCRIBUS_API ReOrderText(ScribusDoc *doc, ScribusView *view); |
||
413 | Franz | 29 | // end of utils.cpp |
30 | |||
9701 | jghali | 31 | #if defined(_WIN32) |
32 | #include "scwinprint.h" |
||
33 | #endif |
||
1745 | subik | 34 | |
733 | subik | 35 | typedef struct |
413 | Franz | 36 | { |
1745 | subik | 37 | PyObject_HEAD |
38 | PyObject *allPrinters; // list of strings - names of installed printers |
||
39 | PyObject *printer; // string - selected printer |
||
40 | PyObject *file; // string - name of file to print into (eg. output.ps) |
||
41 | PyObject *cmd; // string - if "" use standard command else use this as command (eg. "kprinter", "xpp" ...) |
||
42 | PyObject *pages; // list of integers - pages to be printed |
||
43 | int copies; // numer of printed copies |
||
44 | PyObject *separation; // string - No; All; Cyan; Magenta; Yellow; Black |
||
45 | int color; // bool - do we print in color=1 or greyscale=0 |
||
46 | int useICC; // bool - do we use ICC Profiles 0 = No 1 = Yes |
||
47 | int pslevel; // integer - 1, 2 or 3 level of used postscript |
||
48 | int mph; // bool - mirror pages horizontally |
||
49 | int mpv; // bool - mirror pages vertically |
||
50 | int ucr; // bool - Under Color Removal |
||
413 | Franz | 51 | } Printer; |
52 | |||
53 | |||
54 | static void Printer_dealloc(Printer* self) |
||
55 | { |
||
1745 | subik | 56 | Py_XDECREF(self->allPrinters); |
57 | Py_XDECREF(self->printer); |
||
58 | Py_XDECREF(self->file); |
||
59 | Py_XDECREF(self->cmd); |
||
60 | Py_XDECREF(self->pages); |
||
61 | Py_XDECREF(self->separation); |
||
62 | self->ob_type->tp_free((PyObject *)self); |
||
413 | Franz | 63 | } |
64 | |||
1745 | subik | 65 | static PyObject * Printer_new(PyTypeObject *type, PyObject */*args*/, PyObject */*kwds*/) |
413 | Franz | 66 | { |
67 | // do not create new object if there is no opened document |
||
4026 | craig | 68 | if (!ScMW->HaveDoc) { |
1745 | subik | 69 | PyErr_SetString(PyExc_SystemError, "Need to open document first"); |
70 | return NULL; |
||
71 | } |
||
413 | Franz | 72 | |
1745 | subik | 73 | Printer *self; |
74 | self = (Printer *)type->tp_alloc(type, 0); |
||
75 | if (self != NULL) { |
||
413 | Franz | 76 | // set allPrinters attribute |
1745 | subik | 77 | self->allPrinters = PyList_New(0); |
78 | if (self->allPrinters == NULL){ |
||
79 | Py_DECREF(self); |
||
80 | return NULL; |
||
81 | } |
||
413 | Franz | 82 | // set printer attribute |
1745 | subik | 83 | self->printer = PyString_FromString(""); |
84 | if (self->printer == NULL){ |
||
85 | Py_DECREF(self); |
||
86 | return NULL; |
||
87 | } |
||
413 | Franz | 88 | // set file attribute |
1745 | subik | 89 | self->file = PyString_FromString(""); |
90 | if (self->file == NULL){ |
||
91 | Py_DECREF(self); |
||
92 | return NULL; |
||
93 | } |
||
413 | Franz | 94 | // set cmd attribute |
1745 | subik | 95 | self->cmd = PyString_FromString(""); |
96 | if (self->cmd == NULL){ |
||
97 | Py_DECREF(self); |
||
98 | return NULL; |
||
99 | } |
||
413 | Franz | 100 | // set pages attribute |
1745 | subik | 101 | self->pages = PyList_New(0); |
102 | if (self->pages == NULL){ |
||
103 | Py_DECREF(self); |
||
104 | return NULL; |
||
105 | } |
||
413 | Franz | 106 | // set separation attribute |
1745 | subik | 107 | self->separation = PyString_FromString("No"); |
108 | if (self->separation == NULL){ |
||
109 | Py_DECREF(self); |
||
110 | return NULL; |
||
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; |
413 | Franz | 116 | // set pslevel attribute |
1745 | subik | 117 | self->pslevel = 3; |
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 | |||
1745 | subik | 130 | static int Printer_init(Printer *self, PyObject */*args*/, PyObject */*kwds*/) |
413 | Franz | 131 | { |
132 | // pool system for installed printers |
||
133 | // most code is stolen and little adopted from druck.cpp |
||
1745 | subik | 134 | PyObject *allPrinters = PyList_New(0); |
135 | if (allPrinters){ |
||
136 | Py_DECREF(self->allPrinters); |
||
137 | self->allPrinters = allPrinters; |
||
138 | } |
||
9698 | jghali | 139 | QStringList printers = PrinterUtil::getPrinterNames(); |
140 | for (uint i = 0; i < printers.count(); ++i) |
||
1745 | subik | 141 | { |
9698 | jghali | 142 | QString prn = printers[i]; |
143 | if (prn.isEmpty()) |
||
144 | continue; |
||
145 | PyObject *tmppr = PyString_FromString(prn); |
||
146 | if (tmppr){ |
||
147 | PyList_Append(self->allPrinters, tmppr); |
||
148 | Py_DECREF(tmppr); |
||
1745 | subik | 149 | } |
150 | } |
||
151 | PyObject *tmp2 = PyString_FromString("File"); |
||
152 | PyList_Append(self->allPrinters, tmp2); |
||
153 | Py_DECREF(tmp2); |
||
413 | Franz | 154 | // as defaut set to print into file |
1745 | subik | 155 | PyObject *printer = NULL; |
156 | printer = PyString_FromString("File"); |
||
157 | if (printer){ |
||
158 | Py_DECREF(self->printer); |
||
159 | self->printer = printer; |
||
160 | } |
||
413 | Franz | 161 | // set defaul name of file to print into |
4026 | craig | 162 | QString tf = ScMW->doc->PDF_Options.Datei; |
2877 | cbradney | 163 | if (tf.isEmpty()) { |
4026 | craig | 164 | QFileInfo fi = QFileInfo(ScMW->doc->DocName); |
1745 | subik | 165 | tf = fi.dirPath()+"/"+fi.baseName()+".pdf"; |
166 | } |
||
167 | PyObject *file = NULL; |
||
168 | file = PyString_FromString(tf.ascii()); |
||
169 | if (file){ |
||
170 | Py_DECREF(self->file); |
||
171 | self->file = file; |
||
172 | } else { |
||
173 | PyErr_SetString(PyExc_SystemError, "Can not initialize 'file' attribute"); |
||
174 | return -1; |
||
175 | } |
||
413 | Franz | 176 | // alternative printer commands default to "" |
1745 | subik | 177 | PyObject *cmd = NULL; |
178 | cmd = PyString_FromString(""); |
||
179 | if (cmd){ |
||
180 | Py_DECREF(self->cmd); |
||
181 | self->cmd = cmd; |
||
182 | } |
||
413 | Franz | 183 | // if document exist when created Printer instance |
184 | // set to print all pages |
||
1745 | subik | 185 | PyObject *pages = NULL; |
186 | int num = 0; |
||
4026 | craig | 187 | if (ScMW->HaveDoc) |
1745 | subik | 188 | // which one should I use ??? |
4026 | craig | 189 | // new = ScMW->view->Pages.count() |
4069 | craig | 190 | num = ScMW->doc->Pages->count(); |
1745 | subik | 191 | pages = PyList_New(num); |
192 | if (pages){ |
||
193 | Py_DECREF(self->pages); |
||
194 | self->pages = pages; |
||
195 | } |
||
196 | for (int i = 0; i<num; i++) { |
||
197 | PyObject *tmp=NULL; |
||
198 | tmp = PyInt_FromLong((long)i+1L); // instead of 1 put here first page number |
||
199 | if (tmp) |
||
200 | PyList_SetItem(self->pages, i, tmp); |
||
201 | } |
||
413 | Franz | 202 | // do not print separation |
1745 | subik | 203 | PyObject *separation = NULL; |
204 | separation = PyString_FromString("No"); |
||
205 | if (separation){ |
||
206 | Py_DECREF(self->separation); |
||
207 | self->separation = separation; |
||
208 | } |
||
413 | Franz | 209 | // print in color |
1745 | subik | 210 | self->color = 1; |
413 | Franz | 211 | // do not use ICC Profile |
1745 | subik | 212 | self->useICC = 0; |
413 | Franz | 213 | // use PostScrip level 3 |
1745 | subik | 214 | self->pslevel = 3; |
413 | Franz | 215 | // do not mirror pages |
1745 | subik | 216 | self->mph = 0; |
413 | Franz | 217 | // do not mirror pages |
1745 | subik | 218 | self->mpv = 0; |
413 | Franz | 219 | // apply Under Color Removal as default |
1745 | subik | 220 | self->ucr = 1; |
413 | Franz | 221 | // number of copies |
1745 | subik | 222 | self->copies = 1; |
223 | return 0; |
||
413 | Franz | 224 | } |
225 | |||
226 | static PyMemberDef Printer_members[] = { |
||
1745 | subik | 227 | {const_cast<char*>("copies"), T_INT, offsetof(Printer, copies), 0, const_cast<char*>("Number of copies")}, |
228 | {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")}, |
||
229 | {const_cast<char*>("useICC"), T_INT, offsetof(Printer, useICC), 0, const_cast<char*>("Use ICC Profile\n\tTrue\n\tFalse -- Default")}, |
||
230 | {const_cast<char*>("pslevel"), T_INT, offsetof(Printer, pslevel), 0, const_cast<char*>("PostScript Level\nCan be 1 or 2 or 3 -- Default is 3.")}, |
||
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")}, |
||
234 | {NULL, 0, 0, 0, NULL} // sentinel |
||
413 | Franz | 235 | }; |
236 | |||
237 | /* Here begins Getter & Setter functions */ |
||
238 | |||
1745 | subik | 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 | |||
1745 | subik | 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 | |||
1745 | subik | 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 | |||
1745 | subik | 257 | static int Printer_setprinter(Printer *self, PyObject *value, void */*closure*/) |
413 | Franz | 258 | { |
1745 | subik | 259 | if (value == NULL) { |
260 | PyErr_SetString(PyExc_TypeError, "Cannot delete 'printer' attribute."); |
||
261 | return -1; |
||
262 | } |
||
263 | if (!PyString_Check(value)) { |
||
264 | PyErr_SetString(PyExc_TypeError, "The 'printer' attribute value must be string."); |
||
265 | return -1; |
||
266 | } |
||
267 | int n = PyList_Size(self->allPrinters); |
||
268 | bool same = 0; |
||
269 | for (int i = 0; i<n; i++) |
||
270 | if (PyObject_RichCompareBool(value, PyList_GetItem(self->allPrinters, i), Py_EQ) == 1) |
||
271 | same = true; |
||
272 | if (!same) { |
||
273 | PyErr_SetString(PyExc_ValueError, "'printer' value can be only one of string in 'allPrinters' attribute "); |
||
274 | return -1; |
||
275 | } |
||
276 | Py_DECREF(self->printer); |
||
277 | Py_INCREF(value); |
||
278 | self->printer = value; |
||
279 | return 0; |
||
413 | Franz | 280 | } |
281 | |||
1745 | subik | 282 | static PyObject *Printer_getfile(Printer *self, void */*closure*/) |
413 | Franz | 283 | { |
1745 | subik | 284 | Py_INCREF(self->file); |
285 | return self->file; |
||
413 | Franz | 286 | } |
287 | |||
1745 | subik | 288 | static int Printer_setfile(Printer *self, PyObject *value, void */*closure*/) |
413 | Franz | 289 | { |
1745 | subik | 290 | if (value == NULL) { |
291 | PyErr_SetString(PyExc_TypeError, "Cannot delete 'file' attribute."); |
||
292 | return -1; |
||
293 | } |
||
294 | if (!PyString_Check(value)) { |
||
295 | PyErr_SetString(PyExc_TypeError, "The 'file' attribute value must be string."); |
||
296 | return -1; |
||
297 | } |
||
298 | Py_DECREF(self->file); |
||
299 | Py_INCREF(value); |
||
300 | self->file = value; |
||
301 | return 0; |
||
413 | Franz | 302 | } |
303 | |||
1745 | subik | 304 | static PyObject *Printer_getcmd(Printer *self, void */*closure*/) |
413 | Franz | 305 | { |
1745 | subik | 306 | Py_INCREF(self->cmd); |
307 | return self->cmd; |
||
413 | Franz | 308 | } |
309 | |||
1745 | subik | 310 | static int Printer_setcmd(Printer *self, PyObject *value, void */*closure*/) |
413 | Franz | 311 | { |
1745 | subik | 312 | if (value == NULL) { |
313 | PyErr_SetString(PyExc_TypeError, "Cannot delete 'cmd' attribute."); |
||
314 | return -1; |
||
315 | } |
||
316 | if (!PyString_Check(value)) { |
||
317 | PyErr_SetString(PyExc_TypeError, "The 'cmd' attribute value must be string."); |
||
318 | return -1; |
||
319 | } |
||
320 | Py_DECREF(self->cmd); |
||
321 | Py_INCREF(value); |
||
322 | self->cmd = value; |
||
323 | return 0; |
||
413 | Franz | 324 | } |
325 | |||
1745 | subik | 326 | static PyObject *Printer_getpages(Printer *self, void */*closure*/) |
413 | Franz | 327 | { |
1745 | subik | 328 | Py_INCREF(self->pages); |
329 | return self->pages; |
||
413 | Franz | 330 | } |
331 | |||
1745 | subik | 332 | static int Printer_setpages(Printer *self, PyObject *value, void */*closure*/) |
413 | Franz | 333 | { |
1745 | subik | 334 | if (value == NULL) { |
335 | PyErr_SetString(PyExc_TypeError, "Cannot delete 'pages' attribute."); |
||
336 | return -1; |
||
337 | } |
||
338 | if (!PyList_Check(value)) { |
||
339 | PyErr_SetString(PyExc_TypeError, "'pages' attribute value must be list of integers."); |
||
340 | return -1; |
||
341 | } |
||
342 | int len = PyList_Size(value); |
||
343 | for (int i = 0; i<len; i++){ |
||
344 | PyObject *tmp = PyList_GetItem(value, i); |
||
345 | if (!PyInt_Check(tmp)){ |
||
346 | PyErr_SetString(PyExc_TypeError, "'pages' attribute must be list containing only integers."); |
||
347 | return -1; |
||
348 | } |
||
4166 | fschmid | 349 | if (PyInt_AsLong(tmp) > static_cast<int>(ScMW->doc->Pages->count()) || PyInt_AsLong(tmp) < 1) { |
1745 | subik | 350 | PyErr_SetString(PyExc_ValueError, "'pages' value out of range."); |
351 | return -1; |
||
352 | } |
||
353 | } |
||
354 | Py_DECREF(self->pages); |
||
355 | Py_INCREF(value); |
||
356 | self->pages = value; |
||
357 | return 0; |
||
413 | Franz | 358 | } |
359 | |||
1745 | subik | 360 | static PyObject *Printer_getseparation(Printer *self, void */*closure*/) |
413 | Franz | 361 | { |
1745 | subik | 362 | Py_INCREF(self->separation); |
363 | return self->separation; |
||
413 | Franz | 364 | } |
365 | |||
1745 | subik | 366 | static int Printer_setseparation(Printer *self, PyObject *value, void */*closure*/) |
413 | Franz | 367 | { |
1745 | subik | 368 | if (value == NULL) { |
369 | PyErr_SetString(PyExc_TypeError, "Cannot delete 'separation' attribute."); |
||
370 | return -1; |
||
371 | } |
||
372 | if (!PyString_Check(value)) { |
||
373 | PyErr_SetString(PyExc_TypeError, "The 'separation' attribute value must be string."); |
||
374 | return -1; |
||
375 | } |
||
376 | Py_DECREF(self->separation); |
||
377 | Py_INCREF(value); |
||
378 | self->separation = value; |
||
379 | return 0; |
||
413 | Franz | 380 | } |
381 | |||
382 | |||
383 | static PyGetSetDef Printer_getseters [] = { |
||
1745 | subik | 384 | {const_cast<char*>("allPrinters"), (getter)Printer_getallPrinters, (setter)Printer_setallPrinters, const_cast<char*>("List of installed printers -- read only"), NULL}, |
385 | {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"), NULL}, |
||
386 | {const_cast<char*>("file"), (getter)Printer_getfile, (setter)Printer_setfile, const_cast<char*>("Name of file to print into"), NULL}, |
||
387 | {const_cast<char*>("cmd"), (getter)Printer_getcmd, (setter)Printer_setcmd, const_cast<char*>("Alternative Printer Command"), NULL}, |
||
388 | {const_cast<char*>("pages"), (getter)Printer_getpages, (setter)Printer_setpages, const_cast<char*>("List of pages to be printed"), NULL}, |
||
389 | {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"), NULL}, |
||
390 | {NULL, NULL, NULL, NULL, NULL} // sentinel |
||
413 | Franz | 391 | }; |
392 | |||
733 | subik | 393 | // Here we actually print |
413 | Franz | 394 | static PyObject *Printer_print(Printer *self) |
395 | { |
||
4026 | craig | 396 | if (!ScMW->HaveDoc) { |
1745 | subik | 397 | PyErr_SetString(PyExc_SystemError, "Need to open documetnt first"); |
398 | return NULL; |
||
399 | } |
||
4026 | craig | 400 | // copied from void ScribusMainWindow::slotFilePrint() in file scribus.cpp |
1745 | subik | 401 | QString fna, prn, cmd, scmd, cc, data, SepName; |
402 | QString printcomm; |
||
403 | int Nr, PSLevel; |
||
404 | bool fil, sep, color, PSfile, mirrorH, mirrorV, useICC, DoGCR; |
||
405 | PSfile = false; |
||
413 | Franz | 406 | |
4026 | craig | 407 | // ReOrderText(ScMW->doc, ScMW->view); |
1745 | subik | 408 | prn = QString(PyString_AsString(self->printer)); |
409 | fna = QString(PyString_AsString(self->file)); |
||
410 | fil = (QString(PyString_AsString(self->printer)) == QString("File")) ? true : false; |
||
411 | std::vector<int> pageNs; |
||
412 | for (int i = 0; i < PyList_Size(self->pages); ++i) { |
||
413 | pageNs.push_back((int)PyInt_AsLong(PyList_GetItem(self->pages, i))); |
||
414 | } |
||
415 | Nr = (self->copies < 1) ? 1 : self->copies; |
||
416 | SepName = QString(PyString_AsString(self->separation)); |
||
417 | sep =(SepName == QString("No")) ? false : true; |
||
418 | // if (SepName == QString("All")) |
||
419 | // SepName = tr(SepName); |
||
420 | color = self->color; |
||
421 | mirrorH = self->mph; |
||
422 | mirrorV = self->mpv; |
||
423 | useICC = self->useICC; |
||
424 | DoGCR = self->ucr; |
||
425 | int psl = self->pslevel; |
||
426 | if (psl < 1) |
||
427 | psl = 1; |
||
428 | else if (psl > 3) |
||
429 | psl = 3; |
||
430 | PSLevel = psl; |
||
431 | printcomm = QString(PyString_AsString(self->cmd)); |
||
3544 | avox | 432 | QMap<QString,int> ReallyUsed; |
1745 | subik | 433 | ReallyUsed.clear(); |
4026 | craig | 434 | ScMW->doc->getUsedFonts(&ReallyUsed); |
3136 | fschmid | 435 | PrefsManager *prefsManager=PrefsManager::instance(); |
9701 | jghali | 436 | |
437 | #if defined(_WIN32) |
||
438 | if (!fil) |
||
439 | { |
||
440 | PrintOptions options; |
||
441 | options.printer = prn; |
||
442 | options.filename = fna; |
||
443 | options.toFile = fil; |
||
444 | options.pageNumbers = pageNs; |
||
445 | options.copies = Nr; |
||
446 | options.outputSeparations = sep; |
||
447 | options.separationName = SepName; |
||
448 | options.allSeparations = false; |
||
449 | options.useColor = color; |
||
450 | options.mirrorH = mirrorH; |
||
451 | options.mirrorV = mirrorV; |
||
452 | options.useICC = useICC; |
||
453 | options.doClip = false; |
||
454 | options.doGCR = DoGCR; |
||
455 | options.PSLevel = psl; |
||
456 | options.setDevParam = false; |
||
457 | options.useAltPrintCommand = false; |
||
458 | |||
459 | QByteArray devMode; |
||
460 | bool printDone = false; |
||
461 | if ( PrinterUtil::getDefaultSettings(prn, devMode) ) |
||
462 | { |
||
463 | ScWinPrint winPrint; |
||
464 | printDone = winPrint.print( ScMW->doc, options, devMode, false ); |
||
465 | } |
||
466 | if (!printDone) |
||
467 | PyErr_SetString(PyExc_SystemError, "Printing failed"); |
||
468 | Py_INCREF(Py_None); |
||
469 | return Py_None; |
||
470 | } |
||
471 | #endif |
||
472 | |||
4026 | craig | 473 | PSLib *dd = new PSLib(true, prefsManager->appPrefs.AvailFonts, ReallyUsed, ScMW->doc->PageColors, false, true); |
1745 | subik | 474 | if (dd != NULL) |
475 | { |
||
476 | if (!fil) |
||
9701 | jghali | 477 | fna = ScMW->PrefsPfad + "/tmp.ps"; |
1745 | subik | 478 | PSfile = dd->PS_set_file(fna); |
2921 | fschmid | 479 | fna = QDir::convertSeparators(fna); |
1745 | subik | 480 | if (PSfile) |
481 | { |
||
3068 | fschmid | 482 | QStringList spots; |
4649 | fschmid | 483 | dd->CreatePS(ScMW->doc, /*ScMW->view, */pageNs, sep, SepName, spots, color, mirrorH, mirrorV, useICC, DoGCR, false, false); |
1745 | subik | 484 | if (PSLevel != 3) |
485 | { |
||
486 | QString tmp; |
||
4194 | fschmid | 487 | QStringList opts; |
488 | opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(ScMW->doc->pageWidth)) ); |
||
489 | opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(ScMW->doc->pageHeight)) ); |
||
490 | convertPS2PS(fna, fna+".tmp", opts, PSLevel); |
||
491 | moveFile( fna + ".tmp", fna ); |
||
1745 | subik | 492 | } |
418 | Franz | 493 | |
1745 | subik | 494 | if (!fil) |
495 | { |
||
2877 | cbradney | 496 | if (!printcomm.isEmpty()) |
1745 | subik | 497 | cmd = printcomm + " "+fna; |
498 | else |
||
499 | { |
||
500 | cmd = "lpr -P" + prn; |
||
501 | if (Nr > 1) |
||
502 | cmd += " -#" + cc.setNum(Nr); |
||
413 | Franz | 503 | #ifdef HAVE_CUPS |
418 | Franz | 504 | // This need yet to be implemented by object Printer |
1745 | subik | 505 | // cmd += printer->PrinterOpts; |
413 | Franz | 506 | #endif |
1745 | subik | 507 | cmd += " "+fna; |
508 | } |
||
509 | system(cmd); |
||
510 | unlink(fna); |
||
511 | } |
||
512 | } |
||
513 | else { |
||
514 | delete dd; |
||
515 | PyErr_SetString(PyExc_SystemError, "Printing failed"); |
||
516 | return NULL; |
||
517 | } |
||
518 | delete dd; |
||
519 | } |
||
520 | Py_INCREF(Py_None); |
||
521 | return Py_None; |
||
413 | Franz | 522 | } |
523 | |||
524 | static PyMethodDef Printer_methods[] = { |
||
1745 | subik | 525 | {const_cast<char*>("print"), (PyCFunction)Printer_print, METH_NOARGS, const_cast<char*>("Prints selected pages.")}, |
526 | {NULL, (PyCFunction)(0), 0, NULL} // sentinel |
||
413 | Franz | 527 | }; |
528 | |||
529 | PyTypeObject Printer_Type = { |
||
1745 | subik | 530 | PyObject_HEAD_INIT(NULL) // PyObject_VAR_HEAD |
531 | 0, // |
||
532 | const_cast<char*>("Printer"), // char *tp_name; /* For printing, in format "<module>.<name>" */ |
||
533 | sizeof(Printer), // int tp_basicsize, /* For allocation */ |
||
534 | 0, // int tp_itemsize; /* For allocation */ |
||
413 | Franz | 535 | |
536 | /* Methods to implement standard operations */ |
||
537 | |||
1745 | subik | 538 | (destructor) Printer_dealloc, // destructor tp_dealloc; |
539 | 0, // printfunc tp_print; |
||
540 | 0, // getattrfunc tp_getattr; |
||
541 | 0, // setattrfunc tp_setattr; |
||
542 | 0, // cmpfunc tp_compare; |
||
543 | 0, // reprfunc tp_repr; |
||
413 | Franz | 544 | |
545 | /* Method suites for standard classes */ |
||
546 | |||
1745 | subik | 547 | 0, // PyNumberMethods *tp_as_number; |
548 | 0, // PySequenceMethods *tp_as_sequence; |
||
549 | 0, // PyMappingMethods *tp_as_mapping; |
||
413 | Franz | 550 | |
551 | /* More standard operations (here for binary compatibility) */ |
||
552 | |||
1745 | subik | 553 | 0, // hashfunc tp_hash; |
554 | 0, // ternaryfunc tp_call; |
||
555 | 0, // reprfunc tp_str; |
||
556 | 0, // getattrofunc tp_getattro; |
||
557 | 0, // setattrofunc tp_setattro; |
||
413 | Franz | 558 | |
559 | /* Functions to access object as input/output buffer */ |
||
1745 | subik | 560 | 0, // PyBufferProcs *tp_as_buffer; |
413 | Franz | 561 | |
562 | /* Flags to define presence of optional/expanded features */ |
||
1745 | subik | 563 | Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, // long tp_flags; |
413 | Franz | 564 | |
1745 | subik | 565 | printer__doc__, // char *tp_doc; /* Documentation string */ |
733 | subik | 566 | |
413 | Franz | 567 | /* Assigned meaning in release 2.0 */ |
568 | /* call function for all accessible objects */ |
||
1745 | subik | 569 | 0, // traverseproc tp_traverse; |
413 | Franz | 570 | |
571 | /* delete references to contained objects */ |
||
1745 | subik | 572 | 0, // inquiry tp_clear; |
413 | Franz | 573 | |
574 | /* Assigned meaning in release 2.1 */ |
||
575 | /* rich comparisons */ |
||
1745 | subik | 576 | 0, // richcmpfunc tp_richcompare; |
413 | Franz | 577 | |
578 | /* weak reference enabler */ |
||
1745 | subik | 579 | 0, // long tp_weaklistoffset; |
413 | Franz | 580 | |
581 | /* Added in release 2.2 */ |
||
582 | /* Iterators */ |
||
1745 | subik | 583 | 0, // getiterfunc tp_iter; |
584 | 0, // iternextfunc tp_iternext; |
||
413 | Franz | 585 | |
586 | /* Attribute descriptor and subclassing stuff */ |
||
1745 | subik | 587 | Printer_methods, // struct PyMethodDef *tp_methods; |
588 | Printer_members, // struct PyMemberDef *tp_members; |
||
589 | Printer_getseters, // struct PyGetSetDef *tp_getset; |
||
590 | 0, // struct _typeobject *tp_base; |
||
591 | 0, // PyObject *tp_dict; |
||
592 | 0, // descrgetfunc tp_descr_get; |
||
593 | 0, // descrsetfunc tp_descr_set; |
||
594 | 0, // long tp_dictoffset; |
||
595 | (initproc)Printer_init, // initproc tp_init; |
||
596 | 0, // allocfunc tp_alloc; |
||
597 | Printer_new, // newfunc tp_new; |
||
598 | 0, // freefunc tp_free; /* Low-level free-memory routine */ |
||
599 | 0, // inquiry tp_is_gc; /* For PyObject_IS_GC */ |
||
600 | 0, // PyObject *tp_bases; |
||
601 | 0, // PyObject *tp_mro; /* method resolution order */ |
||
602 | 0, // PyObject *tp_cache; |
||
603 | 0, // PyObject *tp_subclasses; |
||
604 | 0, // PyObject *tp_weaklist; |
||
605 | 0, // destructor tp_del; |
||
413 | Franz | 606 | |
607 | #ifdef COUNT_ALLOCS |
||
608 | /* these must be last and never explicitly initialized */ |
||
1745 | subik | 609 | // int tp_allocs; |
610 | // int tp_frees; |
||
611 | // int tp_maxalloc; |
||
612 | // struct _typeobject *tp_next; |
||
413 | Franz | 613 | #endif |
614 | }; |