Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
object-renderer.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef SEEN_OBJECT_RENDERER_H
3#define SEEN_OBJECT_RENDERER_H
4
5#include <cairomm/context.h>
6#include <cairomm/refptr.h>
7#include <cairomm/surface.h>
8#include <cairomm/context.h>
9#include <gdkmm/rgba.h>
10#include <glibmm/ustring.h>
11#include <memory>
12#include <optional>
13#include "display/drawing.h"
14#include "object/sp-object.h"
15#include "document.h"
16
17namespace Inkscape {
18 namespace Colors {
19 class Color;
20 };
21
23public:
25
26 struct options {
28 // foreground color, where used
29 options& foreground(Gdk::RGBA fg) {
30 _foreground = fg;
31 return *this;
32 }
33 // background color, where used
34 options& solid_background(uint32_t bg, double margin, double corner_radius = 0) {
35 _add_background = true;
36 _background = bg;
38 _radius = corner_radius;
39 return *this;
40 }
41 // use checkerboard pattern for drawing background
42 options& checkerboard(uint32_t color) {
43 _checkerboard = color;
44 return *this;
45 }
46 // option to add an outline to rendered image
47 options& frame(uint32_t rgba, double thickness = 1) {
48 _stroke = thickness;
49 _draw_frame = true;
50 _frame_rgba = rgba;
51 return *this;
52 }
53 // option to reduce opacity of rendered image
54 options& image_opacity(double alpha) {
55 _image_opacity = alpha;
56 return *this;
57 }
58 // for symbols only: take style from <use> element
59 options& symbol_style_from_use(bool from_use_element = true) {
60 _symbol_style_from_use = from_use_element;
61 return *this;
62 }
63
64 private:
65 friend class object_renderer;
66 Gdk::RGBA _foreground;
67 bool _add_background = false;
68 uint32_t _background;
69 double _margin = 0;
70 double _radius = 0;
72 bool _draw_frame = false;
73 double _stroke = 0;
74 uint32_t _frame_rgba = 0;
75 double _image_opacity = 1;
76 std::optional<uint32_t> _checkerboard;
77 };
78
79 Cairo::RefPtr<Cairo::Surface> render(SPObject& object, double width, double height, double device_scale, options options = {});
80
81private:
82 std::unique_ptr<SPDocument> _symbol_document;
83 std::unique_ptr<SPDocument> _sandbox;
84};
85
86// Place 'image' on a solid background with given color optionally adding border.
87// If no image is provided, only background surface will be created.
88Cairo::RefPtr<Cairo::Surface> add_background_to_image(Cairo::RefPtr<Cairo::Surface> image, uint32_t rgb, double margin, double radius, int device_scale, std::optional<uint32_t> border = std::optional<uint32_t>());
89
96std::unique_ptr<SPDocument> ink_markers_preview_doc(const Glib::ustring& group_id);
97
103Cairo::RefPtr<Cairo::Surface> create_marker_image(
104 const Glib::ustring& group_id,
105 SPDocument* _sandbox,
106 Gdk::RGBA marker_color,
107 Geom::IntPoint pixel_size,
108 const char* mname,
109 SPDocument* source,
110 Inkscape::Drawing& drawing,
111 std::optional<guint32> checkerboard,
112 bool no_clip,
113 double scale,
114 int device_scale);
115
119void draw_gradient(const Cairo::RefPtr<Cairo::Context>& cr, SPGradient* gradient, int x, int width);
120
121
122} // namespace
123
124void set_source_inkscape_color(Cairo::RefPtr<Cairo::Context> context, Inkscape::Colors::Color const &color, double opacity);
125
126#endif // SEEN_OBJECT_RENDERER_H
uint32_t Color
int margin
Definition canvas.cpp:166
Two-dimensional point with integer coordinates.
Definition int-point.h:57
std::unique_ptr< SPDocument > _symbol_document
Cairo::RefPtr< Cairo::Surface > render(SPObject &object, double width, double height, double device_scale, options options={})
std::unique_ptr< SPDocument > _sandbox
Typed SVG document implementation.
Definition document.h:101
Gradient.
Definition sp-gradient.h:86
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
SVG drawing for display.
std::unique_ptr< Magick::Image > image
Helper class to stream background task notifications as a series of messages.
Cairo::RefPtr< Cairo::Surface > add_background_to_image(Cairo::RefPtr< Cairo::Surface > image, uint32_t rgb, double margin, double radius, int device_scale, std::optional< uint32_t > border=std::optional< uint32_t >())
std::unique_ptr< SPDocument > ink_markers_preview_doc(const Glib::ustring &group_id)
Returns a new document containing default start, mid, and end markers.
void draw_gradient(const Cairo::RefPtr< Cairo::Context > &cr, SPGradient *gradient, int x, int width)
Renders a preview of a gradient into the passed context.
Cairo::RefPtr< Cairo::Surface > create_marker_image(const Glib::ustring &group_id, SPDocument *_sandbox, Gdk::RGBA marker_color, Geom::IntPoint pixel_size, const char *mname, SPDocument *source, Inkscape::Drawing &drawing, std::optional< guint32 > checkerboard, bool no_clip, double scale, int device_scale)
Creates a copy of the marker named mname, determines its visible and renderable area in the bounding ...
void set_source_inkscape_color(Cairo::RefPtr< Cairo::Context > context, Inkscape::Colors::Color const &color, double opacity)
RGB rgb
Definition quantize.cpp:36
options & checkerboard(uint32_t color)
std::optional< uint32_t > _checkerboard
options & frame(uint32_t rgba, double thickness=1)
options & foreground(Gdk::RGBA fg)
options & symbol_style_from_use(bool from_use_element=true)
options & image_opacity(double alpha)
options & solid_background(uint32_t bg, double margin, double corner_radius=0)
double border
double height
double width