mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Object stastistics (first part)
This commit is contained in:
@ -17,6 +17,8 @@
|
||||
|
||||
#include "pdfobjectutils.h"
|
||||
#include "pdfvisitor.h"
|
||||
#include "pdfexecutionpolicy.h"
|
||||
#include "pdfdocumentwriter.h"
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
@ -362,6 +364,59 @@ std::vector<PDFObjectReference> PDFObjectClassifier::getObjectsByType(Type type)
|
||||
return result;
|
||||
}
|
||||
|
||||
PDFObjectClassifier::Statistics PDFObjectClassifier::calculateStatistics(const PDFDocument* document) const
|
||||
{
|
||||
Statistics result;
|
||||
|
||||
// Jakub Melka: prepare statistics map
|
||||
result.statistics[None];
|
||||
|
||||
for (uint i = 0; i < 32; ++i)
|
||||
{
|
||||
uint32_t mask = 1 << i;
|
||||
if (m_allTypesUsed & mask)
|
||||
{
|
||||
result.statistics[Type(mask)];
|
||||
}
|
||||
}
|
||||
|
||||
auto processEntry = [document, &result](const Classification& entry)
|
||||
{
|
||||
const PDFObject& object = document->getObjectByReference(entry.reference);
|
||||
|
||||
if (object.isNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Type type = Type(uint32_t(entry.types));
|
||||
if (!result.statistics.count(type))
|
||||
{
|
||||
type = None;
|
||||
}
|
||||
|
||||
Q_ASSERT(result.statistics.count(type));
|
||||
|
||||
const qint64 objectSize = PDFDocumentWriter::getObjectSize(document, entry.reference);
|
||||
|
||||
StatisticsItem& statisticsItem = result.statistics.at(type);
|
||||
statisticsItem.count.fetch_add(1);
|
||||
statisticsItem.bytes.fetch_add(objectSize);
|
||||
};
|
||||
|
||||
PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Unknown, m_classification.cbegin(), m_classification.cend(), processEntry);
|
||||
|
||||
PDFStatisticsCollector collector;
|
||||
PDFApplyVisitor(*document, &collector);
|
||||
|
||||
for (PDFObject::Type objectType : PDFObject::getTypes())
|
||||
{
|
||||
result.objectCountByType[size_t(objectType)] = collector.getObjectCount(objectType);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void PDFObjectClassifier::mark(PDFObjectReference reference, Type type)
|
||||
{
|
||||
Q_ASSERT(hasObject(reference));
|
||||
|
Reference in New Issue
Block a user