2020-01-18 11:38:54 +01:00
|
|
|
// Copyright (C) 2019-2020 Jakub Melka
|
2019-12-07 17:59:03 +01:00
|
|
|
//
|
|
|
|
// This file is part of PdfForQt.
|
|
|
|
//
|
|
|
|
// PdfForQt is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// PdfForQt is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2019-09-06 19:07:52 +02:00
|
|
|
#include "pdfviewersettings.h"
|
2019-12-15 19:28:25 +01:00
|
|
|
#include "pdfconstants.h"
|
|
|
|
|
|
|
|
#include <QPixmapCache>
|
2019-09-06 19:07:52 +02:00
|
|
|
|
|
|
|
namespace pdfviewer
|
|
|
|
{
|
2019-12-15 19:28:25 +01:00
|
|
|
const int PIXMAP_CACHE_LIMIT = QPixmapCache::cacheLimit();
|
2019-09-06 19:07:52 +02:00
|
|
|
|
2019-09-07 19:01:54 +02:00
|
|
|
void PDFViewerSettings::setSettings(const PDFViewerSettings::Settings& settings)
|
|
|
|
{
|
2019-12-24 17:29:40 +01:00
|
|
|
if (m_settings != settings)
|
|
|
|
{
|
|
|
|
m_settings = settings;
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
2019-09-07 19:01:54 +02:00
|
|
|
}
|
|
|
|
|
2019-12-24 17:29:40 +01:00
|
|
|
void PDFViewerSettings::readSettings(QSettings& settings, const pdf::PDFCMSSettings& defaultCMSSettings)
|
2019-09-06 19:07:52 +02:00
|
|
|
{
|
2019-09-28 18:26:31 +02:00
|
|
|
Settings defaultSettings;
|
|
|
|
|
2019-09-06 19:07:52 +02:00
|
|
|
settings.beginGroup("ViewerSettings");
|
|
|
|
m_settings.m_directory = settings.value("defaultDirectory", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)).toString();
|
|
|
|
m_settings.m_features = static_cast<pdf::PDFRenderer::Features>(settings.value("rendererFeatures", static_cast<int>(pdf::PDFRenderer::getDefaultFeatures())).toInt());
|
|
|
|
m_settings.m_rendererEngine = static_cast<pdf::RendererEngine>(settings.value("renderingEngine", static_cast<int>(pdf::RendererEngine::OpenGL)).toInt());
|
2019-09-28 18:26:31 +02:00
|
|
|
m_settings.m_multisampleAntialiasing = settings.value("msaa", defaultSettings.m_multisampleAntialiasing).toBool();
|
|
|
|
m_settings.m_rendererSamples = settings.value("rendererSamples", defaultSettings.m_rendererSamples).toInt();
|
2019-12-15 17:46:58 +01:00
|
|
|
m_settings.m_prefetchPages = settings.value("prefetchPages", defaultSettings.m_prefetchPages).toBool();
|
2019-09-28 18:26:31 +02:00
|
|
|
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();
|
2019-12-15 19:28:25 +01:00
|
|
|
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();
|
2019-11-30 16:26:32 +01:00
|
|
|
m_settings.m_allowLaunchApplications = settings.value("allowLaunchApplications", defaultSettings.m_allowLaunchApplications).toBool();
|
|
|
|
m_settings.m_allowLaunchURI = settings.value("allowLaunchURI", defaultSettings.m_allowLaunchURI).toBool();
|
2020-01-18 14:55:26 +01:00
|
|
|
m_settings.m_multithreadingStrategy = static_cast<pdf::PDFExecutionPolicy::Strategy>(settings.value("mutlithreadingStrategy", static_cast<int>(defaultSettings.m_multithreadingStrategy)).toInt());
|
2019-09-06 19:07:52 +02:00
|
|
|
settings.endGroup();
|
|
|
|
|
2019-12-24 17:29:40 +01:00
|
|
|
settings.beginGroup("ColorManagementSystemSettings");
|
|
|
|
m_colorManagementSystemSettings.system = static_cast<pdf::PDFCMSSettings::System>(settings.value("system", int(defaultCMSSettings.system)).toInt());
|
|
|
|
m_colorManagementSystemSettings.accuracy = static_cast<pdf::PDFCMSSettings::Accuracy>(settings.value("accuracy", int(defaultCMSSettings.accuracy)).toInt());
|
|
|
|
m_colorManagementSystemSettings.intent = static_cast<pdf::RenderingIntent>(settings.value("intent", int(defaultCMSSettings.intent)).toInt());
|
|
|
|
m_colorManagementSystemSettings.isBlackPointCompensationActive = settings.value("isBlackPointCompensationActive", defaultCMSSettings.isBlackPointCompensationActive).toBool();
|
|
|
|
m_colorManagementSystemSettings.isWhitePaperColorTransformed = settings.value("isWhitePaperColorTransformed", defaultCMSSettings.isWhitePaperColorTransformed).toBool();
|
|
|
|
m_colorManagementSystemSettings.outputCS = settings.value("outputCS", defaultCMSSettings.outputCS).toString();
|
|
|
|
m_colorManagementSystemSettings.deviceGray = settings.value("deviceGray", defaultCMSSettings.deviceGray).toString();
|
|
|
|
m_colorManagementSystemSettings.deviceRGB = settings.value("deviceRGB", defaultCMSSettings.deviceRGB).toString();
|
|
|
|
m_colorManagementSystemSettings.deviceCMYK = settings.value("deviceCMYK", defaultCMSSettings.deviceCMYK).toString();
|
2019-12-25 14:34:37 +01:00
|
|
|
m_colorManagementSystemSettings.profileDirectory = settings.value("profileDirectory", defaultCMSSettings.profileDirectory).toString();
|
2019-12-24 17:29:40 +01:00
|
|
|
settings.endGroup();
|
|
|
|
|
2019-09-06 19:07:52 +02:00
|
|
|
emit settingsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PDFViewerSettings::writeSettings(QSettings& settings)
|
|
|
|
{
|
|
|
|
settings.beginGroup("ViewerSettings");
|
|
|
|
settings.setValue("defaultDirectory", m_settings.m_directory);
|
|
|
|
settings.setValue("rendererFeatures", static_cast<int>(m_settings.m_features));
|
|
|
|
settings.setValue("renderingEngine", static_cast<int>(m_settings.m_rendererEngine));
|
2019-09-08 11:13:59 +02:00
|
|
|
settings.setValue("msaa", m_settings.m_multisampleAntialiasing);
|
2019-09-06 19:07:52 +02:00
|
|
|
settings.setValue("rendererSamples", m_settings.m_rendererSamples);
|
2019-12-15 17:46:58 +01:00
|
|
|
settings.setValue("prefetchPages", m_settings.m_prefetchPages);
|
2019-09-28 18:26:31 +02:00
|
|
|
settings.setValue("preferredMeshResolutionRatio", m_settings.m_preferredMeshResolutionRatio);
|
|
|
|
settings.setValue("minimalMeshResolutionRatio", m_settings.m_minimalMeshResolutionRatio);
|
|
|
|
settings.setValue("colorTolerance", m_settings.m_colorTolerance);
|
2019-12-15 19:28:25 +01:00
|
|
|
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);
|
2019-11-30 16:26:32 +01:00
|
|
|
settings.setValue("allowLaunchApplications", m_settings.m_allowLaunchApplications);
|
|
|
|
settings.setValue("allowLaunchURI", m_settings.m_allowLaunchURI);
|
2020-01-18 14:55:26 +01:00
|
|
|
settings.setValue("mutlithreadingStrategy", static_cast<int>(m_settings.m_multithreadingStrategy));
|
2019-09-06 19:07:52 +02:00
|
|
|
settings.endGroup();
|
2019-12-24 17:29:40 +01:00
|
|
|
|
|
|
|
settings.beginGroup("ColorManagementSystemSettings");
|
|
|
|
settings.setValue("system", int(m_colorManagementSystemSettings.system));
|
|
|
|
settings.setValue("accuracy", int(m_colorManagementSystemSettings.accuracy));
|
|
|
|
settings.setValue("intent", int(m_colorManagementSystemSettings.intent));
|
|
|
|
settings.setValue("isBlackPointCompensationActive", m_colorManagementSystemSettings.isBlackPointCompensationActive);
|
|
|
|
settings.setValue("isWhitePaperColorTransformed", m_colorManagementSystemSettings.isWhitePaperColorTransformed);
|
|
|
|
settings.setValue("outputCS", m_colorManagementSystemSettings.outputCS);
|
|
|
|
settings.setValue("deviceGray", m_colorManagementSystemSettings.deviceGray);
|
|
|
|
settings.setValue("deviceRGB", m_colorManagementSystemSettings.deviceRGB);
|
|
|
|
settings.setValue("deviceCMYK", m_colorManagementSystemSettings.deviceCMYK);
|
2019-12-25 14:34:37 +01:00
|
|
|
settings.setValue("profileDirectory", m_colorManagementSystemSettings.profileDirectory);
|
2019-12-24 17:29:40 +01:00
|
|
|
settings.endGroup();
|
2019-09-06 19:07:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString PDFViewerSettings::getDirectory() const
|
|
|
|
{
|
|
|
|
return m_settings.m_directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PDFViewerSettings::setDirectory(const QString& directory)
|
|
|
|
{
|
|
|
|
if (m_settings.m_directory != directory)
|
|
|
|
{
|
|
|
|
m_settings.m_directory = directory;
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pdf::PDFRenderer::Features PDFViewerSettings::getFeatures() const
|
|
|
|
{
|
|
|
|
return m_settings.m_features;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PDFViewerSettings::setFeatures(const pdf::PDFRenderer::Features& features)
|
|
|
|
{
|
|
|
|
if (m_settings.m_features != features)
|
|
|
|
{
|
|
|
|
m_settings.m_features = features;
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pdf::RendererEngine PDFViewerSettings::getRendererEngine() const
|
|
|
|
{
|
|
|
|
return m_settings.m_rendererEngine;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PDFViewerSettings::setRendererEngine(pdf::RendererEngine rendererEngine)
|
|
|
|
{
|
|
|
|
if (m_settings.m_rendererEngine != rendererEngine)
|
|
|
|
{
|
|
|
|
m_settings.m_rendererEngine = rendererEngine;
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int PDFViewerSettings::getRendererSamples() const
|
|
|
|
{
|
|
|
|
return m_settings.m_rendererSamples;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PDFViewerSettings::setRendererSamples(int rendererSamples)
|
|
|
|
{
|
|
|
|
if (m_settings.m_rendererSamples != rendererSamples)
|
|
|
|
{
|
|
|
|
m_settings.m_rendererSamples = rendererSamples;
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-28 18:26:31 +02:00
|
|
|
void PDFViewerSettings::setPreferredMeshResolutionRatio(pdf::PDFReal preferredMeshResolutionRatio)
|
|
|
|
{
|
|
|
|
if (m_settings.m_preferredMeshResolutionRatio != preferredMeshResolutionRatio)
|
|
|
|
{
|
|
|
|
m_settings.m_preferredMeshResolutionRatio = preferredMeshResolutionRatio;
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PDFViewerSettings::setMinimalMeshResolutionRatio(pdf::PDFReal minimalMeshResolutionRatio)
|
|
|
|
{
|
|
|
|
if (m_settings.m_minimalMeshResolutionRatio != minimalMeshResolutionRatio)
|
|
|
|
{
|
|
|
|
m_settings.m_minimalMeshResolutionRatio = minimalMeshResolutionRatio;
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PDFViewerSettings::setColorTolerance(pdf::PDFReal colorTolerance)
|
|
|
|
{
|
|
|
|
if (m_settings.m_colorTolerance != colorTolerance)
|
|
|
|
{
|
|
|
|
m_settings.m_colorTolerance = colorTolerance;
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-15 19:28:25 +01:00
|
|
|
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),
|
2020-01-18 14:55:26 +01:00
|
|
|
m_instancedFontCacheLimit(pdf::DEFAULT_REALIZED_FONT_CACHE_LIMIT),
|
|
|
|
m_multithreadingStrategy(pdf::PDFExecutionPolicy::Strategy::PageMultithreaded)
|
2019-12-15 19:28:25 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-06 19:07:52 +02:00
|
|
|
} // namespace pdfviewer
|