38#define NOVA_VERSION_MAJOR 0
39#define NOVA_VERSION_MINOR 11
40#define NOVA_VERSION_PATCH 5
42#define NOVA_VERSION_ENCODE(major, minor, patch) (((major) * 10000) + ((minor) * 100) + ((patch) * 1))
43#define NOVA_VERSION NOVA_VERSION_ENCODE(NOVA_VERSION_MAJOR, NOVA_VERSION_MINOR, NOVA_VERSION_PATCH)
45#define NOVA_VERSION_XSTRINGIZE(major, minor, patch) #major"."#minor"."#patch
46#define NOVA_VERSION_STRINGIZE(major, minor, patch) NOVA_VERSION_XSTRINGIZE(major, minor, patch)
47#define NOVA_VERSION_STRING NOVA_VERSION_STRINGIZE(NOVA_VERSION_MAJOR, NOVA_VERSION_MINOR, NOVA_VERSION_PATCH)
49#include <stb/color.hpp>
50#include <stb/image.hpp>
51#include <stb/outline.hpp>
178 const std::string&
data()
const;
188 svg_text_node* text()
const;
211 const std::string&
attribute(
const std::string& name)
const;
230 void render(stb::image& image,
const stb::matrix& matrix = stb::matrix())
const;
239 stb::image
render_to_image(
int width = -1,
int height = -1,
const stb::color& background_color = stb::color(0, 0, 0, 0))
const;
245 void render(pixmap& bitmap,
const stb::matrix& matrix = stb::matrix())
const;
250 pixmap
render_to_pixmap(
int width = -1,
int height = -1,
const stb::color& background_color = stb::color(0, 0, 0, 0))
const;
290 svg_element* el(
bool layout_if_needed =
false)
const;
297class svg_root_element;
306 static std::unique_ptr<document>
load_file(
const std::string& filename);
313 static std::unique_ptr<document>
load_data(
const std::string&
string);
320 static std::unique_ptr<document>
load_data(
const char* data);
328 static std::unique_ptr<document>
load_data(
const char* data,
size_t length_);
388 void render(stb::image& image,
const stb::matrix& matrix = stb::matrix())
const;
403 void render(pixmap& bitmap,
const stb::matrix& matrix = stb::matrix())
const;
432 enum class pdf_text { outlines, embed, embed_ignore_license };
488 svg_root_element* root_element(
bool layout_if_needed =
false)
const;
489 bool parse(
const char* data,
size_t length_);
490 std::unique_ptr<svg_root_element> m_root_element;
531 bool bold =
false,
bool italic =
false);
540 int weight,
bool italic =
false);
void apply_style_sheet(const std::string &content)
Applies a CSS stylesheet to the dom.
box bounding_box() const
Returns the smallest rectangle that encloses the dom content.
void render(stb::image &image, const stb::matrix &matrix=stb::matrix()) const
Renders the dom onto an existing image, using a transformation matrix.
bool save_pdf(const std::string &filename, pdf_mode mode=pdf_mode::vector, float dpi=192.f, pdf_text text=pdf_text::outlines) const
render_to_pdf() written to a file.
void set_foreign_object_renderer(std::shared_ptr< foreign_object_renderer > renderer)
Sets the renderer that draws this document's <foreignObject> elements (see foreign_object....
void render(pixmap &bitmap, const stb::matrix &matrix=stb::matrix()) const
document & operator=(document &&)
std::shared_ptr< foreign_object_renderer > foreign_object_renderer_ptr() const
The renderer in use (null: foreignObject elements are skipped).
pixmap render_to_pixmap(int width=-1, int height=-1, const stb::color &background_color=stb::color(0, 0, 0, 0)) const
element element_by_id(const std::string &id) const
Retrieves an el by its ID.
static std::unique_ptr< document > load_data(const std::string &string)
Load an svg dom from a string.
static std::unique_ptr< document > load_data(const char *data, size_t length_)
Load an svg dom from a string with a specified length.
static std::unique_ptr< document > load_data(const char *data)
Load an svg dom from a null-terminated string.
element element_from_point(float x, float y) const
Returns the topmost el under the specified point.
std::vector< uint8_t > render_to_pdf(pdf_mode mode=pdf_mode::vector, float dpi=192.f, pdf_text text=pdf_text::outlines) const
Renders the document as a one-page PDF (page size = the document's size, 1 px = 0....
float height() const
Returns the intrinsic height of the dom in pixels.
pdf_text
How render_to_pdf() writes text in the vector mode (the raster mode has no text).
const std::string & title() const
Returns the text of the root <svg>'s first <title> child (entities decoded, white space trimmed),...
stb::image render_to_image(int width=-1, int height=-1, const stb::color &background_color=stb::color(0, 0, 0, 0)) const
Renders the dom to a new straight-alpha RGBA image with specified dimensions.
void update_layout()
Updates the layout of the dom if needed.
element_list query_selector_all(const std::string &content) const
Selects all elements that match the given CSS selector(s).
float width() const
Returns the intrinsic width of the dom in pixels.
friend class svg_uri_reference
pdf_mode
How render_to_pdf() writes the page.
static std::unique_ptr< document > load_file(const std::string &filename)
Load an svg dom from a file.
void force_layout()
Forces an immediate layout update.
element document_element() const
Retrieves the dom el.
pixmap render_to_pixmap(int width=-1, int height=-1, const stb::color &background_color=stb::color(0, 0, 0, 0)) const
void set_attribute(const std::string &name, const std::string &value)
Sets the value of an attribute.
stb::matrix global_matrix() const
Retrieves the global transformation matrix of the el.
stb::matrix local_matrix() const
Retrieves the local transformation matrix of the el.
box bounding_box() const
Retrieves the bounding box of the el without any transformations.
const std::string & attribute(const std::string &name) const
Retrieves the value of an attribute.
element()=default
Constructs a null el.
node_list children() const
Returns the child nodes of this nd.
void render(stb::image &image, const stb::matrix &matrix=stb::matrix()) const
Renders the el onto an existing image, using a transformation matrix.
void render(pixmap &bitmap, const stb::matrix &matrix=stb::matrix()) const
box local_bounding_box() const
Retrieves the local bounding box of the el.
stb::image render_to_image(int width=-1, int height=-1, const stb::color &background_color=stb::color(0, 0, 0, 0)) const
Renders the el to a new straight-alpha RGBA image with specified dimensions.
bool has_attribute(const std::string &name) const
Checks if the el has a specific attribute.
box global_bounding_box() const
Retrieves the global bounding box of the el.
text_node to_text_node() const
Converts the nd to a text_node.
node()=default
Constructs a null nd.
element parent_element() const
Returns the parent el.
bool is_null() const
Checks if the nd is null.
bool operator==(const node &nd) const
Checks if two nodes are equal.
bool is_text_node() const
Checks if the nd is a text nd.
element to_element() const
Converts the nd to an element.
bool operator!=(const node &nd) const
Checks if two nodes are not equal.
bool is_element() const
Checks if the nd is an el nd.
text_node()=default
Constructs a null text nd.
const std::string & data() const
Returns the text content of the nd.
void set_data(const std::string &data)
Sets the text content of the nd.
Represents a 2D axis-aligned bounding box.
bool is_valid_selector(const std::string &selector)
Measures utf8_text with the same font lookup, shaping and kerning that <text> uses.
std::shared_ptr< foreign_object_renderer > default_foreign_object_renderer()
int version()
Returns the version of the novasvg library encoded in a single integer.
std::vector< node > node_list
std::string version_string()
Returns the novasvg library version as a human-readable string in "X.Y.Z" format.
std::vector< element > element_list
text_metrics measure_text(const std::string &utf8_text, const std::string &font_family, float font_size, bool bold=false, bool italic=false)
How big a piece of text is, measured the way a <text> element is laid out.
float ascent
Distance from the baseline up to the top of the font's line box; never negative.
float descent
Distance from the baseline down to the bottom of the line box; never negative.
float line_gap
Extra leading the font asks for between two lines.
float width
Advance of the whole text (kerning and ligatures included).