Fixes to import and export of files containing PDFs

The scale of PDF items was sometimes badly calculated when opening a
document made with a previous version of OpenBoard or made on another
computer.

Specifically, this solves the following issues:

- PDF scale calculation in documents that did not specify the pageDPI
used to render the PDF (happened with documents created with some old
versions of OpenBoard)

- PDF scale calculation in multi-page documents (it was set correctly
for the first page, but not the following ones)
preferencesAboutTextFull
Craig Watson 9 years ago
parent b323f2f9bb
commit 3abf154dfd
  1. 4
      src/adaptors/UBExportFullPDF.cpp
  2. 23
      src/adaptors/UBSvgSubsetAdaptor.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);

@ -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);

Loading…
Cancel
Save