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.

149 lines
4.0 KiB

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