Commit b323f2f9 authored by Craig Watson's avatar Craig Watson

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.
parent 3995d007
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment