From 3015f39368c8ff0244a601932227492a53fdf061 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sun, 30 Oct 2022 08:41:00 +0300 Subject: [PATCH] Review interfaceFontGetStringWidthImpl --- src/font_manager.cc | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/font_manager.cc b/src/font_manager.cc index 85c163e..67df34d 100644 --- a/src/font_manager.cc +++ b/src/font_manager.cc @@ -236,26 +236,22 @@ static int interfaceFontGetStringWidthImpl(const char* string) return 0; } - const char* pch = string; - int width = 0; + int stringWidth = 0; - while (*pch != '\0') { - int v3; - int v4; + while (*string != '\0') { + unsigned char ch = static_cast(*string++); - if (*pch == ' ') { - v3 = gCurrentInterfaceFontDescriptor->letterSpacing; - v4 = gCurrentInterfaceFontDescriptor->wordSpacing; + int characterWidth; + if (ch == ' ') { + characterWidth = gCurrentInterfaceFontDescriptor->wordSpacing; } else { - v3 = gCurrentInterfaceFontDescriptor->glyphs[*pch & 0xFF].width; - v4 = gCurrentInterfaceFontDescriptor->letterSpacing; + characterWidth = gCurrentInterfaceFontDescriptor->glyphs[ch].width; } - width += v3 + v4; - pch++; + stringWidth += characterWidth + gCurrentInterfaceFontDescriptor->letterSpacing; } - return width; + return stringWidth; } // 0x4421DC