#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 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()); m_registry.registerPass(std::make_unique()); m_registry.registerPass(std::make_unique()); m_registry.registerPass(std::make_unique()); } std::shared_ptr 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