Android: Allow specifying custom fonts in .xsys35rc

Now custom font files specified in .xsys35rc (as relative paths from the
ZIP root) can be loaded correctly.

This fixes #20 for Android.
This commit is contained in:
kichikuou
2021-06-03 18:58:29 +09:00
parent ac703b3448
commit cc60fdfb7d
+10 -1
View File
@@ -80,7 +80,16 @@ void font_select(int type, int size) {
TTF_Font *fs;
fs = TTF_OpenFontIndex(this.name[type], size, this.face[type]);
#ifdef __ANDROID__
// If `this.name[type]` is a custom font file specified in .xys35rc,
// SDL_RWFromFile used by TTF_OpenFontIndex does not work because it
// does not resolve relative path with the current directory. On the
// other hand, we can't just use fopen because SDL_RWFromFile can open
// apk assets and the default fonts are stored as assets.
FILE *fp = fopen(this.name[type], "r");
if (fp)
fs = TTF_OpenFontIndexRW(SDL_RWFromFP(fp, true), true, size, this.face[type]);
#endif
if (fs == NULL) {
WARNING("%s is not found:\n", this.name[type]);
return;