From b323f2f9bbf6d9bc23bceb0999d5fd918ad55912 Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Wed, 22 Jun 2016 16:34:23 +0200 Subject: [PATCH] Fix PDF export of documents containing both PDFs and tools In some cases, the PDF background of a document could be scaled badly when tools such as the ruler, compass etc. were present on the page. This happened with PDFs of version <= 1.4, and when the tools were outside of / larger than the page. --- src/adaptors/UBExportFullPDF.cpp | 6 +++--- src/domain/UBGraphicsScene.cpp | 15 +++++++++++++++ src/domain/UBGraphicsScene.h | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/adaptors/UBExportFullPDF.cpp b/src/adaptors/UBExportFullPDF.cpp index 2f426a46..6d69aef2 100644 --- a/src/adaptors/UBExportFullPDF.cpp +++ b/src/adaptors/UBExportFullPDF.cpp @@ -182,7 +182,7 @@ bool UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QS { QString pdfName = UBPersistenceManager::objectDirectory + "/" + pdfItem->fileUuid().toString() + ".pdf"; QString backgroundPath = pDocumentProxy->persistencePath() + "/" + pdfName; - QRectF annotationsRect = scene->itemsBoundingRect(); + QRectF annotationsRect = scene->annotationsBoundingRect(); // Original datas double xAnnotation = qRound(annotationsRect.x()); @@ -192,8 +192,8 @@ bool UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QS double hPdf = qRound(pdfItem->sceneBoundingRect().height()); // Exportation-transformed datas - double hScaleFactor = pageSize.width()/scene->itemsBoundingRect().width(); - double vScaleFactor = pageSize.height()/scene->itemsBoundingRect().height(); + double hScaleFactor = pageSize.width()/annotationsRect.width(); + double vScaleFactor = pageSize.height()/annotationsRect.height(); double scaleFactor = qMin(hScaleFactor, vScaleFactor); double xAnnotationsOffset = 0; diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index b38c8936..5181af4a 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1811,6 +1811,21 @@ void UBGraphicsScene::deselectAllItemsExcept(QGraphicsItem* item) } } +/** + * Return the bounding rectangle of all items on the page except for tools (ruler, compass,...) + */ +QRectF UBGraphicsScene::annotationsBoundingRect() const +{ + QRectF boundingRect; + + foreach (QGraphicsItem *item, items()) { + if (!mTools.contains(rootItem(item))) + boundingRect |= item->sceneBoundingRect(); + } + + return boundingRect; +} + bool UBGraphicsScene::isEmpty() const { return mItemCount == 0; diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index f445beef..29966f6d 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -321,6 +321,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void notifyZChanged(QGraphicsItem *item, qreal zValue); void deselectAllItemsExcept(QGraphicsItem* graphicsItem); + QRectF annotationsBoundingRect() const; + public slots: void updateSelectionFrame(); void updateSelectionFrameWrapper(int);