MUSX Document Model
Loading...
Searching...
No Matches
SvgConvert.h
1/*
2 * Copyright (C) 2025, Robert Patterson
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22#pragma once
23
24#include <cstdint>
25#include <functional>
26#include <optional>
27#include <string>
28#include <string_view>
29#include <vector>
30
31#include "musx/dom/Fundamentals.h"
32#include "musx/dom/MusxInstance.h"
33
34namespace musx {
35namespace dom {
36class FontInfo;
37namespace others {
38class ShapeDef;
39} // namespace others
40} // namespace dom
41
42namespace util {
43
47{
48public:
52 enum class SvgUnit
53 {
54 None,
55 Pixels,
56 Points,
57 Picas,
60 Inches
61 };
62
73
77 using GlyphMetricsFn = std::function<std::optional<GlyphMetrics>(const dom::FontInfo&, std::u32string_view)>;
78
88 static std::string toSvg(const dom::others::ShapeDef& shape);
89
95 static std::string toSvg(const dom::others::ShapeDef& shape,
96 GlyphMetricsFn glyphMetrics);
97
104 static std::string toSvg(const dom::others::ShapeDef& shape,
105 double scaling,
106 SvgUnit unit);
107
116 static std::string toSvg(const dom::others::ShapeDef& shape,
117 double scaling,
118 SvgUnit unit,
119 GlyphMetricsFn glyphMetrics);
120
129 static std::string presetArrowheadAsSvg(dom::ArrowheadPreset preset,
130 double scaling = 1.0,
131 SvgUnit unit = SvgUnit::None);
132
137 static std::string toSvgWithPageFormatScaling(const dom::others::ShapeDef& shape,
139
146 static std::string toSvgWithPageFormatScaling(const dom::others::ShapeDef& shape,
147 SvgUnit unit,
148 GlyphMetricsFn glyphMetrics);
149};
150
151} // namespace util
152} // namespace musx
Represents the default font settings for a particular element type.
Definition CommonClasses.h:66
Converts a Shape Designer definition into an SVG buffer.
Definition SvgConvert.h:47
std::function< std::optional< GlyphMetrics >(const dom::FontInfo &, std::u32string_view)> GlyphMetricsFn
Optional callback that returns glyph metrics in EVPU units.
Definition SvgConvert.h:77
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.
Definition SvgConvert.cpp:2682
static std::string toSvg(const dom::others::ShapeDef &shape)
Convert a ShapeDef into an SVG string buffer.
Definition SvgConvert.cpp:1047
SvgUnit
SVG unit suffixes supported by the converter.
Definition SvgConvert.h:53
@ None
Unitless (no suffix).
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.
Definition SvgConvert.cpp:2743
double EvpuFloat
EVPU fractional value (288.0 per inch)
Definition Fundamentals.h:58
ArrowheadPreset
Finale-defined arrowhead presets.
Definition EnumClasses.h:52
object model for musx file (enigmaxml)
Definition BaseClasses.h:36
Metrics for sizing SVG text bounds.
Definition SvgConvert.h:65
dom::EvpuFloat advance
The advance width of the text in EVPU units.
Definition SvgConvert.h:67
dom::EvpuFloat ascent
The ascent above the baseline in EVPU units.
Definition SvgConvert.h:69
dom::EvpuFloat descent
The descent below the baseline in EVPU units (positive value).
Definition SvgConvert.h:71