Use PrintParameters for conversion settings
This commit is contained in:
parent
e16bfbe7c6
commit
09ceb4f0ec
13 changed files with 125 additions and 253 deletions
|
@ -91,6 +91,7 @@ HEADERS += \
|
|||
ppm2pwg/pdf2printable.h \
|
||||
ppm2pwg/baselinify.h \
|
||||
ppm2pwg/madness.h \
|
||||
ppm2pwg/printparameters.h \
|
||||
ppm2pwg/PwgPgHdr.h \
|
||||
ppm2pwg/PwgPgHdr.codable \
|
||||
ppm2pwg/UrfPgHdr.h \
|
||||
|
|
2
ppm2pwg
2
ppm2pwg
|
@ -1 +1 @@
|
|||
Subproject commit 4844ff3ce2b773ae43585039aae146b6d225e0a6
|
||||
Subproject commit 7db7a12a8dbf8659050601888a6a48a38404f543
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
Q_DECLARE_METATYPE(CURLcode)
|
||||
Q_DECLARE_METATYPE(Bytestream)
|
||||
Q_DECLARE_METATYPE(PrintParameters)
|
||||
|
||||
template <class T>
|
||||
static QObject* singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||
|
@ -26,6 +27,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
qRegisterMetaType<CURLcode>();
|
||||
qRegisterMetaType<Bytestream>();
|
||||
qRegisterMetaType<PrintParameters>();
|
||||
|
||||
// Turn on/off logging according to setting
|
||||
QLoggingCategory::defaultCategory()->setEnabled(QtMsgType::QtDebugMsg, Settings::instance()->debugLog());
|
||||
|
|
|
@ -517,6 +517,7 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
|
|||
_progress = "";
|
||||
emit progressChanged();
|
||||
|
||||
PrintParameters Params;
|
||||
QFileInfo fileinfo(filename);
|
||||
|
||||
if(!fileinfo.exists())
|
||||
|
@ -542,8 +543,8 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
|
|||
|
||||
QString PaperSize = getAttrOrDefault(jobAttrs, "media").toString();
|
||||
|
||||
QString documentFormat = getAttrOrDefault(jobAttrs, "document-format").toString();
|
||||
qDebug() << "target format:" << documentFormat;
|
||||
QString targetFormat = getAttrOrDefault(jobAttrs, "document-format").toString();
|
||||
qDebug() << "target format:" << targetFormat;
|
||||
|
||||
QMargins margins(getAttrOrDefault(jobAttrs, "media-left-margin", "media-col").toInt(),
|
||||
getAttrOrDefault(jobAttrs, "media-top-margin", "media-col").toInt(),
|
||||
|
@ -551,7 +552,7 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
|
|||
getAttrOrDefault(jobAttrs, "media-bottom-margin", "media-col").toInt());
|
||||
|
||||
// Only keep margin setting for JPEG - but only attemt to remove it if media-col exists
|
||||
if(!(mimeType == Mimer::JPEG && documentFormat == Mimer::JPEG) && jobAttrs.contains("media-col"))
|
||||
if(!(mimeType == Mimer::JPEG && targetFormat == Mimer::JPEG) && jobAttrs.contains("media-col"))
|
||||
{
|
||||
QJsonObject MediaCol = jobAttrs["media-col"].toObject();
|
||||
QJsonObject MediaColValue = MediaCol["value"].toObject();
|
||||
|
@ -603,18 +604,45 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
|
|||
}
|
||||
|
||||
// document-format goes in the op-attrs and not the job-attrs
|
||||
o.insert("document-format", QJsonObject {{"tag", IppMsg::MimeMediaType}, {"value", documentFormat}});
|
||||
o.insert("document-format", QJsonObject {{"tag", IppMsg::MimeMediaType}, {"value", targetFormat}});
|
||||
jobAttrs.remove("document-format");
|
||||
|
||||
documentFormat = targetFormatIfAuto(documentFormat, mimeType, supportedMimeTypes);
|
||||
qDebug() << "adjusted target format:" << documentFormat;
|
||||
targetFormat = targetFormatIfAuto(targetFormat, mimeType, supportedMimeTypes);
|
||||
qDebug() << "adjusted target format:" << targetFormat;
|
||||
|
||||
if(documentFormat == "" || documentFormat == Mimer::OctetStream)
|
||||
if(targetFormat == "" || targetFormat == Mimer::OctetStream)
|
||||
{
|
||||
emit convertFailed(tr("Unknown document format"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(targetFormat == Mimer::PDF)
|
||||
{
|
||||
Params.format = PrintParameters::PDF;
|
||||
}
|
||||
else if(targetFormat == Mimer::Postscript)
|
||||
{
|
||||
Params.format = PrintParameters::Postscript;
|
||||
}
|
||||
else if(targetFormat == Mimer::PWG)
|
||||
{
|
||||
Params.format = PrintParameters::PWG;
|
||||
}
|
||||
else if(targetFormat == Mimer::URF)
|
||||
{
|
||||
Params.format = PrintParameters::URF;
|
||||
}
|
||||
|
||||
if(!PaperSizes.contains(Params.paperSizeName.c_str()))
|
||||
{
|
||||
qDebug() << "Unsupported paper size" << Params.paperSizeName.c_str();
|
||||
emit convertFailed(tr("Unsupported paper size"));
|
||||
}
|
||||
QSizeF size = PaperSizes[Params.paperSizeName.c_str()];
|
||||
Params.paperSizeUnits = PrintParameters::Millimeters;
|
||||
Params.paperSizeW = size.width();
|
||||
Params.paperSizeH = size.height();
|
||||
|
||||
qDebug() << "Printing job" << o << jobAttrs;
|
||||
|
||||
QJsonValue PrinterResolutionRef = getAttrOrDefault(jobAttrs, "printer-resolution");
|
||||
|
@ -623,22 +651,20 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
|
|||
bool BackHFlip = false;
|
||||
bool BackVFlip = false;
|
||||
|
||||
adjustRasterSettings(documentFormat, jobAttrs, HwResX, HwResY, BackHFlip, BackVFlip);
|
||||
adjustRasterSettings(targetFormat, jobAttrs, HwResX, HwResY, BackHFlip, BackVFlip);
|
||||
|
||||
quint32 Quality = getAttrOrDefault(jobAttrs, "print-quality").toInt();
|
||||
Params.quality = getAttrOrDefault(jobAttrs, "print-quality").toInt();
|
||||
|
||||
QString PrintColorMode = getAttrOrDefault(jobAttrs, "print-color-mode").toString();
|
||||
quint32 Colors = PrintColorMode.contains("color") ? 3 : PrintColorMode.contains("monochrome") ? 1 : 0;
|
||||
Params.colors = PrintColorMode.contains("color") ? 3 : PrintColorMode.contains("monochrome") ? 1 : Params.colors;
|
||||
|
||||
quint32 PageRangeLow = 0;
|
||||
quint32 PageRangeHigh = 0;
|
||||
if(jobAttrs.contains("page-ranges"))
|
||||
{
|
||||
QJsonObject PageRanges = getAttrOrDefault(jobAttrs, "page-ranges").toObject();
|
||||
PageRangeLow = PageRanges["low"].toInt();
|
||||
PageRangeHigh = PageRanges["high"].toInt();
|
||||
Params.fromPage = PageRanges["low"].toInt();
|
||||
Params.toPage = PageRanges["high"].toInt();
|
||||
// Effected locally, unless it is Postscript which we cant't render
|
||||
if(documentFormat != Mimer::Postscript)
|
||||
if(targetFormat != Mimer::Postscript)
|
||||
{
|
||||
jobAttrs.remove("page-ranges");
|
||||
}
|
||||
|
@ -652,11 +678,11 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
|
|||
|
||||
setBusyMessage(tr("Preparing"));
|
||||
|
||||
if((mimeType == documentFormat) && (documentFormat == Mimer::Postscript))
|
||||
if((mimeType == targetFormat) && (targetFormat == Mimer::Postscript))
|
||||
{ // Can't process Postscript
|
||||
emit doJustUpload(filename, contents);
|
||||
}
|
||||
else if((mimeType == documentFormat) && (documentFormat == Mimer::JPEG))
|
||||
else if((mimeType == targetFormat) && (targetFormat == Mimer::JPEG))
|
||||
{ // Just make the jpeg baseline-encoded, don't resize locally
|
||||
emit doFixupJpeg(filename, contents);
|
||||
}
|
||||
|
@ -672,41 +698,33 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
|
|||
return;
|
||||
}
|
||||
|
||||
bool TwoSided = false;
|
||||
bool Tumble = false;
|
||||
QString Sides = getAttrOrDefault(jobAttrs, "sides").toString();
|
||||
|
||||
if(Sides=="two-sided-long-edge")
|
||||
{
|
||||
TwoSided = true;
|
||||
Params.duplex = true;
|
||||
}
|
||||
else if(Sides=="two-sided-short-edge")
|
||||
{
|
||||
TwoSided = true;
|
||||
Tumble = true;
|
||||
Params.duplex = true;
|
||||
Params.tumble = true;
|
||||
}
|
||||
|
||||
if(mimeType == Mimer::PDF)
|
||||
{
|
||||
emit doConvertPdf(filename, contents, documentFormat, Colors, Quality,
|
||||
PaperSize, HwResX, HwResY, TwoSided, Tumble, PageRangeLow, PageRangeHigh,
|
||||
BackHFlip, BackVFlip);
|
||||
emit doConvertPdf(filename, contents, Params);
|
||||
}
|
||||
else if(mimeType == Mimer::Plaintext)
|
||||
{
|
||||
emit doConvertPlaintext(filename, contents, documentFormat, Colors, Quality,
|
||||
PaperSize, HwResX, HwResY, TwoSided, Tumble, BackHFlip, BackVFlip);
|
||||
emit doConvertPlaintext(filename, contents, Params);
|
||||
}
|
||||
else if (Mimer::isImage(mimeType))
|
||||
{
|
||||
emit doConvertImage(filename, contents, documentFormat, Colors, Quality,
|
||||
PaperSize, HwResX, HwResY, margins);
|
||||
emit doConvertImage(filename, contents, Params, targetFormat, margins);
|
||||
}
|
||||
else if(Mimer::isOffice(mimeType))
|
||||
{
|
||||
emit doConvertOfficeDocument(filename, contents, documentFormat, Colors, Quality,
|
||||
PaperSize, HwResX, HwResY, TwoSided, Tumble, PageRangeLow, PageRangeHigh,
|
||||
BackHFlip, BackVFlip);
|
||||
emit doConvertOfficeDocument(filename, contents, Params);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -61,23 +61,13 @@ signals:
|
|||
void doJustUpload(QString filename, Bytestream header);
|
||||
void doFixupJpeg(QString filename, Bytestream header);
|
||||
|
||||
void doConvertPdf(QString filename, Bytestream header,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip);
|
||||
void doConvertPdf(QString filename, Bytestream header, PrintParameters Params);
|
||||
|
||||
void doConvertImage(QString filename, Bytestream header,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, QMargins margins);
|
||||
void doConvertImage(QString filename, Bytestream header, PrintParameters Params, QString targetFormat, QMargins margins);
|
||||
|
||||
void doConvertOfficeDocument(QString filename, Bytestream header,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip);
|
||||
void doConvertOfficeDocument(QString filename, Bytestream header, PrintParameters Params);
|
||||
|
||||
void doConvertPlaintext(QString filename, Bytestream header,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, bool BackHFlip, bool BackVFlip);
|
||||
void doConvertPlaintext(QString filename, Bytestream header, PrintParameters Params);
|
||||
|
||||
void doGetStrings(QUrl url);
|
||||
void doGetImage(QUrl url);
|
||||
|
|
|
@ -101,42 +101,9 @@ catch(const ConvertFailedException& e)
|
|||
}
|
||||
}
|
||||
|
||||
void PrinterWorker::convertPdf(QString filename, Bytestream header,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip)
|
||||
void PrinterWorker::convertPdf(QString filename, Bytestream header, PrintParameters Params)
|
||||
{
|
||||
try {
|
||||
Format format;
|
||||
|
||||
emit busyMessage(tr("Printing"));
|
||||
|
||||
if(targetFormat == Mimer::URF)
|
||||
{
|
||||
format = Format::URF;
|
||||
}
|
||||
else if(targetFormat == Mimer::PWG)
|
||||
{
|
||||
format = Format::PWG;
|
||||
}
|
||||
else if(targetFormat == Mimer::Postscript)
|
||||
{
|
||||
format = Format::Postscript;
|
||||
}
|
||||
else if (targetFormat == Mimer::PDF)
|
||||
{
|
||||
format = Format::PDF;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ConvertFailedException(tr("Unsupported target format"));
|
||||
}
|
||||
|
||||
if(Colors == 0)
|
||||
{
|
||||
Colors = 3;
|
||||
}
|
||||
|
||||
CurlRequester cr(_printer->httpUrl());
|
||||
connect(&cr, &CurlRequester::done, _printer, &IppPrinter::printRequestFinished);
|
||||
|
||||
|
@ -154,19 +121,9 @@ try {
|
|||
emit progress(page, total);
|
||||
});
|
||||
|
||||
if(!PaperSizes.contains(PaperSize))
|
||||
{
|
||||
qDebug() << "Unsupported paper size" << PaperSize;
|
||||
throw ConvertFailedException(tr("Unsupported paper size"));
|
||||
}
|
||||
QSizeF size = PaperSizes[PaperSize];
|
||||
float Width = size.width();
|
||||
float Height = size.height();
|
||||
|
||||
bool verbose = QLoggingCategory::defaultCategory()->isDebugEnabled();
|
||||
|
||||
int res = pdf_to_printable(filename.toStdString(), WriteFun, Colors, Quality, PaperSize.toStdString(), Width, Height, HwResX, HwResY,
|
||||
format, TwoSided, Tumble, BackHFlip, BackVFlip, PageRangeLow, PageRangeHigh, ProgressFun, verbose);
|
||||
int res = pdf_to_printable(filename.toStdString(), WriteFun, Params, ProgressFun, verbose);
|
||||
|
||||
if(res != 0)
|
||||
{
|
||||
|
@ -181,60 +138,25 @@ catch(const ConvertFailedException& e)
|
|||
}
|
||||
}
|
||||
|
||||
void PrinterWorker::convertImage(QString filename, Bytestream header,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, QMargins margins)
|
||||
void PrinterWorker::convertImage(QString filename, Bytestream header, PrintParameters Params, QString targetFormat, QMargins margins)
|
||||
{
|
||||
try {
|
||||
|
||||
bool urf = false;
|
||||
bool pdfOrPostscript = false;
|
||||
QString imageFormat = "";
|
||||
QStringList supportedImageFormats = {Mimer::JPEG, Mimer::PNG};
|
||||
|
||||
if(targetFormat == Mimer::URF)
|
||||
{
|
||||
urf = true;
|
||||
}
|
||||
else if(targetFormat == Mimer::PWG)
|
||||
{
|
||||
//ok
|
||||
}
|
||||
else if(targetFormat == Mimer::PDF || targetFormat == Mimer::Postscript)
|
||||
{
|
||||
HwResX = HwResY = std::min(HwResX, HwResY);
|
||||
pdfOrPostscript = true;
|
||||
}
|
||||
else if(supportedImageFormats.contains(targetFormat))
|
||||
if(supportedImageFormats.contains(targetFormat))
|
||||
{
|
||||
imageFormat = targetFormat.split("/")[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ConvertFailedException(tr("Unsupported target format"));
|
||||
}
|
||||
|
||||
if(Colors == 0)
|
||||
{
|
||||
Colors = 3;
|
||||
}
|
||||
|
||||
if(urf && (HwResX != HwResY))
|
||||
if(Params.format == PrintParameters::URF && (Params.hwResW != Params.hwResH))
|
||||
{ // URF only supports symmetric resolutions
|
||||
qDebug() << "Unsupported URF resolution" << PaperSize;
|
||||
qDebug() << "Unsupported URF resolution";
|
||||
throw ConvertFailedException(tr("Unsupported resolution (dpi)"));
|
||||
}
|
||||
|
||||
if(!PaperSizes.contains(PaperSize))
|
||||
{
|
||||
qDebug() << "Unsupported paper size" << PaperSize;
|
||||
throw ConvertFailedException(tr("Unsupported paper size"));
|
||||
}
|
||||
QSizeF size = PaperSizes[PaperSize];
|
||||
quint32 Width = qRound(size.width()/25.4*HwResX);
|
||||
quint32 Height = qRound(size.height()/25.4*HwResY);
|
||||
|
||||
qDebug() << "Size is" << Width << "x" << Height;
|
||||
qDebug() << "Size is" << Params.getPaperSizeWInPixels() << "x" << Params.getPaperSizeHInPixels();
|
||||
|
||||
QImage inImage;
|
||||
if(!inImage.load(filename))
|
||||
|
@ -248,39 +170,38 @@ try {
|
|||
inImage = inImage.transformed(QMatrix().rotate(270.0));
|
||||
}
|
||||
|
||||
int leftMarginPx = (margins.left()/2540.0)*HwResX;
|
||||
int rightMarginPx = (margins.right()/2540.0)*HwResX;
|
||||
int topMarginPx = (margins.top()/2540.0)*HwResY;
|
||||
int bottomMarginPx = (margins.bottom()/2540.0)*HwResY;
|
||||
int leftMarginPx = (margins.left()/2540.0)*Params.hwResW;
|
||||
int rightMarginPx = (margins.right()/2540.0)*Params.hwResW;
|
||||
int topMarginPx = (margins.top()/2540.0)*Params.hwResH;
|
||||
int bottomMarginPx = (margins.bottom()/2540.0)*Params.hwResH;
|
||||
|
||||
int totalXMarginPx = leftMarginPx+rightMarginPx;
|
||||
int totalYMarginPx = topMarginPx+bottomMarginPx;
|
||||
|
||||
inImage = inImage.scaled(Width-totalXMarginPx, Height-totalYMarginPx,
|
||||
inImage = inImage.scaled(Params.getPaperSizeWInPixels()-totalXMarginPx, Params.getPaperSizeHInPixels()-totalYMarginPx,
|
||||
Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
|
||||
if(pdfOrPostscript)
|
||||
if(imageFormat == "" && (Params.format == PrintParameters::PDF || Params.format == PrintParameters::Postscript))
|
||||
{
|
||||
QTemporaryFile tmpPdfFile;
|
||||
tmpPdfFile.open();
|
||||
QPdfWriter pdfWriter(tmpPdfFile.fileName());
|
||||
pdfWriter.setCreator("SeaPrint " SEAPRINT_VERSION);
|
||||
QPageSize pageSize(size, QPageSize::Millimeter);
|
||||
QPageSize pageSize({Params.getPaperSizeWInPoints(), Params.getPaperSizeHInPoints()}, QPageSize::Point);
|
||||
pdfWriter.setPageSize(pageSize);
|
||||
pdfWriter.setResolution(HwResX);
|
||||
pdfWriter.setResolution(Params.hwResH);
|
||||
QPainter painter(&pdfWriter);
|
||||
int xOffset = ((pdfWriter.width()-totalXMarginPx)-inImage.width())/2 + leftMarginPx;
|
||||
int yOffset = ((pdfWriter.height()-totalYMarginPx)-inImage.height())/2 + topMarginPx;
|
||||
painter.drawImage(xOffset, yOffset, inImage);
|
||||
painter.end();
|
||||
|
||||
convertPdf(tmpPdfFile.fileName(), header, targetFormat, Colors, Quality, PaperSize,
|
||||
HwResX, HwResY, false, false, 0, 0, false, false);
|
||||
convertPdf(tmpPdfFile.fileName(), header, Params);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
QImage outImage = QImage(Width, Height, inImage.format());
|
||||
QImage outImage = QImage(Params.getPaperSizeWInPixels(), Params.getPaperSizeHInPixels(), inImage.format());
|
||||
outImage.fill(Qt::white);
|
||||
QPainter painter(&outImage);
|
||||
int xOffset = ((outImage.width()-totalXMarginPx)-inImage.width())/2 + leftMarginPx;
|
||||
|
@ -302,16 +223,19 @@ try {
|
|||
else
|
||||
{ // We are converting to a raster format
|
||||
|
||||
bool gray = Colors == 0 ? inImage.allGray() : Colors == 1;
|
||||
if(inImage.allGray())
|
||||
{
|
||||
Params.colors = 1; // No need to waste space/bandwidth...
|
||||
}
|
||||
|
||||
outImage.save(&buf, gray ? "pgm" : "ppm");
|
||||
outImage.save(&buf, Params.colors==1 ? "pgm" : "ppm");
|
||||
buf.seek(0);
|
||||
// Skip header - TODO consider reimplementing
|
||||
buf.readLine(255);
|
||||
buf.readLine(255);
|
||||
buf.readLine(255);
|
||||
|
||||
Bytestream inBts(Width*Height*Colors);
|
||||
Bytestream inBts(Params.getPaperSizeWInPixels() * Params.getPaperSizeHInPixels() * Params.colors);
|
||||
|
||||
if((((size_t)buf.size())-buf.pos()) != inBts.size())
|
||||
{
|
||||
|
@ -321,11 +245,11 @@ try {
|
|||
|
||||
buf.read((char*)(inBts.raw()), inBts.size());
|
||||
|
||||
outBts << (urf ? make_urf_file_hdr(1) : make_pwg_file_hdr());
|
||||
outBts << (Params.format == PrintParameters::URF ? make_urf_file_hdr(1) : make_pwg_file_hdr());
|
||||
|
||||
bool verbose = QLoggingCategory::defaultCategory()->isDebugEnabled();
|
||||
|
||||
bmp_to_pwg(inBts, outBts, urf, 1, Colors, Quality, HwResX, HwResY, Width, Height, false, false, PaperSize.toStdString(), false, false, verbose);
|
||||
bmp_to_pwg(inBts, outBts, 1, Params, verbose);
|
||||
}
|
||||
|
||||
CurlRequester cr(_printer->httpUrl());
|
||||
|
@ -346,27 +270,24 @@ catch(const ConvertFailedException& e)
|
|||
}
|
||||
}
|
||||
|
||||
void PrinterWorker::convertOfficeDocument(QString filename, Bytestream header,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip)
|
||||
void PrinterWorker::convertOfficeDocument(QString filename, Bytestream header, PrintParameters Params)
|
||||
{
|
||||
try {
|
||||
|
||||
if(targetFormat == Mimer::URF && (HwResX != HwResY))
|
||||
if(Params.format == PrintParameters::URF && (Params.hwResW != Params.hwResH))
|
||||
{ // URF only supports symmetric resolutions
|
||||
qDebug() << "Unsupported URF resolution" << PaperSize;
|
||||
qDebug() << "Unsupported URF resolution";
|
||||
throw ConvertFailedException(tr("Unsupported resolution (dpi)"));
|
||||
}
|
||||
|
||||
QString ShortPaperSize;
|
||||
if(CalligraPaperSizes.contains(PaperSize))
|
||||
if(CalligraPaperSizes.contains(Params.paperSizeName.c_str()))
|
||||
{
|
||||
ShortPaperSize = CalligraPaperSizes[PaperSize];
|
||||
ShortPaperSize = CalligraPaperSizes[Params.paperSizeName.c_str()];
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Unsupported PDF paper size" << PaperSize;
|
||||
qDebug() << "Unsupported PDF paper size" << Params.paperSizeName.c_str();
|
||||
throw ConvertFailedException(tr("Unsupported PDF paper size"));
|
||||
}
|
||||
|
||||
|
@ -403,30 +324,7 @@ try {
|
|||
|
||||
// qDebug() << CalligraConverter->readAllStandardError();
|
||||
|
||||
quint32 pages = ConvertChecker::instance()->pdfPages(tmpPdfFile.fileName());
|
||||
if (!pages)
|
||||
{
|
||||
qDebug() << "pdfinfo returned 0 pages";
|
||||
throw ConvertFailedException(tr("Failed to get info about PDF file"));
|
||||
}
|
||||
|
||||
if(PageRangeLow==0)
|
||||
{
|
||||
PageRangeLow=1;
|
||||
}
|
||||
|
||||
if(PageRangeHigh==0 || PageRangeHigh > pages)
|
||||
{
|
||||
PageRangeHigh=pages;
|
||||
}
|
||||
|
||||
// Actual number of pages to print
|
||||
pages = PageRangeHigh-PageRangeLow+1;
|
||||
|
||||
qDebug() << "PageRangeLow" << PageRangeLow << "PageRangeHigh" << PageRangeHigh << "pages" << pages;
|
||||
|
||||
convertPdf(tmpPdfFile.fileName(), header, targetFormat, Colors, Quality, PaperSize, HwResX, HwResY, TwoSided, Tumble,
|
||||
PageRangeLow, PageRangeHigh, BackHFlip, BackVFlip);
|
||||
convertPdf(tmpPdfFile.fileName(), header, Params);
|
||||
|
||||
qDebug() << "posted";
|
||||
|
||||
|
@ -437,19 +335,16 @@ catch(const ConvertFailedException& e)
|
|||
}
|
||||
}
|
||||
|
||||
void PrinterWorker::convertPlaintext(QString filename, Bytestream header,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
bool BackHFlip, bool BackVFlip)
|
||||
void PrinterWorker::convertPlaintext(QString filename, Bytestream header, PrintParameters Params)
|
||||
{
|
||||
try {
|
||||
|
||||
if(!PaperSizes.contains(PaperSize))
|
||||
if(!PaperSizes.contains(Params.paperSizeName.c_str()))
|
||||
{
|
||||
qDebug() << "Unsupported paper size" << PaperSize;
|
||||
qDebug() << "Unsupported paper size" << Params.paperSizeName.c_str();
|
||||
throw ConvertFailedException(tr("Unsupported paper size"));
|
||||
}
|
||||
QSizeF size = PaperSizes[PaperSize];
|
||||
QSizeF size = PaperSizes[Params.paperSizeName.c_str()];
|
||||
|
||||
QFile inFile(filename);
|
||||
if(!inFile.open(QIODevice::ReadOnly))
|
||||
|
@ -457,7 +352,7 @@ try {
|
|||
throw ConvertFailedException(tr("Failed to open file"));
|
||||
}
|
||||
|
||||
quint32 resolution = std::min(HwResX, HwResY);
|
||||
quint32 resolution = std::min(Params.hwResW, Params.hwResH);
|
||||
|
||||
QTemporaryFile tmpPdfFile;
|
||||
tmpPdfFile.open();
|
||||
|
@ -578,8 +473,7 @@ try {
|
|||
|
||||
painter.end();
|
||||
|
||||
convertPdf(tmpPdfFile.fileName(), header, targetFormat, Colors, Quality, PaperSize, HwResX, HwResY,
|
||||
TwoSided, Tumble, 0, 0, BackHFlip, BackVFlip);
|
||||
convertPdf(tmpPdfFile.fileName(), header, Params);
|
||||
|
||||
qDebug() << "Finished";
|
||||
qDebug() << "posted";
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define PRINTERWORKER_H
|
||||
#include <QObject>
|
||||
#include "curlrequester.h"
|
||||
#include "ppm2pwg/printparameters.h"
|
||||
|
||||
class IppPrinter;
|
||||
|
||||
|
@ -40,23 +41,13 @@ public slots:
|
|||
|
||||
void fixupJpeg(QString filename, Bytestream header);
|
||||
|
||||
void convertPdf(QString filename, Bytestream header,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip);
|
||||
void convertPdf(QString filename, Bytestream header, PrintParameters Params);
|
||||
|
||||
void convertImage(QString filename, Bytestream header,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, QMargins margins);
|
||||
void convertImage(QString filename, Bytestream header, PrintParameters Params, QString targetFormat, QMargins margins);
|
||||
|
||||
void convertOfficeDocument(QString filename, Bytestream header,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
|
||||
quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip);
|
||||
void convertOfficeDocument(QString filename, Bytestream header, PrintParameters Params);
|
||||
|
||||
void convertPlaintext(QString filename, Bytestream header,
|
||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, bool BackHFlip, bool BackVFlip);
|
||||
void convertPlaintext(QString filename, Bytestream header, PrintParameters Params);
|
||||
|
||||
signals:
|
||||
void progress(qint64 done, qint64 pages);
|
||||
|
|
|
@ -307,6 +307,10 @@
|
|||
<source>Preparing</source>
|
||||
<translation>Vorbereiten</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported paper size</source>
|
||||
<translation>Nicht unterstütztes Papierformat</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>JobsPage</name>
|
||||
|
@ -500,14 +504,6 @@ auf diesem Drucker</translation>
|
|||
<source>Unsupported resolution (dpi)</source>
|
||||
<translation>Nicht unterstützte Auflösung (dpi)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported target format</source>
|
||||
<translation>Nicht unterstützes Zielformat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Failed to get info about PDF file</source>
|
||||
<translation>Informationen über die PDF-Datei können nicht abgerufen werden</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Failed to open file</source>
|
||||
<translation>Öffnen der Datei fehlgeschlagen</translation>
|
||||
|
|
|
@ -307,6 +307,10 @@
|
|||
<source>Preparing</source>
|
||||
<translation>Preparando</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported paper size</source>
|
||||
<translation>Tamaño de papel no soportado</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>JobsPage</name>
|
||||
|
@ -499,14 +503,6 @@
|
|||
<source>Unsupported resolution (dpi)</source>
|
||||
<translation>Resolución (ppp) no soportada</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported target format</source>
|
||||
<translation>Formato de destino no soportado</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Failed to get info about PDF file</source>
|
||||
<translation>Error al obtener info de archivo PDF</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Failed to open file</source>
|
||||
<translation>Error al abrir archivo</translation>
|
||||
|
|
|
@ -307,6 +307,10 @@
|
|||
<source>Preparing</source>
|
||||
<translation>En cours de préparation</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported paper size</source>
|
||||
<translation>Taille de papier non prise en charge</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>JobsPage</name>
|
||||
|
@ -500,14 +504,6 @@ sur cette imprimante</translation>
|
|||
<source>Unsupported resolution (dpi)</source>
|
||||
<translation>Résolution (dpi) non prise en charge</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported target format</source>
|
||||
<translation>Format cible non pris en charge</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Failed to get info about PDF file</source>
|
||||
<translation>Échec de l'obtention d'informations du fichier PDF</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Failed to open file</source>
|
||||
<translation>Échec de l'ouverture du fichier</translation>
|
||||
|
|
|
@ -307,6 +307,10 @@
|
|||
<source>Preparing</source>
|
||||
<translation>Voorbereiden</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported paper size</source>
|
||||
<translation>Niet-ondersteund papierformaat</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>JobsPage</name>
|
||||
|
@ -499,14 +503,6 @@
|
|||
<source>Unsupported resolution (dpi)</source>
|
||||
<translation>Niet-ondersteunde resolutie (dpi)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported target format</source>
|
||||
<translation>Niet-ondersteund doelformaat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Failed to get info about PDF file</source>
|
||||
<translation>Informatie over het PDF-bestand ophalen mislukt</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Failed to open file</source>
|
||||
<translation>Bestand openen mislukt</translation>
|
||||
|
|
|
@ -307,6 +307,10 @@
|
|||
<source>Preparing</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported paper size</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>JobsPage</name>
|
||||
|
@ -479,14 +483,6 @@
|
|||
</context>
|
||||
<context>
|
||||
<name>PrinterWorker</name>
|
||||
<message>
|
||||
<source>Failed to get info about PDF file</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported target format</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported resolution (dpi)</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
|
|
@ -307,6 +307,10 @@
|
|||
<source>Preparing</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported paper size</source>
|
||||
<translation>纸张大小不受支持</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>JobsPage</name>
|
||||
|
@ -499,14 +503,6 @@
|
|||
<source>Unsupported resolution (dpi)</source>
|
||||
<translation>分辨率不受支持(dpi)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported target format</source>
|
||||
<translation>目标格式不受支持</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Failed to get info about PDF file</source>
|
||||
<translation>获取PDF文件信息错误</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Failed to open file</source>
|
||||
<translation>打开文件失败</translation>
|
||||
|
|
Loading…
Reference in a new issue