Subversion Repositories Scribus

Rev

Rev 24049 | Rev 24501 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10967 jghali 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
*/
7
 
23849 jghali 8
#include "scpaths.h"
10967 jghali 9
#include "scprintengine_ps.h"
10
#include "scribusstructs.h"
11
#include "scribusdoc.h"
12
#include "scribuscore.h"
13
#include "pslib.h"
11605 jghali 14
#include "util_file.h"
10967 jghali 15
#include "util_ghostscript.h"
16
 
23873 jghali 17
ScPrintEngine_PS::ScPrintEngine_PS(ScribusDoc& doc)
18
        : ScPrintEngine(doc)
10967 jghali 19
{
23873 jghali 20
 
21
}
22
 
23
bool ScPrintEngine_PS::print(PrintOptions& options)
24
{
10967 jghali 25
        QString filename(options.filename);
23873 jghali 26
        PSLib *dd = new PSLib(&m_doc, options, PSLib::OutputPS);
22534 craig 27
        if (dd == nullptr)
28
                return false;
29
 
30
        if (!options.toFile)
23849 jghali 31
                filename = ScPaths::tempFileDir() + "/tmp.ps";
22689 jghali 32
 
33
        // Write the PS to a file
22534 craig 34
        filename = QDir::toNativeSeparators(filename);
22689 jghali 35
 
23559 jghali 36
        int psCreationRetVal = dd->createPS(filename);
23557 jghali 37
        if (psCreationRetVal != 0)
10967 jghali 38
        {
22689 jghali 39
                QFile::remove(filename);
23557 jghali 40
                if (psCreationRetVal == 2)
22689 jghali 41
                        return true;
42
                m_errorMessage = dd->errorMessage();
43
                return false;
44
        }
24049 jghali 45
        if (options.prnLanguage != PrintLanguage::PostScript3 && ScCore->haveGS())
22689 jghali 46
        {
47
                // use gs to convert our PS to a lower version
48
                QString tmp;
49
                QStringList opts;
23873 jghali 50
                opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(m_doc.pageWidth())) );
51
                opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(m_doc.pageHeight())) );
24049 jghali 52
                convertPS2PS(filename, filename + ".tmp", opts, (int) options.prnLanguage);
22689 jghali 53
                moveFile(filename + ".tmp", filename);
54
        }
23873 jghali 55
        if (options.toFile)
56
                return true;
57
 
58
        // Print and delete the PS file
59
        QByteArray cmd;
60
        if (options.useAltPrintCommand)
22689 jghali 61
        {
23873 jghali 62
                cmd += options.printerCommand;
63
                cmd += " ";
24060 jghali 64
                cmd += "\"" + filename + "\"";
23873 jghali 65
                system(cmd.data());
10967 jghali 66
        }
23873 jghali 67
        else
68
        {
69
                QByteArray cc;
70
                cmd += "lpr -P '";
71
                cmd += options.printer;
72
                cmd += "'";
73
                if (options.copies > 1)
74
                        cmd += " -#" + cc.setNum(options.copies);
75
                cmd += options.printerOptions;
24060 jghali 76
                cmd += " ";
77
                cmd += "\"" + filename + "\"";
23873 jghali 78
                system(cmd.data());
79
        }
80
        // Disabled that for now, as kprinter won't work otherwise
81
        // leaving that file around doesn't harm, as it will be overwritten the next time.
82
        // unlink(filename);
22689 jghali 83
 
23873 jghali 84
        return true;
11229 fschmid 85
}