Skip to content

Commit

Permalink
Official GF names by default (#4241)
Browse files Browse the repository at this point in the history
  • Loading branch information
AsparagusEduardo committed Apr 25, 2024
2 parents d42de03 + 664fe90 commit dd098ba
Show file tree
Hide file tree
Showing 86 changed files with 1,634 additions and 483 deletions.
3 changes: 3 additions & 0 deletions charmap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ FONT_NORMAL = FC 06 01
FONT_SHORT = FC 06 02
FONT_NARROW = FC 06 07
FONT_SMALL_NARROW = FC 06 08
FONT_NARROWER = FC 06 0A
FONT_SMALL_NARROWER = FC 06 0B
FONT_SHORT_NARROW = FC 06 0C

@ colors

Expand Down
331 changes: 311 additions & 20 deletions gflib/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,26 @@ static u16 FontFunc_ShortCopy2(struct TextPrinter *);
static u16 FontFunc_ShortCopy3(struct TextPrinter *);
static u16 FontFunc_Narrow(struct TextPrinter *);
static u16 FontFunc_SmallNarrow(struct TextPrinter *);
static u16 FontFunc_Narrower(struct TextPrinter *);
static u16 FontFunc_SmallNarrower(struct TextPrinter *);
static u16 FontFunc_ShortNarrow(struct TextPrinter *);
static void DecompressGlyph_Small(u16, bool32);
static void DecompressGlyph_Normal(u16, bool32);
static void DecompressGlyph_Short(u16, bool32);
static void DecompressGlyph_Narrow(u16, bool32);
static void DecompressGlyph_SmallNarrow(u16, bool32);
static void DecompressGlyph_Bold(u16);
static void DecompressGlyph_Narrower(u16, bool32);
static void DecompressGlyph_SmallNarrower(u16, bool32);
static void DecompressGlyph_ShortNarrow(u16, bool32);
static u32 GetGlyphWidth_Small(u16, bool32);
static u32 GetGlyphWidth_Normal(u16, bool32);
static u32 GetGlyphWidth_Short(u16, bool32);
static u32 GetGlyphWidth_Narrow(u16, bool32);
static u32 GetGlyphWidth_SmallNarrow(u16, bool32);
static u32 GetGlyphWidth_Narrower(u16, bool32);
static u32 GetGlyphWidth_SmallNarrower(u16, bool32);
static u32 GetGlyphWidth_ShortNarrow(u16, bool32);

static EWRAM_DATA struct TextPrinter sTempTextPrinter = {0};
static EWRAM_DATA struct TextPrinter sTextPrinters[WINDOWS_MAX] = {0};
Expand Down Expand Up @@ -81,15 +90,18 @@ static const u8 sWindowVerticalScrollSpeeds[] = {

static const struct GlyphWidthFunc sGlyphWidthFuncs[] =
{
{ FONT_SMALL, GetGlyphWidth_Small },
{ FONT_NORMAL, GetGlyphWidth_Normal },
{ FONT_SHORT, GetGlyphWidth_Short },
{ FONT_SHORT_COPY_1, GetGlyphWidth_Short },
{ FONT_SHORT_COPY_2, GetGlyphWidth_Short },
{ FONT_SHORT_COPY_3, GetGlyphWidth_Short },
{ FONT_BRAILLE, GetGlyphWidth_Braille },
{ FONT_NARROW, GetGlyphWidth_Narrow },
{ FONT_SMALL_NARROW, GetGlyphWidth_SmallNarrow }
{ FONT_SMALL, GetGlyphWidth_Small },
{ FONT_NORMAL, GetGlyphWidth_Normal },
{ FONT_SHORT, GetGlyphWidth_Short },
{ FONT_SHORT_COPY_1, GetGlyphWidth_Short },
{ FONT_SHORT_COPY_2, GetGlyphWidth_Short },
{ FONT_SHORT_COPY_3, GetGlyphWidth_Short },
{ FONT_BRAILLE, GetGlyphWidth_Braille },
{ FONT_NARROW, GetGlyphWidth_Narrow },
{ FONT_SMALL_NARROW, GetGlyphWidth_SmallNarrow },
{ FONT_NARROWER, GetGlyphWidth_Narrower },
{ FONT_SMALL_NARROWER, GetGlyphWidth_SmallNarrower },
{ FONT_SHORT_NARROW, GetGlyphWidth_ShortNarrow },
};

struct
Expand Down Expand Up @@ -217,21 +229,54 @@ static const struct FontInfo sFontInfos[] =
.fgColor = 1,
.bgColor = 2,
.shadowColor = 15,
}
},
[FONT_NARROWER] = {
.fontFunction = FontFunc_Narrower,
.maxLetterWidth = 5,
.maxLetterHeight = 16,
.letterSpacing = 0,
.lineSpacing = 0,
.fgColor = 2,
.bgColor = 1,
.shadowColor = 3,
},
[FONT_SMALL_NARROWER] = {
.fontFunction = FontFunc_SmallNarrower,
.maxLetterWidth = 5,
.maxLetterHeight = 8,
.letterSpacing = 0,
.lineSpacing = 0,
.fgColor = 2,
.bgColor = 1,
.shadowColor = 3,
},
[FONT_SHORT_NARROW] = {
.fontFunction = FontFunc_ShortNarrow,
.maxLetterWidth = 5,
.maxLetterHeight = 14,
.letterSpacing = 0,
.lineSpacing = 0,
.fgColor = 2,
.bgColor = 1,
.shadowColor = 3,
},
};

static const u8 sMenuCursorDimensions[][2] =
{
[FONT_SMALL] = { 8, 12 },
[FONT_NORMAL] = { 8, 15 },
[FONT_SHORT] = { 8, 14 },
[FONT_SHORT_COPY_1] = { 8, 14 },
[FONT_SHORT_COPY_2] = { 8, 14 },
[FONT_SHORT_COPY_3] = { 8, 14 },
[FONT_BRAILLE] = { 8, 16 },
[FONT_NARROW] = { 8, 15 },
[FONT_SMALL_NARROW] = { 8, 8 },
[FONT_BOLD] = {}
[FONT_SMALL] = { 8, 12 },
[FONT_NORMAL] = { 8, 15 },
[FONT_SHORT] = { 8, 14 },
[FONT_SHORT_COPY_1] = { 8, 14 },
[FONT_SHORT_COPY_2] = { 8, 14 },
[FONT_SHORT_COPY_3] = { 8, 14 },
[FONT_BRAILLE] = { 8, 16 },
[FONT_NARROW] = { 8, 15 },
[FONT_SMALL_NARROW] = { 8, 8 },
[FONT_BOLD] = {},
[FONT_NARROWER] = { 8, 15 },
[FONT_SMALL_NARROWER] = { 8, 8 },
[FONT_SHORT_NARROW] = { 8, 14 },
};

static const u16 sFontBoldJapaneseGlyphs[] = INCBIN_U16("graphics/fonts/bold.hwjpnfont");
Expand Down Expand Up @@ -813,6 +858,42 @@ static u16 FontFunc_SmallNarrow(struct TextPrinter *textPrinter)
return RenderText(textPrinter);
}

static u16 FontFunc_Narrower(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);

if (subStruct->hasFontIdBeenSet == FALSE)
{
subStruct->fontId = FONT_NARROWER;
subStruct->hasFontIdBeenSet = TRUE;
}
return RenderText(textPrinter);
}

static u16 FontFunc_SmallNarrower(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);

if (subStruct->hasFontIdBeenSet == FALSE)
{
subStruct->fontId = FONT_SMALL_NARROWER;
subStruct->hasFontIdBeenSet = TRUE;
}
return RenderText(textPrinter);
}

static u16 FontFunc_ShortNarrow(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);

if (subStruct->hasFontIdBeenSet == FALSE)
{
subStruct->fontId = FONT_SHORT_NARROW;
subStruct->hasFontIdBeenSet = TRUE;
}
return RenderText(textPrinter);
}

void TextPrinterInitDownArrowCounters(struct TextPrinter *textPrinter)
{
struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
Expand Down Expand Up @@ -1250,6 +1331,15 @@ static u16 RenderText(struct TextPrinter *textPrinter)
case FONT_SMALL_NARROW:
DecompressGlyph_SmallNarrow(currChar, textPrinter->japanese);
break;
case FONT_NARROWER:
DecompressGlyph_Narrower(currChar, textPrinter->japanese);
break;
case FONT_SMALL_NARROWER:
DecompressGlyph_SmallNarrower(currChar, textPrinter->japanese);
break;
case FONT_SHORT_NARROW:
DecompressGlyph_ShortNarrow(currChar, textPrinter->japanese);
break;
case FONT_BRAILLE:
break;
}
Expand Down Expand Up @@ -2012,3 +2102,204 @@ static void DecompressGlyph_Bold(u16 glyphId)
gCurGlyph.width = 8;
gCurGlyph.height = 12;
}

static void DecompressGlyph_Narrower(u16 glyphId, bool32 isJapanese)
{
const u16 *glyphs;

if (isJapanese == TRUE)
{
glyphs = gFontNormalJapaneseGlyphs + (0x100 * (glyphId >> 0x4)) + (0x8 * (glyphId % 0x10));
DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop);
DecompressGlyphTile(glyphs + 0x80, gCurGlyph.gfxBufferBottom);
gCurGlyph.width = 8;
gCurGlyph.height = 15;
}
else
{
glyphs = gFontNarrowerLatinGlyphs + (0x20 * glyphId);
gCurGlyph.width = gFontNarrowerLatinGlyphWidths[glyphId];

if (gCurGlyph.width <= 8)
{
DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop);
DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom);
}
else
{
DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop);
DecompressGlyphTile(glyphs + 0x8, gCurGlyph.gfxBufferTop + 8);
DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom);
DecompressGlyphTile(glyphs + 0x18, gCurGlyph.gfxBufferBottom + 8);
}

gCurGlyph.height = 15;
}
}

static u32 GetGlyphWidth_Narrower(u16 glyphId, bool32 isJapanese)
{
if (isJapanese == TRUE)
return 8;
else
return gFontNarrowerLatinGlyphWidths[glyphId];
}

static void DecompressGlyph_SmallNarrower(u16 glyphId, bool32 isJapanese)
{
const u16 *glyphs;

if (isJapanese == TRUE)
{
glyphs = gFontSmallJapaneseGlyphs + (0x100 * (glyphId >> 0x4)) + (0x8 * (glyphId % 0x10));
DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop);
DecompressGlyphTile(glyphs + 0x80, gCurGlyph.gfxBufferBottom);
gCurGlyph.width = 8;
gCurGlyph.height = 15;
}
else
{
glyphs = gFontSmallNarrowerLatinGlyphs + (0x20 * glyphId);
gCurGlyph.width = gFontSmallNarrowerLatinGlyphWidths[glyphId];

if (gCurGlyph.width <= 8)
{
DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop);
DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom);
}
else
{
DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop);
DecompressGlyphTile(glyphs + 0x8, gCurGlyph.gfxBufferTop + 8);
DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom);
DecompressGlyphTile(glyphs + 0x18, gCurGlyph.gfxBufferBottom + 8);
}

gCurGlyph.height = 15;
}
}

static u32 GetGlyphWidth_SmallNarrower(u16 glyphId, bool32 isJapanese)
{
if (isJapanese == TRUE)
return 8;
else
return gFontSmallNarrowerLatinGlyphWidths[glyphId];
}

static void DecompressGlyph_ShortNarrow(u16 glyphId, bool32 isJapanese)
{
const u16 *glyphs;

if (isJapanese == TRUE)
{
glyphs = gFontShortJapaneseGlyphs + (0x100 * (glyphId >> 0x3)) + (0x10 * (glyphId & 0x7));
DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop);
DecompressGlyphTile(glyphs + 0x8, gCurGlyph.gfxBufferTop + 8);
DecompressGlyphTile(glyphs + 0x80, gCurGlyph.gfxBufferBottom); // gCurGlyph + 0x20
DecompressGlyphTile(glyphs + 0x88, gCurGlyph.gfxBufferBottom + 8); // gCurGlyph + 0x60
gCurGlyph.width = gFontShortJapaneseGlyphWidths[glyphId];
gCurGlyph.height = 14;
}
else
{
glyphs = gFontShortNarrowLatinGlyphs + (0x20 * glyphId);
gCurGlyph.width = gFontShortNarrowLatinGlyphWidths[glyphId];

if (gCurGlyph.width <= 8)
{
DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop);
DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom);
}
else
{
DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop);
DecompressGlyphTile(glyphs + 0x8, gCurGlyph.gfxBufferTop + 8);
DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom);
DecompressGlyphTile(glyphs + 0x18, gCurGlyph.gfxBufferBottom + 8);
}

gCurGlyph.height = 14;
}
}

static u32 GetGlyphWidth_ShortNarrow(u16 glyphId, bool32 isJapanese)
{
if (isJapanese == TRUE)
return gFontShortJapaneseGlyphWidths[glyphId];
else
return gFontShortNarrowLatinGlyphWidths[glyphId];
}

static const s8 sNarrowerFontIds[] =
{
[FONT_SMALL] = FONT_SMALL_NARROW,
[FONT_NORMAL] = FONT_NARROW,
[FONT_SHORT] = FONT_SHORT_NARROW,
[FONT_SHORT_COPY_1] = FONT_SHORT_NARROW,
[FONT_SHORT_COPY_2] = FONT_SHORT_NARROW,
[FONT_SHORT_COPY_3] = FONT_SHORT_NARROW,
[FONT_BRAILLE] = -1,
[FONT_NARROW] = FONT_NARROWER,
[FONT_SMALL_NARROW] = FONT_SMALL_NARROWER,
[FONT_BOLD] = -1,
[FONT_NARROWER] = -1,
[FONT_SMALL_NARROWER] = -1,
[FONT_SHORT_NARROW] = -1,
};

// If the narrowest font ID doesn't fit the text, we still return that
// ID because clipping is better than crashing.
u32 GetFontIdToFit(const u8 *string, u32 fontId, u32 letterSpacing, u32 widthPx)
{
for (;;)
{
s32 narrowerFontId = sNarrowerFontIds[fontId];
if (narrowerFontId == -1)
return fontId;
if (GetStringWidth(fontId, string, letterSpacing) <= widthPx)
return fontId;
fontId = narrowerFontId;
}
}

u8 *PrependFontIdToFit(u8 *start, u8 *end, u32 fontId, u32 width)
{

u32 fitFontId = GetFontIdToFit(start, fontId, 0, width);
if (fitFontId != fontId)
{
memmove(&start[3], &start[0], end - start);
start[0] = EXT_CTRL_CODE_BEGIN;
start[1] = EXT_CTRL_CODE_FONT;
start[2] = fitFontId;
end[3] = EOS;
return end + 3;
}
else
{
return end;
}
}

u8 *WrapFontIdToFit(u8 *start, u8 *end, u32 fontId, u32 width)
{

u32 fitFontId = GetFontIdToFit(start, fontId, 0, width);
if (fitFontId != fontId)
{
memmove(&start[3], &start[0], end - start);
start[0] = EXT_CTRL_CODE_BEGIN;
start[1] = EXT_CTRL_CODE_FONT;
start[2] = fitFontId;
end[3] = EXT_CTRL_CODE_BEGIN;
end[4] = EXT_CTRL_CODE_FONT;
end[5] = fontId;
end[6] = EOS;
return end + 6;
}
else
{
return end;
}
}
Loading

0 comments on commit dd098ba

Please sign in to comment.