MUSX Document Model
Loading...
Searching...
No Matches
musx::util::SvgConvert Class Reference

Converts a Shape Designer definition into an SVG buffer. More...

#include <SvgConvert.h>

Classes

struct  ExternalGraphicInfo
 Metadata describing an external graphic instruction. More...
 
struct  ExternalGraphicPayload
 Payload data for external graphics. More...
 
struct  GlyphMetrics
 Metrics for sizing SVG text bounds. More...
 

Public Types

using GlyphMetricsFn = std::function< std::optional< GlyphMetrics >(const dom::FontInfo &, std::u32string_view)>
 Optional callback that returns glyph metrics in EVPU units.
 
using ExternalGraphicFn = std::function< std::optional< ExternalGraphicPayload >(const ExternalGraphicInfo &)>
 Optional callback that resolves external graphics to a MIME type and byte buffer.
 

Static Public Member Functions

static std::string toSvg (const dom::others::ShapeDef &shape, GlyphMetricsFn glyphMetrics=nullptr, ExternalGraphicFn externalGraphicResolver=nullptr)
 Convert a ShapeDef into an SVG string buffer.
 

Detailed Description

Converts a Shape Designer definition into an SVG buffer.

Member Typedef Documentation

◆ GlyphMetricsFn

using musx::util::SvgConvert::GlyphMetricsFn = std::function<std::optional<GlyphMetrics>(const dom::FontInfo&, std::u32string_view)>

Optional callback that returns glyph metrics in EVPU units.

Note
The callback receives the resolved font and the glyph(s) to measure.
Return std::nullopt to fall back to heuristic metrics.

Member Function Documentation

◆ toSvg()

std::string musx::util::SvgConvert::toSvg ( const dom::others::ShapeDef &  shape,
GlyphMetricsFn  glyphMetrics = nullptr,
ExternalGraphicFn  externalGraphicResolver = nullptr 
)
static

Convert a ShapeDef into an SVG string buffer.

Parameters
shapeThe shape definition to convert.
glyphMetricsOptional callback that returns glyph metrics in EVPU units.
externalGraphicResolverOptional callback that resolves external graphics to bytes and MIME types.
Returns
An SVG buffer encoded as a string.
Note
The glyph callback receives the resolved font and the glyph(s) to measure.
If an external graphic is encountered and cannot be resolved, this returns an empty string.
Todo:
External graphic handling has not been tested yet.