Output preview plugin

This commit is contained in:
Jakub Melka 2021-01-30 18:54:38 +01:00
parent 1a13aa4e22
commit 8d6b47dbd4
12 changed files with 525 additions and 3 deletions

View File

@ -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<uint32_t>(m_spotColors.size(), MAX_SPOT_COLOR_COMPONENTS);
size_t minIndex = qMin<uint32_t>(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

View File

@ -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<SpotColorInfo> m_spotColors;
size_t m_activeSpotColors = 0;
};
/// Renders PDF pages with transparency, using 32-bit floating point precision.

View File

@ -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)."
}

View File

@ -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 <https://www.gnu.org/licenses/>.
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

View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/pdfplugins/outputpreview">
<file>preview.svg</file>
</qresource>
</RCC>

View File

@ -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 <https://www.gnu.org/licenses/>.
#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

View File

@ -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 <https://www.gnu.org/licenses/>.
#ifndef OUTPUTPREVIEWDIALOG_H
#define OUTPUTPREVIEWDIALOG_H
#include <QDialog>
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

View File

@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OutputPreviewDialog</class>
<widget class="QDialog" name="OutputPreviewDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>852</width>
<height>503</height>
</rect>
</property>
<property name="windowTitle">
<string>Output Preview</string>
</property>
<layout class="QVBoxLayout" name="outputPreviewDialogLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="3,1">
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="frameViewLayout">
<property name="spacing">
<number>0</number>
</property>
<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="QLabel" name="imageLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QScrollBar" name="verticalScrollBar">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="settingsGroupBox">
<property name="title">
<string>Settings</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="inksGroupBox">
<property name="title">
<string>Inks</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTreeView" name="treeView"/>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>OutputPreviewDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>OutputPreviewDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -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 <https://www.gnu.org/licenses/>.
#include "outputpreviewplugin.h"
#include "outputpreviewdialog.h"
#include "pdfdrawwidget.h"
#include <QAction>
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<QAction*> 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);
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
#ifndef OUTPUTPREVIEWPLUGIN_H
#define OUTPUTPREVIEWPLUGIN_H
#include "pdfplugin.h"
#include <QObject>
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<QAction*> getActions() const override;
private:
void onOutputPreviewTriggered();
void updateActions();
QAction* m_outputPreviewAction;
};
} // namespace pdfplugin
#endif // OUTPUTPREVIEWPLUGIN_H

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
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="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="preview.svg"
enable-background="new">
<defs
id="defs2">
<inkscape:path-effect
effect="spiro"
id="path-effect831"
is_visible="true" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="3.959798"
inkscape:cx="178.45235"
inkscape:cy="84.431316"
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="metadata5">
<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 />
<cc:license
rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
<dc:creator>
<cc:Agent>
<dc:title>Jakub Melka</dc:title>
</cc:Agent>
</dc:creator>
</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)">
<g
aria-label="👁"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:25.39999962px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
id="text839"
transform="matrix(1.35,0,0,1.35,-5.4088903,-98.643511)">
<path
d="m 26.095183,281.84479 q -0.954981,1.72393 -2.344043,2.93936 -3.336231,2.95176 -8.284766,2.95176 -4.948535,0 -8.2971674,-2.95176 -1.3890625,-1.21543 -2.3564453,-2.93936 0.9673828,-1.72392 2.3564453,-2.95175 3.3486324,-2.95176 8.2971674,-2.95176 4.948535,0 8.284766,2.95176 1.389062,1.22783 2.344043,2.95175 z m -2.021582,0 q -0.607715,-1.0666 -1.475879,-1.90996 -2.083594,-2.00918 -5.13457,-2.51767 1.32705,0.5705 2.133203,1.74873 0.818554,1.21543 0.818554,2.6789 0,1.45108 -0.806152,2.6417 -0.79375,1.19063 -2.095996,1.77354 4.489648,-0.76895 6.56084,-4.41524 z m -4.688086,0 q 0,-1.5875 -1.153418,-2.71611 -1.153418,-1.12861 -2.778125,-1.12861 -0.855762,0 -1.624707,0.34726 l -0.409277,-0.93017 q -4.502051,0.76894 -6.5856447,4.42763 0.6077148,1.06661 1.4634765,1.89756 2.0711912,1.99678 5.0849612,2.51768 -1.302246,-0.58291 -2.095996,-1.77354 -0.79375,-1.19062 -0.79375,-2.6417 0,-0.88056 0.310058,-1.71152 l 0.992188,0.31006 q -0.272852,0.68213 -0.272852,1.40146 0,1.59991 1.153418,2.72852 1.153418,1.11621 2.778125,1.11621 1.624707,0 2.778125,-1.11621 1.153418,-1.12861 1.153418,-2.72852 z m -0.95498,0 q 0,1.20303 -0.880567,2.05879 -0.868164,0.85576 -2.095996,0.85576 -1.240234,0 -2.108398,-0.85576 -0.868164,-0.85576 -0.868164,-2.05879 0,-0.5333 0.186035,-1.02939 l 3.038574,1.37666 -1.42627,-3.01377 q 0.558106,-0.24805 1.178223,-0.24805 1.227832,0 2.095996,0.85576 0.880567,0.85577 0.880567,2.05879 z"
style="stroke-width:0.26458332"
id="path845"
inkscape:connector-curvature="0"
sodipodi:insensitive="true" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -21,6 +21,7 @@ TEMPLATE = subdirs
SUBDIRS += \
DimensionsPlugin \
SoftProofingPlugin \
RedactPlugin
RedactPlugin \
OutputPreviewPlugin