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 {
53 std::string mimeType;
54 std::vector<std::uint8_t> bytes;
55 };
56
65
68 {
70 double advance{};
72 double ascent{};
74 double descent{};
75 };
76
80 using GlyphMetricsFn = std::function<std::optional<GlyphMetrics>(const dom::FontInfo&, std::u32string_view)>;
81
83 using ExternalGraphicFn = std::function<std::optional<ExternalGraphicPayload>(const ExternalGraphicInfo&)>;
84
93 static std::string toSvg(const dom::others::ShapeDef& shape,
94 GlyphMetricsFn glyphMetrics = nullptr,
95 ExternalGraphicFn externalGraphicResolver = nullptr);
96};
97
98} // namespace util
99} // 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:80
std::function< std::optional< ExternalGraphicPayload >(const ExternalGraphicInfo &)> ExternalGraphicFn
Optional callback that resolves external graphics to a MIME type and byte buffer.
Definition SvgConvert.h:83
static std::string toSvg(const dom::others::ShapeDef &shape, GlyphMetricsFn glyphMetrics=nullptr, ExternalGraphicFn externalGraphicResolver=nullptr)
Convert a ShapeDef into an SVG string buffer.
Definition SvgConvert.cpp:663
int32_t Evpu
EVPU value (288 per inch)
Definition Fundamentals.h:57
uint16_t Cmper
Enigma "comperator" key type.
Definition Fundamentals.h:55
object model for musx file (enigmaxml)
Definition BaseClasses.h:36
Metadata describing an external graphic instruction.
Definition SvgConvert.h:60
dom::Evpu width
Width of the external graphic in EVPU units.
Definition SvgConvert.h:61
dom::Cmper cmper
Cmper matching dom::others::PageGraphicAssign::graphicCmper.
Definition SvgConvert.h:63
dom::Evpu height
Height of the external graphic in EVPU units.
Definition SvgConvert.h:62
Payload data for external graphics.
Definition SvgConvert.h:52
std::vector< std::uint8_t > bytes
Raw graphic bytes (caller-provided).
Definition SvgConvert.h:54
std::string mimeType
MIME type for the graphic data.
Definition SvgConvert.h:53
Metrics for sizing SVG text bounds.
Definition SvgConvert.h:68
double descent
The descent below the baseline in EVPU units (positive value).
Definition SvgConvert.h:74
double advance
The advance width of the text in EVPU units.
Definition SvgConvert.h:70
double ascent
The ascent above the baseline in EVPU units.
Definition SvgConvert.h:72