diff --git a/arm9/source/common/ui.c b/arm9/source/common/ui.c index f139d2b..e983b61 100644 --- a/arm9/source/common/ui.c +++ b/arm9/source/common/ui.c @@ -18,11 +18,10 @@ #define STRBUF_SIZE 512 // maximum size of the string buffer #define FONT_MAX_WIDTH 8 #define FONT_MAX_HEIGHT 10 -#define FONT_N_SYMBOLS 256 static u32 font_width = 0; static u32 font_height = 0; -static u8 font_bin[FONT_MAX_HEIGHT * FONT_N_SYMBOLS]; +static u8 font_bin[FONT_MAX_HEIGHT * 256]; u8* GetFontFromPbm(const void* pbm, const u32 pbm_size, u32* w, u32* h) { @@ -68,14 +67,22 @@ u8* GetFontFromPbm(const void* pbm, const u32 pbm_size, u32* w, u32* h) { return NULL; // check sizes - if ((pbm_w > FONT_MAX_WIDTH) || (pbm_h % FONT_N_SYMBOLS) || - ((pbm_h / FONT_N_SYMBOLS) > FONT_MAX_HEIGHT) || - (pbm_h != (pbm_size - p))) - return NULL; + if (pbm_w <= 8) { // 1x256 format + if ((pbm_w > FONT_MAX_WIDTH) || (pbm_h % 256) || + ((pbm_h / 256) > FONT_MAX_HEIGHT) || + (pbm_h != (pbm_size - p))) + return NULL; + } else { // 16x16 format + if ((pbm_w % 16) || (pbm_h % 16) || + ((pbm_w / 16) > FONT_MAX_WIDTH) || + ((pbm_h / 16) > FONT_MAX_HEIGHT) || + ((pbm_h * pbm_w / 8) != (pbm_size - p))) + return NULL; + } // all good if (w) *w = pbm_w; - if (h) *h = pbm_h / FONT_N_SYMBOLS; + if (h) *h = pbm_h; return (u8*) pbm + p; } @@ -94,12 +101,31 @@ bool SetFontFromPbm(const void* pbm, u32 pbm_size) { if (pbm) ptr = GetFontFromPbm(pbm, pbm_size, &w, &h); - if (ptr) { + if (!ptr) { + return false; + } else if (w > 8) { + font_width = w / 16; + font_height = h / 16; + memset(font_bin, 0x00, w * h / 8); + + for (u32 cy = 0; cy < 16; cy++) { + for (u32 row = 0; row < font_height; row++) { + for (u32 cx = 0; cx < 16; cx++) { + u32 bp0 = (cx * font_width) >> 3; + u32 bm0 = (cx * font_width) % 8; + u8 byte = ((ptr[bp0] << bm0) | (ptr[bp0+1] >> (8 - bm0))) & (0xFF << (8 - font_width)); + font_bin[(((cy << 4) + cx) * font_height) + row] = byte; + } + ptr += font_width << 1; + } + } + } else { font_width = w; - font_height = h; - memcpy(font_bin, ptr, h * FONT_N_SYMBOLS); - return true; - } else return false; + font_height = h / 256; + memcpy(font_bin, ptr, h); + } + + return true; } void ClearScreen(u8* screen, int color) diff --git a/data/font.pbm b/data/font.pbm index 88b2267..36c1c93 100644 Binary files a/data/font.pbm and b/data/font.pbm differ diff --git a/resources/fonts/font_6x10.pbm b/resources/fonts/font_6x10.pbm index 88b2267..36c1c93 100644 Binary files a/resources/fonts/font_6x10.pbm and b/resources/fonts/font_6x10.pbm differ diff --git a/resources/fonts/font_acorn_8x8.pbm b/resources/fonts/font_acorn_8x8.pbm index 62b7cd6..4cdd0df 100644 Binary files a/resources/fonts/font_acorn_8x8.pbm and b/resources/fonts/font_acorn_8x8.pbm differ diff --git a/resources/fonts/font_gb_7x6.pbm b/resources/fonts/font_gb_7x6.pbm index 0a867fb..2b66768 100644 Binary files a/resources/fonts/font_gb_7x6.pbm and b/resources/fonts/font_gb_7x6.pbm differ diff --git a/resources/fonts/font_original_8x8.pbm b/resources/fonts/font_original_8x8.pbm index ddc044a..6420a01 100644 Binary files a/resources/fonts/font_original_8x8.pbm and b/resources/fonts/font_original_8x8.pbm differ diff --git a/resources/fonts/font_sheikah_8x8.pbm b/resources/fonts/font_sheikah_8x8.pbm deleted file mode 100644 index 9bbb62e..0000000 Binary files a/resources/fonts/font_sheikah_8x8.pbm and /dev/null differ diff --git a/resources/fonts/font_zuish_8x8.pbm b/resources/fonts/font_zuish_8x8.pbm deleted file mode 100644 index be01f46..0000000 Binary files a/resources/fonts/font_zuish_8x8.pbm and /dev/null differ