8 #ifndef __VRV_RESOURCES_H__
9 #define __VRV_RESOURCES_H__
13 #include <unordered_map>
17 #include "fontstore.h"
35 using GlyphNameTable = std::unordered_map<std::string, char32_t>;
36 using FaceStyle = std::pair<FontStore::Weight, FontStore::Style>;
50 static std::string GetDefaultPath() {
return s_defaultPath; }
51 static void SetDefaultPath(
const std::string &path) { s_defaultPath = path; }
53 std::string GetPath()
const {
return m_path; }
54 void SetPath(
const std::string &path) { m_path = path; }
55 const FontStore &GetFontStore()
const {
return m_fontStore; }
56 FontStore &GetFontStoreForModification() {
return m_fontStore; }
73 const std::string &fontName, std::string &bundledFile)
const;
81 std::string GetCurrentFont()
const {
return m_currentFontName; }
82 bool IsFontLoaded(
const std::string &fontName)
const;
92 const Glyph *
GetGlyph(char32_t smuflCode,
const std::string &fontName)
const;
115 std::optional<FontStore::ShapedRun>
ShapeText(
const FontInfo &font,
const std::u32string &text)
const;
146 std::string m_fallbackFontName;
147 std::string m_currentFontName;
148 std::string m_textFontName;
151 mutable std::optional<std::pair<char32_t, const Glyph *>> m_cachedGlyph;
154 mutable std::unordered_map<uint64_t, std::map<std::pair<int, std::string>,
Glyph>> m_runtimeGlyphs;
157 std::map<std::string, std::vector<unsigned char>> m_musicFontSubsets;
167 static thread_local std::string s_defaultPath;
This class is store font properties.
Definition: devicecontextbase.h:137
This class registers OpenType fonts at runtime and gives access to their glyph metrics,...
Definition: fontstore.h:27
This class is used for storing a music font glyph.
Definition: glyph.h:32
This class provides resource values.
Definition: resources.h:33
std::string GetFallbackFont() const
Get the fallback font name.
Definition: resources.h:77
std::string GetTextFont() const
Return the default text family.
Definition: resources.h:111
static char32_t GetSmuflGlyphForUnicodeChar(const char32_t unicodeChar)
Static method that converts unicode music code points to SMuFL equivalent.
bool FontHasGlyphAvailable(const std::string &fontName, char32_t smuflCode) const
Returns true if the specified font is loaded and it contains the requested glyph.
int GetTextAdvance(const FontInfo &font, const FontStore::ShapedRun &run) const
Return the scaled advance of a shaped run, including letter spacing.
std::string GetTextFontMetricEquivalent() const
The widespread font family with the same metrics as the text font, if any (e.g., Times for Tinos)
static FaceStyle GetFaceStyle(const FontInfo &font)
Static method that returns the weight and style of the face for a drawing font.
bool SetFallbackFont(const std::string &fontName)
Set the music fallback family, which has to be registered.
bool IsSmuflFallbackNeeded(const std::u32string &text) const
Check if the text has any character that needs the smufl fallback font.
const Glyph * GetRuntimeGlyph(FontStore::FaceIdentity face, int glyphId, const std::string &code="") const
Returns a cached runtime glyph by immutable face identity and glyph ID.
const Glyph * GetGlyph(char32_t smuflCode) const
Retrieving glyphs.
const Glyph * GetTextGlyph(char32_t code, const FontInfo &font) const
Returns a glyph from the runtime face selected by a drawing font.
static std::string FindSmuflMetadata(const std::string &fontFilename)
Static method that looks for the SMuFL metadata file of a music font file.
std::optional< FontStore::ShapedRun > ShapeText(const FontInfo &font, const std::u32string &text) const
Shape text using the family and style requested by a drawing font.
bool SetTextFont(const std::string &fontName)
Text fonts.
bool Ok() const
Status checker.
const Glyph * GetGlyph(const std::string &smuflName) const
Returns the glyph (if exists) for a glyph name in the current SMuFL font.
char32_t GetGlyphCode(const std::string &smuflName) const
Returns the glyph (if exists) for a glyph name in the current SMuFL font.
bool SetCurrentFont(const std::string &fontName)
Select a particular font.
const Glyph * GetGlyph(char32_t smuflCode, const std::string &fontName) const
Returns a music glyph using an explicit registered family.
std::optional< FontStore::FontFile > GetMusicFontForEmbedding(const std::string &fontName, std::string &bundledFile) const
Return the font file of a music font for embedding in the SVG, which is a subset for the bundled font...
bool InitFonts()
Font initialization.
The identity of a face, which is the same for identical font data.
Definition: fontstore.h:34
A shaped text run.
Definition: fontstore.h:73