create the api for the display list

This commit is contained in:
saqib mir
2026-06-22 16:23:59 +05:30
parent caf3feea15
commit 23b162f3c2
8 changed files with 161 additions and 3 deletions
@@ -209,6 +209,9 @@ public:
[[nodiscard]] virtual DevicePoint pageToDevice(const Point2D& pagePoint, int deviceWidth, int deviceHeight, int rotate = 0) const noexcept = 0;
[[nodiscard]] virtual Point2D deviceToPage(const DevicePoint& devicePoint, int deviceWidth, int deviceHeight, int rotate = 0) const noexcept = 0;
[[nodiscard]] virtual std::expected<std::string, EngineError> extractDisplayListJson() const = 0;
[[nodiscard]] virtual std::expected<std::vector<uint8_t>, EngineError> extractImageXObject(const std::string& name) const = 0;
};
namespace fonts::pdf_fonts { class Font; }
+48
View File
@@ -19,6 +19,9 @@
#include "fonts/shaping/hb_shaper.hpp"
#include "fonts/face/font_face.hpp"
#include "decoration_builder.hpp"
#include "qpdf/qpdf_extractor.hpp"
#include "parser/lexer.hpp"
#include "parser/parser.hpp"
#include <nlohmann/json.hpp>
#include <spdlog/spdlog.h>
@@ -4328,6 +4331,51 @@ std::expected<std::shared_ptr<fonts::pdf_fonts::Font>, std::string> PdfiumDocume
#endif
}
std::expected<std::string, EngineError> PdfiumPage::extractDisplayListJson() const {
#ifdef PDFENGINE_WITH_PDFIUM
if (!ownerDoc_) return std::unexpected(EngineError::Unknown);
const auto& buffer = ownerDoc_->getMemoryBuffer();
if (buffer.empty()) return std::unexpected(EngineError::FileNotFound);
qpdf_layer::QpdfExtractor extractor;
auto stream = extractor.extractPageStreamFromMemory(buffer, pageIndex_);
if (!stream) return std::unexpected(EngineError::InvalidFormat);
Lexer lexer(stream->decodedContent);
auto tokens = lexer.tokenize();
ContentParser parser(tokens);
auto operations = parser.parse();
nlohmann::json j_array = nlohmann::json::array();
for (const auto& op : operations) {
nlohmann::json j_op = nlohmann::json::object();
j_op["op"] = op.op;
if (!op.operands.empty()) {
nlohmann::json j_args = nlohmann::json::array();
for (const auto& arg : op.operands) {
if (arg->type == AstNodeType::Number) {
j_args.push_back(arg->numberValue);
} else if (arg->type == AstNodeType::Name || arg->type == AstNodeType::String) {
j_args.push_back(arg->stringValue);
} else {
j_args.push_back("<other>");
}
}
j_op["args"] = j_args;
}
j_array.push_back(j_op);
}
return j_array.dump();
#else
return std::unexpected(EngineError::Unknown);
#endif
}
std::expected<std::vector<uint8_t>, EngineError> PdfiumPage::extractImageXObject(const std::string& name) const {
(void)name;
return std::unexpected(EngineError::Unknown); // Stub for now
}
void PdfiumDocument::invalidateCaches() {
{
std::lock_guard<std::mutex> lock(fontsMutex_);
+5
View File
@@ -55,6 +55,9 @@ public:
std::expected<double, EngineError> getGlyphWidth(const std::string& fontName, uint32_t charcode, double fontSize) const override;
std::expected<std::string, EngineError> extractDisplayListJson() const override;
std::expected<std::vector<uint8_t>, EngineError> extractImageXObject(const std::string& name) const override;
DevicePoint pageToDevice(const Point2D& pagePoint, int deviceWidth, int deviceHeight, int rotate = 0) const noexcept override;
Point2D deviceToPage(const DevicePoint& devicePoint, int deviceWidth, int deviceHeight, int rotate = 0) const noexcept override;
@@ -102,6 +105,8 @@ public:
std::string lastReflowLayout() const { return lastReflowLayout_; }
bool lastReflowOverflowed() const { return lastReflowOverflowed_; }
const std::vector<uint8_t>& getMemoryBuffer() const { return memoryBuffer_; }
private:
mutable std::string lastReflowLayout_;
mutable bool lastReflowOverflowed_ = false;