Move some raster compensation to where it belongs

This commit is contained in:
Anton Thomasson 2022-08-01 20:30:22 +02:00
parent 6a06fa5ffd
commit 9287da53aa
2 changed files with 24 additions and 20 deletions

View file

@ -419,7 +419,7 @@ QString targetFormatIfAuto(QString documentFormat, QString mimeType, QJsonArray
return documentFormat; return documentFormat;
} }
void IppPrinter::adjustRasterSettings(QString documentFormat, QJsonObject& jobAttrs, PrintParameters& Params) void IppPrinter::adjustRasterSettings(QString filename, QString mimeType, QString documentFormat, QJsonObject& jobAttrs, PrintParameters& Params)
{ {
if(documentFormat != Mimer::PWG && documentFormat != Mimer::URF) if(documentFormat != Mimer::PWG && documentFormat != Mimer::URF)
{ {
@ -563,6 +563,26 @@ void IppPrinter::adjustRasterSettings(QString documentFormat, QJsonObject& jobAt
Params.documentCopies = copies_requested; Params.documentCopies = copies_requested;
} }
jobAttrs.remove("copies"); jobAttrs.remove("copies");
if(Sides != "one-sided")
{
bool singlePageRange = false;
if(Params.pageRangeList.size() == 1)
{
size_t fromPage = Params.pageRangeList.begin()->first;
size_t toPage = Params.pageRangeList.begin()->second;
singlePageRange = fromPage != 0 && fromPage == toPage;
}
bool singlePageDocument = (Mimer::instance()->isImage(mimeType) ||
(mimeType == Mimer::PDF && ConvertChecker::instance()->pdfPages(filename) == 1));
if(singlePageDocument || singlePageRange)
{
jobAttrs.insert("sides", QJsonObject {{"tag", IppMsg::Keyword}, {"value", "one-sided"}});
qDebug() << "Optimizing one-page document to one-sided";
}
}
} }
} }
@ -701,8 +721,6 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
Params.hwResW = PrinterResolutionRef.toObject()["x"].toInt(Params.hwResW); Params.hwResW = PrinterResolutionRef.toObject()["x"].toInt(Params.hwResW);
Params.hwResH = PrinterResolutionRef.toObject()["y"].toInt(Params.hwResH); Params.hwResH = PrinterResolutionRef.toObject()["y"].toInt(Params.hwResH);
bool singlePageRange = false;
if(jobAttrs.contains("page-ranges")) if(jobAttrs.contains("page-ranges"))
{ {
QJsonObject PageRanges = getAttrOrDefault(jobAttrs, "page-ranges").toObject(); QJsonObject PageRanges = getAttrOrDefault(jobAttrs, "page-ranges").toObject();
@ -711,7 +729,6 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
if(fromPage != 0 || toPage != 0) if(fromPage != 0 || toPage != 0)
{ {
Params.pageRangeList = {{fromPage, toPage}}; Params.pageRangeList = {{fromPage, toPage}};
singlePageRange = toPage == fromPage;
} }
// Effected locally, unless it is Postscript which we cant't render // Effected locally, unless it is Postscript which we cant't render
@ -721,20 +738,9 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
} }
} }
adjustRasterSettings(filename, mimeType, targetFormat, jobAttrs, Params);
QString Sides = getAttrOrDefault(jobAttrs, "sides").toString(); QString Sides = getAttrOrDefault(jobAttrs, "sides").toString();
int copies_requested = getAttrOrDefault(jobAttrs, "copies").toInt(1);
if((Params.format == PrintParameters::PWG || Params.format == PrintParameters::URF) &&
copies_requested > 1 &&
Sides != "one-sided" &&
(Mimer::instance()->isImage(mimeType) ||
(mimeType == Mimer::PDF && (singlePageRange || ConvertChecker::instance()->pdfPages(filename) == 1))))
{
jobAttrs.insert("sides", QJsonObject {{"tag", IppMsg::Keyword}, {"value", "one-sided"}});
qDebug() << "Optimizing one-page document to one-sided";
}
Sides = getAttrOrDefault(jobAttrs, "sides").toString();
if(Sides=="two-sided-long-edge") if(Sides=="two-sided-long-edge")
{ {
@ -746,8 +752,6 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
Params.tumble = true; Params.tumble = true;
} }
adjustRasterSettings(targetFormat, jobAttrs, Params);
Params.quality = getAttrOrDefault(jobAttrs, "print-quality").toInt(); Params.quality = getAttrOrDefault(jobAttrs, "print-quality").toInt();
QString PrintColorMode = getAttrOrDefault(jobAttrs, "print-color-mode").toString(); QString PrintColorMode = getAttrOrDefault(jobAttrs, "print-color-mode").toString();

View file

@ -107,7 +107,7 @@ private:
QJsonObject opAttrs(); QJsonObject opAttrs();
void adjustRasterSettings(QString documentFormat, QJsonObject& jobAttrs, PrintParameters& Params); void adjustRasterSettings(QString filename, QString mimeType, QString documentFormat, QJsonObject& jobAttrs, PrintParameters& Params);
void setBusyMessage(QString msg); void setBusyMessage(QString msg);
void setProgress(qint64 sent, qint64 total); void setProgress(qint64 sent, qint64 total);