1.10 |
An SVG image. More...
#include <svgimage.h>
Public Member Functions | |
SvgImage () | |
SvgImage (const std::string &uri, const SizeF &size={}) | |
SvgImage (const SvgImage &)=delete | |
SvgImage (SvgImage &&) noexcept | |
~SvgImage () noexcept | |
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. | |
operator Image () const | |
Overload to convert to an Image. | |
SvgImage & | operator= (const SvgImage &)=delete |
SvgImage & | operator= (SvgImage &&) noexcept |
EGT_NODISCARD Image | render (const std::string &id={}, const RectF &rect={}) const |
Render the SVG optionally with only the specified element id in the SVG file. | |
EGT_NODISCARD SizeF | size () const |
Get the SVG size. | |
void | size (const SizeF &size) |
Set the size you want any rendered Image to be. | |
void | uri (const std::string &uri) |
Set the URI. | |
Protected Member Functions | |
EGT_NODISCARD shared_cairo_surface_t | do_render (const std::string &id={}, const RectF &rect={}) const |
Render and return a new surface. | |
void | load () |
Load the SVG file. | |
Protected Attributes | |
std::unique_ptr< SvgImpl > | m_impl |
Implementation pointer. | |
SizeF | m_size |
User set size. | |
std::string | m_uri |
User set URI. | |
An SVG image.
This class is not just for working with a single Image. It allows loading an SVG file or data once, and then rendering any number of images at different sizes or made up of different elements from the SVG file.
For using individual elements from a SVG file and render them separately the document must be created with element IDs. In the dashboard example for instance, one of the dash_background.svg
element has the attribute:
Several methods in the SvgImage class allow the use of such elements when the id
parameter is present. Element IDs must follow the syntax of an URL fragment identifier. For example, use "#right_blink" (hash right_blink) to obtain a handle on the SVG element mentioned just above; which gives:
SvgImage | ( | ) |
uri | Resource path. |
[in] | size | Size of the image. |
|
noexcept |
|
protected |
Render and return a new surface.
EGT_NODISCARD RectF id_box | ( | const std::string & | id | ) | const |
Get the position and size of an element in the SVG.
[in] | id | The id of the SVG element. Element IDs must follow the syntax of an URL fragment identifier. For example, use "#right_blink" (hash right_blink) to obtain a handle on the SVG element with id="right_blink". |
EGT_NODISCARD bool id_exists | ( | const std::string & | id | ) | const |
Test if an element exists in the SVG image.
[in] | id | The id of the SVG element. Element IDs must follow the syntax of an URL fragment identifier. For example, use "#right_blink" (hash right_blink) to obtain a handle on the SVG element with id="right_blink". |
|
inline |
Render the image of the specific element in the SVG file.
This is the same as calling:
|
protected |
Load the SVG file.
Render the SVG optionally with only the specified element id in the SVG file.
[in] | id | Optional id of the SVG element to render. If no id is specified, all elements in the SVG will be rendered. Element IDs must follow the syntax of an URL fragment identifier. For example, use "#right_blink" (hash right_blink) to obtain a handle on the SVG element with id="right_blink". |
[in] | rect | Optional rect to clip to. |
EGT_NODISCARD SizeF size | ( | ) | const |
Get the SVG size.
|
inline |
Set the size you want any rendered Image to be.
This is somewhat special. If you specify zero for one of the dimensions, the other dimension will be automatically computed keeping the same aspect ratio.
If both dimensions are zero, the default size will be loaded from the SVG file.
void uri | ( | const std::string & | uri | ) |
Set the URI.
If this results in changing the URI for this instance, this will cause a re-load of the SVG file
|
protected |
Implementation pointer.
|
protected |
User set URI.