Settings of cache size

This commit is contained in:
Jakub Melka
2019-12-15 19:28:25 +01:00
parent 3cd2dd5104
commit 7dbae1c3dc
17 changed files with 467 additions and 24 deletions

View File

@ -22,5 +22,6 @@
<file>resources/zoom-fit-horizontal.svg</file>
<file>resources/zoom-fit-vertical.svg</file>
<file>resources/synchronize.svg</file>
<file>resources/cache.svg</file>
</qresource>
</RCC>

View File

@ -153,6 +153,7 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget *parent) :
m_pdfWidget = new pdf::PDFWidget(m_settings->getRendererEngine(), m_settings->isMultisampleAntialiasingEnabled() ? m_settings->getRendererSamples() : -1, this);
setCentralWidget(m_pdfWidget);
setFocusProxy(m_pdfWidget);
m_pdfWidget->updateCacheLimits(m_settings->getCompiledPageCacheLimit() * 1024, m_settings->getThumbnailsCacheLimit(), m_settings->getFontCacheLimit(), m_settings->getInstancedFontCacheLimit());
m_sidebarWidget = new PDFSidebarWidget(m_pdfWidget->getDrawWidgetProxy(), this);
m_sidebarDockWidget = new QDockWidget(tr("Sidebar"), this);
@ -650,10 +651,12 @@ void PDFViewerMainWindow::updateUI(bool fullUpdate)
void PDFViewerMainWindow::onViewerSettingsChanged()
{
m_pdfWidget->updateRenderer(m_settings->getRendererEngine(), m_settings->isMultisampleAntialiasingEnabled() ? m_settings->getRendererSamples() : -1);
m_pdfWidget->updateCacheLimits(m_settings->getCompiledPageCacheLimit() * 1024, m_settings->getThumbnailsCacheLimit(), m_settings->getFontCacheLimit(), m_settings->getInstancedFontCacheLimit());
m_pdfWidget->getDrawWidgetProxy()->setFeatures(m_settings->getFeatures());
m_pdfWidget->getDrawWidgetProxy()->setPreferredMeshResolutionRatio(m_settings->getPreferredMeshResolutionRatio());
m_pdfWidget->getDrawWidgetProxy()->setMinimalMeshResolutionRatio(m_settings->getMinimalMeshResolutionRatio());
m_pdfWidget->getDrawWidgetProxy()->setColorTolerance(m_settings->getColorTolerance());
updateRenderingOptionActions();
}

View File

@ -16,9 +16,13 @@
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#include "pdfviewersettings.h"
#include "pdfconstants.h"
#include <QPixmapCache>
namespace pdfviewer
{
const int PIXMAP_CACHE_LIMIT = QPixmapCache::cacheLimit();
void PDFViewerSettings::setSettings(const PDFViewerSettings::Settings& settings)
{
@ -40,6 +44,10 @@ void PDFViewerSettings::readSettings(QSettings& settings)
m_settings.m_preferredMeshResolutionRatio = settings.value("preferredMeshResolutionRatio", defaultSettings.m_preferredMeshResolutionRatio).toDouble();
m_settings.m_minimalMeshResolutionRatio = settings.value("minimalMeshResolutionRatio", defaultSettings.m_minimalMeshResolutionRatio).toDouble();
m_settings.m_colorTolerance = settings.value("colorTolerance", defaultSettings.m_colorTolerance).toDouble();
m_settings.m_compiledPageCacheLimit = settings.value("compiledPageCacheLimit", defaultSettings.m_compiledPageCacheLimit).toInt();
m_settings.m_thumbnailsCacheLimit = settings.value("thumbnailsCacheLimit", defaultSettings.m_thumbnailsCacheLimit).toInt();
m_settings.m_fontCacheLimit = settings.value("fontCacheLimit", defaultSettings.m_fontCacheLimit).toInt();
m_settings.m_instancedFontCacheLimit = settings.value("instancedFontCacheLimit", defaultSettings.m_instancedFontCacheLimit).toInt();
m_settings.m_allowLaunchApplications = settings.value("allowLaunchApplications", defaultSettings.m_allowLaunchApplications).toBool();
m_settings.m_allowLaunchURI = settings.value("allowLaunchURI", defaultSettings.m_allowLaunchURI).toBool();
settings.endGroup();
@ -59,6 +67,10 @@ void PDFViewerSettings::writeSettings(QSettings& settings)
settings.setValue("preferredMeshResolutionRatio", m_settings.m_preferredMeshResolutionRatio);
settings.setValue("minimalMeshResolutionRatio", m_settings.m_minimalMeshResolutionRatio);
settings.setValue("colorTolerance", m_settings.m_colorTolerance);
settings.setValue("compiledPageCacheLimit", m_settings.m_compiledPageCacheLimit);
settings.setValue("thumbnailsCacheLimit", m_settings.m_thumbnailsCacheLimit);
settings.setValue("fontCacheLimit", m_settings.m_fontCacheLimit);
settings.setValue("instancedFontCacheLimit", m_settings.m_instancedFontCacheLimit);
settings.setValue("allowLaunchApplications", m_settings.m_allowLaunchApplications);
settings.setValue("allowLaunchURI", m_settings.m_allowLaunchURI);
settings.endGroup();
@ -147,4 +159,23 @@ void PDFViewerSettings::setColorTolerance(pdf::PDFReal colorTolerance)
}
}
PDFViewerSettings::Settings::Settings() :
m_features(pdf::PDFRenderer::getDefaultFeatures()),
m_rendererEngine(pdf::RendererEngine::OpenGL),
m_multisampleAntialiasing(true),
m_rendererSamples(16),
m_prefetchPages(true),
m_preferredMeshResolutionRatio(0.02),
m_minimalMeshResolutionRatio(0.005),
m_colorTolerance(0.01),
m_allowLaunchApplications(true),
m_allowLaunchURI(true),
m_compiledPageCacheLimit(128 * 1024),
m_thumbnailsCacheLimit(PIXMAP_CACHE_LIMIT),
m_fontCacheLimit(pdf::DEFAULT_FONT_CACHE_LIMIT),
m_instancedFontCacheLimit(pdf::DEFAULT_REALIZED_FONT_CACHE_LIMIT)
{
}
} // namespace pdfviewer

View File

@ -38,20 +38,7 @@ public:
struct Settings
{
Settings() :
m_features(pdf::PDFRenderer::getDefaultFeatures()),
m_rendererEngine(pdf::RendererEngine::OpenGL),
m_multisampleAntialiasing(true),
m_rendererSamples(16),
m_prefetchPages(true),
m_preferredMeshResolutionRatio(0.02),
m_minimalMeshResolutionRatio(0.005),
m_colorTolerance(0.01),
m_allowLaunchApplications(true),
m_allowLaunchURI(true)
{
}
Settings();
pdf::PDFRenderer::Features m_features;
QString m_directory;
@ -64,6 +51,12 @@ public:
pdf::PDFReal m_colorTolerance;
bool m_allowLaunchApplications;
bool m_allowLaunchURI;
// Cache settings
int m_compiledPageCacheLimit;
int m_thumbnailsCacheLimit;
int m_fontCacheLimit;
int m_instancedFontCacheLimit;
};
const Settings& getSettings() const { return m_settings; }
@ -96,6 +89,11 @@ public:
pdf::PDFReal getColorTolerance() const { return m_settings.m_colorTolerance; }
void setColorTolerance(pdf::PDFReal colorTolerance);
int getCompiledPageCacheLimit() const { return m_settings.m_compiledPageCacheLimit; }
int getThumbnailsCacheLimit() const { return m_settings.m_thumbnailsCacheLimit; }
int getFontCacheLimit() const { return m_settings.m_fontCacheLimit; }
int getInstancedFontCacheLimit() const { return m_settings.m_instancedFontCacheLimit; }
signals:
void settingsChanged();

View File

@ -38,6 +38,7 @@ PDFViewerSettingsDialog::PDFViewerSettingsDialog(const PDFViewerSettings::Settin
new QListWidgetItem(QIcon(":/resources/engine.svg"), tr("Engine"), ui->optionsPagesWidget, EngineSettings);
new QListWidgetItem(QIcon(":/resources/rendering.svg"), tr("Rendering"), ui->optionsPagesWidget, RenderingSettings);
new QListWidgetItem(QIcon(":/resources/shading.svg"), tr("Shading"), ui->optionsPagesWidget, ShadingSettings);
new QListWidgetItem(QIcon(":/resources/cache.svg"), tr("Cache"), ui->optionsPagesWidget, CacheSettings);
new QListWidgetItem(QIcon(":/resources/security.svg"), tr("Security"), ui->optionsPagesWidget, SecuritySettings);
ui->renderingEngineComboBox->addItem(tr("Software"), static_cast<int>(pdf::RendererEngine::Software));
@ -65,6 +66,10 @@ PDFViewerSettingsDialog::PDFViewerSettingsDialog(const PDFViewerSettings::Settin
{
connect(spinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &PDFViewerSettingsDialog::saveData);
}
for (QSpinBox* spinBox : findChildren<QSpinBox*>())
{
connect(spinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &PDFViewerSettingsDialog::saveData);
}
ui->optionsPagesWidget->setCurrentRow(0);
adjustSize();
@ -94,6 +99,10 @@ void PDFViewerSettingsDialog::on_optionsPagesWidget_currentItemChanged(QListWidg
ui->stackedWidget->setCurrentWidget(ui->shadingPage);
break;
case CacheSettings:
ui->stackedWidget->setCurrentWidget(ui->cachePage);
break;
case SecuritySettings:
ui->stackedWidget->setCurrentWidget(ui->securityPage);
break;
@ -148,6 +157,12 @@ void PDFViewerSettingsDialog::loadData()
ui->minimalMeshResolutionEdit->setValue(m_settings.m_minimalMeshResolutionRatio);
ui->colorToleranceEdit->setValue(m_settings.m_colorTolerance);
// Cache
ui->compiledPageCacheSizeEdit->setValue(m_settings.m_compiledPageCacheLimit);
ui->thumbnailCacheSizeEdit->setValue(m_settings.m_thumbnailsCacheLimit);
ui->cachedFontLimitEdit->setValue(m_settings.m_fontCacheLimit);
ui->cachedInstancedFontLimitEdit->setValue(m_settings.m_instancedFontCacheLimit);
// Security
ui->allowLaunchCheckBox->setChecked(m_settings.m_allowLaunchApplications);
ui->allowRunURICheckBox->setChecked(m_settings.m_allowLaunchURI);
@ -222,6 +237,22 @@ void PDFViewerSettingsDialog::saveData()
{
m_settings.m_allowLaunchURI = ui->allowRunURICheckBox->isChecked();
}
else if (sender == ui->compiledPageCacheSizeEdit)
{
m_settings.m_compiledPageCacheLimit = ui->compiledPageCacheSizeEdit->value();
}
else if (sender == ui->thumbnailCacheSizeEdit)
{
m_settings.m_thumbnailsCacheLimit = ui->thumbnailCacheSizeEdit->value();
}
else if (sender == ui->cachedFontLimitEdit)
{
m_settings.m_fontCacheLimit = ui->cachedFontLimitEdit->value();
}
else if (sender == ui->cachedInstancedFontLimitEdit)
{
m_settings.m_instancedFontCacheLimit = ui->cachedInstancedFontLimitEdit->value();
}
loadData();
}

View File

@ -45,6 +45,7 @@ public:
EngineSettings,
RenderingSettings,
ShadingSettings,
CacheSettings,
SecuritySettings
};

View File

@ -26,7 +26,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<widget class="QWidget" name="enginePage">
<layout class="QVBoxLayout" name="enginePageLayout">
@ -394,6 +394,144 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="cachePage">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="cacheGroupBox">
<property name="title">
<string>Cache Settings</string>
</property>
<layout class="QVBoxLayout" name="cacheGroupBoxLayout">
<item>
<layout class="QGridLayout" name="cacheSettingsGridLayout">
<item row="1" column="0">
<widget class="QLabel" name="thumbnailCacheSizeLabel">
<property name="text">
<string>Thumbnail image cache size</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="cachedFontLabel">
<property name="text">
<string>Cached font limit</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="cachedFontLimitEdit">
<property name="buttonSymbols">
<enum>QAbstractSpinBox::PlusMinus</enum>
</property>
<property name="minimum">
<number>4</number>
</property>
<property name="maximum">
<number>256</number>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="compiledPageCacheSizeEdit">
<property name="buttonSymbols">
<enum>QAbstractSpinBox::PlusMinus</enum>
</property>
<property name="suffix">
<string> kB</string>
</property>
<property name="minimum">
<number>65536</number>
</property>
<property name="maximum">
<number>1048576</number>
</property>
<property name="singleStep">
<number>1024</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="compiledPageCacheLabel">
<property name="text">
<string>Compiled page cache size</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="thumbnailCacheSizeEdit">
<property name="suffix">
<string> kB</string>
</property>
<property name="minimum">
<number>1024</number>
</property>
<property name="maximum">
<number>65536</number>
</property>
<property name="singleStep">
<number>1024</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="cachedInstancedFontLimitLabel">
<property name="text">
<string>Cached instanced font limit</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="cachedInstancedFontLimitEdit">
<property name="minimum">
<number>4</number>
</property>
<property name="maximum">
<number>256</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="cacheInfoLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Rendering engine first compiles page for fast drawing, and then stores them in the cache. Stored compiled pages are usually drawn much faster than direct drawing. &lt;span style=&quot; font-weight:600;&quot;&gt;Compiled page cache size&lt;/span&gt; sets limits for compiled pages in kB. This limit should be at least two times large than largest compiled page size. If compiled page can't be inserted, then error is displayed during rendering. The higher this value is set, the faster the engine will be, at the cost of consumed operating memory.&lt;/p&gt;&lt;p&gt;Also, there is cache for thumbnails images. &lt;span style=&quot; font-weight:600;&quot;&gt;Thumbnail image cache size &lt;/span&gt;determines, how much space there is for thumbnail images. Set this value to at least fill space for thumbnails images on the screen. Again, the higher value is, the faster displaying of thumbnails is, at the cost of consumed operating memory. Thumbnails are stored as bitmaps for fast drawing, not as precompiled pages.&lt;/p&gt;&lt;p&gt;During rendering, fonts are cached. There is a two-level cache, one for general fonts, one for instanced fonts (fonts with given size). The &lt;span style=&quot; font-weight:600;&quot;&gt;cached font limit&lt;/span&gt; sets font cache limit (number of fonts) which can be stored in the cache. The &lt;span style=&quot; font-weight:600;&quot;&gt;instanced font cache limit&lt;/span&gt; sets font cache limit for instanced fonts (number of fonts with determined size), which can be stored in the cache. When cache limit is exceeded, then fonts are erased from the cache, but only if no operation in another thread is performed (for example, compiling pages), to avoid race conditions.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="cachePageVerticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>74</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="securityPage">
<layout class="QVBoxLayout" name="securityPageLayout">
<property name="leftMargin">

View File

@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="30mm"
height="30mm"
viewBox="0 0 30 30"
version="1.1"
id="svg5291"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="cache.svg">
<defs
id="defs5285">
<inkscape:path-effect
effect="skeletal"
id="path-effect853"
is_visible="true"
pattern="M 0,5 C 0,2.24 2.24,0 5,0 7.76,0 10,2.24 10,5 10,7.76 7.76,10 5,10 2.24,10 0,7.76 0,5 Z"
copytype="single_stretched"
prop_scale="0.26458333"
scale_y_rel="false"
spacing="0"
normal_offset="0"
tang_offset="0"
prop_units="false"
vertical_pattern="false"
fuse_tolerance="0" />
<inkscape:path-effect
effect="skeletal"
id="path-effect849"
is_visible="true"
pattern="M 0,5 C 0,2.24 2.24,0 5,0 7.76,0 10,2.24 10,5 10,7.76 7.76,10 5,10 2.24,10 0,7.76 0,5 Z"
copytype="single_stretched"
prop_scale="0.26458333"
scale_y_rel="false"
spacing="0"
normal_offset="0"
tang_offset="0"
prop_units="false"
vertical_pattern="false"
fuse_tolerance="0" />
<linearGradient
id="linearGradient841"
osb:paint="solid">
<stop
style="stop-color:#ffffff;stop-opacity:1;"
offset="0"
id="stop839" />
</linearGradient>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.98994949"
inkscape:cx="-375.5706"
inkscape:cy="-30.46167"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="3840"
inkscape:window-height="2035"
inkscape:window-x="-13"
inkscape:window-y="-13"
inkscape:window-maximized="1" />
<metadata
id="metadata5288">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:creator>
<cc:Agent>
<dc:title>Jakub Melka</dc:title>
</cc:Agent>
</dc:creator>
<cc:license
rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#ShareAlike" />
</cc:License>
</rdf:RDF>
</metadata>
<g
inkscape:label="Vrstva 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-267)">
<ellipse
style="fill:#dcdcdc;fill-opacity:1;stroke:#000000;stroke-width:0.6;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path831"
cx="13.087426"
cy="280.41635"
rx="11.114326"
ry="10.500114" />
<ellipse
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:0.86595404;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path835"
cx="51.361652"
cy="275.41348"
rx="2.5243223"
ry="2.5364435"
transform="matrix(0.9883438,0.15223844,-0.13518619,0.99082021,0,0)" />
<ellipse
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.67466593;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path837"
cx="13.479585"
cy="280.6969"
rx="4.051156"
ry="3.999856" />
<ellipse
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.80000001;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path845"
cx="24.667669"
cy="290.52716"
rx="1.8662573"
ry="1.842634" />
<path
style="fill:none;stroke:#000000;stroke-width:0.69999999;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 25.966964,289.0625 -7.748512,-4.25223 5.055431,7.1343"
id="path871"
inkscape:connector-curvature="0" />
<ellipse
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.69999999;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
id="path876"
cx="18.023989"
cy="284.6889"
rx="0.88533032"
ry="0.81851292" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 5.4 KiB