Skip to content

Commit

Permalink
Add support for client-side copies
Browse files Browse the repository at this point in the history
  • Loading branch information
attah committed Jul 31, 2022
1 parent b7aeb09 commit 6a06fa5
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ppm2pwg
17 changes: 15 additions & 2 deletions qml/components/IntegerSetting.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@ import QtQuick 2.6
import Sailfish.Silica 1.0

Setting {
property int low: valid ? parent.printer.attrs[name+"-supported"].value.low : 0
property int high: valid ? parent.printer.attrs[name+"-supported"].value.high : 0
property int minimum_high: 0
property int low: _valid ? parent.printer.attrs[name+"-supported"].value.low : (minimum_high != 0) ? 1 : 0
property int high: _valid ? ensure_minimum(parent.printer.attrs[name+"-supported"].value.high) : minimum_high

function ensure_minimum(orig)
{
if(orig < minimum_high)
{
return minimum_high;
}
else
{
return orig;
}
}

property bool suppressChange: false

Expand Down
2 changes: 2 additions & 0 deletions qml/pages/PrinterPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Page {
tag: IppMsg.Integer
name: "copies"
prettyName: qsTr("Copies")
valid: _valid || Utils.supports_raster(printer)
minimum_high: 99
}
ChoiceSetting {
tag: IppMsg.Keyword
Expand Down
10 changes: 10 additions & 0 deletions qml/pages/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ function supported_formats(printer, considerAdditionalFormats)
return {pdf: pdf, postscript: postscript, plaintext: plaintext, office: office, images: images, mimetypes: mimetypes};
}

function supports_raster(printer)
{
var formats = printer.attrs["document-format-supported"].value;
if(considerAdditionalFormats)
{
formats=formats+printer.additionalDocumentFormats;
}
return (has(formats, Mimer.Mimer.PWG) || has(formats, Mimer.Mimer.URF));
}

function has(arrayish, what)
{
return arrayish.indexOf(what) != -1;
Expand Down
59 changes: 51 additions & 8 deletions src/ippprinter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ippprinter.h"
#include "ippdiscovery.h"
#include "mimer.h"
#include "convertchecker.h"
#include "papersizes.h"
#include "overrider.h"
#include "settings.h"
Expand Down Expand Up @@ -542,6 +543,27 @@ void IppPrinter::adjustRasterSettings(QString documentFormat, QJsonObject& jobAt
}
}

int copies_requested = getAttrOrDefault(jobAttrs, "copies").toInt(1);
QJsonArray varying_attributes = _attrs["document-format-varying-attributes"].toObject()["value"].toArray();
bool supports_copies = _attrs.contains("copies-supported")
&& _attrs["copies-supported"].toObject()["value"].toObject()["high"].toInt(1) != 1
// assume raster formats causes the variation in supported copies
&& !(varying_attributes.contains("copies-supported") || varying_attributes.contains("copies"));

if(copies_requested > 1 && !supports_copies)
{
QString copyMode = getAttrOrDefault(jobAttrs, "multiple-document-handling").toString();
qDebug() << "Doing local copies" << copyMode << copies_requested;
if(copyMode == "separate-documents-uncollated-copies")
{ // Only do silly copies if explicitly requested
Params.pageCopies = copies_requested;
}
else
{
Params.documentCopies = copies_requested;
}
jobAttrs.remove("copies");
}
}

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

adjustRasterSettings(targetFormat, jobAttrs, Params);

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

QString PrintColorMode = getAttrOrDefault(jobAttrs, "print-color-mode").toString();
Params.colors = PrintColorMode.contains("color") ? 3 : PrintColorMode.contains("monochrome") ? 1 : Params.colors;
bool singlePageRange = false;

if(jobAttrs.contains("page-ranges"))
{
QJsonObject PageRanges = getAttrOrDefault(jobAttrs, "page-ranges").toObject();
Params.fromPage = PageRanges["low"].toInt();
Params.toPage = PageRanges["high"].toInt();
size_t fromPage = PageRanges["low"].toInt();
size_t toPage = PageRanges["high"].toInt();
if(fromPage != 0 || toPage != 0)
{
Params.pageRangeList = {{fromPage, toPage}};
singlePageRange = toPage == fromPage;
}

// Effected locally, unless it is Postscript which we cant't render
if(targetFormat != Mimer::Postscript)
{
Expand All @@ -699,6 +722,19 @@ 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";
}

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

if(Sides=="two-sided-long-edge")
{
Expand All @@ -710,6 +746,13 @@ 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();
Params.colors = PrintColorMode.contains("color") ? 3 : PrintColorMode.contains("monochrome") ? 1 : Params.colors;

QJsonArray supportedOperations = _attrs["operations-supported"].toObject()["value"].toArray();

if(supportedOperations.contains(IppMsg::CreateJob) && supportedOperations.contains(IppMsg::SendDocument))
Expand Down
19 changes: 16 additions & 3 deletions src/printerworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,14 @@ void PrinterWorker::convertImage(QString filename, Bytestream header, PrintParam
}
else
{
size_t total_pages = Params.documentCopies*Params.pageCopies;

if(total_pages > 1 && Params.duplex)
{ // Images are one page by definition - if we need to do client-side copies, they must be one-sided or we'd have to insert backsides
qDebug() << "Inconsistent duplex setting";
throw ConvertFailedException(tr("Inconsistent duplex setting"));
}

QImage outImage = QImage(Params.getPaperSizeWInPixels(), Params.getPaperSizeHInPixels(), inImage.format());
outImage.fill(Qt::white);
QPainter painter(&outImage);
Expand All @@ -463,7 +471,7 @@ void PrinterWorker::convertImage(QString filename, Bytestream header, PrintParam

QBuffer buf;
buf.open(QIODevice::ReadWrite);
Bytestream outBts;
Bytestream fileHdr, outBts;


if(inImage.allGray())
Expand All @@ -488,7 +496,7 @@ void PrinterWorker::convertImage(QString filename, Bytestream header, PrintParam

buf.read((char*)(inBts.raw()), inBts.size());

outBts << (Params.format == PrintParameters::URF ? make_urf_file_hdr(1) : make_pwg_file_hdr());
fileHdr << (Params.format == PrintParameters::URF ? make_urf_file_hdr(1) : make_pwg_file_hdr());

bool verbose = QLoggingCategory::defaultCategory()->isDebugEnabled();

Expand All @@ -499,7 +507,12 @@ void PrinterWorker::convertImage(QString filename, Bytestream header, PrintParam
emit busyMessage(tr("Printing"));

OK(cr.write((char*)header.raw(), header.size()));
OK(cr.write((char*)(outBts.raw()), outBts.size()));
OK(cr.write((char*)fileHdr.raw(), fileHdr.size()));
for(size_t c = 0; c < total_pages; c++)
{
OK(cr.write((char*)(outBts.raw()), outBts.size()));
emit progress(c+1, total_pages);
}

awaitResult(cr, "printRequestFinished");
}
Expand Down
4 changes: 4 additions & 0 deletions translations/harbour-seaprint-de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@ auf diesem Drucker</translation>
<source>Print error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Inconsistent duplex setting</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RangeSetting</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/harbour-seaprint-es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@
<source>Print error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Inconsistent duplex setting</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RangeSetting</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/harbour-seaprint-fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@ sur cette imprimante</translation>
<source>Print error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Inconsistent duplex setting</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RangeSetting</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/harbour-seaprint-nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@
<source>Print error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Inconsistent duplex setting</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RangeSetting</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/harbour-seaprint-pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@
<source>Print error</source>
<translation>Błąd drukowania</translation>
</message>
<message>
<source>Inconsistent duplex setting</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RangeSetting</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/harbour-seaprint-zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@
<source>Print error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Inconsistent duplex setting</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RangeSetting</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/harbour-seaprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@
<source>Unknown target format</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Inconsistent duplex setting</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RangeSetting</name>
Expand Down

0 comments on commit 6a06fa5

Please sign in to comment.