80 lines
3.9 KiB
C++
80 lines
3.9 KiB
C++
#pragma once
|
|
|
|
#include <pdfengine/pdf_document.hpp>
|
|
#include <pdfengine/display_list.hpp>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
#include <memory>
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
class WasmMockPage : public pdfengine::PdfPage {
|
|
public:
|
|
explicit WasmMockPage(int pageIndex);
|
|
~WasmMockPage() override = default;
|
|
|
|
[[nodiscard]] double width() const noexcept override { return 800.0; }
|
|
[[nodiscard]] double height() const noexcept override { return 1100.0; }
|
|
|
|
[[nodiscard]] std::expected<pdfengine::PageImage, pdfengine::EngineError> render(int dpi = 96) const override;
|
|
[[nodiscard]] std::expected<std::string, pdfengine::EngineError> extractText() const override;
|
|
[[nodiscard]] std::expected<std::vector<pdfengine::GlyphBounds>, pdfengine::EngineError> extractTextWithBounds() const override;
|
|
[[nodiscard]] std::expected<pdfengine::PageModel, pdfengine::EngineError> extractDocumentModel() const override;
|
|
[[nodiscard]] std::expected<std::vector<pdfengine::FontInfo>, pdfengine::EngineError> getFonts() const override;
|
|
[[nodiscard]] std::expected<std::vector<std::string>, pdfengine::EngineError> extractAnnotationsText() const override;
|
|
[[nodiscard]] std::expected<std::vector<pdfengine::PdfPage::AnnotationInfo>, pdfengine::EngineError> extractAnnotations() const override;
|
|
[[nodiscard]] std::expected<double, pdfengine::EngineError> getGlyphWidth(const std::string& fontName, uint32_t charcode, double fontSize) const override;
|
|
|
|
[[nodiscard]] pdfengine::DevicePoint pageToDevice(const pdfengine::Point2D& pagePoint, int deviceWidth, int deviceHeight, int rotate = 0) const noexcept override;
|
|
[[nodiscard]] pdfengine::Point2D deviceToPage(const pdfengine::DevicePoint& devicePoint, int deviceWidth, int deviceHeight, int rotate = 0) const noexcept override;
|
|
|
|
[[nodiscard]] const pdfengine::DisplayList& getDisplayList() const { return m_displayList; }
|
|
|
|
private:
|
|
int m_pageIndex;
|
|
pdfengine::DisplayList m_displayList;
|
|
};
|
|
|
|
class WasmMockDocument : public pdfengine::PdfDocument {
|
|
public:
|
|
WasmMockDocument(int pageCount, std::vector<uint8_t> data);
|
|
~WasmMockDocument() override = default;
|
|
|
|
[[nodiscard]] int pageCount() const noexcept override { return m_pageCount; }
|
|
[[nodiscard]] pdfengine::DocumentMetadata metadata() const noexcept override;
|
|
[[nodiscard]] std::expected<std::shared_ptr<pdfengine::PdfPage>, pdfengine::EngineError> getPage(int pageIndex) override;
|
|
[[nodiscard]] std::expected<std::vector<pdfengine::FontInfo>, pdfengine::EngineError> getFonts(int startPage = 0, int endPage = -1) const override;
|
|
|
|
std::expected<void, pdfengine::EngineError> applyEdits(const std::string& editsJson) override;
|
|
[[nodiscard]] std::expected<std::vector<uint8_t>, pdfengine::EngineError> saveIncremental() const override;
|
|
[[nodiscard]] std::expected<std::vector<uint8_t>, pdfengine::EngineError> getFontData(const std::string& internalFontId) const override;
|
|
[[nodiscard]] std::expected<std::shared_ptr<pdfengine::fonts::pdf_fonts::Font>, std::string> getResolvedFont(const pdfengine::FontInfo& fontInfo) override;
|
|
[[nodiscard]] std::expected<std::vector<uint8_t>, pdfengine::EngineError> saveFull() const override;
|
|
|
|
private:
|
|
int m_pageCount;
|
|
std::vector<uint8_t> m_data;
|
|
std::unordered_map<int, std::shared_ptr<WasmMockPage>> m_pages;
|
|
};
|
|
|
|
class PdfEngineFacade {
|
|
public:
|
|
PdfEngineFacade();
|
|
~PdfEngineFacade();
|
|
|
|
int loadDocument(const uint8_t* buffer, int size);
|
|
bool renderPage(int docHandle, int pageIndex, float scale, uint8_t* outputBuffer, int width, int height);
|
|
void freeDocument(int docHandle);
|
|
|
|
std::string getDocumentFonts(int docHandle, int startPage, int endPage);
|
|
std::string getPageFonts(int docHandle, int pageIndex);
|
|
std::string getPageTextJson(int docHandle, int pageIndex);
|
|
|
|
static const char* buildInfo();
|
|
static bool hasSkia();
|
|
|
|
private:
|
|
int m_nextHandle;
|
|
std::unordered_map<int, std::shared_ptr<pdfengine::PdfDocument>> m_documents;
|
|
};
|