Image XObject handler (Do operator)

This commit is contained in:
saqib mir
2026-06-18 16:14:29 +05:30
parent 661600075a
commit b3d3ac4469
16 changed files with 596 additions and 23 deletions
@@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include <memory>
#include <pdfengine/graphics_state.hpp>
namespace pdfengine {
@@ -13,6 +14,13 @@ enum class ContentObjectType {
Unknown
};
enum class XObjectType {
Image,
Form,
Pattern,
Unknown
};
class ContentObject {
public:
virtual ~ContentObject() = default;
@@ -32,4 +40,23 @@ public:
double tm[6] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0};
};
class ImageObject : public ContentObject {
public:
ContentObjectType getType() const override { return ContentObjectType::Image; }
std::string name;
int width = 0;
int height = 0;
std::string colorSpace;
std::string filter;
int bitsPerComponent = 8;
bool hasSoftMask = false;
// Decoded raw pixels (RGBA format for Skia)
std::vector<uint8_t> pixelData;
// The Current Transformation Matrix (CTM) at the time the 'Do' operator was invoked
Matrix transform;
};
} // namespace pdfengine
+7 -4
View File
@@ -60,12 +60,15 @@ struct StrokePathCommand : public Command {
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) {}
Matrix matrix;
float opacity;
DrawImageCommand(ImageInfo img, Matrix m, float op = 1.0f)
: image(std::move(img)), matrix(m), opacity(op) {}
void accept(CommandVisitor& visitor) const override;
};
// --- Visitor Interface ---
// The visitor interface that the renderer (or replay engine) implements
@@ -103,7 +106,7 @@ public:
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);
void drawImage(const ImageInfo& image, const Matrix& m, float opacity = 1.0f);
[[nodiscard]] size_t size() const noexcept { return m_commands.size(); }
void clear() { m_commands.clear(); }