67 lines
1.4 KiB
C++
67 lines
1.4 KiB
C++
#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
|