Add SVG support
This commit is contained in:
parent
1e6be94965
commit
6c7e09fdb5
14 changed files with 138 additions and 22 deletions
|
@ -26,6 +26,7 @@ INSTALLS += i18n
|
|||
system(lrelease $$PWD/translations/*.ts)
|
||||
|
||||
CONFIG += sailfishapp
|
||||
QT += svg
|
||||
PKGCONFIG += mlite5 libcurl poppler glib-2.0 cairo libjpeg
|
||||
LIBS += -lcurl -lglib-2.0 -lgobject-2.0 -ldl
|
||||
DEFINES += MADNESS=1
|
||||
|
|
|
@ -75,7 +75,11 @@ ApplicationWindow
|
|||
}
|
||||
|
||||
function simplifyType(mimetype) {
|
||||
if(Mimer.isImage(mimetype))
|
||||
if(mimetype == Mimer.SVG)
|
||||
{
|
||||
return {simple: "svg", translatable: qsTr("SVGs")};
|
||||
}
|
||||
else if(Mimer.isImage(mimetype))
|
||||
{
|
||||
return {simple: "image", translatable: qsTr("images")};
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ Page {
|
|||
tag: IppMsg.Keyword
|
||||
name: "print-scaling"
|
||||
prettyName: qsTr("Scaling")
|
||||
valid: _valid && Mimer.isImage(selectedFileType)
|
||||
valid: _valid && Mimer.isImage(selectedFileType) && selectedFileType != Mimer.SVG
|
||||
DependentOn {
|
||||
target: transferFormatSetting
|
||||
values: [Mimer.JPEG, Mimer.PNG]
|
||||
|
|
|
@ -46,8 +46,7 @@ function supported_formats(printer, considerAdditionalFormats)
|
|||
mimetypes = mimetypes.concat(Mimer.Mimer.OfficeFormats);
|
||||
}
|
||||
|
||||
if (raster || has(formats, Mimer.Mimer.JPEG) || has(formats, Mimer.Mimer.PNG) || has(formats, Mimer.Mimer.RBMP) ||
|
||||
has(formats, Mimer.Mimer.PDF) || has(formats, Mimer.Mimer.Postscript))
|
||||
if(pdf || has(formats, Mimer.Mimer.JPEG) || has(formats, Mimer.Mimer.PNG) || has(formats, Mimer.Mimer.RBMP))
|
||||
{
|
||||
images = true;
|
||||
mimetypes.push(Mimer.Mimer.JPEG);
|
||||
|
@ -56,6 +55,11 @@ function supported_formats(printer, considerAdditionalFormats)
|
|||
mimetypes.push(Mimer.Mimer.GIF);
|
||||
}
|
||||
|
||||
if(pdf)
|
||||
{
|
||||
mimetypes.push(Mimer.Mimer.SVG);
|
||||
}
|
||||
|
||||
return {pdf: pdf, postscript: postscript, plaintext: plaintext, office: office, images: images, mimetypes: mimetypes};
|
||||
}
|
||||
|
||||
|
@ -259,6 +263,8 @@ function ippName(name, value, printerStrings)
|
|||
return qsTr("JPEG");
|
||||
case Mimer.Mimer.GIF:
|
||||
return qsTr("GIF");
|
||||
case Mimer.Mimer.SVG:
|
||||
return qsTr("SVG");
|
||||
case Mimer.Mimer.RBMP:
|
||||
return qsTr("Reverse BMP");
|
||||
default:
|
||||
|
@ -401,12 +407,16 @@ function canConvertPlaintextTo(type)
|
|||
return has(targets, type)
|
||||
}
|
||||
|
||||
|
||||
function canConvertOfficeDocumentTo(type)
|
||||
{
|
||||
return has(pdfTargets, type)
|
||||
}
|
||||
|
||||
function canConvertSvgTo(type)
|
||||
{
|
||||
return has(pdfTargets, type)
|
||||
}
|
||||
|
||||
function canConvertImageTo(type)
|
||||
{
|
||||
var targets = [Mimer.Mimer.OctetStream, Mimer.Mimer.JPEG, Mimer.Mimer.PNG, Mimer.Mimer.RBMP,
|
||||
|
@ -445,6 +455,10 @@ function fixupChoices(name, choices, mimeType)
|
|||
{
|
||||
return choices.filter(canConvertOfficeDocumentTo)
|
||||
}
|
||||
else if(mimeType == Mimer.Mimer.SVG)
|
||||
{
|
||||
return choices.filter(canConvertSvgTo)
|
||||
}
|
||||
else if(Mimer.Mimer.isImage(mimeType))
|
||||
{
|
||||
return choices.filter(canConvertImageTo);
|
||||
|
|
|
@ -383,6 +383,11 @@ QString targetFormatIfAuto(QString documentFormat, QString mimeType, QJsonArray
|
|||
{
|
||||
return firstMatch(supportedMimeTypes, PdfPrioList);
|
||||
}
|
||||
else if(documentFormat == Mimer::SVG)
|
||||
{
|
||||
QStringList SvgPrioList {Mimer::PWG, Mimer::URF, Mimer::PDF, Mimer::Postscript};
|
||||
return firstMatch(supportedMimeTypes, SvgPrioList);
|
||||
}
|
||||
else if(Mimer::isImage(mimeType))
|
||||
{
|
||||
QStringList ImageFormatPrioList {Mimer::PNG, Mimer::PWG, Mimer::URF, Mimer::PDF, Mimer::Postscript, Mimer::JPEG};
|
||||
|
@ -696,7 +701,7 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
|
|||
{ // Can't process Postscript
|
||||
emit doJustUpload(filename, contents);
|
||||
}
|
||||
else if(mimer->isImage(mimeType) && mimer->isImage(targetFormat))
|
||||
else if((mimeType != Mimer::SVG) && mimer->isImage(mimeType) && mimer->isImage(targetFormat))
|
||||
{ // Just make sure the image is in the desired format (and jpeg baseline-encoded), don't resize locally
|
||||
emit doPrintImageAsImage(filename, contents, targetFormat);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "mimer.h"
|
||||
#include <QDebug>
|
||||
|
||||
const QString Mimer::OctetStream = "application/octet-stream";
|
||||
|
||||
|
@ -11,6 +12,7 @@ const QString Mimer::PNG = "image/png";
|
|||
const QString Mimer::GIF = "image/gif";
|
||||
const QString Mimer::JPEG = "image/jpeg";
|
||||
const QString Mimer::TIFF = "image/tiff";
|
||||
const QString Mimer::SVG = "image/svg+xml";
|
||||
const QString Mimer::RBMP = "image/reverse-encoding-bmp";
|
||||
|
||||
const QString Mimer::DOC = "application/msword";
|
||||
|
@ -51,5 +53,7 @@ Mimer* Mimer::instance()
|
|||
}
|
||||
|
||||
QString Mimer::get_type(QString filename) {
|
||||
return _db.mimeTypeForFile(filename).name();
|
||||
QString type = _db.mimeTypeForFile(filename).name();
|
||||
qDebug() << "MimeType:" << type;
|
||||
return type;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
Q_PROPERTY(const QString GIF MEMBER GIF CONSTANT);
|
||||
Q_PROPERTY(const QString JPEG MEMBER JPEG CONSTANT);
|
||||
Q_PROPERTY(const QString TIFF MEMBER TIFF CONSTANT);
|
||||
Q_PROPERTY(const QString SVG MEMBER SVG CONSTANT);
|
||||
Q_PROPERTY(const QString RBMP MEMBER RBMP CONSTANT);
|
||||
|
||||
Q_PROPERTY(const QString DOC MEMBER DOC CONSTANT);
|
||||
|
@ -50,6 +51,7 @@ public:
|
|||
static const QString GIF;
|
||||
static const QString JPEG;
|
||||
static const QString TIFF;
|
||||
static const QString SVG;
|
||||
static const QString RBMP;
|
||||
|
||||
static const QString DOC;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <QTextDocument>
|
||||
#include <QPdfWriter>
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QtSvg>
|
||||
#include "ippprinter.h"
|
||||
#include "pdf2printable.h"
|
||||
#include "ppm2pwg.h"
|
||||
|
@ -258,7 +259,7 @@ catch(const ConvertFailedException& e)
|
|||
void PrinterWorker::convertImage(QString filename, Bytestream header, PrintParameters Params, QMargins margins)
|
||||
{
|
||||
try {
|
||||
|
||||
QString mimeType = Mimer::instance()->get_type(filename);
|
||||
|
||||
if(Params.format == PrintParameters::URF && (Params.hwResW != Params.hwResH))
|
||||
{ // URF only supports symmetric resolutions
|
||||
|
@ -268,18 +269,6 @@ try {
|
|||
|
||||
qDebug() << "Size is" << Params.getPaperSizeWInPixels() << "x" << Params.getPaperSizeHInPixels();
|
||||
|
||||
QImage inImage;
|
||||
if(!inImage.load(filename))
|
||||
{
|
||||
qDebug() << "failed to load";
|
||||
throw ConvertFailedException(tr("Failed to load image"));
|
||||
}
|
||||
|
||||
if(inImage.width() > inImage.height())
|
||||
{
|
||||
inImage = inImage.transformed(QMatrix().rotate(270.0));
|
||||
}
|
||||
|
||||
int leftMarginPx = (margins.left()/2540.0)*Params.hwResW;
|
||||
int rightMarginPx = (margins.right()/2540.0)*Params.hwResW;
|
||||
int topMarginPx = (margins.top()/2540.0)*Params.hwResH;
|
||||
|
@ -288,8 +277,57 @@ try {
|
|||
int totalXMarginPx = leftMarginPx+rightMarginPx;
|
||||
int totalYMarginPx = topMarginPx+bottomMarginPx;
|
||||
|
||||
inImage = inImage.scaled(Params.getPaperSizeWInPixels()-totalXMarginPx, Params.getPaperSizeHInPixels()-totalYMarginPx,
|
||||
Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
size_t targetWidth = Params.getPaperSizeWInPixels()-totalXMarginPx;
|
||||
size_t targetHeight = Params.getPaperSizeHInPixels()-totalYMarginPx;
|
||||
|
||||
QImage inImage;
|
||||
if(mimeType == Mimer::SVG)
|
||||
{
|
||||
QSvgRenderer renderer(filename);
|
||||
if(!renderer.isValid())
|
||||
{
|
||||
qDebug() << "failed to load svg";
|
||||
throw ConvertFailedException(tr("Failed to load image"));
|
||||
}
|
||||
QSize defaultSize = renderer.defaultSize();
|
||||
QSize targetSize(targetWidth, targetHeight);
|
||||
|
||||
if(defaultSize.width() > defaultSize.height())
|
||||
{
|
||||
targetSize.transpose();
|
||||
}
|
||||
|
||||
QSize initialSize = defaultSize.scaled(targetSize, Qt::KeepAspectRatio);
|
||||
|
||||
inImage = QImage(initialSize, QImage::Format_RGB32);
|
||||
inImage.fill(QColor("white"));
|
||||
QPainter painter(&inImage);
|
||||
|
||||
renderer.render(&painter);
|
||||
painter.end(); // Or else the painter segfaults on destruction if we have messed with the image
|
||||
|
||||
if(inImage.width() > inImage.height())
|
||||
{
|
||||
inImage = inImage.transformed(QMatrix().rotate(270.0));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!inImage.load(filename))
|
||||
{
|
||||
qDebug() << "failed to load";
|
||||
throw ConvertFailedException(tr("Failed to load image"));
|
||||
}
|
||||
if(inImage.width() > inImage.height())
|
||||
{
|
||||
inImage = inImage.transformed(QMatrix().rotate(270.0));
|
||||
}
|
||||
|
||||
inImage = inImage.scaled(targetWidth, targetHeight,
|
||||
Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
|
||||
if(Params.format == PrintParameters::PDF || Params.format == PrintParameters::Postscript)
|
||||
{
|
||||
|
|
|
@ -611,6 +611,10 @@ auf diesem Drucker</translation>
|
|||
<source>plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SVGs</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>strings</name>
|
||||
|
@ -5505,5 +5509,9 @@ auf diesem Drucker</translation>
|
|||
<source>Reverse BMP</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SVG</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -610,6 +610,10 @@
|
|||
<source>plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SVGs</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>strings</name>
|
||||
|
@ -5504,5 +5508,9 @@
|
|||
<source>Reverse BMP</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SVG</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -611,6 +611,10 @@ sur cette imprimante</translation>
|
|||
<source>plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SVGs</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>strings</name>
|
||||
|
@ -5505,5 +5509,9 @@ sur cette imprimante</translation>
|
|||
<source>Reverse BMP</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SVG</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -610,6 +610,10 @@
|
|||
<source>plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SVGs</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>strings</name>
|
||||
|
@ -5504,5 +5508,9 @@
|
|||
<source>Reverse BMP</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SVG</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -610,6 +610,10 @@
|
|||
<source>plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SVGs</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>strings</name>
|
||||
|
@ -5504,5 +5508,9 @@
|
|||
<source>Reverse BMP</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SVG</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -610,6 +610,10 @@
|
|||
<source>plaintext</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SVGs</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>strings</name>
|
||||
|
@ -5504,5 +5508,9 @@
|
|||
<source>Reverse BMP</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SVG</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
Loading…
Reference in a new issue