NovaSVG 0.10.0
A header-only SVG library
Loading...
Searching...
No Matches
novasvg::Document Class Reference

#include <novasvg.h>

Public Member Functions

void applyStyleSheet (const std::string &content)
 Applies a CSS stylesheet to the document.
 
ElementList querySelectorAll (const std::string &content) const
 Selects all elements that match the given CSS selector(s).
 
float width () const
 Returns the intrinsic width of the document in pixels.
 
float height () const
 Returns the intrinsic height of the document in pixels.
 
Box boundingBox () const
 Returns the smallest rectangle that encloses the document content.
 
void updateLayout ()
 Updates the layout of the document if needed.
 
void forceLayout ()
 Forces an immediate layout update.
 
void render (Bitmap &bitmap, const Matrix &matrix=Matrix()) const
 Renders the document onto a bitmap using a transformation matrix.
 
Bitmap renderToBitmap (int width=-1, int height=-1, const Color &backgroundColor=Color(0, 0, 0, 0)) const
 Renders the document to a bitmap with specified dimensions.
 
Element elementFromPoint (float x, float y) const
 Returns the topmost element under the specified point.
 
Element getElementById (const std::string &id) const
 Retrieves an element by its ID.
 
Element documentElement () const
 Retrieves the document element.
 
 Document (Document &&)
 
Document & operator= (Document &&)
 
 ~Document ()
 

Static Public Member Functions

static std::unique_ptr< Document > loadFromFile (const std::string &filename)
 Load an SVG document from a file.
 
static std::unique_ptr< Document > loadFromData (const std::string &string)
 Load an SVG document from a string.
 
static std::unique_ptr< Document > loadFromData (const char *data)
 Load an SVG document from a null-terminated string.
 
static std::unique_ptr< Document > loadFromData (const char *data, size_t length)
 Load an SVG document from a string with a specified length.
 

Friends

class SVGURIReference
 
class SVGNode
 

Detailed Description

Definition at line 551 of file novasvg.h.

Constructor & Destructor Documentation

◆ Document()

novasvg::Document::Document ( Document &&  )
inlinedefault

◆ ~Document()

novasvg::Document::~Document ( )
inlinedefault

Member Function Documentation

◆ applyStyleSheet()

NOVASVG_INLINE void novasvg::Document::applyStyleSheet ( const std::string &  content)

Applies a CSS stylesheet to the document.

Parameters
contentA string containing the CSS rules to apply, with comments removed.

Definition at line 1613 of file svgparser.hpp.

References novasvg::RuleIndex::candidates(), novasvg::ForeignObject, novasvg::SVGElement::id(), novasvg::SVGElement::setAttribute(), novasvg::Unknown, and width().

◆ boundingBox()

Box novasvg::Document::boundingBox ( ) const
inline

Returns the smallest rectangle that encloses the document content.

Returns
A Box representing the bounding box of the document.

Definition at line 1051 of file novasvg.h.

References novasvg::SVGSVGElement::localTransform(), and novasvg::Transform::mapRect().

◆ documentElement()

Element novasvg::Document::documentElement ( ) const
inline

Retrieves the document element.

Returns
The root Element of the document.

Definition at line 1147 of file novasvg.h.

◆ elementFromPoint()

Element novasvg::Document::elementFromPoint ( float  x,
float  y 
) const
inline

Returns the topmost element under the specified point.

Parameters
xThe x-coordinate in viewport space.
yThe y-coordinate in viewport space.
Returns
The topmost Element at the given point, or a null Element if no match is found.

Definition at line 1137 of file novasvg.h.

References novasvg::SVGElement::elementFromPoint().

◆ forceLayout()

void novasvg::Document::forceLayout ( )
inline

Forces an immediate layout update.

Definition at line 1061 of file novasvg.h.

◆ getElementById()

Element novasvg::Document::getElementById ( const std::string &  id) const
inline

Retrieves an element by its ID.

Parameters
idThe ID of the element to retrieve.
Returns
The Element with the specified ID, or a null Element if not found.

Definition at line 1142 of file novasvg.h.

◆ height()

float novasvg::Document::height ( ) const
inline

Returns the intrinsic height of the document in pixels.

Returns
The height of the document.

Definition at line 1046 of file novasvg.h.

References novasvg::SVGRootElement::intrinsicHeight().

Referenced by renderToBitmap().

◆ loadFromData() [1/3]

std::unique_ptr< Document > novasvg::Document::loadFromData ( const char *  data)
inlinestatic

Load an SVG document from a null-terminated string.

Parameters
dataThe string containing the SVG data.
Returns
A pointer to the loaded Document, or nullptr on failure.

Definition at line 1028 of file novasvg.h.

References loadFromData().

◆ loadFromData() [2/3]

std::unique_ptr< Document > novasvg::Document::loadFromData ( const char *  data,
size_t  length 
)
inlinestatic

Load an SVG document from a string with a specified length.

Parameters
dataThe string containing the SVG data.
lengthThe length of the string in bytes.
Returns
A pointer to the loaded Document, or nullptr on failure.

Definition at line 1033 of file novasvg.h.

◆ loadFromData() [3/3]

std::unique_ptr< Document > novasvg::Document::loadFromData ( const std::string &  string)
inlinestatic

Load an SVG document from a string.

Parameters
stringThe SVG data as a string.
Returns
A pointer to the loaded Document, or nullptr on failure.

Definition at line 1023 of file novasvg.h.

References loadFromData().

Referenced by loadFromData(), loadFromData(), and loadFromFile().

◆ loadFromFile()

std::unique_ptr< Document > novasvg::Document::loadFromFile ( const std::string &  filename)
inlinestatic

Load an SVG document from a file.

Parameters
filenameThe path to the SVG file.
Returns
A pointer to the loaded Document, or nullptr on failure.

Definition at line 1011 of file novasvg.h.

References loadFromData(), and width().

◆ operator=()

Document & novasvg::Document::operator= ( Document &&  )
inlinedefault

◆ querySelectorAll()

NOVASVG_INLINE ElementList novasvg::Document::querySelectorAll ( const std::string &  content) const

Selects all elements that match the given CSS selector(s).

Parameters
contentA string containing the CSS selector(s) to match elements.
Returns
A list of elements matching the selector(s).

Definition at line 1659 of file svgparser.hpp.

References width().

◆ render()

void novasvg::Document::render ( Bitmap &  bitmap,
const Matrix &  matrix = Matrix() 
) const
inline

Renders the document onto a bitmap using a transformation matrix.

Parameters
bitmapThe bitmap to render onto.
Theroot transformation matrix.

Definition at line 1066 of file novasvg.h.

References novasvg::Background_Color, novasvg::render::color_parse(), novasvg::render::color_to_argb32(), novasvg::Painting, novasvg::SVGSVGElement::render(), and width().

Referenced by renderToBitmap().

◆ renderToBitmap()

Bitmap novasvg::Document::renderToBitmap ( int  width = -1,
int  height = -1,
const Color &  backgroundColor = Color(0, 0, 0, 0) 
) const
inline

Renders the document to a bitmap with specified dimensions.

Parameters
widthThe desired width in pixels, or -1 to auto-scale based on the intrinsic size.
heightThe desired height in pixels, or -1 to auto-scale based on the intrinsic size.
backgroundColorThe background color to render onto.
Returns
A Bitmap containing the raster representation of the document.

Definition at line 1112 of file novasvg.h.

References height(), novasvg::SVGRootElement::intrinsicHeight(), novasvg::SVGRootElement::intrinsicWidth(), render(), and width().

◆ updateLayout()

void novasvg::Document::updateLayout ( )
inline

Updates the layout of the document if needed.

Definition at line 1056 of file novasvg.h.

◆ width()

float novasvg::Document::width ( ) const
inline

Returns the intrinsic width of the document in pixels.

Returns
The width of the document.

Definition at line 1041 of file novasvg.h.

References novasvg::SVGRootElement::intrinsicWidth().

Referenced by applyStyleSheet(), loadFromFile(), querySelectorAll(), render(), and renderToBitmap().

Friends And Related Symbol Documentation

◆ SVGNode

Definition at line 672 of file novasvg.h.

◆ SVGURIReference

Definition at line 671 of file novasvg.h.


The documentation for this class was generated from the following files: