bool ScPrintEngine_GDI::printPage_PS ( ScribusDoc* doc, Page* page, PrintOptions& options, HDC printerDC, cairo_t* /*context*/ ) { bool succeed = false; ColorList usedColors; PrintOptions options2 = options; QMap<QString, QMap<uint, FPointArray> > usedFonts; QString tempFilePath; int ret = 0; doc->getUsedFonts(usedFonts); doc->getUsedColors(usedColors); options2.pageNumbers.clear(); options2.pageNumbers.push_back(page->pageNr() + 1 ); tempFilePath = PrefsManager::instance()->preferencesLocation() + "/tmp.ps"; PSLib *dd = new PSLib(options2, false, PrefsManager::instance()->appPrefs.AvailFonts, usedFonts, usedColors, false, options2.useSpotColors ); dd->PS_set_file( tempFilePath ); ret = dd->CreatePS( doc, options2); delete dd; if (ret != 0) return false; if ( options.prnEngine == PostScript1 || options.prnEngine == PostScript2 ) { QString tmp; QStringList opts; QString tempFilePath2 = PrefsManager::instance()->preferencesLocation() + "/tmp2.ps"; opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(doc->pageWidth)) ); opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(doc->pageHeight)) ); if ( QFile::exists( tempFilePath2 ) ) QFile::remove( tempFilePath2 ); ret = convertPS2PS(tempFilePath, tempFilePath2, opts, options.prnEngine); if ( ret == 0 ) { QFile::remove( tempFilePath ); tempFilePath = tempFilePath2; } else { QFile::remove( tempFilePath2 ); } } if( ret == 0 ) { double bleedH = options.bleeds.Left + options.bleeds.Right; double bleedV = options.bleeds.Top + options.bleeds.Bottom; StartPage( printerDC ); succeed = sendPSFile( tempFilePath, printerDC, page->width() + bleedH, page->height() + bleedV, (page->PageOri == 1)); EndPage( printerDC ); } QFile::remove( tempFilePath ); return succeed; }
void PrinterAPI::doPrint() { // copied from void ScribusMainWindow::slotFilePrint() in file scribus.cpp QString fna, prn, cmd, scmd, cc, data, SepName; QString printcomm; bool fil, PSfile; PSfile = false; // ReOrderText(ScCore->primaryMainWindow()->doc, ScCore->primaryMainWindow()->view); prn = printer; fna = file; fil = (printer == QString("File")) ? true : false; std::vector<int> pageNs; PrintOptions options; for (int i = 0; i < pages.size(); ++i) { options.pageNumbers.push_back(pages[i]); } int Nr = (copies < 1) ? 1 : copies; SepName = separation; options.printer = prn; options.prnEngine = (PrintEngine) pslevel; options.toFile = fil; options.separationName = SepName; options.outputSeparations = (SepName == QString("No")) ? false : true; options.useColor = color; options.mirrorH = mph; options.mirrorV = mpv; options.useICC = useICC; options.doGCR = ucr; options.cropMarks = false; options.bleedMarks = false; options.registrationMarks = false; options.colorMarks = false; options.markOffset = 0.0; options.bleeds.setTop(0.0); options.bleeds.setLeft(0.0); options.bleeds.setRight(0.0); options.bleeds.setBottom(0.0); if (!PrinterUtil::checkPrintEngineSupport(options.printer, options.prnEngine, options.toFile)) options.prnEngine = PrinterUtil::getDefaultPrintEngine(options.printer, options.toFile); printcomm = cmd; QMap<QString, QMap<uint, FPointArray> > ReallyUsed; ReallyUsed.clear(); ScCore->primaryMainWindow()->doc->getUsedFonts(ReallyUsed); PrefsManager *prefsManager=PrefsManager::instance(); #if defined(_WIN32) if (!options.toFile) { QByteArray devMode; bool printDone = false; if ( PrinterUtil::getDefaultSettings(prn, options.devMode) ) { ScPrintEngine_GDI winPrint; printDone = winPrint.print( *ScCore->primaryMainWindow()->doc, options ); } if (!printDone) RAISE("Printing failed"); } #endif PSLib *dd = new PSLib(options, true, prefsManager->appPrefs.fontPrefs.AvailFonts, ReallyUsed, ScCore->primaryMainWindow()->doc->PageColors, false, true); if (dd != NULL) { if (!fil) fna = QDir::toNativeSeparators(ScPaths::getTempFileDir()+"/tmp.ps"); PSfile = dd->PS_set_file(fna); fna = QDir::toNativeSeparators(fna); if (PSfile) { options.setDevParam = false; options.doClip = false; dd->CreatePS(ScCore->primaryMainWindow()->doc, options); if (options.prnEngine == PostScript1 || options.prnEngine == PostScript2) { if (ScCore->haveGS()) { QString tmp; QStringList opts; opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(ScCore->primaryMainWindow()->doc->pageWidth())) ); opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(ScCore->primaryMainWindow()->doc->pageHeight())) ); convertPS2PS(fna, fna+".tmp", opts, options.prnEngine); moveFile( fna + ".tmp", fna ); } else { RAISE("Printing failed : GhostScript is needed to print to PostScript Level 1 or Level 2"); } } if (!fil) { if (!printcomm.isEmpty()) cmd = printcomm + " "+fna; else { cmd = "lpr -P" + prn; if (Nr > 1) cmd += " -#" + cc.setNum(Nr); #ifdef HAVE_CUPS // This need yet to be implemented by object Printer // cmd += printer->PrinterOpts; #endif cmd += " "+fna; } system(cmd.toLocal8Bit().constData()); unlink(fna.toLocal8Bit().constData()); } } else { delete dd; RAISE("Printing failed"); } delete dd; } }
// Here we actually print static PyObject *Printer_print(Printer *self) { if (!checkHaveDocument()) { return NULL; } // copied from void ScribusMainWindow::slotFilePrint() in file scribus.cpp QString fna, prn, cmd, cc, SepName; QString printcomm; bool fil, PSfile; PSfile = false; // ReOrderText(ScCore->primaryMainWindow()->doc, ScCore->primaryMainWindow()->view); prn = QString(PyString_AsString(self->printer)); fna = QString(PyString_AsString(self->file)); fil = (QString(PyString_AsString(self->printer)) == QString("File")) ? true : false; std::vector<int> pageNs; PrintOptions options; for (int i = 0; i < PyList_Size(self->pages); ++i) { options.pageNumbers.push_back((int)PyInt_AsLong(PyList_GetItem(self->pages, i))); } int Nr = (self->copies < 1) ? 1 : self->copies; SepName = QString(PyString_AsString(self->separation)); options.printer = prn; options.prnEngine = (PrintEngine) self->pslevel; options.toFile = fil; options.separationName = SepName; options.outputSeparations = (SepName == QString("No")) ? false : true; options.useColor = self->color; options.mirrorH = self->mph; options.mirrorV = self->mpv; options.doGCR = self->ucr; options.cropMarks = false; options.bleedMarks = false; options.registrationMarks = false; options.colorMarks = false; options.markOffset = 0.0; options.bleeds.set(0, 0, 0, 0); if (!PrinterUtil::checkPrintEngineSupport(options.printer, options.prnEngine, options.toFile)) options.prnEngine = PrinterUtil::getDefaultPrintEngine(options.printer, options.toFile); printcomm = QString(PyString_AsString(self->cmd)); QMap<QString, QMap<uint, FPointArray> > ReallyUsed; ReallyUsed.clear(); ScCore->primaryMainWindow()->doc->getUsedFonts(ReallyUsed); PrefsManager *prefsManager=PrefsManager::instance(); #if defined(_WIN32) if (!options.toFile) { QByteArray devMode; bool printDone = false; if ( PrinterUtil::getDefaultSettings(prn, options.devMode) ) { ScPrintEngine_GDI winPrint; printDone = winPrint.print( *ScCore->primaryMainWindow()->doc, options ); } if (!printDone) PyErr_SetString(PyExc_SystemError, "Printing failed"); Py_RETURN_NONE; } #endif PSLib *dd = new PSLib(options, true, prefsManager->appPrefs.fontPrefs.AvailFonts, ReallyUsed, ScCore->primaryMainWindow()->doc->PageColors, false, true); if (dd != NULL) { if (!fil) fna = QDir::toNativeSeparators(ScPaths::tempFileDir()+"/tmp.ps"); PSfile = dd->PS_set_file(fna); fna = QDir::toNativeSeparators(fna); if (PSfile) { options.setDevParam = false; options.doClip = false; dd->CreatePS(ScCore->primaryMainWindow()->doc, options); if (options.prnEngine == PostScript1 || options.prnEngine == PostScript2) { if (ScCore->haveGS()) { QString tmp; QStringList opts; opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(ScCore->primaryMainWindow()->doc->pageWidth())) ); opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(ScCore->primaryMainWindow()->doc->pageHeight())) ); convertPS2PS(fna, fna+".tmp", opts, options.prnEngine); moveFile( fna + ".tmp", fna ); } else { PyErr_SetString(PyExc_SystemError, "Printing failed : GhostScript is needed to print to PostScript Level 1 or Level 2"); Py_RETURN_NONE; } } if (!fil) { if (!printcomm.isEmpty()) cmd = printcomm + " "+fna; else { cmd = "lpr -P" + prn; if (Nr > 1) cmd += " -#" + cc.setNum(Nr); cmd += " "+fna; } system(cmd.toLocal8Bit().constData()); unlink(fna.toLocal8Bit().constData()); } } else { delete dd; PyErr_SetString(PyExc_SystemError, "Printing failed"); return NULL; } delete dd; } // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; }
bool ScPrintEngine_PS::print(ScribusDoc& doc, PrintOptions& options) { bool retw = false; ColorList usedColors; QMap<QString, QMap<uint, FPointArray> > usedFonts; QString filename(options.filename); doc.getUsedFonts(usedFonts); doc.getUsedColors(usedColors); PrefsManager *prefsManager = PrefsManager::instance(); PSLib *dd = new PSLib(options, true, prefsManager->appPrefs.AvailFonts, usedFonts, usedColors, options.includePDFMarks, options.useSpotColors); if (dd != NULL) { if (!options.toFile) filename = prefsManager->preferencesLocation()+"/tmp.ps"; bool PSfile = dd->PS_set_file(filename); filename = QDir::toNativeSeparators(filename); if (PSfile) { // Write the PS to a file int psCreationRetVal=dd->CreatePS(&doc, options); if (psCreationRetVal!=0) { QFile::remove(filename); if (psCreationRetVal==2) return true; else { m_errorMessage = dd->errorMessage(); return false; } } if (options.prnEngine != PostScript3 && ScCore->haveGS()) { // use gs to convert our PS to a lower version QString tmp; QStringList opts; opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(doc.pageWidth)) ); opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(doc.pageHeight)) ); convertPS2PS(filename, filename + ".tmp", opts, options.prnEngine); moveFile( filename + ".tmp", filename ); } if (!options.toFile) { // print and delete the PS file QByteArray cmd; if (options.useAltPrintCommand) { cmd += options.printerCommand; cmd += " "; cmd += filename; system(cmd.data()); } else { QByteArray cc; cmd += "lpr -P '"; cmd += options.printer; cmd += "'"; if (options.copies > 1) cmd += " -#" + cc.setNum(options.copies); cmd += options.printerOptions; cmd += " "+filename; system(cmd.data()); } // Disabled that for now, as kprinter won't work otherwise // leaving that file around doesn't harm, as it will be overwritten the next time. // unlink(filename); } retw = true; } else retw = false; delete dd; } return retw; }