From 8d6b47dbd41441652f75678365b8f178bb398bd4 Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Sat, 30 Jan 2021 18:54:38 +0100 Subject: [PATCH] Output preview plugin --- Pdf4QtLib/sources/pdftransparencyrenderer.cpp | 17 ++- Pdf4QtLib/sources/pdftransparencyrenderer.h | 8 ++ .../OutputPreviewPlugin.json | 7 + .../OutputPreviewPlugin.pro | 52 +++++++ .../OutputPreviewPlugin/icons.qrc | 5 + .../outputpreviewdialog.cpp | 36 +++++ .../OutputPreviewPlugin/outputpreviewdialog.h | 45 ++++++ .../outputpreviewdialog.ui | 132 ++++++++++++++++++ .../outputpreviewplugin.cpp | 74 ++++++++++ .../OutputPreviewPlugin/outputpreviewplugin.h | 52 +++++++ .../OutputPreviewPlugin/preview.svg | 97 +++++++++++++ Pdf4QtViewerPlugins/Pdf4QtViewerPlugins.pro | 3 +- 12 files changed, 525 insertions(+), 3 deletions(-) create mode 100644 Pdf4QtViewerPlugins/OutputPreviewPlugin/OutputPreviewPlugin.json create mode 100644 Pdf4QtViewerPlugins/OutputPreviewPlugin/OutputPreviewPlugin.pro create mode 100644 Pdf4QtViewerPlugins/OutputPreviewPlugin/icons.qrc create mode 100644 Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewdialog.cpp create mode 100644 Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewdialog.h create mode 100644 Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewdialog.ui create mode 100644 Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewplugin.cpp create mode 100644 Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewplugin.h create mode 100644 Pdf4QtViewerPlugins/OutputPreviewPlugin/preview.svg diff --git a/Pdf4QtLib/sources/pdftransparencyrenderer.cpp b/Pdf4QtLib/sources/pdftransparencyrenderer.cpp index 4ec443b..e41f955 100644 --- a/Pdf4QtLib/sources/pdftransparencyrenderer.cpp +++ b/Pdf4QtLib/sources/pdftransparencyrenderer.cpp @@ -762,6 +762,7 @@ PDFInkMapper::PDFInkMapper(const PDFDocument* document) : void PDFInkMapper::createSpotColors(bool activate) { m_spotColors.clear(); + m_activeSpotColors = 0; const PDFCatalog* catalog = m_document->getCatalog(); const size_t pageCount = catalog->getPageCount(); @@ -821,7 +822,7 @@ void PDFInkMapper::createSpotColors(bool activate) { SpotColorInfo info; info.name = colorantInfo.name; - info.index = i; + info.index = uint32_t(i); info.colorSpace = colorSpacePointer; m_spotColors.emplace_back(qMove(info)); } @@ -841,11 +842,12 @@ void PDFInkMapper::createSpotColors(bool activate) if (activate) { - size_t minIndex = qMin(m_spotColors.size(), MAX_SPOT_COLOR_COMPONENTS); + size_t minIndex = qMin(uint32_t(m_spotColors.size()), MAX_SPOT_COLOR_COMPONENTS); for (size_t i = 0; i < minIndex; ++i) { m_spotColors[i].active = true; } + m_activeSpotColors = minIndex; } } @@ -854,4 +856,15 @@ bool PDFInkMapper::containsSpotColor(const QByteArray& colorName) const return getSpotColor(colorName) != nullptr; } +const PDFInkMapper::SpotColorInfo* PDFInkMapper::getSpotColor(const QByteArray& colorName) const +{ + auto it = std::find_if(m_spotColors.cbegin(), m_spotColors.cend(), [&colorName](const auto& info) { return info.name == colorName; }); + if (it != m_spotColors.cend()) + { + return &*it; + } + + return nullptr; +} + } // namespace pdf diff --git a/Pdf4QtLib/sources/pdftransparencyrenderer.h b/Pdf4QtLib/sources/pdftransparencyrenderer.h index fdf3d43..7ac214e 100644 --- a/Pdf4QtLib/sources/pdftransparencyrenderer.h +++ b/Pdf4QtLib/sources/pdftransparencyrenderer.h @@ -262,10 +262,18 @@ public: /// \param colorName Color name bool containsSpotColor(const QByteArray& colorName) const; + /// Returns number of active spot colors + size_t getActiveSpotColorCount() const { return m_activeSpotColors; } + + /// Returns spot color information (or nullptr, if spot color is not present) + /// \param colorName Color name + const SpotColorInfo* getSpotColor(const QByteArray& colorName) const; + private: const PDFDocument* m_document; std::vector m_spotColors; + size_t m_activeSpotColors = 0; }; /// Renders PDF pages with transparency, using 32-bit floating point precision. diff --git a/Pdf4QtViewerPlugins/OutputPreviewPlugin/OutputPreviewPlugin.json b/Pdf4QtViewerPlugins/OutputPreviewPlugin/OutputPreviewPlugin.json new file mode 100644 index 0000000..3030e3c --- /dev/null +++ b/Pdf4QtViewerPlugins/OutputPreviewPlugin/OutputPreviewPlugin.json @@ -0,0 +1,7 @@ +{ + "Name" : "OutputPreview", + "Author" : "Jakub Melka", + "Version" : "1.0.0", + "License" : "LGPL v3", + "Description" : "View prepress output preview (overprint, spot colors, advanced transparency)." +} diff --git a/Pdf4QtViewerPlugins/OutputPreviewPlugin/OutputPreviewPlugin.pro b/Pdf4QtViewerPlugins/OutputPreviewPlugin/OutputPreviewPlugin.pro new file mode 100644 index 0000000..b531d2f --- /dev/null +++ b/Pdf4QtViewerPlugins/OutputPreviewPlugin/OutputPreviewPlugin.pro @@ -0,0 +1,52 @@ +# Copyright (C) 2021 Jakub Melka +# +# This file is part of Pdf4Qt. +# +# Pdf4Qt 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. +# +# Pdf4Qt 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 Pdf4Qt. If not, see . + +TEMPLATE = lib +DEFINES += OUTPUTPREVIEWPLUGIN_LIBRARY + +QT += gui widgets + +LIBS += -L$$OUT_PWD/../.. + +LIBS += -lPdf4QtLib + +QMAKE_CXXFLAGS += /std:c++latest /utf-8 + +INCLUDEPATH += $$PWD/../../Pdf4QtLib/Sources + +DESTDIR = $$OUT_PWD/../../pdfplugins + +CONFIG += c++11 + +SOURCES += \ + outputpreviewdialog.cpp \ + outputpreviewplugin.cpp + +HEADERS += \ + outputpreviewdialog.h \ + outputpreviewplugin.h + +CONFIG += force_debug_info + +DISTFILES += \ + OutputPreviewPlugin.json + +RESOURCES += \ + icons.qrc + +FORMS += \ + outputpreviewdialog.ui diff --git a/Pdf4QtViewerPlugins/OutputPreviewPlugin/icons.qrc b/Pdf4QtViewerPlugins/OutputPreviewPlugin/icons.qrc new file mode 100644 index 0000000..18865ff --- /dev/null +++ b/Pdf4QtViewerPlugins/OutputPreviewPlugin/icons.qrc @@ -0,0 +1,5 @@ + + + preview.svg + + diff --git a/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewdialog.cpp b/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewdialog.cpp new file mode 100644 index 0000000..9e2cbc2 --- /dev/null +++ b/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewdialog.cpp @@ -0,0 +1,36 @@ +// Copyright (C) 2021 Jakub Melka +// +// This file is part of Pdf4Qt. +// +// Pdf4Qt 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. +// +// Pdf4Qt 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 Pdf4Qt. If not, see . + +#include "outputpreviewdialog.h" +#include "ui_outputpreviewdialog.h" + +namespace pdfplugin +{ + +OutputPreviewDialog::OutputPreviewDialog(QWidget* parent) : + QDialog(parent), + ui(new Ui::OutputPreviewDialog) +{ + ui->setupUi(this); +} + +OutputPreviewDialog::~OutputPreviewDialog() +{ + delete ui; +} + +} // namespace pdfplugin diff --git a/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewdialog.h b/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewdialog.h new file mode 100644 index 0000000..e9f4872 --- /dev/null +++ b/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewdialog.h @@ -0,0 +1,45 @@ +// Copyright (C) 2021 Jakub Melka +// +// This file is part of Pdf4Qt. +// +// Pdf4Qt 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. +// +// Pdf4Qt 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 Pdf4Qt. If not, see . + +#ifndef OUTPUTPREVIEWDIALOG_H +#define OUTPUTPREVIEWDIALOG_H + +#include + +namespace Ui +{ +class OutputPreviewDialog; +} + +namespace pdfplugin +{ + +class OutputPreviewDialog : public QDialog +{ + Q_OBJECT + +public: + explicit OutputPreviewDialog(QWidget* parent); + virtual ~OutputPreviewDialog() override; + +private: + Ui::OutputPreviewDialog* ui; +}; + +} // namespace pdf + +#endif // OUTPUTPREVIEWDIALOG_H diff --git a/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewdialog.ui b/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewdialog.ui new file mode 100644 index 0000000..6231303 --- /dev/null +++ b/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewdialog.ui @@ -0,0 +1,132 @@ + + + OutputPreviewDialog + + + + 0 + 0 + 852 + 503 + + + + Output Preview + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + Qt::Vertical + + + + + + + + + + + + Settings + + + + + + + Inks + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + OutputPreviewDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + OutputPreviewDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewplugin.cpp b/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewplugin.cpp new file mode 100644 index 0000000..f97e49e --- /dev/null +++ b/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewplugin.cpp @@ -0,0 +1,74 @@ +// Copyright (C) 2021 Jakub Melka +// +// This file is part of Pdf4Qt. +// +// Pdf4Qt 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. +// +// Pdf4Qt 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 Pdf4Qt. If not, see . + +#include "outputpreviewplugin.h" +#include "outputpreviewdialog.h" +#include "pdfdrawwidget.h" + +#include + +namespace pdfplugin +{ + +OutputPreviewPlugin::OutputPreviewPlugin() : + pdf::PDFPlugin(nullptr), + m_outputPreviewAction(nullptr) +{ + +} + +void OutputPreviewPlugin::setWidget(pdf::PDFWidget* widget) +{ + Q_ASSERT(!m_widget); + + BaseClass::setWidget(widget); + + m_outputPreviewAction = new QAction(QIcon(":/pdfplugins/outputpreview/preview.svg"), tr("Output Preview"), this); + m_outputPreviewAction->setObjectName("actionOutputPreview_OutputPreview"); + + connect(m_outputPreviewAction, &QAction::triggered, this, &OutputPreviewPlugin::onOutputPreviewTriggered); + + updateActions(); +} + +void OutputPreviewPlugin::setDocument(const pdf::PDFModifiedDocument& document) +{ + BaseClass::setDocument(document); + + if (document.hasReset()) + { + updateActions(); + } +} + +std::vector OutputPreviewPlugin::getActions() const +{ + return { m_outputPreviewAction }; +} + +void OutputPreviewPlugin::onOutputPreviewTriggered() +{ + OutputPreviewDialog dialog(m_widget); + dialog.exec(); +} + +void OutputPreviewPlugin::updateActions() +{ + m_outputPreviewAction->setEnabled(m_widget && m_document); +} + +} diff --git a/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewplugin.h b/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewplugin.h new file mode 100644 index 0000000..7213993 --- /dev/null +++ b/Pdf4QtViewerPlugins/OutputPreviewPlugin/outputpreviewplugin.h @@ -0,0 +1,52 @@ +// Copyright (C) 2021 Jakub Melka +// +// This file is part of Pdf4Qt. +// +// Pdf4Qt 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. +// +// Pdf4Qt 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 Pdf4Qt. If not, see . + +#ifndef OUTPUTPREVIEWPLUGIN_H +#define OUTPUTPREVIEWPLUGIN_H + +#include "pdfplugin.h" + +#include + +namespace pdfplugin +{ + +class OutputPreviewPlugin : public pdf::PDFPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "Pdf4Qt.OutputPreviewPlugin" FILE "OutputPreviewPlugin.json") + +private: + using BaseClass = pdf::PDFPlugin; + +public: + OutputPreviewPlugin(); + + virtual void setWidget(pdf::PDFWidget* widget) override; + virtual void setDocument(const pdf::PDFModifiedDocument& document) override; + virtual std::vector getActions() const override; + +private: + void onOutputPreviewTriggered(); + void updateActions(); + + QAction* m_outputPreviewAction; +}; + +} // namespace pdfplugin + +#endif // OUTPUTPREVIEWPLUGIN_H diff --git a/Pdf4QtViewerPlugins/OutputPreviewPlugin/preview.svg b/Pdf4QtViewerPlugins/OutputPreviewPlugin/preview.svg new file mode 100644 index 0000000..a9b8d2c --- /dev/null +++ b/Pdf4QtViewerPlugins/OutputPreviewPlugin/preview.svg @@ -0,0 +1,97 @@ + + + + + + + + + + + + image/svg+xml + + + + + + Jakub Melka + + + + + + + + + + + + + + + + + + + diff --git a/Pdf4QtViewerPlugins/Pdf4QtViewerPlugins.pro b/Pdf4QtViewerPlugins/Pdf4QtViewerPlugins.pro index f439520..1aa0898 100644 --- a/Pdf4QtViewerPlugins/Pdf4QtViewerPlugins.pro +++ b/Pdf4QtViewerPlugins/Pdf4QtViewerPlugins.pro @@ -21,6 +21,7 @@ TEMPLATE = subdirs SUBDIRS += \ DimensionsPlugin \ SoftProofingPlugin \ - RedactPlugin + RedactPlugin \ + OutputPreviewPlugin