mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Code generator (start)
This commit is contained in:
@ -225,6 +225,13 @@ const PDFObject& PDFObjectStorage::getObject(PDFObjectReference reference) const
|
||||
}
|
||||
}
|
||||
|
||||
PDFObjectReference PDFObjectStorage::addObject(PDFObject object)
|
||||
{
|
||||
PDFObjectReference reference(m_objects.size(), 0);
|
||||
m_objects.emplace_back(0, qMove(object));
|
||||
return reference;
|
||||
}
|
||||
|
||||
QByteArray PDFDocumentDataLoaderDecorator::readName(const PDFObject& object)
|
||||
{
|
||||
const PDFObject& dereferencedObject = m_document->getObject(object);
|
||||
|
@ -31,6 +31,7 @@
|
||||
namespace pdf
|
||||
{
|
||||
class PDFDocument;
|
||||
class PDFDocumentBuilder;
|
||||
|
||||
/// Storage for objects. This class is not thread safe for writing (calling non-const functions). Caller must ensure
|
||||
/// locking, if this object is used from multiple threads. Calling const functions should be thread safe.
|
||||
@ -77,6 +78,12 @@ public:
|
||||
/// Returns security handler associated with these objects
|
||||
const PDFSecurityHandler* getSecurityHandler() const { return m_securityHandler.data(); }
|
||||
|
||||
/// Adds a new object to the object list. This function
|
||||
/// is not thread safe, do not call it from multiple threads.
|
||||
/// \param object Object to be added
|
||||
/// \returns Reference to new object
|
||||
PDFObjectReference addObject(PDFObject object);
|
||||
|
||||
private:
|
||||
PDFObjects m_objects;
|
||||
PDFObject m_trailerDictionary;
|
||||
@ -372,6 +379,7 @@ public:
|
||||
|
||||
private:
|
||||
friend class PDFDocumentReader;
|
||||
friend class PDFDocumentBuilder;
|
||||
|
||||
explicit PDFDocument(PDFObjectStorage&& storage, PDFVersion version) :
|
||||
m_pdfObjectStorage(std::move(storage))
|
||||
|
@ -62,6 +62,15 @@ void PDFObjectFactory::endDictionaryItem()
|
||||
std::get<PDFDictionary>(dictionaryItem.object).addEntry(qMove(topItem.itemName), qMove(std::get<PDFObject>(topItem.object)));
|
||||
}
|
||||
|
||||
PDFObject PDFObjectFactory::takeObject()
|
||||
{
|
||||
Q_ASSERT(m_items.size() == 1);
|
||||
Q_ASSERT(m_items.back().type == ItemType::Object);
|
||||
PDFObject result = qMove(std::get<PDFObject>(m_items.back().object));
|
||||
m_items.clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
void PDFObjectFactory::addObject(PDFObject object)
|
||||
{
|
||||
if (m_items.empty())
|
||||
@ -127,4 +136,26 @@ PDFObjectFactory& PDFObjectFactory::operator<<(PDFObjectReference value)
|
||||
return *this;
|
||||
}
|
||||
|
||||
PDFDocumentBuilder::PDFDocumentBuilder() :
|
||||
m_version(1, 7)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PDFDocumentBuilder::PDFDocumentBuilder(const PDFDocument* document) :
|
||||
m_storage(document->getStorage()),
|
||||
m_version(document->getInfo()->version)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PDFDocument PDFDocumentBuilder::build() const
|
||||
{
|
||||
return PDFDocument(PDFObjectStorage(m_storage), m_version);
|
||||
}
|
||||
|
||||
/* START GENERATED CODE */
|
||||
|
||||
/* END GENERATED CODE */
|
||||
|
||||
} // namespace pdf
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define PDFDOCUMENTBUILDER_H
|
||||
|
||||
#include "pdfobject.h"
|
||||
#include "pdfdocument.h"
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
@ -63,6 +64,8 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
PDFObject takeObject();
|
||||
|
||||
private:
|
||||
void addObject(PDFObject object);
|
||||
|
||||
@ -111,7 +114,18 @@ private:
|
||||
class PDFDocumentBuilder
|
||||
{
|
||||
public:
|
||||
PDFDocumentBuilder();
|
||||
explicit PDFDocumentBuilder();
|
||||
explicit PDFDocumentBuilder(const PDFDocument* document);
|
||||
|
||||
PDFDocument build() const;
|
||||
|
||||
/* START GENERATED CODE */
|
||||
|
||||
/* END GENERATED CODE */
|
||||
|
||||
private:
|
||||
PDFObjectStorage m_storage;
|
||||
PDFVersion m_version;
|
||||
};
|
||||
|
||||
} // namespace pdf
|
||||
|
@ -646,7 +646,7 @@ PDFMesh PDFFunctionShading::createMesh(const PDFMeshQualitySettings& settings, c
|
||||
{
|
||||
if (std::fabs(sourceColorBuffer[colorComponentIndex + i] - sourceColorBuffer[colorOtherComponentIndex + i]) > settings.tolerance)
|
||||
{
|
||||
isMeshOK.store(std::memory_order_relaxed);
|
||||
isMeshOK.store(false, std::memory_order_relaxed);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -659,7 +659,7 @@ PDFMesh PDFFunctionShading::createMesh(const PDFMeshQualitySettings& settings, c
|
||||
{
|
||||
if (std::fabs(sourceColorBuffer[colorComponentIndex + i] - sourceColorBuffer[colorOtherComponentIndex + i]) > settings.tolerance)
|
||||
{
|
||||
isMeshOK.store(std::memory_order_relaxed);
|
||||
isMeshOK.store(false, std::memory_order_relaxed);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user