diff --git a/src/adaptors/UBExportFullPDF.cpp b/src/adaptors/UBExportFullPDF.cpp index 6d69aef2..64b989a0 100644 --- a/src/adaptors/UBExportFullPDF.cpp +++ b/src/adaptors/UBExportFullPDF.cpp @@ -210,9 +210,7 @@ bool UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QS // If the PDF was scaled when added to the scene (e.g if it was loaded from a document with a different DPI // than the current one), it should also be scaled here. - qreal currentDpi = (UBApplication::desktop()->physicalDpiX() + UBApplication::desktop()->physicalDpiY()) / 2; - qreal documentDpi = pDocumentProxy->pageDpi(); - qreal pdfScale = documentDpi != 0 ? documentDpi/currentDpi : 1; + qreal pdfScale = pdfItem->scale(); TransformationDescription pdfTransform(xPdfOffset, yPdfOffset, scaleFactor * pdfScale, 0); TransformationDescription annotationTransform(xAnnotationsOffset, yAnnotationsOffset, 1, 0); diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 9e0cbd92..e44eba15 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -354,6 +354,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene(UBDocumentProx time.start(); mScene = 0; UBGraphicsWidgetItem *currentWidget = 0; + bool pageDpiSpecified = true; mFileVersion = 40100; // default to 4.1.0 @@ -436,8 +437,11 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene(UBDocumentProx if (!pageDpi.isNull()) proxy->setPageDpi(pageDpi.toInt()); - else + + else if (proxy->pageDpi() == 0) { proxy->setPageDpi((UBApplication::desktop()->physicalDpiX() + UBApplication::desktop()->physicalDpiY())/2); + pageDpiSpecified = false; + } bool darkBackground = false; bool crossedBackground = false; @@ -768,9 +772,22 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene(UBDocumentProx { QDesktopWidget* desktop = UBApplication::desktop(); qreal currentDpi = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2; - qDebug() << "currentDpi (" << desktop->physicalDpiX() << " + " << desktop->physicalDpiY() << ")/2 = " << currentDpi; + // qDebug() << "currentDpi (" << desktop->physicalDpiX() << " + " << desktop->physicalDpiY() << ")/2 = " << currentDpi; qreal pdfScale = qreal(proxy->pageDpi())/currentDpi; - qDebug() << "pdfScale " << pdfScale; + // qDebug() << "pdfScale " << pdfScale; + + // If the PDF is in the background, it occupies the whole page; so we can simply + // use that information to calculate its scale. + if (isBackground) { + qreal pageWidth = mScene->nominalSize().width(); + qreal pageHeight = mScene->nominalSize().height(); + + qreal scaleX = pageWidth / pdfItem->sceneBoundingRect().width(); + qreal scaleY = pageHeight / pdfItem->sceneBoundingRect().height(); + + pdfScale = (scaleX+scaleY)/2.; + } + pdfItem->setScale(pdfScale); pdfItem->setFlag(QGraphicsItem::ItemIsMovable, true); pdfItem->setFlag(QGraphicsItem::ItemIsSelectable, true);