done Image XObject handler (Do operator)

This commit is contained in:
azeeee05
2026-06-11 11:24:35 +05:30
parent 98e3a2f89c
commit addc888545
11 changed files with 410 additions and 2 deletions
+28 -1
View File
@@ -4,7 +4,8 @@
#include <memory>
#include <string>
#include <pdfengine/graphics_state.hpp>
#include <pdfengine/path.hpp>
#include <pdfengine/image.hpp>
namespace pdfengine {
class CommandVisitor;
@@ -45,6 +46,26 @@ struct DrawTextCommand : public Command {
void accept(CommandVisitor& visitor) const override;
};
struct FillPathCommand : public Command {
Path path;
explicit FillPathCommand(Path path) : path(std::move(path)) {}
void accept(CommandVisitor& visitor) const override;
};
struct StrokePathCommand : public Command {
Path path;
explicit StrokePathCommand(Path path) : path(std::move(path)) {}
void accept(CommandVisitor& visitor) const override;
};
struct DrawImageCommand : public Command {
ImageInfo image;
float x, y, width, height;
DrawImageCommand(ImageInfo img, float x, float y, float w, float h)
: image(std::move(img)), x(x), y(y), width(w), height(h) {}
void accept(CommandVisitor& visitor) const override;
};
// --- Visitor Interface ---
// The visitor interface that the renderer (or replay engine) implements
@@ -56,6 +77,9 @@ public:
virtual void visit(const SetTransformCommand& cmd) = 0;
virtual void visit(const FillRectCommand& cmd) = 0;
virtual void visit(const DrawTextCommand& cmd) = 0;
virtual void visit(const FillPathCommand& cmd) = 0;
virtual void visit(const StrokePathCommand& cmd) = 0;
virtual void visit(const DrawImageCommand& cmd) = 0;
};
// --- Display List Container ---
@@ -77,6 +101,9 @@ public:
void setTransform(const Matrix& m);
void fillRect(float x, float y, float w, float h);
void drawText(const std::string& text, float x, float y);
void fillPath(const Path& path);
void strokePath(const Path& path);
void drawImage(const ImageInfo& image, float x, float y, float w, float h);
[[nodiscard]] size_t size() const noexcept { return m_commands.size(); }
void clear() { m_commands.clear(); }
+24
View File
@@ -0,0 +1,24 @@
#pragma once
#include <vector>
#include <cstdint>
namespace pdfengine {
// Basic color spaces we might encounter
enum class ColorSpace {
DeviceGray,
DeviceRGB,
DeviceCMYK,
Indexed
};
// Holds decoded image data ready for the display list (typically RGBA)
struct ImageInfo {
int width = 0;
int height = 0;
int channels = 4; // 4 = RGBA
std::vector<uint8_t> pixelData; // Decoded raw pixels
};
} // namespace pdfengine
+66
View File
@@ -0,0 +1,66 @@
#pragma once
#include <vector>
namespace pdfengine {
// Basic point structure
struct Point {
float x = 0.0f;
float y = 0.0f;
};
// Represents a 2D vector path constructed from basic drawing commands.
class Path {
public:
enum class Verb {
MoveTo,
LineTo,
CubicBezierTo,
Close
};
struct Segment {
Verb verb;
Point points[3]; // Up to 3 points depending on verb (e.g., Cubic bezier)
};
Path() = default;
void moveTo(float x, float y) {
m_segments.push_back({Verb::MoveTo, {{x, y}, {}, {}}});
}
void lineTo(float x, float y) {
m_segments.push_back({Verb::LineTo, {{x, y}, {}, {}}});
}
void cubicTo(float cp1x, float cp1y, float cp2x, float cp2y, float x, float y) {
m_segments.push_back({Verb::CubicBezierTo, {{cp1x, cp1y}, {cp2x, cp2y}, {x, y}}});
}
void close() {
m_segments.push_back({Verb::Close, {{}, {}, {}}});
}
// Helper for 're' (rectangle) operator
void addRect(float x, float y, float w, float h) {
moveTo(x, y);
lineTo(x + w, y);
lineTo(x + w, y + h);
lineTo(x, y + h);
close();
}
void clear() {
m_segments.clear();
}
[[nodiscard]] const std::vector<Segment>& segments() const { return m_segments; }
[[nodiscard]] bool empty() const { return m_segments.empty(); }
private:
std::vector<Segment> m_segments;
};
} // namespace pdfengine
+3 -1
View File
@@ -19,7 +19,9 @@ public:
void visit(const SetTransformCommand& cmd) override;
void visit(const FillRectCommand& cmd) override;
void visit(const DrawTextCommand& cmd) override;
void visit(const FillPathCommand& cmd) override;
void visit(const StrokePathCommand& cmd) override;
void visit(const DrawImageCommand& cmd) override;
// Renders the entire display list to the canvas
void render(const DisplayList& displayList);