8 #ifndef __VRV_RESOURCES_H__
9 #define __VRV_RESOURCES_H__
12 #include <unordered_map>
16 #include "filereader.h"
32 using StyleAttributes = std::pair<data_FONTWEIGHT, data_FONTSTYLE>;
33 using GlyphTable = std::unordered_map<char32_t, Glyph>;
34 using GlyphNameTable = std::unordered_map<std::string, char32_t>;
35 using GlyphTextMap = std::map<StyleAttributes, GlyphTable>;
49 static std::string GetDefaultPath() {
return s_defaultPath; }
50 static void SetDefaultPath(
const std::string &path) { s_defaultPath = path; }
52 std::string GetPath()
const {
return m_path; }
53 void SetPath(
const std::string &path) { m_path = path; }
63 bool SetFont(
const std::string &fontName);
65 bool AddCustom(
const std::vector<std::string> &extraFonts);
75 std::string GetCurrentFont()
const {
return m_currentFontName; }
76 bool IsFontLoaded(
const std::string &fontName)
const {
return m_loadedFonts.find(fontName) != m_loadedFonts.end(); }
138 LoadedFont(
const std::string &name,
bool isFallback) : m_name(name), m_isFallback(isFallback) {}
140 const std::string GetName()
const {
return m_name; };
141 const GlyphTable &GetGlyphTable()
const {
return m_glyphTable; };
142 GlyphTable &GetGlyphTableForModification() {
return m_glyphTable; };
143 bool isFallback()
const {
return m_isFallback; };
145 void SetCSSFont(
const std::string &css) { m_css = css; }
146 std::string GetCSSFont(
const std::string &path)
const;
151 GlyphTable m_glyphTable;
153 const bool m_isFallback;
160 bool LoadFont(
const std::string &fontName, ZipFileReader *zipFile = NULL);
163 bool InitTextFont(
const std::string &fontName,
const StyleAttributes &style);
165 const GlyphTable &GetCurrentGlyphTable()
const {
return m_loadedFonts.at(m_currentFontName).GetGlyphTable(); };
166 const GlyphTable &GetFallbackGlyphTable()
const {
return m_loadedFonts.at(m_fallbackFontName).GetGlyphTable(); };
169 std::string m_defaultFontName;
170 std::string m_fallbackFontName;
171 std::map<std::string, LoadedFont> m_loadedFonts;
172 std::string m_currentFontName;
175 GlyphTextMap m_textFont;
176 mutable StyleAttributes m_currentStyle;
180 GlyphNameTable m_glyphNameTable;
183 mutable std::optional<std::pair<char32_t, const Glyph *>> m_cachedGlyph;
190 static thread_local std::string s_defaultPath;
193 static const StyleAttributes k_defaultStyle;
This class is used for storing a music font glyph.
Definition: glyph.h:31
This class provides resource values.
Definition: resources.h:30
std::string GetFallbackFont() const
Get the fallback font name.
Definition: resources.h:71
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.
bool SetFont(const std::string &fontName)
Set the font to be used and loads it if necessary.
const Glyph * GetTextGlyph(char32_t code) const
Returns the glyph (if exists) for the text font (bounding box and ASCII only)
std::string GetCustomFontname(const std::string &filename, const ZipFileReader &zipFile)
Retrieve the font name either from the filename path or from the zipFile content.
void SetFallbackFont(const std::string &fontName)
Set the fallback font (Leipzig or Bravura) when some glyphs are missing in the current font.
bool IsSmuflFallbackNeeded(const std::u32string &text) const
Check if the text has any charachter that needs the smufl fallback font.
std::string GetCSSFontFor(const std::string &fontName) const
Get the CSS font string for the corresponding font.
const Glyph * GetGlyph(char32_t smuflCode) const
Retrieving glyphs.
bool IsCurrentFontFallback() const
Check if the current font is the fallback font.
bool AddCustom(const std::vector< std::string > &extraFonts)
Add custom (external) fonts.
const Glyph * GetGlyph(const std::string &smuflName) const
Returns the glyph (if exists) for a glyph name in the current SMuFL font.
bool LoadAll()
Load all music fonts available in the resource directory.
char32_t GetGlyphCode(const std::string &smuflName) const
Returns the glyph (if exists) for a glyph name in the current SMuFL font.
void SelectTextFont(data_FONTWEIGHT fontWeight, data_FONTSTYLE fontStyle) const
Text fonts.
bool InitFonts()
Font initialization.
bool SetCurrentFont(const std::string &fontName, bool allowLoading=false)
Select a particular font.
This class is a reader for zip archives.
Definition: filereader.h:33