Mercurial > mm7
diff GUIFont.cpp @ 189:038a4d09406f
new texts file, fix text rendender error
author | Gloval |
---|---|
date | Sat, 16 Feb 2013 00:33:21 +0400 |
parents | c5bd7a825ef2 |
children | 1527f66fd81b |
line wrap: on
line diff
--- a/GUIFont.cpp Fri Feb 15 19:46:25 2013 +0600 +++ b/GUIFont.cpp Sat Feb 16 00:33:21 2013 +0400 @@ -21,6 +21,10 @@ struct GUIFont *pFontComic; struct GUIFont *pFontSmallnum; +char temp_string[2048]; + +char pTmpBuf3[2048]; + //----- (0044C448) -------------------------------------------------------- GUIFont *LoadFont(const char *pFontFile, const char *pFontPalette, ...) { @@ -605,10 +609,10 @@ //----- (0044C59D) -------------------------------------------------------- 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 + int uAllHeght; + unsigned int uStringLen; + char c; + char *test_string; if (!pString) return 0; @@ -694,147 +698,97 @@ //----- (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 + unsigned char c; + unsigned int uInStrLen; + char digits[4]; + int possible_transition_point; + int string_pixel_Width; + int start_pixel_offset; - v5 = pInString; - v6 = pFont; - v30 = pInString; - v35 = pFont; - if ( !pInString ) + 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 ) + uInStrLen = strlen(pInString); + strcpy(&temp_string[0], pInString); + if (uInStrLen==0) + return &temp_string[0]; + + start_pixel_offset=string_pixel_Width=uX; + possible_transition_point=0; + for(int i=0; i<uInStrLen; ++i) { - while ( 1 ) + c=temp_string[i]; + if (pFont->IsCharValid(c)) { - 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 ) + switch (c) + { + case '\t': // Horizontal tab 09 + { + strncpy(digits, &temp_string[i+1],3); + digits[3]=0; + string_pixel_Width= atoi(digits)+uX; + i+=3; + break; + } + case '\n': //Line Feed 0A 10 + { + string_pixel_Width=start_pixel_offset; + possible_transition_point=i; + break; + } + case '\f': //Form Feed, page eject 0C 12 { - strncpy(Str, &pTmpBuf3[v9 + 1], 3u); - v32 = 0; - v26 = atoi(Str); - v8 = uX + v26; - v25 = v9 + 3; - v34 = v8; - goto LABEL_43; + i+=5; + break; } - v13 = v11 - 1; - if ( !v13 ) + case '\r': //Carriage Return 0D 13 + { + if (!a5) + return (char*)pInString; break; - v14 = v13 - 2; - if ( !v14 ) + } + case ' ' : { - v25 = v9 + 5; -LABEL_43: - v37 = v25; - goto LABEL_34; + string_pixel_Width+=pFont->pMetrics[c].uWidth; + possible_transition_point=i; + break; } - v15 = v14 - 1; - if ( v15 ) - { - if ( v15 != 19 ) + default: + + if ((string_pixel_Width+pFont->pMetrics[c].uWidth+ pFont->pMetrics[c].uLeftSpacing+ + pFont->pMetrics[c].uRightSpacing)<pWindow->uFrameWidth) { - v16 = v12->uRightSpacing; - v17 = v12->uWidth; - v18 = v12->uLeftSpacing; - if ( v8 + v16 + v18 + v17 < pWindow->uFrameWidth ) + if(i>possible_transition_point) + string_pixel_Width+=pFont->pMetrics[c].uLeftSpacing; + string_pixel_Width+=pFont->pMetrics[c].uWidth; + if (i<uInStrLen) + string_pixel_Width+=pFont->pMetrics[c].uRightSpacing; + } + else + { + temp_string[possible_transition_point]='\n'; + string_pixel_Width=start_pixel_offset; + if (i>possible_transition_point) { - 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 ) + for(int j=possible_transition_point;j<i; ++j ) { - do + c=temp_string[j]; + if (pFont->IsCharValid(c)) { - 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; + if(j>possible_transition_point) + string_pixel_Width+=pFont->pMetrics[c].uLeftSpacing; + string_pixel_Width+=pFont->pMetrics[c].uWidth; + if (j<i) + string_pixel_Width+=pFont->pMetrics[c].uRightSpacing; + } - 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; + return &temp_string[0]; }