2020-01-18 11:38:54 +01:00
|
|
|
// Copyright (C) 2018-2020 Jakub Melka
|
2018-11-21 19:30:15 +01:00
|
|
|
//
|
2020-12-20 19:03:58 +01:00
|
|
|
// This file is part of Pdf4Qt.
|
2018-11-21 19:30:15 +01:00
|
|
|
//
|
2020-12-20 19:03:58 +01:00
|
|
|
// Pdf4Qt is free software: you can redistribute it and/or modify
|
2018-11-21 19:30:15 +01: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,
|
2018-11-21 19:30:15 +01: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/>.
|
2018-11-21 19:30:15 +01:00
|
|
|
|
|
|
|
#ifndef PDFXREFTABLE_H
|
|
|
|
#define PDFXREFTABLE_H
|
|
|
|
|
|
|
|
#include "pdfglobal.h"
|
|
|
|
#include "pdfobject.h"
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace pdf
|
|
|
|
{
|
|
|
|
class PDFParsingContext;
|
|
|
|
|
|
|
|
/// Represents table of references in the PDF file. It contains
|
|
|
|
/// scanned table in the PDF file, together with information, if entry
|
|
|
|
/// is occupied, or it is free.
|
|
|
|
class PDFXRefTable
|
|
|
|
{
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(pdf::PDFXRefTable)
|
|
|
|
|
|
|
|
public:
|
|
|
|
constexpr inline explicit PDFXRefTable() = default;
|
|
|
|
|
|
|
|
// Enforce default copy constructor and default move constructor
|
|
|
|
constexpr inline PDFXRefTable(const PDFXRefTable&) = default;
|
|
|
|
constexpr inline PDFXRefTable(PDFXRefTable&&) = default;
|
|
|
|
|
|
|
|
// Enforce default copy assignment operator and move assignment operator
|
|
|
|
constexpr inline PDFXRefTable& operator=(const PDFXRefTable&) = default;
|
|
|
|
constexpr inline PDFXRefTable& operator=(PDFXRefTable&&) = default;
|
|
|
|
|
|
|
|
enum class EntryType
|
|
|
|
{
|
2019-07-01 12:29:57 +02:00
|
|
|
Free, ///< Entry represents a free item (no object)
|
|
|
|
Occupied, ///< Entry represents a occupied item (object)
|
|
|
|
InObjectStream ///< Entry in object stream
|
2018-11-21 19:30:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Entry
|
|
|
|
{
|
|
|
|
PDFObjectReference reference;
|
2019-07-01 12:29:57 +02:00
|
|
|
PDFObjectReference objectStream;
|
2018-11-21 19:30:15 +01:00
|
|
|
PDFInteger offset = -1;
|
2019-07-01 12:29:57 +02:00
|
|
|
PDFInteger indexInObjectStream = -1;
|
2018-11-21 19:30:15 +01:00
|
|
|
EntryType type = EntryType::Free;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Tries to read reference table from the byte array. If error occurs, then exception
|
|
|
|
/// is raised. This fuction also checks redundant entries.
|
|
|
|
/// \param context Current parsing context
|
|
|
|
/// \param byteArray Input byte array (containing the PDF file)
|
|
|
|
/// \param startTableOffset Offset of first reference table
|
|
|
|
void readXRefTable(PDFParsingContext* context, const QByteArray& byteArray, PDFInteger startTableOffset);
|
|
|
|
|
2018-11-25 14:48:08 +01:00
|
|
|
/// Filters only occupied entries and returns them
|
|
|
|
std::vector<Entry> getOccupiedEntries() const;
|
|
|
|
|
2019-07-01 12:29:57 +02:00
|
|
|
/// Filters only object stream entries and returns them
|
|
|
|
std::vector<Entry> getObjectStreamEntries() const;
|
|
|
|
|
2018-11-25 14:48:08 +01:00
|
|
|
/// Returns size of the reference table
|
|
|
|
std::size_t getSize() const { return m_entries.size(); }
|
|
|
|
|
|
|
|
/// Gets the entry for given reference. If entry for given reference is not found,
|
|
|
|
/// then free entry is returned.
|
|
|
|
const Entry& getEntry(PDFObjectReference reference) const;
|
|
|
|
|
2018-12-01 11:36:07 +01:00
|
|
|
/// Returns the trailer dictionary
|
|
|
|
const PDFObject& getTrailerDictionary() const { return m_trailerDictionary; }
|
|
|
|
|
2018-11-21 19:30:15 +01:00
|
|
|
private:
|
|
|
|
/// Reference table entries
|
|
|
|
std::vector<Entry> m_entries;
|
|
|
|
|
|
|
|
/// Trailer dictionary
|
|
|
|
PDFObject m_trailerDictionary;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace pdf
|
|
|
|
|
|
|
|
#endif // PDFXREFTABLE_H
|