Structure tree parsing finalization

This commit is contained in:
Jakub Melka
2020-07-24 19:47:21 +02:00
parent 707f68fa19
commit 5d0b485d4e
2 changed files with 166 additions and 0 deletions

View File

@ -512,6 +512,30 @@ PDFStructureTree PDFStructureTree::parse(const PDFObjectStorage* storage, PDFObj
return tree;
}
PDFStructureItemPointer PDFStructureItem::parse(const PDFObjectStorage* storage, PDFObject object, PDFMarkedObjectsContext* context)
{
if (const PDFDictionary* dictionary = storage->getDictionaryFromObject(object))
{
PDFDocumentDataLoaderDecorator loader(storage);
QByteArray typeName = loader.readNameFromDictionary(dictionary, "Type");
if (typeName == "MCR")
{
return PDFStructureMarkedContentReference::parse(storage, object, context);
}
else if (typeName == "OBJR")
{
return PDFStructureObjectReference::parse(storage, object, context);
}
else
{
return PDFStructureElement::parse(storage, object, context);
}
}
return nullptr;
}
PDFStructureItem::Type PDFStructureItem::getTypeFromName(const QByteArray& name)
{
for (const auto& item : s_structureTreeItemTypes)
@ -655,4 +679,68 @@ PDFStructureItemPointer PDFStructureElement::parseElement(const PDFObjectStorage
return pointer;
}
PDFStructureItemPointer PDFStructureMarkedContentReference::parseMarkedContentReference(const PDFObjectStorage* storage,
PDFObject object,
PDFMarkedObjectsContext* context,
PDFStructureItem* parent,
PDFStructureTree* root)
{
PDFStructureItemPointer pointer;
Q_ASSERT(root);
if (auto lock = PDFMarkedObjectsLock(context, object))
{
if (const PDFDictionary* dictionary = storage->getDictionaryFromObject(object))
{
PDFStructureMarkedContentReference* item = new PDFStructureMarkedContentReference(parent, root);
pointer.reset(item);
if (object.isReference())
{
item->m_selfReference = object.getReference();
}
PDFDocumentDataLoaderDecorator loader(storage);
item->m_pageReference = loader.readReferenceFromDictionary(dictionary, "Pg");
item->m_contentStreamReference = loader.readReferenceFromDictionary(dictionary, "Stm");
item->m_contentStreamOwnerReference = loader.readReferenceFromDictionary(dictionary, "StmOwn");
item->m_markedContentIdentifier = loader.readIntegerFromDictionary(dictionary, "MCID", 0);
}
}
return pointer;
}
PDFStructureItemPointer PDFStructureObjectReference::parseObjectReference(const PDFObjectStorage* storage,
PDFObject object,
PDFMarkedObjectsContext* context,
PDFStructureItem* parent,
PDFStructureTree* root)
{
PDFStructureItemPointer pointer;
Q_ASSERT(root);
if (auto lock = PDFMarkedObjectsLock(context, object))
{
if (const PDFDictionary* dictionary = storage->getDictionaryFromObject(object))
{
PDFStructureObjectReference* item = new PDFStructureObjectReference(parent, root);
pointer.reset(item);
if (object.isReference())
{
item->m_selfReference = object.getReference();
}
PDFDocumentDataLoaderDecorator loader(storage);
item->m_pageReference = loader.readReferenceFromDictionary(dictionary, "Pg");
item->m_objectReference = loader.readReferenceFromDictionary(dictionary, "Obj");
}
}
return pointer;
}
} // namespace pdf