Skip to content

Commit cef2ee6

Browse files
Kernellccw808
authored andcommitted
Added quality argument for dxCreateFont
1 parent d7ddaba commit cef2ee6

10 files changed

+70
-24
lines changed

MTA10/core/CGraphics.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,8 +1140,7 @@ bool CGraphics::CreateStandardDXFontWithCustomScale ( eFontType fontType, float
11401140
return true;
11411141
}
11421142

1143-
1144-
bool CGraphics::LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, ID3DXFont** ppD3DXFont )
1143+
bool CGraphics::LoadAdditionalDXFont( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, DWORD ulQuality, ID3DXFont** ppD3DXFont )
11451144
{
11461145
int iLoaded = AddFontResourceEx ( strFontPath.c_str (), FR_PRIVATE, 0 );
11471146

@@ -1151,7 +1150,7 @@ bool CGraphics::LoadAdditionalDXFont ( std::string strFontPath, std::string strF
11511150
bool bSuccess = true;
11521151
// Normal size
11531152
if( !SUCCEEDED ( D3DXCreateFont ( m_pDevice, uiHeight, 0, iWeight, 1,
1154-
FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, strFontName.c_str(),
1153+
FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ulQuality, DEFAULT_PITCH | FF_DONTCARE, strFontName.c_str(),
11551154
ppD3DXFont ) ) )
11561155
{
11571156
WriteErrorEvent( SString( "Could not create Direct3D font '%s'", strFontName.c_str() ) );
@@ -1161,6 +1160,12 @@ bool CGraphics::LoadAdditionalDXFont ( std::string strFontPath, std::string strF
11611160
return bSuccess && ( iLoaded == 1 );
11621161
}
11631162

1163+
1164+
bool CGraphics::LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, ID3DXFont** ppD3DXFont )
1165+
{
1166+
return this->LoadAdditionalDXFont( strFontPath, strFontName, uiHeight, bBold, PROOF_QUALITY, ppD3DXFont );
1167+
}
1168+
11641169
bool CGraphics::DestroyAdditionalDXFont ( std::string strFontPath, ID3DXFont *pD3DXFont )
11651170
{
11661171
bool bResult = RemoveFontResourceEx ( strFontPath.c_str (), FR_PRIVATE, 0 ) != 0;

MTA10/core/CGraphics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class CGraphics : public CGraphicsInterface, public CSingleton < CGraphics >
108108
bool CreateStandardDXFontWithCustomScale ( eFontType fontType, float fScale, ID3DXFont** ppD3DXFont );
109109

110110
bool LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, ID3DXFont** ppD3DXFont );
111+
bool LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, DWORD ulQuality, ID3DXFont** ppD3DXFont );
111112
bool DestroyAdditionalDXFont ( std::string strFontPath, ID3DXFont* pD3DXFont );
112113

113114
float GetDXFontHeight ( float fScale = 1.0f, ID3DXFont * pDXFont = NULL );

MTA10/core/CRenderItem.DxFont.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
//
2020
//
2121
////////////////////////////////////////////////////////////////
22-
void CDxFontItem::PostConstruct ( CRenderItemManager* pManager, const SString& strFullFilePath, uint uiSize, bool bBold )
22+
void CDxFontItem::PostConstruct ( CRenderItemManager* pManager, const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality )
2323
{
2424
Super::PostConstruct ( pManager );
2525
m_strFullFilePath = strFullFilePath;
2626

2727
// Initial creation of d3d data
28-
CreateUnderlyingData ( uiSize, bBold );
28+
CreateUnderlyingData ( uiSize, bBold, ulQuality );
2929
}
3030

3131

@@ -89,7 +89,7 @@ void CDxFontItem::OnResetDevice ( void )
8989
//
9090
//
9191
////////////////////////////////////////////////////////////////
92-
void CDxFontItem::CreateUnderlyingData ( uint uiSize, bool bBold )
92+
void CDxFontItem::CreateUnderlyingData ( uint uiSize, bool bBold, DWORD ulQuality )
9393
{
9494
assert ( !m_pFntNormal );
9595

@@ -98,7 +98,7 @@ void CDxFontItem::CreateUnderlyingData ( uint uiSize, bool bBold )
9898
// Create the D3DX fonts
9999
FONT_PROPERTIES sFontProps;
100100
if ( GetFontProperties ( LPCTSTR ( m_strFullFilePath.c_str () ), &sFontProps ) )
101-
CCore::GetSingleton ().GetGraphics()->LoadAdditionalDXFont ( m_strFullFilePath, sFontProps.csName, static_cast < int > ( std::floor ( uiSize * 1.75f ) ), bBold, &m_pFntNormal );
101+
CCore::GetSingleton ().GetGraphics()->LoadAdditionalDXFont ( m_strFullFilePath, sFontProps.csName, static_cast < int > ( std::floor ( uiSize * 1.75f ) ), bBold, ulQuality, &m_pFntNormal );
102102

103103
if ( !m_pFntNormal )
104104
return;

MTA10/core/CRenderItemManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,13 @@ CShaderItem* CRenderItemManager::CreateShader ( const SString& strFullFilePath,
236236
// TODO: Make underlying data for fonts shared
237237
//
238238
////////////////////////////////////////////////////////////////
239-
CDxFontItem* CRenderItemManager::CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold )
239+
CDxFontItem* CRenderItemManager::CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality )
240240
{
241241
if ( !CanCreateRenderItem ( CDxFontItem::GetClassId () ) )
242242
return NULL;
243243

244244
CDxFontItem* pDxFontItem = new CDxFontItem ();
245-
pDxFontItem->PostConstruct ( this, strFullFilePath, uiSize, bBold );
245+
pDxFontItem->PostConstruct ( this, strFullFilePath, uiSize, bBold, ulQuality );
246246

247247
if ( !pDxFontItem->IsValid () )
248248
{

MTA10/core/CRenderItemManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CRenderItemManager : public CRenderItemManagerInterface
2525

2626
// CRenderItemManagerInterface
2727
virtual void DoPulse ( void );
28-
virtual CDxFontItem* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold );
28+
virtual CDxFontItem* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY );
2929
virtual CGuiFontItem* CreateGuiFont ( const SString& strFullFilePath, const SString& strFontName, uint uiSize );
3030
virtual CTextureItem* CreateTexture ( const SString& strFullFilePath, const CPixels* pPixels, bool bMipMaps = true, uint uiSizeX = RDEFAULT, uint uiSizeY = RDEFAULT, ERenderFormat format = RFORMAT_UNKNOWN, ETextureAddress textureAddress = TADDRESS_WRAP, ETextureType textureType = TTYPE_TEXTURE, uint uiVolumeDepth = 1 );
3131
virtual CShaderItem* CreateShader ( const SString& strFullFilePath, const SString& strRootPath, SString& strOutStatus, float fPriority, float fMaxDistance, bool bLayered, bool bDebug, int iTypeMask );

MTA10/mods/shared_logic/CClientRenderElementManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ CClientRenderElementManager::~CClientRenderElementManager ( void )
5252
//
5353
//
5454
////////////////////////////////////////////////////////////////
55-
CClientDxFont* CClientRenderElementManager::CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold )
55+
CClientDxFont* CClientRenderElementManager::CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, const DWORD ulQuality )
5656
{
5757
// Create the item
58-
CDxFontItem* pDxFontItem = m_pRenderItemManager->CreateDxFont ( strFullFilePath, uiSize, bBold );
58+
CDxFontItem* pDxFontItem = m_pRenderItemManager->CreateDxFont ( strFullFilePath, uiSize, bBold, ulQuality );
5959

6060
// Check create worked
6161
if ( !pDxFontItem )

MTA10/mods/shared_logic/CClientRenderElementManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CClientRenderElementManager
2525
CClientRenderElementManager ( CClientManager* pClientManager );
2626
~CClientRenderElementManager ( void );
2727

28-
CClientDxFont* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold );
28+
CClientDxFont* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY );
2929
CClientGuiFont* CreateGuiFont ( const SString& strFullFilePath, const SString& strUniqueName, uint uiSize );
3030
CClientTexture* CreateTexture ( const SString& strFullFilePath, const CPixels* pPixels = NULL, bool bMipMaps = true, uint uiSizeX = RDEFAULT, uint uiSizeY = RDEFAULT, ERenderFormat format = RFORMAT_UNKNOWN, ETextureAddress textureAddress = TADDRESS_WRAP, ETextureType textureType = TTYPE_TEXTURE, uint uiVolumeDepth = 1 );
3131
CClientShader* CreateShader ( const SString& strFullFilePath, const SString& strRootPath, SString& strOutStatus, float fPriority, float fMaxDistance, bool bLayered, bool bDebug, int iTypeMask );

MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Drawing.cpp

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -852,12 +852,13 @@ int CLuaFunctionDefs::dxUpdateScreenSource ( lua_State* luaVM )
852852
int CLuaFunctionDefs::dxCreateFont ( lua_State* luaVM )
853853
{
854854
// element dxCreateFont( string filepath [, int size=9, bool bold=false ] )
855-
SString strFilePath; int iSize; bool bBold;
855+
SString strFilePath, strQuality; int iSize; bool bBold;
856856

857857
CScriptArgReader argStream ( luaVM );
858858
argStream.ReadString ( strFilePath );
859859
argStream.ReadNumber ( iSize, 9 );
860860
argStream.ReadBool ( bBold, false );
861+
argStream.ReadString ( strQuality, "proof" );
861862

862863
if ( !argStream.HasErrors () )
863864
{
@@ -871,15 +872,53 @@ int CLuaFunctionDefs::dxCreateFont ( lua_State* luaVM )
871872
{
872873
if ( FileExists ( strPath ) )
873874
{
874-
CClientDxFont* pDxFont = g_pClientGame->GetManager ()->GetRenderElementManager ()->CreateDxFont ( strPath, iSize, bBold );
875-
if ( pDxFont )
875+
DWORD ulQuality = 0xFF;
876+
877+
strQuality = strQuality.ToLower();
878+
879+
if( strQuality.compare( "default" ) == 0 )
876880
{
877-
// Make it a child of the resource's file root ** CHECK Should parent be pFileResource, and element added to pParentResource's ElementGroup? **
878-
pDxFont->SetParent ( pParentResource->GetResourceDynamicEntity () );
879-
lua_pushelement ( luaVM, pDxFont );
880-
return 1;
881+
ulQuality = DEFAULT_QUALITY;
882+
}
883+
else if( strQuality.compare( "draft" ) == 0 )
884+
{
885+
ulQuality = DRAFT_QUALITY;
886+
}
887+
else if( strQuality.compare( "proof" ) == 0 )
888+
{
889+
ulQuality = PROOF_QUALITY;
890+
}
891+
else if( strQuality.compare( "nonantialiased" ) == 0 )
892+
{
893+
ulQuality = NONANTIALIASED_QUALITY;
894+
}
895+
else if( strQuality.compare( "antialiased" ) == 0 )
896+
{
897+
ulQuality = ANTIALIASED_QUALITY;
881898
}
882-
argStream.SetCustomError( strFilePath, "Error creating font" );
899+
else if( strQuality.compare( "cleartype" ) == 0 )
900+
{
901+
ulQuality = CLEARTYPE_QUALITY;
902+
}
903+
else if( strQuality.compare( "cleartype_natural" ) == 0 )
904+
{
905+
ulQuality = CLEARTYPE_NATURAL_QUALITY;
906+
}
907+
908+
if( ulQuality != 0xFF )
909+
{
910+
CClientDxFont* pDxFont = g_pClientGame->GetManager()->GetRenderElementManager()->CreateDxFont( strPath, iSize, bBold, ulQuality );
911+
if( pDxFont )
912+
{
913+
// Make it a child of the resource's file root ** CHECK Should parent be pFileResource, and element added to pParentResource's ElementGroup? **
914+
pDxFont->SetParent( pParentResource->GetResourceDynamicEntity() );
915+
lua_pushelement( luaVM, pDxFont );
916+
return 1;
917+
}
918+
argStream.SetCustomError( strFilePath, "Error creating font" );
919+
}
920+
else
921+
argStream.SetCustomError( strFilePath, "Invalid font quality" );
883922
}
884923
else
885924
argStream.SetCustomError( strFilePath, "File not found" );

MTA10/sdk/core/CGraphicsInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class CGraphicsInterface
7878
virtual float GetDXTextExtent ( const char * szText, float fScale = 1.0f, ID3DXFont * pDXFont = NULL, bool bColorCoded = false ) = 0;
7979

8080
virtual bool LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, ID3DXFont** ppD3DXFont ) = 0;
81+
virtual bool LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, DWORD ulQuality, ID3DXFont** ppD3DXFont ) = 0;
8182
virtual bool DestroyAdditionalDXFont ( std::string strFontPath, ID3DXFont* pD3DXFont ) = 0;
8283

8384
virtual ID3DXFont * GetFont ( eFontType fontType = FONT_DEFAULT, float* pfOutScaleUsed = NULL, float fRequestedScale = 1, const char* szCustomScaleUser = NULL ) = 0;

MTA10/sdk/core/CRenderItemManagerInterface.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class CRenderItemManagerInterface
134134

135135
// CRenderItemManagerInterface
136136
virtual void DoPulse ( void ) = 0;
137-
virtual CDxFontItem* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold ) = 0;
137+
virtual CDxFontItem* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY ) = 0;
138138
virtual CGuiFontItem* CreateGuiFont ( const SString& strFullFilePath, const SString& strFontName, uint uiSize ) = 0;
139139
virtual CTextureItem* CreateTexture ( const SString& strFullFilePath, const CPixels* pPixels = NULL, bool bMipMaps = true, uint uiSizeX = RDEFAULT, uint uiSizeY = RDEFAULT, ERenderFormat format = RFORMAT_UNKNOWN, ETextureAddress textureAddress = TADDRESS_WRAP, ETextureType textureType = TTYPE_TEXTURE, uint uiVolumeDepth = 1 ) = 0;
140140
virtual CShaderItem* CreateShader ( const SString& strFullFilePath, const SString& strRootPath, SString& strOutStatus, float fPriority, float fMaxDistance, bool bLayered, bool bDebug, int iTypeMask ) = 0;
@@ -259,12 +259,12 @@ class CDxFontItem : public CRenderItem
259259
{
260260
DECLARE_CLASS( CDxFontItem, CRenderItem )
261261
CDxFontItem ( void ) : ClassInit ( this ) {}
262-
virtual void PostConstruct ( CRenderItemManager* pManager, const SString& strFullFilePath, uint uiSize, bool bBold );
262+
virtual void PostConstruct ( CRenderItemManager* pManager, const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY );
263263
virtual void PreDestruct ( void );
264264
virtual bool IsValid ( void );
265265
virtual void OnLostDevice ( void );
266266
virtual void OnResetDevice ( void );
267-
void CreateUnderlyingData ( uint uiSize, bool bBold );
267+
void CreateUnderlyingData ( uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY );
268268
void ReleaseUnderlyingData ( void );
269269

270270
SString m_strFullFilePath;

0 commit comments

Comments
 (0)