48 lines
1.5 KiB
C++
48 lines
1.5 KiB
C++
#include "passes/column_detection_pass.hpp"
|
|||
|
|
#include "passes/line_detection_pass.hpp"
|
||
|
|
#include "passes/paragraph_detection_pass.hpp"
|
||
|
|
#include "passes/region_detection_pass.hpp"
|
||
|
|
|
||
|
|
#include <pdfengine/layout_engine.hpp>
|
||
|
|
|
||
|
|
namespace pdfengine {
|
||
|
|
|
||
|
|
LayoutEngine& LayoutEngine::instance() {
|
||
|
|
static LayoutEngine s_instance;
|
||
|
|
return s_instance;
|
||
|
|
}
|
||
|
|
|
||
|
|
LayoutEngine::LayoutEngine() {
|
||
|
|
// Register default pipeline passes in order
|
||
|
|
m_registry.registerPass(std::make_unique<LineDetectionPass>());
|
||
|
|
m_registry.registerPass(std::make_unique<ParagraphDetectionPass>());
|
||
|
|
m_registry.registerPass(std::make_unique<ColumnDetectionPass>());
|
||
|
|
m_registry.registerPass(std::make_unique<RegionDetectionPass>());
|
||
|
|
}
|
||
|
|
|
||
|
|
std::shared_ptr<PhysicalLayoutTree>
|
||
|
|
LayoutEngine::processPage(const std::string& documentId, int pageIndex, float width, float height) {
|
||
|
|
// Check MultiLevelCache first
|
||
|
|
CacheKey key{documentId, pageIndex, 1, 1};
|
||
|
|
auto cached = MultiLevelCache::instance().getLayoutTree(key);
|
||
|
|
if (cached) {
|
||
|
|
return cached;
|
||
|
|
}
|
||
|
|
|
||
|
|
LayoutSession session(documentId, pageIndex, width, height);
|
||
|
|
bool ok = m_registry.executeAll(session);
|
||
|
|
session.finish();
|
||
|
|
|
||
|
|
if (ok && session.context().physicalTree) {
|
||
|
|
MultiLevelCache::instance().putLayoutTree(key, session.context().physicalTree);
|
||
|
|
if (session.context().spatialIndex) {
|
||
|
|
MultiLevelCache::instance().putSpatialIndex(key, session.context().spatialIndex);
|
||
|
|
}
|
||
|
|
return session.context().physicalTree;
|
||
|
|
}
|
||
|
|
|
||
|
|
return nullptr;
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace pdfengine
|