W3DGameFont.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: W3DGameFont.cpp //////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: RTS3
  34. //
  35. // File name: W3DGameFont.cpp
  36. //
  37. // Created: Colin Day, June 2001
  38. //
  39. // Desc: W3D implementation for managing font definitions
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  44. #include <stdlib.h>
  45. // USER INCLUDES //////////////////////////////////////////////////////////////
  46. #include "Common/Debug.h"
  47. #include "W3DDevice/GameClient/W3DGameFont.h"
  48. #include "WW3D2/WW3D.h"
  49. #include "WW3D2/AssetMgr.h"
  50. #include "WW3D2/Render2DSentence.h"
  51. #include "GameClient/GlobalLanguage.h"
  52. // DEFINES ////////////////////////////////////////////////////////////////////
  53. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  54. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  55. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  56. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  57. ///////////////////////////////////////////////////////////////////////////////
  58. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  59. ///////////////////////////////////////////////////////////////////////////////
  60. // W3DFontLibrary::loadFontData ===============================================
  61. /** Load a font */
  62. //=============================================================================
  63. Bool W3DFontLibrary::loadFontData( GameFont *font )
  64. {
  65. FontCharsClass *fontChar;
  66. // sanity
  67. if( font == NULL )
  68. return FALSE;
  69. if ((UnsignedInt)font->pointSize > 100) //sanity check the size - anything over 100 is probably wrong. -MW
  70. fontChar = NULL;
  71. else
  72. { // get the font data from the asset manager
  73. fontChar = WW3DAssetManager::
  74. Get_Instance()->Get_FontChars( font->nameString.str(), font->pointSize,
  75. font->bold ? true : false );
  76. }
  77. if( fontChar == NULL )
  78. {
  79. DEBUG_LOG(( "W3D load font: unable to find font '%s' from asset manager\n",
  80. font->nameString.str() ));
  81. DEBUG_ASSERTCRASH(fontChar, ("Missing or Corrupted Font. Pleas see log for details"));
  82. return FALSE;
  83. } // end if
  84. // assign font data
  85. font->fontData = fontChar;
  86. font->height = fontChar->Get_Char_Height();
  87. FontCharsClass *unicodeFontChar = NULL;
  88. // load unicode of same point size
  89. if(TheGlobalLanguageData)
  90. unicodeFontChar = WW3DAssetManager::
  91. Get_Instance()->Get_FontChars( TheGlobalLanguageData->m_unicodeFontName.str(), font->pointSize,
  92. font->bold ? true : false );
  93. else
  94. unicodeFontChar = WW3DAssetManager::
  95. Get_Instance()->Get_FontChars( "Arial Unicode MS", font->pointSize,
  96. font->bold ? true : false );
  97. if ( unicodeFontChar )
  98. {
  99. fontChar->AlternateUnicodeFont = unicodeFontChar;
  100. }
  101. // all done and loaded
  102. return TRUE;
  103. } // end loadFont
  104. // W3DFontLibrary::releaseFontData ============================================
  105. /** Release font data */
  106. //=============================================================================
  107. void W3DFontLibrary::releaseFontData( GameFont *font )
  108. {
  109. // presently we don't need to do anything because fonts are handled in
  110. // the W3D asset manager which is all taken for of us
  111. if (font && font->fontData)
  112. {
  113. if(((FontCharsClass *)(font->fontData))->AlternateUnicodeFont)
  114. ((FontCharsClass *)(font->fontData))->AlternateUnicodeFont->Release_Ref();
  115. ((FontCharsClass *)(font->fontData))->Release_Ref();
  116. }
  117. font->fontData = NULL;
  118. } // end releaseFont
  119. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////