Fixed text wrap obtaining the incorrect glyph width (#5620)
This commit is contained in:
parent
56331abbb4
commit
ac1dd857f7
5 changed files with 18 additions and 22 deletions
|
@ -159,7 +159,7 @@ bool32 TextPrinterWait(struct TextPrinter *textPrinter);
|
|||
void DrawDownArrow(u8 windowId, u16 x, u16 y, u8 bgColor, bool32 drawArrow, u8 *counter, u8 *yCoordIndex);
|
||||
s32 GetGlyphWidth(u16 glyphId, bool32 isJapanese, u8 fontId);
|
||||
s32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing);
|
||||
s32 GetStringLineWidth(u8 fontId, const u8 *str, s16 letterSpacing, u32 lineNum, u32 strSize, bool32 printDebug);
|
||||
s32 GetStringLineWidth(u8 fontId, const u8 *str, s16 letterSpacing, u32 lineNum, u32 strSize);
|
||||
u8 RenderTextHandleBold(u8 *pixels, u8 fontId, u8 *str);
|
||||
u8 DrawKeypadIcon(u8 windowId, u8 keypadIconId, u16 x, u16 y);
|
||||
u8 GetKeypadIconTileOffset(u8 keypadIconId);
|
||||
|
|
|
@ -3097,7 +3097,7 @@ u32 BattleStringExpandPlaceholdersToDisplayedString(const u8 *src)
|
|||
u32 dstID = BattleStringExpandPlaceholders(src, gDisplayedStringBattle, sizeof(gDisplayedStringBattle));
|
||||
for (j = 1;; j++)
|
||||
{
|
||||
strWidth = GetStringLineWidth(0, gDisplayedStringBattle, 0, j, sizeof(gDisplayedStringBattle), TRUE);
|
||||
strWidth = GetStringLineWidth(0, gDisplayedStringBattle, 0, j, sizeof(gDisplayedStringBattle));
|
||||
if (strWidth == 0)
|
||||
break;
|
||||
}
|
||||
|
@ -3164,7 +3164,7 @@ static void GetBattlerNick(u32 battler, u8 *dst)
|
|||
} \
|
||||
GetBattlerNick(battler, text); \
|
||||
toCpy = text; \
|
||||
dstWidth = GetStringLineWidth(fontId, dst, letterSpacing, lineNum, dstSize, FALSE);
|
||||
dstWidth = GetStringLineWidth(fontId, dst, letterSpacing, lineNum, dstSize);
|
||||
|
||||
#define HANDLE_NICKNAME_STRING_LOWERCASE(battler) \
|
||||
if (GetBattlerSide(battler) != B_SIDE_PLAYER) \
|
||||
|
@ -3182,7 +3182,7 @@ static void GetBattlerNick(u32 battler, u8 *dst)
|
|||
} \
|
||||
GetBattlerNick(battler, text); \
|
||||
toCpy = text; \
|
||||
dstWidth = GetStringLineWidth(fontId, dst, letterSpacing, lineNum, dstSize, FALSE);
|
||||
dstWidth = GetStringLineWidth(fontId, dst, letterSpacing, lineNum, dstSize);
|
||||
|
||||
static const u8 *BattleStringGetOpponentNameByTrainerId(u16 trainerId, u8 *text, u8 multiplayerId, u8 battler)
|
||||
{
|
||||
|
@ -3357,7 +3357,7 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize)
|
|||
while (*src != EOS)
|
||||
{
|
||||
toCpy = NULL;
|
||||
dstWidth = GetStringLineWidth(fontId, dst, letterSpacing, lineNum, dstSize, FALSE);
|
||||
dstWidth = GetStringLineWidth(fontId, dst, letterSpacing, lineNum, dstSize);
|
||||
|
||||
if (*src == PLACEHOLDER_BEGIN)
|
||||
{
|
||||
|
@ -3749,12 +3749,12 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize)
|
|||
|
||||
if (toCpy != NULL)
|
||||
{
|
||||
toCpyWidth = GetStringLineWidth(fontId, toCpy, letterSpacing, 1, dstSize, FALSE);
|
||||
toCpyWidth = GetStringLineWidth(fontId, toCpy, letterSpacing, 1, dstSize);
|
||||
|
||||
if (dstWidth + toCpyWidth > BATTLE_MSG_MAX_WIDTH)
|
||||
{
|
||||
dst[lastValidSkip] = lineNum == 1 ? CHAR_NEWLINE : CHAR_PROMPT_SCROLL;
|
||||
dstWidth = GetStringLineWidth(fontId, dst, letterSpacing, lineNum, dstSize, FALSE);
|
||||
dstWidth = GetStringLineWidth(fontId, dst, letterSpacing, lineNum, dstSize);
|
||||
lineNum++;
|
||||
}
|
||||
while (*toCpy != EOS)
|
||||
|
@ -3776,7 +3776,7 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize)
|
|||
}
|
||||
else
|
||||
{
|
||||
toCpyWidth = GetGlyphWidth(dst[dstID + 1], FALSE, fontId);
|
||||
toCpyWidth = GetGlyphWidth(*src, FALSE, fontId);
|
||||
dst[dstID] = *src;
|
||||
if (dstWidth + toCpyWidth > BATTLE_MSG_MAX_WIDTH)
|
||||
{
|
||||
|
|
16
src/fonts.c
16
src/fonts.c
|
@ -17,7 +17,7 @@ ALIGNED(4) const u8 gFontSmallNarrowLatinGlyphWidths[] = {
|
|||
5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5,
|
||||
5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 5,
|
||||
4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 7,
|
||||
3, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 8, 3, 3, 3, 3,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
|
@ -53,7 +53,7 @@ ALIGNED(4) const u8 gFontSmallLatinGlyphWidths[] = {
|
|||
5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5,
|
||||
5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 8,
|
||||
7, 5, 5, 5, 5, 5, 5, 9, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
7, 5, 5, 5, 5, 5, 5, 9, 3, 3, 3, 8, 3, 3, 3, 3,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
|
@ -89,7 +89,7 @@ ALIGNED(4) const u8 gFontNarrowLatinGlyphWidths[] = {
|
|||
5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5,
|
||||
4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 8,
|
||||
3, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 8, 3, 3, 3, 3,
|
||||
10, 10, 10, 10, 8, 8, 10, 8, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
|
@ -125,7 +125,7 @@ ALIGNED(4) const u8 gFontShortLatinGlyphWidths[] = {
|
|||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 6, 4, 6, 5,
|
||||
5, 6, 5, 6, 6, 6, 5, 5, 5, 6, 6, 6, 6, 6, 6, 8,
|
||||
5, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
5, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 8, 3, 3, 3, 3,
|
||||
12, 12, 12, 12, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
|
@ -161,7 +161,7 @@ ALIGNED(4) const u8 gFontNormalLatinGlyphWidths[] = {
|
|||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 5, 6,
|
||||
4, 6, 6, 6, 6, 6, 5, 6, 6, 6, 6, 6, 6, 6, 6, 8,
|
||||
3, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 8, 3, 3, 3, 3,
|
||||
10, 10, 10, 10, 8, 10, 10, 8, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
|
@ -197,7 +197,7 @@ ALIGNED(4) const u8 gFontNarrowerLatinGlyphWidths[] = {
|
|||
4, 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4,
|
||||
2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8,
|
||||
4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 8, 3, 3, 3, 3,
|
||||
10, 10, 10, 10, 8, 8, 10, 8, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
|
@ -233,7 +233,7 @@ ALIGNED(4) const u8 gFontSmallNarrowerLatinGlyphWidths[] = {
|
|||
4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 3, 4,
|
||||
2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7,
|
||||
4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 8, 3, 3, 3, 3,
|
||||
8, 8, 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
|
@ -269,7 +269,7 @@ ALIGNED(4) const u8 gFontShortNarrowLatinGlyphWidths[] = {
|
|||
5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5,
|
||||
5, 5, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5,
|
||||
4, 6, 5, 5, 5, 5, 5, 5, 4, 5, 5, 6, 4, 5, 5, 8,
|
||||
5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 8, 3, 3, 3, 3,
|
||||
12, 12, 12, 12, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
|
|
|
@ -1605,7 +1605,7 @@ s32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing)
|
|||
return width;
|
||||
}
|
||||
|
||||
s32 GetStringLineWidth(u8 fontId, const u8 *str, s16 letterSpacing, u32 lineNum, u32 strSize, bool32 printDebug)
|
||||
s32 GetStringLineWidth(u8 fontId, const u8 *str, s16 letterSpacing, u32 lineNum, u32 strSize)
|
||||
{
|
||||
u32 strWidth = 0, strLen, currLine;
|
||||
u8 strCopy[strSize];
|
||||
|
@ -1621,10 +1621,6 @@ s32 GetStringLineWidth(u8 fontId, const u8 *str, s16 letterSpacing, u32 lineNum,
|
|||
strWidth = GetStringWidth(fontId, strCopy, letterSpacing);
|
||||
strLen = StringLineLength(strCopy);
|
||||
StringAppend(strCopy, gText_EmptyString3);
|
||||
#ifndef NDEBUG
|
||||
if (printDebug && strWidth != 0)
|
||||
DebugPrintf(" Line %d, len:%d, width:%d, \"%S\"", currLine, strLen, strWidth, strCopy);
|
||||
#endif
|
||||
}
|
||||
str += strLen + 1;
|
||||
}
|
||||
|
|
|
@ -890,7 +890,7 @@ TEST("Battle strings fit on the battle message window")
|
|||
DebugPrintf("Battle String ID %d: %S", battleStringId + BATTLESTRINGS_TABLE_START, battleString);
|
||||
for (j = 1;; j++)
|
||||
{
|
||||
strWidth = GetStringLineWidth(fontId, battleString, 0, j, BATTLE_STRING_BUFFER_SIZE, TRUE);
|
||||
strWidth = GetStringLineWidth(fontId, battleString, 0, j, BATTLE_STRING_BUFFER_SIZE);
|
||||
if (strWidth == 0)
|
||||
break;
|
||||
EXPECT_LE(strWidth - 1, BATTLE_MSG_MAX_WIDTH); // -1 because there's a pixel-wide space that doesn't visually look like it's out of frame when using FONT_NORMAL.
|
||||
|
|
Loading…
Reference in a new issue