diff options
author | Kurausukun <lord.uber1@gmail.com> | 2021-04-19 02:26:12 -0400 |
---|---|---|
committer | Kurausukun <lord.uber1@gmail.com> | 2021-04-19 02:26:12 -0400 |
commit | 1f194a4169c0694dbc036cad7e411db15606f9f8 (patch) | |
tree | 62a756c24ab59a65c7d463b1a28a383812cb5f3c /src | |
parent | d4a5f580c5aa77080bddf3f5dd48c074683c588f (diff) |
fix GetStringWidth fakematching
Diffstat (limited to 'src')
-rw-r--r-- | src/text.c | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/src/text.c b/src/text.c index 1bf8626fa..f92c73df1 100644 --- a/src/text.c +++ b/src/text.c @@ -1007,16 +1007,12 @@ s32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing) int minGlyphWidth; s32 (*func)(u16 glyphId, bool32 isJapanese); int localLetterSpacing; - #ifndef NONMATCHING - register u32 lineWidth asm("r5"); - #else - u32 lineWidth; - #endif + u32 lineWidth; const u8 *bufferPointer; int glyphWidth; u32 width; - isJapanese = 0; + isJapanese = FALSE; minGlyphWidth = 0; func = GetFontWidthFunc(fontId); @@ -1024,7 +1020,7 @@ s32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing) return 0; if (letterSpacing == -1) - localLetterSpacing = GetFontAttribute(fontId, 2); + localLetterSpacing = GetFontAttribute(fontId, FONTATTR_LETTER_SPACING); else localLetterSpacing = letterSpacing; @@ -1041,7 +1037,7 @@ s32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing) width = lineWidth; lineWidth = 0; break; - case PLACEHOLDER_BEGIN: + case PLACEHOLDER_BEGIN: switch (*++str) { case PLACEHOLDER_ID_STRING_VAR_1: @@ -1063,18 +1059,15 @@ s32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing) { glyphWidth = func(*bufferPointer++, isJapanese); if (minGlyphWidth > 0) - { - if (glyphWidth < minGlyphWidth) - glyphWidth = minGlyphWidth; - } - else if (isJapanese) - { - glyphWidth += localLetterSpacing; - } - lineWidth += glyphWidth; + lineWidth += minGlyphWidth > glyphWidth ? minGlyphWidth : glyphWidth; + else + lineWidth += isJapanese ? glyphWidth + localLetterSpacing : glyphWidth; } bufferPointer = NULL; break; + case CHAR_PROMPT_SCROLL: + case CHAR_PROMPT_CLEAR: + break; case EXT_CTRL_CODE_BEGIN: switch (*++str) { @@ -1092,13 +1085,17 @@ s32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing) case EXT_CTRL_CODE_SHIFT_RIGHT: case EXT_CTRL_CODE_SHIFT_DOWN: ++str; + case EXT_CTRL_CODE_RESET_FONT: + case EXT_CTRL_CODE_WAIT_BUTTON: + case EXT_CTRL_CODE_WAIT_SE: + case EXT_CTRL_CODE_FILL_WINDOW: break; case EXT_CTRL_CODE_FONT: func = GetFontWidthFunc(*++str); if (func == NULL) return 0; if (letterSpacing == -1) - localLetterSpacing = GetFontAttribute(*str, 2); + localLetterSpacing = GetFontAttribute(*str, FONTATTR_LETTER_SPACING); break; case EXT_CTRL_CODE_CLEAR: glyphWidth = *++str; @@ -1115,15 +1112,10 @@ s32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing) minGlyphWidth = *++str; break; case EXT_CTRL_CODE_JPN: - isJapanese = 1; + isJapanese = TRUE; break; case EXT_CTRL_CODE_ENG: - isJapanese = 0; - break; - case EXT_CTRL_CODE_RESET_FONT: - case EXT_CTRL_CODE_WAIT_BUTTON: - case EXT_CTRL_CODE_WAIT_SE: - case EXT_CTRL_CODE_FILL_WINDOW: + isJapanese = FALSE; default: break; } @@ -1146,9 +1138,6 @@ s32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing) } lineWidth += glyphWidth; break; - case CHAR_PROMPT_SCROLL: - case CHAR_PROMPT_CLEAR: - break; default: glyphWidth = func(*str, isJapanese); if (minGlyphWidth > 0) |