diff --git a/.gitignore b/.gitignore index 371a6c5..55d9a35 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ include/translated_text.h source/translated_text.cpp text_helper/output.json text_helper/text.xlsx +include/latin_normal.h +source/latin_normal.c diff --git a/font_helper/main.py b/font_helper/main.py new file mode 100644 index 0000000..8265056 --- /dev/null +++ b/font_helper/main.py @@ -0,0 +1,160 @@ +import os +import math +from PIL import Image +import numpy as np + +# THIS PROGRAM ASSUMES THAT THE FIRST TWO COLORS IN THE PALETTE ARE THE BACKGROUND AND CELL BACKGROUND! + +dir = os.curdir +BACKGROUND_PAL_INDEX = 0 +CELL_PAL_INDEX = 1 + +class Font: + def __init__(self, fileName, numColors, numChars, numCharsX, numCharsY, cellWidth, cellHeight): + self.fileName = fileName + self.numColors = numColors + self.numChars = numChars + self.numCharsX = numCharsX + self.numCharsY = numCharsY + self.cellWidth = cellWidth + self.cellHeight = cellHeight + + self.bpp = int(math.log(numColors, 2)) + 1 + self.numWords = self.numChars * self.cellWidth * self.cellHeight * self.bpp // (8 * 4) + self.numBytes = self.numWords * 4 + + self.charWordTable = [0] * self.numWords + self.charWidthTable = [0] * self.numBytes + + +def build_h(myFont): + with open(dir + "/include/" + myFont.fileName + ".h", 'w') as f: + f.write(f''' +#ifndef __{myFont.fileName.upper()}__ +#define __{myFont.fileName.upper()}__ + +extern const TFont {myFont.fileName}Font; + +#define {myFont.fileName}GlyphsLen {myFont.numBytes} +extern const unsigned int {myFont.fileName}Glyphs[{myFont.numBytes}]; + +#define {myFont.fileName}WidthsLen {myFont.numChars} +extern const unsigned char {myFont.fileName}Widths[{myFont.numChars}]; + +#endif +''') + f.close() + +def build_c(myFont): + with open(dir + "/source/" + myFont.fileName + ".c", 'w') as f: + f.write(f'''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;\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}Widths, + 0, // All heights are the same + 0, // Character offset, is set to zero + {myFont.numChars}, + {myFont.cellWidth}, {myFont.cellHeight}, + {myFont.cellWidth}, {myFont.cellHeight}, + {myFont.numBytes // myFont.numChars}, + {myFont.bpp}, + 0, // Padding, left blank +}}; + ''') + + f.close() + +def generate_tables(myFont): + img = Image.open(f'{dir}/graphics/{myFont.fileName}.png') + if (img.mode != "P"): + print("Error: Image file does not contain a palette") + exit() + pixels = img.load() + + 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 + + for charY in range(charsPerChartY): + for charX in range(charsPerChartX): + for tileY in range(tilesPerCharY): + for tileX in range(tilesPerCharX): + 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) + + val = (pixels[globalX, globalY] - 2) & ((1 << myFont.bpp) - 1) + myFont.charWordTable[arrayIndex] |= val << bitIndex + + #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[globalX, globalY] == BACKGROUND_PAL_INDEX): + myFont.charWidthTable[(charY * charsPerChartX) + charX] = x + break + +# Main: +latin_normal = Font("latin_normal", 1, 256, 16, 16, 16, 16) +generate_tables(latin_normal) +build_h(latin_normal) +build_c(latin_normal) + diff --git a/graphics/latin_normal.png b/graphics/latin_normal.png new file mode 100644 index 0000000..e3f323b Binary files /dev/null and b/graphics/latin_normal.png differ diff --git a/graphics/unused graphics/latin_normal.png b/graphics/unused graphics/latin_normal.png deleted file mode 100644 index 774a05c..0000000 Binary files a/graphics/unused graphics/latin_normal.png and /dev/null differ diff --git a/graphics/unused graphics/latin_short.png b/graphics/unused graphics/latin_short.png index 75ec62c..52e40df 100644 Binary files a/graphics/unused graphics/latin_short.png and b/graphics/unused graphics/latin_short.png differ diff --git a/include/latin_short.h b/include/latin_short.h deleted file mode 100644 index 6e61434..0000000 --- a/include/latin_short.h +++ /dev/null @@ -1,21 +0,0 @@ -#include "debug_mode.h" -#include "pokemon_data.h" - -#if PTGB_BUILD_LANGUAGE != JPN_ID - -//{{BLOCK(latin_short) - -#ifndef __LATIN_SHORT__ -#define __LATIN_SHORT__ - -extern const TFont latin_shortFont; - -#define latin_shortGlyphsLen 4096 -extern const unsigned int latin_shortGlyphs[1024]; -#define BUILD_FONT &latin_shortFont - -#endif // __LATIN_SHORT__ - -//}}BLOCK(latin_short) - -#endif \ No newline at end of file diff --git a/source/japanese_small.s b/source/japanese_small.s deleted file mode 100644 index 3238a8c..0000000 --- a/source/japanese_small.s +++ /dev/null @@ -1,163 +0,0 @@ - -@{{BLOCK(japanese_small) - - .section .rodata - .align 2 - .global japanese_smallFont -japanese_smallFont: - .word japanese_smallGlyphs, 0, 0 - .hword 0, 256 - .byte 8, 10 - .byte 8, 16 - .hword 16 - .byte 1, 0 - - .section .rodata - .align 2 - .global japanese_smallGlyphs @ 4096 unsigned chars -japanese_smallGlyphs: - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x3F040000,0x49553E04,0x00000026,0x00000000 - .word 0x21000000,0x0A414141,0x00000004,0x00000000,0x001E0000,0x1020201E,0x0000000C,0x00000000 - .word 0x001E0000,0x120C101F,0x00000061,0x00000000,0x5F440000,0x45453E04,0x00000026,0x00000000 - .word 0x4F220000,0x10111252,0x0000000C,0x00000000,0x3F080000,0x01107E08,0x0000003E,0x00000000 - .word 0x08100000,0x08040204,0x00000010,0x00000000,0x79200000,0x21212121,0x00000012,0x00000000 - .word 0x1F000000,0x01000020,0x0000003E,0x00000000,0x7F080000,0x01013E10,0x0000003E,0x00000000 - .word 0x02020000,0x42420202,0x0000003C,0x00000000,0x7F200000,0x203C223C,0x00000018,0x00000000 - .word 0x22220000,0x0212227F,0x0000003C,0x00000000,0x081E0000,0x020C3F04,0x0000001C,0x00000000 - - .word 0x3F040000,0x09027A02,0x00000071,0x00000000,0x3F040000,0x40423E02,0x00000038,0x00000000 - .word 0x3F000000,0x20404040,0x0000001C,0x00000000,0x307F0000,0x08040408,0x00000030,0x00000000 - .word 0x34040000,0x0101010E,0x0000007E,0x00000000,0x4F240000,0x623C2102,0x0000001C,0x00000000 - .word 0x01790000,0x05050101,0x00000079,0x00000000,0x12120000,0x55654B3E,0x00000032,0x00000000 - .word 0x37040000,0x5566444C,0x00000074,0x00000000,0x2A1C0000,0x49494949,0x00000026,0x00000000 - .word 0x79210000,0x65392121,0x00000019,0x00000000,0x240F0000,0x11312262,0x0000000E,0x00000000 - .word 0x101C0000,0x51511208,0x0000000C,0x00000000,0x04000000,0x4020110A,0x00000000,0x00000000 - .word 0x21790000,0x65392179,0x00000019,0x00000000,0x207C0000,0x623C207C,0x0000003C,0x00000000 - - .word 0x280E0000,0x25653E28,0x00000012,0x00000000,0x5F440000,0x46450506,0x0000003C,0x00000000 - .word 0x1A120000,0x4D495536,0x00000032,0x00000000,0x1F040000,0x44041F04,0x00000038,0x00000000 - .word 0x3F120000,0x04324252,0x00000004,0x00000000,0x3D080000,0x3C515153,0x00000008,0x00000000 - .word 0x38080000,0x093E0808,0x00000006,0x00000000,0x011C0000,0x2020231D,0x0000001E,0x00000000 - .word 0x22220000,0x10202222,0x0000000C,0x00000000,0x081E0000,0x524C413E,0x0000003C,0x00000000 - .word 0x37040000,0x2526444C,0x00000044,0x00000000,0x183E0000,0x4040423C,0x00000038,0x00000000 - .word 0x37040000,0x4546444C,0x00000024,0x00000000,0x3E040000,0x04143A0C,0x00000038,0x00000000 - .word 0x04040000,0x11120E04,0x00000061,0x00000000,0x04000000,0x351E143F,0x0000002E,0x00000000 - - .word 0x00000000,0x0A212111,0x00000004,0x00000000,0x1E000000,0x10201E00,0x0000000C,0x00000000 - .word 0x0E000000,0x1E081F00,0x00000031,0x00000000,0x24000000,0x251E042F,0x00000016,0x00000000 - .word 0x0A000000,0x14222B1E,0x00000004,0x00000000,0x08000000,0x1C292B1D,0x00000008,0x00000000 - .word 0x08000000,0x190E0818,0x0000000E,0x00000000,0x2F025050,0x10115252,0x0000000C,0x00000000 - .word 0x3F085050,0x01107E08,0x0000003E,0x00000000,0x08100000,0x08045254,0x00000010,0x00000000 - .word 0x79205050,0x21212121,0x00000012,0x00000000,0x1F005050,0x01000020,0x0000003E,0x00000000 - .word 0x7F085050,0x01013E10,0x0000003E,0x00000000,0x52020000,0x42420252,0x0000003C,0x00000000 - .word 0x7F205050,0x203C223C,0x00000018,0x00000000,0x22225050,0x0212227F,0x0000003C,0x00000000 - - .word 0x080E5050,0x020C3F04,0x0000001C,0x00000000,0x3F045050,0x09027A02,0x00000071,0x00000000 - .word 0x3F045050,0x40423E02,0x00000038,0x00000000,0x3F005050,0x20404040,0x0000001C,0x00000000 - .word 0x307F5050,0x08040408,0x00000030,0x00000000,0x34045050,0x0101010E,0x0000007E,0x00000000 - .word 0x79215050,0x65392121,0x00000019,0x00000000,0x240F5050,0x11312262,0x0000000E,0x00000000 - .word 0x100C5050,0x51511208,0x0000000C,0x00000000,0x54500000,0x4020110A,0x00000000,0x00000000 - .word 0x21795050,0x65392179,0x00000019,0x00000000,0x79216060,0x65392121,0x00000019,0x00000000 - .word 0x240F6060,0x11312262,0x0000000E,0x00000000,0x101C6060,0x51511208,0x0000000C,0x00000000 - .word 0x34300000,0x4020110A,0x00000000,0x00000000,0x21396060,0x65392179,0x00000019,0x00000000 - - .word 0x00000000,0x0810100F,0x00000006,0x00000000,0x407F0000,0x08083848,0x00000006,0x00000000 - .word 0x10200000,0x08080B0C,0x00000008,0x00000000,0x7F080000,0x20404141,0x00000018,0x00000000 - .word 0x3E000000,0x08080808,0x0000007F,0x00000000,0x7F100000,0x11121418,0x00000018,0x00000000 - .word 0x7E040000,0x42444444,0x00000031,0x00000000,0x7F080000,0x087F0808,0x00000008,0x00000000 - .word 0x223E0000,0x10202021,0x0000000E,0x00000000,0x7E020000,0x10202122,0x0000000C,0x00000000 - .word 0x203F0000,0x20202020,0x0000003F,0x00000000,0x7F220000,0x20202222,0x0000001C,0x00000000 - .word 0x400E0000,0x2040404E,0x0000001E,0x00000000,0x203F0000,0x24181020,0x00000043,0x00000000 - .word 0x7F020000,0x02022242,0x0000003C,0x00000000,0x41410000,0x10202042,0x0000000C,0x00000000 - - .word 0x427E0000,0x2040714E,0x0000001C,0x00000000,0x1E300000,0x08107F10,0x00000006,0x00000000 - .word 0x4A4A0000,0x2040404A,0x0000001C,0x00000000,0x003E0000,0x1010107F,0x0000000C,0x00000000 - .word 0x04040000,0x0404443C,0x00000004,0x00000000,0x7F100000,0x08101010,0x00000006,0x00000000 - .word 0x3E000000,0x00000000,0x0000007F,0x00000000,0x203F0000,0x14081420,0x00000023,0x00000000 - .word 0x7F080000,0x4B2C1820,0x00000008,0x00000000,0x20200000,0x0C101020,0x00000003,0x00000000 - .word 0x12000000,0x41422222,0x00000041,0x00000000,0x31010000,0x0101010F,0x0000007E,0x00000000 - .word 0x407F0000,0x10202040,0x0000000C,0x00000000,0x04000000,0x4020110A,0x00000000,0x00000000 - .word 0x7F080000,0x4A4A2A08,0x00000049,0x00000000,0x407F0000,0x08142240,0x00000010,0x00000000 - - .word 0x001E0000,0x03001C02,0x0000003C,0x00000000,0x04040000,0x41222204,0x0000007F,0x00000000 - .word 0x24200000,0x4C301028,0x00000003,0x00000000,0x043F0000,0x04047F04,0x00000078,0x00000000 - .word 0x7F040000,0x04142444,0x00000004,0x00000000,0x101E0000,0x7F101010,0x00000000,0x00000000 - .word 0x407F0000,0x40407E40,0x0000007F,0x00000000,0x003E0000,0x2040407F,0x0000001C,0x00000000 - .word 0x22220000,0x10202222,0x0000000C,0x00000000,0x0A0A0000,0x4A0A0A0A,0x00000039,0x00000000 - .word 0x02020000,0x1A224202,0x00000006,0x00000000,0x417F0000,0x7F414141,0x00000000,0x00000000 - .word 0x417F0000,0x20404041,0x0000001C,0x00000000,0x407F0000,0x20407E40,0x0000001E,0x00000000 - .word 0x40470000,0x20404040,0x0000001F,0x00000000,0x00000000,0x0C14101F,0x00000002,0x00000000 - - .word 0x00000000,0x080E0810,0x00000008,0x00000000,0x00000000,0x08111F04,0x00000006,0x00000000 - .word 0x00000000,0x04040E00,0x0000001F,0x00000000,0x00000000,0x0A0C1F08,0x00000009,0x00000000 - .word 0x00000000,0x0A121F02,0x00000002,0x00000000,0x00000000,0x08080E00,0x0000001F,0x00000000 - .word 0x00000000,0x080F080F,0x0000000F,0x00000000,0x7E045050,0x42444444,0x00000031,0x00000000 - .word 0x7F085050,0x087F0808,0x00000008,0x00000000,0x223E5050,0x10202021,0x0000000E,0x00000000 - .word 0x7E025050,0x10202122,0x0000000C,0x00000000,0x203F5050,0x20202020,0x0000003F,0x00000000 - .word 0x7F225050,0x20202222,0x0000001C,0x00000000,0x400E5050,0x2040404E,0x0000001E,0x00000000 - .word 0x203F5050,0x24181020,0x00000043,0x00000000,0x7F025050,0x02022242,0x0000003C,0x00000000 - - .word 0x41015050,0x10202042,0x0000000C,0x00000000,0x427E5050,0x2040714E,0x0000001C,0x00000000 - .word 0x1E305050,0x08107F10,0x00000006,0x00000000,0x4A0A5050,0x2040404A,0x0000001C,0x00000000 - .word 0x003E5050,0x1010107F,0x0000000C,0x00000000,0x04045050,0x0404443C,0x00000004,0x00000000 - .word 0x12005050,0x41422222,0x00000041,0x00000000,0x31015050,0x0101010F,0x0000007E,0x00000000 - .word 0x407F5050,0x10202040,0x0000000C,0x00000000,0x54500000,0x4020110A,0x00000000,0x00000000 - .word 0x7F085050,0x4A4A2A08,0x00000049,0x00000000,0x12606000,0x41422222,0x00000041,0x00000000 - .word 0x19616000,0x01010107,0x0000007E,0x00000000,0x7F606000,0x10202040,0x0000000C,0x00000000 - .word 0x34300000,0x4020110A,0x00000000,0x00000000,0x7F686000,0x4A4A2A08,0x00000049,0x00000000 - - .word 0x00000000,0x08101515,0x00000006,0x00000000,0x1C000000,0x26636332,0x0000001C,0x00000000 - .word 0x18000000,0x1818181C,0x0000007E,0x00000000,0x3E000000,0x071E7063,0x0000007F,0x00000000 - .word 0x7E000000,0x63601C30,0x0000003E,0x00000000,0x38000000,0x7F33363C,0x00000030,0x00000000 - .word 0x3F000000,0x63603F03,0x0000003E,0x00000000,0x3E000000,0x63633F03,0x0000003E,0x00000000 - .word 0x7F000000,0x0C183063,0x0000000C,0x00000000,0x3E000000,0x63633E63,0x0000003E,0x00000000 - .word 0x3E000000,0x607E6363,0x0000003E,0x00000000,0x3C3C0000,0x1800183C,0x00000018,0x00000000 - .word 0x673E0000,0x18001873,0x00000018,0x00000000,0x00000000,0x0A0E0000,0x0000000E,0x00000000 - .word 0x00000000,0x00003F00,0x00000000,0x00000000,0x00000000,0x00181800,0x00000000,0x00000000 - - .word 0x00000000,0x00220000,0x00000000,0x00000000,0x447C0000,0x1C141474,0x00000000,0x00000000 - .word 0x1C000000,0x11171414,0x0000001F,0x00000000,0x10700000,0x00001010,0x00000000,0x00000000 - .word 0x00000000,0x04040400,0x00000007,0x00000000,0x2A1C0000,0x22221C08,0x0000001C,0x00000000 - .word 0x221C0000,0x3E081C22,0x00000808,0x00000000,0x497F0000,0x41417F49,0x00000061,0x00000000 - .word 0x00000000,0x0C0C0000,0x00000000,0x00000000,0x22000000,0x22140814,0x00000000,0x00000000 - .word 0x20400000,0x02040810,0x00000001,0x00000000,0x361C0000,0x637F6363,0x00000063,0x00000000 - .word 0x633F0000,0x63633F63,0x0000003F,0x00000000,0x673E0000,0x67030303,0x0000003E,0x00000000 - .word 0x331F0000,0x33636363,0x0000001F,0x00000000,0x037F0000,0x03033F03,0x0000007F,0x00000000 - - .word 0x037F0000,0x03033F03,0x00000003,0x00000000,0x077E0000,0x67637303,0x0000007E,0x00000000 - .word 0x63630000,0x63637F63,0x00000063,0x00000000,0x187E0000,0x18181818,0x0000007E,0x00000000 - .word 0x60600000,0x63636060,0x0000003E,0x00000000,0x63630000,0x63331F33,0x00000063,0x00000000 - .word 0x06060000,0x06060606,0x0000007E,0x00000000,0x63410000,0x636B7F77,0x00000063,0x00000000 - .word 0x67630000,0x737B7F6F,0x00000063,0x00000000,0x633E0000,0x63636363,0x0000003E,0x00000000 - .word 0x633F0000,0x033F6363,0x00000003,0x00000000,0x633E0000,0x3B636363,0x0000006E,0x00000000 - .word 0x633F0000,0x3B1F7363,0x00000073,0x00000000,0x331E0000,0x63603E03,0x0000003E,0x00000000 - .word 0x187E0000,0x18181818,0x00000018,0x00000000,0x63630000,0x63636363,0x0000003E,0x00000000 - - .word 0x63630000,0x1C3E7763,0x00000008,0x00000000,0x63630000,0x777F7F6B,0x00000063,0x00000000 - .word 0x63630000,0x63361C36,0x00000063,0x00000000,0x66660000,0x18183C66,0x00000018,0x00000000 - .word 0x707F0000,0x070E1C38,0x0000007F,0x00000000,0x00000000,0x667E603C,0x0000007C,0x00000000 - .word 0x06000000,0x66663E06,0x0000003E,0x00000000,0x00000000,0x6606663C,0x0000003C,0x00000000 - .word 0x60000000,0x66667C60,0x0000007C,0x00000000,0x00000000,0x067E663C,0x0000003C,0x00000000 - .word 0x38000000,0x0C0C3E0C,0x0000000C,0x00000000,0x7C000000,0x607C6666,0x0000003E,0x00000000 - .word 0x06000000,0x66663E06,0x00000066,0x00000000,0x18000000,0x18181800,0x00000018,0x00000000 - .word 0x30000000,0x33303000,0x0000001E,0x00000000,0x06000000,0x361E3666,0x00000066,0x00000000 - - .word 0x0E000000,0x0C0C0C0C,0x0000000C,0x00000000,0x00000000,0x6B6B6B3F,0x00000063,0x00000000 - .word 0x00000000,0x6666663E,0x00000066,0x00000000,0x00000000,0x6666663C,0x0000003C,0x00000000 - .word 0x00000000,0x3E66663C,0x00000006,0x00000000,0x00000000,0x7C66663C,0x00000060,0x00000000 - .word 0x00000000,0x0C0C1C6C,0x0000000C,0x00000000,0x00000000,0x303E063C,0x0000001E,0x00000000 - .word 0x0C000000,0x0C0C0C1E,0x0000001C,0x00000000,0x00000000,0x66666666,0x0000007C,0x00000000 - .word 0x00000000,0x36666666,0x0000001C,0x00000000,0x00000000,0x6B6B6B63,0x00000037,0x00000000 - .word 0x00000000,0x361C3663,0x00000063,0x00000000,0x00000000,0x607C6666,0x0000003C,0x00000000 - .word 0x00000000,0x0C18307E,0x0000007E,0x00000000,0x0E060000,0x0E1E3E1E,0x00000006,0x00000000 - - .word 0x00000000,0x08000008,0x00000000,0x00000000,0x00660000,0x7F63361C,0x00000063,0x00000000 - .word 0x00660000,0x6363633E,0x0000003E,0x00000000,0x00660000,0x63636363,0x0000003E,0x00000000 - .word 0x00660000,0x667E603C,0x0000007C,0x00000000,0x00660000,0x6666663C,0x0000003C,0x00000000 - .word 0x00660000,0x66666666,0x0000007C,0x00000000,0xFFFFFE7C,0xC68339EF,0x0000007C,0x00000000 - .word 0x01010000,0x00010101,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - -@}}BLOCK(japanese_small) diff --git a/source/latin_short.s b/source/latin_short.s deleted file mode 100644 index 8bdf1bb..0000000 --- a/source/latin_short.s +++ /dev/null @@ -1,163 +0,0 @@ - -@{{BLOCK(latin_short) - - .section .rodata - .align 2 - .global latin_shortFont -latin_shortFont: - .word latin_shortGlyphs, 0, 0 - .hword 0, 256 - .byte 6, 10 - .byte 8, 16 - .hword 16 - .byte 1, 0 - - .section .rodata - .align 2 - .global latin_shortGlyphs @ 4096 unsigned chars -latin_shortGlyphs: - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x0E000806,0x111F1111,0x00000011,0x00000000 - .word 0x0E00020C,0x111F1111,0x00000011,0x00000000,0x0E000A04,0x111F1111,0x00000011,0x00000000 - .word 0x01110E00,0x040E1101,0x00000002,0x00000000,0x1F000806,0x01010F01,0x0000001F,0x00000000 - .word 0x1F00020C,0x01010F01,0x0000001F,0x00000000,0x1F000A04,0x01010F01,0x0000001F,0x00000000 - .word 0x1F000011,0x01010F01,0x0000001F,0x00000000,0x1F000806,0x04040404,0x0000001F,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x1F000A04,0x04040404,0x0000001F,0x00000000 - .word 0x1F000011,0x04040404,0x0000001F,0x00000000,0x0E000806,0x11111111,0x0000000E,0x00000000 - .word 0x0E00020C,0x11111111,0x0000000E,0x00000000,0x0E000A04,0x11111111,0x0000000E,0x00000000 - - .word 0x76000000,0x19117119,0x00000076,0x00000000,0x11000806,0x11111111,0x0000000E,0x00000000 - .word 0x1100020C,0x11111111,0x0000000E,0x00000000,0x11000A04,0x11111111,0x0000000E,0x00000000 - .word 0x11001926,0x11191513,0x00000011,0x00000000,0x09090700,0x09110907,0x00000001,0x00000000 - .word 0x00080600,0x1911111E,0x00000016,0x00000000,0x00020C00,0x1911111E,0x00000016,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x110E0000,0x040E1101,0x00000002,0x00000000 - .word 0x00080600,0x011F110E,0x0000001E,0x00000000,0x00020C00,0x011F110E,0x0000001E,0x00000000 - .word 0x000A0400,0x011F110E,0x0000001E,0x00000000,0x00001100,0x011F110E,0x0000001E,0x00000000 - .word 0x00080600,0x04040404,0x00000004,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - - .word 0x000A0400,0x04040404,0x00000004,0x00000000,0x00001100,0x04040404,0x00000004,0x00000000 - .word 0x00080600,0x1111110E,0x0000000E,0x00000000,0x00020C00,0x1111110E,0x0000000E,0x00000000 - .word 0x000A0400,0x1111110E,0x0000000E,0x00000000,0x00000000,0x09794936,0x00000076,0x00000000 - .word 0x00080600,0x09090909,0x00000016,0x00000000,0x00020C00,0x09090909,0x00000016,0x00000000 - .word 0x000A0400,0x09090909,0x00000016,0x00000000,0x00192600,0x1212120E,0x00000012,0x00000000 - .word 0x1111110E,0x0000000E,0x00000000,0x00000000,0x0909090E,0x00000016,0x00000000,0x00000000 - .word 0x212F69A6,0x0000002E,0x00000000,0x00000000,0x08141408,0x12121428,0x0000002C,0x00000000 - .word 0x00000000,0x083E0808,0x00000008,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x11010100,0x47A1A111,0x00000000,0x00000000,0x013E0000,0x00003E01,0x00000000,0x00000000 - .word 0x00060600,0x04060600,0x00000002,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - - .word 0x1111111F,0x11111111,0x0000001F,0x00000000,0x04000404,0x11111106,0x0000000E,0x00000000 - .word 0x04000404,0x04040404,0x00000004,0x00000000,0x57555507,0x50515131,0x00000050,0x00000000 - .word 0x59494F09,0x49696959,0x00000048,0x00000000,0xBF858587,0x28A9A9A9,0x00000038,0x00000000 - .word 0x39021222,0x280A3A2A,0x00000038,0x00000000,0x95951300,0x95959593,0x00000073,0x00000000 - .word 0x8AAA9100,0xAA8A8A8A,0x00000091,0x00000000,0x02040400,0x04020101,0x00000004,0x00000000 - .word 0x1F00020C,0x04040404,0x0000001F,0x00000000,0x15252700,0x74080817,0x00725254,0x00000000 - .word 0x02020204,0x02020202,0x00000004,0x00000000,0x04040402,0x04040404,0x00000002,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x000A0400,0x1911111E,0x00000016,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00020C00,0x04040404,0x00000004,0x00000000 - - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0xFE7C3810,0x7C7C7CFF,0x00000000,0x00000000 - .word 0x7C7C7C00,0x387CFEFF,0x00000010,0x00000000,0xFEFC1810,0x18FCFEFF,0x00000010,0x00000000 - .word 0xFE7E3010,0x307EFEFE,0x00000010,0x00000000,0x00000000,0x00000001,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x010F0906,0x0000000E,0x00000000,0x00000000,0x04081020,0x10080402,0x00000020,0x00000000 - .word 0x10080402,0x04081020,0x00000002,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - - .word 0x09794B35,0x00000071,0x00000000,0x00000000,0x1111110E,0x11111111,0x0000000E,0x00000000 - .word 0x04040604,0x04040404,0x0000000E,0x00000000,0x1011110E,0x01020408,0x0000001F,0x00000000 - .word 0x1010110E,0x1110100C,0x0000000E,0x00000000,0x090A0A0C,0x081F0909,0x00000008,0x00000000 - .word 0x0101011F,0x1110100F,0x0000000E,0x00000000,0x0101110E,0x1111110F,0x0000000E,0x00000000 - .word 0x1010101F,0x04040808,0x00000004,0x00000000,0x1111110E,0x1111110E,0x0000000E,0x00000000 - .word 0x1111110E,0x1110101E,0x0000000E,0x00000000,0x04040404,0x04000404,0x00000004,0x00000000 - .word 0x1111110E,0x0400040C,0x00000004,0x00000000,0x00000000,0x06000000,0x00000006,0x00000000 - .word 0x00000000,0x0000001F,0x00000000,0x00000000,0x00000000,0x00000606,0x00000000,0x00000000 - - .word 0x00000000,0x00000000,0x00150000,0x00000000,0x1B1B0912,0x00000000,0x00000000,0x00000000 - .word 0x09121B1B,0x00000000,0x00000000,0x00000000,0x03030102,0x00000000,0x00000000,0x00000000 - .word 0x01020303,0x00000000,0x00000000,0x00000000,0x04150E04,0x1111110E,0x0000000E,0x00000000 - .word 0x1111110E,0x041F040E,0x00000004,0x00000000,0x1C24241C,0x3E043E04,0x00000004,0x00000000 - .word 0x00000000,0x04060600,0x00000002,0x00000000,0x42000000,0x24181824,0x00000042,0x00000000 - .word 0x08081000,0x02020404,0x00000001,0x00000000,0x11110E00,0x11111F11,0x00000011,0x00000000 - .word 0x11110F00,0x1111110F,0x0000000F,0x00000000,0x01110E00,0x11010101,0x0000000E,0x00000000 - .word 0x11110F00,0x11111111,0x0000000F,0x00000000,0x01011F00,0x0101010F,0x0000001F,0x00000000 - - .word 0x01011F00,0x0101010F,0x00000001,0x00000000,0x11110E00,0x11111901,0x0000000E,0x00000000 - .word 0x11111100,0x1111111F,0x00000011,0x00000000,0x04041F00,0x04040404,0x0000001F,0x00000000 - .word 0x10101000,0x11101010,0x0000000E,0x00000000,0x05091100,0x09050303,0x00000011,0x00000000 - .word 0x01010100,0x01010101,0x0000001F,0x00000000,0x1B1B1100,0x11111515,0x00000011,0x00000000 - .word 0x13131100,0x11191915,0x00000011,0x00000000,0x11110E00,0x11111111,0x0000000E,0x00000000 - .word 0x11110F00,0x01010F11,0x00000001,0x00000000,0x11110E00,0x19171111,0x0000002E,0x00000000 - .word 0x11110F00,0x11090F11,0x00000011,0x00000000,0x01110E00,0x11100806,0x0000000E,0x00000000 - .word 0x04041F00,0x04040404,0x00000004,0x00000000,0x11111100,0x11111111,0x0000000E,0x00000000 - - .word 0x11111100,0x040A0A11,0x00000004,0x00000000,0x15111100,0x1B1B1515,0x00000011,0x00000000 - .word 0x0A111100,0x110A0404,0x00000011,0x00000000,0x0A111100,0x0404040A,0x00000004,0x00000000 - .word 0x08101F00,0x01020404,0x0000001F,0x00000000,0x00000000,0x1911111E,0x00000016,0x00000000 - .word 0x01010100,0x1111110F,0x0000000F,0x00000000,0x00000000,0x1101110E,0x0000000E,0x00000000 - .word 0x10101000,0x1111111E,0x0000001E,0x00000000,0x00000000,0x011F110E,0x0000001E,0x00000000 - .word 0x02020C00,0x0202020F,0x00000002,0x00000000,0x00000000,0x101E111E,0x0000000E,0x00000000 - .word 0x01010100,0x1111110F,0x00000011,0x00000000,0x00000200,0x02020202,0x00000002,0x00000000 - .word 0x00000800,0x09090808,0x00000006,0x00000000,0x01010100,0x05030509,0x00000009,0x00000000 - - .word 0x04040600,0x04040404,0x00000004,0x00000000,0x00000000,0x1515150F,0x00000015,0x00000000 - .word 0x00000000,0x09090907,0x00000009,0x00000000,0x00000000,0x1111110E,0x0000000E,0x00000000 - .word 0x00000000,0x0F11110F,0x00000001,0x00000000,0x00000000,0x1E11111E,0x00000010,0x00000000 - .word 0x00000000,0x0101030D,0x00000001,0x00000000,0x00000000,0x0806010F,0x0000000F,0x00000000 - .word 0x02020000,0x0202020F,0x0000000E,0x00000000,0x00000000,0x09090909,0x00000016,0x00000000 - .word 0x00000000,0x0A0A1111,0x00000004,0x00000000,0x00000000,0x15151515,0x0000000A,0x00000000 - .word 0x00000000,0x0A040A11,0x00000011,0x00000000,0x00000000,0x101E1111,0x0000000F,0x00000000 - .word 0x00000000,0x0204081F,0x0000001F,0x00000000,0x1E0E0602,0x060E1E3E,0x00000002,0x00000000 - - .word 0x06060000,0x06060000,0x00000000,0x00000000,0x0E000011,0x111F1111,0x00000011,0x00000000 - .word 0x0E000011,0x11111111,0x0000000E,0x00000000,0x11000011,0x11111111,0x0000000E,0x00000000 - .word 0x00001100,0x1911111E,0x00000016,0x00000000,0x00001100,0x1111110E,0x0000000E,0x00000000 - .word 0x00001100,0x09090909,0x00000016,0x00000000,0x3F3F3E3C,0x0603392F,0x0000003C,0x00000000 - .word 0x07070301,0x03060407,0x00000001,0x00000000,0x10020702,0x0E041038,0x00000004,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - .word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000 - -@}}BLOCK(latin_short) diff --git a/source/text_engine.cpp b/source/text_engine.cpp index 2a8efb7..01fd39f 100644 --- a/source/text_engine.cpp +++ b/source/text_engine.cpp @@ -8,7 +8,8 @@ #include "debug_mode.h" #include "button_menu.h" #include "sprite_data.h" -#include "latin_short.h" +//#include "latin_short.h" +#include "latin_normal.h" #include "japanese_small.h" #include "text_data_table.h" #include "background_engine.h" @@ -64,16 +65,17 @@ 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 0 - BG_CBB(TEXT_CBB) | BG_SBB(TEXT_SBB), // Charblock 0; screenblock 31 + tte_init_chr4c(3, // BG 3 + BG_CBB(TEXT_CBB) | BG_SBB(TEXT_SBB), // Charblock 0; screenblock 10 0xF000, // Screen-entry offset bytes2word( // Color attributes: - 15, // Text color - 0, // Shadow color + 13, // Text color + 15, // Shadow color 0, // Paper 0), // Special CLR_WHITE, // White text - BUILD_FONT, // Custom font + //&latin_shortFont, // Custom font + &latin_normalFont, // Custom font NULL // Use default chr4 renderer ); tte_init_con(); diff --git a/text_helper/main.py b/text_helper/main.py index 03ef573..8d1481f 100755 --- a/text_helper/main.py +++ b/text_helper/main.py @@ -7,6 +7,9 @@ from collections import defaultdict import sys from pathlib import Path import hashlib +import math +from PIL import Image +import numpy as np class Languages(Enum): Japanese = 0 @@ -21,7 +24,7 @@ FIRST_TRANSLATION_COL_INDEX = 8 BASE_DIR = Path(__file__).resolve().parent # read by default 1st sheet of an excel file -dir = os.curdir + "/text_helper" +textDir = os.curdir + "/text_helper" url = 'https://docs.google.com/spreadsheets/d/14LLs5lLqWasFcssBmJdGXjjYxARAJBa_QUOUhXZt4v8/export?format=xlsx' new_file_path = BASE_DIR / 'new_text.xlsx' @@ -463,7 +466,7 @@ def download_xlsx_file(): def transfer_xlsx_to_dict(): print("\tGetting character arrays") - currSheet = pd.read_excel(dir + "/text.xlsx", sheet_name="Character Arrays", header=None) + currSheet = pd.read_excel(textDir + "/text.xlsx", sheet_name="Character Arrays", header=None) offset = 0 for key, value in charArrays.items(): for r in range(16): @@ -478,7 +481,7 @@ def transfer_xlsx_to_dict(): print("\tGetting string data") - currSheet = pd.read_excel(dir + "/text.xlsx", sheet_name="Translations") + currSheet = pd.read_excel(textDir + "/text.xlsx", sheet_name="Translations") for row in currSheet.iterrows(): currRow = row[1]["Text Section"] @@ -581,11 +584,169 @@ def output_json_file(): outText += str(byte) mainDict[lang.name][section][item]["text"] = outText - with open(dir + '/output.json', 'w') as jsonFile: + with open(textDir + '/output.json', 'w') as jsonFile: jsonFile.write(json.dumps(mainDict)) + +# This is for the font generation +fontDir = os.curdir +BACKGROUND_PAL_INDEX = 0 +CELL_PAL_INDEX = 1 + +class Font: + def __init__(self, fileName, numColors, numChars, numCharsX, numCharsY, cellWidth, cellHeight): + self.fileName = fileName + self.numColors = numColors + self.numChars = numChars + self.numCharsX = numCharsX + self.numCharsY = numCharsY + self.cellWidth = cellWidth + self.cellHeight = cellHeight + + self.bpp = int(math.log(numColors, 2)) + 1 + self.numWords = self.numChars * self.cellWidth * self.cellHeight * self.bpp // (8 * 4) + self.numBytes = self.numWords * 4 + + self.charWordTable = [0] * self.numWords + self.charWidthTable = [0] * self.numBytes + +def build_h(myFont): + with open(fontDir + "/include/" + myFont.fileName + ".h", 'w') as f: + f.write(f''' +#ifndef __{myFont.fileName.upper()}__ +#define __{myFont.fileName.upper()}__ + +extern const TFont {myFont.fileName}Font; + +#define {myFont.fileName}GlyphsLen {myFont.numBytes} +extern const unsigned int {myFont.fileName}Glyphs[{myFont.numBytes}]; + +#define {myFont.fileName}WidthsLen {myFont.numChars} +extern const unsigned char {myFont.fileName}Widths[{myFont.numChars}]; + +#endif +''') + f.close() + +def build_c(myFont): + with open(fontDir + "/source/" + myFont.fileName + ".c", 'w') as f: + f.write(f'''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;\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}Widths, + 0, // All heights are the same + 0, // Character offset, is set to zero + {myFont.numChars}, + {myFont.cellWidth}, {myFont.cellHeight}, + {myFont.cellWidth}, {myFont.cellHeight}, + {myFont.numBytes // myFont.numChars}, + {myFont.bpp}, + 0, // Padding, left blank +}}; + ''') + + f.close() + +def generate_tables(myFont): + img = Image.open(f'{fontDir}/graphics/{myFont.fileName}.png') + if (img.mode != "P"): + print("Error: Image file does not contain a palette") + exit() + pixels = img.load() + + 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 + + for charY in range(charsPerChartY): + for charX in range(charsPerChartX): + for tileY in range(tilesPerCharY): + for tileX in range(tilesPerCharX): + 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) + + val = (pixels[globalX, globalY] - 2) & ((1 << myFont.bpp) - 1) + myFont.charWordTable[arrayIndex] |= val << bitIndex + + #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[globalX, globalY] == BACKGROUND_PAL_INDEX): + myFont.charWidthTable[(charY * charsPerChartX) + charX] = x + break + +def generate_font(): + latin_normal = Font("latin_normal", 1, 256, 16, 16, 16, 16) + generate_tables(latin_normal) + build_h(latin_normal) + build_c(latin_normal) + + + # Main print("Running text_helper:") +print("\tGenerating font") +generate_font() download_xlsx_file() transfer_xlsx_to_dict() generate_header_file()