PlottingSVG::SVGDocument
PlottingSVG::SVGDocument
Builds a UTF-8 SVG 1.1 document string with a full-canvas background and ordered <g> layers. More…
#include <SVGDocument.hpp>
Public Functions
| Name | |
|---|---|
| SVGDocument(int width, int height) Create a document with pixel width and height used for the root <svg> and viewBox. |
|
| void | setBackground(std::string const & hex_color) Set the full-canvas background rectangle fill (SVG paint syntax, typically #RRGGBB). |
| void | setDescription(std::string const & desc) Set prose inside <desc>…</desc>; the tag is omitted only when the stored string is empty. |
| void | addElements(std::string const & layer_name, std::vector< std::string > const & elements) Append SVG fragments into a named layer ( <g id="layer_name">). |
| std::string | build() const Serialize the accumulated document. |
Detailed Description
class PlottingSVG::SVGDocument;Builds a UTF-8 SVG 1.1 document string with a full-canvas background and ordered <g> layers.
Precondition: ).
Layer content is concatenated verbatim; [build()](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md#function-build) does not escape or validate SVG/XML. Callers must supply safe strings (see [setBackground](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md#function-setbackground), [setDescription](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md#function-setdescription), [addElements](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md#function-addelements), and [build](/api_generated/Classes/classPlottingSVG_1_1SVGDocument.md#function-build)
Public Functions Documentation
function SVGDocument
explicit SVGDocument(
int width,
int height
)Create a document with pixel width and height used for the root <svg> and viewBox.
Precondition: width > 0 and height > 0 for a conventional pixel canvas and viewBox="0 0 …" (enforcement: none) [IMPORTANT]
function setBackground
void setBackground(
std::string const & hex_color
)Set the full-canvas background rectangle fill (SVG paint syntax, typically #RRGGBB).
Precondition: hex_color must not contain ", &, or < (and otherwise be valid inside a double-quoted XML attribute). Values are inserted unescaped (enforcement: none) [IMPORTANT]
function setDescription
void setDescription(
std::string const & desc
)Set prose inside <desc>…</desc>; the tag is omitted only when the stored string is empty.
Precondition: desc must not break XML structure (e.g. must not contain a raw </desc> sequence or unescaped & / < unless intentional). Content is inserted unescaped (enforcement: none) [IMPORTANT]
function addElements
void addElements(
std::string const & layer_name,
std::vector< std::string > const & elements
)Append SVG fragments into a named layer (<g id="layer_name">).
Precondition:
layer_namemust be safe inside a double-quotedid="…"attribute (no",&,<, etc.). Should be a valididtoken for consumers that enforce XML/SVG id rules (enforcement: none) [IMPORTANT]- Each string in
elementsshould be a single SVG element (or fragment) that is valid in this context; content is written verbatim with indentation only (enforcement: none) [LOW]
If layer_name already exists, elements are appended to that layer’s vector in order.
function build
std::string build() constSerialize the accumulated document.
Postcondition:
- Returns a string starting with
<?xml version="1.0" encoding="UTF-8"?>, then a root<svg>withxmlns,width,height, andviewBox="0 0 width height"from the constructor. - When the stored description is non-empty, includes one
<desc>child with that text (unescaped). - Always includes a full-viewport
<rect width="100%" height="100%" fill="…"/>using the current background string. - Emits one
<g id="…">per distinctlayer_namein insertion order, each containing all accumulated elements for that layer, then closes</svg>. - Does not throw under normal
std::ostringstreambehavior.
Updated on 2026-11-13 at 20:25:41 +0000