Flip duplex backsides according to printer needs

This commit is contained in:
Anton Thomasson 2021-06-26 14:58:14 +02:00
parent b566dc723c
commit deaf63eb82
4 changed files with 107 additions and 29 deletions

View file

@ -13,7 +13,7 @@
void ppm2PwgEnv(QStringList& env, bool urf, quint32 Quality, QString PaperSize, 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,
bool ForcePortrait, quint32 pages) bool ForcePortrait, quint32 pages, bool BackHFlip, bool BackVFlip)
{ {
env.append("HWRES_X="+QString::number(HwResX)); env.append("HWRES_X="+QString::number(HwResX));
env.append("HWRES_Y="+QString::number(HwResY)); env.append("HWRES_Y="+QString::number(HwResY));
@ -46,12 +46,20 @@ void ppm2PwgEnv(QStringList& env, bool urf, quint32 Quality, QString PaperSize,
env.append("PAGES="+QString::number(pages)); env.append("PAGES="+QString::number(pages));
} }
if(BackHFlip)
{
env.append("BACK_HFLIP=true");
}
if(BackVFlip)
{
env.append("BACK_VFLIP=true");
}
} }
void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile, void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize, QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
quint32 PageRangeLow, quint32 PageRangeHigh) quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip)
{ {
try { try {
@ -122,7 +130,7 @@ try {
{ {
pdfToRaster(targetFormat, Colors, Quality, PaperSize, pdfToRaster(targetFormat, Colors, Quality, PaperSize,
HwResX, HwResY, TwoSided, Tumble, HwResX, HwResY, TwoSided, Tumble,
PageRangeLow, PageRangeHigh, pages, PageRangeLow, PageRangeHigh, pages, BackHFlip, BackVFlip,
filename, tempfile, true); filename, tempfile, true);
} }
@ -259,7 +267,7 @@ try {
ppm2pwg.setArguments({"ppm2pwg"}); ppm2pwg.setArguments({"ppm2pwg"});
QStringList env; QStringList env;
ppm2PwgEnv(env, urf, Quality, PaperSize, HwResX, HwResY, false, false, false, 0); ppm2PwgEnv(env, urf, Quality, PaperSize, HwResX, HwResY, false, false, false, 0, false, false);
qDebug() << "ppm2pwg env is " << env; qDebug() << "ppm2pwg env is " << env;
ppm2pwg.setEnvironment(env); ppm2pwg.setEnvironment(env);
@ -302,7 +310,7 @@ catch(const ConvertFailedException& e)
void ConvertWorker::convertOfficeDocument(QNetworkRequest request, QString filename, QTemporaryFile* tempfile, void ConvertWorker::convertOfficeDocument(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize, QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
quint32 PageRangeLow, quint32 PageRangeHigh) quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip)
{ {
try { try {
@ -406,7 +414,7 @@ try {
pdfToRaster(targetFormat, Colors, Quality, PaperSize, pdfToRaster(targetFormat, Colors, Quality, PaperSize,
HwResX, HwResY, TwoSided, Tumble, HwResX, HwResY, TwoSided, Tumble,
PageRangeLow, PageRangeHigh, pages, PageRangeLow, PageRangeHigh, pages, BackHFlip, BackVFlip,
tmpPdfFile.fileName(), tempfile, false); tmpPdfFile.fileName(), tempfile, false);
} }
@ -425,7 +433,8 @@ catch(const ConvertFailedException& e)
void ConvertWorker::convertPlaintext(QNetworkRequest request, QString filename, QTemporaryFile* tempfile, void ConvertWorker::convertPlaintext(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize, QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble) quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
bool BackHFlip, bool BackVFlip)
{ {
try { try {
@ -573,7 +582,7 @@ try {
{ {
pdfToRaster(targetFormat, Colors, Quality, PaperSize, pdfToRaster(targetFormat, Colors, Quality, PaperSize,
HwResX, HwResY, TwoSided, Tumble, HwResX, HwResY, TwoSided, Tumble,
0, 0, pageCount, 0, 0, pageCount, BackHFlip, BackVFlip,
tmpPdfFile.fileName(), tempfile, false); tmpPdfFile.fileName(), tempfile, false);
} }
@ -700,6 +709,7 @@ void ConvertWorker::pdftoPs(QString PaperSize, bool TwoSided, quint32 PageRangeL
void ConvertWorker::pdfToRaster(QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize, void ConvertWorker::pdfToRaster(QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
quint32 PageRangeLow, quint32 PageRangeHigh, quint32 pages, quint32 PageRangeLow, quint32 PageRangeHigh, quint32 pages,
bool BackHFlip, bool BackVFlip,
QString pdfFileName, QTemporaryFile* tempfile, bool resize) QString pdfFileName, QTemporaryFile* tempfile, bool resize)
{ {
@ -760,7 +770,7 @@ void ConvertWorker::pdfToRaster(QString targetFormat, quint32 Colors, quint32 Qu
bool urf = targetFormat == Mimer::URF; bool urf = targetFormat == Mimer::URF;
QStringList env; QStringList env;
ppm2PwgEnv(env, urf, Quality, PaperSize, HwResX, HwResY, TwoSided, Tumble, true, pages); ppm2PwgEnv(env, urf, Quality, PaperSize, HwResX, HwResY, TwoSided, Tumble, true, pages, BackHFlip, BackVFlip);
qDebug() << "ppm2pwg env is " << env; qDebug() << "ppm2pwg env is " << env;
ppm2pwg.setEnvironment(env); ppm2pwg.setEnvironment(env);

View file

@ -25,7 +25,7 @@ public slots:
void convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile, void convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize, QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
quint32 PageRangeLow, quint32 PageRangeHigh); quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip);
void convertImage(QNetworkRequest request, QString filename, QTemporaryFile* tempfile, void convertImage(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize, QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
@ -34,11 +34,11 @@ public slots:
void convertOfficeDocument(QNetworkRequest request, QString filename, QTemporaryFile* tempfile, void convertOfficeDocument(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize, QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
quint32 PageRangeLow, quint32 PageRangeHigh); quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip);
void convertPlaintext(QNetworkRequest request, QString filename, QTemporaryFile* tempfile, void convertPlaintext(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize, QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble); quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, bool BackHFlip, bool BackVFlip);
signals: signals:
void done(QNetworkRequest request, QTemporaryFile* data); void done(QNetworkRequest request, QTemporaryFile* data);
@ -58,6 +58,7 @@ private:
void pdfToRaster(QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize, void pdfToRaster(QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
quint32 PageRangeLow, quint32 PageRangeHigh, quint32 pages, quint32 PageRangeLow, quint32 PageRangeHigh, quint32 pages,
bool BackHFlip, bool BackVFlip,
QString pdfFileName, QTemporaryFile* tempfile, bool resize); QString pdfFileName, QTemporaryFile* tempfile, bool resize);
}; };

View file

@ -345,18 +345,17 @@ QString targetFormatIfAuto(QString documentFormat, QString mimeType, QJsonArray
return documentFormat; return documentFormat;
} }
void IppPrinter::adjustRasterSettings(QString documentFormat, QJsonObject& jobAttrs, quint32& HwResX, quint32& HwResY) void IppPrinter::adjustRasterSettings(QString documentFormat, QJsonObject& jobAttrs, quint32& HwResX, quint32& HwResY,
bool& BackHFlip, bool& BackVFlip)
{ {
if(documentFormat != Mimer::PWG && documentFormat != Mimer::URF)
{
return;
}
if(documentFormat == Mimer::URF) if(documentFormat == Mimer::URF)
{ // Ensure symmetric resolution for URF { // Ensure symmetric resolution for URF
if(HwResX < HwResY) HwResX = HwResY = std::min(HwResX, HwResY);
{
HwResY = HwResX;
}
else
{
HwResX = HwResY;
}
if(jobAttrs.contains("printer-resolution")) if(jobAttrs.contains("printer-resolution"))
{ {
@ -366,6 +365,69 @@ void IppPrinter::adjustRasterSettings(QString documentFormat, QJsonObject& jobAt
jobAttrs["printer-resolution"] = QJsonObject { {"tag", IppMsg::Resolution}, {"value", tmpObj} }; jobAttrs["printer-resolution"] = QJsonObject { {"tag", IppMsg::Resolution}, {"value", tmpObj} };
} }
} }
QString Sides = getAttrOrDefault(jobAttrs, "sides").toString();
if(Sides != "" && Sides != "one-sided")
{
if(documentFormat == Mimer::PWG)
{
QString DocumentSheetBack = _attrs["pwg-raster-document-sheet-back"].toObject()["value"].toString();
if(Sides=="two-sided-long-edge")
{
if(DocumentSheetBack=="flipped")
{
BackVFlip=true;
}
else if(DocumentSheetBack=="rotated")
{
BackHFlip=true;
BackVFlip=true;
}
}
else if(Sides=="two-sided-short-edge")
{
if(DocumentSheetBack=="flipped")
{
BackHFlip=true;
}
else if(DocumentSheetBack=="manual-tumble")
{
BackHFlip=true;
BackVFlip=true;
}
}
}
else if(documentFormat == Mimer::URF)
{
QJsonArray URfSupported = _attrs["urf-supported"].toObject()["value"].toArray();
if(Sides=="two-sided-long-edge")
{
if(URfSupported.contains("DM2"))
{
BackVFlip=true;
}
else if(URfSupported.contains("DM3"))
{
BackHFlip=true;
BackVFlip=true;
}
}
else if(Sides=="two-sided-short-edge")
{
if(URfSupported.contains("DM2"))
{
BackHFlip=true;
}
else if(URfSupported.contains("DM4"))
{
BackHFlip=true;
BackVFlip=true;
}
}
}
}
} }
void IppPrinter::print(QJsonObject jobAttrs, QString filename) void IppPrinter::print(QJsonObject jobAttrs, QString filename)
@ -455,8 +517,10 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
QJsonValue PrinterResolutionRef = getAttrOrDefault(jobAttrs, "printer-resolution"); QJsonValue PrinterResolutionRef = getAttrOrDefault(jobAttrs, "printer-resolution");
quint32 HwResX = PrinterResolutionRef.toObject()["x"].toInt(); quint32 HwResX = PrinterResolutionRef.toObject()["x"].toInt();
quint32 HwResY = PrinterResolutionRef.toObject()["y"].toInt(); quint32 HwResY = PrinterResolutionRef.toObject()["y"].toInt();
bool BackHFlip = false;
bool BackVFlip = false;
adjustRasterSettings(documentFormat, jobAttrs, HwResX, HwResY); adjustRasterSettings(documentFormat, jobAttrs, HwResX, HwResY, BackHFlip, BackVFlip);
quint32 Quality = getAttrOrDefault(jobAttrs, "print-quality").toInt(); quint32 Quality = getAttrOrDefault(jobAttrs, "print-quality").toInt();
@ -545,12 +609,13 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
if(mimeType == Mimer::PDF) if(mimeType == Mimer::PDF)
{ {
emit doConvertPdf(request, filename, tempfile, documentFormat, Colors, Quality, emit doConvertPdf(request, filename, tempfile, documentFormat, Colors, Quality,
PaperSize, HwResX, HwResY, TwoSided, Tumble, PageRangeLow, PageRangeHigh); PaperSize, HwResX, HwResY, TwoSided, Tumble, PageRangeLow, PageRangeHigh,
BackHFlip, BackVFlip);
} }
else if(mimeType == Mimer::Plaintext) else if(mimeType == Mimer::Plaintext)
{ {
emit doConvertPlaintext(request, filename, tempfile, documentFormat, Colors, Quality, emit doConvertPlaintext(request, filename, tempfile, documentFormat, Colors, Quality,
PaperSize, HwResX, HwResY, TwoSided, Tumble); PaperSize, HwResX, HwResY, TwoSided, Tumble, BackHFlip, BackVFlip);
} }
else if (Mimer::isImage(mimeType)) else if (Mimer::isImage(mimeType))
{ {
@ -560,7 +625,8 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
else if(Mimer::isOffice(mimeType)) else if(Mimer::isOffice(mimeType))
{ {
emit doConvertOfficeDocument(request, filename, tempfile, documentFormat, Colors, Quality, emit doConvertOfficeDocument(request, filename, tempfile, documentFormat, Colors, Quality,
PaperSize, HwResX, HwResY, TwoSided, Tumble, PageRangeLow, PageRangeHigh); PaperSize, HwResX, HwResY, TwoSided, Tumble, PageRangeLow, PageRangeHigh,
BackHFlip, BackVFlip);
} }
else else
{ {

View file

@ -48,7 +48,7 @@ signals:
void doConvertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile, void doConvertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize, QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
quint32 PageRangeLow, quint32 PageRangeHigh); quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip);
void doConvertImage(QNetworkRequest request, QString filename, QTemporaryFile* tempfile, void doConvertImage(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize, QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
@ -57,11 +57,11 @@ signals:
void doConvertOfficeDocument(QNetworkRequest request, QString filename, QTemporaryFile* tempfile, void doConvertOfficeDocument(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize, QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
quint32 PageRangeLow, quint32 PageRangeHigh); quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip);
void doConvertPlaintext(QNetworkRequest request, QString filename, QTemporaryFile* tempfile, void doConvertPlaintext(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize, QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble); quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, bool BackHFlip, bool BackVFlip);
void additionalDocumentFormatsChanged(); void additionalDocumentFormatsChanged();
void busyMessageChanged(); void busyMessageChanged();
@ -92,7 +92,8 @@ private:
QJsonObject opAttrs(); QJsonObject opAttrs();
void adjustRasterSettings(QString documentFormat, QJsonObject& jobAttrs, quint32& HwResX, quint32& HwResY); void adjustRasterSettings(QString documentFormat, QJsonObject& jobAttrs, quint32& HwResX, quint32& HwResY,
bool& BackHFlip, bool& BackVFlip);
void setBusyMessage(QString msg); void setBusyMessage(QString msg);
void setProgress(qint64 sent, qint64 total); void setProgress(qint64 sent, qint64 total);