Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

scprintengine_ps.cpp

Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 
00008 #include "scprintengine_ps.h"
00009 #include "scribusstructs.h"
00010 #include "scribusdoc.h"
00011 #include "scribuscore.h"
00012 #include "prefsmanager.h"
00013 #include "pslib.h"
00014 #include "util.h"
00015 #include "util_ghostscript.h"
00016 
00017 bool ScPrintEngine_PS::print(ScribusDoc& doc, PrintOptions& options)
00018 {
00019     bool retw = false;
00020     ColorList usedColors;
00021     QMap<QString, QMap<uint, FPointArray> > usedFonts;
00022     QString filename(options.filename);
00023     doc.getUsedFonts(usedFonts);
00024     doc.getUsedColors(usedColors);
00025     PrefsManager *prefsManager = PrefsManager::instance();
00026     PSLib *dd = new PSLib(options, true, prefsManager->appPrefs.AvailFonts, usedFonts, usedColors, false, options.useSpotColors);
00027     if (dd != NULL)
00028     {
00029         if (!options.toFile)
00030             filename = prefsManager->preferencesLocation()+"/tmp.ps";
00031         bool PSfile = dd->PS_set_file(filename);
00032         filename = QDir::convertSeparators(filename);
00033         if (PSfile)
00034         {
00035             // Write the PS to a file
00036             int psCreationRetVal=dd->CreatePS(&doc, options);
00037             if (psCreationRetVal!=0)
00038             {
00039                 QFile::remove(filename);
00040                 if (psCreationRetVal==2)
00041                     return true;
00042                 else
00043                 {
00044                     m_errorMessage = dd->errorMessage();
00045                     return false;
00046                 }
00047             }
00048             if (options.prnEngine != PostScript3 && ScCore->haveGS())
00049             {
00050                 // use gs to convert our PS to a lower version
00051                 QString tmp;
00052                 QStringList opts;
00053                 opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(doc.pageWidth)) );
00054                 opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(doc.pageHeight)) );
00055                 convertPS2PS(filename, filename + ".tmp", opts, options.prnEngine);
00056                 moveFile( filename + ".tmp", filename );
00057             }
00058             if (!options.toFile)
00059             {
00060                 // print and delete the PS file
00061                 QByteArray cmd;
00062                 if (options.useAltPrintCommand)
00063                 {
00064                     cmd += options.printerCommand;
00065                     cmd += " ";
00066                     cmd += filename;
00067                     system(cmd.data());
00068                 }
00069                 else
00070                 {
00071                     QByteArray cc;
00072                     cmd += "lpr -P '";
00073                     cmd += options.printer;
00074                     cmd += "'";
00075                     if (options.copies > 1)
00076                         cmd += " -#" + cc.setNum(options.copies);
00077                     cmd += options.printerOptions;
00078                     cmd += " "+filename;
00079                     system(cmd.data());
00080                 }
00081 // Disabled that for now, as kprinter won't work otherwise
00082 // leaving that file around doesn't harm, as it will be overwritten the next time.
00083 //              unlink(filename);
00084             }
00085             retw = true;
00086         }
00087         else
00088             retw = false;
00089         delete dd;
00090     }
00091     return retw;
00092 }
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.