1.10
svgimage.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_SVGIMAGE_H
7#define EGT_SVGIMAGE_H
8
14#include <egt/detail/meta.h>
15#include <egt/geometry.h>
16#include <egt/image.h>
17#include <egt/types.h>
18#include <memory>
19#include <string>
20
21namespace egt
22{
23inline namespace v1
24{
25
56class EGT_API SvgImage
57{
58public:
59
61
68 explicit SvgImage(const std::string& uri, const SizeF& size = {});
69
70 SvgImage(const SvgImage&) = delete;
71 SvgImage& operator=(const SvgImage&) = delete;
72 SvgImage(SvgImage&&) noexcept;
73 SvgImage& operator=(SvgImage&&) noexcept;
74
75 ~SvgImage() noexcept;
76
82 // NOLINTNEXTLINE(hicpp-explicit-conversions)
83 operator Image() const;
84
100 EGT_NODISCARD Image render(const std::string& id = {}, const RectF& rect = {}) const;
101
115 EGT_NODISCARD Image id_image(const std::string& id) const
116 {
117 return this->render(id, id_box(id));
118 }
119
129 EGT_NODISCARD RectF id_box(const std::string& id) const;
130
141 EGT_NODISCARD bool id_exists(const std::string& id) const;
142
146 EGT_NODISCARD SizeF size() const;
147
158 void size(const SizeF& size)
159 {
160 m_size = size;
161 }
162
169 void uri(const std::string& uri);
170
171protected:
172
174 void load();
175
179 EGT_NODISCARD shared_cairo_surface_t do_render(const std::string& id = {}, const RectF& rect = {}) const;
180
181 struct SvgImpl;
182
184 std::unique_ptr<SvgImpl> m_impl;
185
191
193 std::string m_uri;
194};
195
196}
197}
198
199#endif
Raster image resource used for drawing or displaying.
Definition image.h:39
A rectangle with a point and a size.
Definition geometry.h:595
An SVG image.
Definition svgimage.h:57
SizeF m_size
User set size.
Definition svgimage.h:190
SvgImage(const SvgImage &)=delete
EGT_NODISCARD shared_cairo_surface_t do_render(const std::string &id={}, const RectF &rect={}) const
Render and return a new surface.
std::unique_ptr< SvgImpl > m_impl
Implementation pointer.
Definition svgimage.h:184
void load()
Load the SVG file.
std::string m_uri
User set URI.
Definition svgimage.h:193
void uri(const std::string &uri)
Set the URI.
SvgImage(const std::string &uri, const SizeF &size={})
void size(const SizeF &size)
Set the size you want any rendered Image to be.
Definition svgimage.h:158
EGT_NODISCARD RectF id_box(const std::string &id) const
Get the position and size of an element in the SVG.
EGT_NODISCARD bool id_exists(const std::string &id) const
Test if an element exists in the SVG image.
EGT_NODISCARD Image id_image(const std::string &id) const
Render the image of the specific element in the SVG file.
Definition svgimage.h:115
SvgImage(SvgImage &&) noexcept
EGT_NODISCARD SizeF size() const
Get the SVG size.
SvgImage & operator=(const SvgImage &)=delete
std::shared_ptr< cairo_surface_t > shared_cairo_surface_t
Shared pointer for a cairo surface.
Definition types.h:29
EGT framework namespace.
Definition animation.h:24