This commit is contained in:
Furqan-14
2026-06-17 11:39:58 +05:30
40 changed files with 2633 additions and 5 deletions
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <cstdint>
#include <memory>
namespace pdfengine {
enum class AstNodeType {
Number,
Name,
String,
HexString,
Boolean,
Null,
Array,
Dictionary
};
class AstNode {
public:
AstNodeType type;
std::string stringValue;
std::vector<uint8_t> bytesValue;
double numberValue = 0.0;
bool boolValue = false;
// We use a vector of shared_ptr for recursive data structures so the node is easily copyable/movable
std::vector<std::shared_ptr<AstNode>> arrayItems;
std::unordered_map<std::string, std::shared_ptr<AstNode>> dictItems;
// Constructors for convenience
AstNode() = default;
explicit AstNode(AstNodeType t) : type(t) {}
};
struct Operation {
std::string op;
std::vector<std::shared_ptr<AstNode>> operands;
};
} // namespace pdfengine
@@ -0,0 +1,35 @@
#pragma once
#include <string>
#include <vector>
#include <memory>
namespace pdfengine {
enum class ContentObjectType {
Text,
Path,
Image,
Unknown
};
class ContentObject {
public:
virtual ~ContentObject() = default;
virtual ContentObjectType getType() const = 0;
};
class TextObject : public ContentObject {
public:
ContentObjectType getType() const override { return ContentObjectType::Text; }
std::string text; // The decoded text string
std::string fontName; // Font resource name (e.g. "F1")
double fontSize = 0.0; // Font size
// Text Transformation Matrix (a, b, c, d, e, f)
// Default is identity matrix: [1 0 0 1 0 0]
double tm[6] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0};
};
} // namespace pdfengine
@@ -0,0 +1,35 @@
#pragma once
#include <string>
#include <vector>
namespace pdfengine {
/// Result of extracting a raw PDF content stream from a page.
/// rawContent — bytes as-found in the PDF (may be compressed)
/// decodedContent — after applying all /Filter chains (FlateDecode, etc.)
/// pageIndex — 0-based page index
/// filters — list of filter names applied, e.g. {"FlateDecode"}
/// compressed — true if at least one filter was applied
struct ExtractedStream {
std::string rawContent;
std::string decodedContent;
int pageIndex = 0;
std::vector<std::string> filters;
bool compressed = false;
bool multiStream = false;
};
/// Verifies structural integrity of a decoded content stream.
/// Returns true if all of: BT, ET, Tf, Tj/TJ are present.
struct StreamVerification {
bool hasBT = false;
bool hasET = false;
bool hasTf = false;
bool hasTj = false; // Tj or TJ
bool multiStream = false; // page had multiple /Contents streams
};
StreamVerification verifyContentStream(const ExtractedStream& stream);
} // namespace pdfengine
+35
View File
@@ -0,0 +1,35 @@
#pragma once
#include <string>
#include <vector>
#include <cstdint>
namespace pdfengine {
enum class TokenType {
Operator, // e.g., "Tj", "BT", "ET", "Tf", "re", "f"
String, // e.g., "(Hello World)", fully unescaped
HexString, // e.g., "<48656C6C6F>", fully decoded to bytes
Name, // e.g., "/F1" (without the slash, unescaped)
Number, // e.g., "12.3", "-4", stored as string/double
ArrayStart, // "["
ArrayEnd, // "]"
DictStart, // "<<"
DictEnd, // ">>"
Boolean, // "true", "false"
Null, // "null"
EndOfStream // EOF marker
};
struct Token {
TokenType type;
std::string stringValue; // Used for Operator, String, Name
std::vector<uint8_t> bytesValue; // Used for HexString
double numberValue = 0.0; // Used for Number
// Position tracking for error reporting (optional but helpful)
size_t startOffset = 0;
size_t endOffset = 0;
};
} // namespace pdfengine