From 05250c0aa20bd4b791a39bf22b8a9bc68cca428c Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Tue, 23 Jul 2024 18:55:50 +0800 Subject: [PATCH] [saco] Implement/match `CFontRender::MeasureText(...)` --- saco/fontrender.cpp | 17 ++++++++++++----- saco/fontrender.h | 13 ++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/saco/fontrender.cpp b/saco/fontrender.cpp index e99151c..9516223 100644 --- a/saco/fontrender.cpp +++ b/saco/fontrender.cpp @@ -1,6 +1,6 @@ #include "main.h" -#include "fontrender.h" +#include "game/util.h" int GetFontSize(); int GetFontWeight(); @@ -105,11 +105,18 @@ void CFontRender::RestoreDeviceObjects() SIZE CFontRender::MeasureText(char * szString, DWORD dwFormat) { - SIZE size = {0,0}; + RECT rect; + SIZE ret = {0, 0}; - // TODO: CFontRender::MeasureText .text:1006B200 - - return size; + if(strlen(szString) > 100000) return ret; + + strcpy(field_1C,szString); + RemoveColorEmbedsFromString(field_1C); + field_0->DrawTextA(NULL,field_1C,-1,&rect,dwFormat|DT_CALCRECT,0xFF000000); + ret.cx = rect.right - rect.left; + ret.cy = rect.bottom - rect.top; + + return ret; } void CFontRender::RenderText(ID3DXSprite * pSprite, char * sz, RECT rect, DWORD dwColor, BOOL bShadowed) diff --git a/saco/fontrender.h b/saco/fontrender.h index cc1b947..c93cff9 100644 --- a/saco/fontrender.h +++ b/saco/fontrender.h @@ -1,22 +1,21 @@ #pragma once -class CFontRender // size: 40 +class CFontRender { -private: +public: + //char _gap0[40]; ID3DXFontHook *field_0; ID3DXFontHook *field_4; ID3DXFont *field_8; ID3DXFont *field_C; ID3DXFont *field_10; - ID3DXSprite* field_14; + ID3DXSprite *field_14; IDirect3DDevice9 *m_pD3DDevice; - CHAR *field_1C; + char *field_1C; LONG field_20; LONG field_24; -public: - CFontRender(IDirect3DDevice9* pD3DDevice); ~CFontRender(); @@ -25,7 +24,7 @@ public: void DeleteDeviceObjects(); void RestoreDeviceObjects(); - SIZE MeasureText(char * szString, DWORD dwFormat = 0); + SIZE MeasureText(char * szString, DWORD dwFormat = DT_LEFT); void RenderText(ID3DXSprite * pSprite, char * sz, RECT rect, DWORD dwColor, BOOL bShadowed = TRUE); };