Add option to remove sides IPP attribute for raster formats

...because apparently my printer doesn't like it,
even if it agrees with the raster file
This commit is contained in:
Anton Thomasson 2020-06-06 14:59:44 +02:00
parent 213ab589a3
commit 76abb7cea5
10 changed files with 80 additions and 14 deletions

@ -1 +1 @@
Subproject commit 66b9eea5a074f08cff948292c07c487a5d90aa78
Subproject commit a404a177038626765b915ce0cf21527704bffd7e

View file

@ -24,6 +24,13 @@ Page {
defaultValue: false
}
ConfigurationValue
{
id: removeDuplexAttributesForRaster
key: "/apps/harbour-seaprint/settings/remove_duplex_attribute_for_raster"
defaultValue: false
}
Component.onCompleted: {
console.log(JSON.stringify(printer.attrs))
}
@ -40,7 +47,8 @@ Page {
console.log(JSON.stringify(jobParams))
pageStack.replace(Qt.resolvedUrl("BusyPage.qml"),{printer:printer},
PageStackAction.Immediate)
printer.print(jobParams, page.selectedFile, alwaysConvert.value, forceIncluDeDocumentFormat.value)
printer.print(jobParams, page.selectedFile,
alwaysConvert.value, forceIncluDeDocumentFormat.value, removeDuplexAttributesForRaster.value)
}
}
}

View file

@ -6,7 +6,7 @@
#include <QPainter>
void ppm2PwgEnv(QStringList& env, bool urf, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble)
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, quint32 pages)
{
env.append("HWRES_X="+QString::number(HwResX));
env.append("HWRES_Y="+QString::number(HwResY));
@ -29,12 +29,45 @@ void ppm2PwgEnv(QStringList& env, bool urf, quint32 Quality, QString PaperSize,
env.append("DUPLEX="+QString::number(TwoSided));
env.append("TUMBLE="+QString::number(Tumble));
if(pages != 0)
{
env.append("PAGES="+QString::number(pages));
}
}
void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble)
{
QProcess* pdfinfo = new QProcess(this);
pdfinfo->setProgram("pdfinfo");
pdfinfo->setArguments({filename});
pdfinfo->start();
if(!pdfinfo->waitForStarted() || !pdfinfo->waitForFinished())
{
qDebug() << "pdfinfo died";
pdfinfo->deleteLater();
tempfile->deleteLater();
emit failed(tr("Failed to get info about PDF file"));
return;
}
QByteArray pdfInfoOutput = pdfinfo->readAllStandardOutput();
pdfinfo->deleteLater();
qDebug() << pdfInfoOutput;
QList<QByteArray> pdfInfoOutputLines = pdfInfoOutput.split('\n');
quint32 pages = 0;
for(QList<QByteArray>::iterator it = pdfInfoOutputLines.begin(); it != pdfInfoOutputLines.end(); it++)
{
if(it->startsWith("Pages"))
{
QList<QByteArray> pagesTokens = it->split(' ');
pages = pagesTokens.last().toInt();
}
}
bool urf = false;
if(targetFormat == "image/urf")
@ -104,7 +137,7 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
ppm2pwg->setArguments({"ppm2pwg"});
QStringList env;
ppm2PwgEnv(env, urf, Quality, PaperSize, HwResX, HwResY, TwoSided, Tumble);
ppm2PwgEnv(env, urf, Quality, PaperSize, HwResX, HwResY, TwoSided, Tumble, pages);
qDebug() << "ppm2pwg env is " << env;
ppm2pwg->setEnvironment(env);
@ -250,7 +283,7 @@ void ConvertWorker::convertImage(QNetworkRequest request, QString filename, QTem
ppm2pwg->setArguments({"ppm2pwg"});
QStringList env;
ppm2PwgEnv(env, urf, Quality, PaperSize, HwResX, HwResY, false, false);
ppm2PwgEnv(env, urf, Quality, PaperSize, HwResX, HwResY, false, false, 0);
qDebug() << "ppm2pwg env is " << env;
ppm2pwg->setEnvironment(env);

View file

@ -297,10 +297,11 @@ QString targetFormatIfAuto(QString documentFormat, QString mimeType, QJsonArray
return documentFormat;
}
// TODO: make alwaysConvert force ratser format
void IppPrinter::print(QJsonObject attrs, QString filename, bool alwaysConvert, bool forceIncluDeDocumentFormat)
void IppPrinter::print(QJsonObject attrs, QString filename,
bool alwaysConvert, bool forceIncluDeDocumentFormat, bool removeDuplexAttributesForRaster)
{
qDebug() << "printing" << filename << attrs << alwaysConvert << forceIncluDeDocumentFormat;
qDebug() << "printing" << filename << attrs
<< alwaysConvert << forceIncluDeDocumentFormat << removeDuplexAttributesForRaster;
_progress = "";
emit progressChanged();
@ -350,9 +351,6 @@ void IppPrinter::print(QJsonObject attrs, QString filename, bool alwaysConvert,
}
qDebug() << "Printing job" << o << attrs;
IppMsg job = IppMsg(o, attrs);
QByteArray contents = job.encode(IppMsg::PrintJob);
QNetworkRequest request;
@ -393,6 +391,14 @@ void IppPrinter::print(QJsonObject attrs, QString filename, bool alwaysConvert,
return;
}
QString Sides = getAttrOrDefault(attrs, "sides").toString();
if(removeDuplexAttributesForRaster && (documentFormat=="image/pwg-raster" || documentFormat=="image/urf"))
{
attrs.remove("sides");
}
IppMsg job = IppMsg(o, attrs);
QByteArray contents = job.encode(IppMsg::PrintJob);
// Always convert images to get resizing
if((mimeType == documentFormat) && !mimeType.contains("image"))
{
@ -418,8 +424,6 @@ void IppPrinter::print(QJsonObject attrs, QString filename, bool alwaysConvert,
if(mimeType == "application/pdf")
{
QString Sides = getAttrOrDefault(attrs, "sides").toString();
bool TwoSided = false;
bool Tumble = false;
if(Sides=="two-sided-long-edge")

View file

@ -55,7 +55,8 @@ signals:
void progressChanged();
public slots:
void print(QJsonObject attrs, QString file, bool alwaysConvert, bool forceIncluDeDocumentFormat);
void print(QJsonObject attrs, QString file,
bool alwaysConvert, bool forceIncluDeDocumentFormat, bool removeDuplexAttributesForRaster);
void onUrlChanged();

View file

@ -144,6 +144,10 @@
<source>Unsupported target format</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to get info about PDF file</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CoverPage</name>

View file

@ -144,6 +144,10 @@
<source>Unsupported target format</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to get info about PDF file</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CoverPage</name>

View file

@ -144,6 +144,10 @@
<source>Unsupported target format</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to get info about PDF file</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CoverPage</name>

View file

@ -144,6 +144,10 @@
<source>Unsupported target format</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to get info about PDF file</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CoverPage</name>

View file

@ -144,6 +144,10 @@
<source>Unsupported target format</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to get info about PDF file</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CoverPage</name>