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.
preferencesAboutTextFull
Craig Watson 9 years ago
parent 3995d007a3
commit b323f2f9bb
  1. 6
      src/adaptors/UBExportFullPDF.cpp
  2. 15
      src/domain/UBGraphicsScene.cpp
  3. 2
      src/domain/UBGraphicsScene.h

@ -182,7 +182,7 @@ bool UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QS
{ {
QString pdfName = UBPersistenceManager::objectDirectory + "/" + pdfItem->fileUuid().toString() + ".pdf"; QString pdfName = UBPersistenceManager::objectDirectory + "/" + pdfItem->fileUuid().toString() + ".pdf";
QString backgroundPath = pDocumentProxy->persistencePath() + "/" + pdfName; QString backgroundPath = pDocumentProxy->persistencePath() + "/" + pdfName;
QRectF annotationsRect = scene->itemsBoundingRect(); QRectF annotationsRect = scene->annotationsBoundingRect();
// Original datas // Original datas
double xAnnotation = qRound(annotationsRect.x()); double xAnnotation = qRound(annotationsRect.x());
@ -192,8 +192,8 @@ bool UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QS
double hPdf = qRound(pdfItem->sceneBoundingRect().height()); double hPdf = qRound(pdfItem->sceneBoundingRect().height());
// Exportation-transformed datas // Exportation-transformed datas
double hScaleFactor = pageSize.width()/scene->itemsBoundingRect().width(); double hScaleFactor = pageSize.width()/annotationsRect.width();
double vScaleFactor = pageSize.height()/scene->itemsBoundingRect().height(); double vScaleFactor = pageSize.height()/annotationsRect.height();
double scaleFactor = qMin(hScaleFactor, vScaleFactor); double scaleFactor = qMin(hScaleFactor, vScaleFactor);
double xAnnotationsOffset = 0; 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 bool UBGraphicsScene::isEmpty() const
{ {
return mItemCount == 0; return mItemCount == 0;

@ -321,6 +321,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
void notifyZChanged(QGraphicsItem *item, qreal zValue); void notifyZChanged(QGraphicsItem *item, qreal zValue);
void deselectAllItemsExcept(QGraphicsItem* graphicsItem); void deselectAllItemsExcept(QGraphicsItem* graphicsItem);
QRectF annotationsBoundingRect() const;
public slots: public slots:
void updateSelectionFrame(); void updateSelectionFrame();
void updateSelectionFrameWrapper(int); void updateSelectionFrameWrapper(int);

Loading…
Cancel
Save