Support printing plaintext as plaintext
It will be converted ro \r\n linebraks, but still has lowest prio for printing plaintext input due to unreliable rendering.
This commit is contained in:
parent
b1cd524b4c
commit
dd19333c81
12 changed files with 141 additions and 14 deletions
|
@ -79,6 +79,10 @@ ApplicationWindow
|
||||||
{
|
{
|
||||||
return {simple: "image", translatable: qsTr("images")};
|
return {simple: "image", translatable: qsTr("images")};
|
||||||
}
|
}
|
||||||
|
else if(mimetype == Mimer.Plaintext)
|
||||||
|
{
|
||||||
|
return {simple: "plaintext", translatable: qsTr("plaintext")};
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return {simple: "document", translatable: qsTr("documents")};
|
return {simple: "document", translatable: qsTr("documents")};
|
||||||
|
|
|
@ -26,17 +26,21 @@ function supported_formats(printer, considerAdditionalFormats)
|
||||||
{
|
{
|
||||||
pdf = true;
|
pdf = true;
|
||||||
mimetypes.push(Mimer.Mimer.PDF);
|
mimetypes.push(Mimer.Mimer.PDF);
|
||||||
plaintext = true;
|
|
||||||
mimetypes.push(Mimer.Mimer.Plaintext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(has(formats, Mimer.Mimer.Postscript))
|
if(has(formats, Mimer.Mimer.Postscript))
|
||||||
{
|
{
|
||||||
postscript = true;
|
postscript = true;
|
||||||
mimetypes.push(Mimer.Mimer.Postscript);
|
mimetypes.push(Mimer.Mimer.Postscript);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((ConvertChecker.ConvertChecker.calligra) &&
|
if(pdf || has(formats, Mimer.Mimer.Plaintext))
|
||||||
( has(formats, Mimer.Mimer.PDF) || has(formats, Mimer.Mimer.Postscript) || raster ))
|
{
|
||||||
|
plaintext = true;
|
||||||
|
mimetypes.push(Mimer.Mimer.Plaintext);
|
||||||
|
}
|
||||||
|
|
||||||
|
if((ConvertChecker.ConvertChecker.calligra) && pdf)
|
||||||
{
|
{
|
||||||
office = true;
|
office = true;
|
||||||
mimetypes = mimetypes.concat(Mimer.Mimer.OfficeFormats);
|
mimetypes = mimetypes.concat(Mimer.Mimer.OfficeFormats);
|
||||||
|
@ -243,6 +247,8 @@ function ippName(name, value, printerStrings)
|
||||||
return qsTr("PDF");
|
return qsTr("PDF");
|
||||||
case Mimer.Mimer.Postscript:
|
case Mimer.Mimer.Postscript:
|
||||||
return qsTr("Postscript");
|
return qsTr("Postscript");
|
||||||
|
case Mimer.Mimer.Plaintext:
|
||||||
|
return qsTr("Plaintext");
|
||||||
case Mimer.Mimer.PWG:
|
case Mimer.Mimer.PWG:
|
||||||
return qsTr("PWG-raster");
|
return qsTr("PWG-raster");
|
||||||
case Mimer.Mimer.URF:
|
case Mimer.Mimer.URF:
|
||||||
|
@ -372,10 +378,12 @@ function endsWith(ending, string)
|
||||||
return string.lastIndexOf(ending) == (string.length - ending.length);
|
return string.lastIndexOf(ending) == (string.length - ending.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pdfTargets = [Mimer.Mimer.OctetStream, Mimer.Mimer.PDF, Mimer.Mimer.Postscript, Mimer.Mimer.PWG, Mimer.Mimer.URF];
|
||||||
|
|
||||||
|
|
||||||
function canConvertPdfTo(type)
|
function canConvertPdfTo(type)
|
||||||
{
|
{
|
||||||
var targets = [Mimer.Mimer.OctetStream, Mimer.Mimer.PDF, Mimer.Mimer.Postscript, Mimer.Mimer.PWG, Mimer.Mimer.URF];
|
return has(pdfTargets, type)
|
||||||
return has(targets, type)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function canTransferPostscriptAs(type)
|
function canTransferPostscriptAs(type)
|
||||||
|
@ -384,10 +392,17 @@ function canTransferPostscriptAs(type)
|
||||||
return has(targets, type)
|
return has(targets, type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function canConvertPlaintextTo(type)
|
||||||
|
{
|
||||||
|
var targets = pdfTargets;
|
||||||
|
targets.push(Mimer.Mimer.Plaintext);
|
||||||
|
return has(targets, type)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function canConvertOfficeDocumentTo(type)
|
function canConvertOfficeDocumentTo(type)
|
||||||
{
|
{
|
||||||
var targets = [Mimer.Mimer.OctetStream, Mimer.Mimer.PDF, Mimer.Mimer.Postscript, Mimer.Mimer.PWG, Mimer.Mimer.URF];
|
return has(pdfTargets, type)
|
||||||
return has(targets, type)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function canConvertImageTo(type)
|
function canConvertImageTo(type)
|
||||||
|
@ -417,8 +432,7 @@ function fixupChoices(name, choices, mimeType)
|
||||||
}
|
}
|
||||||
else if(mimeType == Mimer.Mimer.Plaintext)
|
else if(mimeType == Mimer.Mimer.Plaintext)
|
||||||
{
|
{
|
||||||
// We convert plaintext to PDF internally
|
return choices.filter(canConvertPlaintextTo)
|
||||||
return choices.filter(canConvertPdfTo)
|
|
||||||
}
|
}
|
||||||
else if(mimeType == Mimer.Mimer.Postscript)
|
else if(mimeType == Mimer.Mimer.Postscript)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,6 +18,7 @@ IppPrinter::IppPrinter() : _worker(this)
|
||||||
connect(this, &IppPrinter::doGetJobs, &_worker, &PrinterWorker::getJobs);
|
connect(this, &IppPrinter::doGetJobs, &_worker, &PrinterWorker::getJobs);
|
||||||
connect(this, &IppPrinter::doCancelJob, &_worker, &PrinterWorker::cancelJob);
|
connect(this, &IppPrinter::doCancelJob, &_worker, &PrinterWorker::cancelJob);
|
||||||
connect(this, &IppPrinter::doJustUpload, &_worker, &PrinterWorker::justUpload);
|
connect(this, &IppPrinter::doJustUpload, &_worker, &PrinterWorker::justUpload);
|
||||||
|
connect(this, &IppPrinter::doFixupPlaintext, &_worker, &PrinterWorker::fixupPlaintext);
|
||||||
connect(this, &IppPrinter::doFixupJpeg, &_worker, &PrinterWorker::fixupJpeg);
|
connect(this, &IppPrinter::doFixupJpeg, &_worker, &PrinterWorker::fixupJpeg);
|
||||||
|
|
||||||
connect(this, &IppPrinter::doConvertPdf, &_worker, &PrinterWorker::convertPdf);
|
connect(this, &IppPrinter::doConvertPdf, &_worker, &PrinterWorker::convertPdf);
|
||||||
|
@ -354,17 +355,22 @@ QString targetFormatIfAuto(QString documentFormat, QString mimeType, QJsonArray
|
||||||
{
|
{
|
||||||
if(documentFormat == Mimer::OctetStream)
|
if(documentFormat == Mimer::OctetStream)
|
||||||
{
|
{
|
||||||
if(mimeType == Mimer::PDF || mimeType == Mimer::Plaintext)
|
QStringList PdfPrioList = {Mimer::PDF, Mimer::Postscript, Mimer::PWG, Mimer::URF};
|
||||||
|
if(mimeType == Mimer::PDF)
|
||||||
{
|
{
|
||||||
return firstMatch(supportedMimeTypes, {Mimer::PDF, Mimer::Postscript, Mimer::PWG, Mimer::URF });
|
return firstMatch(supportedMimeTypes, PdfPrioList);
|
||||||
}
|
}
|
||||||
else if(mimeType == Mimer::Postscript)
|
else if(mimeType == Mimer::Postscript)
|
||||||
{
|
{
|
||||||
return firstMatch(supportedMimeTypes, {Mimer::Postscript});
|
return firstMatch(supportedMimeTypes, {Mimer::Postscript});
|
||||||
}
|
}
|
||||||
|
else if(mimeType == Mimer::Plaintext)
|
||||||
|
{
|
||||||
|
return firstMatch(supportedMimeTypes, PdfPrioList << Mimer::Plaintext);
|
||||||
|
}
|
||||||
else if(Mimer::isOffice(mimeType))
|
else if(Mimer::isOffice(mimeType))
|
||||||
{
|
{
|
||||||
return firstMatch(supportedMimeTypes, {Mimer::PDF, Mimer::Postscript, Mimer::PWG, Mimer::URF });
|
return firstMatch(supportedMimeTypes, PdfPrioList);
|
||||||
}
|
}
|
||||||
else if(Mimer::isImage(mimeType))
|
else if(Mimer::isImage(mimeType))
|
||||||
{
|
{
|
||||||
|
@ -697,7 +703,14 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
|
||||||
}
|
}
|
||||||
else if(mimeType == Mimer::Plaintext)
|
else if(mimeType == Mimer::Plaintext)
|
||||||
{
|
{
|
||||||
emit doConvertPlaintext(filename, contents, Params);
|
if(targetFormat == Mimer::Plaintext)
|
||||||
|
{
|
||||||
|
emit doFixupPlaintext(filename, contents);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emit doConvertPlaintext(filename, contents, Params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (Mimer::isImage(mimeType))
|
else if (Mimer::isImage(mimeType))
|
||||||
{
|
{
|
||||||
|
|
|
@ -59,6 +59,7 @@ signals:
|
||||||
void doCancelJob(Bytestream msg);
|
void doCancelJob(Bytestream msg);
|
||||||
|
|
||||||
void doJustUpload(QString filename, Bytestream header);
|
void doJustUpload(QString filename, Bytestream header);
|
||||||
|
void doFixupPlaintext(QString filename, Bytestream header);
|
||||||
void doFixupJpeg(QString filename, Bytestream header);
|
void doFixupJpeg(QString filename, Bytestream header);
|
||||||
|
|
||||||
void doConvertPdf(QString filename, Bytestream header, PrintParameters Params);
|
void doConvertPdf(QString filename, Bytestream header, PrintParameters Params);
|
||||||
|
|
|
@ -101,6 +101,51 @@ catch(const ConvertFailedException& e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrinterWorker::fixupPlaintext(QString filename, Bytestream header)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
CurlRequester cr(_printer->httpUrl());
|
||||||
|
connect(&cr, &CurlRequester::done, _printer, &IppPrinter::printRequestFinished);
|
||||||
|
|
||||||
|
QFile inFile(filename);
|
||||||
|
if(!inFile.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
throw ConvertFailedException(tr("Failed to open file"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString allText = inFile.readAll();
|
||||||
|
if(allText.startsWith("\f"))
|
||||||
|
{
|
||||||
|
allText.remove(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(allText.endsWith("\f"))
|
||||||
|
{
|
||||||
|
allText.chop(1);
|
||||||
|
}
|
||||||
|
else if(allText.endsWith("\f\n"))
|
||||||
|
{
|
||||||
|
allText.chop(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList lines;
|
||||||
|
|
||||||
|
foreach(QString rnline, allText.split("\r\n"))
|
||||||
|
{
|
||||||
|
lines.append(rnline.split("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray outData = lines.join("\r\n").toUtf8();
|
||||||
|
|
||||||
|
OK(cr.write((char*)header.raw(), header.size()));
|
||||||
|
OK(cr.write(outData.data(), outData.length()));
|
||||||
|
}
|
||||||
|
catch(const ConvertFailedException& e)
|
||||||
|
{
|
||||||
|
emit failed(e.what() == QString("") ? tr("Upload error") : e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PrinterWorker::convertPdf(QString filename, Bytestream header, PrintParameters Params)
|
void PrinterWorker::convertPdf(QString filename, Bytestream header, PrintParameters Params)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -41,6 +41,8 @@ public slots:
|
||||||
|
|
||||||
void fixupJpeg(QString filename, Bytestream header);
|
void fixupJpeg(QString filename, Bytestream header);
|
||||||
|
|
||||||
|
void fixupPlaintext(QString filename, Bytestream header);
|
||||||
|
|
||||||
void convertPdf(QString filename, Bytestream header, PrintParameters Params);
|
void convertPdf(QString filename, Bytestream header, PrintParameters Params);
|
||||||
|
|
||||||
void convertImage(QString filename, Bytestream header, PrintParameters Params, QString targetFormat, QMargins margins);
|
void convertImage(QString filename, Bytestream header, PrintParameters Params, QString targetFormat, QMargins margins);
|
||||||
|
|
|
@ -591,6 +591,10 @@ auf diesem Drucker</translation>
|
||||||
<source>documents</source>
|
<source>documents</source>
|
||||||
<translation>Dokumente</translation>
|
<translation>Dokumente</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>plaintext</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>strings</name>
|
<name>strings</name>
|
||||||
|
@ -5477,5 +5481,9 @@ auf diesem Drucker</translation>
|
||||||
<source>Unknown</source>
|
<source>Unknown</source>
|
||||||
<translation type="unfinished">Unbekannt</translation>
|
<translation type="unfinished">Unbekannt</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Plaintext</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
</TS>
|
</TS>
|
||||||
|
|
|
@ -590,6 +590,10 @@
|
||||||
<source>documents</source>
|
<source>documents</source>
|
||||||
<translation>documentos</translation>
|
<translation>documentos</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>plaintext</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>strings</name>
|
<name>strings</name>
|
||||||
|
@ -5476,5 +5480,9 @@
|
||||||
<source>Unknown</source>
|
<source>Unknown</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Plaintext</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
</TS>
|
</TS>
|
||||||
|
|
|
@ -591,6 +591,10 @@ sur cette imprimante</translation>
|
||||||
<source>documents</source>
|
<source>documents</source>
|
||||||
<translation>documents</translation>
|
<translation>documents</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>plaintext</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>strings</name>
|
<name>strings</name>
|
||||||
|
@ -5477,5 +5481,9 @@ sur cette imprimante</translation>
|
||||||
<source>Unknown</source>
|
<source>Unknown</source>
|
||||||
<translation type="unfinished">Inconnu</translation>
|
<translation type="unfinished">Inconnu</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Plaintext</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
</TS>
|
</TS>
|
||||||
|
|
|
@ -590,6 +590,10 @@
|
||||||
<source>documents</source>
|
<source>documents</source>
|
||||||
<translation>documenten</translation>
|
<translation>documenten</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>plaintext</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>strings</name>
|
<name>strings</name>
|
||||||
|
@ -5476,5 +5480,9 @@
|
||||||
<source>Unknown</source>
|
<source>Unknown</source>
|
||||||
<translation type="unfinished">Onbekend</translation>
|
<translation type="unfinished">Onbekend</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Plaintext</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
</TS>
|
</TS>
|
||||||
|
|
|
@ -590,6 +590,10 @@
|
||||||
<source>documents</source>
|
<source>documents</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>plaintext</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>strings</name>
|
<name>strings</name>
|
||||||
|
@ -5476,5 +5480,9 @@
|
||||||
<source>Unknown</source>
|
<source>Unknown</source>
|
||||||
<translation type="unfinished">Nieznana drukarka</translation>
|
<translation type="unfinished">Nieznana drukarka</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Plaintext</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
</TS>
|
</TS>
|
||||||
|
|
|
@ -590,6 +590,10 @@
|
||||||
<source>documents</source>
|
<source>documents</source>
|
||||||
<translation>文档</translation>
|
<translation>文档</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>plaintext</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>strings</name>
|
<name>strings</name>
|
||||||
|
@ -5476,5 +5480,9 @@
|
||||||
<source>Unknown</source>
|
<source>Unknown</source>
|
||||||
<translation type="unfinished">未知</translation>
|
<translation type="unfinished">未知</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Plaintext</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
</TS>
|
</TS>
|
||||||
|
|
Loading…
Reference in a new issue