From 65fd88aa71886e7d6e79ef1842fa3b5ad5847669 Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Sun, 19 Nov 2023 14:28:23 +0100 Subject: [PATCH] Issue #108: Add accessibility options in pdf reader [enhancement] - settings in ui, finish work --- Pdf4QtLib/sources/pdfcms.cpp | 9 ++- Pdf4QtLib/sources/pdfcms.h | 6 ++ Pdf4QtLib/sources/pdfcolorconvertor.cpp | 20 +++++ Pdf4QtLib/sources/pdfcolorconvertor.h | 11 +++ Pdf4QtViewer/pdfviewermainwindowlite.cpp | 6 +- Pdf4QtViewer/pdfviewermainwindowlite.ui | 78 ++++++++++++++++---- Pdf4QtViewer/pdfviewersettings.cpp | 8 ++ Pdf4QtViewer/pdfviewersettingsdialog.cpp | 42 ++++++++++- Pdf4QtViewer/pdfviewersettingsdialog.h | 1 + Pdf4QtViewer/pdfviewersettingsdialog.ui | 93 +++++++++++++++++++++++- 10 files changed, 256 insertions(+), 18 deletions(-) diff --git a/Pdf4QtLib/sources/pdfcms.cpp b/Pdf4QtLib/sources/pdfcms.cpp index ace9b93..567ec6a 100644 --- a/Pdf4QtLib/sources/pdfcms.cpp +++ b/Pdf4QtLib/sources/pdfcms.cpp @@ -1457,7 +1457,14 @@ void PDFCMSManager::setSettings(const PDFCMSSettings& settings) PDFColorConvertor PDFCMSManager::getColorConvertor() const { - return PDFColorConvertor(); + QMutexLocker lock(&m_mutex); + + PDFColorConvertor colorConvertor; + colorConvertor.setBackgroundColor(m_settings.backgroundColor); + colorConvertor.setForegroundColor(m_settings.foregroundColor); + colorConvertor.setHighContrastBrightnessFactor(m_settings.sigmoidSlopeFactor); + colorConvertor.setBitonalThreshold(m_settings.bitonalThreshold); + return colorConvertor; } const PDFColorProfileIdentifiers& PDFCMSManager::getOutputProfiles() const diff --git a/Pdf4QtLib/sources/pdfcms.h b/Pdf4QtLib/sources/pdfcms.h index a056c63..3686c3b 100644 --- a/Pdf4QtLib/sources/pdfcms.h +++ b/Pdf4QtLib/sources/pdfcms.h @@ -84,6 +84,12 @@ struct PDFCMSSettings QString deviceCMYK; ///< Identifiers for color space (device CMYK) QString softProofingProfile; ///< Identifiers for soft proofing profile QString profileDirectory; ///< Directory containing color profiles + + // Postprocessing + QColor foregroundColor = Qt::green; + QColor backgroundColor = Qt::black; + int bitonalThreshold = 128; + double sigmoidSlopeFactor = 10.0; }; /// Color management system base class. It contains functions to transform diff --git a/Pdf4QtLib/sources/pdfcolorconvertor.cpp b/Pdf4QtLib/sources/pdfcolorconvertor.cpp index 8b054ff..ce0d0e0 100644 --- a/Pdf4QtLib/sources/pdfcolorconvertor.cpp +++ b/Pdf4QtLib/sources/pdfcolorconvertor.cpp @@ -197,6 +197,26 @@ void PDFColorConvertor::calculateSigmoidParams() m_sigmoidParamC_Range = sigmoidParamC_Range(); } +QColor PDFColorConvertor::getForegroundColor() const +{ + return m_foregroundColor; +} + +QColor PDFColorConvertor::getBackgroundColor() const +{ + return m_backgroundColor; +} + +void PDFColorConvertor::setForegroundColor(const QColor& newForegroundColor) +{ + m_foregroundColor = newForegroundColor; +} + +void PDFColorConvertor::setBackgroundColor(const QColor& newBackgroundColor) +{ + m_backgroundColor = newBackgroundColor; +} + int PDFColorConvertor::getBitonalThreshold() const { return m_bitonalThreshold; diff --git a/Pdf4QtLib/sources/pdfcolorconvertor.h b/Pdf4QtLib/sources/pdfcolorconvertor.h index 71e4629..6a37788 100644 --- a/Pdf4QtLib/sources/pdfcolorconvertor.h +++ b/Pdf4QtLib/sources/pdfcolorconvertor.h @@ -92,6 +92,17 @@ public: /// to ensure accurate differentiation between light and dark areas in images. void setBitonalThreshold(int newBitonalThreshold); + /// Set background color + /// \param newBackgroundColor Background color + void setBackgroundColor(const QColor& newBackgroundColor); + + /// Set foreground color + /// \param newForegroundColor Foreground color + void setForegroundColor(const QColor& newForegroundColor); + + QColor getBackgroundColor() const; + QColor getForegroundColor() const; + private: /// Correct lightness using sigmoid function /// \return Adjusted lightness normalized in range [0.0, 1.0] diff --git a/Pdf4QtViewer/pdfviewermainwindowlite.cpp b/Pdf4QtViewer/pdfviewermainwindowlite.cpp index a5d7a9e..e5bdc65 100644 --- a/Pdf4QtViewer/pdfviewermainwindowlite.cpp +++ b/Pdf4QtViewer/pdfviewermainwindowlite.cpp @@ -120,7 +120,11 @@ PDFViewerMainWindowLite::PDFViewerMainWindowLite(QWidget* parent) : m_actionManager->setAction(PDFActionManager::RenderOptionSmoothPictures, ui->actionRenderOptionSmoothPictures); m_actionManager->setAction(PDFActionManager::RenderOptionIgnoreOptionalContentSettings, ui->actionRenderOptionIgnoreOptionalContentSettings); m_actionManager->setAction(PDFActionManager::RenderOptionDisplayAnnotations, ui->actionRenderOptionDisplayAnnotations); - m_actionManager->setAction(PDFActionManager::RenderOptionInvertColors, ui->actionInvertColors); + m_actionManager->setAction(PDFActionManager::RenderOptionInvertColors, ui->actionColorInvert); + m_actionManager->setAction(PDFActionManager::RenderOptionGrayscale, ui->actionColorGrayscale); + m_actionManager->setAction(PDFActionManager::RenderOptionHighContrast, ui->actionColorHighContrast); + m_actionManager->setAction(PDFActionManager::RenderOptionBitonal, ui->actionColorBitonal); + m_actionManager->setAction(PDFActionManager::RenderOptionCustomColors, ui->actionColorCustom); m_actionManager->setAction(PDFActionManager::Properties, ui->actionProperties); m_actionManager->setAction(PDFActionManager::Options, ui->actionOptions); m_actionManager->setAction(PDFActionManager::ResetToFactorySettings, ui->actionResetToFactorySettings); diff --git a/Pdf4QtViewer/pdfviewermainwindowlite.ui b/Pdf4QtViewer/pdfviewermainwindowlite.ui index 81860bf..a5b8e7c 100644 --- a/Pdf4QtViewer/pdfviewermainwindowlite.ui +++ b/Pdf4QtViewer/pdfviewermainwindowlite.ui @@ -87,7 +87,11 @@ - + + + + + @@ -349,18 +353,66 @@ Send by E-Mail... - - - true - - - - :/resources/invert-colors.svg:/resources/invert-colors.svg - - - Invert Colors - - + + + true + + + + :/resources/invert-colors.svg:/resources/invert-colors.svg + + + Color | Inverted + + + + + true + + + + :/resources/invert-colors.svg:/resources/invert-colors.svg + + + Color | Grayscale + + + + + true + + + + :/resources/invert-colors.svg:/resources/invert-colors.svg + + + Color | High Contrast + + + + + true + + + + :/resources/invert-colors.svg:/resources/invert-colors.svg + + + Color | Monochromatic + + + + + true + + + + :/resources/invert-colors.svg:/resources/invert-colors.svg + + + Color | Custom + + diff --git a/Pdf4QtViewer/pdfviewersettings.cpp b/Pdf4QtViewer/pdfviewersettings.cpp index eb75948..329c97c 100644 --- a/Pdf4QtViewer/pdfviewersettings.cpp +++ b/Pdf4QtViewer/pdfviewersettings.cpp @@ -78,6 +78,10 @@ void PDFViewerSettings::readSettings(QSettings& settings, const pdf::PDFCMSSetti m_colorManagementSystemSettings.proofingIntent = static_cast(settings.value("proofingIntent", int(defaultCMSSettings.proofingIntent)).toInt()); m_colorManagementSystemSettings.outOfGamutColor = settings.value("outOfGamutColor", defaultCMSSettings.outOfGamutColor).value(); m_colorManagementSystemSettings.profileDirectory = settings.value("profileDirectory", defaultCMSSettings.profileDirectory).toString(); + m_colorManagementSystemSettings.foregroundColor = settings.value("foregroundColor", defaultCMSSettings.foregroundColor).value(); + m_colorManagementSystemSettings.backgroundColor = settings.value("backgroundColor", defaultCMSSettings.backgroundColor).value(); + m_colorManagementSystemSettings.sigmoidSlopeFactor = settings.value("sigmoidSlopeFactor", defaultCMSSettings.sigmoidSlopeFactor).toDouble(); + m_colorManagementSystemSettings.bitonalThreshold = settings.value("bitonalThreshold",defaultCMSSettings.bitonalThreshold).toInt(); settings.endGroup(); settings.beginGroup("SpeechSettings"); @@ -145,6 +149,10 @@ void PDFViewerSettings::writeSettings(QSettings& settings) settings.setValue("proofingIntent", int(m_colorManagementSystemSettings.proofingIntent)); settings.setValue("outOfGamutColor", m_colorManagementSystemSettings.outOfGamutColor); settings.setValue("profileDirectory", m_colorManagementSystemSettings.profileDirectory); + settings.setValue("foregroundColor", m_colorManagementSystemSettings.foregroundColor); + settings.setValue("backgroundColor", m_colorManagementSystemSettings.backgroundColor); + settings.setValue("sigmoidSlopeFactor", m_colorManagementSystemSettings.sigmoidSlopeFactor); + settings.setValue("bitonalThreshold", m_colorManagementSystemSettings.bitonalThreshold); settings.endGroup(); settings.beginGroup("SpeechSettings"); diff --git a/Pdf4QtViewer/pdfviewersettingsdialog.cpp b/Pdf4QtViewer/pdfviewersettingsdialog.cpp index e029ab0..63edada 100644 --- a/Pdf4QtViewer/pdfviewersettingsdialog.cpp +++ b/Pdf4QtViewer/pdfviewersettingsdialog.cpp @@ -22,6 +22,7 @@ #include "pdfutils.h" #include "pdfwidgetutils.h" #include "pdfrecentfilemanager.h" +#include "pdfcolorconvertor.h" #include "pdfdbgheap.h" #include @@ -82,7 +83,8 @@ PDFViewerSettingsDialog::PDFViewerSettingsDialog(const PDFViewerSettings::Settin 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/shortcuts.svg"), tr("Shortcuts"), ui->optionsPagesWidget, ShortcutSettings); - new QListWidgetItem(QIcon(":/resources/cms.svg"), tr("Colors"), ui->optionsPagesWidget, ColorManagementSystemSettings); + new QListWidgetItem(QIcon(":/resources/cms.svg"), tr("Colors | CMS"), ui->optionsPagesWidget, ColorManagementSystemSettings); + new QListWidgetItem(QIcon(":/resources/cms.svg"), tr("Colors | Postprocessing"), ui->optionsPagesWidget, ColorPostprocessingSettings); new QListWidgetItem(QIcon(":/resources/security.svg"), tr("Security"), ui->optionsPagesWidget, SecuritySettings); new QListWidgetItem(QIcon(":/resources/ui.svg"), tr("UI"), ui->optionsPagesWidget, UISettings); new QListWidgetItem(QIcon(":/resources/speech.svg"), tr("Speech"), ui->optionsPagesWidget, SpeechSettings); @@ -146,7 +148,7 @@ PDFViewerSettingsDialog::PDFViewerSettingsDialog(const PDFViewerSettings::Settin fillColorProfileList(ui->cmsDeviceRGBColorProfileComboBox, cmsManager->getRGBProfiles()); fillColorProfileList(ui->cmsDeviceCMYKColorProfileComboBox, cmsManager->getCMYKProfiles()); - for (QWidget* widget : { ui->engineInfoLabel, ui->renderingInfoLabel, ui->securityInfoLabel, ui->cmsInfoLabel }) + for (QWidget* widget : { ui->engineInfoLabel, ui->renderingInfoLabel, ui->securityInfoLabel, ui->cmsInfoLabel, ui->colorPostProcessingInfoLabel }) { widget->setMinimumWidth(widget->sizeHint().width()); } @@ -236,6 +238,10 @@ void PDFViewerSettingsDialog::on_optionsPagesWidget_currentItemChanged(QListWidg ui->stackedWidget->setCurrentWidget(ui->cmsPage); break; + case ColorPostprocessingSettings: + ui->stackedWidget->setCurrentWidget(ui->cmsPostprocessingPage); + break; + case SecuritySettings: ui->stackedWidget->setCurrentWidget(ui->securityPage); break; @@ -386,6 +392,12 @@ void PDFViewerSettingsDialog::loadData() ui->cmsProfileDirectoryEdit->setText(QString()); } + // Color postprocessing + ui->foregroundColorEdit->setText(m_cmsSettings.foregroundColor.name(QColor::HexRgb)); + ui->backgroundColorEdit->setText(m_cmsSettings.backgroundColor.name(QColor::HexRgb)); + ui->sigmoidFunctionSlopeEdit->setValue(m_cmsSettings.sigmoidSlopeFactor); + ui->bitonalThresholdEdit->setValue(m_cmsSettings.bitonalThreshold); + // Text-to-speech ui->speechEnginesComboBox->setCurrentIndex(ui->speechEnginesComboBox->findData(m_settings.m_speechEngine)); setSpeechEngine(m_settings.m_speechEngine, m_settings.m_speechLocale); @@ -587,6 +599,32 @@ void PDFViewerSettingsDialog::saveData() { m_settings.m_magnifierZoom = ui->magnifierZoomEdit->value(); } + else if (sender == ui->foregroundColorEdit) + { + m_cmsSettings.foregroundColor.setNamedColor(ui->foregroundColorEdit->text()); + if (!m_cmsSettings.foregroundColor.isValid()) + { + pdf::PDFColorConvertor colorConvertor; + m_cmsSettings.foregroundColor = colorConvertor.getForegroundColor(); + } + } + else if (sender == ui->backgroundColorEdit) + { + m_cmsSettings.backgroundColor.setNamedColor(ui->backgroundColorEdit->text()); + if (!m_cmsSettings.backgroundColor.isValid()) + { + pdf::PDFColorConvertor colorConvertor; + m_cmsSettings.backgroundColor = colorConvertor.getBackgroundColor(); + } + } + else if (sender == ui->sigmoidFunctionSlopeEdit) + { + m_cmsSettings.sigmoidSlopeFactor = ui->sigmoidFunctionSlopeEdit->value(); + } + else if (sender == ui->bitonalThresholdEdit) + { + m_cmsSettings.bitonalThreshold = ui->bitonalThresholdEdit->value(); + } else if (sender == ui->formHighlightFieldsCheckBox) { m_settings.m_formAppearanceFlags.setFlag(pdf::PDFFormManager::HighlightFields, ui->formHighlightFieldsCheckBox->isChecked()); diff --git a/Pdf4QtViewer/pdfviewersettingsdialog.h b/Pdf4QtViewer/pdfviewersettingsdialog.h index c21563d..5a6eab1 100644 --- a/Pdf4QtViewer/pdfviewersettingsdialog.h +++ b/Pdf4QtViewer/pdfviewersettingsdialog.h @@ -74,6 +74,7 @@ public: CacheSettings, ShortcutSettings, ColorManagementSystemSettings, + ColorPostprocessingSettings, SecuritySettings, UISettings, SpeechSettings, diff --git a/Pdf4QtViewer/pdfviewersettingsdialog.ui b/Pdf4QtViewer/pdfviewersettingsdialog.ui index e947d20..ad687e1 100644 --- a/Pdf4QtViewer/pdfviewersettingsdialog.ui +++ b/Pdf4QtViewer/pdfviewersettingsdialog.ui @@ -35,7 +35,7 @@ - 7 + 6 @@ -792,6 +792,97 @@ + + + + + + Color Postprocessing + + + + + + + + + + + Sigmoid function slope parameter + + + + + + + Foreground color + + + + + + + + + + Background color + + + + + + + 1.000000000000000 + + + 100.000000000000000 + + + + + + + Bitonal threshold + + + + + + + 255 + + + + + + + + + <html><head/><body><p><span style=" font-weight:700;">Foreground</span> and <span style=" font-weight:700;">background</span> colors refer to a custom colors rendering mode, where two colors are used - the paper is drawn with the background color, and the foreground color is used for text and graphics. By default, the background is black and the foreground is green, which is easy on the eyes. </p><p><span style=" font-weight:700;">Sigmoid function slope parameter</span> is a parameter in high contrast color rendering. This rendering mode displays all graphics in high contrast. This parameter affects the degree of contrast. Set the value from 1 to 5 for a small contrast change, from 5 to 10 for a medium contrast change, and more than 10 for very high contrast rendering. </p><p><span style=" font-weight:700;">Bitonal threshold</span> is used in the bitonal rendering color mode. It distinguishes between black and white colors. However, the threshold for images is determined automatically. </p></body></html> + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + +