Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions resources/etc/OpenBoard.config
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,12 @@ VideosDirectory=./library/videos
RefreshRateInFramePerSecond=2

[PDF]
enableQualityLossToIncreaseZoomPerfs=true
ExportBackgroundGrid=false
ExportBackgroundColor=false
Margin=20
PageFormat=A4
Resolution=300
UsePDFMerger=true
ZoomBehavior=4

[Podcast]
AudioRecordingDevice=Default
Expand Down
10 changes: 0 additions & 10 deletions resources/forms/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,6 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="enableQualityLossToIncreaseZoomPerfs">
<property name="text">
<string>Improve zoom execution time (can slightly affect rendering quality)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="exportBackgroundColor">
<property name="text">
Expand Down
16 changes: 0 additions & 16 deletions src/core/UBPreferencesController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ void UBPreferencesController::wire()
connect(mPreferencesUI->useSystemOSKCheckBox, SIGNAL(clicked(bool)), this, SLOT(systemOSKCheckBoxToggled(bool)));

// PDF preferences
connect(mPreferencesUI->enableQualityLossToIncreaseZoomPerfs, SIGNAL(clicked(bool)), settings->enableQualityLossToIncreaseZoomPerfs, SLOT(setBool(bool)));
connect(mPreferencesUI->enableQualityLossToIncreaseZoomPerfs, SIGNAL(clicked(bool)), this, SLOT(setPdfZoomBehavior(bool)));
connect(mPreferencesUI->exportBackgroundGrid, SIGNAL(clicked(bool)), settings->exportBackgroundGrid, SLOT(setBool(bool)));
connect(mPreferencesUI->exportBackgroundColor, SIGNAL(clicked(bool)), settings->exportBackgroundColor, SLOT(setBool(bool)));

Expand Down Expand Up @@ -317,7 +315,6 @@ void UBPreferencesController::init()
mPreferencesUI->useSystemOSKCheckBox->setChecked(settings->useSystemOnScreenKeyboard->get().toBool());
this->systemOSKCheckBoxToggled(mPreferencesUI->useSystemOSKCheckBox->isChecked());

mPreferencesUI->enableQualityLossToIncreaseZoomPerfs->setChecked(settings->enableQualityLossToIncreaseZoomPerfs->get().toBool());
mPreferencesUI->exportBackgroundGrid->setChecked(settings->exportBackgroundGrid->get().toBool());
mPreferencesUI->exportBackgroundColor->setChecked(settings->exportBackgroundColor->get().toBool());

Expand Down Expand Up @@ -395,7 +392,6 @@ void UBPreferencesController::defaultSettings()
mPreferencesUI->showDateColumnOnAlphabeticalSort->setChecked(settings->showDateColumnOnAlphabeticalSort->reset().toBool());
UBApplication::documentController->refreshDateColumns();

mPreferencesUI->enableQualityLossToIncreaseZoomPerfs->setChecked(settings->enableQualityLossToIncreaseZoomPerfs->reset().toBool());
mPreferencesUI->exportBackgroundGrid->setChecked(settings->exportBackgroundGrid->reset().toBool());
mPreferencesUI->exportBackgroundColor->setChecked(settings->exportBackgroundColor->reset().toBool());

Expand Down Expand Up @@ -700,18 +696,6 @@ void UBPreferencesController::systemOSKCheckBoxToggled(bool checked)
mPreferencesUI->keyboardPaletteKeyButtonSize_Label->setVisible(!checked);
}

void UBPreferencesController::setPdfZoomBehavior(bool checked)
{
if (checked)
{
UBSettings::settings()->pdfZoomBehavior->setInt(4);// Multithreaded, several steps, downsampled.
}
else
{
UBSettings::settings()->pdfZoomBehavior->setInt(0);//Old behavior. To remove if no issues found with the other mode
}
}

UBBrushPropertiesFrame::UBBrushPropertiesFrame(QFrame* owner, const QList<QColor>& lightBackgroundColors,
const QList<QColor>& darkBackgroundColors, const QList<QColor>& lightBackgroundSelectedColors,
const QList<QColor>& darkBackgroundSelectedColors, UBPreferencesController* controller)
Expand Down
1 change: 0 additions & 1 deletion src/core/UBPreferencesController.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class UBPreferencesController : public QObject
void toolbarOrientationVertical(bool checked);
void toolbarOrientationHorizontal(bool checked);
void systemOSKCheckBoxToggled(bool checked);
void setPdfZoomBehavior(bool checked);

private slots:
void adjustScreensPreferences();
Expand Down
2 changes: 0 additions & 2 deletions src/core/UBSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,6 @@ void UBSettings::init()
pdfUsePDFMerger = new UBSetting(this, "PDF", "UsePDFMerger", "true");
pdfResolution = new UBSetting(this, "PDF", "Resolution", "300");

pdfZoomBehavior = new UBSetting(this, "PDF", "ZoomBehavior", "4");
enableQualityLossToIncreaseZoomPerfs = new UBSetting(this, "PDF", "enableQualityLossToIncreaseZoomPerfs", true);
exportBackgroundGrid = new UBSetting(this, "PDF", "ExportBackgroundGrid", false);
exportBackgroundColor = new UBSetting(this, "PDF", "ExportBackgroundColor", false);

Expand Down
2 changes: 0 additions & 2 deletions src/core/UBSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,6 @@ class UBSettings : public QObject
UBSetting* pdfUsePDFMerger;
UBSetting* pdfResolution;

UBSetting* pdfZoomBehavior;
UBSetting* enableQualityLossToIncreaseZoomPerfs;
UBSetting* exportBackgroundGrid;
UBSetting* exportBackgroundColor;

Expand Down
105 changes: 32 additions & 73 deletions src/pdf/XPDFRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
#include <QtGui>

#include <frameworks/UBPlatformUtils.h>
#ifndef USE_XPDF
#include <poppler/cpp/poppler-version.h>
#endif
#include <poppler/cpp/poppler-version.h>

#include "core/memcheck.h"
#include "core/UBSettings.h"
Expand All @@ -47,9 +45,8 @@ namespace constants{
}

XPDFRenderer::XPDFRenderer(const QString &filename, bool importingFile)
: m_pdfZoomMode(UBSettings::settings()->pdfZoomBehavior->get().toUInt())
, mpSplashBitmapHistorical(nullptr)
, mSplashHistorical(nullptr)
: mpSplashBitmapUncached(nullptr)
, mSplashUncached(nullptr)
, mDocument(nullptr)
{
Q_UNUSED(importingFile);
Expand All @@ -64,9 +61,7 @@ XPDFRenderer::XPDFRenderer(const QString &filename, bool importingFile)
#endif
globalParams->setupBaseFonts(QFile::encodeName(UBPlatformUtils::applicationResourcesDirectory() + "/" + "fonts").data());
}
#ifdef USE_XPDF
mDocument = new PDFDoc(new GString(filename.toLocal8Bit()), 0, 0, 0); // the filename GString is deleted on PDFDoc desctruction
#elif POPPLER_VERSION_MAJOR > 22 || (POPPLER_VERSION_MAJOR == 22 && POPPLER_VERSION_MINOR >= 3)
#if POPPLER_VERSION_MAJOR > 22 || (POPPLER_VERSION_MAJOR == 22 && POPPLER_VERSION_MINOR >= 3)
mDocument = new PDFDoc(std::make_unique<GooString>(filename.toLocal8Bit()));
#else
mDocument = new PDFDoc(new GooString(filename.toLocal8Bit()), 0, 0, 0); // the filename GString is deleted on PDFDoc desctruction
Expand Down Expand Up @@ -106,8 +101,8 @@ XPDFRenderer::~XPDFRenderer()
}
}

if(mSplashHistorical)
delete mSplashHistorical;
if(mSplashUncached)
delete mSplashUncached;

if (mDocument)
{
Expand All @@ -132,9 +127,9 @@ void XPDFRenderer::initPDFZoomData()
{
m_perPagepdfZoomCache.insert(i, QVector<PdfZoomCacheData>());

for (int j = 0; j < XPDFRendererZoomFactor::mode4_zoomFactorIterations; j++ )
for (int j = 0; j < XPDFRendererZoomFactor::zoomFactorIterations; j++ )
{
double const zoomValue = XPDFRendererZoomFactor::mode4_zoomFactorStart+XPDFRendererZoomFactor::mode4_zoomFactorStepSquare*static_cast<double>(j*j);
double const zoomValue = XPDFRendererZoomFactor::zoomFactorStart+XPDFRendererZoomFactor::zoomFactorStepSquare*static_cast<double>(j*j);
m_perPagepdfZoomCache[i].push_back(zoomValue);
}
}
Expand Down Expand Up @@ -231,19 +226,16 @@ QSizeF XPDFRenderer::pointSizeF(int pageNumber) const
}


QImage* XPDFRenderer::createPDFImageHistorical(int pageNumber, qreal xscale, qreal yscale, const QRectF &bounds)
QImage* XPDFRenderer::createPDFImageUncached(int pageNumber, qreal xscale, qreal yscale, const QRectF &bounds)
{
if (isValid())
{
if(mSplashHistorical)
delete mSplashHistorical;
if(mSplashUncached)
delete mSplashUncached;

mSplashUncached = new SplashOutputDev(splashModeRGB8, 1, false, constants::paperColor);
mSplashUncached->startDoc(mDocument);

mSplashHistorical = new SplashOutputDev(splashModeRGB8, 1, false, constants::paperColor);
#ifdef USE_XPDF
mSplashHistorical->startDoc(mDocument->getXRef());
#else
mSplashHistorical->startDoc(mDocument);
#endif
int rotation = 0; // in degrees (get it from the worldTransform if we want to support rotation)
bool useMediaBox = false;
bool crop = true;
Expand All @@ -253,7 +245,7 @@ QImage* XPDFRenderer::createPDFImageHistorical(int pageNumber, qreal xscale, qre

if (bounds.isNull())
{
mDocument->displayPage(mSplashHistorical, pageNumber, this->dpiForRendering * xscale, this->dpiForRendering *yscale,
mDocument->displayPage(mSplashUncached, pageNumber, this->dpiForRendering * xscale, this->dpiForRendering *yscale,
rotation, useMediaBox, crop, printing);
}
else
Expand All @@ -263,13 +255,13 @@ QImage* XPDFRenderer::createPDFImageHistorical(int pageNumber, qreal xscale, qre
qreal sliceW = bounds.width() * xscale;
qreal sliceH = bounds.height() * yscale;

mDocument->displayPageSlice(mSplashHistorical, pageNumber, this->dpiForRendering * xscale, this->dpiForRendering * yscale,
mDocument->displayPageSlice(mSplashUncached, pageNumber, this->dpiForRendering * xscale, this->dpiForRendering * yscale,
rotation, useMediaBox, crop, printing, mSliceX, mSliceY, sliceW, sliceH);
}

mpSplashBitmapHistorical = mSplashHistorical->getBitmap();
mpSplashBitmapUncached = mSplashUncached->getBitmap();
}
return new QImage(mpSplashBitmapHistorical->getDataPtr(), mpSplashBitmapHistorical->getWidth(), mpSplashBitmapHistorical->getHeight(), mpSplashBitmapHistorical->getWidth() * 3, QImage::Format_RGB888);
return new QImage(mpSplashBitmapUncached->getDataPtr(), mpSplashBitmapUncached->getWidth(), mpSplashBitmapUncached->getHeight(), mpSplashBitmapUncached->getWidth() * 3, QImage::Format_RGB888);
}

void XPDFRenderer::OnThreadFinished()
Expand All @@ -294,43 +286,21 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, bool const cacheAllowed,

qreal zoomRequested = xscale;
int zoomIndex = 0;
if (m_pdfZoomMode == 3)
{
// Choose a zoom which is inferior or equivalent than the user choice (= minor loss, downscaling).
bool foundIndex = false;
for (zoomIndex = m_perPagepdfZoomCache[pageNumber].size()-1; zoomIndex >= 0 && !foundIndex;)
{
if (zoomRequested >= m_perPagepdfZoomCache[pageNumber][zoomIndex].ratio) {
foundIndex = true;
} else {
zoomIndex--;
}
}

if (!foundIndex) // Use the smallest one.
zoomIndex = 0;

if (zoomIndex == 0 && m_perPagepdfZoomCache[pageNumber][zoomIndex].ratio != zoomRequested)
{
m_perPagepdfZoomCache[pageNumber][zoomIndex].cleanup();
m_perPagepdfZoomCache[pageNumber][zoomIndex] = PdfZoomCacheData(zoomRequested);
}
} else {
// Choose a zoom which is superior or equivalent than the user choice (= no loss, upscaling).
bool foundIndex = false;
for (; zoomIndex < m_perPagepdfZoomCache[pageNumber].size() && !foundIndex;)
{
if (zoomRequested <= (m_perPagepdfZoomCache[pageNumber][zoomIndex].ratio+0.1)) {
foundIndex = true;
} else {
zoomIndex++;
}
// Choose a zoom which is superior or equivalent than the user choice (= no loss, upscaling).
bool foundIndex = false;
for (; zoomIndex < m_perPagepdfZoomCache[pageNumber].size() && !foundIndex;)
{
if (zoomRequested <= (m_perPagepdfZoomCache[pageNumber][zoomIndex].ratio+0.1)) {
foundIndex = true;
} else {
zoomIndex++;
}

if (!foundIndex) // Use the previous one.
zoomIndex--;
}

if (!foundIndex) // Use the previous one.
zoomIndex--;

QImage pdfImage = createPDFImageCached(pageNumber, m_perPagepdfZoomCache[pageNumber][zoomIndex]);
qreal ratioExpected = m_perPagepdfZoomCache[pageNumber][zoomIndex].ratio;
qreal ratioObtained = ratioExpected;
Expand Down Expand Up @@ -393,7 +363,7 @@ void XPDFRenderer::render(QPainter *p, int pageNumber, bool const cacheAllowed,
qreal xscale = p->worldTransform().m11();
qreal yscale = p->worldTransform().m22();

QImage *pdfImage = createPDFImageHistorical(pageNumber, xscale, yscale, bounds);
QImage *pdfImage = createPDFImageUncached(pageNumber, xscale, yscale, bounds);
QTransform savedTransform = p->worldTransform();
p->resetTransform();
//qDebug() << "drawImage size=" << p->viewport() << "bounds" << bounds << "pdfImage" << pdfImage->size() << "savedTransform" << savedTransform.m11();
Expand Down Expand Up @@ -425,14 +395,8 @@ QImage& XPDFRenderer::createPDFImageCached(int pageNumber, PdfZoomCacheData &cac
jobData.cacheData->cachedImage = QImage();
m_cacheThread.pushJob(jobData);

if (m_pdfZoomMode == 4)
{
// Start the job multithreaded. The item will be refreshed when the signal 'finished' is emitted.
m_cacheThread.start();
} else {
// Perform the job now. Note this will lock the GUI until the job is done.
m_cacheThread.run();
}
// Start the job multithreaded. The item will be refreshed when the signal 'finished' is emitted.
m_cacheThread.start();
}
} else {
cacheData.cachedImage = QImage();
Expand All @@ -451,12 +415,7 @@ void XPDFRenderer::CacheThread::run()
<< "ratio" << jobData.cacheData->ratio; */

jobData.cacheData->prepareNewSplash(jobData.pageNumber, constants::paperColor);

#ifdef USE_XPDF
jobData.cacheData->splash->startDoc(jobData.document->getXRef());
#else
jobData.cacheData->splash->startDoc(jobData.document);
#endif

m_jobMutex.unlock();

Expand Down
28 changes: 8 additions & 20 deletions src/pdf/XPDFRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ class PDFDoc;

namespace XPDFRendererZoomFactor
{
const double mode1_zoomFactor = 3.0;
const double mode2_zoomFactorStage1 = 2.5;
const double mode2_zoomFactorStage2 = 5.0;
const double mode2_zoomFactorStage3 = 10.0;
const double mode3_zoomFactorStage1 = 1.0;
const double mode3_zoomFactorStage2 = 3.0;
const double mode4_zoomFactorStart = .25;
const double mode4_zoomFactorStepSquare = .25;
const double mode4_zoomFactorIterations = 7;
const double zoomFactorStart = .25;
const double zoomFactorStepSquare = .25;
const double zoomFactorIterations = 7;
}

namespace XPDFThreadMaxTimeoutOnExit
Expand Down Expand Up @@ -154,20 +148,14 @@ class XPDFRenderer : public PDFRenderer
CacheThread m_cacheThread;

QImage &createPDFImageCached(int pageNumber, PdfZoomCacheData &cacheData);
QImage* createPDFImageHistorical(int pageNumber, qreal xscale, qreal yscale, const QRectF &bounds);
QImage* createPDFImageUncached(int pageNumber, qreal xscale, qreal yscale, const QRectF &bounds);

// Used when 'ZoomBehavior == 1, 2, 3 or 4'.
// =1 has only x3 zoom in cache (= loss if user zoom > 3.0).
// =2, has 2.5, 5 and 10 (= no loss, but a bit slower).
// =3, has 1.0, 2.5, 5 and 10, but downsampled instead of upsampled (= minor quality loss, a bit faster).
// =4, multithreaded, multiple level of zoom.
QMap<int, QVector<PdfZoomCacheData>> m_perPagepdfZoomCache;
int const m_pdfZoomMode;

// Used when 'ZoomBehavior == 0' (no cache).
SplashBitmap* mpSplashBitmapHistorical;
// Used when 'ZoomBehavior == 0' (no cache).
SplashOutputDev* mSplashHistorical;
// Used when no cache allowed (e.g. rendering to a file).
SplashBitmap* mpSplashBitmapUncached;
// Used when no cache allowed (e.g. rendering to a file).
SplashOutputDev* mSplashUncached;

PDFDoc *mDocument;
static QAtomicInt sInstancesCount;
Expand Down