2019-06-23 18:35:32 +02:00
|
|
|
// Copyright (C) 2018-2019 Jakub Melka
|
2018-12-14 19:41:12 +01:00
|
|
|
//
|
|
|
|
// This file is part of PdfForQt.
|
|
|
|
//
|
|
|
|
// PdfForQt is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// PdfForQt 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 PDFForQt. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#ifndef PDFCATALOG_H
|
|
|
|
#define PDFCATALOG_H
|
|
|
|
|
|
|
|
#include "pdfobject.h"
|
2018-12-26 18:00:17 +01:00
|
|
|
#include "pdfpage.h"
|
2019-06-23 18:35:32 +02:00
|
|
|
#include "pdfoptionalcontent.h"
|
2019-11-17 17:41:07 +01:00
|
|
|
#include "pdfoutline.h"
|
2019-11-29 19:10:29 +01:00
|
|
|
#include "pdfaction.h"
|
2018-12-14 19:41:12 +01:00
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <vector>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace pdf
|
|
|
|
{
|
|
|
|
|
|
|
|
class PDFDocument;
|
|
|
|
|
|
|
|
/// Defines page layout. Default value is SinglePage. This enum specifies the page layout
|
|
|
|
/// to be used in viewer application.
|
|
|
|
enum class PageLayout
|
|
|
|
{
|
|
|
|
SinglePage, ///< Display one page at time (single page on screen)
|
|
|
|
OneColumn, ///< Displays pages in one column (continuous mode)
|
|
|
|
TwoColumnLeft, ///< Display pages in two continuous columns, odd numbered pages are on the left
|
|
|
|
TwoColumnRight, ///< Display pages in two continuous columns, even numbered pages are on the left
|
|
|
|
TwoPagesLeft, ///< Display two pages on the screen, odd numbered pages are on the left
|
|
|
|
TwoPagesRight ///< Display two pages on the screen, even numbered pages are on the left
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Specifies, how the document should be displayed in the viewer application.
|
|
|
|
enum class PageMode
|
|
|
|
{
|
|
|
|
UseNone, ///< Default value, neither document outline or thumbnails are visible
|
|
|
|
UseOutlines, ///< Document outline window is selected and visible
|
|
|
|
UseThumbnails, ///< Document thumbnails window is selected and visible
|
|
|
|
Fullscreen, ///< Use fullscreen mode, no menu bars, window controls, or any other window visible (presentation mode)
|
|
|
|
UseOptionalContent, ///< Optional content group window is selected and visible
|
|
|
|
UseAttachments, ///< Attachments window is selected and visible
|
|
|
|
};
|
|
|
|
|
2018-12-24 17:09:23 +01:00
|
|
|
/// Represents page numbering definition object
|
|
|
|
class PDFPageLabel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum class NumberingStyle
|
|
|
|
{
|
|
|
|
None, ///< This means, only prefix is used, no numbering
|
|
|
|
DecimalArabic,
|
|
|
|
UppercaseRoman,
|
|
|
|
LowercaseRoman,
|
|
|
|
UppercaseLetters,
|
|
|
|
LowercaseLetters
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit inline PDFPageLabel() :
|
|
|
|
m_numberingType(NumberingStyle::None),
|
|
|
|
m_prefix(),
|
|
|
|
m_pageIndex(0),
|
|
|
|
m_startNumber(0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit inline PDFPageLabel(NumberingStyle numberingType, const QString& prefix, PDFInteger pageIndex, PDFInteger startNumber) :
|
|
|
|
m_numberingType(numberingType),
|
|
|
|
m_prefix(prefix),
|
|
|
|
m_pageIndex(pageIndex),
|
|
|
|
m_startNumber(startNumber)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Comparison operator, works only with page indices (because they should be unique)
|
|
|
|
bool operator<(const PDFPageLabel& other) const { return m_pageIndex < other.m_pageIndex; }
|
|
|
|
|
|
|
|
/// Parses page label object from PDF object, according to PDF Reference 1.7, Table 8.10
|
|
|
|
static PDFPageLabel parse(PDFInteger pageIndex, const PDFDocument* document, const PDFObject& object);
|
|
|
|
|
|
|
|
private:
|
|
|
|
NumberingStyle m_numberingType;
|
|
|
|
QString m_prefix;
|
|
|
|
PDFInteger m_pageIndex;
|
|
|
|
PDFInteger m_startNumber;
|
|
|
|
};
|
|
|
|
|
2018-12-14 19:41:12 +01:00
|
|
|
class PDFViewerPreferences
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum OptionFlag
|
|
|
|
{
|
|
|
|
None = 0x0000, ///< Empty flag
|
|
|
|
HideToolbar = 0x0001, ///< Hide toolbar
|
|
|
|
HideMenubar = 0x0002, ///< Hide menubar
|
|
|
|
HideWindowUI = 0x0004, ///< Hide window UI (for example scrollbars, navigation controls, etc.)
|
|
|
|
FitWindow = 0x0008, ///< Resize window to fit first displayed page
|
|
|
|
CenterWindow = 0x0010, ///< Position of the document's window should be centered on the screen
|
|
|
|
DisplayDocTitle = 0x0020, ///< Display documents title instead of file name (introduced in PDF 1.4)
|
|
|
|
PickTrayByPDFSize = 0x0040 ///< Pick tray by PDF size (printing option)
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_FLAGS(OptionFlags, OptionFlag)
|
|
|
|
|
|
|
|
/// This enum specifies, how to display document, when exiting full screen mode.
|
|
|
|
enum class NonFullScreenPageMode
|
|
|
|
{
|
|
|
|
UseNone,
|
|
|
|
UseOutline,
|
|
|
|
UseThumbnails,
|
|
|
|
UseOptionalContent
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Predominant reading order of text.
|
|
|
|
enum class Direction
|
|
|
|
{
|
|
|
|
LeftToRight, ///< Default
|
|
|
|
RightToLeft ///< Reading order is right to left. Also used for vertical writing systems (Chinese/Japan etc.)
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Printer settings - paper handling option to use when printing the document.
|
|
|
|
enum class Duplex
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Simplex,
|
|
|
|
DuplexFlipShortEdge,
|
|
|
|
DuplexFlipLongEdge
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class PrintScaling
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
AppDefault
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Properties
|
|
|
|
{
|
|
|
|
ViewArea,
|
|
|
|
ViewClip,
|
|
|
|
PrintArea,
|
|
|
|
PrintClip,
|
|
|
|
EndProperties
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr inline PDFViewerPreferences() = default;
|
|
|
|
|
|
|
|
constexpr inline PDFViewerPreferences(const PDFViewerPreferences&) = default;
|
|
|
|
constexpr inline PDFViewerPreferences(PDFViewerPreferences&&) = default;
|
|
|
|
|
|
|
|
constexpr inline PDFViewerPreferences& operator=(const PDFViewerPreferences&) = default;
|
|
|
|
constexpr inline PDFViewerPreferences& operator=(PDFViewerPreferences&&) = default;
|
|
|
|
|
|
|
|
/// Parses viewer preferences from catalog dictionary. If object cannot be parsed, or error occurs,
|
|
|
|
/// then exception is thrown.
|
|
|
|
static PDFViewerPreferences parse(const PDFObject& catalogDictionary, const PDFDocument* document);
|
|
|
|
|
2019-11-06 18:25:46 +01:00
|
|
|
OptionFlags getOptions() const { return m_optionFlags; }
|
|
|
|
const QByteArray& getProperty(Properties property) const { return m_properties.at(property); }
|
|
|
|
NonFullScreenPageMode getNonFullScreenPageMode() const { return m_nonFullScreenPageMode; }
|
|
|
|
Direction getDirection() const { return m_direction; }
|
|
|
|
Duplex getDuplex() const { return m_duplex; }
|
|
|
|
PrintScaling getPrintScaling() const { return m_printScaling; }
|
|
|
|
const std::vector<std::pair<PDFInteger, PDFInteger>>& getPrintPageRanges() const { return m_printPageRanges; }
|
|
|
|
PDFInteger getNumberOfCopies() const { return m_numberOfCopies; }
|
|
|
|
|
2018-12-14 19:41:12 +01:00
|
|
|
private:
|
|
|
|
OptionFlags m_optionFlags = None;
|
|
|
|
std::array<QByteArray, EndProperties> m_properties;
|
|
|
|
NonFullScreenPageMode m_nonFullScreenPageMode = NonFullScreenPageMode::UseNone;
|
|
|
|
Direction m_direction = Direction::LeftToRight;
|
|
|
|
Duplex m_duplex = Duplex::None;
|
|
|
|
PrintScaling m_printScaling = PrintScaling::AppDefault;
|
|
|
|
std::vector<std::pair<PDFInteger, PDFInteger>> m_printPageRanges;
|
|
|
|
PDFInteger m_numberOfCopies = 1;
|
|
|
|
};
|
|
|
|
|
2019-11-30 16:26:32 +01:00
|
|
|
class PDFFORQTLIBSHARED_EXPORT PDFCatalog
|
2018-12-14 19:41:12 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
constexpr inline PDFCatalog() = default;
|
|
|
|
|
|
|
|
constexpr inline PDFCatalog(const PDFCatalog&) = default;
|
|
|
|
constexpr inline PDFCatalog(PDFCatalog&&) = default;
|
|
|
|
|
|
|
|
constexpr inline PDFCatalog& operator=(const PDFCatalog&) = default;
|
|
|
|
constexpr inline PDFCatalog& operator=(PDFCatalog&&) = default;
|
|
|
|
|
2019-11-30 16:26:32 +01:00
|
|
|
static constexpr const size_t INVALID_PAGE_INDEX = std::numeric_limits<size_t>::max();
|
|
|
|
|
2018-12-14 19:41:12 +01:00
|
|
|
/// Returns viewer preferences of the application
|
|
|
|
const PDFViewerPreferences* getViewerPreferences() const { return &m_viewerPreferences; }
|
|
|
|
|
2019-01-20 17:55:06 +01:00
|
|
|
/// Returns the page count
|
|
|
|
size_t getPageCount() const { return m_pages.size(); }
|
|
|
|
|
|
|
|
/// Returns the page
|
|
|
|
const PDFPage* getPage(size_t index) const { return &m_pages.at(index); }
|
|
|
|
|
2019-11-30 16:26:32 +01:00
|
|
|
/// Returns page index. If page is not found, then INVALID_PAGE_INDEX is returned.
|
|
|
|
size_t getPageIndexFromPageReference(PDFObjectReference reference) const;
|
|
|
|
|
2019-11-28 18:20:32 +01:00
|
|
|
/// Returns optional content properties
|
2019-06-23 18:35:32 +02:00
|
|
|
const PDFOptionalContentProperties* getOptionalContentProperties() const { return &m_optionalContentProperties; }
|
|
|
|
|
2019-11-28 18:20:32 +01:00
|
|
|
/// Returns root pointer for outline items
|
|
|
|
QSharedPointer<PDFOutlineItem> getOutlineRootPtr() const { return m_outlineRoot; }
|
|
|
|
|
2019-11-29 19:10:29 +01:00
|
|
|
/// Returns action, which should be performed
|
|
|
|
const PDFAction* getOpenAction() const { return m_openAction.data(); }
|
|
|
|
|
2019-11-30 16:26:32 +01:00
|
|
|
/// Returns version of the PDF specification, to which the document conforms.
|
|
|
|
const QByteArray& getVersion() const { return m_version; }
|
|
|
|
|
2019-11-29 19:10:29 +01:00
|
|
|
PageLayout getPageLayout() const { return m_pageLayout; }
|
|
|
|
PageMode getPageMode() const { return m_pageMode; }
|
2019-11-30 16:26:32 +01:00
|
|
|
const QByteArray& getBaseURI() const { return m_baseURI; }
|
2019-12-01 18:10:11 +01:00
|
|
|
const std::map<QByteArray, PDFFileSpecification>& getEmbeddedFiles() const { return m_embeddedFiles; }
|
2019-11-30 16:26:32 +01:00
|
|
|
|
|
|
|
/// Returns destination using the key. If destination with the key is not found,
|
|
|
|
/// then nullptr is returned.
|
|
|
|
/// \param key Destination key
|
|
|
|
/// \returns Pointer to the destination, or nullptr
|
|
|
|
const PDFDestination* getDestination(const QByteArray& key) const;
|
2019-11-29 19:10:29 +01:00
|
|
|
|
2018-12-14 19:41:12 +01:00
|
|
|
/// Parses catalog from catalog dictionary. If object cannot be parsed, or error occurs,
|
|
|
|
/// then exception is thrown.
|
|
|
|
static PDFCatalog parse(const PDFObject& catalog, const PDFDocument* document);
|
|
|
|
|
|
|
|
private:
|
2019-11-30 16:26:32 +01:00
|
|
|
QByteArray m_version;
|
2018-12-14 19:41:12 +01:00
|
|
|
PDFViewerPreferences m_viewerPreferences;
|
2018-12-26 18:00:17 +01:00
|
|
|
std::vector<PDFPage> m_pages;
|
2018-12-24 17:09:23 +01:00
|
|
|
std::vector<PDFPageLabel> m_pageLabels;
|
2019-06-23 18:35:32 +02:00
|
|
|
PDFOptionalContentProperties m_optionalContentProperties;
|
2019-11-17 17:41:07 +01:00
|
|
|
QSharedPointer<PDFOutlineItem> m_outlineRoot;
|
2019-11-29 19:10:29 +01:00
|
|
|
PDFActionPtr m_openAction;
|
|
|
|
PageLayout m_pageLayout = PageLayout::SinglePage;
|
|
|
|
PageMode m_pageMode = PageMode::UseNone;
|
2019-11-30 16:26:32 +01:00
|
|
|
QByteArray m_baseURI;
|
|
|
|
|
|
|
|
// Maps from Names dictionary
|
|
|
|
std::map<QByteArray, PDFDestination> m_destinations;
|
|
|
|
std::map<QByteArray, PDFActionPtr> m_javaScriptActions;
|
|
|
|
std::map<QByteArray, PDFFileSpecification> m_embeddedFiles;
|
2018-12-14 19:41:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace pdf
|
|
|
|
|
|
|
|
#endif // PDFCATALOG_H
|