From ac1dd857f79a7b42a6b93b00221e83af5254ee3f Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Fri, 1 Nov 2024 11:07:58 -0300 Subject: [PATCH] Fixed text wrap obtaining the incorrect glyph width (#5620) --- include/text.h | 2 +- src/battle_message.c | 14 +++++++------- src/fonts.c | 16 ++++++++-------- src/text.c | 6 +----- test/text.c | 2 +- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/include/text.h b/include/text.h index 1791ae401f..55500868dc 100644 --- a/include/text.h +++ b/include/text.h @@ -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); diff --git a/src/battle_message.c b/src/battle_message.c index fc730c19df..be131ec7d6 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -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) { diff --git a/src/fonts.c b/src/fonts.c index 3f2c536985..2dcb0a7e78 100644 --- a/src/fonts.c +++ b/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, 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, 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, diff --git a/src/text.c b/src/text.c index 8a5b7b0cd3..acb2871a86 100644 --- a/src/text.c +++ b/src/text.c @@ -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; } diff --git a/test/text.c b/test/text.c index 996549ab1b..3a592b10d1 100644 --- a/test/text.c +++ b/test/text.c @@ -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.