Merge branch 'master' of github.com:Sankore/Sankore-3.1

preferencesAboutTextFull
Claudio Valerio 13 years ago
commit 6d18c193bd
  1. 36
      src/adaptors/UBExportPDF.cpp
  2. 2
      src/adaptors/UBExportPDF.h

@ -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);
pdfPrinter.setFullPage(true);
if (UBSettings::settings()->pdfPageFormat->get().toString() == "Letter") //need to calculate screen resolution
pdfPrinter.setPageSize(QPrinter::Letter); QDesktopWidget* desktop = UBApplication::desktop();
else int dpiCommon = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2;
pdfPrinter.setPageSize(QPrinter::A4); float scaleFactor = 72.0f / dpiCommon;
// pdfMargin is in mm, but margin should be in px QPainter pdfPainter;
qreal margin = UBSettings::settings()->pdfMargin->get().toDouble() * pdfPrinter.resolution() / 25.4; bool painterNeedsBegin = true;
pdfPrinter.setOrientation(QPrinter::Landscape);
pdfPrinter.setFullPage(true);
QPainter pdfPainter(&pdfPrinter);
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()

@ -33,7 +33,7 @@ class UBExportPDF : public UBExportAdaptor
virtual QString exportExtention(); virtual QString exportExtention();
virtual void persist(UBDocumentProxy* pDocument); virtual void persist(UBDocumentProxy* pDocument);
static void persistsDocument(UBDocumentProxy* pDocument, QString filename); static void persistsDocument(UBDocumentProxy* pDocument, const QString& filename);
}; };
#endif /* UBEXPORTPDF_H_ */ #endif /* UBEXPORTPDF_H_ */

Loading…
Cancel
Save