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")};
|
||||
}
|
||||
else if(mimetype == Mimer.Plaintext)
|
||||
{
|
||||
return {simple: "plaintext", translatable: qsTr("plaintext")};
|
||||
}
|
||||
else
|
||||
{
|
||||
return {simple: "document", translatable: qsTr("documents")};
|
||||
|
|
|
@ -26,17 +26,21 @@ function supported_formats(printer, considerAdditionalFormats)
|
|||
{
|
||||
pdf = true;
|
||||
mimetypes.push(Mimer.Mimer.PDF);
|
||||
plaintext = true;
|
||||
mimetypes.push(Mimer.Mimer.Plaintext);
|
||||
}
|
||||
|
||||
if(has(formats, Mimer.Mimer.Postscript))
|
||||
{
|
||||
postscript = true;
|
||||
mimetypes.push(Mimer.Mimer.Postscript);
|
||||
}
|
||||
|
||||
if((ConvertChecker.ConvertChecker.calligra) &&
|
||||
( has(formats, Mimer.Mimer.PDF) || has(formats, Mimer.Mimer.Postscript) || raster ))
|
||||
if(pdf || has(formats, Mimer.Mimer.Plaintext))
|
||||
{
|
||||
plaintext = true;
|
||||
mimetypes.push(Mimer.Mimer.Plaintext);
|
||||
}
|
||||
|
||||
if((ConvertChecker.ConvertChecker.calligra) && pdf)
|
||||
{
|
||||
office = true;
|
||||
mimetypes = mimetypes.concat(Mimer.Mimer.OfficeFormats);
|
||||
|
@ -243,6 +247,8 @@ function ippName(name, value, printerStrings)
|
|||
return qsTr("PDF");
|
||||
case Mimer.Mimer.Postscript:
|
||||
return qsTr("Postscript");
|
||||
case Mimer.Mimer.Plaintext:
|
||||
return qsTr("Plaintext");
|
||||
case Mimer.Mimer.PWG:
|
||||
return qsTr("PWG-raster");
|
||||
case Mimer.Mimer.URF:
|
||||
|
@ -372,10 +378,12 @@ function endsWith(ending, string)
|
|||
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)
|
||||
{
|
||||
var targets = [Mimer.Mimer.OctetStream, Mimer.Mimer.PDF, Mimer.Mimer.Postscript, Mimer.Mimer.PWG, Mimer.Mimer.URF];
|
||||
return has(targets, type)
|
||||
return has(pdfTargets, type)
|
||||
}
|
||||
|
||||
function canTransferPostscriptAs(type)
|
||||
|
@ -384,10 +392,17 @@ function canTransferPostscriptAs(type)
|
|||
return has(targets, type)
|
||||
}
|
||||
|
||||
function canConvertPlaintextTo(type)
|
||||
{
|
||||
var targets = pdfTargets;
|
||||
targets.push(Mimer.Mimer.Plaintext);
|
||||
return has(targets, type)
|
||||
}
|
||||
|
||||
|
||||
function canConvertOfficeDocumentTo(type)
|
||||
{
|
||||
var targets = [Mimer.Mimer.OctetStream, Mimer.Mimer.PDF, Mimer.Mimer.Postscript, Mimer.Mimer.PWG, Mimer.Mimer.URF];
|
||||
return has(targets, type)
|
||||
return has(pdfTargets, type)
|
||||
}
|
||||
|
||||
function canConvertImageTo(type)
|
||||
|
@ -417,8 +432,7 @@ function fixupChoices(name, choices, mimeType)
|
|||
}
|
||||
else if(mimeType == Mimer.Mimer.Plaintext)
|
||||
{
|
||||
// We convert plaintext to PDF internally
|
||||
return choices.filter(canConvertPdfTo)
|
||||
return choices.filter(canConvertPlaintextTo)
|
||||
}
|
||||
else if(mimeType == Mimer.Mimer.Postscript)
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@ IppPrinter::IppPrinter() : _worker(this)
|
|||
connect(this, &IppPrinter::doGetJobs, &_worker, &PrinterWorker::getJobs);
|
||||
connect(this, &IppPrinter::doCancelJob, &_worker, &PrinterWorker::cancelJob);
|
||||
connect(this, &IppPrinter::doJustUpload, &_worker, &PrinterWorker::justUpload);
|
||||
connect(this, &IppPrinter::doFixupPlaintext, &_worker, &PrinterWorker::fixupPlaintext);
|
||||
connect(this, &IppPrinter::doFixupJpeg, &_worker, &PrinterWorker::fixupJpeg);
|
||||
|
||||
connect(this, &IppPrinter::doConvertPdf, &_worker, &PrinterWorker::convertPdf);
|
||||
|
@ -354,17 +355,22 @@ QString targetFormatIfAuto(QString documentFormat, QString mimeType, QJsonArray
|
|||
{
|
||||
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)
|
||||
{
|
||||
return firstMatch(supportedMimeTypes, {Mimer::Postscript});
|
||||
}
|
||||
else if(mimeType == Mimer::Plaintext)
|
||||
{
|
||||
return firstMatch(supportedMimeTypes, PdfPrioList << Mimer::Plaintext);
|
||||
}
|
||||
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))
|
||||
{
|
||||
|
@ -697,7 +703,14 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
|
|||
}
|
||||
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))
|
||||
{
|
||||
|
|
|
@ -59,6 +59,7 @@ signals:
|
|||
void doCancelJob(Bytestream msg);
|
||||
|
||||
void doJustUpload(QString filename, Bytestream header);
|
||||
void doFixupPlaintext(QString filename, Bytestream header);
|
||||
void doFixupJpeg(QString filename, Bytestream header);
|
||||
|
||||
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)
|
||||
{
|
||||
try {
|
||||
|
|
|
@ -41,6 +41,8 @@ public slots:
|
|||
|
||||
void fixupJpeg(QString filename, Bytestream header);
|
||||
|
||||
void fixupPlaintext(QString filename, Bytestream header);
|
||||
|
||||
void convertPdf(QString filename, Bytestream header, PrintParameters Params);
|
||||
|
||||
void convertImage(QString filename, Bytestream header, PrintParameters Params, QString targetFormat, QMargins margins);
|
||||
|
|
|
@ -591,6 +591,10 @@ auf diesem Drucker</translation>
|
|||
<source>documents</source>
|
||||
<translation>Dokumente</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>strings</name>
|
||||
|
@ -5477,5 +5481,9 @@ auf diesem Drucker</translation>
|
|||
<source>Unknown</source>
|
||||
<translation type="unfinished">Unbekannt</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -590,6 +590,10 @@
|
|||
<source>documents</source>
|
||||
<translation>documentos</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>strings</name>
|
||||
|
@ -5476,5 +5480,9 @@
|
|||
<source>Unknown</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -591,6 +591,10 @@ sur cette imprimante</translation>
|
|||
<source>documents</source>
|
||||
<translation>documents</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>strings</name>
|
||||
|
@ -5477,5 +5481,9 @@ sur cette imprimante</translation>
|
|||
<source>Unknown</source>
|
||||
<translation type="unfinished">Inconnu</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -590,6 +590,10 @@
|
|||
<source>documents</source>
|
||||
<translation>documenten</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>strings</name>
|
||||
|
@ -5476,5 +5480,9 @@
|
|||
<source>Unknown</source>
|
||||
<translation type="unfinished">Onbekend</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -590,6 +590,10 @@
|
|||
<source>documents</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>strings</name>
|
||||
|
@ -5476,5 +5480,9 @@
|
|||
<source>Unknown</source>
|
||||
<translation type="unfinished">Nieznana drukarka</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -590,6 +590,10 @@
|
|||
<source>documents</source>
|
||||
<translation>文档</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>strings</name>
|
||||
|
@ -5476,5 +5480,9 @@
|
|||
<source>Unknown</source>
|
||||
<translation type="unfinished">未知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
Loading…
Reference in a new issue