Use stub Font_UNSAFE_GetDefault for web client to prevent it getting bloated into ~180 lines of JS code

This commit is contained in:
UnknownShadow200 2020-11-07 20:14:48 +11:00
parent 8981b3cbbd
commit 9d1f2cda6a
3 changed files with 20 additions and 20 deletions

View File

@ -54,20 +54,6 @@ void Drawer2D_SetDefaultFont(const cc_string* fontName) {
Event_RaiseVoid(&ChatEvents.FontChanged); 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 */ /* adjusts height to be closer to system fonts */
static int Drawer2D_AdjHeight(int point) { return Math_CeilDiv(point * 3, 2); } static int Drawer2D_AdjHeight(int point) { return Math_CeilDiv(point * 3, 2); }
@ -709,10 +695,9 @@ struct IGameComponent Drawer2D_Component = {
*------------------------------------------------------System fonts-------------------------------------------------------* *------------------------------------------------------System fonts-------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
#ifdef CC_BUILD_WEB #ifdef CC_BUILD_WEB
const cc_string* Font_UNSAFE_GetDefault(void) { return &font_candidates[0]; }
void Font_GetNames(struct StringsBuffer* buffer) { } void Font_GetNames(struct StringsBuffer* buffer) { }
cc_string Font_Lookup(const cc_string* fontName, int flags) { cc_string Font_Lookup(const cc_string* fontName, int flags) { return String_Empty; }
return String_Empty;
}
cc_result Font_Make(struct FontDesc* desc, const cc_string* fontName, int size, int flags) { cc_result Font_Make(struct FontDesc* desc, const cc_string* fontName, int size, int flags) {
desc->size = size; 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) { void Font_GetNames(struct StringsBuffer* buffer) {
cc_string entry, name, path; cc_string entry, name, path;
int i; int i;

View File

@ -20,8 +20,6 @@ void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, struct FontDesc* font, cc
/* Sets default system font name and raises ChatEvents.FontChanged */ /* Sets default system font name and raises ChatEvents.FontChanged */
void Drawer2D_SetDefaultFont(const cc_string* fontName); 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. */ /* 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); 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. */ /* The bitmap must be square and consist of a 16x16 tile layout. */
cc_bool Drawer2D_SetFontBitmap(struct Bitmap* bmp); 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. */ /* Gets the list of all supported system font names on this platform. */
CC_API void Font_GetNames(struct StringsBuffer* buffer); CC_API void Font_GetNames(struct StringsBuffer* buffer);
/* Sets padding for a bitmapped font. */ /* Sets padding for a bitmapped font. */
void Font_SetPadding(struct FontDesc* desc, int amount); void Font_SetPadding(struct FontDesc* desc, int amount);
/* Finds the path and face number of the given system font, with closest matching style */ /* Finds the path and face number of the given system font, with closest matching style */

View File

@ -1601,7 +1601,7 @@ static void FontListScreen_UpdateEntry(struct ListScreen* s, struct ButtonWidget
static void FontListScreen_LoadEntries(struct ListScreen* s) { static void FontListScreen_LoadEntries(struct ListScreen* s) {
Font_GetNames(&s->entries); Font_GetNames(&s->entries);
ListScreen_Sort(s); ListScreen_Sort(s);
ListScreen_Select(s, Drawer2D_UNSAFE_GetDefaultFont()); ListScreen_Select(s, Font_UNSAFE_GetDefault());
} }
void FontListScreen_Show(void) { void FontListScreen_Show(void) {