PDF4QT/PdfTool/pdftoolabstractapplication.h

289 lines
11 KiB
C
Raw Normal View History

2020-09-25 18:08:39 +02:00
// Copyright (C) 2020 Jakub Melka
//
2020-12-20 19:03:58 +01:00
// This file is part of Pdf4Qt.
2020-09-25 18:08:39 +02:00
//
2020-12-20 19:03:58 +01:00
// Pdf4Qt is free software: you can redistribute it and/or modify
2020-09-25 18:08:39 +02:00
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
2020-12-20 19:03:58 +01:00
// Pdf4Qt is distributed in the hope that it will be useful,
2020-09-25 18:08:39 +02:00
// 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
2020-12-20 19:03:58 +01:00
// along with Pdf4Qt. If not, see <https://www.gnu.org/licenses/>.
2020-09-25 18:08:39 +02:00
#ifndef PDFTOOLABSTRACTAPPLICATION_H
#define PDFTOOLABSTRACTAPPLICATION_H
2020-09-26 17:10:23 +02:00
#include "pdfoutputformatter.h"
#include "pdfdocument.h"
2020-10-11 18:21:20 +02:00
#include "pdfdocumenttextflow.h"
2020-10-25 18:55:25 +01:00
#include "pdfrenderer.h"
#include "pdfcms.h"
2020-11-01 18:50:21 +01:00
#include "pdfoptimizer.h"
2020-09-26 17:10:23 +02:00
2020-09-25 18:08:39 +02:00
#include <QtGlobal>
#include <QString>
2020-09-28 19:08:57 +02:00
#include <QDateTime>
2020-09-25 18:08:39 +02:00
#include <QCoreApplication>
#include <vector>
class QCommandLineParser;
namespace pdftool
{
struct PDFToolTranslationContext
{
Q_DECLARE_TR_FUNCTIONS(PDFToolTranslationContext)
};
struct PDFToolOptions
{
// For option 'ConsoleFormat'
PDFOutputFormatter::Style outputStyle = PDFOutputFormatter::Style::Text;
2020-10-17 16:56:39 +02:00
QString outputCodec = "UTF-8";
2020-10-04 16:56:55 +02:00
// For option 'DateFormat'
Qt::DateFormat outputDateFormat = Qt::DefaultLocaleShortDate;
// For option 'OpenDocument'
2020-09-25 18:08:39 +02:00
QString document;
QString password;
bool permissiveReading = true;
// For option 'SignatureVerification'
bool verificationUseUserCertificates = true;
bool verificationUseSystemCertificates = true;
bool verificationOmitCertificateCheck = false;
bool verificationPrintCertificateDetails = false;
bool verificationIgnoreExpirationDate = false;
// For option 'XMLExport'
2020-10-01 13:27:45 +02:00
bool xmlExportStreams = false;
bool xmlExportStreamsAsText = false;
2020-10-01 13:27:45 +02:00
bool xmlUseIndent = false;
bool xmlAlwaysBinaryStrings = false;
2020-10-02 15:14:45 +02:00
// For option 'Attachments'
QString attachmentsSaveNumber;
QString attachmentsSaveFileName;
QString attachmentsOutputDirectory;
QString attachmentsTargetFile;
bool attachmentsSaveAll = false;
2020-10-04 16:56:55 +02:00
// For option 'ComputeHashes'
bool computeHashes = false;
2020-10-05 19:50:04 +02:00
// For option 'PageSelector'
QString pageSelectorFirstPage;
QString pageSelectorLastPage;
QString pageSelectorSelection;
2020-10-11 18:21:20 +02:00
// For option 'TextAnalysis'
pdf::PDFDocumentTextFlowFactory::Algorithm textAnalysisAlgorithm = pdf::PDFDocumentTextFlowFactory::Algorithm::Auto;
2020-10-18 12:57:27 +02:00
// For option 'TextShow'
bool textShowPageNumbers = false;
bool textShowStructTitles = false;
bool textShowStructLanguage = false;
bool textShowStructAlternativeDescription = false;
bool textShowStructExpandedForm = false;
bool textShowStructActualText = false;
bool textShowStructPhoneme = false;
2020-10-19 18:51:30 +02:00
// For option 'VoiceSelector'
QString textVoiceName;
QString textVoiceGender;
QString textVoiceAge;
QString textVoiceLangCode;
// For option 'TextSpeech'
bool textSpeechMarkPageNumbers = false;
bool textSpeechSayPageNumbers = false;
bool textSpeechSayStructTitles = false;
bool textSpeechSayStructAlternativeDescription = false;
bool textSpeechSayStructExpandedForm = false;
bool textSpeechSayStructActualText = false;
2020-10-23 16:32:56 +02:00
QString textSpeechAudioFormat = "mp3";
2020-10-19 18:51:30 +02:00
2020-10-25 13:51:57 +01:00
// For option 'CharacterMaps'
bool showCharacterMapsForEmbeddedFonts = false;
2020-10-25 18:55:25 +01:00
// For option 'ImageWriterSettings'
pdf::PDFImageWriterSettings imageWriterSettings;
// For option 'ImageExportSettings'
pdf::PDFPageImageExportSettings imageExportSettings;
// For option 'ColorManagementSystem'
pdf::PDFCMSSettings cmsSettings;
2020-10-26 19:28:56 +01:00
// For option 'RenderFlags'
pdf::PDFRenderer::Features renderFeatures = pdf::PDFRenderer::getDefaultFeatures();
2020-10-28 16:35:16 +01:00
bool renderUseHardwareRendering = true;
2020-10-28 17:25:42 +01:00
bool renderShowPageStatistics = false;
2020-10-28 16:35:16 +01:00
int renderMSAAsamples = 4;
int renderRasterizerCount = pdf::PDFRasterizerPool::getDefaultRasterizerCount();
2020-10-26 19:28:56 +01:00
2020-10-31 14:23:13 +01:00
// For option 'Separate'
QString separatePagePattern;
2020-10-31 17:11:51 +01:00
// For option 'Unite'
QStringList uniteFiles;
2020-11-01 18:50:21 +01:00
// For option 'Optimize'
pdf::PDFOptimizer::OptimizationFlags optimizeFlags = pdf::PDFOptimizer::None;
2020-11-02 19:24:27 +01:00
// For option 'CertStore'
bool certStoreEnumerateSystemCertificates = false;
bool certStoreEnumerateUserCertificates = true;
2020-11-03 18:46:15 +01:00
// For option 'CertStoreInstall'
QString certificateStoreInstallCertificateFile;
2020-10-05 19:50:04 +02:00
/// Returns page range. If page range is invalid, then \p errorMessage is empty.
2020-10-07 18:57:34 +02:00
/// \param pageCount Page count
/// \param[out] errorMessage Error message
/// \param zeroBased Convert to zero based page range?
std::vector<pdf::PDFInteger> getPageRange(pdf::PDFInteger pageCount, QString& errorMessage, bool zeroBased) const;
2020-10-26 19:28:56 +01:00
struct RenderFeatureInfo
{
QString option;
QString description;
pdf::PDFRenderer::Feature feature;
};
/// Returns a list of available renderer features
static std::vector<RenderFeatureInfo> getRenderFeatures();
2020-11-01 18:50:21 +01:00
struct OptimizeFeatureInfo
{
QString option;
QString description;
pdf::PDFOptimizer::OptimizationFlag flag;
};
/// Returns a list of available optimize features
static std::vector<OptimizeFeatureInfo> getOptimizeFlagInfos();
2020-09-25 18:08:39 +02:00
};
/// Base class for all applications
class PDFToolAbstractApplication
{
public:
explicit PDFToolAbstractApplication(bool isDefault = false);
virtual ~PDFToolAbstractApplication() = default;
2020-09-26 17:10:23 +02:00
enum ExitCodes
{
ExitSuccess = EXIT_SUCCESS,
2020-10-05 19:50:04 +02:00
ExitFailure = EXIT_FAILURE,
2020-10-31 17:11:51 +01:00
ErrorUnknown,
ErrorNoDocumentSpecified,
2020-10-02 15:14:45 +02:00
ErrorDocumentReading,
2020-11-03 18:46:15 +01:00
ErrorCertificateReading,
2020-10-02 15:14:45 +02:00
ErrorInvalidArguments,
2020-10-18 12:57:27 +02:00
ErrorFailedWriteToFile,
2020-10-18 17:49:16 +02:00
ErrorPermissions,
2020-10-21 18:32:04 +02:00
ErrorNoText,
2020-10-18 17:49:16 +02:00
ErrorCOM,
ErrorSAPI
2020-09-26 17:10:23 +02:00
};
2020-09-25 18:08:39 +02:00
enum StandardString
{
Command, ///< Command, by which is this application invoked
Name, ///< Name of application
Description ///< Description (what this application does)
};
2020-09-26 17:10:23 +02:00
enum Option
{
2020-10-25 18:55:25 +01:00
ConsoleFormat = 0x00000001, ///< Set format of console output (text, xml or html)
OpenDocument = 0x00000002, ///< Flags for document reading
SignatureVerification = 0x00000004, ///< Flags for signature verification,
XmlExport = 0x00000008, ///< Flags for xml export
Attachments = 0x00000010, ///< Flags for attachments manipulating
DateFormat = 0x00000020, ///< Date format
ComputeHashes = 0x00000040, ///< Compute hashes
PageSelector = 0x00000080, ///< Select page range (or all pages)
TextAnalysis = 0x00000100, ///< Text analysis options
TextShow = 0x00000200, ///< Text extract and show options
VoiceSelector = 0x00000400, ///< Select voice from SAPI
TextSpeech = 0x00000800, ///< Text speech options
CharacterMaps = 0x00001000, ///< Character maps for embedded fonts
ImageWriterSettings = 0x00002000, ///< Settings for writing images (for example, format, etc.)
ImageExportSettingsFiles = 0x00004000, ///< Settings for exporting page images to files
ImageExportSettingsResolution = 0x00008000, ///< Settings for resolution of exported images
ColorManagementSystem = 0x00010000, ///< Color management system settings
RenderFlags = 0x00020000, ///< Render flags for page image rasterizer
2020-10-31 14:23:13 +01:00
Separate = 0x00040000, ///< Settings for Separate tool
2020-10-31 17:11:51 +01:00
Unite = 0x00080000, ///< Settings for Unite tool
2020-11-02 19:24:27 +01:00
Optimize = 0x00100000, ///< Settings for Optimize tool
CertStore = 0x00200000, ///< Settings for certificate store tool
2020-11-03 18:46:15 +01:00
CertStoreInstall = 0x00400000, ///< Settings for certificate store install certificate tool
2020-09-26 17:10:23 +02:00
};
Q_DECLARE_FLAGS(Options, Option)
2020-09-25 18:08:39 +02:00
virtual QString getStandardString(StandardString standardString) const = 0;
virtual int execute(const PDFToolOptions& options) = 0;
2020-09-26 17:10:23 +02:00
virtual Options getOptionsFlags() const = 0;
2020-09-25 18:08:39 +02:00
void initializeCommandLineParser(QCommandLineParser* parser) const;
PDFToolOptions getOptions(QCommandLineParser* parser) const;
2020-10-04 16:56:55 +02:00
protected:
/// Tries to read the document. If document is successfully read, true is returned,
/// if error occurs, then false is returned. Optionally, original document content
/// can also be retrieved.
/// \param options Options
/// \param document Document
/// \param[out] sourceData Pointer, to which source data are stored
bool readDocument(const PDFToolOptions& options, pdf::PDFDocument& document, QByteArray* sourceData = nullptr);
2020-09-25 18:08:39 +02:00
};
/// This class stores information about all applications available. Application
/// can be selected by command string. Also, default application is available.
class PDFToolApplicationStorage
{
public:
/// Returns application by command. If application for given command is not found,
/// then nullptr is returned.
/// \param command Command
/// \returns Application for given command or nullptr
static PDFToolAbstractApplication* getApplicationByCommand(const QString& command);
/// Registers application to the application storage. If \p isDefault
/// is set to true, application is registered as default application.
/// \param application Apllication
/// \param isDefault Is default application?
static void registerApplication(PDFToolAbstractApplication* application, bool isDefault = false);
/// Returns default application
/// \returns Default application
static PDFToolAbstractApplication* getDefaultApplication();
2020-09-26 17:10:23 +02:00
/// Returns a list of available applications
static const std::vector<PDFToolAbstractApplication*>& getApplications();
2020-09-25 18:08:39 +02:00
private:
PDFToolApplicationStorage() = default;
static PDFToolApplicationStorage* getInstance();
std::vector<PDFToolAbstractApplication*> m_applications;
PDFToolAbstractApplication* m_defaultApplication = nullptr;
};
} // namespace pdftool
2020-11-19 19:54:33 +01:00
Q_DECLARE_OPERATORS_FOR_FLAGS(pdftool::PDFToolAbstractApplication::Options)
2020-09-25 18:08:39 +02:00
#endif // PDFTOOLABSTRACTAPPLICATION_H