mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2024-12-26 16:22:50 +01:00
DocDiff application: page added/removed
This commit is contained in:
parent
c00939f536
commit
c8c42ccaf0
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2021 Jakub Melka
|
||||
// Copyright (C) 2021 Jakub Melka
|
||||
//
|
||||
// This file is part of PDF4QT.
|
||||
//
|
||||
@ -464,6 +464,68 @@ void PDFDiff::performCompare(const std::vector<PDFDiffPageContext>& leftPrepared
|
||||
|
||||
const bool isAdded = flags.testFlag(AlgorithmLCS::Added);
|
||||
const bool isRemoved = flags.testFlag(AlgorithmLCS::Removed);
|
||||
const bool isReplaced = flags.testFlag(AlgorithmLCS::Replaced);
|
||||
|
||||
Q_ASSERT(isAdded || isRemoved || isReplaced);
|
||||
|
||||
// There are two cases. Some page content was replaced, or either
|
||||
// page range was added, or page range was removed.
|
||||
if (isReplaced)
|
||||
{
|
||||
for (auto it = range.first; it != range.second; ++i)
|
||||
{
|
||||
const AlgorithmLCS::SequenceItem& item = *it;
|
||||
if (item.isReplaced())
|
||||
{
|
||||
const bool isTextComparedAsVectorGraphics = m_options.testFlag(CompareTextsAsVector);
|
||||
const PDFDiffPageContext& leftPageContext = leftPreparedPages[item.index1];
|
||||
const PDFDiffPageContext& rightPageContext = rightPreparedPages[item.index2];
|
||||
|
||||
auto pageLeft = m_leftDocument->getCatalog()->getPage(leftPageContext.pageIndex);
|
||||
auto pageRight = m_rightDocument->getCatalog()->getPage(rightPageContext.pageIndex);
|
||||
PDFReal epsilon = (calculateEpsilonForPage(pageLeft) + calculateEpsilonForPage(pageRight)) * 0.5;
|
||||
|
||||
PDFDiffHelper::Differences differences = PDFDiffHelper::calculateDifferences(leftPageContext.graphicPieces, rightPageContext.graphicPieces, epsilon);
|
||||
|
||||
for (const PDFDiffHelper::GraphicPieceInfo& info : differences.left)
|
||||
{
|
||||
/*
|
||||
switch (info.type)
|
||||
{
|
||||
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
if (item.isAdded())
|
||||
{
|
||||
const PDFDiffPageContext& rightPageContext = rightPreparedPages[item.index2];
|
||||
m_result.addPageAdded(rightPageContext.pageIndex);
|
||||
}
|
||||
if (item.isRemoved())
|
||||
{
|
||||
const PDFDiffPageContext& leftPageContext = leftPreparedPages[item.index1];
|
||||
m_result.addPageRemoved(leftPageContext.pageIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto it = range.first; it != range.second; ++i)
|
||||
{
|
||||
const AlgorithmLCS::SequenceItem& item = *it;
|
||||
Q_ASSERT(item.isAdded() || item.isRemoved());
|
||||
|
||||
if (item.isAdded())
|
||||
{
|
||||
m_result.addPageAdded(rightPreparedPages[item.index2].pageIndex);
|
||||
}
|
||||
if (item.isRemoved())
|
||||
{
|
||||
m_result.addPageRemoved(leftPreparedPages[item.index1].pageIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -542,6 +604,28 @@ void PDFDiffResult::addPageMoved(PDFInteger pageIndex1, PDFInteger pageIndex2)
|
||||
m_differences.emplace_back(std::move(difference));
|
||||
}
|
||||
|
||||
void PDFDiffResult::addPageAdded(PDFInteger pageIndex)
|
||||
{
|
||||
Difference difference;
|
||||
|
||||
difference.type = Type::PageAdded;
|
||||
difference.pageIndex2 = pageIndex;
|
||||
difference.message = PDFDiff::tr("Page no. %1 was added.").arg(pageIndex + 1);
|
||||
|
||||
m_differences.emplace_back(std::move(difference));
|
||||
}
|
||||
|
||||
void PDFDiffResult::addPageRemoved(PDFInteger pageIndex)
|
||||
{
|
||||
Difference difference;
|
||||
|
||||
difference.type = Type::PageMoved;
|
||||
difference.pageIndex1 = pageIndex;
|
||||
difference.message = PDFDiff::tr("Page no. %1 was removed.").arg(pageIndex + 1);
|
||||
|
||||
m_differences.emplace_back(std::move(difference));
|
||||
}
|
||||
|
||||
PDFDiffHelper::Differences PDFDiffHelper::calculateDifferences(const GraphicPieceInfos& left,
|
||||
const GraphicPieceInfos& right,
|
||||
PDFReal epsilon)
|
||||
|
@ -42,7 +42,9 @@ public:
|
||||
enum class Type
|
||||
{
|
||||
Invalid,
|
||||
PageMoved
|
||||
PageMoved,
|
||||
PageAdded,
|
||||
PageRemoved
|
||||
};
|
||||
|
||||
struct Difference
|
||||
@ -59,6 +61,8 @@ public:
|
||||
const PDFOperationResult& getResult() const { return m_result; }
|
||||
|
||||
void addPageMoved(PDFInteger pageIndex1, PDFInteger pageIndex2);
|
||||
void addPageAdded(PDFInteger pageIndex);
|
||||
void addPageRemoved(PDFInteger pageIndex);
|
||||
|
||||
private:
|
||||
Differences m_differences;
|
||||
@ -79,12 +83,13 @@ public:
|
||||
|
||||
enum Option
|
||||
{
|
||||
None = 0x0000,
|
||||
Asynchronous = 0x0001, ///< Compare document asynchronously
|
||||
PC_Text = 0x0002, ///< Use text to compare pages (determine, which pages correspond to each other)
|
||||
PC_VectorGraphics = 0x0004, ///< Use vector graphics to compare pages (determine, which pages correspond to each other)
|
||||
PC_Images = 0x0008, ///< Use images to compare pages (determine, which pages correspond to each other)
|
||||
PC_Mesh = 0x0010, ///< Use mesh to compare pages (determine, which pages correspond to each other)
|
||||
None = 0x0000,
|
||||
Asynchronous = 0x0001, ///< Compare document asynchronously
|
||||
PC_Text = 0x0002, ///< Use text to compare pages (determine, which pages correspond to each other)
|
||||
PC_VectorGraphics = 0x0004, ///< Use vector graphics to compare pages (determine, which pages correspond to each other)
|
||||
PC_Images = 0x0008, ///< Use images to compare pages (determine, which pages correspond to each other)
|
||||
PC_Mesh = 0x0010, ///< Use mesh to compare pages (determine, which pages correspond to each other)
|
||||
CompareTextsAsVector = 0x0020, ///< Compare texts as vector graphics
|
||||
};
|
||||
Q_DECLARE_FLAGS(Options, Option)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user