1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-15 09:25:37 +02:00

GUI: Use the client's fonts for 'Open URL?' dialogues

This popup is related to user safety, thus it should not
use server-provided font media files.
This commit is contained in:
SmallJoker
2025-03-15 15:30:35 +01:00
committed by SmallJoker
parent 5b2b2c7796
commit f1364b1e0b
4 changed files with 72 additions and 32 deletions

View File

@@ -23,10 +23,22 @@ namespace irr {
#define FONT_SIZE_UNSPECIFIED 0xFFFFFFFF
enum FontMode : u8 {
/// Regular font (settings "font_path*", overwritable)
FM_Standard = 0,
/// Monospace font (settings "mono_font*", overwritable)
FM_Mono,
_FM_Fallback, // do not use directly
/// Use only in `FontEngine`. Fallback font to render glyphs that are not present
/// in the originally requested font (setting "fallback_font_path")
_FM_Fallback,
/// Sum of all font modes
FM_MaxMode,
// ----------------------------
/// Request the defult font specified by `s_default_font_mode`
FM_Unspecified
};
@@ -37,15 +49,22 @@ struct FontSpec {
bold(bold),
italic(italic) {}
static const unsigned VARIANT_BITS = 3;
static const size_t MAX_VARIANTS = FM_MaxMode << VARIANT_BITS;
u16 getHash() const
{
return (mode << 2) | (static_cast<u8>(bold) << 1) | static_cast<u8>(italic);
return (mode << VARIANT_BITS)
| (static_cast<u8>(allow_server_media) << 2)
| (static_cast<u8>(bold) << 1)
| static_cast<u8>(italic);
}
unsigned int size;
FontMode mode;
bool bold;
bool italic;
bool allow_server_media = true;
};
class FontEngine
@@ -135,7 +154,7 @@ private:
void updateCache();
/** initialize a new TTF font */
gui::IGUIFont *initFont(const FontSpec &spec);
gui::IGUIFont *initFont(FontSpec spec);
/** update current minetest skin with font changes */
void updateSkin();
@@ -155,7 +174,7 @@ private:
std::recursive_mutex m_font_mutex;
/** internal storage for caching fonts of different size */
std::map<unsigned int, irr::gui::IGUIFont*> m_font_cache[FM_MaxMode << 2];
std::map<unsigned int, irr::gui::IGUIFont*> m_font_cache[FontSpec::MAX_VARIANTS];
/** media-provided faces, indexed by filename (without extension) */
std::unordered_map<std::string, irr_ptr<gui::SGUITTFace>> m_media_faces;
@@ -168,7 +187,7 @@ private:
bool m_default_italic = false;
/** default font engine mode (fixed) */
static const FontMode m_currentMode = FM_Standard;
static const FontMode s_default_font_mode = FM_Standard;
bool m_needs_reload = false;