NDEVR
API Documentation
Font.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: Font
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/File.h>
35#include <NDEVR/RGBColor.h>
36#include <NDEVR/Dictionary.h>
37namespace NDEVR
38{
39 class UUID;
40
45 class Font
46 {
47 public:
48
50 fltp08 point_size = Constant<fltp08>::Invalid;
51 fltp08 pixel_size = Constant<fltp08>::Invalid;
52 fltp08 fixed_width = Constant<fltp08>::Invalid;
53 fltp08 tab_advance = Constant<fltp08>::Invalid;
55 RGBColor color = Constant<RGBColor>::Invalid;
56
57 bool is_underline = false;
58 bool is_overstrike = false;
59 bool is_strikethrough = false;
60
65 StringView name() const { return m_name; };
66
71 bool isBold() const { return m_is_bold; };
72
77 bool isItalic() const { return m_is_italic; };
78
83 void setHasBoldFamily(bool has_bold_family) { m_has_bold_family = has_bold_family; }
84
89 void setHasItalicFamily(bool has_italic_family) { m_has_italic_family = has_italic_family; }
90
95 NDEVR_BASE_API bool hasItalicFamily() const;
96
101 NDEVR_BASE_API bool hasBoldFamily() const;
102
107 NDEVR_BASE_API void setName(const StringView& name);
108
113 NDEVR_BASE_API void setIsBold(bool is_bold);
114
119 NDEVR_BASE_API void setIsItalic(bool is_italic);
120
126 NDEVR_BASE_API bool operator==(const Font& font) const;
127
133 NDEVR_BASE_API bool operator!=(const Font& font) const;
134
139 const File& file() const { return m_file; };
140
146 NDEVR_BASE_API bool findBestFileIfNeeded(bool allow_backup_file = true);
147
152 void setFile(const File& file) { m_file = file; }
153
160 NDEVR_BASE_API bool executeAnsiiCode(uint04 ansii_code, const Font& default_font);
161 protected:
163 bool m_is_bold = false;
164 bool m_is_italic = false;
165 bool m_has_bold_family = false;
166 bool m_has_italic_family = false;
167 mutable File m_file;
168 mutable std::function<Font(wchar_t character)> m_fallback_font;
169 };
170
176 {
177 public:
178 static constexpr StringView DefaultFont = "Default";
179
185 NDEVR_BASE_API static void SetApplicationFont(const StringView& app_font, const Font& font);
186
192 NDEVR_BASE_API static const Font& ApplicationFont(const StringView& app_font);
193
199 NDEVR_BASE_API static bool HasApplicationFont(const StringView& app_font);
200
207 NDEVR_BASE_API static File FindBestFitFontFile(Font& font, bool allow_backup_file = true);
208
213 NDEVR_BASE_API static void PullFontFromFolder(const File& folder);
214
220 NDEVR_BASE_API static bool HasFontFile(const StringView& font_name);
221
228 NDEVR_BASE_API static void SetFontFile(const StringView& font_name, const File& file, uint04 index = 0);
229
234 NDEVR_BASE_API static void SetSettingsFile(const File& file);
235
239 NDEVR_BASE_API static void SaveFontSettings();
240
244 NDEVR_BASE_API static void ReadFontSettings();
245
252 NDEVR_BASE_API static void AddFontListener(const StringView& app_font, UUID id, std::function<void(const StringView&)> callback);
253
259 NDEVR_BASE_API static void RemoveFontListener(const StringView& app_font, UUID id);
260
267 NDEVR_BASE_API static Font FindFallbackFont(Font original, wchar_t character);
268 protected:
274 NDEVR_BASE_API static File TryFontName(const StringView& family);
275 protected:
280 NDEVR_BASE_API static Dictionary<String, Dictionary<UUID, std::function<void(const StringView&)>>> s_app_font_listener;
281 NDEVR_BASE_API static File s_settings_file;
282 };
283
287 {
290 uint01 alignment = Constant<uint01>::Invalid;
291
297 bool operator==(const TextBlock& block) const
298 {
299 return text == block.text && font == block.font && alignment == block.alignment;
300 }
301
307 bool operator!=(const TextBlock& block) const
308 {
309 return text != block.text || font != block.font || alignment != block.alignment;
310 }
311 };
312
329
336 inline uint01 operator|(const TextAlignment& a, const TextAlignment& b)
337 {
338 return cast<uint01>(a) | cast<uint01>(b);
339 }
340}
341
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
Stores many different types of font.
Definition Font.h:176
static Dictionary< String, Font > s_system_fonts
Mapping of font names to system-installed fonts.
Definition Font.h:276
static void SaveFontSettings()
Saves the current font settings to the settings file.
static Font FindFallbackFont(Font original, wchar_t character)
Finds a fallback font that supports the given character.
static constexpr StringView DefaultFont
The default application font identifier.
Definition Font.h:178
static Dictionary< String, Dictionary< UUID, std::function< void(const StringView &)> > > s_app_font_listener
Registered font change listeners per application font.
Definition Font.h:280
static void SetFontFile(const StringView &font_name, const File &file, uint04 index=0)
Associates a font file with a font name.
static void PullFontFromFolder(const File &folder)
Scans a folder for font files and registers them.
static void ReadFontSettings()
Reads font settings from the settings file.
static Dictionary< String, Font > s_application_fonts
Mapping of application font identifiers to fonts.
Definition Font.h:277
static Dictionary< String, String > s_font_files
Mapping of font names to font file paths.
Definition Font.h:278
static bool HasApplicationFont(const StringView &app_font)
Checks whether an application font has been registered with the given name.
static Dictionary< String, uint04 > s_font_indices
Mapping of font names to face indices within font files.
Definition Font.h:279
static void RemoveFontListener(const StringView &app_font, UUID id)
Removes a previously registered font change listener.
static void AddFontListener(const StringView &app_font, UUID id, std::function< void(const StringView &)> callback)
Registers a callback to be invoked when an application font changes.
static bool HasFontFile(const StringView &font_name)
Checks whether a font file is registered for the given font name.
static File s_settings_file
File used to persist font settings.
Definition Font.h:281
static File TryFontName(const StringView &family)
Attempts to locate a font file by font family name.
static void SetSettingsFile(const File &file)
Sets the file used to persist font settings.
static File FindBestFitFontFile(Font &font, bool allow_backup_file=true)
Finds the best matching font file for the given font properties.
static void SetApplicationFont(const StringView &app_font, const Font &font)
Registers or updates an application font by name.
static const Font & ApplicationFont(const StringView &app_font)
Retrieves a registered application font by name.
Information for how to display text data.
Definition Font.h:46
std::function< Font(wchar_t character)> m_fallback_font
Callback to find a fallback font for unsupported characters.
Definition Font.h:168
String m_name
The font family name.
Definition Font.h:162
bool executeAnsiiCode(uint04 ansii_code, const Font &default_font)
Applies an ANSI escape code to modify the font style.
bool operator!=(const Font &font) const
Checks inequality between two Font objects.
void setIsItalic(bool is_italic)
Sets whether the font style is italic.
bool m_has_italic_family
Whether an italic variant of this font family exists.
Definition Font.h:166
String app_font_name
Application-specific font identifier name.
Definition Font.h:49
bool hasBoldFamily() const
Checks whether a bold variant of this font family exists.
void setHasBoldFamily(bool has_bold_family)
Sets whether a bold variant of this font family exists.
Definition Font.h:83
bool m_is_italic
Whether the font is italic.
Definition Font.h:164
bool is_overstrike
Whether the font style includes overstrike.
Definition Font.h:58
bool m_has_bold_family
Whether a bold variant of this font family exists.
Definition Font.h:165
void setName(const StringView &name)
Sets the font family name.
void setIsBold(bool is_bold)
Sets whether the font style is bold.
bool operator==(const Font &font) const
Checks equality between two Font objects.
fltp08 tab_advance
Horizontal advance distance for tab characters.
Definition Font.h:53
StringView name() const
Gets the font family name.
Definition Font.h:65
uint04 index
Index of the font face within a font file.
Definition Font.h:54
bool is_underline
Whether the font style includes underline.
Definition Font.h:57
bool hasItalicFamily() const
Checks whether an italic variant of this font family exists.
fltp08 pixel_size
Font size in pixels.
Definition Font.h:51
const File & file() const
Gets the file path associated with this font.
Definition Font.h:139
bool m_is_bold
Whether the font is bold.
Definition Font.h:163
bool isBold() const
Checks whether the font style is bold.
Definition Font.h:71
bool isItalic() const
Checks whether the font style is italic.
Definition Font.h:77
File m_file
Cached file path for the font.
Definition Font.h:167
RGBColor color
Font rendering color.
Definition Font.h:55
bool findBestFileIfNeeded(bool allow_backup_file=true)
Locates the best matching font file if one has not been set.
fltp08 fixed_width
Fixed character width override.
Definition Font.h:52
fltp08 point_size
Font size in points.
Definition Font.h:50
void setFile(const File &file)
Sets the file path for this font.
Definition Font.h:152
bool is_strikethrough
Whether the font style includes strikethrough.
Definition Font.h:59
void setHasItalicFamily(bool has_italic_family)
Sets whether an italic variant of this font family exists.
Definition Font.h:89
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
This class is like a string view, but may optionally store the data internally Useful if the return t...
Definition String.h:1278
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
The primary namespace for the NDEVR SDK.
TextAlignment
How to align text into a given container.
Definition Font.h:318
@ e_top
Align text to the top.
Definition Font.h:321
@ e_bottom
Align text to the bottom.
Definition Font.h:322
@ e_h_center
Center text horizontally.
Definition Font.h:324
@ e_bottom_base
Align text to the baseline at the bottom.
Definition Font.h:323
@ e_v_baseline_center
Center text vertically using baseline alignment.
Definition Font.h:326
@ e_right
Align text to the right.
Definition Font.h:320
@ e_center
Center text both horizontally and vertically.
Definition Font.h:327
@ e_left
Align text to the left.
Definition Font.h:319
@ e_v_center
Center text vertically.
Definition Font.h:325
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
@ file
The source file path associated with this object.
uint01 operator|(const TextAlignment &a, const TextAlignment &b)
Bitwise OR operator for combining TextAlignment flags.
Definition Font.h:336
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408
text that is formatted the same way, typically part of a bigger group of text
Definition Font.h:287
bool operator!=(const TextBlock &block) const
Checks inequality between two TextBlock objects.
Definition Font.h:307
StringAllocatingView text
The text content of this block.
Definition Font.h:288
bool operator==(const TextBlock &block) const
Checks equality between two TextBlock objects.
Definition Font.h:297
uint01 alignment
The text alignment flags for this block.
Definition Font.h:290
Font font
The font style applied to this block.
Definition Font.h:289