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.

168 lines
4.5 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef LINUXFONT_H
  8. #define LINUXFONT_H
  9. #include "utlrbtree.h"
  10. #include <tier0/memdbgoff.h>
  11. #include <tier0/memdbgon.h>
  12. #include "tier1/strtools.h"
  13. #include "tier1/utlstring.h"
  14. #include <ft2build.h>
  15. #include FT_FREETYPE_H
  16. //-----------------------------------------------------------------------------
  17. // Purpose: encapsulates a OSX font
  18. //-----------------------------------------------------------------------------
  19. class CLinuxFont
  20. {
  21. public:
  22. CLinuxFont();
  23. ~CLinuxFont();
  24. // creates the font from windows. returns false if font does not exist in the OS.
  25. virtual bool Create(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
  26. // writes the char into the specified 32bpp texture
  27. virtual void GetCharRGBA( wchar_t ch, int rgbaWide, int rgbaTall, unsigned char *rgba);
  28. // returns true if the font is equivalent to that specified
  29. virtual bool IsEqualTo(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
  30. // returns true only if this font is valid for use
  31. virtual bool IsValid();
  32. // gets the abc widths for a character
  33. virtual void GetCharABCWidths(int ch, int &a, int &b, int &c);
  34. // set the font to be the one to currently draw with in the gdi
  35. void *SetAsActiveFont( void *glContext );
  36. // returns the height of the font, in pixels
  37. virtual int GetHeight();
  38. // returns the ascent of the font, in pixels (ascent=units above the base line)
  39. virtual int GetAscent();
  40. // returns the maximum width of a character, in pixels
  41. virtual int GetMaxCharWidth();
  42. // returns the flags used to make this font
  43. virtual int GetFlags();
  44. // returns true if this font is underlined
  45. virtual bool GetUnderlined() { return m_bUnderlined; }
  46. // gets the name of this font
  47. const char *GetName() { return m_szName.String(); }
  48. // gets the weight of the font
  49. virtual int GetWeight() { return m_iWeight; }
  50. // gets the width of ch given its position around before and after chars
  51. virtual void GetKernedCharWidth( wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA, float &abcC );
  52. #ifdef DBGFLAG_VALIDATE
  53. void Validate( CValidator &validator, char *pchName );
  54. #endif
  55. virtual bool CreateFromMemory(const char *windowsFontName, void *data, int size, int tall, int weight, int blur, int scanlines, int flags);
  56. protected:
  57. CUtlString m_szName;
  58. int m_iTall;
  59. int m_iWeight;
  60. int m_iFlags;
  61. bool m_bAntiAliased;
  62. bool m_bRotary;
  63. bool m_bAdditive;
  64. int m_iDropShadowOffset;
  65. bool m_bUnderlined;
  66. int m_iOutlineSize;
  67. int m_iHeight;
  68. int m_iMaxCharWidth;
  69. int m_iAscent;
  70. int m_iScanLines;
  71. int m_iBlur;
  72. float *m_pGaussianDistribution;
  73. private:
  74. void InitMetrics();
  75. static void CreateFontList();
  76. // abc widths
  77. struct abc_t
  78. {
  79. short b;
  80. char a;
  81. char c;
  82. };
  83. // cache for storing asian abc widths (since it's too big too just store them all)
  84. struct abc_cache_t
  85. {
  86. wchar_t wch;
  87. abc_t abc;
  88. };
  89. CUtlRBTree<abc_cache_t, unsigned short> m_ExtendedABCWidthsCache;
  90. static bool ExtendedABCWidthsCacheLessFunc(const abc_cache_t &lhs, const abc_cache_t &rhs);
  91. // cache for storing asian abc widths (since it's too big too just store them all)
  92. struct kernedSize
  93. {
  94. float wide;
  95. // float abcA; //$ Not yet used...
  96. // float abcC; //
  97. };
  98. struct kerned_abc_cache_t
  99. {
  100. wchar_t wch;
  101. wchar_t wchBefore;
  102. wchar_t wchAfter;
  103. kernedSize abc;
  104. };
  105. CUtlRBTree<kerned_abc_cache_t, unsigned short> m_ExtendedKernedABCWidthsCache;
  106. static bool ExtendedKernedABCWidthsCacheLessFunc(const kerned_abc_cache_t &lhs, const kerned_abc_cache_t &rhs);
  107. int m_rgiBitmapSize[2];
  108. unsigned char *m_pBuf; // pointer to buffer for use when generated bitmap versions of a texture
  109. FT_Face face;
  110. struct font_name_entry
  111. {
  112. font_name_entry()
  113. {
  114. m_pchFile = NULL;
  115. m_pchFriendlyName = NULL;
  116. }
  117. char *m_pchFile;
  118. char *m_pchFriendlyName;
  119. bool operator<( const font_name_entry &rhs ) const
  120. {
  121. return V_stricmp( rhs.m_pchFriendlyName, m_pchFriendlyName ) > 0;
  122. }
  123. };
  124. static CUtlRBTree< font_name_entry > m_FriendlyNameCache;
  125. static bool ms_bSetFriendlyNameCacheLessFunc;
  126. };
  127. #endif // OSXFONT_H