From 9d1f2cda6a79bb85296cec7e1986570cd0b0bba4 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 7 Nov 2020 20:14:48 +1100 Subject: [PATCH] Use stub Font_UNSAFE_GetDefault for web client to prevent it getting bloated into ~180 lines of JS code --- src/Drawer2D.c | 33 ++++++++++++++++----------------- src/Drawer2D.h | 5 +++-- src/Menus.c | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Drawer2D.c b/src/Drawer2D.c index f666169d1..a4b82b998 100644 --- a/src/Drawer2D.c +++ b/src/Drawer2D.c @@ -54,20 +54,6 @@ void Drawer2D_SetDefaultFont(const cc_string* fontName) { Event_RaiseVoid(&ChatEvents.FontChanged); } -const cc_string* Drawer2D_UNSAFE_GetDefaultFont(void) { - cc_string* font, path; - int i; - - for (i = 0; i < Array_Elems(font_candidates); i++) { - font = &font_candidates[i]; - if (!font->length) continue; - - path = Font_Lookup(font, FONT_FLAGS_NONE); - if (path.length) return font; - } - return &String_Empty; -} - /* adjusts height to be closer to system fonts */ static int Drawer2D_AdjHeight(int point) { return Math_CeilDiv(point * 3, 2); } @@ -709,10 +695,9 @@ struct IGameComponent Drawer2D_Component = { *------------------------------------------------------System fonts-------------------------------------------------------* *#########################################################################################################################*/ #ifdef CC_BUILD_WEB +const cc_string* Font_UNSAFE_GetDefault(void) { return &font_candidates[0]; } void Font_GetNames(struct StringsBuffer* buffer) { } -cc_string Font_Lookup(const cc_string* fontName, int flags) { - return String_Empty; -} +cc_string Font_Lookup(const cc_string* fontName, int flags) { return String_Empty; } cc_result Font_Make(struct FontDesc* desc, const cc_string* fontName, int size, int flags) { desc->size = size; @@ -956,6 +941,20 @@ void SysFonts_Register(const cc_string* path) { } } +const cc_string* Font_UNSAFE_GetDefault(void) { + cc_string* font, path; + int i; + + for (i = 0; i < Array_Elems(font_candidates); i++) { + font = &font_candidates[i]; + if (!font->length) continue; + + path = Font_Lookup(font, FONT_FLAGS_NONE); + if (path.length) return font; + } + return &String_Empty; +} + void Font_GetNames(struct StringsBuffer* buffer) { cc_string entry, name, path; int i; diff --git a/src/Drawer2D.h b/src/Drawer2D.h index 6bfa5248c..c5cae8d19 100644 --- a/src/Drawer2D.h +++ b/src/Drawer2D.h @@ -20,8 +20,6 @@ void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, struct FontDesc* font, cc /* Sets default system font name and raises ChatEvents.FontChanged */ void Drawer2D_SetDefaultFont(const cc_string* fontName); -/* Gets the name of the default system font. */ -const cc_string* Drawer2D_UNSAFE_GetDefaultFont(void); /* Initialises the given font. When Drawer2D_BitmappedText is false, creates native font handle using Font_Make. */ CC_API void Drawer2D_MakeFont(struct FontDesc* desc, int size, int flags); @@ -101,8 +99,11 @@ void Drawer2D_ReducePadding_Height(int* height, int point, int scale); /* The bitmap must be square and consist of a 16x16 tile layout. */ cc_bool Drawer2D_SetFontBitmap(struct Bitmap* bmp); +/* Gets the name of the default system font used. */ +const cc_string* Font_UNSAFE_GetDefault(void); /* Gets the list of all supported system font names on this platform. */ CC_API void Font_GetNames(struct StringsBuffer* buffer); + /* Sets padding for a bitmapped font. */ void Font_SetPadding(struct FontDesc* desc, int amount); /* Finds the path and face number of the given system font, with closest matching style */ diff --git a/src/Menus.c b/src/Menus.c index 4cc1e24a4..85fc7ec03 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -1601,7 +1601,7 @@ static void FontListScreen_UpdateEntry(struct ListScreen* s, struct ButtonWidget static void FontListScreen_LoadEntries(struct ListScreen* s) { Font_GetNames(&s->entries); ListScreen_Sort(s); - ListScreen_Select(s, Drawer2D_UNSAFE_GetDefaultFont()); + ListScreen_Select(s, Font_UNSAFE_GetDefault()); } void FontListScreen_Show(void) {