Mercurial > mm7
diff GUIFont.cpp @ 170:91fa025e6ca6
font cleaning code
author | C:\Documents and Settings\Administrator.SDF-1\Application Data\The Bat! |
---|---|
date | Fri, 15 Feb 2013 01:21:53 +0400 |
parents | b9ac55f2c8e6 |
children | 05682713195c |
line wrap: on
line diff
--- a/GUIFont.cpp Thu Feb 14 14:03:17 2013 +0200 +++ b/GUIFont.cpp Fri Feb 15 01:21:53 2013 +0400 @@ -1,5 +1,5 @@ #include <string> - +#include "LOD.h" #include "GUIFont.h" #include "GUIWindow.h" #include "Render.h" @@ -7,7 +7,7 @@ #include "mm7_data.h" - +extern LODFile_IconsBitmaps *pIcons_LOD; struct GUIFont *pAutonoteFont; @@ -21,6 +21,33 @@ struct GUIFont *pFontComic; struct GUIFont *pFontSmallnum; +//----- (0044C448) -------------------------------------------------------- +GUIFont *LoadFont(const char *pFontFile, const char *pFontPalette, ...) + { + + int pallete_index; // eax@3 + GUIFont *pFont; + unsigned int palletes_count =0; + va_list palettes_ptr; + + pFont = (GUIFont *)pIcons_LOD->LoadRaw(pFontFile, 0); + va_start(palettes_ptr, pFontFile); + + while (NULL!=(pFontPalette=va_arg(palettes_ptr, const char *))) + { + pallete_index =pIcons_LOD->LoadTexture(pFontPalette, TEXTURE_16BIT_PALETTE); + if (pallete_index == -1) + { + wsprintfA(pTmpBuf, "Unable to open %s", pFontPalette); + Abortf(pTmpBuf); + } + pFont->pFontPalettes[palletes_count] = pIcons_LOD->pTextures[pallete_index].pPalette16; + ++palletes_count; + } + va_end(palettes_ptr); + pFont->palletes_count = palletes_count; + return pFont; + } @@ -267,7 +294,7 @@ //----- (0044C933) -------------------------------------------------------- -char *__fastcall GUIFont::_44C933(const char *pString, GUIFont *pFont, GUIFont *a3, int a4, int a5, int a6) +char * GUIFont::_44C933(const char *pString, GUIFont *pFont, GUIFont *a3, int a4, int a5, int a6) { const char *v6; // esi@1 size_t v8; // eax@3 @@ -576,127 +603,238 @@ } //----- (0044C59D) -------------------------------------------------------- -int GUIFont::CalcTextHeight(const char *pString, GUIWindow *pWindow, int a4, int a5) -{ - const char *v5; // ebx@1 - GUIFont *v6; // edi@1 - int v8; // esi@3 - size_t v9; // eax@3 - signed int v10; // ebx@3 - unsigned __int8 v11; // cl@4 - size_t pWindowa; // [sp+10h] [bp+8h]@3 - unsigned __int8 *uX; // [sp+14h] [bp+Ch]@3 +int GUIFont::CalcTextHeight(const char *pString, GUIWindow *pWindow, int uXOffset, int a5) + { + int uAllHeght; // esi@3 + unsigned int uStringLen; // eax@3 + char c; // cl@4 + char *test_string; // [sp+14h] [bp+Ch]@3 - v5 = pString; - v6 = this; - if ( !pString ) - return 0; - v8 = LOBYTE(this->uFontHeight) - 3; - uX = (unsigned __int8 *)FitTextInAWindow(pString, this, pWindow, a4, 0); - v9 = strlen(v5); - v10 = 0; - pWindowa = v9; - while ( v10 < (signed int)pWindowa ) - { - if ( v6->IsCharValid(v11 = *uX) ) - { - if ( v11 == 9 ) - goto LABEL_9; - switch ( v11 ) - { - case 0xAu: - v8 = v8 + LOBYTE(v6->uFontHeight) - 3; - break; - case 0xCu: - uX += 5; - v10 += 5; - break; - case 0xDu: -LABEL_9: - if ( a5 != 1 ) - { - uX += 3; - v10 += 3; - } - break; - } - } - ++v10; - ++uX; - } - return v8; -} + if (!pString) + return 0; + uAllHeght = this->uFontHeight - 3; + test_string = FitTextInAWindow(pString, this, pWindow, uXOffset, 0); + uStringLen = strlen(pString); + for (int i = 0; i < uStringLen; ++i) + { + c = test_string[i]; + if (IsCharValid(c)) + { + switch (c) + { + case '\n': //Line Feed 0A 10: + uAllHeght+= this->uFontHeight - 3; + break; + case '\f': //Form Feed, page eject 0C 12 + i += 5; + break; + case '\t': // Horizontal tab 09 + case '\r': //Carriage Return 0D 13 + if (a5 != 1) + i += 3; + break; + } + } + } + return uAllHeght; + } //----- (0044C51E) -------------------------------------------------------- int GUIFont::GetLineWidth(const char *pString) -{ - GUIFont *pFont; // edi@1 - size_t pNumLen; // ebp@3 - int v5; // esi@3 - signed int i; // ebx@3 - unsigned __int8 v7; // cl@4 - const char *pStr; // [sp+0h] [bp-4h]@1 + { + unsigned int str_len; // ebp@3 + int string_line_width; // esi@3 + unsigned char c; - pStr = pString; - pFont = this; - if ( !pString ) // == 0 - return 0; - pNumLen = strlen(pString); - v5 = 0; - for ( i = 0; i < (signed int)pNumLen; ++i ) - { - if ( IsCharValid(v7 = pStr[i]) ) - { - if ( v7 < 9u ) - { - if ( i > 0 ) - v5 += pFont->pMetrics[v7].uLeftSpacing; - v5 += *((int *)&pFont->cFirstChar + 3 * v7 + 9); - if ( i < (signed int)pNumLen ) - v5 += pFont->pMetrics[v7].uRightSpacing; - continue; - } - if ( v7 <= 0xAu ) - return v5; - if ( v7 != '\f' ) - { - if ( v7 == '\r' ) - return v5; - if ( i > 0 ) - v5 += pFont->pMetrics[v7].uLeftSpacing; - v5 += *((int *)&pFont->cFirstChar + 3 * v7 + 9); - if ( i < (signed int)pNumLen ) - v5 += pFont->pMetrics[v7].uRightSpacing; - continue; - } - i += 5; - } - } - return v5; -} - - + if (!pString) + return 0; + str_len = strlen(pString); + string_line_width = 0; + for ( int i = 0; i < str_len; ++i ) + { + c = pString[i]; + if (IsCharValid(c)) + { + switch (c) + { + case '\t': + case '\n': + case '\r': + return string_line_width; + case '\f': + i += 5; + break; + default: + if (i > 0) + string_line_width += this->pMetrics[c].uLeftSpacing; + string_line_width += this->pMetrics[c].uWidth; + if (i < str_len) + string_line_width +=this->pMetrics[c].uRightSpacing; + } + } + } + return string_line_width; + } //----- (0044C502) -------------------------------------------------------- int GUIFont::AlignText_Center(unsigned int uCenterX, const char *pString) { - signed int v3; // esi@1 - signed int result; // eax@2 + signed int position; // esi@1 + + position = (signed int)(uCenterX - GetLineWidth(pString)) >> 1; + if ( position >= 0 ) + return position; + else + return 0; - v3 = (signed int)(uCenterX - GetLineWidth(pString)) >> 1; - if ( v3 >= 0 ) - result = v3; - else - result = 0; - return result; } +//----- (0044C768) -------------------------------------------------------- +char * FitTextInAWindow(const char *pInString, GUIFont *pFont, GUIWindow *pWindow, unsigned int uX, int a5) + { + const char *v5; // edi@1 + GUIFont *v6; // esi@1 + unsigned int v8; // eax@3 + int v9; // edi@3 + unsigned __int8 v10; // cl@4 + int v11; // edx@10 + GUICharMetric *v12; // ecx@10 + int v13; // edx@11 + int v14; // edx@12 + int v15; // edx@13 + unsigned int v16; // esi@15 + unsigned int v17; // edx@15 + unsigned int v18; // ecx@15 + int v19; // ebx@16 + unsigned __int8 v20; // zf@16 + char v21; // sf@16 + unsigned __int8 v22; // of@16 + int v23; // edi@16 + unsigned __int8 v24; // dl@17 + int v25; // edi@39 + int v26; // eax@42 + std::string v27; // [sp-18h] [bp-40h]@2 + const char *v28; // [sp-8h] [bp-30h]@2 + int v29; // [sp-4h] [bp-2Ch]@2 + const char *v30; // [sp+Ch] [bp-1Ch]@1 + char Str[3]; // [sp+10h] [bp-18h]@42 + char v32; // [sp+13h] [bp-15h]@42 + size_t v33; // [sp+14h] [bp-14h]@3 + unsigned int v34; // [sp+18h] [bp-10h]@3 + GUIFont *v35; // [sp+1Ch] [bp-Ch]@1 + int v36; // [sp+20h] [bp-8h]@3 + int v37; // [sp+24h] [bp-4h]@3 -//----- (0044C4DE) -------------------------------------------------------- -bool GUIFont::IsCharValid(char _c) -{ - unsigned char c = _c; - return c >= cFirstChar && c <= cLastChar || c == '\f' || c == '\r' || c == '\t' || c == '\n'; -} \ No newline at end of file + v5 = pInString; + v6 = pFont; + v30 = pInString; + v35 = pFont; + if ( !pInString ) + { + MessageBoxW(nullptr, L"Invalid string passed !", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Font.cpp:445", 0); + return 0; + } + v33 = strlen(pInString); + strcpy(pTmpBuf3, v5); + v8 = uX; + v9 = 0; + v36 = 0; + v34 = uX; + v37 = 0; + if ( (signed int)v33 > 0 ) + { + while ( 1 ) + { + v10 = pTmpBuf3[v9]; + if ((v10 < v6->cFirstChar || v10 > v6->cLastChar) + && v10 != '\f' && v10 != '\r' && v10 != '\t' && v10 != '\n' ) + goto LABEL_34; + v11 = v10 - 9; + v12 = &v6->pMetrics[v10]; + if ( !v11 ) + { + strncpy(Str, &pTmpBuf3[v9 + 1], 3u); + v32 = 0; + v26 = atoi(Str); + v8 = uX + v26; + v25 = v9 + 3; + v34 = v8; + goto LABEL_43; + } + v13 = v11 - 1; + if ( !v13 ) + break; + v14 = v13 - 2; + if ( !v14 ) + { + v25 = v9 + 5; +LABEL_43: + v37 = v25; + goto LABEL_34; + } + v15 = v14 - 1; + if ( v15 ) + { + if ( v15 != 19 ) + { + v16 = v12->uRightSpacing; + v17 = v12->uWidth; + v18 = v12->uLeftSpacing; + if ( v8 + v16 + v18 + v17 < pWindow->uFrameWidth ) + { + if ( v37 > v36 ) + v8 += v18; + v8 += v17; + if ( v37 < (signed int)v33 ) + v8 += v16; + v6 = v35; + } + else + { + v19 = v36; + v8 = v34; + v22 = v36 > v37; + v20 = v36 == v37; + v21 = v36 - v37 < 0; + v6 = v35; + pTmpBuf3[v36] = 10; + v23 = v19; + if ( (unsigned __int8)(v21 ^ v22) | v20 ) + { + do + { + v24 = pTmpBuf3[v23]; + if ( v24 >= v6->cFirstChar && v24 <= v6->cLastChar || v24 == 12 || v24 == 13 || v24 == 9 || v24 == 10 ) + { + if ( v23 > v19 ) + v8 += v6->pMetrics[v24].uLeftSpacing; + v8 += *((int *)&v6->cFirstChar + 3 * v24 + 9); + if ( v23 < v37 ) + v8 += v6->pMetrics[v24].uRightSpacing; + } + ++v23; + } + while ( v23 <= v37 ); + } + } + goto LABEL_34; + } + v8 += v12->uWidth; + goto LABEL_41; + } + if ( !a5 ) + return (char *)v30; +LABEL_34: + v9 = v37++ + 1; + if ( v37 >= (signed int)v33 ) + return pTmpBuf3; + } + v8 = v34; +LABEL_41: + v36 = v9; + goto LABEL_34; + } + return pTmpBuf3; + }