From a64bc8c6a05fba9897cf4f7e2de479631d4ad683 Mon Sep 17 00:00:00 2001 From: The Gears of Progress Date: Tue, 27 Jan 2026 10:34:06 -0500 Subject: [PATCH] Combining fonts into one file --- .gitignore | 3 +- include/japanese_normal.h | 19 ---- include/latin_normal.h | 19 ---- source/japanese_normal.c | 198 --------------------------------- source/text_engine.cpp | 16 ++- text_helper/main.py | 223 ++++++++++++++++---------------------- 6 files changed, 110 insertions(+), 368 deletions(-) delete mode 100644 include/japanese_normal.h delete mode 100644 include/latin_normal.h delete mode 100644 source/japanese_normal.c diff --git a/.gitignore b/.gitignore index 55d9a35..6537d39 100644 --- a/.gitignore +++ b/.gitignore @@ -15,5 +15,4 @@ include/translated_text.h source/translated_text.cpp text_helper/output.json text_helper/text.xlsx -include/latin_normal.h -source/latin_normal.c +include/fonts.h diff --git a/include/japanese_normal.h b/include/japanese_normal.h deleted file mode 100644 index f621375..0000000 --- a/include/japanese_normal.h +++ /dev/null @@ -1,19 +0,0 @@ -#include "debug_mode.h" -#include "pokemon_data.h" - -#if PTGB_BUILD_LANGUAGE == 1 - -#ifndef __JAPANESE_NORMAL__ -#define __JAPANESE_NORMAL__ - -extern const TFont japanese_normalFont; - -#define japanese_normalGlyphsLen 4096 -extern const unsigned int japanese_normalGlyphs[4096]; - -#define japanese_normalWidthsLen 256 -extern const unsigned char japanese_normalWidths[256]; - -#endif - -#endif diff --git a/include/latin_normal.h b/include/latin_normal.h deleted file mode 100644 index a9601b4..0000000 --- a/include/latin_normal.h +++ /dev/null @@ -1,19 +0,0 @@ -#include "debug_mode.h" -#include "pokemon_data.h" - -#if PTGB_BUILD_LANGUAGE != 1 - -#ifndef __LATIN_NORMAL__ -#define __LATIN_NORMAL__ - -extern const TFont latin_normalFont; - -#define latin_normalGlyphsLen 8192 -extern const unsigned int latin_normalGlyphs[8192]; - -#define latin_normalWidthsLen 256 -extern const unsigned char latin_normalWidths[256]; - -#endif - -#endif diff --git a/source/japanese_normal.c b/source/japanese_normal.c deleted file mode 100644 index 4c7bb2e..0000000 --- a/source/japanese_normal.c +++ /dev/null @@ -1,198 +0,0 @@ -typedef struct TFont -{ - const void *data; //!< Character data. - const unsigned char *widths; //!< Width table for vwf. - const unsigned char *heights; //!< Height table for vhf. - unsigned short charOffset; //!< Character offset. - unsigned short charnumChars; //!< Character numChars. - unsigned char charW; //!< Character width (fwf). - unsigned char charH; //!< Character height. - unsigned char cellW; //!< Glyph cell width. - unsigned char cellH; //!< Glyph cell height. - unsigned short cellSize; //!< Cell-size (bytes). - unsigned char bpp; //!< Font bitdepth; - unsigned char extra; //!< Padding. Free to use. -} TFont; - -const unsigned int japanese_normalGlyphs[1024] __attribute__((aligned(4)))= -{ - 0x00000000,0x00000000,0x00000000,0x00000000,0x04000000,0x3e24043f,0x264d5565,0x00000000, - 0x00000000,0x41412101,0x06094141,0x00000000,0x1c000000,0x40413e00,0x1c204040,0x00000000, - 0x0e000000,0x10103f00,0x61120c08,0x00000000,0x24000000,0x3e04445f,0x36454545,0x00000000, - 0x22000000,0x22225f42,0x18212122,0x00000000,0x08000000,0x207e103e,0x3c020240,0x00000000, - 0x20000000,0x02040810,0x20100804,0x00000000,0x20000000,0x21217d21,0x12212121,0x00000000, - 0x00000000,0x0000201e,0x3c020000,0x00000000,0x10000000,0x20207e10,0x3c020240,0x00000000, - 0x02000000,0x02020202,0x38440202,0x00000000,0x20000000,0x2438207f,0x18203824,0x00000000, - 0x22000000,0x22227f22,0x3c020222,0x00000000,0x3e000000,0x087f0810,0x38040404,0x00000000, - - 0x02000000,0x017a023f,0x79050101,0x00000000,0x02000000,0x3a02023f,0x1c204046,0x00000000, - 0x00000000,0x40201f00,0x1c204040,0x00000000,0x3f000000,0x02040810,0x38040202,0x00000000, - 0x02000000,0x020e3202,0x3e010101,0x00000000,0x02000000,0x2102422f,0x18246439,0x00000000, - 0x00000000,0x01014139,0x72090101,0x00000000,0x12000000,0x4d563e12,0x32555569,0x00000000, - 0x02000000,0x42463a07,0x324a4a73,0x00000000,0x00000000,0x49494a3c,0x26494949,0x00000000, - 0x21000000,0x2121217d,0x19256539,0x00000000,0x07000000,0x21611202,0x0c122121,0x00000000, - 0x1e000000,0x08040808,0x0c515252,0x00000000,0x00000000,0x11120a04,0x40402021,0x00000000, - 0x7d000000,0x21217d21,0x19256539,0x00000000,0x08000000,0x083f083f,0x0629190e,0x00000000, - - 0x0e000000,0x3e282808,0x10262969,0x00000000,0x04000000,0x4624041f,0x38464505,0x00000000, - 0x12000000,0x55563e12,0x264d4d55,0x00000000,0x04000000,0x3e04043e,0x38440404,0x00000000, - 0x12000000,0x42573a12,0x04042442,0x00000000,0x10000000,0x5151533d,0x08103c51,0x00000000, - 0x10000000,0x10107010,0x0e51311e,0x00000000,0x18000000,0x463a0222,0x1c204040,0x00000000, - 0x42000000,0x44424242,0x18204040,0x00000000,0x3e000000,0x221c0810,0x3c524c41,0x00000000, - 0x02000000,0x22261a07,0x42222223,0x00000000,0x3e000000,0x221c0810,0x1c204041,0x00000000, - 0x02000000,0x42463a07,0x32424243,0x00000000,0x08000000,0x196e043f,0x7c020214,0x00000000, - 0x04000000,0x06020204,0x3149494a,0x00000000,0x00000000,0x083e0800,0x2c5a6a3c,0x00000000, - - 0x00000000,0x21110000,0x06012121,0x00000000,0x00000000,0x1c001c00,0x0c102022,0x00000000, - 0x00000000,0x1f000e00,0x310a0408,0x00000000,0x00000000,0x445f2400,0x1625251e,0x00000000, - 0x00000000,0x2a1f1200,0x0212222a,0x00000000,0x00000000,0x2b1d0800,0x04182929,0x00000000, - 0x00000000,0x08380800,0x0629190e,0x00000000,0x52500000,0x22225f22,0x18212122,0x00000000, - 0x54500000,0x107f083f,0x1e010120,0x00000000,0x20000000,0x52540810,0x20100804,0x00000000, - 0x50500000,0x21217d21,0x12212121,0x00000000,0x50500000,0x0000300e,0x3c020000,0x00000000, - 0x58500000,0x10103f08,0x1e010120,0x00000000,0x52000000,0x02020252,0x38440202,0x00000000, - 0x50500000,0x2438207f,0x18203824,0x00000000,0x52500000,0x22227f22,0x3c020222,0x00000000, - - 0x5e500000,0x087f0810,0x38040404,0x00000000,0x52500000,0x017a023f,0x79050101,0x00000000, - 0x52500000,0x3a02023f,0x1c204046,0x00000000,0x50500000,0x40201f00,0x1c204040,0x00000000, - 0x3f000000,0x52540810,0x38040202,0x00000000,0x52500000,0x020e3202,0x3e010101,0x00000000, - 0x51500000,0x21217d21,0x19256539,0x00000000,0x57500000,0x21611202,0x0c122121,0x00000000, - 0x5e500000,0x08040808,0x0c515252,0x00000000,0x50000000,0x11120a54,0x40402021,0x00000000, - 0x51500000,0x217d217d,0x19256539,0x00000000,0x51200000,0x21217d21,0x19256539,0x00000000, - 0xa7400000,0x21611242,0x0c122121,0x00000000,0xae400000,0x08040850,0x0c515252,0x00000000, - 0x40000000,0x11124aa4,0x40402021,0x00000000,0xa1400000,0x217d215d,0x19256539,0x00000000, - - 0x00000000,0x1e000000,0x0c102020,0x00000000,0x00000000,0x4840407f,0x04080828,0x00000000, - 0x20000000,0x17181020,0x10101010,0x00000000,0x08000000,0x41417f08,0x18204040,0x00000000, - 0x00000000,0x0808083e,0x7f080808,0x00000000,0x20000000,0x30307f20,0x20232428,0x00000000, - 0x04000000,0x44447f04,0x30424444,0x00000000,0x08000000,0x08087f08,0x0808087f,0x00000000, - 0x02000000,0x2222223e,0x0c102020,0x00000000,0x02000000,0x21227e02,0x0c102020,0x00000000, - 0x00000000,0x2020203e,0x3e202020,0x00000000,0x22000000,0x22227f22,0x0c102020,0x00000000, - 0x00000000,0x20272007,0x0f102020,0x00000000,0x00000000,0x1020203e,0x43442810,0x00000000, - 0x02000000,0x22223f02,0x3c020212,0x00000000,0x00000000,0x40444242,0x0c102020,0x00000000, - - 0x02000000,0x7946427e,0x1c204040,0x00000000,0x20000000,0x7f10101e,0x0c101010,0x00000000, - 0x00000000,0x40494949,0x1c204040,0x00000000,0x3e000000,0x107f0000,0x04081010,0x00000000, - 0x02000000,0x0e020202,0x02020232,0x00000000,0x10000000,0x10107f10,0x06081010,0x00000000, - 0x00000000,0x0000003e,0x007f0000,0x00000000,0x00000000,0x2620203f,0x47281018,0x00000000, - 0x08000000,0x1820407f,0x0808482f,0x00000000,0x00000000,0x20202020,0x030c1010,0x00000000, - 0x00000000,0x22222202,0x41414242,0x00000000,0x01000000,0x013f0101,0x3e010101,0x00000000, - 0x00000000,0x2020203f,0x06081010,0x00000000,0x00000000,0x11120a04,0x40402021,0x00000000, - 0x08000000,0x2a087f08,0x0849492a,0x00000000,0x00000000,0x2240407f,0x20100814,0x00000000, - - 0x0e000000,0x300e0030,0x38060000,0x00000000,0x08000000,0x24040408,0x7f414222,0x00000000, - 0x20000000,0x30282620,0x07485020,0x00000000,0x00000000,0x3f04043f,0x78040404,0x00000000, - 0x04000000,0x44447f04,0x04040424,0x00000000,0x00000000,0x1010101e,0x7f101010,0x00000000, - 0x00000000,0x3e20203f,0x3f202020,0x00000000,0x1e000000,0x203f0000,0x0c102020,0x00000000, - 0x22000000,0x22222222,0x18202020,0x00000000,0x0a000000,0x0a0a0a0a,0x19294a4a,0x00000000, - 0x02000000,0x02020202,0x0e122202,0x00000000,0x00000000,0x2121213f,0x3f212121,0x00000000, - 0x00000000,0x4041417f,0x18204040,0x00000000,0x00000000,0x3e20203f,0x0e102020,0x00000000, - 0x00000000,0x40404403,0x0f102040,0x00000000,0x00000000,0x203f0000,0x02040414,0x00000000, - - 0x00000000,0x20200000,0x10101618,0x00000000,0x00000000,0x3e080000,0x0c102022,0x00000000, - 0x00000000,0x3e000000,0x3e080808,0x00000000,0x00000000,0x3e100000,0x18121418,0x00000000, - 0x00000000,0x3f040000,0x04041424,0x00000000,0x00000000,0x1c000000,0x3e101010,0x00000000, - 0x00000000,0x3e000000,0x3e203c20,0x00000000,0x54500000,0x44447f04,0x30424444,0x00000000, - 0x58500000,0x08087f08,0x0808087f,0x00000000,0x52500000,0x2222223e,0x0c102020,0x00000000, - 0x52500000,0x21227e02,0x0c102020,0x00000000,0x50500000,0x2020203e,0x3e202020,0x00000000, - 0x52500000,0x22227f22,0x0c102020,0x00000000,0x50500000,0x20270007,0x0f102020,0x00000000, - 0x50500000,0x1020203e,0x43442810,0x00000000,0x2a280000,0x22223f02,0x3c020212,0x00000000, - - 0x50500000,0x20222101,0x06081010,0x00000000,0x52500000,0x7946423e,0x1c204040,0x00000000, - 0x28280000,0x7f10101e,0x0c101010,0x00000000,0x50500000,0x40494909,0x1c204040,0x00000000, - 0x5e500000,0x107f0000,0x04081010,0x00000000,0x52500000,0x0e020202,0x02020232,0x00000000, - 0x50500000,0x22222200,0x41414242,0x00000000,0x51500000,0x013f0101,0x3e010101,0x00000000, - 0x50500000,0x2020203f,0x06081010,0x00000000,0x50000000,0x11120a54,0x40402021,0x00000000, - 0x58500000,0x2a087f08,0x0849492a,0x00000000,0xa0400000,0x22222240,0x41414242,0x00000000, - 0xa1400000,0x013f0141,0x3e010101,0x00000000,0xa0400000,0x2020205f,0x06081010,0x00000000, - 0xa0400000,0x11120a44,0x40402021,0x00000000,0xa8400000,0x2a083f48,0x0849492a,0x00000000, - - 0x00000000,0x0a000000,0x1820202a,0x00000000,0x1c000000,0x22222222,0x1c222222,0x00000000, - 0x08000000,0x0808080c,0x1c080808,0x00000000,0x1c000000,0x10202222,0x3e020408,0x00000000, - 0x1c000000,0x18202222,0x1c222220,0x00000000,0x18000000,0x12121414,0x10103e12,0x00000000, - 0x3e000000,0x1e020202,0x1c222020,0x00000000,0x1c000000,0x1e020222,0x1c222222,0x00000000, - 0x3e000000,0x10202020,0x08080810,0x00000000,0x1c000000,0x1c222222,0x1c222222,0x00000000, - 0x1c000000,0x3c222222,0x1c222020,0x00000000,0x18000000,0x183c3c3c,0x18000018,0x00000000, - 0x3c000000,0x18306666,0x18000018,0x00000000,0x00000000,0x00000000,0x06090906,0x00000000, - 0x00000000,0x3e000000,0x00000000,0x00000000,0x00000000,0x0c000000,0x0000000c,0x00000000, - - 0x00000000,0x22000000,0x00000000,0x00000000,0x427e0000,0x0e0a0a7a,0x00000000,0x00000000, - 0x00000000,0x38000000,0x212f2828,0x0000003f,0x023e0000,0x00020202,0x00000000,0x00000000, - 0x00000000,0x00000000,0x10101010,0x0000001f,0x08000000,0x1c082a1c,0x1c222222,0x00000000, - 0x1c000000,0x1c222222,0x08083e08,0x00000000,0x00000000,0x49497f00,0x6141417f,0x00000000, - 0x00000000,0x00000000,0x06060000,0x00000000,0x00000000,0x22000000,0x22140814,0x00000000, - 0x20200000,0x08081010,0x02020404,0x00000000,0x1c000000,0x22222222,0x2222223e,0x00000000, - 0x1e000000,0x1e222222,0x1e222222,0x00000000,0x1c000000,0x02022222,0x1c222202,0x00000000, - 0x1e000000,0x22222222,0x1e222222,0x00000000,0x3e000000,0x3e020202,0x3e020202,0x00000000, - - 0x3e000000,0x1e020202,0x02020202,0x00000000,0x1c000000,0x02022222,0x1c222232,0x00000000, - 0x22000000,0x3e222222,0x22222222,0x00000000,0x1c000000,0x08080808,0x1c080808,0x00000000, - 0x20000000,0x20202020,0x1c222222,0x00000000,0x22000000,0x060a1222,0x2222120a,0x00000000, - 0x02000000,0x02020202,0x3e020202,0x00000000,0x41000000,0x55636341,0x41494955,0x00000000, - 0x22000000,0x2a262622,0x2232322a,0x00000000,0x1c000000,0x22222222,0x1c222222,0x00000000, - 0x1e000000,0x1e222222,0x02020202,0x00000000,0x1c000000,0x22222222,0x5c263a22,0x00000000, - 0x1e000000,0x1e222222,0x22222212,0x00000000,0x1c000000,0x1c022222,0x1c222220,0x00000000, - 0x3e000000,0x08080808,0x08080808,0x00000000,0x22000000,0x22222222,0x1c222222,0x00000000, - - 0x22000000,0x14222222,0x08081414,0x00000000,0x41000000,0x55554949,0x41416363,0x00000000, - 0x22000000,0x08141422,0x22221414,0x00000000,0x22000000,0x14142222,0x08080808,0x00000000, - 0x3e000000,0x08101020,0x3e020404,0x00000000,0x00000000,0x20201c00,0x3c22223c,0x00000000, - 0x00000000,0x02020202,0x1e22221e,0x00000000,0x00000000,0x02221c00,0x1c220202,0x00000000, - 0x00000000,0x20202020,0x3c22223c,0x00000000,0x00000000,0x221c0000,0x1c22023e,0x00000000, - 0x00000000,0x04040418,0x0404041e,0x00000000,0x00000000,0x22223c00,0x1c22203c,0x00000000, - 0x00000000,0x1e020202,0x22222222,0x00000000,0x00000000,0x00080800,0x08080808,0x00000000, - 0x00000000,0x10001010,0x0c121210,0x00000000,0x02000000,0x0a122202,0x22120a06,0x00000000, - - 0x00000000,0x0808080c,0x08080808,0x00000000,0x00000000,0x49493f00,0x49494949,0x00000000, - 0x00000000,0x22221e00,0x22222222,0x00000000,0x00000000,0x22221c00,0x1c222222,0x00000000, - 0x00000000,0x22221e00,0x0202021e,0x00000000,0x00000000,0x22223c00,0x2020203c,0x00000000, - 0x00000000,0x0c340400,0x04040404,0x00000000,0x00000000,0x02221c00,0x1c22201c,0x00000000, - 0x00000000,0x041e0404,0x18040404,0x00000000,0x00000000,0x22222200,0x3c222222,0x00000000, - 0x00000000,0x22222200,0x08081414,0x00000000,0x00000000,0x49414100,0x22365549,0x00000000, - 0x00000000,0x14224100,0x41221408,0x00000000,0x00000000,0x22222200,0x1c20203c,0x00000000, - 0x00000000,0x20407e00,0x7e040810,0x00000000,0x06000000,0x3e3e1e0e,0x00060e1e,0x00000000, - - 0x00000000,0x00000c0c,0x000c0c00,0x00000000,0x00120000,0x2222221c,0x2222223e,0x00000000, - 0x00120000,0x2222221c,0x1c222222,0x00000000,0x00120000,0x22222222,0x1c222222,0x00000000, - 0x00120000,0x20201c00,0x3c22223c,0x00000000,0x00120000,0x22221c00,0x1c222222,0x00000000, - 0x00120000,0x22222200,0x3c222222,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, -}; - -const unsigned char japanese_normalWidths[256] __attribute__((aligned(4)))= -{ - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, -}; - -const TFont japanese_normalFont= -{ - japanese_normalGlyphs, - japanese_normalWidths, - 0, // All heights are the same - 0, // Character offset, is set to zero - 256, - 8, 16, - 8, 16, - 16, - 1, - 0, // Padding, left blank -}; - \ No newline at end of file diff --git a/source/text_engine.cpp b/source/text_engine.cpp index 088db00..80b18ea 100644 --- a/source/text_engine.cpp +++ b/source/text_engine.cpp @@ -8,8 +8,7 @@ #include "debug_mode.h" #include "button_menu.h" #include "sprite_data.h" -#include "latin_normal.h" -#include "japanese_normal.h" +#include "fonts.h" #include "text_data_table.h" #include "background_engine.h" @@ -59,11 +58,22 @@ static __attribute__((noinline)) const u8 *read_dialogue_text_entry(uint8_t inde return output_buffer; } +// This will have to be changed to be dynamic to support nicknamed Pokemon that are in a different language than the current build. +// Maybe combine Japanese and Latin into one larger font? + +#if PTGB_BUILD_LANGUAGE == 1 + #define BUILD_FONT &japanese_normalFont +#else + #define BUILD_FONT &latin_normalFont +#endif + void init_text_engine() { // Load the TTE // tte_init_se(3, BG_CBB(TEXT_CBB) | BG_SBB(TEXT_SBB) | BG_PRIO(0), 0, CLR_WHITE, 14, &japanese_smallFont, NULL); + + tte_init_chr4c(3, // BG 3 BG_CBB(TEXT_CBB) | BG_SBB(TEXT_SBB), // Charblock 0; screenblock 10 0xF000, // Screen-entry offset @@ -73,7 +83,7 @@ void init_text_engine() 0, // Paper 0), // Special CLR_WHITE, // White text - &japanese_normalFont, // Custom font + BUILD_FONT, // Custom font NULL // Use default chr4 renderer ); tte_init_con(); diff --git a/text_helper/main.py b/text_helper/main.py index 0fc3613..c1d8a12 100755 --- a/text_helper/main.py +++ b/text_helper/main.py @@ -330,6 +330,7 @@ def write_enum_to_header_file(hFile, prefix, dictionary): return num def download_xlsx_file(): + print("Downloading xlsx file") offline = False # ---- Attempt download ---- try: @@ -361,19 +362,19 @@ def download_xlsx_file(): if old_file_path.exists(): if hash_excel(new_file_path) == hash_excel(old_file_path): - print("Downloaded file is identical.") + print("Downloaded file is identical") new_file_path.unlink() if json_file_path.exists(): - print("Skipping parse.\n") + print("Skipping parse\n") sys.exit(0) else: - print("JSON missing - forcing rebuild.") + print("JSON missing - forcing rebuild") else: old_file_path.unlink() new_file_path.rename(old_file_path) else: - print("No cached xlsx - forcing rebuild.") + print("No cached xlsx - forcing rebuild") new_file_path.rename(old_file_path) def transfer_xlsx_to_dict(): @@ -506,9 +507,8 @@ BACKGROUND_PAL_INDEX = 0 CELL_PAL_INDEX = 1 class Font: - def __init__(self, fileName, conditional, numColors, numChars, numCharsX, numCharsY, cellWidth, cellHeight, charWidth, charHeight): + def __init__(self, fileName, numColors, numChars, numCharsX, numCharsY, cellWidth, cellHeight, charWidth, charHeight): self.fileName = fileName - self.conditional = conditional self.numColors = numColors self.numChars = numChars self.numCharsX = numCharsX @@ -525,155 +525,124 @@ class Font: self.charWordTable = [0] * self.numWords self.charWidthTable = [0] * self.numBytes -def build_h(myFont): - with open(fontDir + "/include/" + myFont.fileName + ".h", 'w') as f: +def build_h(): + print("Building font.h") + with open(fontDir + "/include/fonts.h", 'w') as f: f.write(f'''#include "debug_mode.h" #include "pokemon_data.h" -#if {myFont.conditional} +#ifndef __FONTS_H__ +#define __FONTS_H__''') -#ifndef __{myFont.fileName.upper()}__ -#define __{myFont.fileName.upper()}__ - -extern const TFont {myFont.fileName}Font; + for myFont in fonts.values(): + f.write(f'''\n #define {myFont.fileName}GlyphsLen {myFont.numBytes} -extern const unsigned int {myFont.fileName}Glyphs[{myFont.numBytes}]; +#define {myFont.fileName}WidthsLen {myFont.numChars}''') + + f.write(f'\n\nconst unsigned int {myFont.fileName}Glyphs[{myFont.numWords}] __attribute__((aligned(4)))=\n{{\n\t') -#define {myFont.fileName}WidthsLen {myFont.numChars} -extern const unsigned char {myFont.fileName}Widths[{myFont.numChars}]; + for i in range(myFont.numWords): + f.write(f'{myFont.charWordTable[i]:#010x},') + if (i == myFont.numWords - 1): + f.write("\n};\n\n") + elif (i % 64 == 63): + f.write("\n\n\t") + elif (i % 8 == 7): + f.write("\n\t") -#endif + f.write(f'const unsigned char {myFont.fileName}Widths[{myFont.numChars}] __attribute__((aligned(4)))=\n{{\n\t') -#endif -''') - f.close() + for i in range(myFont.numChars): + f.write(f'{myFont.charWidthTable[i]:#04x}, ') + if (i == myFont.numChars - 1): + f.write("\n};\n\n") + elif (i % 128 == 127): + f.write("\n\n\t") + elif (i % 16 == 15): + f.write("\n\t") -def build_c(myFont): - with open(fontDir + "/source/" + myFont.fileName + ".c", 'w') as f: - f.write(f'''typedef struct TFont + f.write(f'''const TFont {myFont.fileName}Font= {{ - const void *data; //!< Character data. - const unsigned char *widths; //!< Width table for vwf. - const unsigned char *heights; //!< Height table for vhf. - unsigned short charOffset; //!< Character offset. - unsigned short charnumChars; //!< Character numChars. - unsigned char charW; //!< Character width (fwf). - unsigned char charH; //!< Character height. - unsigned char cellW; //!< Glyph cell width. - unsigned char cellH; //!< Glyph cell height. - unsigned short cellSize; //!< Cell-size (bytes). - unsigned char bpp; //!< Font bitdepth; - unsigned char extra; //!< Padding. Free to use. -}} TFont;\n -''') - - f.write(f'const unsigned int {myFont.fileName}Glyphs[{myFont.numWords}] __attribute__((aligned(4)))=\n{{\n\t') - - for i in range(myFont.numWords): - f.write(f'{myFont.charWordTable[i]:#010x},') - if (i == myFont.numWords - 1): - f.write("\n};\n\n") - elif (i % 64 == 63): - f.write("\n\n\t") - elif (i % 8 == 7): - f.write("\n\t") - - f.write(f'const unsigned char {myFont.fileName}Widths[{myFont.numChars}] __attribute__((aligned(4)))=\n{{\n\t') - - for i in range(myFont.numChars): - f.write(f'{myFont.charWidthTable[i]:#04x}, ') - if (i == myFont.numChars - 1): - f.write("\n};\n\n") - elif (i % 128 == 127): - f.write("\n\n\t") - elif (i % 16 == 15): - f.write("\n\t") - - f.write(f'''const TFont {myFont.fileName}Font= -{{ - {myFont.fileName}Glyphs, + {myFont.fileName}Glyphs, {myFont.fileName}Widths, 0, // All heights are the same - 0, // Character offset, is set to zero + 0, // Character offset, is set to zero {myFont.numChars}, - {myFont.charWidth}, {myFont.charHeight}, - {myFont.cellWidth}, {myFont.cellHeight}, + {myFont.charWidth}, {myFont.charHeight}, + {myFont.cellWidth}, {myFont.cellHeight}, {myFont.numBytes // myFont.numChars}, - {myFont.bpp}, + {myFont.bpp}, 0, // Padding, left blank -}}; - ''') +}};''') - f.close() + f.write('\n\n#endif') + f.close() -def generate_tables(myFont): - reader = png.Reader(f'{fontDir}/text_helper/fonts/{myFont.fileName}.png') - png_info = reader.read()[3] - palette = png_info.get('palette') - if (palette is None): - print("Error: Image file does not contain a palette") - exit() +def generate_tables(): + print("Generating font tables") + for myFont in fonts.values(): + print(f'\t{myFont.fileName}') + reader = png.Reader(f'{fontDir}/text_helper/fonts/{myFont.fileName}.png') + png_info = reader.read()[3] + palette = png_info.get('palette') + if (palette is None): + print("Error: Image file does not contain a palette") + exit() - width, height, rows, info = reader.read() - pixels = list(rows) + width, height, rows, info = reader.read() + pixels = list(rows) - bitsPerWord = 32 - pixelsPerTileX = 8 - pixelsPerTileY = 8 - tilesPerCharX = myFont.cellWidth // pixelsPerTileX - tilesPerCharY = myFont.cellHeight // pixelsPerTileY - charsPerChartX = myFont.numCharsX - charsPerChartY = myFont.numCharsY + bitsPerWord = 32 + pixelsPerTileX = 8 + pixelsPerTileY = 8 + tilesPerCharX = myFont.cellWidth // pixelsPerTileX + tilesPerCharY = myFont.cellHeight // pixelsPerTileY + charsPerChartX = myFont.numCharsX + charsPerChartY = myFont.numCharsY - globalX = 0 - globalY = 0 - bitTotal = 0 + globalX = 0 + globalY = 0 + bitTotal = 0 - for charY in range(charsPerChartY): - for charX in range(charsPerChartX): - for tileX in range(tilesPerCharX): # Tiles go from top to bottom, then left to right - for tileY in range(tilesPerCharY): - for pixelY in range(pixelsPerTileY): - for pixelX in range(pixelsPerTileX): - - arrayIndex = bitTotal // bitsPerWord - bitIndex = bitTotal % bitsPerWord + for charY in range(charsPerChartY): + for charX in range(charsPerChartX): + for tileX in range(tilesPerCharX): # Tiles go from top to bottom, then left to right + for tileY in range(tilesPerCharY): + for pixelY in range(pixelsPerTileY): + for pixelX in range(pixelsPerTileX): + + arrayIndex = bitTotal // bitsPerWord + bitIndex = bitTotal % bitsPerWord - globalX = pixelX + (tileX * pixelsPerTileX) + (charX * tilesPerCharX * pixelsPerTileX) - globalY = pixelY + (tileY * pixelsPerTileY) + (charY * tilesPerCharY * pixelsPerTileY) + globalX = pixelX + (tileX * pixelsPerTileX) + (charX * tilesPerCharX * pixelsPerTileX) + globalY = pixelY + (tileY * pixelsPerTileY) + (charY * tilesPerCharY * pixelsPerTileY) - val = (pixels[globalY][globalX] - 1) - if val < 0: - val = 0 - val &= myFont.bpp - myFont.charWordTable[arrayIndex] |= val << bitIndex + val = (pixels[globalY][globalX] - 1) + if val < 0: + val = 0 + val &= myFont.bpp + myFont.charWordTable[arrayIndex] |= val << bitIndex - #print(f'globalX: {globalX}, globalY: {globalY}, arrayIndex:{arrayIndex}, bitIndex:{bitIndex}, val:{val}') - bitTotal += myFont.bpp - - #print(f'{charX, charY}') + #print(f'globalX: {globalX}, globalY: {globalY}, arrayIndex:{arrayIndex}, bitIndex:{bitIndex}, val:{val}') + bitTotal += myFont.bpp + + #print(f'{charX, charY}') - myFont.charWidthTable[(charY * charsPerChartX) + charX] = (tilesPerCharX * pixelsPerTileX) - for x in range(tilesPerCharX * pixelsPerTileX): - globalX = x + (charX * tilesPerCharX * pixelsPerTileX) - globalY = 0 + (charY * tilesPerCharY * pixelsPerTileY) - #print(f'x: {globalX}, y: {globalY}') - if (pixels[globalY][globalX] == BACKGROUND_PAL_INDEX): - myFont.charWidthTable[(charY * charsPerChartX) + charX] = x - break - -def generate_font(): - for font in fonts.values(): - generate_tables(font) - build_h(font) - build_c(font) + myFont.charWidthTable[(charY * charsPerChartX) + charX] = (tilesPerCharX * pixelsPerTileX) + for x in range(tilesPerCharX * pixelsPerTileX): + globalX = x + (charX * tilesPerCharX * pixelsPerTileX) + globalY = 0 + (charY * tilesPerCharY * pixelsPerTileY) + #print(f'x: {globalX}, y: {globalY}') + if (pixels[globalY][globalX] == BACKGROUND_PAL_INDEX): + myFont.charWidthTable[(charY * charsPerChartX) + charX] = x + break mainDict = {} textSections = [] fonts = { - "International": Font("latin_normal", "PTGB_BUILD_LANGUAGE != 1", 1, 256, 16, 16, 16, 16, 16, 14), - "Japanese": Font("japanese_normal", "PTGB_BUILD_LANGUAGE == 1", 1, 256, 16, 16, 8, 16, 8, 16), + "International": Font("latin_normal", 1, 256, 16, 16, 16, 16, 16, 14), + "Japanese": Font("japanese_normal", 1, 256, 16, 16, 8, 16, 8, 16), } charArrays = { "International": { @@ -724,8 +693,8 @@ charConversionList = [ # Main print("Running text_helper:") -print("\tGenerating font") -generate_font() +generate_tables() +build_h() download_xlsx_file() transfer_xlsx_to_dict() generate_header_file()