Connect print job settings to ppm2pwg env

This commit is contained in:
Anton Thomasson 2020-05-09 20:39:50 +02:00
parent 2e02ad0bcf
commit aa6daa1d77
4 changed files with 84 additions and 26 deletions

View file

@ -1,28 +1,61 @@
#include "convertworker.h" #include "convertworker.h"
#include <sailfishapp.h> #include <sailfishapp.h>
void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, void ppm2PwgEnv(QStringList& env, bool urf, quint32 Quality,
bool apple, quint32 HwResX, quint32 HwResY, QTemporaryFile* tempfile) 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); if(urf)
QString HwResY_s = QString::number(HwResY); {
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); QProcess* pdftoppm = new QProcess(this);
pdftoppm->setProgram("pdftoppm"); 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); QProcess* ppm2pwg = new QProcess(this);
// Yo dawg, I heard you like programs... // Yo dawg, I heard you like programs...
ppm2pwg->setProgram("harbour-seaprint"); ppm2pwg->setProgram("harbour-seaprint");
ppm2pwg->setArguments({"ppm2pwg"}); ppm2pwg->setArguments({"ppm2pwg"});
QStringList env = {"HWRES_X="+HwResX_s, "HWRES_Y="+HwResY_s};
if(apple) QStringList env;
{ ppm2PwgEnv(env, urf, Quality, HwResX, HwResY, TwoSided, Tumble);
env.append("URF=true"); qDebug() << "ppm2pwg env is " << env;
}
ppm2pwg->setEnvironment(env); ppm2pwg->setEnvironment(env);

View file

@ -8,8 +8,9 @@ class ConvertWorker : public QObject
Q_OBJECT Q_OBJECT
public slots: public slots:
void convertPdf(QNetworkRequest request, QString filename, void convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
bool apple, quint32 HwResX, quint32 HwResY, QTemporaryFile* tempfile); bool urf, quint32 Colors, quint32 Quality,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble);
//convertImage(); //convertImage();
signals: signals:

View file

@ -294,23 +294,32 @@ void IppPrinter::print(QJsonObject attrs, QString filename){
} }
} }
quint32 HwResX = 300; QJsonValue PrinterResolutionRef = getAttrOrDefault(attrs, "printer-resolution");
quint32 HwResY = 300; quint32 HwResX = PrinterResolutionRef.toObject()["x"].toInt();
quint32 HwResY = PrinterResolutionRef.toObject()["y"].toInt();
if(attrs.contains("printer-resolution")) { quint32 Quality = getAttrOrDefault(attrs, "print-quality").toInt();
// TODO: check that units == 3, aka dpi
HwResX = attrs["printer-resolution"].toObject()["value"].toObject()["x"].toInt(); QString PrintColorMode = getAttrOrDefault(attrs, "print-color-mode").toString();
HwResY = attrs["printer-resolution"].toObject()["value"].toObject()["y"].toInt(); quint32 Colors = PrintColorMode=="color" ? 3 : PrintColorMode=="monochrome" ? 1 : 0;
}
else
{
HwResX = _attrs["printer-resolution-default"].toObject()["value"].toObject()["x"].toInt();
HwResY = _attrs["printer-resolution-default"].toObject()["value"].toObject()["y"].toInt();
}
if(from == Pdf && target != NoConvert) if(from == Pdf && target != NoConvert)
{ {
file.close(); 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(); QTemporaryFile* tempfile = new QTemporaryFile();
tempfile->open(); tempfile->open();
tempfile->write(contents); tempfile->write(contents);
@ -319,7 +328,8 @@ void IppPrinter::print(QJsonObject attrs, QString filename){
setBusyMessage("Converting"); 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 else
{ {
@ -393,3 +403,14 @@ void IppPrinter::setBusyMessage(QString msg)
_busyMessage = msg; _busyMessage = msg;
emit busyMessageChanged(); 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"];
}
}

View file

@ -52,7 +52,9 @@ signals:
void jobFinished(bool status); void jobFinished(bool status);
void cancelStatus(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(); void busyMessageChanged();
@ -78,6 +80,7 @@ private:
QJsonObject opAttrs(); QJsonObject opAttrs();
void setBusyMessage(QString msg); void setBusyMessage(QString msg);
QJsonValue getAttrOrDefault(QJsonObject jobAttrs, QString name);
QNetworkAccessManager* _nam; QNetworkAccessManager* _nam;
QNetworkAccessManager* _jobs_nam; QNetworkAccessManager* _jobs_nam;