Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
*.id0
*.id1
*.id2
*.latfont
*.hwlatfont
*.fwlatfont
*.lz
*.map
*.nam
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ clean-assets:
rm -f $(DATA_ASM_SUBDIR)/layouts/layouts.inc $(DATA_ASM_SUBDIR)/layouts/layouts_table.inc
rm -f $(DATA_ASM_SUBDIR)/maps/connections.inc $(DATA_ASM_SUBDIR)/maps/events.inc $(DATA_ASM_SUBDIR)/maps/groups.inc $(DATA_ASM_SUBDIR)/maps/headers.inc
find sound -iname '*.bin' -exec rm {} +
find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' -o -iname '*.rl' -o -iname '*.latfont' -o -iname '*.hwjpnfont' -o -iname '*.fwjpnfont' \) -exec rm {} +
find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' -o -iname '*.rl' -o -iname '*.hwlatfont' -o -iname '*.fwlatfont' -o -iname '*.hwjpnfont' -o -iname '*.fwjpnfont' \) -exec rm {} +
find $(DATA_ASM_SUBDIR)/maps \( -iname 'connections.inc' -o -iname 'events.inc' -o -iname 'header.inc' \) -exec rm {} +

tidy:
Expand Down
Binary file modified graphics/fonts/latin_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions graphics_file_rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $(CASTFORMGFXDIR)/shiny.gbapal: $(CASTFORMGFXDIR)/normal/shiny.gbapal \
$(CASTFORMGFXDIR)/snowy/shiny.gbapal
@cat $^ >$@

$(FONTGFXDIR)/latin_small.latfont: $(FONTGFXDIR)/latin_small.png
$(FONTGFXDIR)/latin_small.hwlatfont: $(FONTGFXDIR)/latin_small.png
$(GFX) $< $@

$(FONTGFXDIR)/japanese_small.fwjpnfont: $(FONTGFXDIR)/japanese_small.png
Expand All @@ -60,19 +60,19 @@ $(FONTGFXDIR)/japanese_small.fwjpnfont: $(FONTGFXDIR)/japanese_small.png
$(FONTGFXDIR)/japanese_tall.fwjpnfont: $(FONTGFXDIR)/japanese_tall.png
$(GFX) $< $@

$(FONTGFXDIR)/latin_normal.latfont: $(FONTGFXDIR)/latin_normal.png
$(FONTGFXDIR)/latin_normal.fwlatfont: $(FONTGFXDIR)/latin_normal.png
$(GFX) $< $@

$(FONTGFXDIR)/japanese_normal.fwjpnfont: $(FONTGFXDIR)/japanese_normal.png
$(GFX) $< $@

$(FONTGFXDIR)/latin_male.latfont: $(FONTGFXDIR)/latin_male.png
$(FONTGFXDIR)/latin_male.fwlatfont: $(FONTGFXDIR)/latin_male.png
$(GFX) $< $@

$(FONTGFXDIR)/japanese_male.fwjpnfont: $(FONTGFXDIR)/japanese_male.png
$(GFX) $< $@

$(FONTGFXDIR)/latin_female.latfont: $(FONTGFXDIR)/latin_female.png
$(FONTGFXDIR)/latin_female.fwlatfont: $(FONTGFXDIR)/latin_female.png
$(GFX) $< $@

$(FONTGFXDIR)/japanese_female.fwjpnfont: $(FONTGFXDIR)/japanese_female.png
Expand Down
10 changes: 5 additions & 5 deletions src/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct

const u8 gKeypadIconTiles[] = INCBIN_U8("graphics/fonts/keypad_icons.4bpp");

static const u16 sFontSmallLatinGlyphs[] = INCBIN_U16("graphics/fonts/latin_small.latfont");
static const u16 sFontSmallLatinGlyphs[] = INCBIN_U16("graphics/fonts/latin_small.hwlatfont");
static const u8 sFontSmallLatinGlyphWidths[] =
{
5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 4, 4, 5,
Expand Down Expand Up @@ -140,7 +140,7 @@ static const u8 sFontSmallLatinGlyphWidths[] =
};
static const u16 sFontSmallJapaneseGlyphs[] = INCBIN_U16("graphics/fonts/japanese_small.fwjpnfont");

static const u16 sFontNormalCopy1LatinGlyphs[] = INCBIN_U16("graphics/fonts/latin_normal.latfont");
static const u16 sFontNormalCopy1LatinGlyphs[] = INCBIN_U16("graphics/fonts/latin_normal.fwlatfont");
static const u8 sFontNormalCopy1LatinGlyphWidths[] =
{
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
Expand Down Expand Up @@ -183,7 +183,7 @@ static const u8 sFontNormalCopy1LatinGlyphWidths[] =
};
static const u16 sFontTallJapaneseGlyphs[] = INCBIN_U16("graphics/fonts/japanese_tall.fwjpnfont");

static const u16 sFontNormalLatinGlyphs[] = INCBIN_U16("graphics/fonts/latin_normal.latfont");
static const u16 sFontNormalLatinGlyphs[] = INCBIN_U16("graphics/fonts/latin_normal.fwlatfont");
static const u8 sFontNormalLatinGlyphWidths[] =
{
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
Expand Down Expand Up @@ -249,7 +249,7 @@ static const u8 sFontNormalJapaneseGlyphWidths[] =
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0
};

static const u16 sFontMaleLatinGlyphs[] = INCBIN_U16("graphics/fonts/latin_male.latfont");
static const u16 sFontMaleLatinGlyphs[] = INCBIN_U16("graphics/fonts/latin_male.fwlatfont");
static const u8 sFontMaleLatinGlyphWidths[] =
{
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
Expand Down Expand Up @@ -315,7 +315,7 @@ static const u8 sFontMaleJapaneseGlyphWidths[] =
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0
};

static const u16 sFontFemaleLatinGlyphs[] = INCBIN_U16("graphics/fonts/latin_female.latfont");
static const u16 sFontFemaleLatinGlyphs[] = INCBIN_U16("graphics/fonts/latin_female.fwlatfont");
static const u8 sFontFemaleLatinGlyphWidths[] =
{
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
Expand Down
107 changes: 101 additions & 6 deletions tools/gbagfx/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,53 @@ unsigned char gFontPalette[][3] = {
{0xFF, 0xFF, 0xFF} // box (white)
};

static void ConvertFromLatinFont(unsigned char *src, unsigned char *dest, unsigned int numRows)
static void ConvertFromHalfWidthLatinFont(unsigned char *src, unsigned char *dest, unsigned int numRows)
{
unsigned int srcPixelsOffset = 0;

for (unsigned int row = 0; row < numRows; row++) {
for (unsigned int column = 0; column < 32; column++) {
for (unsigned int glyphTile = 0; glyphTile < 2; glyphTile++) {
unsigned int pixelsX = (column * 8);

for (unsigned int i = 0; i < 8; i++) {
unsigned int pixelsY = (row * 16) + (glyphTile * 8) + i;
unsigned int destPixelsOffset = (pixelsY * 64) + (pixelsX / 4);

dest[destPixelsOffset] = src[srcPixelsOffset + 1];
dest[destPixelsOffset + 1] = src[srcPixelsOffset];

srcPixelsOffset += 2;
}
}
}
}
}

static void ConvertToHalfWidthLatinFont(unsigned char *src, unsigned char *dest, unsigned int numRows)
{
unsigned int destPixelsOffset = 0;

for (unsigned int row = 0; row < numRows; row++) {
for (unsigned int column = 0; column < 32; column++) {
for (unsigned int glyphTile = 0; glyphTile < 2; glyphTile++) {
unsigned int pixelsX = (column * 8);

for (unsigned int i = 0; i < 8; i++) {
unsigned int pixelsY = (row * 16) + (glyphTile * 8) + i;
unsigned int srcPixelsOffset = (pixelsY * 64) + (pixelsX / 4);

dest[destPixelsOffset] = src[srcPixelsOffset + 1];
dest[destPixelsOffset + 1] = src[srcPixelsOffset];

destPixelsOffset += 2;
}
}
}
}
}

static void ConvertFromFullWidthLatinFont(unsigned char *src, unsigned char *dest, unsigned int numRows)
{
unsigned int srcPixelsOffset = 0;

Expand All @@ -39,7 +85,7 @@ static void ConvertFromLatinFont(unsigned char *src, unsigned char *dest, unsign
}
}

static void ConvertToLatinFont(unsigned char *src, unsigned char *dest, unsigned int numRows)
static void ConvertToFullWidthLatinFont(unsigned char *src, unsigned char *dest, unsigned int numRows)
{
unsigned int destPixelsOffset = 0;

Expand Down Expand Up @@ -173,7 +219,56 @@ static void SetFontPalette(struct Image *image)
image->hasTransparency = false;
}

void ReadLatinFont(char *path, struct Image *image)
void ReadHalfWidthLatinFont(char *path, struct Image *image)
{
int fileSize;
unsigned char *buffer = ReadWholeFile(path, &fileSize);

int numGlyphs = fileSize / 32;

if (numGlyphs % 16 != 0)
FATAL_ERROR("The number of glyphs (%d) is not a multiple of 16.\n", numGlyphs);

int numRows = numGlyphs / 16;

image->width = 256;
image->height = numRows * 16;
image->bitDepth = 2;
image->pixels = malloc(fileSize);

if (image->pixels == NULL)
FATAL_ERROR("Failed to allocate memory for font.\n");

ConvertFromHalfWidthLatinFont(buffer, image->pixels, numRows);

free(buffer);

SetFontPalette(image);
}

void WriteHalfWidthLatinFont(char *path, struct Image *image)
{
if (image->width != 256)
FATAL_ERROR("The width of the font image (%d) is not 256.\n", image->width);

if (image->height % 16 != 0)
FATAL_ERROR("The height of the font image (%d) is not a multiple of 16.\n", image->height);

int numRows = image->height / 16;
int bufferSize = numRows * 16 * 64;
unsigned char *buffer = malloc(bufferSize);

if (buffer == NULL)
FATAL_ERROR("Failed to allocate memory for font.\n");

ConvertToHalfWidthLatinFont(image->pixels, buffer, numRows);

WriteWholeFile(path, buffer, bufferSize);

free(buffer);
}

void ReadFullWidthLatinFont(char *path, struct Image *image)
{
int fileSize;
unsigned char *buffer = ReadWholeFile(path, &fileSize);
Expand All @@ -193,14 +288,14 @@ void ReadLatinFont(char *path, struct Image *image)
if (image->pixels == NULL)
FATAL_ERROR("Failed to allocate memory for font.\n");

ConvertFromLatinFont(buffer, image->pixels, numRows);
ConvertFromFullWidthLatinFont(buffer, image->pixels, numRows);

free(buffer);

SetFontPalette(image);
}

void WriteLatinFont(char *path, struct Image *image)
void WriteFullWidthLatinFont(char *path, struct Image *image)
{
if (image->width != 256)
FATAL_ERROR("The width of the font image (%d) is not 256.\n", image->width);
Expand All @@ -215,7 +310,7 @@ void WriteLatinFont(char *path, struct Image *image)
if (buffer == NULL)
FATAL_ERROR("Failed to allocate memory for font.\n");

ConvertToLatinFont(image->pixels, buffer, numRows);
ConvertToFullWidthLatinFont(image->pixels, buffer, numRows);

WriteWholeFile(path, buffer, bufferSize);

Expand Down
6 changes: 4 additions & 2 deletions tools/gbagfx/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include <stdbool.h>
#include "gfx.h"

void ReadLatinFont(char *path, struct Image *image);
void WriteLatinFont(char *path, struct Image *image);
void ReadHalfWidthLatinFont(char *path, struct Image *image);
void WriteHalfWidthLatinFont(char *path, struct Image *image);
void ReadFullWidthLatinFont(char *path, struct Image *image);
void WriteFullWidthLatinFont(char *path, struct Image *image);
void ReadHalfwidthJapaneseFont(char *path, struct Image *image);
void WriteHalfwidthJapaneseFont(char *path, struct Image *image);
void ReadFullwidthJapaneseFont(char *path, struct Image *image);
Expand Down
38 changes: 32 additions & 6 deletions tools/gbagfx/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,26 +350,50 @@ void HandleJascToGbaPaletteCommand(char *inputPath, char *outputPath, int argc,
WriteGbaPalette(outputPath, &palette);
}

void HandleLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
void HandleHalfWidthLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
{
struct Image image;
image.tilemap.data.affine = NULL; // initialize to NULL to avoid issues in FreeImage

ReadLatinFont(inputPath, &image);
ReadHalfWidthLatinFont(inputPath, &image);
WritePng(outputPath, &image);

FreeImage(&image);
}

void HandlePngToLatinFontCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
void HandlePngToHalfWidthLatinFontCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
{
struct Image image;
image.tilemap.data.affine = NULL; // initialize to NULL to avoid issues in FreeImage

image.bitDepth = 2;

ReadPng(inputPath, &image);
WriteLatinFont(outputPath, &image);
WriteHalfWidthLatinFont(outputPath, &image);

FreeImage(&image);
}

void HandleFullWidthLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
{
struct Image image;
image.tilemap.data.affine = NULL; // initialize to NULL to avoid issues in FreeImage

ReadFullWidthLatinFont(inputPath, &image);
WritePng(outputPath, &image);

FreeImage(&image);
}

void HandlePngToFullWidthLatinFontCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
{
struct Image image;
image.tilemap.data.affine = NULL; // initialize to NULL to avoid issues in FreeImage

image.bitDepth = 2;

ReadPng(inputPath, &image);
WriteFullWidthLatinFont(outputPath, &image);

FreeImage(&image);
}
Expand Down Expand Up @@ -605,8 +629,10 @@ int main(int argc, char **argv)
{ "png", "pal", HandlePngToJascPaletteCommand },
{ "gbapal", "pal", HandleGbaToJascPaletteCommand },
{ "pal", "gbapal", HandleJascToGbaPaletteCommand },
{ "latfont", "png", HandleLatinFontToPngCommand },
{ "png", "latfont", HandlePngToLatinFontCommand },
{ "hwlatfont", "png", HandleHalfWidthLatinFontToPngCommand },
{ "png", "hwlatfont", HandlePngToHalfWidthLatinFontCommand },
{ "fwlatfont", "png", HandleFullWidthLatinFontToPngCommand },
{ "png", "fwlatfont", HandlePngToFullWidthLatinFontCommand },
{ "hwjpnfont", "png", HandleHalfwidthJapaneseFontToPngCommand },
{ "png", "hwjpnfont", HandlePngToHalfwidthJapaneseFontCommand },
{ "fwjpnfont", "png", HandleFullwidthJapaneseFontToPngCommand },
Expand Down