Flip duplex backsides according to printer needs
This commit is contained in:
parent
b566dc723c
commit
deaf63eb82
4 changed files with 107 additions and 29 deletions
|
@ -13,7 +13,7 @@
|
|||
|
||||
void ppm2PwgEnv(QStringList& env, bool urf, quint32 Quality, QString PaperSize,
|
||||
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_Y="+QString::number(HwResY));
|
||||
|
@ -46,12 +46,20 @@ void ppm2PwgEnv(QStringList& env, bool urf, quint32 Quality, QString PaperSize,
|
|||
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,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh)
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip)
|
||||
{
|
||||
try {
|
||||
|
||||
|
@ -122,7 +130,7 @@ try {
|
|||
{
|
||||
pdfToRaster(targetFormat, Colors, Quality, PaperSize,
|
||||
HwResX, HwResY, TwoSided, Tumble,
|
||||
PageRangeLow, PageRangeHigh, pages,
|
||||
PageRangeLow, PageRangeHigh, pages, BackHFlip, BackVFlip,
|
||||
filename, tempfile, true);
|
||||
|
||||
}
|
||||
|
@ -259,7 +267,7 @@ try {
|
|||
ppm2pwg.setArguments({"ppm2pwg"});
|
||||
|
||||
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;
|
||||
|
||||
ppm2pwg.setEnvironment(env);
|
||||
|
@ -302,7 +310,7 @@ catch(const ConvertFailedException& e)
|
|||
void ConvertWorker::convertOfficeDocument(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh)
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip)
|
||||
{
|
||||
try {
|
||||
|
||||
|
@ -406,7 +414,7 @@ try {
|
|||
|
||||
pdfToRaster(targetFormat, Colors, Quality, PaperSize,
|
||||
HwResX, HwResY, TwoSided, Tumble,
|
||||
PageRangeLow, PageRangeHigh, pages,
|
||||
PageRangeLow, PageRangeHigh, pages, BackHFlip, BackVFlip,
|
||||
tmpPdfFile.fileName(), tempfile, false);
|
||||
}
|
||||
|
||||
|
@ -425,7 +433,8 @@ catch(const ConvertFailedException& e)
|
|||
|
||||
void ConvertWorker::convertPlaintext(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
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 {
|
||||
|
||||
|
@ -573,7 +582,7 @@ try {
|
|||
{
|
||||
pdfToRaster(targetFormat, Colors, Quality, PaperSize,
|
||||
HwResX, HwResY, TwoSided, Tumble,
|
||||
0, 0, pageCount,
|
||||
0, 0, pageCount, BackHFlip, BackVFlip,
|
||||
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,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh, quint32 pages,
|
||||
bool BackHFlip, bool BackVFlip,
|
||||
QString pdfFileName, QTemporaryFile* tempfile, bool resize)
|
||||
{
|
||||
|
||||
|
@ -760,7 +770,7 @@ void ConvertWorker::pdfToRaster(QString targetFormat, quint32 Colors, quint32 Qu
|
|||
bool urf = targetFormat == Mimer::URF;
|
||||
|
||||
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;
|
||||
|
||||
ppm2pwg.setEnvironment(env);
|
||||
|
|
|
@ -25,7 +25,7 @@ public slots:
|
|||
void convertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
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,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
|
@ -34,11 +34,11 @@ public slots:
|
|||
void convertOfficeDocument(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
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,
|
||||
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:
|
||||
void done(QNetworkRequest request, QTemporaryFile* data);
|
||||
|
@ -58,6 +58,7 @@ private:
|
|||
void pdfToRaster(QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh, quint32 pages,
|
||||
bool BackHFlip, bool BackVFlip,
|
||||
QString pdfFileName, QTemporaryFile* tempfile, bool resize);
|
||||
};
|
||||
|
||||
|
|
|
@ -345,18 +345,17 @@ QString targetFormatIfAuto(QString documentFormat, QString mimeType, QJsonArray
|
|||
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)
|
||||
{ // Ensure symmetric resolution for URF
|
||||
if(HwResX < HwResY)
|
||||
{
|
||||
HwResY = HwResX;
|
||||
}
|
||||
else
|
||||
{
|
||||
HwResX = HwResY;
|
||||
}
|
||||
HwResX = HwResY = std::min(HwResX, HwResY);
|
||||
|
||||
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} };
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -455,8 +517,10 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
|
|||
QJsonValue PrinterResolutionRef = getAttrOrDefault(jobAttrs, "printer-resolution");
|
||||
quint32 HwResX = PrinterResolutionRef.toObject()["x"].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();
|
||||
|
||||
|
@ -545,12 +609,13 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
|
|||
if(mimeType == Mimer::PDF)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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))
|
||||
{
|
||||
|
@ -560,7 +625,8 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
|
|||
else if(Mimer::isOffice(mimeType))
|
||||
{
|
||||
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
|
||||
{
|
||||
|
|
|
@ -48,7 +48,7 @@ signals:
|
|||
void doConvertPdf(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
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,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
|
@ -57,11 +57,11 @@ signals:
|
|||
void doConvertOfficeDocument(QNetworkRequest request, QString filename, QTemporaryFile* tempfile,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
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,
|
||||
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 busyMessageChanged();
|
||||
|
@ -92,7 +92,8 @@ private:
|
|||
|
||||
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 setProgress(qint64 sent, qint64 total);
|
||||
|
|
Loading…
Reference in a new issue