From cc60fdfb7d3564cc4a5390899f6b83c895ee2ccd Mon Sep 17 00:00:00 2001 From: kichikuou Date: Thu, 3 Jun 2021 18:58:29 +0900 Subject: [PATCH] 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. --- src/font.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/font.c b/src/font.c index 548f6be..7e6b591 100644 --- a/src/font.c +++ b/src/font.c @@ -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;