Skip to main content

PlottingSVG::SVGGlyphRenderer

PlottingSVG::SVGGlyphRenderer

Stateless conversion from [CorePlotting::RenderableGlyphBatch]() to SVG element strings. More…

#include <SVGGlyphRenderer.hpp>

Public Functions

Name
std::vector< std::string > render(CorePlotting::RenderableGlyphBatch const & batch, glm::mat4 const & view, glm::mat4 const & projection, int canvas_width, int canvas_height)
Convert one glyph batch to SVG fragments in canvas pixel space.

Detailed Description

class PlottingSVG::SVGGlyphRenderer;

Stateless conversion from [CorePlotting::RenderableGlyphBatch]() to SVG element strings.

Applies projection * view * batch.model_matrix per batch, maps vertices with [PlottingSVG::transformVertexToSVG](/api_generated/Namespaces/namespacePlottingSVG.md#function-transformvertextosvg), and emits one or two fragments per glyph depending on GlyphType (cross uses two <line> elements).

Public Functions Documentation

function render

static std::vector< std::string > render(
    CorePlotting::RenderableGlyphBatch const & batch,
    glm::mat4 const & view,
    glm::mat4 const & projection,
    int canvas_width,
    int canvas_height
)

Convert one glyph batch to SVG fragments in canvas pixel space.

Parameters:

  • batch Glyph instances: positions in world space; optional parallel colors (per-glyph RGBA when colors.size() > i, otherwise white). batch.size has different coordinate-space semantics per glyph type:

  • Tick / Square / Cross: world-space units. Corners/endpoints are computed at pos ± size/2 (in X and/or Y), then transformed through the MVP to canvas pixels.

  • Circle: screen pixels. The radius size / 2 is emitted directly in the <circle r="..."> attribute (no MVP transform on size).

    • view Shared view matrix (same convention as OpenGL rendering).
    • projection Shared projection matrix.
    • canvas_width Target SVG width in pixels.
    • canvas_height Target SVG height in pixels.

Precondition:

  • batch.glyph_type must be Tick, Circle, Square, or Cross. Other values are not handled by the switch and produce an empty fragment for that glyph (enforcement: none) [IMPORTANT]
  • canvas_width > 0 and canvas_height > 0 if output should match the same NDC→pixel mapping as live OpenGL rendering (enforcement: none) [IMPORTANT]
  • batch.positions[i] and the MVP should yield finite NDC after transform for on-canvas coordinates (enforcement: none) [LOW]
  • If batch.colors is non-empty, only indices i < batch.colors.size() read per-glyph color; shorter colors is allowed (remaining glyphs use opaque white) (enforcement: none) [LOW]

Postcondition:

  • Returns an empty vector when batch.positions is empty.
  • Otherwise returns one <line>, <circle>, or <rect> string per glyph for Tick, Circle, and Square, and two<line> strings per glyph for Cross (so the vector length can exceed batch.positions.size()).
  • Output strings use [colorToSVGHex](/api_generated/Namespaces/namespacePlottingSVG.md#function-colortosvghex) for stroke/fill color and separate opacity attributes where applicable.
  • Does not throw under normal std::string/ostringstream behavior.

Updated on 2026-11-13 at 20:25:41 +0000