Skip to content

Commit 6091c2c

Browse files
committed
Merge pull request #4 from Kernell/master
Added quality argument for dxCreateFont
2 parents b5ed33f + f609388 commit 6091c2c

12 files changed

+65
-21
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
@@ -263,13 +263,13 @@ CShaderItem* CRenderItemManager::CreateShader ( const SString& strFullFilePath,
263263
// TODO: Make underlying data for fonts shared
264264
//
265265
////////////////////////////////////////////////////////////////
266-
CDxFontItem* CRenderItemManager::CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold )
266+
CDxFontItem* CRenderItemManager::CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality )
267267
{
268268
if ( !CanCreateRenderItem ( CDxFontItem::GetClassId () ) )
269269
return NULL;
270270

271271
CDxFontItem* pDxFontItem = new CDxFontItem ();
272-
pDxFontItem->PostConstruct ( this, strFullFilePath, uiSize, bBold );
272+
pDxFontItem->PostConstruct ( this, strFullFilePath, uiSize, bBold, ulQuality );
273273

274274
if ( !pDxFontItem->IsValid () )
275275
{

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
@@ -53,10 +53,10 @@ CClientRenderElementManager::~CClientRenderElementManager ( void )
5353
//
5454
//
5555
////////////////////////////////////////////////////////////////
56-
CClientDxFont* CClientRenderElementManager::CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold )
56+
CClientDxFont* CClientRenderElementManager::CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, const DWORD ulQuality )
5757
{
5858
// Create the item
59-
CDxFontItem* pDxFontItem = m_pRenderItemManager->CreateDxFont ( strFullFilePath, uiSize, bBold );
59+
CDxFontItem* pDxFontItem = m_pRenderItemManager->CreateDxFont ( strFullFilePath, uiSize, bBold, ulQuality );
6060

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

MTA10/mods/shared_logic/CClientRenderElementManager.h

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

29-
CClientDxFont* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold );
29+
CClientDxFont* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY );
3030
CClientGuiFont* CreateGuiFont ( const SString& strFullFilePath, const SString& strUniqueName, uint uiSize );
3131
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 );
3232
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: 8 additions & 5 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; int iSize; bool bBold; eFontQuality ulFontQuality;
856856

857857
CScriptArgReader argStream ( luaVM );
858858
argStream.ReadString ( strFilePath );
859859
argStream.ReadNumber ( iSize, 9 );
860860
argStream.ReadBool ( bBold, false );
861+
argStream.ReadEnumString ( ulFontQuality, FONT_QUALITY_PROOF );
861862

862863
if ( !argStream.HasErrors () )
863864
{
@@ -871,14 +872,16 @@ 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+
CClientDxFont* pDxFont = g_pClientGame->GetManager()->GetRenderElementManager()->CreateDxFont( strPath, iSize, bBold, ulFontQuality );
876+
877+
if( pDxFont )
876878
{
877879
// 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+
pDxFont->SetParent( pParentResource->GetResourceDynamicEntity() );
881+
lua_pushelement( luaVM, pDxFont );
880882
return 1;
881883
}
884+
882885
argStream.SetCustomError( strFilePath, "Error creating font" );
883886
}
884887
else

MTA10/mods/shared_logic/lua/CLuaFunctionParseHelpers.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,20 @@ IMPLEMENT_ENUM_BEGIN( eFontType )
394394
ADD_ENUM( FONT_BECKETT, "beckett" )
395395
IMPLEMENT_ENUM_END_DEFAULTS( "font-type", FONT_DEFAULT, "" )
396396

397+
IMPLEMENT_ENUM_BEGIN( eFontQuality )
398+
ADD_ENUM( FONT_QUALITY_DEFAULT, "default" )
399+
ADD_ENUM( FONT_QUALITY_DRAFT, "draft" )
400+
ADD_ENUM( FONT_QUALITY_PROOF, "proof" )
401+
#if( WINVER >= 0x0400 )
402+
ADD_ENUM( FONT_QUALITY_NONANTIALIASED, "nonantialiased" )
403+
ADD_ENUM( FONT_QUALITY_ANTIALIASED, "antialiased" )
404+
#endif
405+
#if( _WIN32_WINNT >= _WIN32_WINNT_WINXP )
406+
ADD_ENUM( FONT_QUALITY_CLEARTYPE, "cleartype" )
407+
ADD_ENUM( FONT_QUALITY_CLEARTYPE_NATURAL, "cleartype_natural" )
408+
#endif
409+
IMPLEMENT_ENUM_END_DEFAULTS( "font-quality", FONT_QUALITY_DEFAULT, "" )
410+
397411
IMPLEMENT_ENUM_BEGIN ( eAudioLookupIndex )
398412
ADD_ENUM ( AUDIO_LOOKUP_FEET, "feet" )
399413
ADD_ENUM ( AUDIO_LOOKUP_GENRL, "genrl" )

MTA10/mods/shared_logic/lua/CLuaFunctionParseHelpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ DECLARE_ENUM( eWeaponState );
3636
DECLARE_ENUM( eWeaponFlags );
3737
DECLARE_ENUM( eVehicleComponent );
3838
DECLARE_ENUM( eFontType );
39+
DECLARE_ENUM( eFontQuality );
3940
DECLARE_ENUM( eAudioLookupIndex );
4041
DECLARE_ENUM( eAspectRatio );
4142
DECLARE_ENUM( eRadioStreamIndex );

MTA10/sdk/core/CGraphicsInterface.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ enum eFontType
3333
NUM_FONTS
3434
};
3535

36+
enum eFontQuality
37+
{
38+
FONT_QUALITY_DEFAULT = DEFAULT_QUALITY,
39+
FONT_QUALITY_DRAFT = DRAFT_QUALITY,
40+
FONT_QUALITY_PROOF = PROOF_QUALITY,
41+
42+
#if( WINVER >= 0x0400 )
43+
FONT_QUALITY_NONANTIALIASED = NONANTIALIASED_QUALITY,
44+
FONT_QUALITY_ANTIALIASED = ANTIALIASED_QUALITY,
45+
#endif
46+
47+
#if( _WIN32_WINNT >= _WIN32_WINNT_WINXP )
48+
FONT_QUALITY_CLEARTYPE = CLEARTYPE_QUALITY,
49+
FONT_QUALITY_CLEARTYPE_NATURAL = CLEARTYPE_NATURAL_QUALITY,
50+
#endif
51+
52+
NUM_QUALITIES
53+
};
54+
3655
namespace EBlendMode
3756
{
3857
enum EBlendModeType
@@ -78,6 +97,7 @@ class CGraphicsInterface
7897
virtual float GetDXTextExtent ( const char * szText, float fScale = 1.0f, ID3DXFont * pDXFont = NULL, bool bColorCoded = false ) = 0;
7998

8099
virtual bool LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, ID3DXFont** ppD3DXFont ) = 0;
100+
virtual bool LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, DWORD ulQuality, ID3DXFont** ppD3DXFont ) = 0;
81101
virtual bool DestroyAdditionalDXFont ( std::string strFontPath, ID3DXFont* pD3DXFont ) = 0;
82102

83103
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
@@ -136,7 +136,7 @@ class CRenderItemManagerInterface
136136

137137
// CRenderItemManagerInterface
138138
virtual void DoPulse ( void ) = 0;
139-
virtual CDxFontItem* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold ) = 0;
139+
virtual CDxFontItem* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY ) = 0;
140140
virtual CGuiFontItem* CreateGuiFont ( const SString& strFullFilePath, const SString& strFontName, uint uiSize ) = 0;
141141
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;
142142
virtual CShaderItem* CreateShader ( const SString& strFullFilePath, const SString& strRootPath, SString& strOutStatus, float fPriority, float fMaxDistance, bool bLayered, bool bDebug, int iTypeMask ) = 0;
@@ -263,12 +263,12 @@ class CDxFontItem : public CRenderItem
263263
{
264264
DECLARE_CLASS( CDxFontItem, CRenderItem )
265265
CDxFontItem ( void ) : ClassInit ( this ) {}
266-
virtual void PostConstruct ( CRenderItemManager* pManager, const SString& strFullFilePath, uint uiSize, bool bBold );
266+
virtual void PostConstruct ( CRenderItemManager* pManager, const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY );
267267
virtual void PreDestruct ( void );
268268
virtual bool IsValid ( void );
269269
virtual void OnLostDevice ( void );
270270
virtual void OnResetDevice ( void );
271-
void CreateUnderlyingData ( uint uiSize, bool bBold );
271+
void CreateUnderlyingData ( uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY );
272272
void ReleaseUnderlyingData ( void );
273273

274274
SString m_strFullFilePath;

0 commit comments

Comments
 (0)