Connect print job settings to ppm2pwg env
This commit is contained in:
parent
2e02ad0bcf
commit
aa6daa1d77
4 changed files with 84 additions and 26 deletions
|
@ -1,28 +1,61 @@
|
|||
#include "convertworker.h"
|
||||
#include <sailfishapp.h>
|
||||
|
||||
void ConvertWorker::convertPdf(QNetworkRequest request, QString filename,
|
||||
bool apple, quint32 HwResX, quint32 HwResY, QTemporaryFile* tempfile)
|
||||
void ppm2PwgEnv(QStringList& env, bool urf, quint32 Quality,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble)
|
||||
{
|
||||
env.append("HWRES_X="+QString::number(HwResX));
|
||||
env.append("HWRES_Y="+QString::number(HwResY));
|
||||
|
||||
QString HwResX_s = QString::number(HwResX);
|
||||
QString HwResY_s = QString::number(HwResY);
|
||||
if(urf)
|
||||
{
|
||||
env.append("URF=true");
|
||||
}
|
||||
|
||||
if(Quality >= 3 && Quality <= 5)
|
||||
{
|
||||
env.append("QUALITY="+QString::number(Quality));
|
||||
}
|
||||
|
||||
env.append("DUPLEX="+QString::number(TwoSided));
|
||||
env.append("TUMBLE="+QString::number(Tumble));
|
||||
|
||||
}
|
||||
|
||||
void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
bool urf, quint32 Colors, quint32 Quality,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble)
|
||||
{
|
||||
if(urf)
|
||||
{ // URF only supports symmetric resolutions
|
||||
if(HwResX < HwResY)
|
||||
{
|
||||
HwResY = HwResX;
|
||||
}
|
||||
else {
|
||||
HwResX = HwResY;
|
||||
}
|
||||
}
|
||||
|
||||
QProcess* pdftoppm = new QProcess(this);
|
||||
pdftoppm->setProgram("pdftoppm");
|
||||
pdftoppm->setArguments({"-gray", "-rx", HwResX_s, "-ry", HwResY_s, filename});
|
||||
QStringList Pdf2PpmArgs = {"-rx", QString::number(HwResX), "-ry", QString::number(HwResY)};
|
||||
if(Colors != 3)
|
||||
{
|
||||
Pdf2PpmArgs.append("-gray");
|
||||
}
|
||||
Pdf2PpmArgs.append(filename);
|
||||
pdftoppm->setArguments(Pdf2PpmArgs);
|
||||
|
||||
|
||||
QProcess* ppm2pwg = new QProcess(this);
|
||||
// Yo dawg, I heard you like programs...
|
||||
ppm2pwg->setProgram("harbour-seaprint");
|
||||
ppm2pwg->setArguments({"ppm2pwg"});
|
||||
QStringList env = {"HWRES_X="+HwResX_s, "HWRES_Y="+HwResY_s};
|
||||
|
||||
if(apple)
|
||||
{
|
||||
env.append("URF=true");
|
||||
}
|
||||
QStringList env;
|
||||
ppm2PwgEnv(env, urf, Quality, HwResX, HwResY, TwoSided, Tumble);
|
||||
qDebug() << "ppm2pwg env is " << env;
|
||||
|
||||
ppm2pwg->setEnvironment(env);
|
||||
|
||||
|
|
|
@ -8,8 +8,9 @@ class ConvertWorker : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
void convertPdf(QNetworkRequest request, QString filename,
|
||||
bool apple, quint32 HwResX, quint32 HwResY, QTemporaryFile* tempfile);
|
||||
void convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
bool urf, quint32 Colors, quint32 Quality,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble);
|
||||
//convertImage();
|
||||
|
||||
signals:
|
||||
|
|
|
@ -294,23 +294,32 @@ void IppPrinter::print(QJsonObject attrs, QString filename){
|
|||
}
|
||||
}
|
||||
|
||||
quint32 HwResX = 300;
|
||||
quint32 HwResY = 300;
|
||||
QJsonValue PrinterResolutionRef = getAttrOrDefault(attrs, "printer-resolution");
|
||||
quint32 HwResX = PrinterResolutionRef.toObject()["x"].toInt();
|
||||
quint32 HwResY = PrinterResolutionRef.toObject()["y"].toInt();
|
||||
|
||||
if(attrs.contains("printer-resolution")) {
|
||||
// TODO: check that units == 3, aka dpi
|
||||
HwResX = attrs["printer-resolution"].toObject()["value"].toObject()["x"].toInt();
|
||||
HwResY = attrs["printer-resolution"].toObject()["value"].toObject()["y"].toInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
HwResX = _attrs["printer-resolution-default"].toObject()["value"].toObject()["x"].toInt();
|
||||
HwResY = _attrs["printer-resolution-default"].toObject()["value"].toObject()["y"].toInt();
|
||||
}
|
||||
quint32 Quality = getAttrOrDefault(attrs, "print-quality").toInt();
|
||||
|
||||
QString PrintColorMode = getAttrOrDefault(attrs, "print-color-mode").toString();
|
||||
quint32 Colors = PrintColorMode=="color" ? 3 : PrintColorMode=="monochrome" ? 1 : 0;
|
||||
|
||||
if(from == Pdf && target != NoConvert)
|
||||
{
|
||||
file.close();
|
||||
|
||||
QString Sides = getAttrOrDefault(attrs, "sides").toString();
|
||||
bool TwoSided = false;
|
||||
bool Tumble = false;
|
||||
if(Sides=="two-sided-long-edge")
|
||||
{
|
||||
TwoSided = true;
|
||||
}
|
||||
else if(Sides=="two-sided-short-edge")
|
||||
{
|
||||
TwoSided = true;
|
||||
Tumble = true;
|
||||
}
|
||||
|
||||
QTemporaryFile* tempfile = new QTemporaryFile();
|
||||
tempfile->open();
|
||||
tempfile->write(contents);
|
||||
|
@ -319,7 +328,8 @@ void IppPrinter::print(QJsonObject attrs, QString filename){
|
|||
|
||||
setBusyMessage("Converting");
|
||||
|
||||
emit doConvertPdf(request, filename, target==UrfConvert, HwResX, HwResY, tempfile);
|
||||
emit doConvertPdf(request, filename, tempfile, target==UrfConvert, Colors, Quality,
|
||||
HwResX, HwResY, TwoSided, Tumble);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -393,3 +403,14 @@ void IppPrinter::setBusyMessage(QString msg)
|
|||
_busyMessage = msg;
|
||||
emit busyMessageChanged();
|
||||
}
|
||||
|
||||
QJsonValue IppPrinter::getAttrOrDefault(QJsonObject jobAttrs, QString name)
|
||||
{
|
||||
if(jobAttrs.contains(name))
|
||||
{
|
||||
return jobAttrs[name].toObject()["value"];
|
||||
}
|
||||
else {
|
||||
return _attrs[name+"-default"].toObject()["value"];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,9 @@ signals:
|
|||
void jobFinished(bool status);
|
||||
void cancelStatus(bool status);
|
||||
|
||||
void doConvertPdf(QNetworkRequest request, QString filename, bool urf, quint32 HwResX, quint32 HwResY, QTemporaryFile* tempfile);
|
||||
void doConvertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
bool urf, quint32 Colors, quint32 Quality,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble);
|
||||
|
||||
void busyMessageChanged();
|
||||
|
||||
|
@ -78,6 +80,7 @@ private:
|
|||
QJsonObject opAttrs();
|
||||
|
||||
void setBusyMessage(QString msg);
|
||||
QJsonValue getAttrOrDefault(QJsonObject jobAttrs, QString name);
|
||||
|
||||
QNetworkAccessManager* _nam;
|
||||
QNetworkAccessManager* _jobs_nam;
|
||||
|
|
Loading…
Reference in a new issue