Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
4.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef WIN32FONT_H
  8. #define WIN32FONT_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #if !defined( _X360 ) && !defined( _PS3 )
  13. #define WIN32_LEAN_AND_MEAN
  14. #define OEMRESOURCE
  15. #include <windows.h>
  16. #endif
  17. #ifdef GetCharABCWidths
  18. #undef GetCharABCWidths
  19. #endif
  20. #include "utlrbtree.h"
  21. #include "tier1/utlsymbol.h"
  22. #if defined(_PS3)
  23. class IFont;
  24. #endif
  25. //-----------------------------------------------------------------------------
  26. // Purpose: encapsulates a windows font
  27. //-----------------------------------------------------------------------------
  28. class CWin32Font
  29. {
  30. public:
  31. CWin32Font();
  32. ~CWin32Font();
  33. // creates the font from windows. returns false if font does not exist in the OS.
  34. virtual bool Create(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
  35. // writes the char into the specified 32bpp texture
  36. virtual void GetCharRGBA(wchar_t ch, int rgbaWide, int rgbaTall, unsigned char *rgba);
  37. // returns true if the font is equivalent to that specified
  38. virtual bool IsEqualTo(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
  39. // returns true only if this font is valid for use
  40. virtual bool IsValid();
  41. // gets the abc widths for a character
  42. virtual void GetCharABCWidths(int ch, int &a, int &b, int &c);
  43. #if !defined (_PS3)
  44. // set the font to be the one to currently draw with in the gdi
  45. virtual void SetAsActiveFont(HDC hdc);
  46. #endif
  47. // returns the height of the font, in pixels
  48. virtual int GetHeight();
  49. // returns the ascent of the font, in pixels (ascent=units above the base line)
  50. virtual int GetAscent();
  51. // returns the maximum width of a character, in pixels
  52. virtual int GetMaxCharWidth();
  53. // returns the flags used to make this font
  54. virtual int GetFlags();
  55. // returns true if this font is underlined
  56. bool GetUnderlined() { return m_bUnderlined; }
  57. // gets the name of this font
  58. const char *GetName() { return m_szName.String(); }
  59. // gets the width of ch given its position around before and after chars
  60. virtual void GetKernedCharWidth( wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA, float &abcC );
  61. #if defined( _X360 )
  62. // generates texture data for a set of chars
  63. virtual void GetCharsRGBA( newChar_t *newChars, int numNewChars, unsigned char *pRGBA );
  64. virtual void CloseResource();
  65. #endif
  66. private:
  67. #if !defined( _GAMECONSOLE )
  68. HFONT m_hFont;
  69. HDC m_hDC;
  70. HBITMAP m_hDIB;
  71. #elif defined ( _PS3 )
  72. IFont *m_pFont;
  73. #elif defined( _X360 )
  74. HXUIFONT m_hFont;
  75. HDC m_hDC;
  76. #endif
  77. // pointer to buffer for use when generated bitmap versions of a texture
  78. unsigned char *m_pBuf;
  79. protected:
  80. CUtlSymbol m_szName;
  81. short m_iTall;
  82. #ifdef _PS3
  83. int m_iWeight;
  84. #else
  85. unsigned short m_iWeight;
  86. #endif
  87. unsigned short m_iFlags;
  88. unsigned short m_iScanLines;
  89. unsigned short m_iBlur;
  90. unsigned short m_rgiBitmapSize[2];
  91. unsigned int m_iHeight : 8;
  92. unsigned int m_iMaxCharWidth : 8;
  93. unsigned int m_iAscent : 8;
  94. unsigned int m_iDropShadowOffset : 1;
  95. unsigned int m_iOutlineSize : 1;
  96. unsigned int m_bAntiAliased : 1;
  97. unsigned int m_bRotary : 1;
  98. unsigned int m_bAdditive : 1;
  99. unsigned int m_bUnderlined : 1; //30
  100. private:
  101. // abc widths
  102. struct abc_t
  103. {
  104. short b;
  105. char a;
  106. char c;
  107. };
  108. // cache for additional or asian characters (since it's too big too just store them all)
  109. struct abc_cache_t
  110. {
  111. wchar_t wch;
  112. abc_t abc;
  113. };
  114. CUtlRBTree<abc_cache_t, unsigned short> m_ExtendedABCWidthsCache;
  115. static bool ExtendedABCWidthsCacheLessFunc(const abc_cache_t &lhs, const abc_cache_t &rhs);
  116. // First range of characters are automatically cached
  117. #if defined( _PS3 )
  118. enum { ABCWIDTHS_CACHE_SIZE = 128 };
  119. abc_t m_ABCWidthsCache[ABCWIDTHS_CACHE_SIZE];
  120. #elif defined( _X360 )
  121. // 360 requires all possible characters during font init
  122. enum { ABCWIDTHS_CACHE_SIZE = 256 };
  123. abc_t m_ABCWidthsCache[ABCWIDTHS_CACHE_SIZE];
  124. #endif
  125. };
  126. #endif // WIN32FONT_H