Files
pdf/engine/include/pdfengine/graphics_state.hpp
T
2026-05-22 15:49:10 +05:30

68 lines
1.6 KiB
C++

#pragma once
#include <vector>
#include <stdexcept>
namespace pdfengine {
// 2D Affine Transformation Matrix (3x3 matrix optimized for 2D)
// [ a b 0 ]
// [ c d 0 ]
// [ e f 1 ]
struct Matrix {
float a = 1.0f, b = 0.0f;
float c = 0.0f, d = 1.0f;
float e = 0.0f, f = 0.0f;
Matrix() = default;
Matrix(float a, float b, float c, float d, float e, float f)
: a(a), b(b), c(c), d(d), e(e), f(f) {}
// Multiply this matrix by another matrix
[[nodiscard]] Matrix multiply(const Matrix& other) const noexcept;
// Transform a 2D point using this matrix
void transform(float& x, float& y) const noexcept;
};
struct Color {
float r = 0.0f;
float g = 0.0f;
float b = 0.0f;
};
// Represents the current graphics state in a PDF document
struct GraphicsState {
Matrix ctm; // Current Transformation Matrix
Color fillColor;
Color strokeColor;
float lineWidth = 1.0f;
// In the future, this will also hold:
// - Clipping paths
// - Font state (current font, font size)
// - Dash patterns
// - Line cap/join styles
};
// Manages the q/Q stack of graphics states
class GraphicsStateStack {
public:
GraphicsStateStack();
// Corresponds to the 'q' operator (save graphics state)
void push();
// Corresponds to the 'Q' operator (restore graphics state)
void pop();
// Access the current active graphics state
[[nodiscard]] GraphicsState& current();
[[nodiscard]] const GraphicsState& current() const;
private:
std::vector<GraphicsState> m_stack;
};
} // namespace pdfengine