merged code with dev

This commit is contained in:
azeeee05
2026-05-22 15:50:43 +05:30
55 changed files with 5074 additions and 101 deletions
+78 -20
View File
@@ -1,26 +1,84 @@
// pdfengine — document API.
//
// ┌─────────────────────────────────────────────────────────────────────────┐
// │ PLACEHOLDER. This header is the deliverable of Phase 0 Gate G0b: │
// │ "Frozen interface contracts" — the PdfDocument / PdfPage API structs │
// │ reviewed and locked by all three developers before Phase 1 coding. │
// │ │
// │ Do NOT fill in method signatures yet. Nothing proceeds until the │
// │ contract is signed off (see docs/phase0.md, Gate G0b). │
// │ │
// │ Rule R2: only engine/src/parser/ may touch raw FPDF_* PDFium APIs. │
// │ Everything else in the codebase goes through these types. │
// └─────────────────────────────────────────────────────────────────────────┘
#pragma once
#include <expected>
#include <memory>
#include <string>
#include <vector>
#include <cstdint>
namespace pdfengine {
// Opaque, owning handle to a parsed PDF document.
// Full definition + API land at Gate G0b.
class PdfDocument;
enum class EngineError {
FileNotFound,
InvalidFormat,
PasswordRequired,
InvalidPassword,
PageOutOfBounds,
RenderFailed,
WriteFailed,
Unknown
};
// Opaque view onto a single page of a PdfDocument.
// Full definition + API land at Gate G0b.
class PdfPage;
struct DocumentMetadata {
std::string title;
std::string author;
std::string creator;
std::string producer;
std::string creationDate;
std::string modificationDate;
};
} // namespace pdfengine
struct PageImage {
int width;
int height;
std::vector<uint8_t> data;
};
struct Point2D {
double x;
double y;
};
struct DevicePoint {
int x;
int y;
};
class PdfPage {
public:
virtual ~PdfPage() = default;
[[nodiscard]] virtual double width() const noexcept = 0;
[[nodiscard]] virtual double height() const noexcept = 0;
[[nodiscard]] virtual std::expected<PageImage, EngineError> render(int dpi = 96) const = 0;
[[nodiscard]] virtual std::expected<std::string, EngineError> extractText() const = 0;
[[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;
};
class PdfDocument {
public:
virtual ~PdfDocument() = default;
[[nodiscard]] static std::expected<std::shared_ptr<PdfDocument>, EngineError>
loadFromFile(const std::string& path, const std::string& password = "");
[[nodiscard]] static std::expected<std::shared_ptr<PdfDocument>, EngineError>
loadFromMemory(const std::vector<uint8_t>& data, const std::string& password = "");
[[nodiscard]] virtual int pageCount() const noexcept = 0;
[[nodiscard]] virtual DocumentMetadata metadata() const noexcept = 0;
[[nodiscard]] virtual std::expected<std::shared_ptr<PdfPage>, EngineError>
getPage(int pageIndex) = 0;
virtual std::expected<void, EngineError> applyEdits(const std::string& editsJson) = 0;
[[nodiscard]] virtual std::expected<std::vector<uint8_t>, EngineError>
saveIncremental() const = 0;
};
}