Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Core/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,8 @@ Render2DSentenceClass::Build_Sentence (const WCHAR *text, int *hkX, int *hkY)
return ;
}

if (Font == NULL)
return;

if(Centered && (WrapWidth > 0 || wcschr(text,L'\n')))
Build_Sentence_Centered(text, hkX, hkY);
Expand Down Expand Up @@ -1504,7 +1506,7 @@ FontCharsClass::Update_Current_Buffer (int char_width)
// Create_GDI_Font
//
////////////////////////////////////////////////////////////////////////////////////
void
bool
FontCharsClass::Create_GDI_Font (const char *font_name)
{
HDC screen_dc = ::GetDC ((HWND)WW3D::Get_Window());
Expand Down Expand Up @@ -1598,6 +1600,8 @@ FontCharsClass::Create_GDI_Font (const char *font_name)
if (doingGenerals) {
CharOverhang = 0;
}

return GDIFont != NULL && GDIBitmap != NULL;
}


Expand Down Expand Up @@ -1646,7 +1650,7 @@ FontCharsClass::Free_GDI_Font (void)
// Initialize_GDI_Font
//
////////////////////////////////////////////////////////////////////////////////////
void
bool
FontCharsClass::Initialize_GDI_Font (const char *font_name, int point_size, bool is_bold)
{
//
Expand All @@ -1664,8 +1668,7 @@ FontCharsClass::Initialize_GDI_Font (const char *font_name, int point_size, bool
//
// Create the actual font object
//
Create_GDI_Font (font_name);
return ;
return Create_GDI_Font (font_name);
}


Expand Down
4 changes: 2 additions & 2 deletions Core/Libraries/Source/WWVegas/WW3D2/render2dsentence.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class FontCharsClass : public W3DMPO, public RefCountClass
FontCharsClass *AlternateUnicodeFont;


void Initialize_GDI_Font( const char *font_name, int point_size, bool is_bold );
bool Initialize_GDI_Font( const char *font_name, int point_size, bool is_bold );
bool Is_Font( const char *font_name, int point_size, bool is_bold );
const char * Get_Name( void ) { return Name; }

Expand All @@ -99,7 +99,7 @@ class FontCharsClass : public W3DMPO, public RefCountClass
//
// Private methods
//
void Create_GDI_Font( const char *font_name );
bool Create_GDI_Font( const char *font_name );
void Free_GDI_Font( void );
const FontCharsClassCharDataStruct * Store_GDI_Char( WCHAR ch );
void Update_Current_Buffer( int char_width );
Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/Source/GameClient/Credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void CreditsManager::load(void )
TheGlobalLanguageData->adjustFontSize(TheGlobalLanguageData->m_creditsNormalFont.size),
TheGlobalLanguageData->m_creditsNormalFont.bold);

m_normalFontHeight = font->height;
m_normalFontHeight = font ? font->height : 0;
}

void CreditsManager::reset( void )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ void IMECandidateTextAreaDraw( GameWindow *window, WinInstanceData *instData )
return;
}

GameFont *font = window->winGetFont() ;
Int height;
GameFont *font = window->winGetFont();

// set the font
Dstring->setFont( font );

// cacl line height
height = font->height + IMECandidateWindowLineSpacing;
// calculate line height
Int fontHeight = font ? font->height : 0;
Int height = fontHeight + IMECandidateWindowLineSpacing;

// set the clip region
Dstring->setClipRegion( &textRegion );
Expand Down
7 changes: 7 additions & 0 deletions Generals/Code/GameEngine/Source/GameClient/GUI/GameFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ void FontLibrary::reset( void )
//-------------------------------------------------------------------------------------------------
GameFont *FontLibrary::getFont( AsciiString name, Int pointSize, Bool bold )
{
// sanity check the size - anything over 100 is probably wrong. -MW
// TheSuperHackers @fix Now also no longer creates fonts with zero size.
if (pointSize < 1 || pointSize > 100)
{
return NULL;
}

GameFont *font;

// search for font in list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ void GameWindowManager::winGetTextSize( GameFont *font, UnicodeString text,
Int GameWindowManager::winFontHeight( GameFont *font )
{

if (font == NULL)
return 0;

return font->height;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,9 @@ static Bool parseFont( const char *token, WinInstanceData *instData,

if( TheFontLibrary )
{
GameFont *font;

font = TheFontLibrary->getFont( AsciiString(fontName), fontSize, fontBold );
GameFont *font = TheFontLibrary->getFont( AsciiString(fontName), fontSize, fontBold );
if( font )
instData->m_font = font;

}

return TRUE;
Expand Down
6 changes: 4 additions & 2 deletions Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3618,8 +3618,10 @@ void InGameUI::postDraw( void )
m_uiMessages[ i ].displayString->draw( x, y, m_uiMessages[ i ].color, dropColor );

// increment text spot to next location
GameFont *font = m_uiMessages[ i ].displayString->getFont();
y += font->height;
if (GameFont *font = m_uiMessages[ i ].displayString->getFont())
{
y += font->height;
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,55 +73,32 @@
//=============================================================================
Bool W3DFontLibrary::loadFontData( GameFont *font )
{
FontCharsClass *fontChar;

// sanity
if( font == NULL )
return FALSE;

if ((UnsignedInt)font->pointSize > 100) //sanity check the size - anything over 100 is probably wrong. -MW

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this test higher up the call chain for simplicity. getFont is the only caller of loadFontData.

fontChar = NULL;
else
{ // get the font data from the asset manager
fontChar = WW3DAssetManager::
Get_Instance()->Get_FontChars( font->nameString.str(), font->pointSize,
font->bold ? true : false );
}
const char* name = font->nameString.str();
const Int size = font->pointSize;
const Bool bold = font->bold;

// get the font data from the asset manager
FontCharsClass *fontChar = WW3DAssetManager::Get_Instance()->Get_FontChars( name, size, bold );

if( fontChar == NULL )
Comment thread
xezon marked this conversation as resolved.
{

DEBUG_LOG(( "W3D load font: unable to find font '%s' from asset manager",
font->nameString.str() ));
DEBUG_ASSERTCRASH(fontChar, ("Missing or Corrupted Font. Pleas see log for details"));
DEBUG_CRASH(( "Unable to find font '%s' in Asset Manager", name ));
return FALSE;

}

// assign font data
font->fontData = fontChar;
font->height = fontChar->Get_Char_Height();

FontCharsClass *unicodeFontChar = NULL;
// load Unicode of same point size
name = TheGlobalLanguageData ? TheGlobalLanguageData->m_unicodeFontName.str() : "Arial Unicode MS";
fontChar->AlternateUnicodeFont = WW3DAssetManager::Get_Instance()->Get_FontChars( name, size, bold );

// load unicode of same point size
if(TheGlobalLanguageData)
unicodeFontChar = WW3DAssetManager::
Get_Instance()->Get_FontChars( TheGlobalLanguageData->m_unicodeFontName.str(), font->pointSize,
font->bold ? true : false );
else
unicodeFontChar = WW3DAssetManager::
Get_Instance()->Get_FontChars( "Arial Unicode MS", font->pointSize,
font->bold ? true : false );

if ( unicodeFontChar )
{
fontChar->AlternateUnicodeFont = unicodeFontChar;
}

// all done and loaded
return TRUE;

}

// W3DFontLibrary::releaseFontData ============================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,14 @@ void W3DGameWindow::winDrawBorder( void )
}

// W3DGameWindow::winSetFont ==================================================
/** Set the font for a widow */
/** Set the font for a window */
//=============================================================================
void W3DGameWindow::winSetFont( GameFont *font )
{

if (font == NULL)
return;

// extending functionality
GameWindow::winSetFont( font );

Expand Down
15 changes: 10 additions & 5 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/assetmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1485,12 +1485,17 @@ FontCharsClass * WW3DAssetManager::Get_FontChars( const char * name, int point_s
}
}

// If one hasn't been found, create it
// If one hasn't been found, try create it
FontCharsClass * font = NEW_REF( FontCharsClass, () );
font->Initialize_GDI_Font( name, point_size, is_bold );
font->Add_Ref();
FontCharsList.Add( font ); // add it to the list
return font; // return it
if (font->Initialize_GDI_Font( name, point_size, is_bold ))
{
font->Add_Ref();
FontCharsList.Add( font );
return font;
}

font->Release_Ref();
return NULL;
}


Expand Down
10 changes: 7 additions & 3 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/assetmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class RenderObjIterator : public AssetIterator
-------------------------------------------------------------------------------------
Dec 11, 1997, Asset Manager Brainstorming:

- WW3DAssetManager will be diferentiated from other game data asset managers
- WW3DAssetManager will be differentiated from other game data asset managers
(sounds, strings, etc) because they behave differently and serve different
purposes

Expand Down Expand Up @@ -172,6 +172,10 @@ class RenderObjIterator : public AssetIterator
the prototype class needs to be able to tell you the class ID. Actually this
code only seems to be used by tools such as SView but is needed anyway...

-------------------------------------------------------------------------------------
TheSuperHackers @fix xezon 08/11/2025
The Asset Manager will now return null when it cannot find or create a valid font
with the given inputs. This way the user knows that the requested font is unusable.
*/


Expand Down Expand Up @@ -275,12 +279,12 @@ class WW3DAssetManager

/*
** Access to Font3DInstances. (These are not saved, we just use the
** asset manager as a convienient way to create them.)
** asset manager as a convenient way to create them.)
*/
virtual Font3DInstanceClass * Get_Font3DInstance( const char * name);

/*
** Access to FontChars. Used by Render2DSentenceClass
** Access to FontChars. Used by Render2DSentenceClass. Can return null.
*/
virtual FontCharsClass * Get_FontChars( const char * name, int point_size, bool is_bold = false );

Expand Down
2 changes: 1 addition & 1 deletion GeneralsMD/Code/GameEngine/Source/GameClient/Credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void CreditsManager::load(void )
TheGlobalLanguageData->adjustFontSize(TheGlobalLanguageData->m_creditsNormalFont.size),
TheGlobalLanguageData->m_creditsNormalFont.bold);

m_normalFontHeight = font->height;
m_normalFontHeight = font ? font->height : 0;
}

void CreditsManager::reset( void )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ void IMECandidateTextAreaDraw( GameWindow *window, WinInstanceData *instData )
return;
}

GameFont *font = window->winGetFont() ;
Int height;
GameFont *font = window->winGetFont();

// set the font
Dstring->setFont( font );

// cacl line height
height = font->height + IMECandidateWindowLineSpacing;
// calculate line height
Int fontHeight = font ? font->height : 0;
Int height = fontHeight + IMECandidateWindowLineSpacing;

// set the clip region
Dstring->setClipRegion( &textRegion );
Expand Down
7 changes: 7 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ void FontLibrary::reset( void )
//-------------------------------------------------------------------------------------------------
GameFont *FontLibrary::getFont( AsciiString name, Int pointSize, Bool bold )
{
// sanity check the size - anything over 100 is probably wrong. -MW
// TheSuperHackers @fix Now also no longer creates fonts with zero size.
if (pointSize < 1 || pointSize > 100)
{
return NULL;
}

GameFont *font;

// search for font in list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ void GameWindowManager::winGetTextSize( GameFont *font, UnicodeString text,
Int GameWindowManager::winFontHeight( GameFont *font )
{

if (font == NULL)
return 0;

return font->height;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,9 @@ static Bool parseFont( const char *token, WinInstanceData *instData,

if( TheFontLibrary )
{
GameFont *font;

font = TheFontLibrary->getFont( AsciiString(fontName), fontSize, fontBold );
GameFont *font = TheFontLibrary->getFont( AsciiString(fontName), fontSize, fontBold );
if( font )
instData->m_font = font;

}

return TRUE;
Expand Down
6 changes: 4 additions & 2 deletions GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3709,8 +3709,10 @@ void InGameUI::postDraw( void )
m_uiMessages[ i ].displayString->draw( x, y, m_uiMessages[ i ].color, dropColor );

// increment text spot to next location
GameFont *font = m_uiMessages[ i ].displayString->getFont();
y += font->height;
if (GameFont *font = m_uiMessages[ i ].displayString->getFont())
{
y += font->height;
}

}

Expand Down
Loading
Loading