1
0
Fork 0

Add: FontSearcher interface.

pull/12790/head
Peter Nelson 2024-06-15 21:11:16 +01:00
parent b991a399ef
commit 895c0b254e
No known key found for this signature in database
GPG Key ID: 8EF8F0A467DF75ED
2 changed files with 57 additions and 0 deletions

View File

@ -230,6 +230,22 @@ void UninitFontCache()
#endif /* WITH_FREETYPE */
}
/**
* Register the FontSearcher instance. There can be only one font searcher, which depends on platform.
*/
FontSearcher::FontSearcher()
{
FontSearcher::instance = this;
}
/**
* Deregister this FontSearcher.
*/
FontSearcher::~FontSearcher()
{
FontSearcher::instance = nullptr;
}
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(WITH_FONTCONFIG) && !defined(WITH_COCOA)
bool SetFallbackFont(FontCacheSettings *, const std::string &, int, MissingGlyphSearcher *) { return false; }

View File

@ -39,4 +39,45 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face);
*/
bool SetFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, int winlangid, class MissingGlyphSearcher *callback);
struct FontFamily {
std::string family;
std::string style;
int32_t slant;
int32_t weight;
FontFamily(std::string_view family, std::string_view style, int32_t slant, int32_t weight) : family(family), style(style), slant(slant), weight(weight) {}
};
class FontSearcher {
public:
FontSearcher();
virtual ~FontSearcher();
/**
* Get the active FontSearcher instance.
* @return FontSearcher instance, or nullptr if not present.
*/
static inline FontSearcher *GetFontSearcher() { return FontSearcher::instance; }
/**
* List available fonts.
* @param language_isocode the language, e.g. en_GB.
* @param winlangid the language ID windows style.
* @return vector containing font family names.
*/
virtual std::vector<std::string> ListFamilies(const std::string &language_isocode, int winlangid) = 0;
/**
* List available styles for a font family.
* @param language_isocode the language, e.g. en_GB.
* @param winlangid the language ID windows style.
* @param font_family The font family to list.
* @return vector containing style information for the family.
*/
virtual std::vector<FontFamily> ListStyles(const std::string &language_isocode, int winlangid, std::string_view font_family) = 0;
private:
static inline FontSearcher *instance = nullptr;
};
#endif