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.

212 lines
5.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: PS3 support for true type fonts.
  4. //
  5. //=====================================================================================//
  6. #if 0 // clipped for now
  7. #include "materialsystem/imaterialsystem.h"
  8. #include "vgui_surfacelib/Win32Font.h"
  9. #include "vgui_surfacelib/FontManager.h"
  10. #include "../materialsystem/ifont.h"
  11. #include "FontEffects.h"
  12. #include <vgui/ISurface.h>
  13. CWin32Font::CWin32Font() : m_ExtendedABCWidthsCache(256, 0, &ExtendedABCWidthsCacheLessFunc)
  14. {
  15. m_pFont = NULL;
  16. }
  17. CWin32Font::~CWin32Font()
  18. {
  19. //FontManager().MaterialSystem()->CloseTrueTypeFont(m_pFont);
  20. m_pFont = NULL;
  21. }
  22. // Create the font
  23. bool CWin32Font::Create(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags)
  24. {
  25. // setup font properties
  26. m_iTall = tall;
  27. m_iWeight = weight;
  28. m_iFlags = flags;
  29. m_bAntiAliased = (flags & FONTFLAG_ANTIALIAS) ? 1 : 0;
  30. m_iDropShadowOffset = (flags & FONTFLAG_DROPSHADOW) ? 1 : 0;
  31. m_iOutlineSize = (flags & FONTFLAG_OUTLINE) ? 1 : 0;
  32. m_iBlur = blur;
  33. m_iScanLines = scanlines;
  34. m_bRotary = (flags & FONTFLAG_ROTARY) ? 1 : 0;
  35. m_bAdditive = (flags & FONTFLAG_ADDITIVE) ? 1 : 0;
  36. m_szName = windowsFontName;
  37. // if the weight is greater that 400, set the style to bold (cf win32font_x360)
  38. // By default use the regular style
  39. m_iWeight = 0x10000 ; // ONE16Dot16 1.0f (F16Dot16 format used by font fusion)
  40. if ( weight > 400 )
  41. {
  42. m_iWeight = 5L << 14; // 1.25 (F16Dot16 format used by font fusion)
  43. }
  44. // Open the font
  45. ExecuteNTimes( 5, Warning( "Fonts dont work on PS3\n" ) );
  46. //m_pFont = FontManager().MaterialSystem()->OpenTrueTypeFont(windowsFontName, tall, m_iWeight);
  47. if(m_pFont == NULL)
  48. {
  49. Warning("Failed to open font %s\n", windowsFontName);
  50. return false;
  51. }
  52. // Store the font parameters
  53. m_iHeight = m_pFont->GetMaxHeight();
  54. m_iAscent = m_pFont->GetAscent();
  55. m_iMaxCharWidth = m_pFont->GetMaxWidth();
  56. // Setup ABC cache
  57. // get char spacing
  58. // a is space before character (can be negative)
  59. // b is the width of the character
  60. // c is the space after the character
  61. memset(m_ABCWidthsCache, 0, sizeof(m_ABCWidthsCache));
  62. for(int i = 0; i < ABCWIDTHS_CACHE_SIZE; i++)
  63. {
  64. int a,b,c;
  65. a = 0;
  66. b = 0;
  67. c = 0;
  68. m_pFont->GetCharABCWidth(i, a, b, c);
  69. m_ABCWidthsCache[i].a = a - m_iBlur;
  70. m_ABCWidthsCache[i].b = b + m_iBlur*2;
  71. m_ABCWidthsCache[i].c = c - m_iBlur;
  72. }
  73. // many fonts are blindly precached by vgui and never used
  74. // save memory and don't hold font open, re-open if glyph actually requested used during draw
  75. Assert( 0 );
  76. //FontManager().MaterialSystem()->CloseTrueTypeFont( m_pFont );
  77. m_pFont = NULL;
  78. return true;
  79. }
  80. // Render the font to a buffer
  81. void CWin32Font::GetCharRGBA(wchar_t ch, int rgbaWide, int rgbaTall, unsigned char *rgba)
  82. {
  83. if ( ch == '\t' )
  84. {
  85. // tabs don't draw
  86. return;
  87. }
  88. if ( !m_pFont )
  89. {
  90. // demand request for font glyph, re-create font
  91. Assert( 0 );
  92. //m_pFont = FontManager().MaterialSystem()->OpenTrueTypeFont(GetName(), m_iTall, m_iWeight);
  93. }
  94. int a, c, wide, tall;
  95. GetCharABCWidths( ch, a, wide, c );
  96. tall = m_iHeight;
  97. m_pFont->RenderToBuffer(ch, m_iBlur, rgbaWide, rgbaTall, rgba);
  98. // apply requested effects in specified order
  99. //ApplyDropShadowToTexture( rgbaX, rgbaY, rgbaWide, rgbaTall, wide, tall, rgba, m_iDropShadowOffset );
  100. //ApplyOutlineToTexture( rgbaX, rgbaY, rgbaWide, rgbaTall, wide, tall, rgba, m_iOutlineSize );
  101. ApplyGaussianBlurToTexture( rgbaWide, rgbaTall, rgba, m_iBlur );
  102. ApplyScanlineEffectToTexture( rgbaWide, rgbaTall, rgba, m_iScanLines );
  103. //ApplyRotaryEffectToTexture( rgbaX, rgbaY, rgbaWide, rgbaTall, rgba, m_bRotary );
  104. }
  105. bool CWin32Font::IsEqualTo(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags)
  106. {
  107. if ( !stricmp(windowsFontName, m_szName.String() )
  108. && m_iTall == tall
  109. && m_iWeight == weight
  110. && m_iBlur == blur
  111. && m_iScanLines == scanlines)
  112. {
  113. return true;
  114. }
  115. return false;
  116. }
  117. bool CWin32Font::IsValid()
  118. {
  119. return true;
  120. }
  121. // Font metrics
  122. void CWin32Font::GetCharABCWidths(int ch, int &a, int &b, int &c)
  123. {
  124. Assert( IsValid() );
  125. if (ch < ABCWIDTHS_CACHE_SIZE)
  126. {
  127. // use the cache entry
  128. a = m_ABCWidthsCache[ch].a;
  129. b = m_ABCWidthsCache[ch].b;
  130. c = m_ABCWidthsCache[ch].c;
  131. }
  132. else
  133. {
  134. // look for it in the cache
  135. abc_cache_t finder = { (wchar_t)ch };
  136. unsigned short i = m_ExtendedABCWidthsCache.Find(finder);
  137. if (m_ExtendedABCWidthsCache.IsValidIndex(i))
  138. {
  139. a = m_ExtendedABCWidthsCache[i].abc.a;
  140. b = m_ExtendedABCWidthsCache[i].abc.b;
  141. c = m_ExtendedABCWidthsCache[i].abc.c;
  142. return;
  143. }
  144. if(!m_pFont)
  145. {
  146. //BRAD: In some instances (e.g. when you try and create an EAOnline account) it tries
  147. // to call GetCharABCWidths before GetCharRGBA so m_pFont is not opened.
  148. // demand request for font glyph, re-create font
  149. Assert( 0 );
  150. //m_pFont = FontManager().MaterialSystem()->OpenTrueTypeFont(GetName(), m_iTall, m_iWeight);
  151. }
  152. m_pFont->GetCharABCWidth(ch, a, b, c);
  153. // add to the cache
  154. finder.abc.a = a;
  155. finder.abc.b = b;
  156. finder.abc.c = c;
  157. m_ExtendedABCWidthsCache.Insert(finder);
  158. }
  159. }
  160. int CWin32Font::GetHeight()
  161. {
  162. return m_iHeight;
  163. }
  164. int CWin32Font::GetAscent()
  165. {
  166. return m_iAscent;
  167. }
  168. int CWin32Font::GetMaxCharWidth()
  169. {
  170. return m_iMaxCharWidth;
  171. }
  172. int CWin32Font::GetFlags()
  173. {
  174. return m_iFlags;
  175. }
  176. bool CWin32Font::ExtendedABCWidthsCacheLessFunc(const abc_cache_t &lhs, const abc_cache_t &rhs)
  177. {
  178. return lhs.wch < rhs.wch;
  179. }
  180. #endif