Team Fortress 2 Source Code as on 22/4/2020
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.

148 lines
3.9 KiB

  1. //========= Copyright 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 )
  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. struct newChar_t;
  23. //-----------------------------------------------------------------------------
  24. // Purpose: encapsulates a windows font
  25. //-----------------------------------------------------------------------------
  26. class CWin32Font
  27. {
  28. public:
  29. CWin32Font();
  30. ~CWin32Font();
  31. // creates the font from windows. returns false if font does not exist in the OS.
  32. virtual bool Create(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
  33. // writes the char into the specified 32bpp texture
  34. virtual void GetCharRGBA(wchar_t ch, int rgbaWide, int rgbaTall, unsigned char *rgba);
  35. // returns true if the font is equivalent to that specified
  36. virtual bool IsEqualTo(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
  37. // returns true only if this font is valid for use
  38. virtual bool IsValid();
  39. // gets the abc widths for a character
  40. virtual void GetCharABCWidths(int ch, int &a, int &b, int &c);
  41. // set the font to be the one to currently draw with in the gdi
  42. virtual void SetAsActiveFont(HDC hdc);
  43. // returns the height of the font, in pixels
  44. virtual int GetHeight();
  45. // returns requested height of font.
  46. virtual int GetHeightRequested();
  47. // returns the ascent of the font, in pixels (ascent=units above the base line)
  48. virtual int GetAscent();
  49. // returns the maximum width of a character, in pixels
  50. virtual int GetMaxCharWidth();
  51. // returns the flags used to make this font
  52. virtual int GetFlags();
  53. // returns true if this font is underlined
  54. bool GetUnderlined() { return m_bUnderlined; }
  55. // gets the name of this font
  56. const char *GetName() { return m_szName.String(); }
  57. const char *GetFamilyName() { return NULL; }
  58. // gets the width of ch given its position around before and after chars
  59. void GetKernedCharWidth( wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA );
  60. #if defined( _X360 )
  61. // generates texture data for a set of chars
  62. virtual void GetCharsRGBA( newChar_t *newChars, int numNewChars, unsigned char *pRGBA );
  63. virtual void CloseResource();
  64. #endif
  65. private:
  66. #if !defined( _X360 )
  67. HFONT m_hFont;
  68. HDC m_hDC;
  69. HBITMAP m_hDIB;
  70. #else
  71. HXUIFONT m_hFont;
  72. HDC m_hDC;
  73. #endif
  74. // pointer to buffer for use when generated bitmap versions of a texture
  75. unsigned char *m_pBuf;
  76. protected:
  77. CUtlSymbol m_szName;
  78. short m_iTall;
  79. unsigned short m_iWeight;
  80. unsigned short m_iFlags;
  81. unsigned short m_iScanLines;
  82. unsigned short m_iBlur;
  83. unsigned short m_rgiBitmapSize[2];
  84. bool m_bUnderlined;
  85. unsigned int m_iHeight : 8;
  86. unsigned int m_iMaxCharWidth : 8;
  87. unsigned int m_iAscent : 8;
  88. unsigned int m_iDropShadowOffset : 1;
  89. unsigned int m_iOutlineSize : 1;
  90. unsigned int m_bAntiAliased : 1;
  91. unsigned int m_bRotary : 1;
  92. unsigned int m_bAdditive : 1; //29
  93. private:
  94. // abc widths
  95. struct abc_t
  96. {
  97. short b;
  98. char a;
  99. char c;
  100. };
  101. #if !defined( _X360 )
  102. // On PC we cache char widths on demand when actually requested to minimize our use of the kernels
  103. // paged pool (GDI may cache information about glyphs we have requested and take up lots of paged pool)
  104. struct abc_cache_t
  105. {
  106. wchar_t wch;
  107. abc_t abc;
  108. };
  109. CUtlRBTree<abc_cache_t, unsigned short> m_ExtendedABCWidthsCache;
  110. static bool ExtendedABCWidthsCacheLessFunc(const abc_cache_t &lhs, const abc_cache_t &rhs);
  111. #else
  112. // 360 requires all possible characters during font init
  113. enum { ABCWIDTHS_CACHE_SIZE = 256 };
  114. abc_t m_ABCWidthsCache[ABCWIDTHS_CACHE_SIZE];
  115. #endif
  116. };
  117. #endif // WIN32FONT_H