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.

165 lines
4.3 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: console support for fonts
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef PS3FONT_H
  8. #define PS3FONT_H
  9. #ifdef GetCharABCWidths
  10. #undef GetCharABCWidths
  11. #endif
  12. #include "UtlRBTree.h"
  13. #include "tier1/UtlSymbol.h"
  14. #include "vguifont.h"
  15. #if defined(_PS3)
  16. #if defined(HFONT)
  17. #error HFONT defined twice, which breaks the kooky typedef in ps3font.h
  18. #else
  19. typedef void * HPS3FONT ;
  20. #endif
  21. #include <cell/fontFT.h>
  22. #endif
  23. struct CPS3FontMetrics : public CellFontHorizontalLayout
  24. {
  25. float fMaxWidth; // must be initialized externally
  26. inline CPS3FontMetrics() : fMaxWidth(NAN) {};
  27. };
  28. // has some inline accessors to translate from PS3 members to XUI ones
  29. struct CPS3CharMetrics : public CellFontGlyphMetrics
  30. {
  31. inline int A() { return 0; }
  32. inline int B() { return ceilf( Horizontal.advance ); }
  33. inline int C() { return 0; }
  34. };
  35. //-----------------------------------------------------------------------------
  36. // Purpose: encapsulates a windows font
  37. //-----------------------------------------------------------------------------
  38. class CPS3Font
  39. {
  40. public:
  41. CPS3Font();
  42. ~CPS3Font();
  43. // creates the font from windows. returns false if font does not exist in the OS.
  44. virtual bool Create(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
  45. // writes the char into the specified 32bpp texture
  46. virtual void GetCharsRGBA( newChar_t *newChars, int numNewChars, unsigned char *pRGBA );
  47. virtual void GetCharRGBA( wchar_t ch, int rgbaWide, int rgbaTall, unsigned char *pRGBA );
  48. // returns true if the font is equivalent to that specified
  49. virtual bool IsEqualTo(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
  50. // returns true only if this font is valid for use
  51. virtual bool IsValid();
  52. // gets the abc widths for a character
  53. virtual void GetCharABCWidths(int ch, int &a, int &b, int &c);
  54. virtual void GetKernedCharWidth( wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA, float &abcC );
  55. // returns the height of the font, in pixels
  56. virtual int GetHeight();
  57. // returns the ascent of the font, in pixels (ascent=units above the base line)
  58. virtual int GetAscent();
  59. // returns the maximum width of a character, in pixels
  60. virtual int GetMaxCharWidth();
  61. // returns the flags used to make this font
  62. virtual int GetFlags();
  63. // returns true if this font is underlined
  64. bool GetUnderlined() { return m_bUnderlined; }
  65. // gets the name of this font
  66. const char *GetName() { return m_szName.String(); }
  67. // dump the system resource, if it's open
  68. void CloseResource();
  69. enum FontStyleFlags_t
  70. {
  71. kFONT_STYLE_NORMAL = 0,
  72. kFONT_STYLE_ITALIC = 2,
  73. kFONT_STYLE_UNDERLINE = 4,
  74. kFONT_STYLE_BOLD = 8,
  75. };
  76. private:
  77. #if !defined( _GAMECONSOLE )
  78. HFONT m_hFont;
  79. HDC m_hDC;
  80. HBITMAP m_hDIB;
  81. #elif defined ( _PS3 )
  82. HPS3FONT m_hFont;
  83. #elif defined( _X360 )
  84. HXUIFONT m_hFont;
  85. HDC m_hDC;
  86. #endif
  87. // pointer to buffer for use when generated bitmap versions of a texture
  88. unsigned char *m_pBuf;
  89. protected:
  90. CUtlSymbol m_szName;
  91. short m_iTall;
  92. int m_iWeight;
  93. unsigned short m_iFlags;
  94. unsigned short m_iScanLines;
  95. unsigned short m_iBlur;
  96. unsigned short m_rgiBitmapSize[2];
  97. unsigned int m_iHeight : 8;
  98. unsigned int m_iMaxCharWidth : 8;
  99. unsigned int m_iAscent : 8;
  100. unsigned int m_iDropShadowOffset : 1;
  101. unsigned int m_iOutlineSize : 1;
  102. unsigned int m_bAntiAliased : 1;
  103. unsigned int m_bRotary : 1;
  104. unsigned int m_bAdditive : 1;
  105. unsigned int m_bUnderlined : 1; //30
  106. private:
  107. // abc widths
  108. struct abc_t
  109. {
  110. short b;
  111. char a;
  112. char c;
  113. };
  114. // cache for additional or asian characters (since it's too big too just store them all)
  115. struct abc_cache_t
  116. {
  117. wchar_t wch;
  118. abc_t abc;
  119. };
  120. CUtlRBTree<abc_cache_t, unsigned short> m_ExtendedABCWidthsCache;
  121. static bool ExtendedABCWidthsCacheLessFunc(const abc_cache_t &lhs, const abc_cache_t &rhs);
  122. // First range of characters are automatically cached
  123. #if defined( _PS3 )
  124. enum { ABCWIDTHS_CACHE_SIZE = 256 }; // was 128
  125. abc_t m_ABCWidthsCache[ABCWIDTHS_CACHE_SIZE];
  126. #elif defined( _X360 )
  127. // 360 requires all possible characters during font init
  128. enum { ABCWIDTHS_CACHE_SIZE = 256 };
  129. abc_t m_ABCWidthsCache[ABCWIDTHS_CACHE_SIZE];
  130. #endif
  131. };
  132. #endif // PS3FONT_H