From 5cdb6cdab6500130a1f0b2c328ab4b4235e0c9e0 Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Mon, 27 Sep 2021 11:29:00 +0200 Subject: [PATCH] DocDiff application: line ending renormalization --- Pdf4QtDocDiff/Pdf4QtDocDiff.pro | 116 +- Pdf4QtDocDiff/aboutdialog.cpp | 128 +- Pdf4QtDocDiff/aboutdialog.h | 90 +- Pdf4QtDocDiff/aboutdialog.ui | 538 +++--- Pdf4QtDocDiff/main.cpp | 94 +- Pdf4QtDocDiff/mainwindow.cpp | 772 ++++---- Pdf4QtDocDiff/mainwindow.h | 206 +-- Pdf4QtDocDiff/mainwindow.ui | 360 ++-- Pdf4QtDocDiff/resources.qrc | 20 +- Pdf4QtLib/sources/pdfalgorithmlcs.cpp | 354 ++-- Pdf4QtLib/sources/pdfalgorithmlcs.h | 520 +++--- Pdf4QtLib/sources/pdfdiff.cpp | 2396 ++++++++++++------------- Pdf4QtLib/sources/pdfdiff.h | 446 ++--- 13 files changed, 3020 insertions(+), 3020 deletions(-) diff --git a/Pdf4QtDocDiff/Pdf4QtDocDiff.pro b/Pdf4QtDocDiff/Pdf4QtDocDiff.pro index 3a3b410..8fa4b56 100644 --- a/Pdf4QtDocDiff/Pdf4QtDocDiff.pro +++ b/Pdf4QtDocDiff/Pdf4QtDocDiff.pro @@ -1,58 +1,58 @@ -# 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 -# with the written consent of the copyright owner, 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 . - -QT += core gui widgets winextras - -TARGET = Pdf4QtDocDiff -TEMPLATE = app - -VERSION = 1.0.0 - -RC_ICONS = $$PWD/app-icon.ico - -QMAKE_TARGET_DESCRIPTION = "PDF Document Diff" -QMAKE_TARGET_COPYRIGHT = "(c) Jakub Melka 2018-2021" - -DEFINES += QT_DEPRECATED_WARNINGS -QMAKE_CXXFLAGS += /std:c++latest /utf-8 - -INCLUDEPATH += $$PWD/../PDF4QtLib/Sources -DESTDIR = $$OUT_PWD/.. -LIBS += -L$$OUT_PWD/.. -LIBS += -lPDF4QtLib -CONFIG += force_debug_info no_check_exist - -application.files = $$DESTDIR/Pdf4QtDocDiff.exe -application.path = $$DESTDIR/install -application.CONFIG += no_check_exist -INSTALLS += application - -SOURCES += \ - aboutdialog.cpp \ - main.cpp \ - mainwindow.cpp - -FORMS += \ - aboutdialog.ui \ - mainwindow.ui - -HEADERS += \ - aboutdialog.h \ - mainwindow.h - -RESOURCES += \ - resources.qrc +# 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 +# with the written consent of the copyright owner, 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 . + +QT += core gui widgets winextras + +TARGET = Pdf4QtDocDiff +TEMPLATE = app + +VERSION = 1.0.0 + +RC_ICONS = $$PWD/app-icon.ico + +QMAKE_TARGET_DESCRIPTION = "PDF Document Diff" +QMAKE_TARGET_COPYRIGHT = "(c) Jakub Melka 2018-2021" + +DEFINES += QT_DEPRECATED_WARNINGS +QMAKE_CXXFLAGS += /std:c++latest /utf-8 + +INCLUDEPATH += $$PWD/../PDF4QtLib/Sources +DESTDIR = $$OUT_PWD/.. +LIBS += -L$$OUT_PWD/.. +LIBS += -lPDF4QtLib +CONFIG += force_debug_info no_check_exist + +application.files = $$DESTDIR/Pdf4QtDocDiff.exe +application.path = $$DESTDIR/install +application.CONFIG += no_check_exist +INSTALLS += application + +SOURCES += \ + aboutdialog.cpp \ + main.cpp \ + mainwindow.cpp + +FORMS += \ + aboutdialog.ui \ + mainwindow.ui + +HEADERS += \ + aboutdialog.h \ + mainwindow.h + +RESOURCES += \ + resources.qrc diff --git a/Pdf4QtDocDiff/aboutdialog.cpp b/Pdf4QtDocDiff/aboutdialog.cpp index 0d987ce..3bd5dd9 100644 --- a/Pdf4QtDocDiff/aboutdialog.cpp +++ b/Pdf4QtDocDiff/aboutdialog.cpp @@ -1,64 +1,64 @@ -// 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 -// with the written consent of the copyright owner, 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 "aboutdialog.h" -#include "ui_aboutdialog.h" - -#include "pdfutils.h" -#include "pdfwidgetutils.h" - -namespace pdfdocdiff -{ - -PDFAboutDialog::PDFAboutDialog(QWidget* parent) : - QDialog(parent), - ui(new Ui::PDFAboutDialog) -{ - ui->setupUi(this); - - QString html = ui->copyrightLabel->text(); - html.replace("PdfForQtViewer", QApplication::applicationDisplayName()); - ui->copyrightLabel->setText(html); - - std::vector infos = pdf::PDFDependentLibraryInfo::getLibraryInfo(); - - ui->tableWidget->setColumnCount(4); - ui->tableWidget->setRowCount(static_cast(infos.size())); - ui->tableWidget->setHorizontalHeaderLabels(QStringList() << tr("Library") << tr("Version") << tr("License") << tr("URL")); - ui->tableWidget->setEditTriggers(QTableWidget::NoEditTriggers); - ui->tableWidget->setSelectionMode(QTableView::SingleSelection); - ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); - - for (int i = 0; i < infos.size(); ++i) - { - const pdf::PDFDependentLibraryInfo& info = infos[i]; - ui->tableWidget->setItem(i, 0, new QTableWidgetItem(info.library)); - ui->tableWidget->setItem(i, 1, new QTableWidgetItem(info.version)); - ui->tableWidget->setItem(i, 2, new QTableWidgetItem(info.license)); - ui->tableWidget->setItem(i, 3, new QTableWidgetItem(info.url)); - } - - pdf::PDFWidgetUtils::scaleWidget(this, QSize(750, 600)); - pdf::PDFWidgetUtils::style(this); -} - -PDFAboutDialog::~PDFAboutDialog() -{ - delete ui; -} - -} // namespace pdfdocdiff +// 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 +// with the written consent of the copyright owner, 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 "aboutdialog.h" +#include "ui_aboutdialog.h" + +#include "pdfutils.h" +#include "pdfwidgetutils.h" + +namespace pdfdocdiff +{ + +PDFAboutDialog::PDFAboutDialog(QWidget* parent) : + QDialog(parent), + ui(new Ui::PDFAboutDialog) +{ + ui->setupUi(this); + + QString html = ui->copyrightLabel->text(); + html.replace("PdfForQtViewer", QApplication::applicationDisplayName()); + ui->copyrightLabel->setText(html); + + std::vector infos = pdf::PDFDependentLibraryInfo::getLibraryInfo(); + + ui->tableWidget->setColumnCount(4); + ui->tableWidget->setRowCount(static_cast(infos.size())); + ui->tableWidget->setHorizontalHeaderLabels(QStringList() << tr("Library") << tr("Version") << tr("License") << tr("URL")); + ui->tableWidget->setEditTriggers(QTableWidget::NoEditTriggers); + ui->tableWidget->setSelectionMode(QTableView::SingleSelection); + ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + + for (int i = 0; i < infos.size(); ++i) + { + const pdf::PDFDependentLibraryInfo& info = infos[i]; + ui->tableWidget->setItem(i, 0, new QTableWidgetItem(info.library)); + ui->tableWidget->setItem(i, 1, new QTableWidgetItem(info.version)); + ui->tableWidget->setItem(i, 2, new QTableWidgetItem(info.license)); + ui->tableWidget->setItem(i, 3, new QTableWidgetItem(info.url)); + } + + pdf::PDFWidgetUtils::scaleWidget(this, QSize(750, 600)); + pdf::PDFWidgetUtils::style(this); +} + +PDFAboutDialog::~PDFAboutDialog() +{ + delete ui; +} + +} // namespace pdfdocdiff diff --git a/Pdf4QtDocDiff/aboutdialog.h b/Pdf4QtDocDiff/aboutdialog.h index 7a2f3c0..0f931fd 100644 --- a/Pdf4QtDocDiff/aboutdialog.h +++ b/Pdf4QtDocDiff/aboutdialog.h @@ -1,45 +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 -// with the written consent of the copyright owner, 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 PDFDOCDIFF_PDFABOUTDIALOG_H -#define PDFDOCDIFF_PDFABOUTDIALOG_H - -#include - -namespace Ui -{ -class PDFAboutDialog; -} - -namespace pdfdocdiff -{ - -class PDFAboutDialog : public QDialog -{ - Q_OBJECT - -public: - explicit PDFAboutDialog(QWidget* parent); - virtual ~PDFAboutDialog() override; - -private: - Ui::PDFAboutDialog* ui; -}; - -} // namespace pdfdocdiff - -#endif // PDFDOCDIFF_PDFABOUTDIALOG_H +// 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 +// with the written consent of the copyright owner, 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 PDFDOCDIFF_PDFABOUTDIALOG_H +#define PDFDOCDIFF_PDFABOUTDIALOG_H + +#include + +namespace Ui +{ +class PDFAboutDialog; +} + +namespace pdfdocdiff +{ + +class PDFAboutDialog : public QDialog +{ + Q_OBJECT + +public: + explicit PDFAboutDialog(QWidget* parent); + virtual ~PDFAboutDialog() override; + +private: + Ui::PDFAboutDialog* ui; +}; + +} // namespace pdfdocdiff + +#endif // PDFDOCDIFF_PDFABOUTDIALOG_H diff --git a/Pdf4QtDocDiff/aboutdialog.ui b/Pdf4QtDocDiff/aboutdialog.ui index 7c9489e..8cef7a9 100644 --- a/Pdf4QtDocDiff/aboutdialog.ui +++ b/Pdf4QtDocDiff/aboutdialog.ui @@ -1,269 +1,269 @@ - - - PDFAboutDialog - - - - 0 - 0 - 900 - 600 - - - - - 900 - 600 - - - - About - - - - - - <html><head/><body><p><span style=" font-weight:600;">PdfForQtViewer</span></p><p>Copyright 2018-2021 Jakub Melka. All rights reserved.</p><p>THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p></body></html> - - - true - - - - - - - true - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.875pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> GNU LESSER GENERAL PUBLIC LICENSE</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Version 3, 29 June 2007</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Copyright (C) 2007 Free Software Foundation, Inc. &lt;https://fsf.org/&gt;</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Everyone is permitted to copy and distribute verbatim copies</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> of this license document, but changing it is not allowed.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> This version of the GNU Lesser General Public License incorporates</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">the terms and conditions of version 3 of the GNU General Public</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">License, supplemented by the additional permissions listed below.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 0. Additional Definitions.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> As used herein, &quot;this License&quot; refers to version 3 of the GNU Lesser</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">General Public License, and the &quot;GNU GPL&quot; refers to version 3 of the GNU</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">General Public License.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> &quot;The Library&quot; refers to a covered work governed by this License,</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">other than an Application or a Combined Work as defined below.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> An &quot;Application&quot; is any work that makes use of an interface provided</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">by the Library, but which is not otherwise based on the Library.</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Defining a subclass of a class defined by the Library is deemed a mode</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">of using an interface provided by the Library.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> A &quot;Combined Work&quot; is a work produced by combining or linking an</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Application with the Library. The particular version of the Library</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">with which the Combined Work was made is also called the &quot;Linked</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Version&quot;.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> The &quot;Minimal Corresponding Source&quot; for a Combined Work means the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Corresponding Source for the Combined Work, excluding any source code</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">for portions of the Combined Work that, considered in isolation, are</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">based on the Application, and not on the Linked Version.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> The &quot;Corresponding Application Code&quot; for a Combined Work means the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">object code and/or source code for the Application, including any data</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">and utility programs needed for reproducing the Combined Work from the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Application, but excluding the System Libraries of the Combined Work.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 1. Exception to Section 3 of the GNU GPL.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> You may convey a covered work under sections 3 and 4 of this License</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">without being bound by section 3 of the GNU GPL.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 2. Conveying Modified Versions.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> If you modify a copy of the Library, and, in your modifications, a</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">facility refers to a function or data to be supplied by an Application</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">that uses the facility (other than as an argument passed when the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">facility is invoked), then you may convey a copy of the modified</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">version:</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> a) under this License, provided that you make a good faith effort to</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> ensure that, in the event an Application does not supply the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> function or data, the facility still operates, and performs</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> whatever part of its purpose remains meaningful, or</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> b) under the GNU GPL, with none of the additional permissions of</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> this License applicable to that copy.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 3. Object Code Incorporating Material from Library Header Files.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> The object code form of an Application may incorporate material from</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">a header file that is part of the Library. You may convey such object</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">code under terms of your choice, provided that, if the incorporated</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">material is not limited to numerical parameters, data structure</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">layouts and accessors, or small macros, inline functions and templates</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">(ten or fewer lines in length), you do both of the following:</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> a) Give prominent notice with each copy of the object code that the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Library is used in it and that the Library and its use are</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> covered by this License.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> b) Accompany the object code with a copy of the GNU GPL and this license</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> document.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 4. Combined Works.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> You may convey a Combined Work under terms of your choice that,</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">taken together, effectively do not restrict modification of the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">portions of the Library contained in the Combined Work and reverse</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">engineering for debugging such modifications, if you also do each of</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">the following:</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> a) Give prominent notice with each copy of the Combined Work that</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> the Library is used in it and that the Library and its use are</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> covered by this License.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> b) Accompany the Combined Work with a copy of the GNU GPL and this license</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> document.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> c) For a Combined Work that displays copyright notices during</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> execution, include the copyright notice for the Library among</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> these notices, as well as a reference directing the user to the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> copies of the GNU GPL and this license document.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> d) Do one of the following:</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 0) Convey the Minimal Corresponding Source under the terms of this</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> License, and the Corresponding Application Code in a form</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> suitable for, and under terms that permit, the user to</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> recombine or relink the Application with a modified version of</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> the Linked Version to produce a modified Combined Work, in the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> manner specified by section 6 of the GNU GPL for conveying</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Corresponding Source.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 1) Use a suitable shared library mechanism for linking with the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Library. A suitable mechanism is one that (a) uses at run time</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> a copy of the Library already present on the user's computer</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> system, and (b) will operate properly with a modified version</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> of the Library that is interface-compatible with the Linked</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Version.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> e) Provide Installation Information, but only if you would otherwise</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> be required to provide such information under section 6 of the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> GNU GPL, and only to the extent that such information is</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> necessary to install and execute a modified version of the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Combined Work produced by recombining or relinking the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Application with a modified version of the Linked Version. (If</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> you use option 4d0, the Installation Information must accompany</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> the Minimal Corresponding Source and Corresponding Application</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Code. If you use option 4d1, you must provide the Installation</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Information in the manner specified by section 6 of the GNU GPL</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> for conveying Corresponding Source.)</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 5. Combined Libraries.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> You may place library facilities that are a work based on the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Library side by side in a single library together with other library</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">facilities that are not Applications and are not covered by this</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">License, and convey such a combined library under terms of your</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">choice, if you do both of the following:</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> a) Accompany the combined library with a copy of the same work based</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> on the Library, uncombined with any other library facilities,</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> conveyed under the terms of this License.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> b) Give prominent notice with the combined library that part of it</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> is a work based on the Library, and explaining where to find the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> accompanying uncombined form of the same work.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 6. Revised Versions of the GNU Lesser General Public License.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> The Free Software Foundation may publish revised and/or new versions</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">of the GNU Lesser General Public License from time to time. Such new</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">versions will be similar in spirit to the present version, but may</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">differ in detail to address new problems or concerns.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Each version is given a distinguishing version number. If the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Library as you received it specifies that a certain numbered version</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">of the GNU Lesser General Public License &quot;or any later version&quot;</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">applies to it, you have the option of following the terms and</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">conditions either of that published version or of any later version</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">published by the Free Software Foundation. If the Library as you</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">received it does not specify a version number of the GNU Lesser</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">General Public License, you may choose any version of the GNU Lesser</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">General Public License ever published by the Free Software Foundation.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> If the Library as you received it specifies that a proxy can decide</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">whether future versions of the GNU Lesser General Public License shall</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">apply, that proxy's public statement of acceptance of any version is</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">permanent authorization for you to choose that version for the</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Library.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> - - - - - - - Used libraries - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - PDFAboutDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - PDFAboutDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - + + + PDFAboutDialog + + + + 0 + 0 + 900 + 600 + + + + + 900 + 600 + + + + About + + + + + + <html><head/><body><p><span style=" font-weight:600;">PdfForQtViewer</span></p><p>Copyright 2018-2021 Jakub Melka. All rights reserved.</p><p>THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p></body></html> + + + true + + + + + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.875pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> GNU LESSER GENERAL PUBLIC LICENSE</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Version 3, 29 June 2007</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Copyright (C) 2007 Free Software Foundation, Inc. &lt;https://fsf.org/&gt;</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Everyone is permitted to copy and distribute verbatim copies</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> of this license document, but changing it is not allowed.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> This version of the GNU Lesser General Public License incorporates</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">the terms and conditions of version 3 of the GNU General Public</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">License, supplemented by the additional permissions listed below.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 0. Additional Definitions.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> As used herein, &quot;this License&quot; refers to version 3 of the GNU Lesser</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">General Public License, and the &quot;GNU GPL&quot; refers to version 3 of the GNU</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">General Public License.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> &quot;The Library&quot; refers to a covered work governed by this License,</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">other than an Application or a Combined Work as defined below.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> An &quot;Application&quot; is any work that makes use of an interface provided</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">by the Library, but which is not otherwise based on the Library.</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Defining a subclass of a class defined by the Library is deemed a mode</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">of using an interface provided by the Library.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> A &quot;Combined Work&quot; is a work produced by combining or linking an</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Application with the Library. The particular version of the Library</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">with which the Combined Work was made is also called the &quot;Linked</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Version&quot;.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> The &quot;Minimal Corresponding Source&quot; for a Combined Work means the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Corresponding Source for the Combined Work, excluding any source code</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">for portions of the Combined Work that, considered in isolation, are</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">based on the Application, and not on the Linked Version.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> The &quot;Corresponding Application Code&quot; for a Combined Work means the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">object code and/or source code for the Application, including any data</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">and utility programs needed for reproducing the Combined Work from the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Application, but excluding the System Libraries of the Combined Work.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 1. Exception to Section 3 of the GNU GPL.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> You may convey a covered work under sections 3 and 4 of this License</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">without being bound by section 3 of the GNU GPL.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 2. Conveying Modified Versions.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> If you modify a copy of the Library, and, in your modifications, a</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">facility refers to a function or data to be supplied by an Application</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">that uses the facility (other than as an argument passed when the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">facility is invoked), then you may convey a copy of the modified</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">version:</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> a) under this License, provided that you make a good faith effort to</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> ensure that, in the event an Application does not supply the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> function or data, the facility still operates, and performs</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> whatever part of its purpose remains meaningful, or</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> b) under the GNU GPL, with none of the additional permissions of</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> this License applicable to that copy.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 3. Object Code Incorporating Material from Library Header Files.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> The object code form of an Application may incorporate material from</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">a header file that is part of the Library. You may convey such object</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">code under terms of your choice, provided that, if the incorporated</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">material is not limited to numerical parameters, data structure</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">layouts and accessors, or small macros, inline functions and templates</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">(ten or fewer lines in length), you do both of the following:</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> a) Give prominent notice with each copy of the object code that the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Library is used in it and that the Library and its use are</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> covered by this License.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> b) Accompany the object code with a copy of the GNU GPL and this license</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> document.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 4. Combined Works.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> You may convey a Combined Work under terms of your choice that,</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">taken together, effectively do not restrict modification of the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">portions of the Library contained in the Combined Work and reverse</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">engineering for debugging such modifications, if you also do each of</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">the following:</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> a) Give prominent notice with each copy of the Combined Work that</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> the Library is used in it and that the Library and its use are</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> covered by this License.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> b) Accompany the Combined Work with a copy of the GNU GPL and this license</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> document.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> c) For a Combined Work that displays copyright notices during</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> execution, include the copyright notice for the Library among</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> these notices, as well as a reference directing the user to the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> copies of the GNU GPL and this license document.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> d) Do one of the following:</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 0) Convey the Minimal Corresponding Source under the terms of this</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> License, and the Corresponding Application Code in a form</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> suitable for, and under terms that permit, the user to</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> recombine or relink the Application with a modified version of</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> the Linked Version to produce a modified Combined Work, in the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> manner specified by section 6 of the GNU GPL for conveying</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Corresponding Source.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 1) Use a suitable shared library mechanism for linking with the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Library. A suitable mechanism is one that (a) uses at run time</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> a copy of the Library already present on the user's computer</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> system, and (b) will operate properly with a modified version</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> of the Library that is interface-compatible with the Linked</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Version.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> e) Provide Installation Information, but only if you would otherwise</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> be required to provide such information under section 6 of the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> GNU GPL, and only to the extent that such information is</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> necessary to install and execute a modified version of the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Combined Work produced by recombining or relinking the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Application with a modified version of the Linked Version. (If</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> you use option 4d0, the Installation Information must accompany</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> the Minimal Corresponding Source and Corresponding Application</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Code. If you use option 4d1, you must provide the Installation</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Information in the manner specified by section 6 of the GNU GPL</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> for conveying Corresponding Source.)</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 5. Combined Libraries.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> You may place library facilities that are a work based on the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Library side by side in a single library together with other library</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">facilities that are not Applications and are not covered by this</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">License, and convey such a combined library under terms of your</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">choice, if you do both of the following:</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> a) Accompany the combined library with a copy of the same work based</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> on the Library, uncombined with any other library facilities,</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> conveyed under the terms of this License.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> b) Give prominent notice with the combined library that part of it</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> is a work based on the Library, and explaining where to find the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> accompanying uncombined form of the same work.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> 6. Revised Versions of the GNU Lesser General Public License.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> The Free Software Foundation may publish revised and/or new versions</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">of the GNU Lesser General Public License from time to time. Such new</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">versions will be similar in spirit to the present version, but may</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">differ in detail to address new problems or concerns.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> Each version is given a distinguishing version number. If the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Library as you received it specifies that a certain numbered version</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">of the GNU Lesser General Public License &quot;or any later version&quot;</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">applies to it, you have the option of following the terms and</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">conditions either of that published version or of any later version</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">published by the Free Software Foundation. If the Library as you</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">received it does not specify a version number of the GNU Lesser</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">General Public License, you may choose any version of the GNU Lesser</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">General Public License ever published by the Free Software Foundation.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> If the Library as you received it specifies that a proxy can decide</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">whether future versions of the GNU Lesser General Public License shall</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">apply, that proxy's public statement of acceptance of any version is</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">permanent authorization for you to choose that version for the</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Library.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + + + + + Used libraries + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + PDFAboutDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PDFAboutDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/Pdf4QtDocDiff/main.cpp b/Pdf4QtDocDiff/main.cpp index 526fd3c..ad0f7aa 100644 --- a/Pdf4QtDocDiff/main.cpp +++ b/Pdf4QtDocDiff/main.cpp @@ -1,47 +1,47 @@ -// 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 -// with the written consent of the copyright owner, 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 "pdfconstants.h" -#include "mainwindow.h" - -#include -#include - -int main(int argc, char *argv[]) -{ - QApplication::setAttribute(Qt::AA_CompressHighFrequencyEvents, true); - QApplication::setAttribute(Qt::AA_DisableHighDpiScaling, true); - QApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity, true); - QApplication application(argc, argv); - - QCoreApplication::setOrganizationName("MelkaJ"); - QCoreApplication::setApplicationName("PDF4QT Document Diff"); - QCoreApplication::setApplicationVersion(pdf::PDF_LIBRARY_VERSION); - QApplication::setApplicationDisplayName(QApplication::translate("Application", "PDF4QT Document Diff")); - QCommandLineParser parser; - parser.setApplicationDescription(QCoreApplication::applicationName()); - parser.addHelpOption(); - parser.addVersionOption(); - parser.addPositionalArgument("file1", "The PDF file to be compared."); - parser.addPositionalArgument("file2", "The PDF file to be compared."); - parser.process(application); - - pdfdocdiff::MainWindow mainWindow(nullptr); - mainWindow.show(); - - return application.exec(); -} +// 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 +// with the written consent of the copyright owner, 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 "pdfconstants.h" +#include "mainwindow.h" + +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication::setAttribute(Qt::AA_CompressHighFrequencyEvents, true); + QApplication::setAttribute(Qt::AA_DisableHighDpiScaling, true); + QApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity, true); + QApplication application(argc, argv); + + QCoreApplication::setOrganizationName("MelkaJ"); + QCoreApplication::setApplicationName("PDF4QT Document Diff"); + QCoreApplication::setApplicationVersion(pdf::PDF_LIBRARY_VERSION); + QApplication::setApplicationDisplayName(QApplication::translate("Application", "PDF4QT Document Diff")); + QCommandLineParser parser; + parser.setApplicationDescription(QCoreApplication::applicationName()); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument("file1", "The PDF file to be compared."); + parser.addPositionalArgument("file2", "The PDF file to be compared."); + parser.process(application); + + pdfdocdiff::MainWindow mainWindow(nullptr); + mainWindow.show(); + + return application.exec(); +} diff --git a/Pdf4QtDocDiff/mainwindow.cpp b/Pdf4QtDocDiff/mainwindow.cpp index 8f4b020..f4bb7d5 100644 --- a/Pdf4QtDocDiff/mainwindow.cpp +++ b/Pdf4QtDocDiff/mainwindow.cpp @@ -1,386 +1,386 @@ -// 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 -// with the written consent of the copyright owner, 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 "mainwindow.h" -#include "ui_mainwindow.h" - -#include "aboutdialog.h" - -#include "pdfwidgetutils.h" -#include "pdfdocumentreader.h" - -#include -#include -#include -#include -#include -#include - -namespace pdfdocdiff -{ - -MainWindow::MainWindow(QWidget* parent) : - QMainWindow(parent), - ui(new Ui::MainWindow), - m_progress(new pdf::PDFProgress(this)), - m_taskbarButton(new QWinTaskbarButton(this)), - m_progressTaskbarIndicator(nullptr), - m_diff(nullptr), - m_isChangingProgressStep(false), - m_dontDisplayErrorMessage(false) -{ - ui->setupUi(this); - - setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(800, 600))); - - // Initialize task bar progress - m_progressTaskbarIndicator = m_taskbarButton->progress(); - - ui->actionGet_Source->setData(int(Operation::GetSource)); - ui->actionAbout->setData(int(Operation::About)); - ui->actionOpen_Left->setData(int(Operation::OpenLeft)); - ui->actionOpen_Right->setData(int(Operation::OpenRight)); - ui->actionCompare->setData(int(Operation::Compare)); - ui->actionClose->setData(int(Operation::Close)); - - QToolBar* mainToolbar = addToolBar(tr("Main")); - mainToolbar->setObjectName("main_toolbar"); - mainToolbar->addActions({ ui->actionOpen_Left, ui->actionOpen_Right }); - mainToolbar->addSeparator(); - mainToolbar->addAction(ui->actionCompare); - - QSize iconSize = pdf::PDFWidgetUtils::scaleDPI(this, QSize(24, 24)); - auto toolbars = findChildren(); - for (QToolBar* toolbar : toolbars) - { - toolbar->setIconSize(iconSize); - ui->menuToolbars->addAction(toolbar->toggleViewAction()); - } - - connect(&m_mapper, QOverload::of(&QSignalMapper::mapped), this, &MainWindow::onMappedActionTriggered); - - QList actions = findChildren(); - for (QAction* action : actions) - { - QVariant actionData = action->data(); - if (actionData.isValid()) - { - connect(action, &QAction::triggered, &m_mapper, QOverload<>::of(&QSignalMapper::map)); - m_mapper.setMapping(action, actionData.toInt()); - } - } - - connect(m_progress, &pdf::PDFProgress::progressStarted, this, &MainWindow::onProgressStarted); - connect(m_progress, &pdf::PDFProgress::progressStep, this, &MainWindow::onProgressStep); - connect(m_progress, &pdf::PDFProgress::progressFinished, this, &MainWindow::onProgressFinished); - - m_diff.setProgress(m_progress); - m_diff.setOption(pdf::PDFDiff::Asynchronous, true); - connect(&m_diff, &pdf::PDFDiff::comparationFinished, this, &MainWindow::onComparationFinished); - - m_diff.setLeftDocument(&m_leftDocument); - m_diff.setRightDocument(&m_rightDocument); - - loadSettings(); - updateActions(); -} - -MainWindow::~MainWindow() -{ - saveSettings(); - delete ui; -} - -void MainWindow::showEvent(QShowEvent* event) -{ - Q_UNUSED(event); - m_taskbarButton->setWindow(windowHandle()); -} - -void MainWindow::closeEvent(QCloseEvent* event) -{ - BaseClass::closeEvent(event); - m_diff.stop(); -} - -void MainWindow::onMappedActionTriggered(int actionId) -{ - performOperation(static_cast(actionId)); -} - -void MainWindow::onComparationFinished() -{ - auto result = m_diff.getResult().getResult(); - if (!result && !m_dontDisplayErrorMessage) - { - QMessageBox::critical(this, tr("Error"), result.getErrorMessage()); - } -} - -void MainWindow::updateActions() -{ - QList actions = findChildren(); - for (QAction* action : actions) - { - QVariant actionData = action->data(); - if (actionData.isValid()) - { - action->setEnabled(canPerformOperation(static_cast(actionData.toInt()))); - } - } -} - -void MainWindow::loadSettings() -{ - QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName()); - settings.beginGroup("MainWindow"); - QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray(); - if (geometry.isEmpty()) - { - QRect availableGeometry = QApplication::desktop()->availableGeometry(this); - QRect windowRect(0, 0, availableGeometry.width() / 2, availableGeometry.height() / 2); - windowRect = windowRect.translated(availableGeometry.center() - windowRect.center()); - setGeometry(windowRect); - } - else - { - restoreGeometry(geometry); - } - - QByteArray state = settings.value("windowState", QByteArray()).toByteArray(); - if (!state.isEmpty()) - { - restoreState(state); - } - settings.endGroup(); - - settings.beginGroup("Settings"); - m_settings.directory = settings.value("directory").toString(); - settings.endGroup(); -} - -void MainWindow::saveSettings() -{ - QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName()); - settings.beginGroup("MainWindow"); - settings.setValue("geometry", saveGeometry()); - settings.setValue("windowState", saveState()); - settings.endGroup(); - - settings.beginGroup("Settings"); - settings.setValue("directory", m_settings.directory); - settings.endGroup(); -} - -bool MainWindow::canPerformOperation(Operation operation) const -{ - switch (operation) - { - case Operation::OpenLeft: - case Operation::OpenRight: - case Operation::Compare: - case Operation::Close: - case Operation::GetSource: - case Operation::About: - return true; - - default: - Q_ASSERT(false); - break; - } - - return false; -} - -void MainWindow::performOperation(Operation operation) -{ - switch (operation) - { - case Operation::OpenLeft: - { - pdf::PDFTemporaryValueChange guard(&m_dontDisplayErrorMessage, true); - m_diff.stop(); - - std::optional document = openDocument(); - if (document) - { - m_leftDocument = std::move(*document); - - const size_t pageCount = m_leftDocument.getCatalog()->getPageCount(); - if (pageCount > 1) - { - ui->leftPageSelectionEdit->setText(QString("1-%2").arg(pageCount)); - } - else if (pageCount == 1) - { - ui->leftPageSelectionEdit->setText("1"); - } - else - { - ui->leftPageSelectionEdit->clear(); - } - } - break; - } - - case Operation::OpenRight: - { - pdf::PDFTemporaryValueChange guard(&m_dontDisplayErrorMessage, true); - m_diff.stop(); - - std::optional document = openDocument(); - if (document) - { - m_rightDocument = std::move(*document); - - const size_t pageCount = m_rightDocument.getCatalog()->getPageCount(); - if (pageCount > 1) - { - ui->rightPageSelectionEdit->setText(QString("1-%2").arg(pageCount)); - } - else if (pageCount == 1) - { - ui->rightPageSelectionEdit->setText("1"); - } - else - { - ui->rightPageSelectionEdit->clear(); - } - } - break; - } - - case Operation::Compare: - { - pdf::PDFTemporaryValueChange guard(&m_dontDisplayErrorMessage, true); - m_diff.stop(); - - QString errorMessage; - - pdf::PDFClosedIntervalSet rightPageIndices; - pdf::PDFClosedIntervalSet leftPageIndices = pdf::PDFClosedIntervalSet::parse(1, qMax(1, m_leftDocument.getCatalog()->getPageCount()), ui->leftPageSelectionEdit->text(), &errorMessage); - - if (errorMessage.isEmpty()) - { - rightPageIndices = pdf::PDFClosedIntervalSet::parse(1, qMax(1, m_rightDocument.getCatalog()->getPageCount()), ui->rightPageSelectionEdit->text(), &errorMessage); - } - - // Check if pages are succesfully parsed - if (!errorMessage.isEmpty()) - { - QMessageBox::critical(this, tr("Error"), errorMessage); - break; - } - - leftPageIndices.translate(-1); - rightPageIndices.translate(-1); - - m_diff.setPagesForLeftDocument(std::move(leftPageIndices)); - m_diff.setPagesForRightDocument(std::move(rightPageIndices)); - - m_diff.start(); - break; - } - - case Operation::Close: - { - close(); - break; - } - - case Operation::GetSource: - { - QDesktopServices::openUrl(QUrl("https://github.com/JakubMelka/PDF4QT")); - break; - } - - case Operation::About: - { - PDFAboutDialog aboutDialog(this); - aboutDialog.exec(); - break; - } - default: - { - Q_ASSERT(false); - break; - } - } - - updateActions(); -} - -std::optional MainWindow::openDocument() -{ - QString fileName = QFileDialog::getOpenFileName(this, tr("Select PDF document"), m_settings.directory, tr("PDF document (*.pdf)")); - if (fileName.isEmpty()) - { - return std::nullopt; - } - - auto queryPassword = [this](bool* ok) - { - *ok = false; - return QInputDialog::getText(this, tr("Encrypted document"), tr("Enter password to access document content"), QLineEdit::Password, QString(), ok); - }; - - // Mark current directory as this - QFileInfo fileInfo(fileName); - m_settings.directory = fileInfo.dir().absolutePath(); - - // Try to open a new document - pdf::PDFDocumentReader reader(nullptr, qMove(queryPassword), true, false); - pdf::PDFDocument document = reader.readFromFile(fileName); - - QString errorMessage = reader.getErrorMessage(); - pdf::PDFDocumentReader::Result result = reader.getReadingResult(); - if (result == pdf::PDFDocumentReader::Result::OK) - { - return document; - } - else if (result == pdf::PDFDocumentReader::Result::Failed) - { - QMessageBox::critical(this, tr("Error"), errorMessage); - } - - return pdf::PDFDocument(); -} - -void MainWindow::onProgressStarted(pdf::ProgressStartupInfo info) -{ - m_progressTaskbarIndicator->setRange(0, 100); - m_progressTaskbarIndicator->reset(); - m_progressTaskbarIndicator->show(); -} - -void MainWindow::onProgressStep(int percentage) -{ - if (m_isChangingProgressStep) - { - return; - } - - pdf::PDFTemporaryValueChange guard(&m_isChangingProgressStep, true); - m_progressTaskbarIndicator->setValue(percentage); -} - -void MainWindow::onProgressFinished() -{ - m_progressTaskbarIndicator->hide(); -} - -} // namespace pdfdocdiff +// 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 +// with the written consent of the copyright owner, 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 "mainwindow.h" +#include "ui_mainwindow.h" + +#include "aboutdialog.h" + +#include "pdfwidgetutils.h" +#include "pdfdocumentreader.h" + +#include +#include +#include +#include +#include +#include + +namespace pdfdocdiff +{ + +MainWindow::MainWindow(QWidget* parent) : + QMainWindow(parent), + ui(new Ui::MainWindow), + m_progress(new pdf::PDFProgress(this)), + m_taskbarButton(new QWinTaskbarButton(this)), + m_progressTaskbarIndicator(nullptr), + m_diff(nullptr), + m_isChangingProgressStep(false), + m_dontDisplayErrorMessage(false) +{ + ui->setupUi(this); + + setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(800, 600))); + + // Initialize task bar progress + m_progressTaskbarIndicator = m_taskbarButton->progress(); + + ui->actionGet_Source->setData(int(Operation::GetSource)); + ui->actionAbout->setData(int(Operation::About)); + ui->actionOpen_Left->setData(int(Operation::OpenLeft)); + ui->actionOpen_Right->setData(int(Operation::OpenRight)); + ui->actionCompare->setData(int(Operation::Compare)); + ui->actionClose->setData(int(Operation::Close)); + + QToolBar* mainToolbar = addToolBar(tr("Main")); + mainToolbar->setObjectName("main_toolbar"); + mainToolbar->addActions({ ui->actionOpen_Left, ui->actionOpen_Right }); + mainToolbar->addSeparator(); + mainToolbar->addAction(ui->actionCompare); + + QSize iconSize = pdf::PDFWidgetUtils::scaleDPI(this, QSize(24, 24)); + auto toolbars = findChildren(); + for (QToolBar* toolbar : toolbars) + { + toolbar->setIconSize(iconSize); + ui->menuToolbars->addAction(toolbar->toggleViewAction()); + } + + connect(&m_mapper, QOverload::of(&QSignalMapper::mapped), this, &MainWindow::onMappedActionTriggered); + + QList actions = findChildren(); + for (QAction* action : actions) + { + QVariant actionData = action->data(); + if (actionData.isValid()) + { + connect(action, &QAction::triggered, &m_mapper, QOverload<>::of(&QSignalMapper::map)); + m_mapper.setMapping(action, actionData.toInt()); + } + } + + connect(m_progress, &pdf::PDFProgress::progressStarted, this, &MainWindow::onProgressStarted); + connect(m_progress, &pdf::PDFProgress::progressStep, this, &MainWindow::onProgressStep); + connect(m_progress, &pdf::PDFProgress::progressFinished, this, &MainWindow::onProgressFinished); + + m_diff.setProgress(m_progress); + m_diff.setOption(pdf::PDFDiff::Asynchronous, true); + connect(&m_diff, &pdf::PDFDiff::comparationFinished, this, &MainWindow::onComparationFinished); + + m_diff.setLeftDocument(&m_leftDocument); + m_diff.setRightDocument(&m_rightDocument); + + loadSettings(); + updateActions(); +} + +MainWindow::~MainWindow() +{ + saveSettings(); + delete ui; +} + +void MainWindow::showEvent(QShowEvent* event) +{ + Q_UNUSED(event); + m_taskbarButton->setWindow(windowHandle()); +} + +void MainWindow::closeEvent(QCloseEvent* event) +{ + BaseClass::closeEvent(event); + m_diff.stop(); +} + +void MainWindow::onMappedActionTriggered(int actionId) +{ + performOperation(static_cast(actionId)); +} + +void MainWindow::onComparationFinished() +{ + auto result = m_diff.getResult().getResult(); + if (!result && !m_dontDisplayErrorMessage) + { + QMessageBox::critical(this, tr("Error"), result.getErrorMessage()); + } +} + +void MainWindow::updateActions() +{ + QList actions = findChildren(); + for (QAction* action : actions) + { + QVariant actionData = action->data(); + if (actionData.isValid()) + { + action->setEnabled(canPerformOperation(static_cast(actionData.toInt()))); + } + } +} + +void MainWindow::loadSettings() +{ + QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName()); + settings.beginGroup("MainWindow"); + QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray(); + if (geometry.isEmpty()) + { + QRect availableGeometry = QApplication::desktop()->availableGeometry(this); + QRect windowRect(0, 0, availableGeometry.width() / 2, availableGeometry.height() / 2); + windowRect = windowRect.translated(availableGeometry.center() - windowRect.center()); + setGeometry(windowRect); + } + else + { + restoreGeometry(geometry); + } + + QByteArray state = settings.value("windowState", QByteArray()).toByteArray(); + if (!state.isEmpty()) + { + restoreState(state); + } + settings.endGroup(); + + settings.beginGroup("Settings"); + m_settings.directory = settings.value("directory").toString(); + settings.endGroup(); +} + +void MainWindow::saveSettings() +{ + QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName()); + settings.beginGroup("MainWindow"); + settings.setValue("geometry", saveGeometry()); + settings.setValue("windowState", saveState()); + settings.endGroup(); + + settings.beginGroup("Settings"); + settings.setValue("directory", m_settings.directory); + settings.endGroup(); +} + +bool MainWindow::canPerformOperation(Operation operation) const +{ + switch (operation) + { + case Operation::OpenLeft: + case Operation::OpenRight: + case Operation::Compare: + case Operation::Close: + case Operation::GetSource: + case Operation::About: + return true; + + default: + Q_ASSERT(false); + break; + } + + return false; +} + +void MainWindow::performOperation(Operation operation) +{ + switch (operation) + { + case Operation::OpenLeft: + { + pdf::PDFTemporaryValueChange guard(&m_dontDisplayErrorMessage, true); + m_diff.stop(); + + std::optional document = openDocument(); + if (document) + { + m_leftDocument = std::move(*document); + + const size_t pageCount = m_leftDocument.getCatalog()->getPageCount(); + if (pageCount > 1) + { + ui->leftPageSelectionEdit->setText(QString("1-%2").arg(pageCount)); + } + else if (pageCount == 1) + { + ui->leftPageSelectionEdit->setText("1"); + } + else + { + ui->leftPageSelectionEdit->clear(); + } + } + break; + } + + case Operation::OpenRight: + { + pdf::PDFTemporaryValueChange guard(&m_dontDisplayErrorMessage, true); + m_diff.stop(); + + std::optional document = openDocument(); + if (document) + { + m_rightDocument = std::move(*document); + + const size_t pageCount = m_rightDocument.getCatalog()->getPageCount(); + if (pageCount > 1) + { + ui->rightPageSelectionEdit->setText(QString("1-%2").arg(pageCount)); + } + else if (pageCount == 1) + { + ui->rightPageSelectionEdit->setText("1"); + } + else + { + ui->rightPageSelectionEdit->clear(); + } + } + break; + } + + case Operation::Compare: + { + pdf::PDFTemporaryValueChange guard(&m_dontDisplayErrorMessage, true); + m_diff.stop(); + + QString errorMessage; + + pdf::PDFClosedIntervalSet rightPageIndices; + pdf::PDFClosedIntervalSet leftPageIndices = pdf::PDFClosedIntervalSet::parse(1, qMax(1, m_leftDocument.getCatalog()->getPageCount()), ui->leftPageSelectionEdit->text(), &errorMessage); + + if (errorMessage.isEmpty()) + { + rightPageIndices = pdf::PDFClosedIntervalSet::parse(1, qMax(1, m_rightDocument.getCatalog()->getPageCount()), ui->rightPageSelectionEdit->text(), &errorMessage); + } + + // Check if pages are succesfully parsed + if (!errorMessage.isEmpty()) + { + QMessageBox::critical(this, tr("Error"), errorMessage); + break; + } + + leftPageIndices.translate(-1); + rightPageIndices.translate(-1); + + m_diff.setPagesForLeftDocument(std::move(leftPageIndices)); + m_diff.setPagesForRightDocument(std::move(rightPageIndices)); + + m_diff.start(); + break; + } + + case Operation::Close: + { + close(); + break; + } + + case Operation::GetSource: + { + QDesktopServices::openUrl(QUrl("https://github.com/JakubMelka/PDF4QT")); + break; + } + + case Operation::About: + { + PDFAboutDialog aboutDialog(this); + aboutDialog.exec(); + break; + } + default: + { + Q_ASSERT(false); + break; + } + } + + updateActions(); +} + +std::optional MainWindow::openDocument() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Select PDF document"), m_settings.directory, tr("PDF document (*.pdf)")); + if (fileName.isEmpty()) + { + return std::nullopt; + } + + auto queryPassword = [this](bool* ok) + { + *ok = false; + return QInputDialog::getText(this, tr("Encrypted document"), tr("Enter password to access document content"), QLineEdit::Password, QString(), ok); + }; + + // Mark current directory as this + QFileInfo fileInfo(fileName); + m_settings.directory = fileInfo.dir().absolutePath(); + + // Try to open a new document + pdf::PDFDocumentReader reader(nullptr, qMove(queryPassword), true, false); + pdf::PDFDocument document = reader.readFromFile(fileName); + + QString errorMessage = reader.getErrorMessage(); + pdf::PDFDocumentReader::Result result = reader.getReadingResult(); + if (result == pdf::PDFDocumentReader::Result::OK) + { + return document; + } + else if (result == pdf::PDFDocumentReader::Result::Failed) + { + QMessageBox::critical(this, tr("Error"), errorMessage); + } + + return pdf::PDFDocument(); +} + +void MainWindow::onProgressStarted(pdf::ProgressStartupInfo info) +{ + m_progressTaskbarIndicator->setRange(0, 100); + m_progressTaskbarIndicator->reset(); + m_progressTaskbarIndicator->show(); +} + +void MainWindow::onProgressStep(int percentage) +{ + if (m_isChangingProgressStep) + { + return; + } + + pdf::PDFTemporaryValueChange guard(&m_isChangingProgressStep, true); + m_progressTaskbarIndicator->setValue(percentage); +} + +void MainWindow::onProgressFinished() +{ + m_progressTaskbarIndicator->hide(); +} + +} // namespace pdfdocdiff diff --git a/Pdf4QtDocDiff/mainwindow.h b/Pdf4QtDocDiff/mainwindow.h index 38dd6c4..9feeeb7 100644 --- a/Pdf4QtDocDiff/mainwindow.h +++ b/Pdf4QtDocDiff/mainwindow.h @@ -1,103 +1,103 @@ -// 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 -// with the written consent of the copyright owner, 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 PDFDOCDIFF_MAINWINDOW_H -#define PDFDOCDIFF_MAINWINDOW_H - -#include "pdfdocument.h" -#include "pdfdiff.h" - -#include -#include -#include -#include - -namespace Ui -{ -class MainWindow; -} - -namespace pdfdocdiff -{ - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -private: - using BaseClass = QMainWindow; - -public: - explicit MainWindow(QWidget* parent); - virtual ~MainWindow() override; - - enum class Operation - { - OpenLeft, - OpenRight, - Compare, - Close, - GetSource, - About - }; - - virtual void showEvent(QShowEvent* event) override; - virtual void closeEvent(QCloseEvent* event) override; - -private slots: - void updateActions(); - -private: - void onMappedActionTriggered(int actionId); - void onComparationFinished(); - - void onProgressStarted(pdf::ProgressStartupInfo info); - void onProgressStep(int percentage); - void onProgressFinished(); - - void loadSettings(); - void saveSettings(); - - bool canPerformOperation(Operation operation) const; - void performOperation(Operation operation); - - std::optional openDocument(); - - struct Settings - { - QString directory; - }; - - Ui::MainWindow* ui; - - pdf::PDFProgress* m_progress; - QWinTaskbarButton* m_taskbarButton; - QWinTaskbarProgress* m_progressTaskbarIndicator; - - Settings m_settings; - QSignalMapper m_mapper; - pdf::PDFDiff m_diff; - bool m_isChangingProgressStep; - bool m_dontDisplayErrorMessage; - - pdf::PDFDocument m_leftDocument; - pdf::PDFDocument m_rightDocument; -}; - -} // namespace pdfdocdiff - -#endif // PDFDOCDIFF_MAINWINDOW_H +// 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 +// with the written consent of the copyright owner, 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 PDFDOCDIFF_MAINWINDOW_H +#define PDFDOCDIFF_MAINWINDOW_H + +#include "pdfdocument.h" +#include "pdfdiff.h" + +#include +#include +#include +#include + +namespace Ui +{ +class MainWindow; +} + +namespace pdfdocdiff +{ + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +private: + using BaseClass = QMainWindow; + +public: + explicit MainWindow(QWidget* parent); + virtual ~MainWindow() override; + + enum class Operation + { + OpenLeft, + OpenRight, + Compare, + Close, + GetSource, + About + }; + + virtual void showEvent(QShowEvent* event) override; + virtual void closeEvent(QCloseEvent* event) override; + +private slots: + void updateActions(); + +private: + void onMappedActionTriggered(int actionId); + void onComparationFinished(); + + void onProgressStarted(pdf::ProgressStartupInfo info); + void onProgressStep(int percentage); + void onProgressFinished(); + + void loadSettings(); + void saveSettings(); + + bool canPerformOperation(Operation operation) const; + void performOperation(Operation operation); + + std::optional openDocument(); + + struct Settings + { + QString directory; + }; + + Ui::MainWindow* ui; + + pdf::PDFProgress* m_progress; + QWinTaskbarButton* m_taskbarButton; + QWinTaskbarProgress* m_progressTaskbarIndicator; + + Settings m_settings; + QSignalMapper m_mapper; + pdf::PDFDiff m_diff; + bool m_isChangingProgressStep; + bool m_dontDisplayErrorMessage; + + pdf::PDFDocument m_leftDocument; + pdf::PDFDocument m_rightDocument; +}; + +} // namespace pdfdocdiff + +#endif // PDFDOCDIFF_MAINWINDOW_H diff --git a/Pdf4QtDocDiff/mainwindow.ui b/Pdf4QtDocDiff/mainwindow.ui index 4d72ba8..89744ec 100644 --- a/Pdf4QtDocDiff/mainwindow.ui +++ b/Pdf4QtDocDiff/mainwindow.ui @@ -1,180 +1,180 @@ - - - MainWindow - - - - 0 - 0 - 864 - 638 - - - - Workspace - - - - - - - Left - - - - - - Page Selection: - - - - - - - - - - - - - Right - - - - - - Page Selection: - - - - - - - - - - - - - QFrame::Box - - - QFrame::Raised - - - 3 - - - - - - - - - 0 - 0 - 864 - 21 - - - - - File - - - - - - - - Help - - - - - - - Toolbars - - - - - Compare - - - - - - - - - - - - - :/pdfdocdiff/resources/get-source.svg:/pdfdocdiff/resources/get-source.svg - - - Get Source - - - - - - :/pdfdocdiff/resources/about.svg:/pdfdocdiff/resources/about.svg - - - About - - - F1 - - - - - - :/pdfdocdiff/resources/open-left.svg:/pdfdocdiff/resources/open-left.svg - - - Open Left - - - - - - :/pdfdocdiff/resources/open-right.svg:/pdfdocdiff/resources/open-right.svg - - - Open Right - - - - - - :/pdfdocdiff/resources/compare.svg:/pdfdocdiff/resources/compare.svg - - - Compare - - - F5 - - - - - - :/pdfdocdiff/resources/close.svg:/pdfdocdiff/resources/close.svg - - - Close - - - Ctrl+F4 - - - - - - - - + + + MainWindow + + + + 0 + 0 + 864 + 638 + + + + Workspace + + + + + + + Left + + + + + + Page Selection: + + + + + + + + + + + + + Right + + + + + + Page Selection: + + + + + + + + + + + + + QFrame::Box + + + QFrame::Raised + + + 3 + + + + + + + + + 0 + 0 + 864 + 21 + + + + + File + + + + + + + + Help + + + + + + + Toolbars + + + + + Compare + + + + + + + + + + + + + :/pdfdocdiff/resources/get-source.svg:/pdfdocdiff/resources/get-source.svg + + + Get Source + + + + + + :/pdfdocdiff/resources/about.svg:/pdfdocdiff/resources/about.svg + + + About + + + F1 + + + + + + :/pdfdocdiff/resources/open-left.svg:/pdfdocdiff/resources/open-left.svg + + + Open Left + + + + + + :/pdfdocdiff/resources/open-right.svg:/pdfdocdiff/resources/open-right.svg + + + Open Right + + + + + + :/pdfdocdiff/resources/compare.svg:/pdfdocdiff/resources/compare.svg + + + Compare + + + F5 + + + + + + :/pdfdocdiff/resources/close.svg:/pdfdocdiff/resources/close.svg + + + Close + + + Ctrl+F4 + + + + + + + + diff --git a/Pdf4QtDocDiff/resources.qrc b/Pdf4QtDocDiff/resources.qrc index 87b0a23..5b734bb 100644 --- a/Pdf4QtDocDiff/resources.qrc +++ b/Pdf4QtDocDiff/resources.qrc @@ -1,10 +1,10 @@ - - - resources/about.svg - resources/close.svg - resources/compare.svg - resources/get-source.svg - resources/open-left.svg - resources/open-right.svg - - + + + resources/about.svg + resources/close.svg + resources/compare.svg + resources/get-source.svg + resources/open-left.svg + resources/open-right.svg + + diff --git a/Pdf4QtLib/sources/pdfalgorithmlcs.cpp b/Pdf4QtLib/sources/pdfalgorithmlcs.cpp index 5a3ea10..c9eedaa 100644 --- a/Pdf4QtLib/sources/pdfalgorithmlcs.cpp +++ b/Pdf4QtLib/sources/pdfalgorithmlcs.cpp @@ -1,177 +1,177 @@ -// 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 -// with the written consent of the copyright owner, 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 "pdfalgorithmlcs.h" - -namespace pdf -{ - -void PDFAlgorithmLongestCommonSubsequenceBase::markSequence(Sequence& sequence, - const std::vector& movedItemsLeft, - const std::vector& movedItemsRight) -{ - Sequence updatedSequence; - - Q_ASSERT(std::is_sorted(movedItemsLeft.cbegin(), movedItemsLeft.cend())); - Q_ASSERT(std::is_sorted(movedItemsRight.cbegin(), movedItemsRight.cend())); - - for (auto it = sequence.cbegin(); it != sequence.cend();) - { - if (it->isMatch()) - { - updatedSequence.push_back(*it); - ++it; - continue; - } - - Sequence leftItems; - Sequence rightItems; - - for (; it != sequence.cend() && !it->isMatch(); ++it) - { - const SequenceItem& currentItem = *it; - Q_ASSERT(currentItem.isLeft() || currentItem.isRight()); - - if (currentItem.isLeft()) - { - if (std::binary_search(movedItemsLeft.cbegin(), movedItemsLeft.cend(), currentItem.index1)) - { - SequenceItem item = *it; - item.markMovedLeft(); - updatedSequence.push_back(item); - } - else - { - leftItems.push_back(currentItem); - } - } - - if (currentItem.isRight()) - { - if (std::binary_search(movedItemsRight.cbegin(), movedItemsRight.cend(), currentItem.index2)) - { - SequenceItem item = *it; - item.markMovedRight(); - updatedSequence.push_back(item); - } - else - { - rightItems.push_back(currentItem); - } - } - } - - std::reverse(leftItems.begin(), leftItems.end()); - std::reverse(rightItems.begin(), rightItems.end()); - - bool isReplaced = !leftItems.empty() && !rightItems.empty(); - - while (!leftItems.empty() && !rightItems.empty()) - { - SequenceItem item; - item.index1 = leftItems.back().index1; - item.index2 = rightItems.back().index2; - item.markReplaced(); - updatedSequence.push_back(item); - - leftItems.pop_back(); - rightItems.pop_back(); - } - - while (!leftItems.empty()) - { - SequenceItem item = leftItems.back(); - item.markRemoved(); - - if (isReplaced) - { - item.markReplaced(); - } - - updatedSequence.push_back(item); - leftItems.pop_back(); - } - - while (!rightItems.empty()) - { - SequenceItem item = rightItems.back(); - item.markAdded(); - - if (isReplaced) - { - item.markReplaced(); - } - - updatedSequence.push_back(item); - rightItems.pop_back(); - } - } - - for (SequenceItem& item : updatedSequence) - { - if (item.isMatch() && !item.isRemoved() && !item.isReplaced() && !item.isAdded() && item.index1 != item.index2) - { - item.markMoved(); - } - } - - sequence = qMove(updatedSequence); -} - -PDFAlgorithmLongestCommonSubsequenceBase::SequenceItemRanges PDFAlgorithmLongestCommonSubsequenceBase::getModifiedRanges(Sequence& sequence) -{ - SequenceItemRanges result; - - for (auto it = sequence.begin(); it != sequence.end();) - { - const SequenceItem& item = *it; - if (!item.isModified()) - { - ++it; - continue; - } - - // Jakub Melka: now, we have iterator pointing on item, - // which has been modified. We will search for modification - // range. - - auto itEnd = it; - while (itEnd != sequence.end() && itEnd->isModified()) - { - ++itEnd; - } - - result.emplace_back(it, itEnd); - it = itEnd; - } - - return result; -} - -PDFAlgorithmLongestCommonSubsequenceBase::SequenceItemFlags PDFAlgorithmLongestCommonSubsequenceBase::collectFlags(const SequenceItemRange& range) -{ - SequenceItemFlags flags = 0; - - for (auto it = range.first; it != range.second; ++it) - { - flags |= it->flags; - } - - return flags; -} - -} // namespace pdf +// 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 +// with the written consent of the copyright owner, 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 "pdfalgorithmlcs.h" + +namespace pdf +{ + +void PDFAlgorithmLongestCommonSubsequenceBase::markSequence(Sequence& sequence, + const std::vector& movedItemsLeft, + const std::vector& movedItemsRight) +{ + Sequence updatedSequence; + + Q_ASSERT(std::is_sorted(movedItemsLeft.cbegin(), movedItemsLeft.cend())); + Q_ASSERT(std::is_sorted(movedItemsRight.cbegin(), movedItemsRight.cend())); + + for (auto it = sequence.cbegin(); it != sequence.cend();) + { + if (it->isMatch()) + { + updatedSequence.push_back(*it); + ++it; + continue; + } + + Sequence leftItems; + Sequence rightItems; + + for (; it != sequence.cend() && !it->isMatch(); ++it) + { + const SequenceItem& currentItem = *it; + Q_ASSERT(currentItem.isLeft() || currentItem.isRight()); + + if (currentItem.isLeft()) + { + if (std::binary_search(movedItemsLeft.cbegin(), movedItemsLeft.cend(), currentItem.index1)) + { + SequenceItem item = *it; + item.markMovedLeft(); + updatedSequence.push_back(item); + } + else + { + leftItems.push_back(currentItem); + } + } + + if (currentItem.isRight()) + { + if (std::binary_search(movedItemsRight.cbegin(), movedItemsRight.cend(), currentItem.index2)) + { + SequenceItem item = *it; + item.markMovedRight(); + updatedSequence.push_back(item); + } + else + { + rightItems.push_back(currentItem); + } + } + } + + std::reverse(leftItems.begin(), leftItems.end()); + std::reverse(rightItems.begin(), rightItems.end()); + + bool isReplaced = !leftItems.empty() && !rightItems.empty(); + + while (!leftItems.empty() && !rightItems.empty()) + { + SequenceItem item; + item.index1 = leftItems.back().index1; + item.index2 = rightItems.back().index2; + item.markReplaced(); + updatedSequence.push_back(item); + + leftItems.pop_back(); + rightItems.pop_back(); + } + + while (!leftItems.empty()) + { + SequenceItem item = leftItems.back(); + item.markRemoved(); + + if (isReplaced) + { + item.markReplaced(); + } + + updatedSequence.push_back(item); + leftItems.pop_back(); + } + + while (!rightItems.empty()) + { + SequenceItem item = rightItems.back(); + item.markAdded(); + + if (isReplaced) + { + item.markReplaced(); + } + + updatedSequence.push_back(item); + rightItems.pop_back(); + } + } + + for (SequenceItem& item : updatedSequence) + { + if (item.isMatch() && !item.isRemoved() && !item.isReplaced() && !item.isAdded() && item.index1 != item.index2) + { + item.markMoved(); + } + } + + sequence = qMove(updatedSequence); +} + +PDFAlgorithmLongestCommonSubsequenceBase::SequenceItemRanges PDFAlgorithmLongestCommonSubsequenceBase::getModifiedRanges(Sequence& sequence) +{ + SequenceItemRanges result; + + for (auto it = sequence.begin(); it != sequence.end();) + { + const SequenceItem& item = *it; + if (!item.isModified()) + { + ++it; + continue; + } + + // Jakub Melka: now, we have iterator pointing on item, + // which has been modified. We will search for modification + // range. + + auto itEnd = it; + while (itEnd != sequence.end() && itEnd->isModified()) + { + ++itEnd; + } + + result.emplace_back(it, itEnd); + it = itEnd; + } + + return result; +} + +PDFAlgorithmLongestCommonSubsequenceBase::SequenceItemFlags PDFAlgorithmLongestCommonSubsequenceBase::collectFlags(const SequenceItemRange& range) +{ + SequenceItemFlags flags = 0; + + for (auto it = range.first; it != range.second; ++it) + { + flags |= it->flags; + } + + return flags; +} + +} // namespace pdf diff --git a/Pdf4QtLib/sources/pdfalgorithmlcs.h b/Pdf4QtLib/sources/pdfalgorithmlcs.h index 781662e..f029553 100644 --- a/Pdf4QtLib/sources/pdfalgorithmlcs.h +++ b/Pdf4QtLib/sources/pdfalgorithmlcs.h @@ -1,260 +1,260 @@ -// 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 -// with the written consent of the copyright owner, 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 PDFALGORITHMLCS_H -#define PDFALGORITHMLCS_H - -#include "pdfglobal.h" - -namespace pdf -{ - -class PDFAlgorithmLongestCommonSubsequenceBase -{ -public: - - enum SequenceItemFlag - { - None = 0x0000, - MovedLeft = 0x0001, ///< Item has been moved from this position (is present in a sequence no. 1) - MovedRight = 0x0002, ///< Item has been moved to this position (is present in a sequence no. 2) - Moved = 0x0004, ///< Index of item has been changed - Added = 0x0008, ///< Item has been added to a sequence no. 2 - Removed = 0x0010, ///< Item has been removed from a sequence no. 1 - Replaced = 0x0020, ///< Item has been replaced (or sequence of items has been replaced) - }; - Q_DECLARE_FLAGS(SequenceItemFlags, SequenceItemFlag) - - struct SequenceItem - { - size_t index1 = std::numeric_limits::max(); - size_t index2 = std::numeric_limits::max(); - SequenceItemFlags flags = None; - - bool isLeftValid() const { return index1 != std::numeric_limits::max(); } - bool isRightValid() const { return index2 != std::numeric_limits::max(); } - bool isLeft() const { return isLeftValid() && !isRightValid(); } - bool isRight() const { return isRightValid() && !isLeftValid(); } - bool isMatch() const { return isLeftValid() && isRightValid(); } - bool isMovedLeft() const { return flags.testFlag(MovedLeft); } - bool isMovedRight() const { return flags.testFlag(MovedRight); } - bool isMoved() const { return flags.testFlag(Moved); } - bool isAdded() const { return flags.testFlag(Added); } - bool isRemoved() const { return flags.testFlag(Removed); } - bool isReplaced() const { return flags.testFlag(Replaced); } - bool isModified() const { return isAdded() || isRemoved() || isReplaced(); } - - void markMovedLeft() { flags.setFlag(MovedLeft); } - void markMovedRight() { flags.setFlag(MovedRight); } - void markMoved() { flags.setFlag(Moved); } - void markAdded() { flags.setFlag(Added); } - void markRemoved() { flags.setFlag(Removed); } - void markReplaced() { flags.setFlag(Replaced); } - }; - - using Sequence = typename std::vector; - using SequenceIterator = typename Sequence::iterator; - using SequenceItemRange = typename std::pair; - using SequenceItemRanges = typename std::vector; - - /// Marks a sequence with set of flags representing added/removed/replaced/moved - /// items. Moved items sequences must be sorted. - /// \param sequence Sequence to be marked - /// \param movedItemsLeft Sorted sequence of left indices, which have been moved - /// \param movedItemsRight sorted sequence of right indices, which have been moved - static void markSequence(Sequence& sequence, - const std::vector& movedItemsLeft, - const std::vector& movedItemsRight); - - /// Returns item ranges, which should be checked - for example, - /// for text modification. - /// \param sequence Sequence - static SequenceItemRanges getModifiedRanges(Sequence& sequence); - - /// Collect flags from given item range - /// \param range Range - static SequenceItemFlags collectFlags(const SequenceItemRange& range); -}; - -/// Algorithm for computing longest common subsequence, on two sequences -/// of objects, which are implementing operator "==" (equal operator). -/// Constructor takes bidirectional iterators to the sequence. So, iterators -/// are requred to be bidirectional. -template -class PDFAlgorithmLongestCommonSubsequence : public PDFAlgorithmLongestCommonSubsequenceBase -{ -public: - PDFAlgorithmLongestCommonSubsequence(Iterator it1, - Iterator it1End, - Iterator it2, - Iterator it2End, - Comparator comparator); - - - void perform(); - - const Sequence& getSequence() const { return m_sequence; } - -private: - Iterator m_it1; - Iterator m_it1End; - Iterator m_it2; - Iterator m_it2End; - - size_t m_size1; - size_t m_size2; - size_t m_matrixSize; - - Comparator m_comparator; - - std::vector m_backtrackData; - Sequence m_sequence; -}; - -template -PDFAlgorithmLongestCommonSubsequence::PDFAlgorithmLongestCommonSubsequence(Iterator it1, - Iterator it1End, - Iterator it2, - Iterator it2End, - Comparator comparator) : - m_it1(std::move(it1)), - m_it1End(std::move(it1End)), - m_it2(std::move(it2)), - m_it2End(std::move(it2End)), - m_size1(0), - m_size2(0), - m_matrixSize(0), - m_comparator(std::move(comparator)) -{ - m_size1 = std::distance(m_it1, m_it1End) + 1; - m_size2 = std::distance(m_it2, m_it2End) + 1; - m_matrixSize = m_size1 * m_size2; -} - -template -void PDFAlgorithmLongestCommonSubsequence::perform() -{ - m_backtrackData.resize(m_matrixSize); - m_sequence.clear(); - - std::vector rowTop(m_size1, size_t()); - std::vector rowBottom(m_size1, size_t()); - - // Jakub Melka: we will have columns consisting of it1...it1End - // and rows consisting of it2...it2End. We iterate trough rows, - // and for each row, we update longest common subsequence data. - - auto it2 = m_it2; - for (size_t i2 = 1; i2 < m_size2; ++i2, ++it2) - { - auto it1 = m_it1; - for (size_t i1 = 1; i1 < m_size1; ++i1, ++it1) - { - if (m_comparator(*it1, *it2)) - { - // We have match - rowBottom[i1] = rowTop[i1 - 1] + 1; - } - else - { - const size_t leftCellValue = rowBottom[i1 - 1]; - const size_t upperCellValue = rowTop[i1]; - bool isLeftBigger = leftCellValue > upperCellValue; - - if (isLeftBigger) - { - rowBottom[i1] = leftCellValue; - m_backtrackData[i2 * m_size1 + i1] = true; - } - else - { - rowBottom[i1] = upperCellValue; - m_backtrackData[i2 * m_size1 + i1] = false; - } - } - } - - // Bottom row will become top row - std::swap(rowTop, rowBottom); - } - - size_t i1 = m_size1 - 1; - size_t i2 = m_size2 - 1; - - while (i1 > 0 && i2 > 0) - { - SequenceItem item; - - const size_t index1 = i1 - 1; - const size_t index2 = i2 - 1; - - auto it1 = std::next(m_it1, index1); - auto it2 = std::next(m_it2, index2); - - if (m_comparator(*it1, *it2)) - { - item.index1 = index1; - item.index2 = index2; - - --i1; - --i2; - } - else - { - if (m_backtrackData[i2 * m_size1 + i1]) - { - item.index1 = index1; - --i1; - } - else - { - item.index2 = index2; - --i2; - } - } - - m_sequence.push_back(item); - } - - while (i1 > 0) - { - SequenceItem item; - - const size_t index1 = i1 - 1; - item.index1 = index1; - --i1; - - m_sequence.push_back(item); - } - - while (i2 > 0) - { - SequenceItem item; - - const size_t index2 = i2 - 1; - item.index2 = index2; - --i2; - - m_sequence.push_back(item); - } - - std::reverse(m_sequence.begin(), m_sequence.end()); -} - -} // namespace pdf - -#endif // PDFALGORITHMLCS_H +// 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 +// with the written consent of the copyright owner, 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 PDFALGORITHMLCS_H +#define PDFALGORITHMLCS_H + +#include "pdfglobal.h" + +namespace pdf +{ + +class PDFAlgorithmLongestCommonSubsequenceBase +{ +public: + + enum SequenceItemFlag + { + None = 0x0000, + MovedLeft = 0x0001, ///< Item has been moved from this position (is present in a sequence no. 1) + MovedRight = 0x0002, ///< Item has been moved to this position (is present in a sequence no. 2) + Moved = 0x0004, ///< Index of item has been changed + Added = 0x0008, ///< Item has been added to a sequence no. 2 + Removed = 0x0010, ///< Item has been removed from a sequence no. 1 + Replaced = 0x0020, ///< Item has been replaced (or sequence of items has been replaced) + }; + Q_DECLARE_FLAGS(SequenceItemFlags, SequenceItemFlag) + + struct SequenceItem + { + size_t index1 = std::numeric_limits::max(); + size_t index2 = std::numeric_limits::max(); + SequenceItemFlags flags = None; + + bool isLeftValid() const { return index1 != std::numeric_limits::max(); } + bool isRightValid() const { return index2 != std::numeric_limits::max(); } + bool isLeft() const { return isLeftValid() && !isRightValid(); } + bool isRight() const { return isRightValid() && !isLeftValid(); } + bool isMatch() const { return isLeftValid() && isRightValid(); } + bool isMovedLeft() const { return flags.testFlag(MovedLeft); } + bool isMovedRight() const { return flags.testFlag(MovedRight); } + bool isMoved() const { return flags.testFlag(Moved); } + bool isAdded() const { return flags.testFlag(Added); } + bool isRemoved() const { return flags.testFlag(Removed); } + bool isReplaced() const { return flags.testFlag(Replaced); } + bool isModified() const { return isAdded() || isRemoved() || isReplaced(); } + + void markMovedLeft() { flags.setFlag(MovedLeft); } + void markMovedRight() { flags.setFlag(MovedRight); } + void markMoved() { flags.setFlag(Moved); } + void markAdded() { flags.setFlag(Added); } + void markRemoved() { flags.setFlag(Removed); } + void markReplaced() { flags.setFlag(Replaced); } + }; + + using Sequence = typename std::vector; + using SequenceIterator = typename Sequence::iterator; + using SequenceItemRange = typename std::pair; + using SequenceItemRanges = typename std::vector; + + /// Marks a sequence with set of flags representing added/removed/replaced/moved + /// items. Moved items sequences must be sorted. + /// \param sequence Sequence to be marked + /// \param movedItemsLeft Sorted sequence of left indices, which have been moved + /// \param movedItemsRight sorted sequence of right indices, which have been moved + static void markSequence(Sequence& sequence, + const std::vector& movedItemsLeft, + const std::vector& movedItemsRight); + + /// Returns item ranges, which should be checked - for example, + /// for text modification. + /// \param sequence Sequence + static SequenceItemRanges getModifiedRanges(Sequence& sequence); + + /// Collect flags from given item range + /// \param range Range + static SequenceItemFlags collectFlags(const SequenceItemRange& range); +}; + +/// Algorithm for computing longest common subsequence, on two sequences +/// of objects, which are implementing operator "==" (equal operator). +/// Constructor takes bidirectional iterators to the sequence. So, iterators +/// are requred to be bidirectional. +template +class PDFAlgorithmLongestCommonSubsequence : public PDFAlgorithmLongestCommonSubsequenceBase +{ +public: + PDFAlgorithmLongestCommonSubsequence(Iterator it1, + Iterator it1End, + Iterator it2, + Iterator it2End, + Comparator comparator); + + + void perform(); + + const Sequence& getSequence() const { return m_sequence; } + +private: + Iterator m_it1; + Iterator m_it1End; + Iterator m_it2; + Iterator m_it2End; + + size_t m_size1; + size_t m_size2; + size_t m_matrixSize; + + Comparator m_comparator; + + std::vector m_backtrackData; + Sequence m_sequence; +}; + +template +PDFAlgorithmLongestCommonSubsequence::PDFAlgorithmLongestCommonSubsequence(Iterator it1, + Iterator it1End, + Iterator it2, + Iterator it2End, + Comparator comparator) : + m_it1(std::move(it1)), + m_it1End(std::move(it1End)), + m_it2(std::move(it2)), + m_it2End(std::move(it2End)), + m_size1(0), + m_size2(0), + m_matrixSize(0), + m_comparator(std::move(comparator)) +{ + m_size1 = std::distance(m_it1, m_it1End) + 1; + m_size2 = std::distance(m_it2, m_it2End) + 1; + m_matrixSize = m_size1 * m_size2; +} + +template +void PDFAlgorithmLongestCommonSubsequence::perform() +{ + m_backtrackData.resize(m_matrixSize); + m_sequence.clear(); + + std::vector rowTop(m_size1, size_t()); + std::vector rowBottom(m_size1, size_t()); + + // Jakub Melka: we will have columns consisting of it1...it1End + // and rows consisting of it2...it2End. We iterate trough rows, + // and for each row, we update longest common subsequence data. + + auto it2 = m_it2; + for (size_t i2 = 1; i2 < m_size2; ++i2, ++it2) + { + auto it1 = m_it1; + for (size_t i1 = 1; i1 < m_size1; ++i1, ++it1) + { + if (m_comparator(*it1, *it2)) + { + // We have match + rowBottom[i1] = rowTop[i1 - 1] + 1; + } + else + { + const size_t leftCellValue = rowBottom[i1 - 1]; + const size_t upperCellValue = rowTop[i1]; + bool isLeftBigger = leftCellValue > upperCellValue; + + if (isLeftBigger) + { + rowBottom[i1] = leftCellValue; + m_backtrackData[i2 * m_size1 + i1] = true; + } + else + { + rowBottom[i1] = upperCellValue; + m_backtrackData[i2 * m_size1 + i1] = false; + } + } + } + + // Bottom row will become top row + std::swap(rowTop, rowBottom); + } + + size_t i1 = m_size1 - 1; + size_t i2 = m_size2 - 1; + + while (i1 > 0 && i2 > 0) + { + SequenceItem item; + + const size_t index1 = i1 - 1; + const size_t index2 = i2 - 1; + + auto it1 = std::next(m_it1, index1); + auto it2 = std::next(m_it2, index2); + + if (m_comparator(*it1, *it2)) + { + item.index1 = index1; + item.index2 = index2; + + --i1; + --i2; + } + else + { + if (m_backtrackData[i2 * m_size1 + i1]) + { + item.index1 = index1; + --i1; + } + else + { + item.index2 = index2; + --i2; + } + } + + m_sequence.push_back(item); + } + + while (i1 > 0) + { + SequenceItem item; + + const size_t index1 = i1 - 1; + item.index1 = index1; + --i1; + + m_sequence.push_back(item); + } + + while (i2 > 0) + { + SequenceItem item; + + const size_t index2 = i2 - 1; + item.index2 = index2; + --i2; + + m_sequence.push_back(item); + } + + std::reverse(m_sequence.begin(), m_sequence.end()); +} + +} // namespace pdf + +#endif // PDFALGORITHMLCS_H diff --git a/Pdf4QtLib/sources/pdfdiff.cpp b/Pdf4QtLib/sources/pdfdiff.cpp index 08a35f8..62ee6f8 100644 --- a/Pdf4QtLib/sources/pdfdiff.cpp +++ b/Pdf4QtLib/sources/pdfdiff.cpp @@ -1,1198 +1,1198 @@ -// 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 -// with the written consent of the copyright owner, 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 "pdfdiff.h" -#include "pdfrenderer.h" -#include "pdfdocumenttextflow.h" -#include "pdfexecutionpolicy.h" -#include "pdffont.h" -#include "pdfcms.h" -#include "pdfcompiler.h" -#include "pdfconstants.h" -#include "pdfalgorithmlcs.h" - -#include - -namespace pdf -{ - -class PDFDiffHelper -{ -public: - using GraphicPieceInfo = PDFPrecompiledPage::GraphicPieceInfo; - using GraphicPieceInfos = PDFPrecompiledPage::GraphicPieceInfos; - using PageSequence = PDFAlgorithmLongestCommonSubsequenceBase::Sequence; - - - struct Differences - { - GraphicPieceInfos left; - GraphicPieceInfos right; - - bool isEmpty() const { return left.empty() && right.empty(); } - }; - - struct TextFlowDifferences - { - PDFDocumentTextFlow leftTextFlow; - PDFDocumentTextFlow rightTextFlow; - QString leftText; - QString rightText; - }; - - struct TextCompareItem - { - size_t index = 0; - int charIndex = 0; - int charCount = 0; - bool left = false; - }; - - static Differences calculateDifferences(const GraphicPieceInfos& left, const GraphicPieceInfos& right, PDFReal epsilon); - static std::vector getLeftUnmatched(const PageSequence& sequence); - static std::vector getRightUnmatched(const PageSequence& sequence); - static void matchPage(PageSequence& sequence, size_t leftPage, size_t rightPage); - static std::vector prepareTextCompareItems(const PDFDocumentTextFlow& textFlow, - bool isWordsComparingMode, - bool isLeft); -}; - -PDFDiff::PDFDiff(QObject* parent) : - BaseClass(parent), - m_progress(nullptr), - m_leftDocument(nullptr), - m_rightDocument(nullptr), - m_options(Asynchronous | PC_Text | PC_VectorGraphics | PC_Images | CompareWords), - m_epsilon(0.001), - m_cancelled(false), - m_textAnalysisAlgorithm(PDFDocumentTextFlowFactory::Algorithm::Layout) -{ - -} - -PDFDiff::~PDFDiff() -{ - stop(); -} - -void PDFDiff::setLeftDocument(const PDFDocument* leftDocument) -{ - if (m_leftDocument != leftDocument) - { - stop(); - m_leftDocument = leftDocument; - } -} - -void PDFDiff::setRightDocument(const PDFDocument* rightDocument) -{ - if (m_rightDocument != rightDocument) - { - stop(); - m_rightDocument = rightDocument; - } -} - -void PDFDiff::setPagesForLeftDocument(PDFClosedIntervalSet pagesForLeftDocument) -{ - stop(); - m_pagesForLeftDocument = std::move(pagesForLeftDocument); -} - -void PDFDiff::setPagesForRightDocument(PDFClosedIntervalSet pagesForRightDocument) -{ - stop(); - m_pagesForRightDocument = std::move(pagesForRightDocument); -} - -void PDFDiff::start() -{ - // Jakub Melka: First, we must ensure, that comparation - // process is finished, otherwise we must wait for end. - // Then, create a new future watcher. - stop(); - - m_cancelled = false; - - if (m_options.testFlag(Asynchronous)) - { - m_futureWatcher = std::nullopt; - m_futureWatcher.emplace(); - - m_future = QtConcurrent::run(std::bind(&PDFDiff::perform, this)); - connect(&*m_futureWatcher, &QFutureWatcher::finished, this, &PDFDiff::onComparationPerformed); - m_futureWatcher->setFuture(m_future); - } - else - { - // Just do comparation immediately - m_result = perform(); - emit comparationFinished(); - } -} - -void PDFDiff::stop() -{ - if (m_futureWatcher && !m_futureWatcher->isFinished()) - { - // Do stop only if process doesn't finished already. - // If we are finished, we do not want to set cancelled state. - m_cancelled = true; - m_futureWatcher->waitForFinished(); - } -} - -PDFDiffResult PDFDiff::perform() -{ - PDFDiffResult result; - - if (!m_leftDocument || !m_rightDocument) - { - result.setResult(tr("No document to be compared.")); - return result; - } - - if (m_pagesForLeftDocument.isEmpty() || m_pagesForRightDocument.isEmpty()) - { - result.setResult(tr("No page to be compared.")); - return result; - } - - auto leftPages = m_pagesForLeftDocument.unfold(); - auto rightPages = m_pagesForRightDocument.unfold(); - - const size_t leftDocumentPageCount = m_leftDocument->getCatalog()->getPageCount(); - const size_t rightDocumentPageCount = m_rightDocument->getCatalog()->getPageCount(); - - if (leftPages.front() < 0 || - leftPages.back() >= PDFInteger(leftDocumentPageCount) || - rightPages.front() < 0 || - rightPages.back() >= PDFInteger(rightDocumentPageCount)) - { - result.setResult(tr("Invalid page range.")); - return result; - } - - if (m_progress) - { - ProgressStartupInfo info; - info.showDialog = false; - info.text = tr("Comparing documents."); - m_progress->start(StepLast, std::move(info)); - } - - performSteps(leftPages, rightPages); - - if (m_progress) - { - m_progress->finish(); - } - - return result; -} - -void PDFDiff::stepProgress() -{ - if (m_progress) - { - m_progress->step(); - } -} - -struct PDFDiffPageContext -{ - PDFInteger pageIndex = 0; - std::array pageHash = { }; - PDFPrecompiledPage::GraphicPieceInfos graphicPieces; - PDFDocumentTextFlow text; -}; - -void PDFDiff::performPageMatching(const std::vector& leftPreparedPages, - const std::vector& rightPreparedPages, - PDFAlgorithmLongestCommonSubsequenceBase::Sequence& pageSequence, - std::map& pageMatches) -{ - // Match pages. We will use following algorithm: exact solution can fail, because - // we are using hashes and due to numerical instability, hashes can be different - // even for exactly the same page. But if hashes are the same, the page must be the same. - // So, we use longest common subsequence algorithm to detect same page ranges, - // and then we match the rest. We assume the number of failing pages is relatively small. - - auto comparePages = [&](const PDFDiffPageContext& left, const PDFDiffPageContext& right) - { - if (left.pageHash == right.pageHash) - { - return true; - } - - auto it = pageMatches.find(left.pageIndex); - if (it != pageMatches.cend()) - { - return it->second == right.pageIndex; - } - - return false; - }; - PDFAlgorithmLongestCommonSubsequence algorithm(leftPreparedPages.cbegin(), leftPreparedPages.cend(), - rightPreparedPages.cbegin(), rightPreparedPages.cend(), - comparePages); - algorithm.perform(); - pageSequence = algorithm.getSequence(); - - std::vector leftUnmatched = PDFDiffHelper::getLeftUnmatched(pageSequence); - std::vector rightUnmatched = PDFDiffHelper::getRightUnmatched(pageSequence); - - // We are matching left pages to the right ones - std::map> matchedPages; - - for (const size_t index : leftUnmatched) - { - matchedPages[index] = std::vector(); - } - - auto matchLeftPage = [&, this](size_t leftIndex) - { - const PDFDiffPageContext& leftPageContext = leftPreparedPages[leftIndex]; - - auto page = m_leftDocument->getCatalog()->getPage(leftPageContext.pageIndex); - PDFReal epsilon = calculateEpsilonForPage(page); - - for (const size_t rightIndex : rightUnmatched) - { - const PDFDiffPageContext& rightPageContext = rightPreparedPages[rightIndex]; - if (leftPageContext.graphicPieces.size() != rightPageContext.graphicPieces.size()) - { - // Match cannot exist, graphic pieces have different size - continue; - } - - PDFDiffHelper::Differences differences = PDFDiffHelper::calculateDifferences(leftPageContext.graphicPieces, rightPageContext.graphicPieces, epsilon); - - if (differences.isEmpty()) - { - // Jakub Melka: we have a match - matchedPages[leftIndex].push_back(rightIndex); - } - } - }; - - PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Page, leftUnmatched.begin(), leftUnmatched.end(), matchLeftPage); - - std::vector leftPagesMoved; - std::vector rightPagesMoved; - - std::set matchedRightPages; - for (const auto& matchedPage : matchedPages) - { - for (size_t rightContextIndex : matchedPage.second) - { - if (!matchedRightPages.count(rightContextIndex)) - { - matchedRightPages.insert(rightContextIndex); - const PDFDiffPageContext& leftPageContext = leftPreparedPages[matchedPage.first]; - const PDFDiffPageContext& rightPageContext = rightPreparedPages[rightContextIndex]; - - leftPagesMoved.push_back(leftPageContext.pageIndex); - rightPagesMoved.push_back(rightPageContext.pageIndex); - - pageMatches[leftPageContext.pageIndex] = rightPageContext.pageIndex; - } - } - } - - if (!pageMatches.empty()) - { - algorithm.perform(); - pageSequence = algorithm.getSequence(); - } - - std::sort(leftPagesMoved.begin(), leftPagesMoved.end()); - std::sort(rightPagesMoved.begin(), rightPagesMoved.end()); - - PDFAlgorithmLongestCommonSubsequenceBase::markSequence(pageSequence, leftPagesMoved, rightPagesMoved); -} - -void PDFDiff::performSteps(const std::vector& leftPages, const std::vector& rightPages) -{ - std::vector leftPreparedPages; - std::vector rightPreparedPages; - - PDFDiffHelper::PageSequence pageSequence; - std::map pageMatches; // Indices are real page indices, not indices to page contexts - - auto createDiffPageContext = [](auto pageIndex) - { - PDFDiffPageContext context; - context.pageIndex = pageIndex; - return context; - }; - std::transform(leftPages.cbegin(), leftPages.cend(), std::back_inserter(leftPreparedPages), createDiffPageContext); - std::transform(rightPages.cbegin(), rightPages.cend(), std::back_inserter(rightPreparedPages), createDiffPageContext); - - // StepExtractContentLeftDocument - if (!m_cancelled) - { - PDFFontCache fontCache(DEFAULT_FONT_CACHE_LIMIT, DEFAULT_REALIZED_FONT_CACHE_LIMIT); - PDFOptionalContentActivity optionalContentActivity(m_leftDocument, pdf::OCUsage::View, nullptr); - fontCache.setDocument(pdf::PDFModifiedDocument(const_cast(m_leftDocument), &optionalContentActivity)); - - PDFCMSManager cmsManager(nullptr); - cmsManager.setDocument(m_leftDocument); - PDFCMSPointer cms = cmsManager.getCurrentCMS(); - - auto fillPageContext = [&, this](PDFDiffPageContext& context) - { - PDFPrecompiledPage compiledPage; - constexpr PDFRenderer::Features features = PDFRenderer::IgnoreOptionalContent; - PDFRenderer renderer(m_leftDocument, &fontCache, cms.data(), &optionalContentActivity, features, pdf::PDFMeshQualitySettings()); - renderer.compile(&compiledPage, context.pageIndex); - - auto page = m_leftDocument->getCatalog()->getPage(context.pageIndex); - PDFReal epsilon = calculateEpsilonForPage(page); - context.graphicPieces = compiledPage.calculateGraphicPieceInfos(page->getMediaBox(), epsilon); - - finalizeGraphicsPieces(context); - }; - PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Page, leftPreparedPages.begin(), leftPreparedPages.end(), fillPageContext); - stepProgress(); - } - - // StepExtractContentRightDocument - if (!m_cancelled) - { - PDFFontCache fontCache(DEFAULT_FONT_CACHE_LIMIT, DEFAULT_REALIZED_FONT_CACHE_LIMIT); - PDFOptionalContentActivity optionalContentActivity(m_rightDocument, pdf::OCUsage::View, nullptr); - fontCache.setDocument(pdf::PDFModifiedDocument(const_cast(m_rightDocument), &optionalContentActivity)); - - PDFCMSManager cmsManager(nullptr); - cmsManager.setDocument(m_rightDocument); - PDFCMSPointer cms = cmsManager.getCurrentCMS(); - - auto fillPageContext = [&, this](PDFDiffPageContext& context) - { - PDFPrecompiledPage compiledPage; - constexpr PDFRenderer::Features features = PDFRenderer::IgnoreOptionalContent; - PDFRenderer renderer(m_rightDocument, &fontCache, cms.data(), &optionalContentActivity, features, pdf::PDFMeshQualitySettings()); - renderer.compile(&compiledPage, context.pageIndex); - - const PDFPage* page = m_rightDocument->getCatalog()->getPage(context.pageIndex); - PDFReal epsilon = calculateEpsilonForPage(page); - context.graphicPieces = compiledPage.calculateGraphicPieceInfos(page->getMediaBox(), epsilon); - - finalizeGraphicsPieces(context); - }; - - PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Page, rightPreparedPages.begin(), rightPreparedPages.end(), fillPageContext); - stepProgress(); - } - - // StepMatchPages - if (!m_cancelled) - { - performPageMatching(leftPreparedPages, rightPreparedPages, pageSequence, pageMatches); - stepProgress(); - } - - // StepExtractTextLeftDocument - if (!m_cancelled) - { - pdf::PDFDocumentTextFlowFactory factoryLeftDocumentTextFlow; - factoryLeftDocumentTextFlow.setCalculateBoundingBoxes(true); - PDFDocumentTextFlow leftTextFlow = factoryLeftDocumentTextFlow.create(m_leftDocument, leftPages, m_textAnalysisAlgorithm); - std::map splittedText = leftTextFlow.split(PDFDocumentTextFlow::Text); - for (PDFDiffPageContext& leftContext : leftPreparedPages) - { - auto it = splittedText.find(leftContext.pageIndex); - if (it != splittedText.cend()) - { - leftContext.text = std::move(it->second); - splittedText.erase(it); - } - } - stepProgress(); - } - - // StepExtractTextRightDocument - if (!m_cancelled) - { - pdf::PDFDocumentTextFlowFactory factoryRightDocumentTextFlow; - factoryRightDocumentTextFlow.setCalculateBoundingBoxes(true); - PDFDocumentTextFlow rightTextFlow = factoryRightDocumentTextFlow.create(m_rightDocument, rightPages, m_textAnalysisAlgorithm); - std::map splittedText = rightTextFlow.split(PDFDocumentTextFlow::Text); - for (PDFDiffPageContext& rightContext : rightPreparedPages) - { - auto it = splittedText.find(rightContext.pageIndex); - if (it != splittedText.cend()) - { - rightContext.text = std::move(it->second); - splittedText.erase(it); - } - } - stepProgress(); - } - - // StepCompare - if (!m_cancelled) - { - performCompare(leftPreparedPages, rightPreparedPages, pageSequence, pageMatches); - stepProgress(); - } -} - -void PDFDiff::performCompare(const std::vector& leftPreparedPages, - const std::vector& rightPreparedPages, - PDFAlgorithmLongestCommonSubsequenceBase::Sequence& pageSequence, - const std::map& pageMatches) -{ - using AlgorithmLCS = PDFAlgorithmLongestCommonSubsequenceBase; - - auto modifiedRanges = AlgorithmLCS::getModifiedRanges(pageSequence); - - // First find all moved pages - for (const AlgorithmLCS::SequenceItem& item : pageSequence) - { - if (item.isMovedLeft()) - { - Q_ASSERT(pageMatches.contains(leftPreparedPages.at(item.index1).pageIndex)); - const PDFInteger leftIndex = leftPreparedPages[item.index1].pageIndex; - const PDFInteger rightIndex = pageMatches.at(leftIndex); - m_result.addPageMoved(leftIndex, rightIndex); - } - if (item.isMoved()) - { - m_result.addPageMoved(leftPreparedPages[item.index1].pageIndex, rightPreparedPages[item.index2].pageIndex); - } - } - - std::vector textFlowDifferences; - - for (const auto& range : modifiedRanges) - { - AlgorithmLCS::SequenceItemFlags flags = AlgorithmLCS::collectFlags(range); - - 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) - { - PDFDocumentTextFlow leftTextFlow; - PDFDocumentTextFlow rightTextFlow; - - const bool isTextComparedAsVectorGraphics = m_options.testFlag(CompareTextsAsVector); - - for (auto it = range.first; it != range.second; ++it) - { - const AlgorithmLCS::SequenceItem& item = *it; - if (item.isReplaced()) - { - const PDFDiffPageContext& leftPageContext = leftPreparedPages[item.index1]; - const PDFDiffPageContext& rightPageContext = rightPreparedPages[item.index2]; - - if (!isTextComparedAsVectorGraphics) - { - leftTextFlow.append(leftPageContext.text); - rightTextFlow.append(rightPageContext.text); - } - - 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) - { - case PDFDiffHelper::GraphicPieceInfo::Type::Text: - if (isTextComparedAsVectorGraphics) - { - m_result.addRemovedTextCharContent(leftPageContext.pageIndex, info.boundingRect); - } - break; - - case PDFDiffHelper::GraphicPieceInfo::Type::VectorGraphics: - m_result.addRemovedVectorGraphicContent(leftPageContext.pageIndex, info.boundingRect); - break; - - case PDFDiffHelper::GraphicPieceInfo::Type::Image: - m_result.addRemovedImageContent(leftPageContext.pageIndex, info.boundingRect); - break; - - case PDFDiffHelper::GraphicPieceInfo::Type::Shading: - m_result.addRemovedShadingContent(leftPageContext.pageIndex, info.boundingRect); - break; - - default: - Q_ASSERT(false); - break; - } - } - - for (const PDFDiffHelper::GraphicPieceInfo& info : differences.right) - { - switch (info.type) - { - case PDFDiffHelper::GraphicPieceInfo::Type::Text: - if (isTextComparedAsVectorGraphics) - { - m_result.addAddedTextCharContent(rightPageContext.pageIndex, info.boundingRect); - } - break; - - case PDFDiffHelper::GraphicPieceInfo::Type::VectorGraphics: - m_result.addAddedVectorGraphicContent(rightPageContext.pageIndex, info.boundingRect); - break; - - case PDFDiffHelper::GraphicPieceInfo::Type::Image: - m_result.addAddedImageContent(rightPageContext.pageIndex, info.boundingRect); - break; - - case PDFDiffHelper::GraphicPieceInfo::Type::Shading: - m_result.addAddedShadingContent(rightPageContext.pageIndex, info.boundingRect); - break; - - default: - Q_ASSERT(false); - break; - } - } - } - - if (item.isAdded()) - { - const PDFDiffPageContext& rightPageContext = rightPreparedPages[item.index2]; - - if (!isTextComparedAsVectorGraphics) - { - rightTextFlow.append(rightPageContext.text); - } - - m_result.addPageAdded(rightPageContext.pageIndex); - } - if (item.isRemoved()) - { - const PDFDiffPageContext& leftPageContext = leftPreparedPages[item.index1]; - - if (!isTextComparedAsVectorGraphics) - { - leftTextFlow.append(leftPageContext.text); - } - - m_result.addPageRemoved(leftPageContext.pageIndex); - } - } - - textFlowDifferences.emplace_back(); - PDFDiffHelper::TextFlowDifferences& addedDifferences = textFlowDifferences.back(); - addedDifferences.leftText = leftTextFlow.getText(); - addedDifferences.rightText = rightTextFlow.getText(); - - if (addedDifferences.leftText == addedDifferences.rightText) - { - // Text is the same, no difference is found - textFlowDifferences.pop_back(); - } - else - { - addedDifferences.leftTextFlow = std::move(leftTextFlow); - addedDifferences.rightTextFlow = std::move(rightTextFlow); - } - } - else - { - for (auto it = range.first; it != range.second; ++it) - { - 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); - } - } - } - } - - // Jakub Melka: try to compare text differences - auto compareTexts = [this](PDFDiffHelper::TextFlowDifferences& context) - { - using TextCompareItem = PDFDiffHelper::TextCompareItem; - const bool isWordsComparingMode = m_options.testFlag(CompareWords); - - std::vector leftItems; - std::vector rightItems; - - leftItems = PDFDiffHelper::prepareTextCompareItems(context.leftTextFlow, isWordsComparingMode, true); - rightItems = PDFDiffHelper::prepareTextCompareItems(context.rightTextFlow, isWordsComparingMode, false); - - auto compareCharacters = [&](const TextCompareItem& a, const TextCompareItem& b) - { - const auto& aItem = a.left ? context.leftTextFlow : context.rightTextFlow; - const auto& bItem = b.left ? context.leftTextFlow : context.rightTextFlow; - - QStringRef aText(&aItem.getItem(a.index)->text, a.charIndex, a.charCount); - QStringRef bText(&bItem.getItem(b.index)->text, b.charIndex, b.charCount); - - return aText == bText; - }; - PDFAlgorithmLongestCommonSubsequence algorithm(leftItems.cbegin(), leftItems.cend(), - rightItems.cbegin(), rightItems.cend(), - compareCharacters); - algorithm.perform(); - PDFAlgorithmLongestCommonSubsequenceBase::Sequence sequence = algorithm.getSequence(); - PDFAlgorithmLongestCommonSubsequenceBase::markSequence(sequence, { }, { }); - PDFAlgorithmLongestCommonSubsequenceBase::SequenceItemRanges modifiedRanges = PDFAlgorithmLongestCommonSubsequenceBase::getModifiedRanges(sequence); - - // Merge modified sequences separated by just space - if (!isWordsComparingMode && !modifiedRanges.empty()) - { - auto itPrev = sequence.end(); - for (const auto& range : modifiedRanges) - { - if (itPrev != sequence.end()) - { - auto itNext = range.first; - - bool isReplaced = true; - for (auto it = itPrev; it != itNext && isReplaced; ++it) - { - const PDFAlgorithmLongestCommonSubsequenceBase::SequenceItem& item = *it; - - // If we doesn't have a match, then it is not a whitespace - if (!item.isMatch()) - { - isReplaced = false; - break; - } - - const TextCompareItem& compareItem = leftItems[item.index1]; - const auto& flowItem = compareItem.left ? context.leftTextFlow : context.rightTextFlow; - QChar character = flowItem.getItem(compareItem.index)->text.at(compareItem.charIndex); - - isReplaced = !character.isSpace(); - } - - if (isReplaced) - { - for (auto it = itPrev; it != itNext; ++it) - { - PDFAlgorithmLongestCommonSubsequenceBase::SequenceItem& item = *it; - item.markReplaced(); - } - } - } - - itPrev = range.second; - } - - modifiedRanges = PDFAlgorithmLongestCommonSubsequenceBase::getModifiedRanges(sequence); - } - - for (const auto& range : modifiedRanges) - { - auto it = range.first; - auto itEnd = range.second; - - QStringList leftStrings; - QStringList rightStrings; - - for (; it != itEnd; ++it) - { - const PDFAlgorithmLongestCommonSubsequenceBase::SequenceItem& item = *it; - - if (item.isLeftValid()) - { - const TextCompareItem& textCompareItem = leftItems[item.index1]; - const auto& textFlow = textCompareItem.left ? context.leftTextFlow : context.rightTextFlow; - QStringRef text(&textFlow.getItem(textCompareItem.index)->text, textCompareItem.charIndex, textCompareItem.charCount); - leftStrings << text.toString(); - } - - if (item.isRightValid()) - { - const TextCompareItem& textCompareItem = rightItems[item.index2]; - const auto& textFlow = textCompareItem.left ? context.leftTextFlow : context.rightTextFlow; - QStringRef text(&textFlow.getItem(textCompareItem.index)->text, textCompareItem.charIndex, textCompareItem.charCount); - rightStrings << text.toString(); - } - } - - QString leftString; - QString rightString; - - if (isWordsComparingMode) - { - leftString = leftStrings.join(QChar::Space); - rightString = rightStrings.join(QChar::Space); - } - else - { - leftString = leftStrings.join(QString()); - rightString = rightStrings.join(QString()); - } - - - } - }; - - PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Page, textFlowDifferences.begin(), textFlowDifferences.end(), compareTexts); - //std::for_each(textFlowDifferences.begin(), textFlowDifferences.end(), compareTexts); -} - -void PDFDiff::finalizeGraphicsPieces(PDFDiffPageContext& context) -{ - std::sort(context.graphicPieces.begin(), context.graphicPieces.end()); - - // Compute page hash using active settings - QCryptographicHash hasher(QCryptographicHash::Sha512); - hasher.reset(); - - for (const PDFPrecompiledPage::GraphicPieceInfo& info : context.graphicPieces) - { - if (info.isText() && !m_options.testFlag(PC_Text)) - { - continue; - } - if (info.isVectorGraphics() && !m_options.testFlag(PC_VectorGraphics)) - { - continue; - } - if (info.isImage() && !m_options.testFlag(PC_Images)) - { - continue; - } - if (info.isShading() && !m_options.testFlag(PC_Mesh)) - { - continue; - } - - hasher.addData(reinterpret_cast(info.hash.data()), int(info.hash.size())); - } - - QByteArray hash = hasher.result(); - Q_ASSERT(QCryptographicHash::hashLength(QCryptographicHash::Sha512) == 64); - - size_t size = qMin(hash.length(), context.pageHash.size()); - std::copy(hash.data(), hash.data() + size, context.pageHash.data()); -} - -void PDFDiff::onComparationPerformed() -{ - m_cancelled = false; - m_result = m_future.result(); - emit comparationFinished(); -} - -PDFReal PDFDiff::calculateEpsilonForPage(const PDFPage* page) const -{ - Q_ASSERT(page); - - QRectF mediaBox = page->getMediaBox(); - - PDFReal width = mediaBox.width(); - PDFReal height = mediaBox.height(); - PDFReal factor = qMax(width, height); - - return factor * m_epsilon; -} - -PDFDocumentTextFlowFactory::Algorithm PDFDiff::getTextAnalysisAlgorithm() const -{ - return m_textAnalysisAlgorithm; -} - -void PDFDiff::setTextAnalysisAlgorithm(PDFDocumentTextFlowFactory::Algorithm textAnalysisAlgorithm) -{ - m_textAnalysisAlgorithm = textAnalysisAlgorithm; -} - -PDFDiffResult::PDFDiffResult() : - m_result(true) -{ - -} - -void PDFDiffResult::addPageMoved(PDFInteger pageIndex1, PDFInteger pageIndex2) -{ - Difference difference; - - difference.type = Type::PageMoved; - difference.pageIndex1 = pageIndex1; - difference.pageIndex2 = pageIndex2; - - m_differences.emplace_back(std::move(difference)); -} - -void PDFDiffResult::addPageAdded(PDFInteger pageIndex) -{ - Difference difference; - - difference.type = Type::PageAdded; - difference.pageIndex2 = pageIndex; - - m_differences.emplace_back(std::move(difference)); -} - -void PDFDiffResult::addPageRemoved(PDFInteger pageIndex) -{ - Difference difference; - - difference.type = Type::PageRemoved; - difference.pageIndex1 = pageIndex; - - m_differences.emplace_back(std::move(difference)); -} - -void PDFDiffResult::addLeftItem(Type type, PDFInteger pageIndex, QRectF rect) -{ - Difference difference; - - difference.type = type; - difference.pageIndex1 = pageIndex; - addRectLeft(difference, rect); - - m_differences.emplace_back(std::move(difference)); -} - -void PDFDiffResult::addRightItem(Type type, PDFInteger pageIndex, QRectF rect) -{ - Difference difference; - - difference.type = type; - difference.pageIndex2 = pageIndex; - addRectRight(difference, rect); - - m_differences.emplace_back(std::move(difference)); -} - -void PDFDiffResult::addRemovedTextCharContent(PDFInteger pageIndex, QRectF rect) -{ - addLeftItem(Type::RemovedTextCharContent, pageIndex, rect); -} - -void PDFDiffResult::addRemovedVectorGraphicContent(PDFInteger pageIndex, QRectF rect) -{ - addLeftItem(Type::RemovedVectorGraphicContent, pageIndex, rect); -} - -void PDFDiffResult::addRemovedImageContent(PDFInteger pageIndex, QRectF rect) -{ - addLeftItem(Type::RemovedImageContent, pageIndex, rect); -} - -void PDFDiffResult::addRemovedShadingContent(PDFInteger pageIndex, QRectF rect) -{ - addLeftItem(Type::RemovedShadingContent, pageIndex, rect); -} - -void PDFDiffResult::addAddedTextCharContent(PDFInteger pageIndex, QRectF rect) -{ - addRightItem(Type::AddedTextCharContent, pageIndex, rect); -} - -void PDFDiffResult::addAddedVectorGraphicContent(PDFInteger pageIndex, QRectF rect) -{ - addRightItem(Type::AddedVectorGraphicContent, pageIndex, rect); -} - -void PDFDiffResult::addAddedImageContent(PDFInteger pageIndex, QRectF rect) -{ - addRightItem(Type::AddedImageContent, pageIndex, rect); -} - -void PDFDiffResult::addAddedShadingContent(PDFInteger pageIndex, QRectF rect) -{ - addRightItem(Type::AddedShadingContent, pageIndex, rect); -} - -QString PDFDiffResult::getMessage(size_t index) const -{ - if (index >= m_differences.size()) - { - return QString(); - } - - const Difference& difference = m_differences[index]; - switch (difference.type) - { - case Type::PageMoved: - return PDFDiff::tr("Page no. %1 from old document has been moved to a new document at page no. %2.").arg(difference.pageIndex1 + 1).arg(difference.pageIndex2 + 1); - - case Type::PageAdded: - return PDFDiff::tr("Page no. %1 was added.").arg(difference.pageIndex2 + 1); - - case Type::PageRemoved: - return PDFDiff::tr("Page no. %1 was removed.").arg(difference.pageIndex1 + 1); - - case Type::RemovedTextCharContent: - return PDFDiff::tr("Removed text character from page %1.").arg(difference.pageIndex1 + 1); - - case Type::RemovedVectorGraphicContent: - return PDFDiff::tr("Removed vector graphics from page %1.").arg(difference.pageIndex1 + 1); - - case Type::RemovedImageContent: - return PDFDiff::tr("Removed image from page %1.").arg(difference.pageIndex1 + 1); - - case Type::RemovedShadingContent: - return PDFDiff::tr("Removed shading from page %1.").arg(difference.pageIndex1 + 1); - - case Type::AddedTextCharContent: - return PDFDiff::tr("Added text character from page %1.").arg(difference.pageIndex2 + 1); - - case Type::AddedVectorGraphicContent: - return PDFDiff::tr("Added vector graphics from page %1.").arg(difference.pageIndex2 + 1); - - case Type::AddedImageContent: - return PDFDiff::tr("Added image from page %1.").arg(difference.pageIndex2 + 1); - - case Type::AddedShadingContent: - return PDFDiff::tr("Added shading from page %1.").arg(difference.pageIndex2 + 1); - - default: - Q_ASSERT(false); - break; - } - - return QString(); -} - -void PDFDiffResult::addRectLeft(Difference& difference, QRectF rect) -{ - difference.leftRectIndex = m_rects.size(); - difference.leftRectCount = 1; - m_rects.emplace_back(rect); -} - -void PDFDiffResult::addRectRight(Difference& difference, QRectF rect) -{ - difference.rightRectIndex = m_rects.size(); - difference.rightRectCount = 1; - m_rects.emplace_back(rect); -} - -PDFDiffHelper::Differences PDFDiffHelper::calculateDifferences(const GraphicPieceInfos& left, - const GraphicPieceInfos& right, - PDFReal epsilon) -{ - Differences differences; - - Q_ASSERT(std::is_sorted(left.cbegin(), left.cend())); - Q_ASSERT(std::is_sorted(right.cbegin(), right.cend())); - - for (const GraphicPieceInfo& info : left) - { - if (!std::binary_search(right.cbegin(), right.cend(), info)) - { - differences.left.push_back(info); - } - } - - for (const GraphicPieceInfo& info : right) - { - if (!std::binary_search(left.cbegin(), left.cend(), info)) - { - differences.right.push_back(info); - } - } - - const PDFReal epsilonSquared = epsilon * epsilon; - - // If exact match fails, then try to use match with epsilon. For each - // item in left, we try to find matching item in right. - for (auto it = differences.left.begin(); it != differences.left.end();) - { - bool hasMatch = false; - - const GraphicPieceInfo& leftInfo = *it; - for (auto it2 = differences.right.begin(); it2 != differences.right.end();) - { - // Heuristically compare these items - - const GraphicPieceInfo& rightInfo = *it2; - if (leftInfo.type != rightInfo.type || !leftInfo.boundingRect.intersects(rightInfo.boundingRect)) - { - ++it2; - continue; - } - - const int elementCountPath1 = leftInfo.pagePath.elementCount(); - const int elementCountPath2 = rightInfo.pagePath.elementCount(); - - if (elementCountPath1 != elementCountPath2) - { - ++it2; - continue; - } - - hasMatch = (leftInfo.type != GraphicPieceInfo::Type::Image) || (leftInfo.imageHash == rightInfo.imageHash); - const int elementCount = leftInfo.pagePath.elementCount(); - for (int i = 0; i < elementCount && hasMatch; ++i) - { - QPainterPath::Element leftElement = leftInfo.pagePath.elementAt(i); - QPainterPath::Element rightElement = rightInfo.pagePath.elementAt(i); - - PDFReal diffX = leftElement.x - rightElement.x; - PDFReal diffY = leftElement.y - rightElement.y; - PDFReal squaredDistance = diffX * diffX + diffY * diffY; - - hasMatch = (leftElement.type == rightElement.type) && - (squaredDistance < epsilonSquared); - } - - if (hasMatch) - { - it2 = differences.right.erase(it2); - } - else - { - ++it2; - } - } - - if (hasMatch) - { - it = differences.left.erase(it); - } - else - { - ++it; - } - } - - return differences; -} - -std::vector PDFDiffHelper::getLeftUnmatched(const PageSequence& sequence) -{ - std::vector result; - - for (const auto& item : sequence) - { - if (item.isLeft()) - { - result.push_back(item.index1); - } - } - - return result; -} - -std::vector PDFDiffHelper::getRightUnmatched(const PageSequence& sequence) -{ - std::vector result; - - for (const auto& item : sequence) - { - if (item.isRight()) - { - result.push_back(item.index2); - } - } - - return result; -} - -void PDFDiffHelper::matchPage(PageSequence& sequence, - size_t leftPage, - size_t rightPage) -{ - for (auto it = sequence.begin(); it != sequence.end();) - { - auto& item = *it; - - if (item.isLeft() && item.index1 == leftPage) - { - item.index2 = rightPage; - } - - if (item.isRight() && item.index2 == rightPage) - { - it = sequence.erase(it); - } - else - { - ++it; - } - } -} - -std::vector PDFDiffHelper::prepareTextCompareItems(const PDFDocumentTextFlow& textFlow, - bool isWordsComparingMode, - bool isLeft) -{ - std::vector items; - - const size_t leftCount = textFlow.getSize(); - for (size_t i = 0; i < leftCount; ++i) - { - PDFDiffHelper::TextCompareItem item; - item.index = i; - item.left = isLeft; - item.charCount = 0; - - const PDFDocumentTextFlow::Item* textFlowItem = textFlow.getItem(i); - for (int j = 0; j < textFlowItem->text.size(); ++j) - { - if (isWordsComparingMode) - { - if (textFlowItem->text[j].isSpace()) - { - // Flush buffer - if (item.charCount > 0) - { - items.push_back(item); - item.charCount = 0; - } - } - else - { - if (item.charCount == 0) - { - item.charIndex = j; - } - ++item.charCount; - } - } - else - { - item.charIndex = j; - item.charCount = 1; - items.push_back(item); - } - } - - if (isWordsComparingMode && item.charCount > 0) - { - items.push_back(item); - item.charCount = 0; - } - } - - return items; -} - -} // namespace pdf +// 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 +// with the written consent of the copyright owner, 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 "pdfdiff.h" +#include "pdfrenderer.h" +#include "pdfdocumenttextflow.h" +#include "pdfexecutionpolicy.h" +#include "pdffont.h" +#include "pdfcms.h" +#include "pdfcompiler.h" +#include "pdfconstants.h" +#include "pdfalgorithmlcs.h" + +#include + +namespace pdf +{ + +class PDFDiffHelper +{ +public: + using GraphicPieceInfo = PDFPrecompiledPage::GraphicPieceInfo; + using GraphicPieceInfos = PDFPrecompiledPage::GraphicPieceInfos; + using PageSequence = PDFAlgorithmLongestCommonSubsequenceBase::Sequence; + + + struct Differences + { + GraphicPieceInfos left; + GraphicPieceInfos right; + + bool isEmpty() const { return left.empty() && right.empty(); } + }; + + struct TextFlowDifferences + { + PDFDocumentTextFlow leftTextFlow; + PDFDocumentTextFlow rightTextFlow; + QString leftText; + QString rightText; + }; + + struct TextCompareItem + { + size_t index = 0; + int charIndex = 0; + int charCount = 0; + bool left = false; + }; + + static Differences calculateDifferences(const GraphicPieceInfos& left, const GraphicPieceInfos& right, PDFReal epsilon); + static std::vector getLeftUnmatched(const PageSequence& sequence); + static std::vector getRightUnmatched(const PageSequence& sequence); + static void matchPage(PageSequence& sequence, size_t leftPage, size_t rightPage); + static std::vector prepareTextCompareItems(const PDFDocumentTextFlow& textFlow, + bool isWordsComparingMode, + bool isLeft); +}; + +PDFDiff::PDFDiff(QObject* parent) : + BaseClass(parent), + m_progress(nullptr), + m_leftDocument(nullptr), + m_rightDocument(nullptr), + m_options(Asynchronous | PC_Text | PC_VectorGraphics | PC_Images | CompareWords), + m_epsilon(0.001), + m_cancelled(false), + m_textAnalysisAlgorithm(PDFDocumentTextFlowFactory::Algorithm::Layout) +{ + +} + +PDFDiff::~PDFDiff() +{ + stop(); +} + +void PDFDiff::setLeftDocument(const PDFDocument* leftDocument) +{ + if (m_leftDocument != leftDocument) + { + stop(); + m_leftDocument = leftDocument; + } +} + +void PDFDiff::setRightDocument(const PDFDocument* rightDocument) +{ + if (m_rightDocument != rightDocument) + { + stop(); + m_rightDocument = rightDocument; + } +} + +void PDFDiff::setPagesForLeftDocument(PDFClosedIntervalSet pagesForLeftDocument) +{ + stop(); + m_pagesForLeftDocument = std::move(pagesForLeftDocument); +} + +void PDFDiff::setPagesForRightDocument(PDFClosedIntervalSet pagesForRightDocument) +{ + stop(); + m_pagesForRightDocument = std::move(pagesForRightDocument); +} + +void PDFDiff::start() +{ + // Jakub Melka: First, we must ensure, that comparation + // process is finished, otherwise we must wait for end. + // Then, create a new future watcher. + stop(); + + m_cancelled = false; + + if (m_options.testFlag(Asynchronous)) + { + m_futureWatcher = std::nullopt; + m_futureWatcher.emplace(); + + m_future = QtConcurrent::run(std::bind(&PDFDiff::perform, this)); + connect(&*m_futureWatcher, &QFutureWatcher::finished, this, &PDFDiff::onComparationPerformed); + m_futureWatcher->setFuture(m_future); + } + else + { + // Just do comparation immediately + m_result = perform(); + emit comparationFinished(); + } +} + +void PDFDiff::stop() +{ + if (m_futureWatcher && !m_futureWatcher->isFinished()) + { + // Do stop only if process doesn't finished already. + // If we are finished, we do not want to set cancelled state. + m_cancelled = true; + m_futureWatcher->waitForFinished(); + } +} + +PDFDiffResult PDFDiff::perform() +{ + PDFDiffResult result; + + if (!m_leftDocument || !m_rightDocument) + { + result.setResult(tr("No document to be compared.")); + return result; + } + + if (m_pagesForLeftDocument.isEmpty() || m_pagesForRightDocument.isEmpty()) + { + result.setResult(tr("No page to be compared.")); + return result; + } + + auto leftPages = m_pagesForLeftDocument.unfold(); + auto rightPages = m_pagesForRightDocument.unfold(); + + const size_t leftDocumentPageCount = m_leftDocument->getCatalog()->getPageCount(); + const size_t rightDocumentPageCount = m_rightDocument->getCatalog()->getPageCount(); + + if (leftPages.front() < 0 || + leftPages.back() >= PDFInteger(leftDocumentPageCount) || + rightPages.front() < 0 || + rightPages.back() >= PDFInteger(rightDocumentPageCount)) + { + result.setResult(tr("Invalid page range.")); + return result; + } + + if (m_progress) + { + ProgressStartupInfo info; + info.showDialog = false; + info.text = tr("Comparing documents."); + m_progress->start(StepLast, std::move(info)); + } + + performSteps(leftPages, rightPages); + + if (m_progress) + { + m_progress->finish(); + } + + return result; +} + +void PDFDiff::stepProgress() +{ + if (m_progress) + { + m_progress->step(); + } +} + +struct PDFDiffPageContext +{ + PDFInteger pageIndex = 0; + std::array pageHash = { }; + PDFPrecompiledPage::GraphicPieceInfos graphicPieces; + PDFDocumentTextFlow text; +}; + +void PDFDiff::performPageMatching(const std::vector& leftPreparedPages, + const std::vector& rightPreparedPages, + PDFAlgorithmLongestCommonSubsequenceBase::Sequence& pageSequence, + std::map& pageMatches) +{ + // Match pages. We will use following algorithm: exact solution can fail, because + // we are using hashes and due to numerical instability, hashes can be different + // even for exactly the same page. But if hashes are the same, the page must be the same. + // So, we use longest common subsequence algorithm to detect same page ranges, + // and then we match the rest. We assume the number of failing pages is relatively small. + + auto comparePages = [&](const PDFDiffPageContext& left, const PDFDiffPageContext& right) + { + if (left.pageHash == right.pageHash) + { + return true; + } + + auto it = pageMatches.find(left.pageIndex); + if (it != pageMatches.cend()) + { + return it->second == right.pageIndex; + } + + return false; + }; + PDFAlgorithmLongestCommonSubsequence algorithm(leftPreparedPages.cbegin(), leftPreparedPages.cend(), + rightPreparedPages.cbegin(), rightPreparedPages.cend(), + comparePages); + algorithm.perform(); + pageSequence = algorithm.getSequence(); + + std::vector leftUnmatched = PDFDiffHelper::getLeftUnmatched(pageSequence); + std::vector rightUnmatched = PDFDiffHelper::getRightUnmatched(pageSequence); + + // We are matching left pages to the right ones + std::map> matchedPages; + + for (const size_t index : leftUnmatched) + { + matchedPages[index] = std::vector(); + } + + auto matchLeftPage = [&, this](size_t leftIndex) + { + const PDFDiffPageContext& leftPageContext = leftPreparedPages[leftIndex]; + + auto page = m_leftDocument->getCatalog()->getPage(leftPageContext.pageIndex); + PDFReal epsilon = calculateEpsilonForPage(page); + + for (const size_t rightIndex : rightUnmatched) + { + const PDFDiffPageContext& rightPageContext = rightPreparedPages[rightIndex]; + if (leftPageContext.graphicPieces.size() != rightPageContext.graphicPieces.size()) + { + // Match cannot exist, graphic pieces have different size + continue; + } + + PDFDiffHelper::Differences differences = PDFDiffHelper::calculateDifferences(leftPageContext.graphicPieces, rightPageContext.graphicPieces, epsilon); + + if (differences.isEmpty()) + { + // Jakub Melka: we have a match + matchedPages[leftIndex].push_back(rightIndex); + } + } + }; + + PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Page, leftUnmatched.begin(), leftUnmatched.end(), matchLeftPage); + + std::vector leftPagesMoved; + std::vector rightPagesMoved; + + std::set matchedRightPages; + for (const auto& matchedPage : matchedPages) + { + for (size_t rightContextIndex : matchedPage.second) + { + if (!matchedRightPages.count(rightContextIndex)) + { + matchedRightPages.insert(rightContextIndex); + const PDFDiffPageContext& leftPageContext = leftPreparedPages[matchedPage.first]; + const PDFDiffPageContext& rightPageContext = rightPreparedPages[rightContextIndex]; + + leftPagesMoved.push_back(leftPageContext.pageIndex); + rightPagesMoved.push_back(rightPageContext.pageIndex); + + pageMatches[leftPageContext.pageIndex] = rightPageContext.pageIndex; + } + } + } + + if (!pageMatches.empty()) + { + algorithm.perform(); + pageSequence = algorithm.getSequence(); + } + + std::sort(leftPagesMoved.begin(), leftPagesMoved.end()); + std::sort(rightPagesMoved.begin(), rightPagesMoved.end()); + + PDFAlgorithmLongestCommonSubsequenceBase::markSequence(pageSequence, leftPagesMoved, rightPagesMoved); +} + +void PDFDiff::performSteps(const std::vector& leftPages, const std::vector& rightPages) +{ + std::vector leftPreparedPages; + std::vector rightPreparedPages; + + PDFDiffHelper::PageSequence pageSequence; + std::map pageMatches; // Indices are real page indices, not indices to page contexts + + auto createDiffPageContext = [](auto pageIndex) + { + PDFDiffPageContext context; + context.pageIndex = pageIndex; + return context; + }; + std::transform(leftPages.cbegin(), leftPages.cend(), std::back_inserter(leftPreparedPages), createDiffPageContext); + std::transform(rightPages.cbegin(), rightPages.cend(), std::back_inserter(rightPreparedPages), createDiffPageContext); + + // StepExtractContentLeftDocument + if (!m_cancelled) + { + PDFFontCache fontCache(DEFAULT_FONT_CACHE_LIMIT, DEFAULT_REALIZED_FONT_CACHE_LIMIT); + PDFOptionalContentActivity optionalContentActivity(m_leftDocument, pdf::OCUsage::View, nullptr); + fontCache.setDocument(pdf::PDFModifiedDocument(const_cast(m_leftDocument), &optionalContentActivity)); + + PDFCMSManager cmsManager(nullptr); + cmsManager.setDocument(m_leftDocument); + PDFCMSPointer cms = cmsManager.getCurrentCMS(); + + auto fillPageContext = [&, this](PDFDiffPageContext& context) + { + PDFPrecompiledPage compiledPage; + constexpr PDFRenderer::Features features = PDFRenderer::IgnoreOptionalContent; + PDFRenderer renderer(m_leftDocument, &fontCache, cms.data(), &optionalContentActivity, features, pdf::PDFMeshQualitySettings()); + renderer.compile(&compiledPage, context.pageIndex); + + auto page = m_leftDocument->getCatalog()->getPage(context.pageIndex); + PDFReal epsilon = calculateEpsilonForPage(page); + context.graphicPieces = compiledPage.calculateGraphicPieceInfos(page->getMediaBox(), epsilon); + + finalizeGraphicsPieces(context); + }; + PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Page, leftPreparedPages.begin(), leftPreparedPages.end(), fillPageContext); + stepProgress(); + } + + // StepExtractContentRightDocument + if (!m_cancelled) + { + PDFFontCache fontCache(DEFAULT_FONT_CACHE_LIMIT, DEFAULT_REALIZED_FONT_CACHE_LIMIT); + PDFOptionalContentActivity optionalContentActivity(m_rightDocument, pdf::OCUsage::View, nullptr); + fontCache.setDocument(pdf::PDFModifiedDocument(const_cast(m_rightDocument), &optionalContentActivity)); + + PDFCMSManager cmsManager(nullptr); + cmsManager.setDocument(m_rightDocument); + PDFCMSPointer cms = cmsManager.getCurrentCMS(); + + auto fillPageContext = [&, this](PDFDiffPageContext& context) + { + PDFPrecompiledPage compiledPage; + constexpr PDFRenderer::Features features = PDFRenderer::IgnoreOptionalContent; + PDFRenderer renderer(m_rightDocument, &fontCache, cms.data(), &optionalContentActivity, features, pdf::PDFMeshQualitySettings()); + renderer.compile(&compiledPage, context.pageIndex); + + const PDFPage* page = m_rightDocument->getCatalog()->getPage(context.pageIndex); + PDFReal epsilon = calculateEpsilonForPage(page); + context.graphicPieces = compiledPage.calculateGraphicPieceInfos(page->getMediaBox(), epsilon); + + finalizeGraphicsPieces(context); + }; + + PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Page, rightPreparedPages.begin(), rightPreparedPages.end(), fillPageContext); + stepProgress(); + } + + // StepMatchPages + if (!m_cancelled) + { + performPageMatching(leftPreparedPages, rightPreparedPages, pageSequence, pageMatches); + stepProgress(); + } + + // StepExtractTextLeftDocument + if (!m_cancelled) + { + pdf::PDFDocumentTextFlowFactory factoryLeftDocumentTextFlow; + factoryLeftDocumentTextFlow.setCalculateBoundingBoxes(true); + PDFDocumentTextFlow leftTextFlow = factoryLeftDocumentTextFlow.create(m_leftDocument, leftPages, m_textAnalysisAlgorithm); + std::map splittedText = leftTextFlow.split(PDFDocumentTextFlow::Text); + for (PDFDiffPageContext& leftContext : leftPreparedPages) + { + auto it = splittedText.find(leftContext.pageIndex); + if (it != splittedText.cend()) + { + leftContext.text = std::move(it->second); + splittedText.erase(it); + } + } + stepProgress(); + } + + // StepExtractTextRightDocument + if (!m_cancelled) + { + pdf::PDFDocumentTextFlowFactory factoryRightDocumentTextFlow; + factoryRightDocumentTextFlow.setCalculateBoundingBoxes(true); + PDFDocumentTextFlow rightTextFlow = factoryRightDocumentTextFlow.create(m_rightDocument, rightPages, m_textAnalysisAlgorithm); + std::map splittedText = rightTextFlow.split(PDFDocumentTextFlow::Text); + for (PDFDiffPageContext& rightContext : rightPreparedPages) + { + auto it = splittedText.find(rightContext.pageIndex); + if (it != splittedText.cend()) + { + rightContext.text = std::move(it->second); + splittedText.erase(it); + } + } + stepProgress(); + } + + // StepCompare + if (!m_cancelled) + { + performCompare(leftPreparedPages, rightPreparedPages, pageSequence, pageMatches); + stepProgress(); + } +} + +void PDFDiff::performCompare(const std::vector& leftPreparedPages, + const std::vector& rightPreparedPages, + PDFAlgorithmLongestCommonSubsequenceBase::Sequence& pageSequence, + const std::map& pageMatches) +{ + using AlgorithmLCS = PDFAlgorithmLongestCommonSubsequenceBase; + + auto modifiedRanges = AlgorithmLCS::getModifiedRanges(pageSequence); + + // First find all moved pages + for (const AlgorithmLCS::SequenceItem& item : pageSequence) + { + if (item.isMovedLeft()) + { + Q_ASSERT(pageMatches.contains(leftPreparedPages.at(item.index1).pageIndex)); + const PDFInteger leftIndex = leftPreparedPages[item.index1].pageIndex; + const PDFInteger rightIndex = pageMatches.at(leftIndex); + m_result.addPageMoved(leftIndex, rightIndex); + } + if (item.isMoved()) + { + m_result.addPageMoved(leftPreparedPages[item.index1].pageIndex, rightPreparedPages[item.index2].pageIndex); + } + } + + std::vector textFlowDifferences; + + for (const auto& range : modifiedRanges) + { + AlgorithmLCS::SequenceItemFlags flags = AlgorithmLCS::collectFlags(range); + + 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) + { + PDFDocumentTextFlow leftTextFlow; + PDFDocumentTextFlow rightTextFlow; + + const bool isTextComparedAsVectorGraphics = m_options.testFlag(CompareTextsAsVector); + + for (auto it = range.first; it != range.second; ++it) + { + const AlgorithmLCS::SequenceItem& item = *it; + if (item.isReplaced()) + { + const PDFDiffPageContext& leftPageContext = leftPreparedPages[item.index1]; + const PDFDiffPageContext& rightPageContext = rightPreparedPages[item.index2]; + + if (!isTextComparedAsVectorGraphics) + { + leftTextFlow.append(leftPageContext.text); + rightTextFlow.append(rightPageContext.text); + } + + 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) + { + case PDFDiffHelper::GraphicPieceInfo::Type::Text: + if (isTextComparedAsVectorGraphics) + { + m_result.addRemovedTextCharContent(leftPageContext.pageIndex, info.boundingRect); + } + break; + + case PDFDiffHelper::GraphicPieceInfo::Type::VectorGraphics: + m_result.addRemovedVectorGraphicContent(leftPageContext.pageIndex, info.boundingRect); + break; + + case PDFDiffHelper::GraphicPieceInfo::Type::Image: + m_result.addRemovedImageContent(leftPageContext.pageIndex, info.boundingRect); + break; + + case PDFDiffHelper::GraphicPieceInfo::Type::Shading: + m_result.addRemovedShadingContent(leftPageContext.pageIndex, info.boundingRect); + break; + + default: + Q_ASSERT(false); + break; + } + } + + for (const PDFDiffHelper::GraphicPieceInfo& info : differences.right) + { + switch (info.type) + { + case PDFDiffHelper::GraphicPieceInfo::Type::Text: + if (isTextComparedAsVectorGraphics) + { + m_result.addAddedTextCharContent(rightPageContext.pageIndex, info.boundingRect); + } + break; + + case PDFDiffHelper::GraphicPieceInfo::Type::VectorGraphics: + m_result.addAddedVectorGraphicContent(rightPageContext.pageIndex, info.boundingRect); + break; + + case PDFDiffHelper::GraphicPieceInfo::Type::Image: + m_result.addAddedImageContent(rightPageContext.pageIndex, info.boundingRect); + break; + + case PDFDiffHelper::GraphicPieceInfo::Type::Shading: + m_result.addAddedShadingContent(rightPageContext.pageIndex, info.boundingRect); + break; + + default: + Q_ASSERT(false); + break; + } + } + } + + if (item.isAdded()) + { + const PDFDiffPageContext& rightPageContext = rightPreparedPages[item.index2]; + + if (!isTextComparedAsVectorGraphics) + { + rightTextFlow.append(rightPageContext.text); + } + + m_result.addPageAdded(rightPageContext.pageIndex); + } + if (item.isRemoved()) + { + const PDFDiffPageContext& leftPageContext = leftPreparedPages[item.index1]; + + if (!isTextComparedAsVectorGraphics) + { + leftTextFlow.append(leftPageContext.text); + } + + m_result.addPageRemoved(leftPageContext.pageIndex); + } + } + + textFlowDifferences.emplace_back(); + PDFDiffHelper::TextFlowDifferences& addedDifferences = textFlowDifferences.back(); + addedDifferences.leftText = leftTextFlow.getText(); + addedDifferences.rightText = rightTextFlow.getText(); + + if (addedDifferences.leftText == addedDifferences.rightText) + { + // Text is the same, no difference is found + textFlowDifferences.pop_back(); + } + else + { + addedDifferences.leftTextFlow = std::move(leftTextFlow); + addedDifferences.rightTextFlow = std::move(rightTextFlow); + } + } + else + { + for (auto it = range.first; it != range.second; ++it) + { + 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); + } + } + } + } + + // Jakub Melka: try to compare text differences + auto compareTexts = [this](PDFDiffHelper::TextFlowDifferences& context) + { + using TextCompareItem = PDFDiffHelper::TextCompareItem; + const bool isWordsComparingMode = m_options.testFlag(CompareWords); + + std::vector leftItems; + std::vector rightItems; + + leftItems = PDFDiffHelper::prepareTextCompareItems(context.leftTextFlow, isWordsComparingMode, true); + rightItems = PDFDiffHelper::prepareTextCompareItems(context.rightTextFlow, isWordsComparingMode, false); + + auto compareCharacters = [&](const TextCompareItem& a, const TextCompareItem& b) + { + const auto& aItem = a.left ? context.leftTextFlow : context.rightTextFlow; + const auto& bItem = b.left ? context.leftTextFlow : context.rightTextFlow; + + QStringRef aText(&aItem.getItem(a.index)->text, a.charIndex, a.charCount); + QStringRef bText(&bItem.getItem(b.index)->text, b.charIndex, b.charCount); + + return aText == bText; + }; + PDFAlgorithmLongestCommonSubsequence algorithm(leftItems.cbegin(), leftItems.cend(), + rightItems.cbegin(), rightItems.cend(), + compareCharacters); + algorithm.perform(); + PDFAlgorithmLongestCommonSubsequenceBase::Sequence sequence = algorithm.getSequence(); + PDFAlgorithmLongestCommonSubsequenceBase::markSequence(sequence, { }, { }); + PDFAlgorithmLongestCommonSubsequenceBase::SequenceItemRanges modifiedRanges = PDFAlgorithmLongestCommonSubsequenceBase::getModifiedRanges(sequence); + + // Merge modified sequences separated by just space + if (!isWordsComparingMode && !modifiedRanges.empty()) + { + auto itPrev = sequence.end(); + for (const auto& range : modifiedRanges) + { + if (itPrev != sequence.end()) + { + auto itNext = range.first; + + bool isReplaced = true; + for (auto it = itPrev; it != itNext && isReplaced; ++it) + { + const PDFAlgorithmLongestCommonSubsequenceBase::SequenceItem& item = *it; + + // If we doesn't have a match, then it is not a whitespace + if (!item.isMatch()) + { + isReplaced = false; + break; + } + + const TextCompareItem& compareItem = leftItems[item.index1]; + const auto& flowItem = compareItem.left ? context.leftTextFlow : context.rightTextFlow; + QChar character = flowItem.getItem(compareItem.index)->text.at(compareItem.charIndex); + + isReplaced = !character.isSpace(); + } + + if (isReplaced) + { + for (auto it = itPrev; it != itNext; ++it) + { + PDFAlgorithmLongestCommonSubsequenceBase::SequenceItem& item = *it; + item.markReplaced(); + } + } + } + + itPrev = range.second; + } + + modifiedRanges = PDFAlgorithmLongestCommonSubsequenceBase::getModifiedRanges(sequence); + } + + for (const auto& range : modifiedRanges) + { + auto it = range.first; + auto itEnd = range.second; + + QStringList leftStrings; + QStringList rightStrings; + + for (; it != itEnd; ++it) + { + const PDFAlgorithmLongestCommonSubsequenceBase::SequenceItem& item = *it; + + if (item.isLeftValid()) + { + const TextCompareItem& textCompareItem = leftItems[item.index1]; + const auto& textFlow = textCompareItem.left ? context.leftTextFlow : context.rightTextFlow; + QStringRef text(&textFlow.getItem(textCompareItem.index)->text, textCompareItem.charIndex, textCompareItem.charCount); + leftStrings << text.toString(); + } + + if (item.isRightValid()) + { + const TextCompareItem& textCompareItem = rightItems[item.index2]; + const auto& textFlow = textCompareItem.left ? context.leftTextFlow : context.rightTextFlow; + QStringRef text(&textFlow.getItem(textCompareItem.index)->text, textCompareItem.charIndex, textCompareItem.charCount); + rightStrings << text.toString(); + } + } + + QString leftString; + QString rightString; + + if (isWordsComparingMode) + { + leftString = leftStrings.join(QChar::Space); + rightString = rightStrings.join(QChar::Space); + } + else + { + leftString = leftStrings.join(QString()); + rightString = rightStrings.join(QString()); + } + + + } + }; + + PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Page, textFlowDifferences.begin(), textFlowDifferences.end(), compareTexts); + //std::for_each(textFlowDifferences.begin(), textFlowDifferences.end(), compareTexts); +} + +void PDFDiff::finalizeGraphicsPieces(PDFDiffPageContext& context) +{ + std::sort(context.graphicPieces.begin(), context.graphicPieces.end()); + + // Compute page hash using active settings + QCryptographicHash hasher(QCryptographicHash::Sha512); + hasher.reset(); + + for (const PDFPrecompiledPage::GraphicPieceInfo& info : context.graphicPieces) + { + if (info.isText() && !m_options.testFlag(PC_Text)) + { + continue; + } + if (info.isVectorGraphics() && !m_options.testFlag(PC_VectorGraphics)) + { + continue; + } + if (info.isImage() && !m_options.testFlag(PC_Images)) + { + continue; + } + if (info.isShading() && !m_options.testFlag(PC_Mesh)) + { + continue; + } + + hasher.addData(reinterpret_cast(info.hash.data()), int(info.hash.size())); + } + + QByteArray hash = hasher.result(); + Q_ASSERT(QCryptographicHash::hashLength(QCryptographicHash::Sha512) == 64); + + size_t size = qMin(hash.length(), context.pageHash.size()); + std::copy(hash.data(), hash.data() + size, context.pageHash.data()); +} + +void PDFDiff::onComparationPerformed() +{ + m_cancelled = false; + m_result = m_future.result(); + emit comparationFinished(); +} + +PDFReal PDFDiff::calculateEpsilonForPage(const PDFPage* page) const +{ + Q_ASSERT(page); + + QRectF mediaBox = page->getMediaBox(); + + PDFReal width = mediaBox.width(); + PDFReal height = mediaBox.height(); + PDFReal factor = qMax(width, height); + + return factor * m_epsilon; +} + +PDFDocumentTextFlowFactory::Algorithm PDFDiff::getTextAnalysisAlgorithm() const +{ + return m_textAnalysisAlgorithm; +} + +void PDFDiff::setTextAnalysisAlgorithm(PDFDocumentTextFlowFactory::Algorithm textAnalysisAlgorithm) +{ + m_textAnalysisAlgorithm = textAnalysisAlgorithm; +} + +PDFDiffResult::PDFDiffResult() : + m_result(true) +{ + +} + +void PDFDiffResult::addPageMoved(PDFInteger pageIndex1, PDFInteger pageIndex2) +{ + Difference difference; + + difference.type = Type::PageMoved; + difference.pageIndex1 = pageIndex1; + difference.pageIndex2 = pageIndex2; + + m_differences.emplace_back(std::move(difference)); +} + +void PDFDiffResult::addPageAdded(PDFInteger pageIndex) +{ + Difference difference; + + difference.type = Type::PageAdded; + difference.pageIndex2 = pageIndex; + + m_differences.emplace_back(std::move(difference)); +} + +void PDFDiffResult::addPageRemoved(PDFInteger pageIndex) +{ + Difference difference; + + difference.type = Type::PageRemoved; + difference.pageIndex1 = pageIndex; + + m_differences.emplace_back(std::move(difference)); +} + +void PDFDiffResult::addLeftItem(Type type, PDFInteger pageIndex, QRectF rect) +{ + Difference difference; + + difference.type = type; + difference.pageIndex1 = pageIndex; + addRectLeft(difference, rect); + + m_differences.emplace_back(std::move(difference)); +} + +void PDFDiffResult::addRightItem(Type type, PDFInteger pageIndex, QRectF rect) +{ + Difference difference; + + difference.type = type; + difference.pageIndex2 = pageIndex; + addRectRight(difference, rect); + + m_differences.emplace_back(std::move(difference)); +} + +void PDFDiffResult::addRemovedTextCharContent(PDFInteger pageIndex, QRectF rect) +{ + addLeftItem(Type::RemovedTextCharContent, pageIndex, rect); +} + +void PDFDiffResult::addRemovedVectorGraphicContent(PDFInteger pageIndex, QRectF rect) +{ + addLeftItem(Type::RemovedVectorGraphicContent, pageIndex, rect); +} + +void PDFDiffResult::addRemovedImageContent(PDFInteger pageIndex, QRectF rect) +{ + addLeftItem(Type::RemovedImageContent, pageIndex, rect); +} + +void PDFDiffResult::addRemovedShadingContent(PDFInteger pageIndex, QRectF rect) +{ + addLeftItem(Type::RemovedShadingContent, pageIndex, rect); +} + +void PDFDiffResult::addAddedTextCharContent(PDFInteger pageIndex, QRectF rect) +{ + addRightItem(Type::AddedTextCharContent, pageIndex, rect); +} + +void PDFDiffResult::addAddedVectorGraphicContent(PDFInteger pageIndex, QRectF rect) +{ + addRightItem(Type::AddedVectorGraphicContent, pageIndex, rect); +} + +void PDFDiffResult::addAddedImageContent(PDFInteger pageIndex, QRectF rect) +{ + addRightItem(Type::AddedImageContent, pageIndex, rect); +} + +void PDFDiffResult::addAddedShadingContent(PDFInteger pageIndex, QRectF rect) +{ + addRightItem(Type::AddedShadingContent, pageIndex, rect); +} + +QString PDFDiffResult::getMessage(size_t index) const +{ + if (index >= m_differences.size()) + { + return QString(); + } + + const Difference& difference = m_differences[index]; + switch (difference.type) + { + case Type::PageMoved: + return PDFDiff::tr("Page no. %1 from old document has been moved to a new document at page no. %2.").arg(difference.pageIndex1 + 1).arg(difference.pageIndex2 + 1); + + case Type::PageAdded: + return PDFDiff::tr("Page no. %1 was added.").arg(difference.pageIndex2 + 1); + + case Type::PageRemoved: + return PDFDiff::tr("Page no. %1 was removed.").arg(difference.pageIndex1 + 1); + + case Type::RemovedTextCharContent: + return PDFDiff::tr("Removed text character from page %1.").arg(difference.pageIndex1 + 1); + + case Type::RemovedVectorGraphicContent: + return PDFDiff::tr("Removed vector graphics from page %1.").arg(difference.pageIndex1 + 1); + + case Type::RemovedImageContent: + return PDFDiff::tr("Removed image from page %1.").arg(difference.pageIndex1 + 1); + + case Type::RemovedShadingContent: + return PDFDiff::tr("Removed shading from page %1.").arg(difference.pageIndex1 + 1); + + case Type::AddedTextCharContent: + return PDFDiff::tr("Added text character from page %1.").arg(difference.pageIndex2 + 1); + + case Type::AddedVectorGraphicContent: + return PDFDiff::tr("Added vector graphics from page %1.").arg(difference.pageIndex2 + 1); + + case Type::AddedImageContent: + return PDFDiff::tr("Added image from page %1.").arg(difference.pageIndex2 + 1); + + case Type::AddedShadingContent: + return PDFDiff::tr("Added shading from page %1.").arg(difference.pageIndex2 + 1); + + default: + Q_ASSERT(false); + break; + } + + return QString(); +} + +void PDFDiffResult::addRectLeft(Difference& difference, QRectF rect) +{ + difference.leftRectIndex = m_rects.size(); + difference.leftRectCount = 1; + m_rects.emplace_back(rect); +} + +void PDFDiffResult::addRectRight(Difference& difference, QRectF rect) +{ + difference.rightRectIndex = m_rects.size(); + difference.rightRectCount = 1; + m_rects.emplace_back(rect); +} + +PDFDiffHelper::Differences PDFDiffHelper::calculateDifferences(const GraphicPieceInfos& left, + const GraphicPieceInfos& right, + PDFReal epsilon) +{ + Differences differences; + + Q_ASSERT(std::is_sorted(left.cbegin(), left.cend())); + Q_ASSERT(std::is_sorted(right.cbegin(), right.cend())); + + for (const GraphicPieceInfo& info : left) + { + if (!std::binary_search(right.cbegin(), right.cend(), info)) + { + differences.left.push_back(info); + } + } + + for (const GraphicPieceInfo& info : right) + { + if (!std::binary_search(left.cbegin(), left.cend(), info)) + { + differences.right.push_back(info); + } + } + + const PDFReal epsilonSquared = epsilon * epsilon; + + // If exact match fails, then try to use match with epsilon. For each + // item in left, we try to find matching item in right. + for (auto it = differences.left.begin(); it != differences.left.end();) + { + bool hasMatch = false; + + const GraphicPieceInfo& leftInfo = *it; + for (auto it2 = differences.right.begin(); it2 != differences.right.end();) + { + // Heuristically compare these items + + const GraphicPieceInfo& rightInfo = *it2; + if (leftInfo.type != rightInfo.type || !leftInfo.boundingRect.intersects(rightInfo.boundingRect)) + { + ++it2; + continue; + } + + const int elementCountPath1 = leftInfo.pagePath.elementCount(); + const int elementCountPath2 = rightInfo.pagePath.elementCount(); + + if (elementCountPath1 != elementCountPath2) + { + ++it2; + continue; + } + + hasMatch = (leftInfo.type != GraphicPieceInfo::Type::Image) || (leftInfo.imageHash == rightInfo.imageHash); + const int elementCount = leftInfo.pagePath.elementCount(); + for (int i = 0; i < elementCount && hasMatch; ++i) + { + QPainterPath::Element leftElement = leftInfo.pagePath.elementAt(i); + QPainterPath::Element rightElement = rightInfo.pagePath.elementAt(i); + + PDFReal diffX = leftElement.x - rightElement.x; + PDFReal diffY = leftElement.y - rightElement.y; + PDFReal squaredDistance = diffX * diffX + diffY * diffY; + + hasMatch = (leftElement.type == rightElement.type) && + (squaredDistance < epsilonSquared); + } + + if (hasMatch) + { + it2 = differences.right.erase(it2); + } + else + { + ++it2; + } + } + + if (hasMatch) + { + it = differences.left.erase(it); + } + else + { + ++it; + } + } + + return differences; +} + +std::vector PDFDiffHelper::getLeftUnmatched(const PageSequence& sequence) +{ + std::vector result; + + for (const auto& item : sequence) + { + if (item.isLeft()) + { + result.push_back(item.index1); + } + } + + return result; +} + +std::vector PDFDiffHelper::getRightUnmatched(const PageSequence& sequence) +{ + std::vector result; + + for (const auto& item : sequence) + { + if (item.isRight()) + { + result.push_back(item.index2); + } + } + + return result; +} + +void PDFDiffHelper::matchPage(PageSequence& sequence, + size_t leftPage, + size_t rightPage) +{ + for (auto it = sequence.begin(); it != sequence.end();) + { + auto& item = *it; + + if (item.isLeft() && item.index1 == leftPage) + { + item.index2 = rightPage; + } + + if (item.isRight() && item.index2 == rightPage) + { + it = sequence.erase(it); + } + else + { + ++it; + } + } +} + +std::vector PDFDiffHelper::prepareTextCompareItems(const PDFDocumentTextFlow& textFlow, + bool isWordsComparingMode, + bool isLeft) +{ + std::vector items; + + const size_t leftCount = textFlow.getSize(); + for (size_t i = 0; i < leftCount; ++i) + { + PDFDiffHelper::TextCompareItem item; + item.index = i; + item.left = isLeft; + item.charCount = 0; + + const PDFDocumentTextFlow::Item* textFlowItem = textFlow.getItem(i); + for (int j = 0; j < textFlowItem->text.size(); ++j) + { + if (isWordsComparingMode) + { + if (textFlowItem->text[j].isSpace()) + { + // Flush buffer + if (item.charCount > 0) + { + items.push_back(item); + item.charCount = 0; + } + } + else + { + if (item.charCount == 0) + { + item.charIndex = j; + } + ++item.charCount; + } + } + else + { + item.charIndex = j; + item.charCount = 1; + items.push_back(item); + } + } + + if (isWordsComparingMode && item.charCount > 0) + { + items.push_back(item); + item.charCount = 0; + } + } + + return items; +} + +} // namespace pdf diff --git a/Pdf4QtLib/sources/pdfdiff.h b/Pdf4QtLib/sources/pdfdiff.h index bd814ed..32712f7 100644 --- a/Pdf4QtLib/sources/pdfdiff.h +++ b/Pdf4QtLib/sources/pdfdiff.h @@ -1,223 +1,223 @@ -// 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 -// with the written consent of the copyright owner, 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 PDFDIFF_H -#define PDFDIFF_H - -#include "pdfdocument.h" -#include "pdfprogress.h" -#include "pdfutils.h" -#include "pdfalgorithmlcs.h" -#include "pdfdocumenttextflow.h" - -#include -#include -#include - -#include - -namespace pdf -{ - -struct PDFDiffPageContext; - -class PDFDiffResult -{ -public: - explicit PDFDiffResult(); - - enum class Type - { - Invalid, - PageMoved, - PageAdded, - PageRemoved, - RemovedTextCharContent, - RemovedVectorGraphicContent, - RemovedImageContent, - RemovedShadingContent, - AddedTextCharContent, - AddedVectorGraphicContent, - AddedImageContent, - AddedShadingContent, - }; - - struct Difference - { - Type type = Type::Invalid; - PDFInteger pageIndex1 = -1; - PDFInteger pageIndex2 = -1; - size_t leftRectIndex = 0; - size_t leftRectCount = 0; - size_t rightRectIndex = 0; - size_t rightRectCount = 0; - }; - - using Differences = std::vector; - - void setResult(PDFOperationResult result) { m_result = std::move(result); } - const PDFOperationResult& getResult() const { return m_result; } - - void addPageMoved(PDFInteger pageIndex1, PDFInteger pageIndex2); - void addPageAdded(PDFInteger pageIndex); - void addPageRemoved(PDFInteger pageIndex); - - void addRemovedTextCharContent(PDFInteger pageIndex, QRectF rect); - void addRemovedVectorGraphicContent(PDFInteger pageIndex, QRectF rect); - void addRemovedImageContent(PDFInteger pageIndex, QRectF rect); - void addRemovedShadingContent(PDFInteger pageIndex, QRectF rect); - void addAddedTextCharContent(PDFInteger pageIndex, QRectF rect); - void addAddedVectorGraphicContent(PDFInteger pageIndex, QRectF rect); - void addAddedImageContent(PDFInteger pageIndex, QRectF rect); - void addAddedShadingContent(PDFInteger pageIndex, QRectF rect); - - QString getMessage(size_t index) const; - -private: - void addLeftItem(Type type, PDFInteger pageIndex, QRectF rect); - void addRightItem(Type type, PDFInteger pageIndex, QRectF rect); - - void addRectLeft(Difference& difference, QRectF rect); - void addRectRight(Difference& difference, QRectF rect); - - Differences m_differences; - std::vector m_rects; - PDFOperationResult m_result; -}; - -/// Diff engine for comparing two pdf documents. -class PDF4QTLIBSHARED_EXPORT PDFDiff : public QObject -{ - Q_OBJECT - -private: - using BaseClass = QObject; - -public: - explicit PDFDiff(QObject* parent); - virtual ~PDFDiff() override; - - 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) - CompareTextsAsVector = 0x0020, ///< Compare texts as vector graphics - CompareWords = 0x0040, ///< Compare words, not just characters - }; - Q_DECLARE_FLAGS(Options, Option) - - /// Source document (left) - /// \param leftDocument Document - void setLeftDocument(const PDFDocument* leftDocument); - - /// Source document (right)( - /// \param rightDocument Document - void setRightDocument(const PDFDocument* rightDocument); - - /// Source pages to be compared (left document) - /// \param pagesForLeftDocument Page indices - void setPagesForLeftDocument(PDFClosedIntervalSet pagesForLeftDocument); - - /// Source pages to be compared (right document) - /// \param pagesForRightDocument Page indices - void setPagesForRightDocument(PDFClosedIntervalSet pagesForRightDocument); - - /// Sets progress object - /// \param progress Progress object - void setProgress(PDFProgress* progress) { m_progress = progress; } - - /// Enables or disables comparator engine option - /// \param option Option - /// \param enable Enable or disable option? - void setOption(Option option, bool enable) { m_options.setFlag(option, enable); } - - /// Starts comparator engine. If asynchronous engine option - /// is enabled, then separate thread is started, in which two - /// document is compared, and then signal \p comparationFinished, - /// otherwise this function is blocking until comparation process - /// is finished. - void start(); - - /// Stops comparator engine. Result data are cleared. - void stop(); - - /// Returns result of a comparation process - const PDFDiffResult& getResult() const { return m_result; } - - PDFDocumentTextFlowFactory::Algorithm getTextAnalysisAlgorithm() const; - void setTextAnalysisAlgorithm(PDFDocumentTextFlowFactory::Algorithm textAnalysisAlgorithm); - -signals: - void comparationFinished(); - -private: - - enum Steps - { - StepExtractContentLeftDocument, - StepExtractContentRightDocument, - StepMatchPages, - StepExtractTextLeftDocument, - StepExtractTextRightDocument, - StepCompare, - StepLast - }; - - PDFDiffResult perform(); - void stepProgress(); - void performSteps(const std::vector& leftPages, - const std::vector& rightPages); - void performPageMatching(const std::vector& leftPreparedPages, - const std::vector& rightPreparedPages, - PDFAlgorithmLongestCommonSubsequenceBase::Sequence& pageSequence, - std::map& pageMatches); - void performCompare(const std::vector& leftPreparedPages, - const std::vector& rightPreparedPages, - PDFAlgorithmLongestCommonSubsequenceBase::Sequence& pageSequence, - const std::map& pageMatches); - void finalizeGraphicsPieces(PDFDiffPageContext& context); - - void onComparationPerformed(); - - /// Calculates real epsilon for a page. Epsilon is used in page - /// comparation process, where points closer that epsilon - /// are recognized as equal. - /// \param page Page - PDFReal calculateEpsilonForPage(const PDFPage* page) const; - - PDFProgress* m_progress; - const PDFDocument* m_leftDocument; - const PDFDocument* m_rightDocument; - PDFClosedIntervalSet m_pagesForLeftDocument; - PDFClosedIntervalSet m_pagesForRightDocument; - Options m_options; - PDFReal m_epsilon; - std::atomic_bool m_cancelled; - PDFDiffResult m_result; - PDFDocumentTextFlowFactory::Algorithm m_textAnalysisAlgorithm; - - QFuture m_future; - std::optional> m_futureWatcher; -}; - -} // namespace pdf - -#endif // PDFDIFF_H +// 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 +// with the written consent of the copyright owner, 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 PDFDIFF_H +#define PDFDIFF_H + +#include "pdfdocument.h" +#include "pdfprogress.h" +#include "pdfutils.h" +#include "pdfalgorithmlcs.h" +#include "pdfdocumenttextflow.h" + +#include +#include +#include + +#include + +namespace pdf +{ + +struct PDFDiffPageContext; + +class PDFDiffResult +{ +public: + explicit PDFDiffResult(); + + enum class Type + { + Invalid, + PageMoved, + PageAdded, + PageRemoved, + RemovedTextCharContent, + RemovedVectorGraphicContent, + RemovedImageContent, + RemovedShadingContent, + AddedTextCharContent, + AddedVectorGraphicContent, + AddedImageContent, + AddedShadingContent, + }; + + struct Difference + { + Type type = Type::Invalid; + PDFInteger pageIndex1 = -1; + PDFInteger pageIndex2 = -1; + size_t leftRectIndex = 0; + size_t leftRectCount = 0; + size_t rightRectIndex = 0; + size_t rightRectCount = 0; + }; + + using Differences = std::vector; + + void setResult(PDFOperationResult result) { m_result = std::move(result); } + const PDFOperationResult& getResult() const { return m_result; } + + void addPageMoved(PDFInteger pageIndex1, PDFInteger pageIndex2); + void addPageAdded(PDFInteger pageIndex); + void addPageRemoved(PDFInteger pageIndex); + + void addRemovedTextCharContent(PDFInteger pageIndex, QRectF rect); + void addRemovedVectorGraphicContent(PDFInteger pageIndex, QRectF rect); + void addRemovedImageContent(PDFInteger pageIndex, QRectF rect); + void addRemovedShadingContent(PDFInteger pageIndex, QRectF rect); + void addAddedTextCharContent(PDFInteger pageIndex, QRectF rect); + void addAddedVectorGraphicContent(PDFInteger pageIndex, QRectF rect); + void addAddedImageContent(PDFInteger pageIndex, QRectF rect); + void addAddedShadingContent(PDFInteger pageIndex, QRectF rect); + + QString getMessage(size_t index) const; + +private: + void addLeftItem(Type type, PDFInteger pageIndex, QRectF rect); + void addRightItem(Type type, PDFInteger pageIndex, QRectF rect); + + void addRectLeft(Difference& difference, QRectF rect); + void addRectRight(Difference& difference, QRectF rect); + + Differences m_differences; + std::vector m_rects; + PDFOperationResult m_result; +}; + +/// Diff engine for comparing two pdf documents. +class PDF4QTLIBSHARED_EXPORT PDFDiff : public QObject +{ + Q_OBJECT + +private: + using BaseClass = QObject; + +public: + explicit PDFDiff(QObject* parent); + virtual ~PDFDiff() override; + + 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) + CompareTextsAsVector = 0x0020, ///< Compare texts as vector graphics + CompareWords = 0x0040, ///< Compare words, not just characters + }; + Q_DECLARE_FLAGS(Options, Option) + + /// Source document (left) + /// \param leftDocument Document + void setLeftDocument(const PDFDocument* leftDocument); + + /// Source document (right)( + /// \param rightDocument Document + void setRightDocument(const PDFDocument* rightDocument); + + /// Source pages to be compared (left document) + /// \param pagesForLeftDocument Page indices + void setPagesForLeftDocument(PDFClosedIntervalSet pagesForLeftDocument); + + /// Source pages to be compared (right document) + /// \param pagesForRightDocument Page indices + void setPagesForRightDocument(PDFClosedIntervalSet pagesForRightDocument); + + /// Sets progress object + /// \param progress Progress object + void setProgress(PDFProgress* progress) { m_progress = progress; } + + /// Enables or disables comparator engine option + /// \param option Option + /// \param enable Enable or disable option? + void setOption(Option option, bool enable) { m_options.setFlag(option, enable); } + + /// Starts comparator engine. If asynchronous engine option + /// is enabled, then separate thread is started, in which two + /// document is compared, and then signal \p comparationFinished, + /// otherwise this function is blocking until comparation process + /// is finished. + void start(); + + /// Stops comparator engine. Result data are cleared. + void stop(); + + /// Returns result of a comparation process + const PDFDiffResult& getResult() const { return m_result; } + + PDFDocumentTextFlowFactory::Algorithm getTextAnalysisAlgorithm() const; + void setTextAnalysisAlgorithm(PDFDocumentTextFlowFactory::Algorithm textAnalysisAlgorithm); + +signals: + void comparationFinished(); + +private: + + enum Steps + { + StepExtractContentLeftDocument, + StepExtractContentRightDocument, + StepMatchPages, + StepExtractTextLeftDocument, + StepExtractTextRightDocument, + StepCompare, + StepLast + }; + + PDFDiffResult perform(); + void stepProgress(); + void performSteps(const std::vector& leftPages, + const std::vector& rightPages); + void performPageMatching(const std::vector& leftPreparedPages, + const std::vector& rightPreparedPages, + PDFAlgorithmLongestCommonSubsequenceBase::Sequence& pageSequence, + std::map& pageMatches); + void performCompare(const std::vector& leftPreparedPages, + const std::vector& rightPreparedPages, + PDFAlgorithmLongestCommonSubsequenceBase::Sequence& pageSequence, + const std::map& pageMatches); + void finalizeGraphicsPieces(PDFDiffPageContext& context); + + void onComparationPerformed(); + + /// Calculates real epsilon for a page. Epsilon is used in page + /// comparation process, where points closer that epsilon + /// are recognized as equal. + /// \param page Page + PDFReal calculateEpsilonForPage(const PDFPage* page) const; + + PDFProgress* m_progress; + const PDFDocument* m_leftDocument; + const PDFDocument* m_rightDocument; + PDFClosedIntervalSet m_pagesForLeftDocument; + PDFClosedIntervalSet m_pagesForRightDocument; + Options m_options; + PDFReal m_epsilon; + std::atomic_bool m_cancelled; + PDFDiffResult m_result; + PDFDocumentTextFlowFactory::Algorithm m_textAnalysisAlgorithm; + + QFuture m_future; + std::optional> m_futureWatcher; +}; + +} // namespace pdf + +#endif // PDFDIFF_H