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.

146 lines
3.8 KiB

  1. //========= Copyright 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 <tier0/memdbgon.h>
  17. //-----------------------------------------------------------------------------
  18. // Purpose: encapsulates a OSX font
  19. //-----------------------------------------------------------------------------
  20. class COSXFont
  21. {
  22. public:
  23. COSXFont();
  24. ~COSXFont();
  25. // creates the font from windows. returns false if font does not exist in the OS.
  26. virtual bool Create(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
  27. // writes the char into the specified 32bpp texture
  28. virtual void GetCharRGBA( wchar_t ch, int rgbaWide, int rgbaTall, unsigned char *rgba);
  29. // returns true if the font is equivalent to that specified
  30. virtual bool IsEqualTo(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
  31. // returns true only if this font is valid for use
  32. virtual bool IsValid();
  33. // gets the abc widths for a character
  34. virtual void GetCharABCWidths(int ch, int &a, int &b, int &c);
  35. // set the font to be the one to currently draw with in the gdi
  36. ATSUStyle *SetAsActiveFont( CGContextRef cgContext );
  37. // returns the height of the font, in pixels
  38. virtual int GetHeight();
  39. // returns requested height of font.
  40. virtual int GetHeightRequested();
  41. // returns the ascent of the font, in pixels (ascent=units above the base line)
  42. virtual int GetAscent();
  43. // returns the maximum width of a character, in pixels
  44. virtual int GetMaxCharWidth();
  45. // returns the flags used to make this font
  46. virtual int GetFlags();
  47. // returns true if this font is underlined
  48. virtual bool GetUnderlined() { return m_bUnderlined; }
  49. // gets the name of this font
  50. const char *GetName() { return m_szName.String(); }
  51. const char *GetFamilyName() { return NULL; }
  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. void GetKernedCharWidth( wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA );
  56. #ifdef DBGFLAG_VALIDATE
  57. void Validate( CValidator &validator, char *pchName );
  58. #endif
  59. protected:
  60. CUtlString m_szName;
  61. int m_iTall;
  62. int m_iWeight;
  63. int m_iFlags;
  64. bool m_bAntiAliased;
  65. bool m_bRotary;
  66. bool m_bAdditive;
  67. int m_iDropShadowOffset;
  68. bool m_bUnderlined;
  69. int m_iOutlineSize;
  70. int m_iHeight;
  71. int m_iMaxCharWidth;
  72. int m_iAscent;
  73. int m_iScanLines;
  74. int m_iBlur;
  75. float *m_pGaussianDistribution;
  76. private:
  77. bool CreateStyle( float flFontSize, bool bBold );
  78. bool CreateTextLayout();
  79. // abc widths
  80. struct abc_t
  81. {
  82. short b;
  83. char a;
  84. char c;
  85. };
  86. // Cache for storing asian abc widths (since it's too big too just store them all).
  87. struct abc_cache_t
  88. {
  89. wchar_t wch;
  90. abc_t abc;
  91. };
  92. // Cache for storing asian abc widths (since it's too big too just store them all).
  93. struct kernedSize
  94. {
  95. float wide;
  96. float abcA;
  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. static bool ExtendedABCWidthsCacheLessFunc(const abc_cache_t &lhs, const abc_cache_t &rhs);
  106. static bool ExtendedKernedABCWidthsCacheLessFunc(const kerned_abc_cache_t &lhs, const kerned_abc_cache_t &rhs);
  107. CUtlRBTree<abc_cache_t, unsigned short> m_ExtendedABCWidthsCache;
  108. CUtlRBTree<kerned_abc_cache_t, unsigned short> m_ExtendedKernedABCWidthsCache;
  109. char *m_pContextMemory;
  110. ATSUFontID m_ATSUFont;
  111. CGContextRef m_ContextRef;
  112. ATSUStyle m_ATSUStyle;
  113. ATSUTextLayout m_ATSUTextLayout;
  114. };
  115. #endif // OSXFONT_H