Files
pdf/engine/src/layout/layout_engine.cpp
T

48 lines
1.5 KiB
C++
Raw Normal View History

2026-08-03 11:26:44 +05:30
#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