diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:50:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:50:49 +0000 |
commit | c853ffb5b2f75f5a889ed2e3ef89b818a736e87a (patch) | |
tree | 7d13a0883bb7936b84d6ecdd7bc332b41ed04bee /src/util/object-renderer.h | |
parent | Initial commit. (diff) | |
download | inkscape-c853ffb5b2f75f5a889ed2e3ef89b818a736e87a.tar.xz inkscape-c853ffb5b2f75f5a889ed2e3ef89b818a736e87a.zip |
Adding upstream version 1.3+ds.upstream/1.3+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/util/object-renderer.h')
-rw-r--r-- | src/util/object-renderer.h | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/util/object-renderer.h b/src/util/object-renderer.h new file mode 100644 index 0000000..98f8890 --- /dev/null +++ b/src/util/object-renderer.h @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef SEEN_OBJECT_RENDERER_H +#define SEEN_OBJECT_RENDERER_H + +#include <cairomm/refptr.h> +#include <cairomm/surface.h> +#include <gdkmm/rgba.h> +#include <glibmm/ustring.h> +#include <memory> +#include <optional> +#include "display/drawing.h" +#include "object/sp-object.h" +#include "document.h" + +namespace Inkscape { + +class object_renderer { +public: + object_renderer(); + + struct options { + options() {} + // foreground color, where used + options& foreground(Gdk::RGBA fg) { + _foreground = fg; + return *this; + } + // background color, where used + options& solid_background(uint32_t bg, double margin, double corner_radius = 0) { + _add_background = true; + _background = bg; + _margin = margin; + _radius = corner_radius; + return *this; + } + // use checkerboard pattern for drawing background + options& checkerboard(uint32_t color) { + _checkerboard = color; + return *this; + } + // option to add an outline to rendered image + options& frame(uint32_t rgba, double thickness = 1) { + _stroke = thickness; + _draw_frame = true; + _frame_rgba = rgba; + return *this; + } + // option to reduce opacity of rendered image + options& image_opacity(double alpha) { + _image_opacity = alpha; + return *this; + } + // for symbols only: take style from <use> element + options& symbol_style_from_use(bool from_use_element = true) { + _symbol_style_from_use = from_use_element; + return *this; + } + + private: + friend class object_renderer; + Gdk::RGBA _foreground; + bool _add_background = false; + uint32_t _background; + double _margin = 0; + double _radius = 0; + bool _symbol_style_from_use = false; + bool _draw_frame = false; + double _stroke = 0; + uint32_t _frame_rgba = 0; + double _image_opacity = 1; + std::optional<uint32_t> _checkerboard; + }; + + Cairo::RefPtr<Cairo::Surface> render(SPObject& object, double width, double height, double device_scale, options options = {}); + +private: + std::unique_ptr<SPDocument> _symbol_document; + std::unique_ptr<SPDocument> _sandbox; +}; + +// Place 'image' on a solid background with given color optinally adding border. +// If no image is provided, only background surface will be created. +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>()); + +/** + * Returns a new document containing default start, mid, and end markers. + * Note 1: group IDs are matched against "group_id" to render correct preview object. + * Note 2: paths/lines are kept outside of groups, so they don't inflate visible bounds + * Note 3: invisible rects inside groups keep visual bounds from getting too small, so we can see relative marker sizes + */ +std::unique_ptr<SPDocument> ink_markers_preview_doc(const Glib::ustring& group_id); + +/** + * Creates a copy of the marker named mname, determines its visible and renderable + * area in the bounding box, and then renders it. This allows us to fill in + * preview images of each marker in the marker combobox. + */ +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); + +} // namespace + +#endif // SEEN_OBJECT_RENDERER_H |