5#include <cairomm-1.16/cairomm/cairomm.h>
10export import quantify;
43 editor->set_source_rgba(
c.r,
c.g,
c.b,
c.a * opacity);
52 return new solid{*
this};
62 return c == ((
const solid*)&rhl)->c;
75 std::pair<int, int> start,
76 std::pair<int, int> end,
77 const std::vector<std::pair<double, color::Color>>& _color_stops
83 for (
auto& item: _color_stops) {
87 .green = item.second.g,
88 .blue = item.second.b,
89 .alpha = item.second.a,
95 auto lg = Cairo::LinearGradient::create(
x0,
y0,
x1,
y1);
97 lg->add_color_stop_rgba(item.offset, item.red, item.green, item.blue, item.alpha);
99 editor->set_source(lg);
102 return "#00000000"_color;
125 std::pair<int, int> start,
127 std::pair<int, int> end,
129 const std::vector<std::pair<double, color::Color>>& _color_stops
137 for (
auto& item: _color_stops) {
139 .offset = item.first,
140 .red = item.second.r,
141 .green = item.second.g,
142 .blue = item.second.b,
143 .alpha = item.second.a,
149 auto lg = Cairo::RadialGradient::create(
x0,
y0,
r0,
x1,
y1,
r1);
151 lg->add_color_stop_rgba(item.offset, item.red, item.green, item.blue, item.alpha);
153 editor->set_source(lg);
156 return "#00000000"_color;
191 std::unique_ptr<base_i>
paint_data = std::make_unique<solid>();
193 type(
decltype(
paint_type) type_, std::unique_ptr<base_i>&& paint_data_)
197 template <
typename Pa
int>
198 static type make (Paint paint_data_) {
199 return type{paint_data_.get_type(), std::make_unique<Paint>(paint_data_)};
207 auto new_paint_data = std::unique_ptr<base_i>(rhl.
paint_data->make_copy());
208 std::swap(this->paint_data, new_paint_data);
220#define VG_ATTRIBUTE(TYPE, NAME, DEFAULT) \
221 template <typename E> \
222 struct attr_##NAME: public attribute_i { \
223 inline E& NAME(TYPE& _##NAME##_) { \
224 this->_##NAME = _##NAME##_; \
227 inline E& NAME(TYPE&& _##NAME##_) { \
228 this->_##NAME = _##NAME##_; \
231 TYPE _##NAME = DEFAULT; \
234#define VG_ATTRIBUTE_AUTO(TYPE, NAME, DEFAULT) \
235 template <typename E> \
236 struct attr_##NAME: public attribute_i { \
237 inline E& NAME(auto& _##NAME##_) { \
238 this->_##NAME = _##NAME##_; \
241 inline E& NAME(auto&& _##NAME##_) { \
242 this->_##NAME = _##NAME##_; \
245 TYPE _##NAME = DEFAULT; \
248#define VG_ATTRIBUTE_PAINT(NAME) \
249 template <typename E> \
250 struct attr_##NAME: public attribute_i { \
251 inline E& NAME(vg::paint::type& _##NAME##_) { \
252 this->_##NAME = _##NAME##_; \
255 inline E& NAME(vg::paint::type&& _##NAME##_) { \
256 this->_##NAME = _##NAME##_; \
259 inline E& NAME(vg::paint::solid& _##NAME##_) { \
260 this->_##NAME.paint_data = std::make_unique<vg::paint::solid>(_##NAME##_); \
261 this->_##NAME.paint_type = vg::paint::type::SOLID; \
264 inline E& NAME(vg::paint::solid&& _##NAME##_) { \
265 this->_##NAME.paint_data = std::make_unique<vg::paint::solid>(_##NAME##_); \
266 this->_##NAME.paint_type = vg::paint::type::SOLID; \
269 inline E& NAME(vg::paint::gradient::linear& _##NAME##_) { \
270 this->_##NAME.paint_data = std::make_unique<vg::paint::gradient::linear>(_##NAME##_); \
271 this->_##NAME.paint_type = vg::paint::type::GRADIENT_LINEAR; \
274 inline E& NAME(vg::paint::gradient::linear&& _##NAME##_) { \
275 this->_##NAME.paint_data = std::make_unique<vg::paint::gradient::linear>(_##NAME##_); \
276 this->_##NAME.paint_type = vg::paint::type::GRADIENT_LINEAR; \
279 inline E& NAME(vg::paint::gradient::radial& _##NAME##_) { \
280 this->_##NAME.paint_data = std::make_unique<vg::paint::gradient::radial>(_##NAME##_); \
281 this->_##NAME.paint_type = vg::paint::type::GRADIENT_RADIAL; \
284 inline E& NAME(vg::paint::gradient::radial&& _##NAME##_) { \
285 this->_##NAME.paint_data = std::make_unique<vg::paint::gradient::radial>(_##NAME##_); \
286 this->_##NAME.paint_type = vg::paint::type::GRADIENT_RADIAL; \
289 vg::paint::type _##NAME{vg::paint::type::SOLID, std::make_unique<vg::paint::solid>()}; \
292#define VG_ATTRIBUTE_DIMENSION(NAME, DEFAULT) \
293 template <typename E> \
294 struct attr_##NAME: public attribute_i { \
295 template <typename UNIT, typename T> \
296 inline E& NAME(const quantify::quantity_t<UNIT, T>& _##NAME##_) { \
297 this->_##NAME = _##NAME##_.value_as_base_unit(); \
300 template <typename UNIT, typename T> \
301 inline E& NAME(quantify::quantity_t<UNIT, T>&& _##NAME##_) { \
302 this->_##NAME = _##NAME##_.value_as_base_unit(); \
305 inline E& NAME(const int& _##NAME##_) { \
306 this->_##NAME = _##NAME##_; \
309 inline E& NAME(int&& _##NAME##_) { \
310 this->_##NAME = _##NAME##_; \
313 int _##NAME = DEFAULT; \
466 template <
typename T>
490 return this->
_stroke.paint_data->sample(x, y);
494 template <
typename T>
507 return this->
_fill.paint_data->sample(x, y);
511 template <
typename T>
525 template <
typename T>
#define VG_ATTRIBUTE_PAINT(NAME)
#define VG_ATTRIBUTE_DIMENSION(NAME, DEFAULT)
#define VG_ATTRIBUTE(TYPE, NAME, DEFAULT)
Cairo::Context::FillRule fill_rule_e
Cairo::ToyFontFace::Weight font_weight_e
Cairo::Context::LineCap stroke_linecap_e
std::vector< std::array< int, 2 > > point_list_t
Cairo::ToyFontFace::Slant font_style_e
UNUSED.
Cairo::Context::LineJoin stroke_linejoin_e
E & cx(const quantify::quantity_t< UNIT, T > &_cx_)
E & cy(const quantify::quantity_t< UNIT, T > &_cy_)
E & fill_opacity(double &_fill_opacity_)
E & fill_rule(fill_rule_e &_fill_rule_)
E & fill(vg::paint::type &_fill_)
E & font_family(std::string &_font_family_)
E & font_size(int &_font_size_)
E & font_stretch(double &_font_stretch_)
E & font_style(font_style_e &_font_style_)
E & font_weight(font_weight_e &_font_weight_)
font_weight_e _font_weight
E & h(const quantify::quantity_t< UNIT, T > &_h_)
hidden - replaces display="none" from SVG
E & hidden(bool &_hidden_)
E & opacity(float &_opacity_)
E & path_str(std::string &_path_str_)
E & pivot_x(const quantify::quantity_t< UNIT, T > &_pivot_x_)
E & pivot_y(const quantify::quantity_t< UNIT, T > &_pivot_y_)
E & points(point_list_t &_points_)
E & r(const quantify::quantity_t< UNIT, T > &_r_)
E & rotate(double &_rotate_)
E & rx(const quantify::quantity_t< UNIT, T > &_rx_)
E & ry(const quantify::quantity_t< UNIT, T > &_ry_)
E & scale_x(double &_scale_x_)
E & scale_y(double &_scale_y_)
std::valarray< double > _stroke_dasharray
E & stroke_dasharray(std::valarray< double > &_stroke_dasharray_)
double _stroke_dashoffset
E & stroke_dashoffset(double &_stroke_dashoffset_)
E & stroke_linecap(stroke_linecap_e &_stroke_linecap_)
stroke_linecap_e _stroke_linecap
E & stroke_linejoin(stroke_linejoin_e &_stroke_linejoin_)
stroke_linejoin_e _stroke_linejoin
E & stroke_miterlimit(int &_stroke_miterlimit_)
E & stroke_opacity(float &_stroke_opacity_)
E & stroke_width(const quantify::quantity_t< UNIT, T > &_stroke_width_)
E & stroke(vg::paint::type &_stroke_)
E & style_class(std::vector< std::string > &_style_class_)
E & text_anchor(text_anchor_e &_text_anchor_)
E & text_decoration(text_decoration_t &_text_decoration_)
E & w(const quantify::quantity_t< UNIT, T > &_w_)
E & x1(const quantify::quantity_t< UNIT, T > &_x1_)
E & x2(const quantify::quantity_t< UNIT, T > &_x2_)
E & x(const quantify::quantity_t< UNIT, T > &_x_)
E & y1(const quantify::quantity_t< UNIT, T > &_y1_)
E & y2(const quantify::quantity_t< UNIT, T > &_y2_)
E & y(const quantify::quantity_t< UNIT, T > &_y_)
void apply_fill(pixelmap_editor_t &editor) const
void set_source_to_fill(pixelmap_editor_t &editor) const
color::Color sample_fill(int x, int y) const
void apply_font(pixelmap_editor_t &editor) const
void set_source_to_stroke(pixelmap_editor_t &editor) const
void apply_stroke(pixelmap_editor_t &editor) const
color::Color sample_stroke(int x, int y) const
virtual void apply_to_source(pixelmap_editor_t &editor, double opacity) const =0
virtual color::Color sample(int x, int y) const =0
virtual bool operator==(const base_i &rhl) const =0
virtual paint_type_e get_type() const =0
virtual ~base_i()=default
virtual base_i * make_copy() const =0
std::vector< Cairo::ColorStop > color_stops
bool operator==(const paint::base_i &rhl_) const override
void apply_to_source(pixelmap_editor_t &editor, double opacity) const override
paint_type_e get_type() const override
base_i * make_copy() const override
color::Color sample(int x, int y) const override
linear(std::pair< int, int > start, std::pair< int, int > end, const std::vector< std::pair< double, color::Color > > &_color_stops)
paint_type_e get_type() const override
radial(std::pair< int, int > start, int r0, std::pair< int, int > end, int r1, const std::vector< std::pair< double, color::Color > > &_color_stops)
void apply_to_source(pixelmap_editor_t &editor, double opacity) const override
bool operator==(const paint::base_i &rhl_) const override
color::Color sample(int x, int y) const override
base_i * make_copy() const override
bool operator==(const base_i &rhl) const override
paint_type_e get_type() const override
color::Color sample(int x, int y) const override
void apply_to_source(pixelmap_editor_t &editor, double opacity) const override
base_i * make_copy() const override
bool operator==(const type &rhl) const
static type make(Paint paint_data_)
type(decltype(paint_type) type_, std::unique_ptr< base_i > &&paint_data_)
type & operator=(const type &rhl)
std::unique_ptr< base_i > paint_data