Ink coverage dialog

This commit is contained in:
Jakub Melka
2021-04-20 19:33:54 +02:00
parent cfedca6f4f
commit d8b5eed3a9
12 changed files with 829 additions and 5 deletions

View File

@ -1,4 +1,4 @@
// Copyright (C) 2019-2020 Jakub Melka
// Copyright (C) 2019-2021 Jakub Melka
//
// This file is part of Pdf4Qt.
//
@ -54,7 +54,7 @@ void PDFProgress::step()
if (emitSignal)
{
progressStep(newPercentage);
emit progressStep(newPercentage);
}
}

View File

@ -3853,12 +3853,14 @@ PDFInkCoverageCalculator::PDFInkCoverageCalculator(const PDFDocument* document,
const PDFCMSManager* cmsManager,
const PDFOptionalContentActivity* optionalContentActivity,
const PDFInkMapper* inkMapper,
PDFProgress* progress,
PDFTransparencyRendererSettings settings) :
m_document(document),
m_fontCache(fontCache),
m_cmsManager(cmsManager),
m_optionalContentActivity(optionalContentActivity),
m_inkMapper(inkMapper),
m_progress(progress),
m_settings(settings)
{
Q_ASSERT(m_document);
@ -3876,6 +3878,11 @@ void PDFInkCoverageCalculator::perform(QSize size, const std::vector<PDFInteger>
return;
}
if (m_progress)
{
m_progress->start(pages.size(), ProgressStartupInfo());
}
auto calculatePageCoverage = [this, size](PDFInteger pageIndex)
{
if (pageIndex >= PDFInteger(m_document->getCatalog()->getPageCount()))
@ -3971,11 +3978,27 @@ void PDFInkCoverageCalculator::perform(QSize size, const std::vector<PDFInteger>
results.emplace_back(qMove(info));
}
if (m_progress)
{
m_progress->step();
}
QMutexLocker lock(&m_mutex);
m_inkCoverageResults[pageIndex] = qMove(results);
};
PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Page, pages.begin(), pages.end(), calculatePageCoverage);
if (m_progress)
{
m_progress->finish();
}
}
void PDFInkCoverageCalculator::clear()
{
QMutexLocker lock(&m_mutex);
m_inkCoverageResults.clear();
}
const std::vector<PDFInkCoverageCalculator::InkCoverageChannelInfo>* PDFInkCoverageCalculator::getInkCoverage(PDFInteger pageIndex) const
@ -3990,4 +4013,27 @@ const std::vector<PDFInkCoverageCalculator::InkCoverageChannelInfo>* PDFInkCover
return &dummy;
}
const PDFInkCoverageCalculator::InkCoverageChannelInfo* PDFInkCoverageCalculator::findCoverageInfoByName(const std::vector<PDFInkCoverageCalculator::InkCoverageChannelInfo>& infos,
const QByteArray& name)
{
auto it = std::find_if(infos.cbegin(), infos.cend(), [&name](const auto& info) { return info.name == name; });
if (it != infos.cend())
{
return &*it;
}
return nullptr;
}
PDFInkCoverageCalculator::InkCoverageChannelInfo* PDFInkCoverageCalculator::findCoverageInfoByName(std::vector<PDFInkCoverageCalculator::InkCoverageChannelInfo>& infos, const QByteArray& name)
{
auto it = std::find_if(infos.begin(), infos.end(), [&name](const auto& info) { return info.name == name; });
if (it != infos.cend())
{
return &*it;
}
return nullptr;
}
} // namespace pdf

View File

@ -23,6 +23,7 @@
#include "pdfpagecontentprocessor.h"
#include "pdfconstants.h"
#include "pdfutils.h"
#include "pdfprogress.h"
#include <QImage>
@ -934,6 +935,7 @@ public:
const PDFCMSManager* cmsManager,
const PDFOptionalContentActivity* optionalContentActivity,
const PDFInkMapper* inkMapper,
PDFProgress* progress,
PDFTransparencyRendererSettings settings);
struct InkCoverageChannelInfo
@ -953,17 +955,35 @@ public:
/// \param pages Page indices
void perform(QSize size, const std::vector<PDFInteger>& pages);
/// Clear all calculated ink coverage results
void clear();
/// Clears calculated ink coverage for all pages. If ink coverage is not
/// calculated for given page index, empty vector is returned.
/// \param pageIndex Page index
const std::vector<InkCoverageChannelInfo>* getInkCoverage(PDFInteger pageIndex) const;
/// Find coverage info in vector by colorant name. If coverage info with a given colorant
/// name is not found, then nullptr is returned.
/// \param infos Vector of coverage info
/// \param name Colornant name
/// \returns Info for a given colorant name, or nullptr, if it is not found
static const InkCoverageChannelInfo* findCoverageInfoByName(const std::vector<InkCoverageChannelInfo>& infos, const QByteArray& name);
/// Find coverage info in vector by colorant name. If coverage info with a given colorant
/// name is not found, then nullptr is returned.
/// \param infos Vector of coverage info
/// \param name Colornant name
/// \returns Info for a given colorant name, or nullptr, if it is not found
static InkCoverageChannelInfo* findCoverageInfoByName(std::vector<InkCoverageChannelInfo>& infos, const QByteArray& name);
private:
const PDFDocument* m_document;
const PDFFontCache* m_fontCache;
const PDFCMSManager* m_cmsManager;
const PDFOptionalContentActivity* m_optionalContentActivity;
const PDFInkMapper* m_inkMapper;
PDFProgress* m_progress;
PDFTransparencyRendererSettings m_settings;
QMutex m_mutex;