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.

129 lines
4.2 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef FONTMANAGER_H
  8. #define FONTMANAGER_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "vgui/vgui.h"
  13. #include "vgui_surfacelib/FontAmalgam.h"
  14. #include "vgui_surfacelib/ifontsurface.h"
  15. #include "materialsystem/imaterialsystem.h"
  16. #include "filesystem.h"
  17. #include "vguifont.h"
  18. #ifdef LINUX
  19. #include <ft2build.h>
  20. #include FT_FREETYPE_H
  21. typedef void *(*FontDataHelper)( const char *pchFontName, int &size );
  22. #endif
  23. #ifdef CreateFont
  24. #undef CreateFont
  25. #endif
  26. using vgui::HFont;
  27. //-----------------------------------------------------------------------------
  28. // Purpose: Creates and maintains list of actively used fonts
  29. //-----------------------------------------------------------------------------
  30. class CFontManager
  31. {
  32. public:
  33. CFontManager();
  34. ~CFontManager();
  35. void SetLanguage(const char *language);
  36. const char *GetLanguage();
  37. // clears the current font list, frees any resources
  38. void ClearAllFonts();
  39. HFont CreateFont();
  40. bool SetFontGlyphSet(HFont font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
  41. bool SetFontGlyphSet(HFont font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int nRangeMin, int nRangeMax);
  42. bool SetBitmapFontGlyphSet(HFont font, const char *windowsFontName, float scalex, float scaley, int flags);
  43. void SetFontScale(HFont font, float sx, float sy);
  44. const char *GetFontName( HFont font );
  45. void GetCharABCwide(HFont font, int ch, int &a, int &b, int &c);
  46. int GetFontTall(HFont font);
  47. int GetFontAscent(HFont font, wchar_t wch);
  48. int GetCharacterWidth(HFont font, int ch);
  49. bool GetFontUnderlined( HFont font );
  50. void GetTextSize(HFont font, const wchar_t *text, int &wide, int &tall);
  51. font_t *GetFontForChar(HFont, wchar_t wch);
  52. bool IsFontAdditive(HFont font);
  53. bool IsBitmapFont(HFont font );
  54. void SetInterfaces( IFileSystem *pFileSystem, IMaterialSystem *pMaterialSystem )
  55. {
  56. m_pFileSystem = pFileSystem;
  57. m_pMaterialSystem = pMaterialSystem;
  58. }
  59. IFileSystem *FileSystem() { return m_pFileSystem; }
  60. IMaterialSystem *MaterialSystem() { return m_pMaterialSystem; }
  61. #ifdef LINUX
  62. FT_Library GetFontLibraryHandle() { return library; }
  63. void SetFontDataHelper( FontDataHelper helper ) { pFontDataHelper = helper; }
  64. #endif
  65. #if defined( _X360 )
  66. // secondary cache to speed TTF setup
  67. bool GetCachedXUIMetrics( const char *pWindowsFontName, int tall, int style, XUIFontMetrics *pFontMetrics, XUICharMetrics charMetrics[256] );
  68. void SetCachedXUIMetrics( const char *pWindowsFontName, int tall, int style, XUIFontMetrics *pFontMetrics, XUICharMetrics charMetrics[256] );
  69. #endif
  70. // used as a hint that intensive TTF operations are finished
  71. void ClearTemporaryFontCache();
  72. void GetKernedCharWidth( vgui::HFont font, wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA, float &abcC );
  73. private:
  74. bool IsFontForeignLanguageCapable(const char *windowsFontName);
  75. font_t *CreateOrFindWin32Font(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
  76. CBitmapFont *CreateOrFindBitmapFont(const char *windowsFontName, float scalex, float scaley, int flags);
  77. const char *GetFallbackFontName(const char *windowsFontName);
  78. const char *GetForeignFallbackFontName();
  79. CUtlVector<CFontAmalgam> m_FontAmalgams;
  80. CUtlVector<font_t *> m_Win32Fonts;
  81. #ifdef LINUX
  82. FT_Library library;
  83. FontDataHelper pFontDataHelper;
  84. #endif
  85. char m_szLanguage[64];
  86. IFileSystem *m_pFileSystem;
  87. IMaterialSystem *m_pMaterialSystem;
  88. #if defined( _X360 )
  89. // These are really bounded by the number of fonts that the game would ever realistically create, so ~100 is expected.
  90. // Many of these fonts are redundant and the same underlying metrics can be used. This avoid the very expensive TTF font metric lookup.
  91. struct XUIMetricCache_t
  92. {
  93. // the font signature that can change
  94. CUtlSymbol fontSymbol;
  95. int tall;
  96. int style;
  97. // the metrics
  98. XUIFontMetrics fontMetrics;
  99. XUICharMetrics charMetrics[256];
  100. };
  101. CUtlVector< XUIMetricCache_t > m_XUIMetricCache;
  102. #endif
  103. };
  104. // singleton accessor
  105. extern CFontManager &FontManager();
  106. #endif // FONTMANAGER_H