|
|
@ -63,9 +63,8 @@ void UBExportPDF::persist(UBDocumentProxy* pDocumentProxy) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, QString filename) |
|
|
|
void UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QString& filename) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//PDF
|
|
|
|
|
|
|
|
QPrinter pdfPrinter; |
|
|
|
QPrinter pdfPrinter; |
|
|
|
|
|
|
|
|
|
|
|
qDebug() << "exporting document to PDF" << filename; |
|
|
|
qDebug() << "exporting document to PDF" << filename; |
|
|
@ -73,19 +72,15 @@ void UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, QString file |
|
|
|
pdfPrinter.setOutputFormat(QPrinter::PdfFormat); |
|
|
|
pdfPrinter.setOutputFormat(QPrinter::PdfFormat); |
|
|
|
pdfPrinter.setResolution(UBSettings::settings()->pdfResolution->get().toInt()); |
|
|
|
pdfPrinter.setResolution(UBSettings::settings()->pdfResolution->get().toInt()); |
|
|
|
pdfPrinter.setOutputFileName(filename); |
|
|
|
pdfPrinter.setOutputFileName(filename); |
|
|
|
|
|
|
|
|
|
|
|
if (UBSettings::settings()->pdfPageFormat->get().toString() == "Letter") |
|
|
|
|
|
|
|
pdfPrinter.setPageSize(QPrinter::Letter); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
pdfPrinter.setPageSize(QPrinter::A4); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// pdfMargin is in mm, but margin should be in px
|
|
|
|
|
|
|
|
qreal margin = UBSettings::settings()->pdfMargin->get().toDouble() * pdfPrinter.resolution() / 25.4; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pdfPrinter.setOrientation(QPrinter::Landscape); |
|
|
|
|
|
|
|
pdfPrinter.setFullPage(true); |
|
|
|
pdfPrinter.setFullPage(true); |
|
|
|
|
|
|
|
|
|
|
|
QPainter pdfPainter(&pdfPrinter); |
|
|
|
//need to calculate screen resolution
|
|
|
|
|
|
|
|
QDesktopWidget* desktop = UBApplication::desktop(); |
|
|
|
|
|
|
|
int dpiCommon = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2; |
|
|
|
|
|
|
|
float scaleFactor = 72.0f / dpiCommon; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPainter pdfPainter; |
|
|
|
|
|
|
|
bool painterNeedsBegin = true; |
|
|
|
|
|
|
|
|
|
|
|
int existingPageCount = pDocumentProxy->pageCount(); |
|
|
|
int existingPageCount = pDocumentProxy->pageCount(); |
|
|
|
|
|
|
|
|
|
|
@ -98,20 +93,20 @@ void UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, QString file |
|
|
|
bool isCrossed = scene->isCrossedBackground(); |
|
|
|
bool isCrossed = scene->isCrossedBackground(); |
|
|
|
scene->setBackground(false, false); |
|
|
|
scene->setBackground(false, false); |
|
|
|
|
|
|
|
|
|
|
|
QRectF paperRect = pdfPrinter.paperRect(); |
|
|
|
QSize pageSize = scene->nominalSize(); |
|
|
|
paperRect = paperRect.adjusted(margin, margin, -margin, -margin); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QRectF normalized = scene->normalizedSceneRect(paperRect.width() / paperRect.height()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set high res rendering
|
|
|
|
// set high res rendering
|
|
|
|
scene->setRenderingQuality(UBItem::RenderingQualityHigh); |
|
|
|
scene->setRenderingQuality(UBItem::RenderingQualityHigh); |
|
|
|
scene->setRenderingContext(UBGraphicsScene::NonScreen); |
|
|
|
scene->setRenderingContext(UBGraphicsScene::NonScreen); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//setting page size to appropriate value
|
|
|
|
|
|
|
|
pdfPrinter.setPaperSize(QSizeF(pageSize.width()*scaleFactor, pageSize.height()*scaleFactor), QPrinter::Point); |
|
|
|
|
|
|
|
pdfPrinter.setOrientation((pageSize.width() > pageSize.height())? QPrinter::Landscape : QPrinter::Portrait); |
|
|
|
|
|
|
|
if(painterNeedsBegin) painterNeedsBegin = !pdfPainter.begin(&pdfPrinter); |
|
|
|
//render to PDF
|
|
|
|
//render to PDF
|
|
|
|
scene->render(&pdfPainter, paperRect, normalized); |
|
|
|
scene->render(&pdfPainter); |
|
|
|
|
|
|
|
|
|
|
|
if (pageIndex < existingPageCount - 1) |
|
|
|
if (pageIndex < existingPageCount - 1) pdfPrinter.newPage(); |
|
|
|
pdfPrinter.newPage(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//restore screen rendering quality
|
|
|
|
//restore screen rendering quality
|
|
|
|
scene->setRenderingContext(UBGraphicsScene::Screen); |
|
|
|
scene->setRenderingContext(UBGraphicsScene::Screen); |
|
|
@ -120,6 +115,7 @@ void UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, QString file |
|
|
|
//restore background state
|
|
|
|
//restore background state
|
|
|
|
scene->setBackground(isDark, isCrossed); |
|
|
|
scene->setBackground(isDark, isCrossed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(!painterNeedsBegin) pdfPainter.end(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QString UBExportPDF::exportExtention() |
|
|
|
QString UBExportPDF::exportExtention() |
|
|
|