PDF4QT/Pdf4QtViewer/pdfviewersettings.cpp

287 lines
16 KiB
C++
Raw Normal View History

2021-04-30 20:12:10 +02:00
// Copyright (C) 2019-2021 Jakub Melka
2019-12-07 17:59:03 +01:00
//
2021-08-10 19:22:56 +02:00
// This file is part of PDF4QT.
2019-12-07 17:59:03 +01:00
//
2021-08-10 19:22:56 +02:00
// PDF4QT is free software: you can redistribute it and/or modify
2019-12-07 17:59:03 +01:00
// 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
2021-04-30 20:12:10 +02:00
// with the written consent of the copyright owner, any later version.
2019-12-07 17:59:03 +01:00
//
2021-08-10 19:22:56 +02:00
// PDF4QT is distributed in the hope that it will be useful,
2019-12-07 17:59:03 +01:00
// 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
2021-08-10 19:22:56 +02:00
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
2019-12-07 17:59:03 +01:00
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)
{
if (m_settings != settings)
{
m_settings = settings;
emit settingsChanged();
}
2019-09-07 19:01:54 +02: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();
2021-05-04 18:40:51 +02:00
m_settings.m_allowDeveloperMode = settings.value("allowDeveloperMode", defaultSettings.m_allowDeveloperMode).toBool();
2020-05-03 18:52:22 +02:00
m_settings.m_multithreadingStrategy = static_cast<pdf::PDFExecutionPolicy::Strategy>(settings.value("multithreadingStrategy", static_cast<int>(defaultSettings.m_multithreadingStrategy)).toInt());
2020-02-22 18:27:33 +01:00
m_settings.m_magnifierSize = settings.value("magnifierSize", defaultSettings.m_magnifierSize).toInt();
m_settings.m_magnifierZoom = settings.value("magnifierZoom", defaultSettings.m_magnifierZoom).toDouble();
2020-05-03 18:52:22 +02:00
m_settings.m_maximumUndoSteps = settings.value("maximumUndoSteps", defaultSettings.m_maximumUndoSteps).toInt();
m_settings.m_maximumRedoSteps = settings.value("maximumRedoSteps", defaultSettings.m_maximumRedoSteps).toInt();
2019-09-06 19:07:52 +02:00
settings.endGroup();
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.colorAdaptationXYZ = static_cast<pdf::PDFCMSSettings::ColorAdaptationXYZ>(settings.value("colorAdaptationXYZ"), int(defaultCMSSettings.colorAdaptationXYZ));
m_colorManagementSystemSettings.isBlackPointCompensationActive = settings.value("isBlackPointCompensationActive", defaultCMSSettings.isBlackPointCompensationActive).toBool();
m_colorManagementSystemSettings.isWhitePaperColorTransformed = settings.value("isWhitePaperColorTransformed", defaultCMSSettings.isWhitePaperColorTransformed).toBool();
m_colorManagementSystemSettings.isConsiderOutputIntent = settings.value("isConsiderOutputIntent", defaultCMSSettings.isConsiderOutputIntent).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();
2020-12-26 12:55:29 +01:00
m_colorManagementSystemSettings.softProofingProfile = settings.value("softProofingProfile", defaultCMSSettings.softProofingProfile).toString();
m_colorManagementSystemSettings.proofingIntent = static_cast<pdf::RenderingIntent>(settings.value("proofingIntent", int(defaultCMSSettings.proofingIntent)).toInt());
m_colorManagementSystemSettings.outOfGamutColor = settings.value("outOfGamutColor", defaultCMSSettings.outOfGamutColor).value<QColor>();
2019-12-25 14:34:37 +01:00
m_colorManagementSystemSettings.profileDirectory = settings.value("profileDirectory", defaultCMSSettings.profileDirectory).toString();
settings.endGroup();
2020-02-13 18:31:00 +01:00
settings.beginGroup("SpeechSettings");
m_settings.m_speechEngine = settings.value("speechEngine", defaultSettings.m_speechEngine).toString();
m_settings.m_speechLocale = settings.value("speechLocale", defaultSettings.m_speechLocale).toString();
m_settings.m_speechVoice = settings.value("speechVoice", defaultSettings.m_speechVoice).toString();
m_settings.m_speechRate = settings.value("speechRate", defaultSettings.m_speechRate).toDouble();
m_settings.m_speechPitch = settings.value("speechPitch", defaultSettings.m_speechPitch).toDouble();
m_settings.m_speechVolume = settings.value("speechVolume", defaultSettings.m_speechVolume).toDouble();
settings.endGroup();
2020-04-22 20:00:44 +02:00
settings.beginGroup("Forms");
m_settings.m_formAppearanceFlags = static_cast<pdf::PDFFormManager::FormAppearanceFlags>(settings.value("formAppearance", int(pdf::PDFFormManager::getDefaultApperanceFlags())).toInt());
settings.endGroup();
2020-06-27 17:28:03 +02:00
settings.beginGroup("Signature");
m_settings.m_signatureVerificationEnabled = settings.value("signatureVerificationEnabled", defaultSettings.m_signatureVerificationEnabled).toBool();
m_settings.m_signatureTreatWarningsAsErrors = settings.value("signatureTreatWarningsAsErrors", defaultSettings.m_signatureTreatWarningsAsErrors).toBool();
m_settings.m_signatureIgnoreCertificateValidityTime = settings.value("signatureIgnoreCertificateValidityTime", defaultSettings.m_signatureIgnoreCertificateValidityTime).toBool();
m_settings.m_signatureUseSystemStore = settings.value("signatureUseSystemStore", defaultSettings.m_signatureUseSystemStore).toBool();
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);
2021-05-04 18:40:51 +02:00
settings.setValue("allowDeveloperMode", m_settings.m_allowDeveloperMode);
2020-05-03 18:52:22 +02:00
settings.setValue("multithreadingStrategy", static_cast<int>(m_settings.m_multithreadingStrategy));
2020-02-22 18:27:33 +01:00
settings.setValue("magnifierSize", m_settings.m_magnifierSize);
settings.setValue("magnifierZoom", m_settings.m_magnifierZoom);
2020-05-03 18:52:22 +02:00
settings.setValue("maximumUndoSteps", m_settings.m_maximumUndoSteps);
settings.setValue("maximumRedoSteps", m_settings.m_maximumRedoSteps);
2019-09-06 19:07:52 +02:00
settings.endGroup();
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("colorAdaptationXYZ", int(m_colorManagementSystemSettings.colorAdaptationXYZ));
settings.setValue("isBlackPointCompensationActive", m_colorManagementSystemSettings.isBlackPointCompensationActive);
settings.setValue("isWhitePaperColorTransformed", m_colorManagementSystemSettings.isWhitePaperColorTransformed);
settings.setValue("isConsiderOutputIntent", m_colorManagementSystemSettings.isConsiderOutputIntent);
settings.setValue("outputCS", m_colorManagementSystemSettings.outputCS);
settings.setValue("deviceGray", m_colorManagementSystemSettings.deviceGray);
settings.setValue("deviceRGB", m_colorManagementSystemSettings.deviceRGB);
settings.setValue("deviceCMYK", m_colorManagementSystemSettings.deviceCMYK);
2020-12-26 12:55:29 +01:00
settings.setValue("softProofingProfile", m_colorManagementSystemSettings.softProofingProfile);
settings.setValue("proofingIntent", int(m_colorManagementSystemSettings.proofingIntent));
settings.setValue("outOfGamutColor", m_colorManagementSystemSettings.outOfGamutColor);
2019-12-25 14:34:37 +01:00
settings.setValue("profileDirectory", m_colorManagementSystemSettings.profileDirectory);
settings.endGroup();
2020-02-13 18:31:00 +01:00
settings.beginGroup("SpeechSettings");
settings.setValue("speechEngine", m_settings.m_speechEngine);
settings.setValue("speechLocale", m_settings.m_speechLocale);
settings.setValue("speechVoice", m_settings.m_speechVoice);
settings.setValue("speechRate", m_settings.m_speechRate);
settings.setValue("speechPitch", m_settings.m_speechPitch);
settings.setValue("speechVolume", m_settings.m_speechVolume);
settings.endGroup();
2020-04-22 20:00:44 +02:00
settings.beginGroup("Forms");
settings.setValue("formAppearance", int(m_settings.m_formAppearanceFlags));
settings.endGroup();
2020-06-27 17:28:03 +02:00
settings.beginGroup("Signature");
settings.setValue("signatureVerificationEnabled", m_settings.m_signatureVerificationEnabled);
settings.setValue("signatureTreatWarningsAsErrors", m_settings.m_signatureTreatWarningsAsErrors);
settings.setValue("signatureIgnoreCertificateValidityTime", m_settings.m_signatureIgnoreCertificateValidityTime);
settings.setValue("signatureUseSystemStore", m_settings.m_signatureUseSystemStore);
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),
2021-05-04 18:40:51 +02:00
m_allowDeveloperMode(false),
2019-12-15 19:28:25 +01:00
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::AlwaysMultithreaded),
2020-02-13 18:31:00 +01:00
m_speechRate(0.0),
m_speechPitch(0.0),
2020-02-22 18:27:33 +01:00
m_speechVolume(1.0),
m_magnifierSize(100),
2020-04-22 20:00:44 +02:00
m_magnifierZoom(2.0),
2020-05-03 18:52:22 +02:00
m_maximumUndoSteps(5),
m_maximumRedoSteps(5),
2020-06-27 17:28:03 +02:00
m_formAppearanceFlags(pdf::PDFFormManager::getDefaultApperanceFlags()),
m_signatureVerificationEnabled(true),
m_signatureTreatWarningsAsErrors(false),
m_signatureIgnoreCertificateValidityTime(false),
m_signatureUseSystemStore(true)
2019-12-15 19:28:25 +01:00
{
}
2019-09-06 19:07:52 +02:00
} // namespace pdfviewer