MNX Document Model
Loading...
Searching...
No Matches
FormattedText.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#include <string>
24#include <string_view>
25#include <vector>
26
27#include "BaseTypes.h"
28
29namespace mnx {
30
35namespace text {
36
42{
43protected:
44 std::string_view defaultType() const override { return "text"; }
45
46public:
47 using ContentObject::ContentObject;
48};
49
64
69class Text : public TextContentObject
70{
71public:
73 struct Required
74 {
75 std::string text;
76 };
77
79 Text(const std::shared_ptr<json>& root, json_pointer pointer)
81 {
82 }
83
88 Text(Base& parent, std::string_view key, const std::string& text)
90 {
91 set_text(text);
92 }
93
95 operator Required() const { return { text() }; }
96
98 static Required make(const std::string& text) { return { text }; }
99
100 MNX_REQUIRED_PROPERTY(std::string, text);
102
103 inline static constexpr std::string_view ContentTypeValue = "text";
104};
105
111{
112public:
114 struct Required
115 {
116 std::vector<std::string> glyphs;
117 };
118
120 Smufl(const std::shared_ptr<json>& root, json_pointer pointer)
122 {
123 }
124
129 Smufl(Base& parent, std::string_view key, const std::vector<std::string>& glyphs)
131 {
132 auto glyphArray = create_glyphs();
133 for (const auto& glyph : glyphs) {
134 glyphArray.push_back(glyph);
135 }
136 }
137
139 operator Required() const { return { glyphs().toStdVector() }; }
140
142 static Required make(const std::vector<std::string>& glyphs) { return { glyphs }; }
143
144 using TextContentObject::TextContentObject;
145
148
149 inline static constexpr std::string_view ContentTypeValue = "smufl";
150};
151
152} // namespace text
153
159{
160public:
161 using ContentArray::ContentArray;
162};
163
164} // namespace mnx
Represents an MNX array, encapsulating property access.
Definition BaseTypes.h:506
Base class wrapper for all MNX JSON nodes.
Definition BaseTypes.h:198
json_pointer pointer() const
Returns the json_pointer for this node.
Definition BaseTypes.h:260
T parent() const
Returns the parent object for this node.
Definition BaseTypes.h:246
const std::shared_ptr< json > & root() const
Returns the root.
Definition BaseTypes.h:283
Class for content arrays.
Definition BaseTypes.h:774
Base class for objects that are elements of content arrays.
Definition BaseTypes.h:696
Container for formatted-text content objects.
Definition FormattedText.h:159
Represents an MNX object, encapsulating property access.
Definition BaseTypes.h:415
Object()
Constructor fresh document or detached instance.
Definition BaseTypes.h:418
Represents a formatted text fragment expressed as SMuFL glyphs.
Definition FormattedText.h:111
Smufl(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Smufl objects.
Definition FormattedText.h:120
static constexpr std::string_view ContentTypeValue
type value that identifies the type within the content array
Definition FormattedText.h:149
MNX_REQUIRED_CHILD(Array< std::string >, glyphs)
the smufl glyphs in this chunk
Smufl(Base &parent, std::string_view key, const std::vector< std::string > &glyphs)
Creates a new Smufl class as a child of a JSON element.
Definition FormattedText.h:129
static Required make(const std::vector< std::string > &glyphs)
Create a Required instance for Smufl.
Definition FormattedText.h:142
MNX_OPTIONAL_CHILD(Style, style)
the style for the glyphs in thie chunk
Describes styling for formatted text content.
Definition FormattedText.h:55
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(FontWeight, weight, FontWeight::Plain)
the font weight
MNX_OPTIONAL_PROPERTY(std::string, font)
the name of the font
MNX_OPTIONAL_PROPERTY(double, size)
the font size
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(FontStyle, fontStyle, FontStyle::Plain)
the font style
Base class for formatted-text content objects.
Definition FormattedText.h:42
Represents a formatted text fragment.
Definition FormattedText.h:70
static Required make(const std::string &text)
Create a Required instance for Text.
Definition FormattedText.h:98
MNX_OPTIONAL_CHILD(Style, style)
the style for this formatted chunk
MNX_REQUIRED_PROPERTY(std::string, text)
the text for this formatted chunk
Text(Base &parent, std::string_view key, const std::string &text)
Creates a new Text class as a child of a JSON element.
Definition FormattedText.h:88
Text(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing Text objects.
Definition FormattedText.h:79
static constexpr std::string_view ContentTypeValue
type value that identifies the type within the content array
Definition FormattedText.h:103
object model for MNX format
json::json_pointer json_pointer
JSON pointer class for MNX.
Definition BaseTypes.h:68
FontWeight
Specifies the weight of text glyphs.
Definition Enumerations.h:146
@ Plain
plain (non-bold) text
FontStyle
Specifies the style of text glyphs.
Definition Enumerations.h:136
@ Plain
plain (non-italic) text
initializer class for Smufl
Definition FormattedText.h:115
std::vector< std::string > glyphs
the smufl glyphs in this chunk
Definition FormattedText.h:116
initializer class for Text
Definition FormattedText.h:74
std::string text
the text to be represented
Definition FormattedText.h:75