Use PrintParameters for conversion settings

This commit is contained in:
Anton Thomasson 2022-03-19 17:31:55 +01:00
parent e16bfbe7c6
commit 09ceb4f0ec
13 changed files with 125 additions and 253 deletions

View file

@ -91,6 +91,7 @@ HEADERS += \
ppm2pwg/pdf2printable.h \ ppm2pwg/pdf2printable.h \
ppm2pwg/baselinify.h \ ppm2pwg/baselinify.h \
ppm2pwg/madness.h \ ppm2pwg/madness.h \
ppm2pwg/printparameters.h \
ppm2pwg/PwgPgHdr.h \ ppm2pwg/PwgPgHdr.h \
ppm2pwg/PwgPgHdr.codable \ ppm2pwg/PwgPgHdr.codable \
ppm2pwg/UrfPgHdr.h \ ppm2pwg/UrfPgHdr.h \

@ -1 +1 @@
Subproject commit 4844ff3ce2b773ae43585039aae146b6d225e0a6 Subproject commit 7db7a12a8dbf8659050601888a6a48a38404f543

View file

@ -10,6 +10,7 @@
Q_DECLARE_METATYPE(CURLcode) Q_DECLARE_METATYPE(CURLcode)
Q_DECLARE_METATYPE(Bytestream) Q_DECLARE_METATYPE(Bytestream)
Q_DECLARE_METATYPE(PrintParameters)
template <class T> template <class T>
static QObject* singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) static QObject* singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
@ -26,6 +27,7 @@ int main(int argc, char *argv[])
{ {
qRegisterMetaType<CURLcode>(); qRegisterMetaType<CURLcode>();
qRegisterMetaType<Bytestream>(); qRegisterMetaType<Bytestream>();
qRegisterMetaType<PrintParameters>();
// Turn on/off logging according to setting // Turn on/off logging according to setting
QLoggingCategory::defaultCategory()->setEnabled(QtMsgType::QtDebugMsg, Settings::instance()->debugLog()); QLoggingCategory::defaultCategory()->setEnabled(QtMsgType::QtDebugMsg, Settings::instance()->debugLog());

View file

@ -517,6 +517,7 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
_progress = ""; _progress = "";
emit progressChanged(); emit progressChanged();
PrintParameters Params;
QFileInfo fileinfo(filename); QFileInfo fileinfo(filename);
if(!fileinfo.exists()) if(!fileinfo.exists())
@ -542,8 +543,8 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
QString PaperSize = getAttrOrDefault(jobAttrs, "media").toString(); QString PaperSize = getAttrOrDefault(jobAttrs, "media").toString();
QString documentFormat = getAttrOrDefault(jobAttrs, "document-format").toString(); QString targetFormat = getAttrOrDefault(jobAttrs, "document-format").toString();
qDebug() << "target format:" << documentFormat; qDebug() << "target format:" << targetFormat;
QMargins margins(getAttrOrDefault(jobAttrs, "media-left-margin", "media-col").toInt(), QMargins margins(getAttrOrDefault(jobAttrs, "media-left-margin", "media-col").toInt(),
getAttrOrDefault(jobAttrs, "media-top-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()); getAttrOrDefault(jobAttrs, "media-bottom-margin", "media-col").toInt());
// Only keep margin setting for JPEG - but only attemt to remove it if media-col exists // 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 MediaCol = jobAttrs["media-col"].toObject();
QJsonObject MediaColValue = MediaCol["value"].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 // 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"); jobAttrs.remove("document-format");
documentFormat = targetFormatIfAuto(documentFormat, mimeType, supportedMimeTypes); targetFormat = targetFormatIfAuto(targetFormat, mimeType, supportedMimeTypes);
qDebug() << "adjusted target format:" << documentFormat; qDebug() << "adjusted target format:" << targetFormat;
if(documentFormat == "" || documentFormat == Mimer::OctetStream) if(targetFormat == "" || targetFormat == Mimer::OctetStream)
{ {
emit convertFailed(tr("Unknown document format")); emit convertFailed(tr("Unknown document format"));
return; 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; qDebug() << "Printing job" << o << jobAttrs;
QJsonValue PrinterResolutionRef = getAttrOrDefault(jobAttrs, "printer-resolution"); QJsonValue PrinterResolutionRef = getAttrOrDefault(jobAttrs, "printer-resolution");
@ -623,22 +651,20 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
bool BackHFlip = false; bool BackHFlip = false;
bool BackVFlip = 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(); 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")) if(jobAttrs.contains("page-ranges"))
{ {
QJsonObject PageRanges = getAttrOrDefault(jobAttrs, "page-ranges").toObject(); QJsonObject PageRanges = getAttrOrDefault(jobAttrs, "page-ranges").toObject();
PageRangeLow = PageRanges["low"].toInt(); Params.fromPage = PageRanges["low"].toInt();
PageRangeHigh = PageRanges["high"].toInt(); Params.toPage = PageRanges["high"].toInt();
// Effected locally, unless it is Postscript which we cant't render // Effected locally, unless it is Postscript which we cant't render
if(documentFormat != Mimer::Postscript) if(targetFormat != Mimer::Postscript)
{ {
jobAttrs.remove("page-ranges"); jobAttrs.remove("page-ranges");
} }
@ -652,11 +678,11 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
setBusyMessage(tr("Preparing")); setBusyMessage(tr("Preparing"));
if((mimeType == documentFormat) && (documentFormat == Mimer::Postscript)) if((mimeType == targetFormat) && (targetFormat == Mimer::Postscript))
{ // Can't process Postscript { // Can't process Postscript
emit doJustUpload(filename, contents); 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 { // Just make the jpeg baseline-encoded, don't resize locally
emit doFixupJpeg(filename, contents); emit doFixupJpeg(filename, contents);
} }
@ -672,41 +698,33 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
return; return;
} }
bool TwoSided = false;
bool Tumble = false;
QString Sides = getAttrOrDefault(jobAttrs, "sides").toString(); QString Sides = getAttrOrDefault(jobAttrs, "sides").toString();
if(Sides=="two-sided-long-edge") if(Sides=="two-sided-long-edge")
{ {
TwoSided = true; Params.duplex = true;
} }
else if(Sides=="two-sided-short-edge") else if(Sides=="two-sided-short-edge")
{ {
TwoSided = true; Params.duplex = true;
Tumble = true; Params.tumble = true;
} }
if(mimeType == Mimer::PDF) if(mimeType == Mimer::PDF)
{ {
emit doConvertPdf(filename, contents, documentFormat, Colors, Quality, emit doConvertPdf(filename, contents, Params);
PaperSize, HwResX, HwResY, TwoSided, Tumble, PageRangeLow, PageRangeHigh,
BackHFlip, BackVFlip);
} }
else if(mimeType == Mimer::Plaintext) else if(mimeType == Mimer::Plaintext)
{ {
emit doConvertPlaintext(filename, contents, documentFormat, Colors, Quality, emit doConvertPlaintext(filename, contents, Params);
PaperSize, HwResX, HwResY, TwoSided, Tumble, BackHFlip, BackVFlip);
} }
else if (Mimer::isImage(mimeType)) else if (Mimer::isImage(mimeType))
{ {
emit doConvertImage(filename, contents, documentFormat, Colors, Quality, emit doConvertImage(filename, contents, Params, targetFormat, margins);
PaperSize, HwResX, HwResY, margins);
} }
else if(Mimer::isOffice(mimeType)) else if(Mimer::isOffice(mimeType))
{ {
emit doConvertOfficeDocument(filename, contents, documentFormat, Colors, Quality, emit doConvertOfficeDocument(filename, contents, Params);
PaperSize, HwResX, HwResY, TwoSided, Tumble, PageRangeLow, PageRangeHigh,
BackHFlip, BackVFlip);
} }
else else
{ {

View file

@ -61,23 +61,13 @@ signals:
void doJustUpload(QString filename, Bytestream header); void doJustUpload(QString filename, Bytestream header);
void doFixupJpeg(QString filename, Bytestream header); void doFixupJpeg(QString filename, Bytestream header);
void doConvertPdf(QString filename, Bytestream header, void doConvertPdf(QString filename, Bytestream header, PrintParameters Params);
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 doConvertImage(QString filename, Bytestream header, void doConvertImage(QString filename, Bytestream header, PrintParameters Params, QString targetFormat, QMargins margins);
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, QMargins margins);
void doConvertOfficeDocument(QString filename, Bytestream header, void doConvertOfficeDocument(QString filename, Bytestream header, PrintParameters Params);
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 doConvertPlaintext(QString filename, Bytestream header, void doConvertPlaintext(QString filename, Bytestream header, PrintParameters Params);
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, bool BackHFlip, bool BackVFlip);
void doGetStrings(QUrl url); void doGetStrings(QUrl url);
void doGetImage(QUrl url); void doGetImage(QUrl url);

View file

@ -101,42 +101,9 @@ catch(const ConvertFailedException& e)
} }
} }
void PrinterWorker::convertPdf(QString filename, Bytestream header, void PrinterWorker::convertPdf(QString filename, Bytestream header, PrintParameters Params)
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip)
{ {
try { 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()); CurlRequester cr(_printer->httpUrl());
connect(&cr, &CurlRequester::done, _printer, &IppPrinter::printRequestFinished); connect(&cr, &CurlRequester::done, _printer, &IppPrinter::printRequestFinished);
@ -154,19 +121,9 @@ try {
emit progress(page, total); 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(); bool verbose = QLoggingCategory::defaultCategory()->isDebugEnabled();
int res = pdf_to_printable(filename.toStdString(), WriteFun, Colors, Quality, PaperSize.toStdString(), Width, Height, HwResX, HwResY, int res = pdf_to_printable(filename.toStdString(), WriteFun, Params, ProgressFun, verbose);
format, TwoSided, Tumble, BackHFlip, BackVFlip, PageRangeLow, PageRangeHigh, ProgressFun, verbose);
if(res != 0) if(res != 0)
{ {
@ -181,60 +138,25 @@ catch(const ConvertFailedException& e)
} }
} }
void PrinterWorker::convertImage(QString filename, Bytestream header, void PrinterWorker::convertImage(QString filename, Bytestream header, PrintParameters Params, QString targetFormat, QMargins margins)
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, QMargins margins)
{ {
try { try {
bool urf = false;
bool pdfOrPostscript = false;
QString imageFormat = ""; QString imageFormat = "";
QStringList supportedImageFormats = {Mimer::JPEG, Mimer::PNG}; QStringList supportedImageFormats = {Mimer::JPEG, Mimer::PNG};
if(targetFormat == Mimer::URF) if(supportedImageFormats.contains(targetFormat))
{
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))
{ {
imageFormat = targetFormat.split("/")[1]; imageFormat = targetFormat.split("/")[1];
} }
else
{
throw ConvertFailedException(tr("Unsupported target format"));
}
if(Colors == 0) if(Params.format == PrintParameters::URF && (Params.hwResW != Params.hwResH))
{
Colors = 3;
}
if(urf && (HwResX != HwResY))
{ // URF only supports symmetric resolutions { // URF only supports symmetric resolutions
qDebug() << "Unsupported URF resolution" << PaperSize; qDebug() << "Unsupported URF resolution";
throw ConvertFailedException(tr("Unsupported resolution (dpi)")); throw ConvertFailedException(tr("Unsupported resolution (dpi)"));
} }
if(!PaperSizes.contains(PaperSize)) qDebug() << "Size is" << Params.getPaperSizeWInPixels() << "x" << Params.getPaperSizeHInPixels();
{
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;
QImage inImage; QImage inImage;
if(!inImage.load(filename)) if(!inImage.load(filename))
@ -248,39 +170,38 @@ try {
inImage = inImage.transformed(QMatrix().rotate(270.0)); inImage = inImage.transformed(QMatrix().rotate(270.0));
} }
int leftMarginPx = (margins.left()/2540.0)*HwResX; int leftMarginPx = (margins.left()/2540.0)*Params.hwResW;
int rightMarginPx = (margins.right()/2540.0)*HwResX; int rightMarginPx = (margins.right()/2540.0)*Params.hwResW;
int topMarginPx = (margins.top()/2540.0)*HwResY; int topMarginPx = (margins.top()/2540.0)*Params.hwResH;
int bottomMarginPx = (margins.bottom()/2540.0)*HwResY; int bottomMarginPx = (margins.bottom()/2540.0)*Params.hwResH;
int totalXMarginPx = leftMarginPx+rightMarginPx; int totalXMarginPx = leftMarginPx+rightMarginPx;
int totalYMarginPx = topMarginPx+bottomMarginPx; int totalYMarginPx = topMarginPx+bottomMarginPx;
inImage = inImage.scaled(Width-totalXMarginPx, Height-totalYMarginPx, inImage = inImage.scaled(Params.getPaperSizeWInPixels()-totalXMarginPx, Params.getPaperSizeHInPixels()-totalYMarginPx,
Qt::KeepAspectRatio, Qt::SmoothTransformation); Qt::KeepAspectRatio, Qt::SmoothTransformation);
if(pdfOrPostscript) if(imageFormat == "" && (Params.format == PrintParameters::PDF || Params.format == PrintParameters::Postscript))
{ {
QTemporaryFile tmpPdfFile; QTemporaryFile tmpPdfFile;
tmpPdfFile.open(); tmpPdfFile.open();
QPdfWriter pdfWriter(tmpPdfFile.fileName()); QPdfWriter pdfWriter(tmpPdfFile.fileName());
pdfWriter.setCreator("SeaPrint " SEAPRINT_VERSION); pdfWriter.setCreator("SeaPrint " SEAPRINT_VERSION);
QPageSize pageSize(size, QPageSize::Millimeter); QPageSize pageSize({Params.getPaperSizeWInPoints(), Params.getPaperSizeHInPoints()}, QPageSize::Point);
pdfWriter.setPageSize(pageSize); pdfWriter.setPageSize(pageSize);
pdfWriter.setResolution(HwResX); pdfWriter.setResolution(Params.hwResH);
QPainter painter(&pdfWriter); QPainter painter(&pdfWriter);
int xOffset = ((pdfWriter.width()-totalXMarginPx)-inImage.width())/2 + leftMarginPx; int xOffset = ((pdfWriter.width()-totalXMarginPx)-inImage.width())/2 + leftMarginPx;
int yOffset = ((pdfWriter.height()-totalYMarginPx)-inImage.height())/2 + topMarginPx; int yOffset = ((pdfWriter.height()-totalYMarginPx)-inImage.height())/2 + topMarginPx;
painter.drawImage(xOffset, yOffset, inImage); painter.drawImage(xOffset, yOffset, inImage);
painter.end(); painter.end();
convertPdf(tmpPdfFile.fileName(), header, targetFormat, Colors, Quality, PaperSize, convertPdf(tmpPdfFile.fileName(), header, Params);
HwResX, HwResY, false, false, 0, 0, false, false);
} }
else else
{ {
QImage outImage = QImage(Width, Height, inImage.format()); QImage outImage = QImage(Params.getPaperSizeWInPixels(), Params.getPaperSizeHInPixels(), inImage.format());
outImage.fill(Qt::white); outImage.fill(Qt::white);
QPainter painter(&outImage); QPainter painter(&outImage);
int xOffset = ((outImage.width()-totalXMarginPx)-inImage.width())/2 + leftMarginPx; int xOffset = ((outImage.width()-totalXMarginPx)-inImage.width())/2 + leftMarginPx;
@ -302,16 +223,19 @@ try {
else else
{ // We are converting to a raster format { // 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); buf.seek(0);
// Skip header - TODO consider reimplementing // Skip header - TODO consider reimplementing
buf.readLine(255); buf.readLine(255);
buf.readLine(255); 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()) if((((size_t)buf.size())-buf.pos()) != inBts.size())
{ {
@ -321,11 +245,11 @@ try {
buf.read((char*)(inBts.raw()), inBts.size()); 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(); 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()); CurlRequester cr(_printer->httpUrl());
@ -346,27 +270,24 @@ catch(const ConvertFailedException& e)
} }
} }
void PrinterWorker::convertOfficeDocument(QString filename, Bytestream header, void PrinterWorker::convertOfficeDocument(QString filename, Bytestream header, PrintParameters Params)
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
quint32 PageRangeLow, quint32 PageRangeHigh, bool BackHFlip, bool BackVFlip)
{ {
try { try {
if(targetFormat == Mimer::URF && (HwResX != HwResY)) if(Params.format == PrintParameters::URF && (Params.hwResW != Params.hwResH))
{ // URF only supports symmetric resolutions { // URF only supports symmetric resolutions
qDebug() << "Unsupported URF resolution" << PaperSize; qDebug() << "Unsupported URF resolution";
throw ConvertFailedException(tr("Unsupported resolution (dpi)")); throw ConvertFailedException(tr("Unsupported resolution (dpi)"));
} }
QString ShortPaperSize; QString ShortPaperSize;
if(CalligraPaperSizes.contains(PaperSize)) if(CalligraPaperSizes.contains(Params.paperSizeName.c_str()))
{ {
ShortPaperSize = CalligraPaperSizes[PaperSize]; ShortPaperSize = CalligraPaperSizes[Params.paperSizeName.c_str()];
} }
else else
{ {
qDebug() << "Unsupported PDF paper size" << PaperSize; qDebug() << "Unsupported PDF paper size" << Params.paperSizeName.c_str();
throw ConvertFailedException(tr("Unsupported PDF paper size")); throw ConvertFailedException(tr("Unsupported PDF paper size"));
} }
@ -403,30 +324,7 @@ try {
// qDebug() << CalligraConverter->readAllStandardError(); // qDebug() << CalligraConverter->readAllStandardError();
quint32 pages = ConvertChecker::instance()->pdfPages(tmpPdfFile.fileName()); convertPdf(tmpPdfFile.fileName(), header, Params);
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);
qDebug() << "posted"; qDebug() << "posted";
@ -437,19 +335,16 @@ catch(const ConvertFailedException& e)
} }
} }
void PrinterWorker::convertPlaintext(QString filename, Bytestream header, void PrinterWorker::convertPlaintext(QString filename, Bytestream header, PrintParameters Params)
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble,
bool BackHFlip, bool BackVFlip)
{ {
try { 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")); throw ConvertFailedException(tr("Unsupported paper size"));
} }
QSizeF size = PaperSizes[PaperSize]; QSizeF size = PaperSizes[Params.paperSizeName.c_str()];
QFile inFile(filename); QFile inFile(filename);
if(!inFile.open(QIODevice::ReadOnly)) if(!inFile.open(QIODevice::ReadOnly))
@ -457,7 +352,7 @@ try {
throw ConvertFailedException(tr("Failed to open file")); throw ConvertFailedException(tr("Failed to open file"));
} }
quint32 resolution = std::min(HwResX, HwResY); quint32 resolution = std::min(Params.hwResW, Params.hwResH);
QTemporaryFile tmpPdfFile; QTemporaryFile tmpPdfFile;
tmpPdfFile.open(); tmpPdfFile.open();
@ -578,8 +473,7 @@ try {
painter.end(); painter.end();
convertPdf(tmpPdfFile.fileName(), header, targetFormat, Colors, Quality, PaperSize, HwResX, HwResY, convertPdf(tmpPdfFile.fileName(), header, Params);
TwoSided, Tumble, 0, 0, BackHFlip, BackVFlip);
qDebug() << "Finished"; qDebug() << "Finished";
qDebug() << "posted"; qDebug() << "posted";

View file

@ -2,6 +2,7 @@
#define PRINTERWORKER_H #define PRINTERWORKER_H
#include <QObject> #include <QObject>
#include "curlrequester.h" #include "curlrequester.h"
#include "ppm2pwg/printparameters.h"
class IppPrinter; class IppPrinter;
@ -40,23 +41,13 @@ public slots:
void fixupJpeg(QString filename, Bytestream header); void fixupJpeg(QString filename, Bytestream header);
void convertPdf(QString filename, Bytestream header, void convertPdf(QString filename, Bytestream header, PrintParameters Params);
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 convertImage(QString filename, Bytestream header, void convertImage(QString filename, Bytestream header, PrintParameters Params, QString targetFormat, QMargins margins);
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, QMargins margins);
void convertOfficeDocument(QString filename, Bytestream header, void convertOfficeDocument(QString filename, Bytestream header, PrintParameters Params);
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 convertPlaintext(QString filename, Bytestream header, void convertPlaintext(QString filename, Bytestream header, PrintParameters Params);
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, bool BackHFlip, bool BackVFlip);
signals: signals:
void progress(qint64 done, qint64 pages); void progress(qint64 done, qint64 pages);

View file

@ -307,6 +307,10 @@
<source>Preparing</source> <source>Preparing</source>
<translation>Vorbereiten</translation> <translation>Vorbereiten</translation>
</message> </message>
<message>
<source>Unsupported paper size</source>
<translation>Nicht unterstütztes Papierformat</translation>
</message>
</context> </context>
<context> <context>
<name>JobsPage</name> <name>JobsPage</name>
@ -500,14 +504,6 @@ auf diesem Drucker</translation>
<source>Unsupported resolution (dpi)</source> <source>Unsupported resolution (dpi)</source>
<translation>Nicht unterstützte Auflösung (dpi)</translation> <translation>Nicht unterstützte Auflösung (dpi)</translation>
</message> </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> <message>
<source>Failed to open file</source> <source>Failed to open file</source>
<translation>Öffnen der Datei fehlgeschlagen</translation> <translation>Öffnen der Datei fehlgeschlagen</translation>

View file

@ -307,6 +307,10 @@
<source>Preparing</source> <source>Preparing</source>
<translation>Preparando</translation> <translation>Preparando</translation>
</message> </message>
<message>
<source>Unsupported paper size</source>
<translation>Tamaño de papel no soportado</translation>
</message>
</context> </context>
<context> <context>
<name>JobsPage</name> <name>JobsPage</name>
@ -499,14 +503,6 @@
<source>Unsupported resolution (dpi)</source> <source>Unsupported resolution (dpi)</source>
<translation>Resolución (ppp) no soportada</translation> <translation>Resolución (ppp) no soportada</translation>
</message> </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> <message>
<source>Failed to open file</source> <source>Failed to open file</source>
<translation>Error al abrir archivo</translation> <translation>Error al abrir archivo</translation>

View file

@ -307,6 +307,10 @@
<source>Preparing</source> <source>Preparing</source>
<translation>En cours de préparation</translation> <translation>En cours de préparation</translation>
</message> </message>
<message>
<source>Unsupported paper size</source>
<translation>Taille de papier non prise en charge</translation>
</message>
</context> </context>
<context> <context>
<name>JobsPage</name> <name>JobsPage</name>
@ -500,14 +504,6 @@ sur cette imprimante</translation>
<source>Unsupported resolution (dpi)</source> <source>Unsupported resolution (dpi)</source>
<translation>Résolution (dpi) non prise en charge</translation> <translation>Résolution (dpi) non prise en charge</translation>
</message> </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&apos;obtention d&apos;informations du fichier PDF</translation>
</message>
<message> <message>
<source>Failed to open file</source> <source>Failed to open file</source>
<translation>Échec de l&apos;ouverture du fichier</translation> <translation>Échec de l&apos;ouverture du fichier</translation>

View file

@ -307,6 +307,10 @@
<source>Preparing</source> <source>Preparing</source>
<translation>Voorbereiden</translation> <translation>Voorbereiden</translation>
</message> </message>
<message>
<source>Unsupported paper size</source>
<translation>Niet-ondersteund papierformaat</translation>
</message>
</context> </context>
<context> <context>
<name>JobsPage</name> <name>JobsPage</name>
@ -499,14 +503,6 @@
<source>Unsupported resolution (dpi)</source> <source>Unsupported resolution (dpi)</source>
<translation>Niet-ondersteunde resolutie (dpi)</translation> <translation>Niet-ondersteunde resolutie (dpi)</translation>
</message> </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> <message>
<source>Failed to open file</source> <source>Failed to open file</source>
<translation>Bestand openen mislukt</translation> <translation>Bestand openen mislukt</translation>

View file

@ -307,6 +307,10 @@
<source>Preparing</source> <source>Preparing</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Unsupported paper size</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>JobsPage</name> <name>JobsPage</name>
@ -479,14 +483,6 @@
</context> </context>
<context> <context>
<name>PrinterWorker</name> <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> <message>
<source>Unsupported resolution (dpi)</source> <source>Unsupported resolution (dpi)</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>

View file

@ -307,6 +307,10 @@
<source>Preparing</source> <source>Preparing</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Unsupported paper size</source>
<translation></translation>
</message>
</context> </context>
<context> <context>
<name>JobsPage</name> <name>JobsPage</name>
@ -499,14 +503,6 @@
<source>Unsupported resolution (dpi)</source> <source>Unsupported resolution (dpi)</source>
<translation>dpi</translation> <translation>dpi</translation>
</message> </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> <message>
<source>Failed to open file</source> <source>Failed to open file</source>
<translation></translation> <translation></translation>