DocPage Organizer: Bugfixing outline creation

This commit is contained in:
Jakub Melka 2021-08-08 15:39:33 +02:00
parent 8731e02823
commit cbdd1bcfb3
1 changed files with 7 additions and 9 deletions

View File

@ -91,12 +91,14 @@ PDFOperationResult PDFDocumentManipulator::assemble(const AssembledPages& pages)
PDFInteger documentIndex = 0; PDFInteger documentIndex = 0;
bool isWholeDocument = false; bool isWholeDocument = false;
QString caption; QString caption;
PDFObjectReference firstPageReference;
}; };
std::vector<DocumentPartInfo> documentParts = { DocumentPartInfo() }; std::vector<DocumentPartInfo> documentParts = { DocumentPartInfo() };
PDFClosedIntervalSet pageNumbers; PDFClosedIntervalSet pageNumbers;
PDFInteger imageCount = 0; PDFInteger imageCount = 0;
PDFInteger blankPageCount = 0; PDFInteger blankPageCount = 0;
PDFInteger totalPageCount = 0;
auto addDocumentPartCaption = [&](PDFInteger documentIndex) auto addDocumentPartCaption = [&](PDFInteger documentIndex)
{ {
@ -132,10 +134,12 @@ PDFOperationResult PDFDocumentManipulator::assemble(const AssembledPages& pages)
info.caption = documentTitle; info.caption = documentTitle;
info.documentIndex = documentIndex; info.documentIndex = documentIndex;
info.firstPageReference = (totalPageCount < PDFInteger(adjustedPages.size())) ? adjustedPages[totalPageCount] : PDFObjectReference();
pageNumbers = PDFClosedIntervalSet(); pageNumbers = PDFClosedIntervalSet();
imageCount = 0; imageCount = 0;
blankPageCount = 0; blankPageCount = 0;
totalPageCount += info.pageCount;
}; };
for (const AssembledPage& page : pages) for (const AssembledPage& page : pages)
@ -171,21 +175,16 @@ PDFOperationResult PDFDocumentManipulator::assemble(const AssembledPages& pages)
std::vector<size_t> documentPartPageCounts; std::vector<size_t> documentPartPageCounts;
std::transform(documentParts.cbegin(), documentParts.cend(), std::back_inserter(documentPartPageCounts), [](const auto& part) { return part.pageCount; }); std::transform(documentParts.cbegin(), documentParts.cend(), std::back_inserter(documentPartPageCounts), [](const auto& part) { return part.pageCount; });
documentBuilder.createDocumentParts(documentPartPageCounts);
std::vector<PDFObjectReference> parts = documentBuilder.createDocumentParts(documentPartPageCounts);
if (m_outlineMode != OutlineMode::NoOutline) if (m_outlineMode != OutlineMode::NoOutline)
{ {
QSharedPointer<PDFOutlineItem> rootItem(new PDFOutlineItem()); QSharedPointer<PDFOutlineItem> rootItem(new PDFOutlineItem());
int partIndex = 0; for (const DocumentPartInfo& info : documentParts)
for (const PDFObjectReference& documentPartReference : parts)
{ {
const DocumentPartInfo& info = documentParts[partIndex++];
QSharedPointer<PDFOutlineItem> documentPartItem(new PDFOutlineItem); QSharedPointer<PDFOutlineItem> documentPartItem(new PDFOutlineItem);
PDFObjectReference actionGoToPart = documentBuilder.createActionGoToDocumentPart(documentPartReference); documentPartItem->setAction(PDFActionPtr(new PDFActionGoTo(PDFDestination::createFit(info.firstPageReference), PDFDestination())));
auto action = PDFAction::parse(documentBuilder.getStorage(), documentBuilder.getObjectByReference(actionGoToPart));
documentPartItem->setAction(std::move(action));
documentPartItem->setTitle(info.caption); documentPartItem->setTitle(info.caption);
documentPartItem->setFontBold(true); documentPartItem->setFontBold(true);
@ -203,7 +202,6 @@ PDFOperationResult PDFDocumentManipulator::assemble(const AssembledPages& pages)
} }
rootItem->addChild(std::move(documentPartItem)); rootItem->addChild(std::move(documentPartItem));
} }
documentBuilder.setOutline(rootItem.data()); documentBuilder.setOutline(rootItem.data());