Skip to content

Commit

Permalink
Move some raster compensation to where it belongs
Browse files Browse the repository at this point in the history
  • Loading branch information
attah committed Aug 1, 2022
1 parent 6a06fa5 commit 9287da5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
42 changes: 23 additions & 19 deletions src/ippprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ QString targetFormatIfAuto(QString documentFormat, QString mimeType, QJsonArray
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)
{
Expand Down Expand Up @@ -563,6 +563,26 @@ void IppPrinter::adjustRasterSettings(QString documentFormat, QJsonObject& jobAt
Params.documentCopies = copies_requested;
}
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";
}
}
}
}

Expand Down Expand Up @@ -701,8 +721,6 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
Params.hwResW = PrinterResolutionRef.toObject()["x"].toInt(Params.hwResW);
Params.hwResH = PrinterResolutionRef.toObject()["y"].toInt(Params.hwResH);

bool singlePageRange = false;

if(jobAttrs.contains("page-ranges"))
{
QJsonObject PageRanges = getAttrOrDefault(jobAttrs, "page-ranges").toObject();
Expand All @@ -711,7 +729,6 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
if(fromPage != 0 || toPage != 0)
{
Params.pageRangeList = {{fromPage, toPage}};
singlePageRange = toPage == fromPage;
}

// Effected locally, unless it is Postscript which we cant't render
Expand All @@ -721,20 +738,9 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
}
}

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";
}
adjustRasterSettings(filename, mimeType, targetFormat, jobAttrs, Params);

Sides = getAttrOrDefault(jobAttrs, "sides").toString();
QString Sides = getAttrOrDefault(jobAttrs, "sides").toString();

if(Sides=="two-sided-long-edge")
{
Expand All @@ -746,8 +752,6 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
Params.tumble = true;
}

adjustRasterSettings(targetFormat, jobAttrs, Params);

Params.quality = getAttrOrDefault(jobAttrs, "print-quality").toInt();

QString PrintColorMode = getAttrOrDefault(jobAttrs, "print-color-mode").toString();
Expand Down
2 changes: 1 addition & 1 deletion src/ippprinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public slots:

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 setProgress(qint64 sent, qint64 total);
Expand Down

0 comments on commit 9287da5

Please sign in to comment.