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  GlyphMetrics
 Metrics for sizing SVG text bounds. More...
 

Public Types

enum class  SvgUnit {
  None , Pixels , Points , Picas ,
  Centimeters , Millimeters , Inches
}
 SVG unit suffixes supported by the converter. More...
 
using GlyphMetricsFn = std::function< std::optional< GlyphMetrics >(const dom::FontInfo &, std::u32string_view)>
 Optional callback that returns glyph metrics in EVPU units.
 

Static Public Member Functions

static std::string toSvg (const dom::others::ShapeDef &shape)
 Convert a ShapeDef into an SVG string buffer.
 
static std::string toSvg (const dom::others::ShapeDef &shape, GlyphMetricsFn glyphMetrics)
 Convert a ShapeDef into an SVG string buffer.
 
static std::string toSvg (const dom::others::ShapeDef &shape, double scaling, SvgUnit unit)
 Convert a ShapeDef into an SVG string buffer with explicit scaling and units.
 
static std::string toSvg (const dom::others::ShapeDef &shape, double scaling, SvgUnit unit, GlyphMetricsFn glyphMetrics)
 Convert a ShapeDef into an SVG string buffer with explicit scaling and units.
 
static std::string presetArrowheadAsSvg (dom::ArrowheadPreset preset, double scaling=1.0, SvgUnit unit=SvgUnit::None)
 Convert a Finale preset arrowhead into a standalone SVG string buffer.
 
static std::string toSvgWithPageFormatScaling (const dom::others::ShapeDef &shape, SvgUnit unit=SvgUnit::Millimeters)
 Convert a ShapeDef into an SVG string buffer using the document's page format scaling.
 
static std::string toSvgWithPageFormatScaling (const dom::others::ShapeDef &shape, SvgUnit unit, GlyphMetricsFn glyphMetrics)
 Convert a ShapeDef into an SVG string buffer using the document's page format scaling.
 

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 Enumeration Documentation

◆ SvgUnit

SVG unit suffixes supported by the converter.

Note
The absolute units (px/pt/pc/cm/mm/in) are converted from EVPU in this converter. When SvgUnit::None is used, output coordinates are unitless EVPU (after any explicit scaling).
Enumerator
None 

Unitless (no suffix).

Pixels 

"px"

Points 

"pt"

Picas 

"pc"

Centimeters 

"cm"

Millimeters 

"mm"

Inches 

"in"

Member Function Documentation

◆ presetArrowheadAsSvg()

std::string musx::util::SvgConvert::presetArrowheadAsSvg ( dom::ArrowheadPreset  preset,
double  scaling = 1.0,
SvgUnit  unit = SvgUnit::None 
)
static

Convert a Finale preset arrowhead into a standalone SVG string buffer.

Parameters
presetThe Finale preset arrowhead type.
scalingScale factor applied to EVPU-based coordinates before unit conversion. When unit is SvgUnit::None, the output coordinates are EVPU * scaling.
unitUnit suffix for width/height (e.g., SvgUnit::Millimeters).
Returns
An SVG buffer encoded as a string.

The returned SVG has the arrow tip anchored at (0,0) and points to the right (positive X axis) at zero rotation.

◆ toSvg() [1/4]

std::string musx::util::SvgConvert::toSvg ( const dom::others::ShapeDef &  shape)
static

Convert a ShapeDef into an SVG string buffer.

Parameters
shapeThe shape definition to convert.
Returns
An SVG buffer encoded as a string.
Note
External graphics are resolved from embedded graphics in the musx::dom::Document when available. Otherwise the converter tries a file with the same filename in the directory containing the source musx/EnigmaXML (provided via musx::factory::DocumentFactory::CreateOptions), then the original file location. If an external graphic still cannot be resolved, toSvg returns an empty string.
Todo:
ShapeDef SetArrowhead instructions are decoded but not yet rendered in SVG output.

◆ toSvg() [2/4]

std::string musx::util::SvgConvert::toSvg ( const dom::others::ShapeDef &  shape,
double  scaling,
SvgUnit  unit 
)
static

Convert a ShapeDef into an SVG string buffer with explicit scaling and units.

Parameters
shapeThe shape definition to convert.
scalingScale factor applied to EVPU-based coordinates before unit conversion. When unit is SvgUnit::None, the output coordinates are EVPU * scaling.
unitUnit suffix for width/height (e.g., SvgUnit::Millimeters).
Returns
An SVG buffer encoded as a string.

◆ toSvg() [3/4]

std::string musx::util::SvgConvert::toSvg ( const dom::others::ShapeDef &  shape,
double  scaling,
SvgUnit  unit,
GlyphMetricsFn  glyphMetrics 
)
static

Convert a ShapeDef into an SVG string buffer with explicit scaling and units.

Parameters
shapeThe shape definition to convert.
scalingScale factor applied to EVPU-based coordinates before unit conversion. When unit is SvgUnit::None, the output coordinates are EVPU * scaling.
unitUnit suffix for width/height (e.g., SvgUnit::Millimeters).
glyphMetricsCallback that receives the resolved font and the glyph(s) to measure and returns glyph metrics in EVPU units.
Returns
An SVG buffer encoded as a string.
Todo:
Render start/end arrowhead caps for line/path instructions.

◆ toSvg() [4/4]

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

Convert a ShapeDef into an SVG string buffer.

Parameters
shapeThe shape definition to convert.
glyphMetricsCallback that receives the resolved font and the glyph(s) to measure and returns glyph metrics in EVPU units.
Returns
An SVG buffer encoded as a string.

◆ toSvgWithPageFormatScaling() [1/2]

std::string musx::util::SvgConvert::toSvgWithPageFormatScaling ( const dom::others::ShapeDef &  shape,
SvgUnit  unit,
GlyphMetricsFn  glyphMetrics 
)
static

Convert a ShapeDef into an SVG string buffer using the document's page format scaling.

Parameters
shapeThe shape definition to convert.
unitUnit suffix for width/height (e.g., SvgUnit::Millimeters).
glyphMetricsCallback that receives the resolved font and the glyph(s) to measure and returns glyph metrics in EVPU units.
Returns
An SVG buffer encoded as a string.

◆ toSvgWithPageFormatScaling() [2/2]

std::string musx::util::SvgConvert::toSvgWithPageFormatScaling ( const dom::others::ShapeDef &  shape,
SvgUnit  unit = SvgUnit::Millimeters 
)
static

Convert a ShapeDef into an SVG string buffer using the document's page format scaling.

Parameters
shapeThe shape definition to convert.
unitUnit suffix for width/height (e.g., SvgUnit::Millimeters).
Returns
An SVG buffer encoded as a string.