1
This commit is contained in:
55
common/vgui_surfacelib/BitmapFont.h
Normal file
55
common/vgui_surfacelib/BitmapFont.h
Normal file
@ -0,0 +1,55 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Baked Bitmap fonts
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
#ifndef _BITMAPFONT_H_
|
||||
#define _BITMAPFONT_H_
|
||||
|
||||
#include "vguifont.h"
|
||||
#include "BitmapFontFile.h"
|
||||
|
||||
class ITexture;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: encapsulates a windows font
|
||||
//-----------------------------------------------------------------------------
|
||||
class CBitmapFont : public font_t
|
||||
{
|
||||
public:
|
||||
CBitmapFont();
|
||||
virtual ~CBitmapFont();
|
||||
|
||||
// creates the font. returns false if the compiled font does not exist.
|
||||
virtual bool Create(const char *windowsFontName, float scalex, float scaley, int flags);
|
||||
|
||||
// returns true if the font is equivalent to that specified
|
||||
virtual bool IsEqualTo(const char *windowsFontName, float scalex, float scaley, int flags);
|
||||
|
||||
// gets the abc widths for a character
|
||||
virtual void GetCharABCWidths(int ch, int &a, int &b, int &c);
|
||||
|
||||
// writes the char into the specified 32bpp texture. We're overloading this because
|
||||
// we derive off font_t, and the implementation there doesn't work for bitmap fonts.
|
||||
virtual void GetCharRGBA( wchar_t ch, int rgbaWide, int rgbaTall, unsigned char *prgba );
|
||||
|
||||
// gets the width of ch given its position around before and after chars
|
||||
virtual void GetKernedCharWidth( wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA, float &abcC );
|
||||
|
||||
// gets the texture coords in the compiled texture page
|
||||
void GetCharCoords( int ch, float *left, float *top, float *right, float *bottom );
|
||||
|
||||
// sets the scale of the font.
|
||||
void SetScale( float sx, float sy );
|
||||
|
||||
// gets the compiled texture page
|
||||
ITexture *GetTexturePage();
|
||||
|
||||
private:
|
||||
int m_bitmapFontHandle;
|
||||
float m_scalex;
|
||||
float m_scaley;
|
||||
};
|
||||
|
||||
#endif // _BITMAPFONT_H
|
79
common/vgui_surfacelib/FontAmalgam.h
Normal file
79
common/vgui_surfacelib/FontAmalgam.h
Normal file
@ -0,0 +1,79 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef FONTAMALGAM_H
|
||||
#define FONTAMALGAM_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "vguifont.h"
|
||||
#include "BitmapFont.h"
|
||||
#include "utlvector.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: object that holds a set of fonts in specified ranges
|
||||
//-----------------------------------------------------------------------------
|
||||
class CFontAmalgam
|
||||
{
|
||||
public:
|
||||
CFontAmalgam();
|
||||
~CFontAmalgam();
|
||||
|
||||
const char *Name();
|
||||
void SetName(const char *name);
|
||||
|
||||
// adds a font to the amalgam
|
||||
void AddFont( font_t *font, int lowRange, int highRange);
|
||||
|
||||
// returns the font for the given character
|
||||
font_t *GetFontForChar(int ch);
|
||||
|
||||
// returns the max height of the font set
|
||||
int GetFontHeight();
|
||||
|
||||
// returns height requested
|
||||
int GetFontHeightRequested();
|
||||
|
||||
// returns the maximum width of a character in a font
|
||||
int GetFontMaxWidth();
|
||||
|
||||
// returns the flags used to make the first font
|
||||
int GetFlags(int i);
|
||||
|
||||
// returns the windows name for the font
|
||||
const char *GetFontName(int i);
|
||||
const char *GetFontFamilyName(int i);
|
||||
|
||||
// returns the number of fonts in this amalgam
|
||||
int GetCount();
|
||||
|
||||
// returns true if this font is underlined
|
||||
bool GetUnderlined();
|
||||
|
||||
// sets the scale of a bitmap font
|
||||
void SetFontScale(float sx, float sy);
|
||||
|
||||
// clears the fonts
|
||||
void RemoveAll();
|
||||
|
||||
private:
|
||||
struct TFontRange
|
||||
{
|
||||
int lowRange;
|
||||
int highRange;
|
||||
font_t *font;
|
||||
};
|
||||
|
||||
CUtlVector<TFontRange> m_Fonts;
|
||||
char m_szName[32];
|
||||
int m_iMaxWidth;
|
||||
int m_iMaxHeight;
|
||||
};
|
||||
|
||||
|
||||
#endif // FONTAMALGAM_H
|
129
common/vgui_surfacelib/FontManager.h
Normal file
129
common/vgui_surfacelib/FontManager.h
Normal file
@ -0,0 +1,129 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef FONTMANAGER_H
|
||||
#define FONTMANAGER_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui/VGUI.h>
|
||||
#include "vgui_surfacelib/FontAmalgam.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "filesystem.h"
|
||||
#include "vguifont.h"
|
||||
|
||||
#ifdef LINUX
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
typedef void *(*FontDataHelper)( const char *pchFontName, int &size, const char *fontFileName );
|
||||
#endif
|
||||
|
||||
#ifdef CreateFont
|
||||
#undef CreateFont
|
||||
#endif
|
||||
|
||||
|
||||
using vgui::HFont;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Creates and maintains list of actively used fonts
|
||||
//-----------------------------------------------------------------------------
|
||||
class CFontManager
|
||||
{
|
||||
public:
|
||||
CFontManager();
|
||||
~CFontManager();
|
||||
|
||||
void SetLanguage(const char *language);
|
||||
|
||||
// clears the current font list, frees any resources
|
||||
void ClearAllFonts();
|
||||
|
||||
HFont CreateFont();
|
||||
bool SetFontGlyphSet(HFont font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
|
||||
bool SetFontGlyphSet(HFont font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int nRangeMin, int nRangeMax);
|
||||
bool SetBitmapFontGlyphSet(HFont font, const char *windowsFontName, float scalex, float scaley, int flags);
|
||||
void SetFontScale(HFont font, float sx, float sy);
|
||||
const char *GetFontName( HFont font );
|
||||
const char *GetFontFamilyName( HFont font );
|
||||
void GetCharABCwide(HFont font, int ch, int &a, int &b, int &c);
|
||||
int GetFontTall(HFont font);
|
||||
int GetFontTallRequested(HFont font);
|
||||
int GetFontAscent(HFont font, wchar_t wch);
|
||||
int GetCharacterWidth(HFont font, int ch);
|
||||
bool GetFontUnderlined( HFont font );
|
||||
void GetTextSize(HFont font, const wchar_t *text, int &wide, int &tall);
|
||||
|
||||
font_t *GetFontForChar(HFont, wchar_t wch);
|
||||
bool IsFontAdditive(HFont font);
|
||||
bool IsBitmapFont(HFont font );
|
||||
|
||||
void SetInterfaces( IFileSystem *pFileSystem, IMaterialSystem *pMaterialSystem )
|
||||
{
|
||||
m_pFileSystem = pFileSystem;
|
||||
m_pMaterialSystem = pMaterialSystem;
|
||||
}
|
||||
IFileSystem *FileSystem() { return m_pFileSystem; }
|
||||
IMaterialSystem *MaterialSystem() { return m_pMaterialSystem; }
|
||||
|
||||
#ifdef LINUX
|
||||
FT_Library GetFontLibraryHandle() { return library; }
|
||||
void SetFontDataHelper( FontDataHelper helper ) { m_pFontDataHelper = helper; }
|
||||
#endif
|
||||
|
||||
#if defined( _X360 )
|
||||
// secondary cache to speed TTF setup
|
||||
bool GetCachedXUIMetrics( const char *pWindowsFontName, int tall, int style, XUIFontMetrics *pFontMetrics, XUICharMetrics charMetrics[256] );
|
||||
void SetCachedXUIMetrics( const char *pWindowsFontName, int tall, int style, XUIFontMetrics *pFontMetrics, XUICharMetrics charMetrics[256] );
|
||||
#endif
|
||||
|
||||
// used as a hint that intensive TTF operations are finished
|
||||
void ClearTemporaryFontCache();
|
||||
void GetKernedCharWidth( vgui::HFont font, wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA, float &abcC );
|
||||
|
||||
private:
|
||||
bool IsFontForeignLanguageCapable(const char *windowsFontName);
|
||||
font_t *CreateOrFindWin32Font(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
|
||||
CBitmapFont *CreateOrFindBitmapFont(const char *windowsFontName, float scalex, float scaley, int flags);
|
||||
const char *GetFallbackFontName(const char *windowsFontName);
|
||||
const char *GetForeignFallbackFontName();
|
||||
|
||||
CUtlVector<CFontAmalgam> m_FontAmalgams;
|
||||
CUtlVector<font_t *> m_Win32Fonts;
|
||||
|
||||
#ifdef LINUX
|
||||
FT_Library library;
|
||||
FontDataHelper m_pFontDataHelper;
|
||||
#endif
|
||||
char m_szLanguage[64];
|
||||
IFileSystem *m_pFileSystem;
|
||||
IMaterialSystem *m_pMaterialSystem;
|
||||
|
||||
#if defined( _X360 )
|
||||
// These are really bounded by the number of fonts that the game would ever realistically create, so ~100 is expected.
|
||||
// Many of these fonts are redundant and the same underlying metrics can be used. This avoid the very expensive TTF font metric lookup.
|
||||
struct XUIMetricCache_t
|
||||
{
|
||||
// the font signature that can change
|
||||
CUtlSymbol fontSymbol;
|
||||
int tall;
|
||||
int style;
|
||||
|
||||
// the metrics
|
||||
XUIFontMetrics fontMetrics;
|
||||
XUICharMetrics charMetrics[256];
|
||||
};
|
||||
CUtlVector< XUIMetricCache_t > m_XUIMetricCache;
|
||||
#endif
|
||||
};
|
||||
|
||||
// singleton accessor
|
||||
extern CFontManager &FontManager();
|
||||
|
||||
|
||||
#endif // FONTMANAGER_H
|
148
common/vgui_surfacelib/Win32Font.h
Normal file
148
common/vgui_surfacelib/Win32Font.h
Normal file
@ -0,0 +1,148 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef WIN32FONT_H
|
||||
#define WIN32FONT_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#if !defined( _X360 )
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define OEMRESOURCE
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifdef GetCharABCWidths
|
||||
#undef GetCharABCWidths
|
||||
#endif
|
||||
|
||||
#include "utlrbtree.h"
|
||||
#include "tier1/utlsymbol.h"
|
||||
|
||||
struct newChar_t;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: encapsulates a windows font
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class CWin32Font
|
||||
{
|
||||
public:
|
||||
CWin32Font();
|
||||
~CWin32Font();
|
||||
|
||||
// creates the font from windows. returns false if font does not exist in the OS.
|
||||
virtual bool Create(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
|
||||
|
||||
// writes the char into the specified 32bpp texture
|
||||
virtual void GetCharRGBA(wchar_t ch, int rgbaWide, int rgbaTall, unsigned char *rgba);
|
||||
|
||||
// returns true if the font is equivalent to that specified
|
||||
virtual bool IsEqualTo(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
|
||||
|
||||
// returns true only if this font is valid for use
|
||||
virtual bool IsValid();
|
||||
|
||||
// gets the abc widths for a character
|
||||
virtual void GetCharABCWidths(int ch, int &a, int &b, int &c);
|
||||
|
||||
// set the font to be the one to currently draw with in the gdi
|
||||
virtual void SetAsActiveFont(HDC hdc);
|
||||
|
||||
// returns the height of the font, in pixels
|
||||
virtual int GetHeight();
|
||||
|
||||
// returns requested height of font.
|
||||
virtual int GetHeightRequested();
|
||||
|
||||
// returns the ascent of the font, in pixels (ascent=units above the base line)
|
||||
virtual int GetAscent();
|
||||
|
||||
// returns the maximum width of a character, in pixels
|
||||
virtual int GetMaxCharWidth();
|
||||
|
||||
// returns the flags used to make this font
|
||||
virtual int GetFlags();
|
||||
|
||||
// returns true if this font is underlined
|
||||
bool GetUnderlined() { return m_bUnderlined; }
|
||||
|
||||
// gets the name of this font
|
||||
const char *GetName() { return m_szName.String(); }
|
||||
const char *GetFamilyName() { return NULL; }
|
||||
|
||||
// gets the width of ch given its position around before and after chars
|
||||
void GetKernedCharWidth( wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA );
|
||||
|
||||
#if defined( _X360 )
|
||||
// generates texture data for a set of chars
|
||||
virtual void GetCharsRGBA( newChar_t *newChars, int numNewChars, unsigned char *pRGBA );
|
||||
|
||||
virtual void CloseResource();
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
#if !defined( _X360 )
|
||||
HFONT m_hFont;
|
||||
HDC m_hDC;
|
||||
HBITMAP m_hDIB;
|
||||
#else
|
||||
HXUIFONT m_hFont;
|
||||
HDC m_hDC;
|
||||
#endif
|
||||
|
||||
// pointer to buffer for use when generated bitmap versions of a texture
|
||||
unsigned char *m_pBuf;
|
||||
|
||||
protected:
|
||||
CUtlSymbol m_szName;
|
||||
|
||||
short m_iTall;
|
||||
unsigned short m_iWeight;
|
||||
unsigned short m_iFlags;
|
||||
unsigned short m_iScanLines;
|
||||
unsigned short m_iBlur;
|
||||
unsigned short m_rgiBitmapSize[2];
|
||||
bool m_bUnderlined;
|
||||
|
||||
unsigned int m_iHeight : 8;
|
||||
unsigned int m_iMaxCharWidth : 8;
|
||||
unsigned int m_iAscent : 8;
|
||||
unsigned int m_iDropShadowOffset : 1;
|
||||
unsigned int m_iOutlineSize : 1;
|
||||
unsigned int m_bAntiAliased : 1;
|
||||
unsigned int m_bRotary : 1;
|
||||
unsigned int m_bAdditive : 1; //29
|
||||
|
||||
private:
|
||||
// abc widths
|
||||
struct abc_t
|
||||
{
|
||||
short b;
|
||||
char a;
|
||||
char c;
|
||||
};
|
||||
|
||||
#if !defined( _X360 )
|
||||
// On PC we cache char widths on demand when actually requested to minimize our use of the kernels
|
||||
// paged pool (GDI may cache information about glyphs we have requested and take up lots of paged pool)
|
||||
struct abc_cache_t
|
||||
{
|
||||
wchar_t wch;
|
||||
abc_t abc;
|
||||
};
|
||||
CUtlRBTree<abc_cache_t, unsigned short> m_ExtendedABCWidthsCache;
|
||||
static bool ExtendedABCWidthsCacheLessFunc(const abc_cache_t &lhs, const abc_cache_t &rhs);
|
||||
#else
|
||||
// 360 requires all possible characters during font init
|
||||
enum { ABCWIDTHS_CACHE_SIZE = 256 };
|
||||
abc_t m_ABCWidthsCache[ABCWIDTHS_CACHE_SIZE];
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // WIN32FONT_H
|
169
common/vgui_surfacelib/linuxfont.h
Normal file
169
common/vgui_surfacelib/linuxfont.h
Normal file
@ -0,0 +1,169 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef LINUXFONT_H
|
||||
#define LINUXFONT_H
|
||||
|
||||
#include "utlrbtree.h"
|
||||
#include <tier0/memdbgoff.h>
|
||||
#include <tier0/memdbgon.h>
|
||||
#include "tier1/strtools.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: encapsulates a OSX font
|
||||
//-----------------------------------------------------------------------------
|
||||
class CLinuxFont
|
||||
{
|
||||
public:
|
||||
CLinuxFont();
|
||||
~CLinuxFont();
|
||||
|
||||
// creates the font from windows. returns false if font does not exist in the OS.
|
||||
virtual bool CreateFromMemory(const char *windowsFontName, void *data, int size, int tall, int weight, int blur, int scanlines, int flags);
|
||||
|
||||
// writes the char into the specified 32bpp texture
|
||||
virtual void GetCharRGBA( wchar_t ch, int rgbaWide, int rgbaTall, unsigned char *rgba);
|
||||
|
||||
// returns true if the font is equivalent to that specified
|
||||
virtual bool IsEqualTo(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
|
||||
|
||||
// returns true only if this font is valid for use
|
||||
virtual bool IsValid();
|
||||
|
||||
// gets the abc widths for a character
|
||||
// A spacing is the distance to add to the current position before drawing the character glyph.
|
||||
// B spacing is the width of the drawn portion of the glyph.
|
||||
// C spacing is the distance to add to the current position to provide white space to the right of the glyph.
|
||||
virtual void GetCharABCWidths(int ch, int &a, int &b, int &c);
|
||||
|
||||
// set the font to be the one to currently draw with in the gdi
|
||||
void *SetAsActiveFont( void *glContext );
|
||||
|
||||
// returns the height of the font, in pixels
|
||||
virtual int GetHeight();
|
||||
|
||||
// returns the requested height of the font.
|
||||
virtual int GetHeightRequested();
|
||||
|
||||
// returns the ascent of the font, in pixels (ascent=units above the base line)
|
||||
virtual int GetAscent();
|
||||
|
||||
// returns the maximum width of a character, in pixels
|
||||
virtual int GetMaxCharWidth();
|
||||
|
||||
// returns the flags used to make this font
|
||||
virtual int GetFlags();
|
||||
|
||||
// returns true if this font is underlined
|
||||
virtual bool GetUnderlined() { return m_bUnderlined; }
|
||||
|
||||
// gets the name of this font
|
||||
const char *GetName() { return m_szName.String(); }
|
||||
const char *GetFamilyName() { return m_face ? m_face->family_name : NULL; }
|
||||
|
||||
// gets the weight of the font
|
||||
virtual int GetWeight() { return m_iWeight; }
|
||||
|
||||
bool HasChar(wchar_t wch);
|
||||
|
||||
// gets the width of ch given its position around before and after chars
|
||||
virtual void GetKernedCharWidth( wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA, float &abcC );
|
||||
|
||||
#ifdef DBGFLAG_VALIDATE
|
||||
void Validate( CValidator &validator, char *pchName );
|
||||
#endif
|
||||
|
||||
// Given a font name from windows, match it to the filename and return that.
|
||||
static char *GetFontFileName(const char *windowsFontName, int flags);
|
||||
|
||||
|
||||
protected:
|
||||
CUtlString m_szName;
|
||||
int m_iTall;
|
||||
int m_iWeight;
|
||||
int m_iFlags;
|
||||
bool m_bAntiAliased;
|
||||
bool m_bRotary;
|
||||
bool m_bAdditive;
|
||||
int m_iDropShadowOffset;
|
||||
bool m_bUnderlined;
|
||||
int m_iOutlineSize;
|
||||
|
||||
int m_iHeight;
|
||||
int m_iHeightRequested;
|
||||
int m_iMaxCharWidth;
|
||||
int m_iAscent;
|
||||
|
||||
int m_iScanLines;
|
||||
int m_iBlur;
|
||||
|
||||
private:
|
||||
static void CreateFontList();
|
||||
// abc widths
|
||||
struct abc_t
|
||||
{
|
||||
short b;
|
||||
char a;
|
||||
char c;
|
||||
};
|
||||
|
||||
// cache for storing asian abc widths (since it's too big too just store them all)
|
||||
struct abc_cache_t
|
||||
{
|
||||
wchar_t wch;
|
||||
abc_t abc;
|
||||
};
|
||||
|
||||
|
||||
CUtlRBTree<abc_cache_t, unsigned short> m_ExtendedABCWidthsCache;
|
||||
static bool ExtendedABCWidthsCacheLessFunc(const abc_cache_t &lhs, const abc_cache_t &rhs);
|
||||
|
||||
// cache for storing asian abc widths (since it's too big too just store them all)
|
||||
struct kernedSize
|
||||
{
|
||||
float wide;
|
||||
};
|
||||
|
||||
struct kerned_abc_cache_t
|
||||
{
|
||||
wchar_t wch;
|
||||
wchar_t wchBefore;
|
||||
wchar_t wchAfter;
|
||||
kernedSize abc;
|
||||
};
|
||||
|
||||
CUtlRBTree<kerned_abc_cache_t, unsigned short> m_ExtendedKernedABCWidthsCache;
|
||||
static bool ExtendedKernedABCWidthsCacheLessFunc(const kerned_abc_cache_t &lhs, const kerned_abc_cache_t &rhs);
|
||||
|
||||
bool m_faceValid;
|
||||
FT_Face m_face;
|
||||
|
||||
struct font_name_entry
|
||||
{
|
||||
font_name_entry()
|
||||
{
|
||||
m_pchFile = NULL;
|
||||
m_pchFriendlyName = NULL;
|
||||
}
|
||||
|
||||
char *m_pchFile;
|
||||
char *m_pchFriendlyName;
|
||||
bool operator<( const font_name_entry &rhs ) const
|
||||
{
|
||||
return V_stricmp( rhs.m_pchFriendlyName, m_pchFriendlyName ) > 0;
|
||||
}
|
||||
};
|
||||
static CUtlRBTree< font_name_entry > m_FriendlyNameCache;
|
||||
static bool ms_bSetFriendlyNameCacheLessFunc;
|
||||
};
|
||||
|
||||
#endif // LINUXFONT_H
|
146
common/vgui_surfacelib/osxfont.h
Normal file
146
common/vgui_surfacelib/osxfont.h
Normal file
@ -0,0 +1,146 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef OSXFONT_H
|
||||
#define OSXFONT_H
|
||||
|
||||
#include "utlrbtree.h"
|
||||
#include "utlsymbol.h"
|
||||
#include "tier1/strtools.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include <tier0/memdbgoff.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include <Carbon/Carbon.h>
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: encapsulates a OSX font
|
||||
//-----------------------------------------------------------------------------
|
||||
class COSXFont
|
||||
{
|
||||
public:
|
||||
COSXFont();
|
||||
~COSXFont();
|
||||
|
||||
// creates the font from windows. returns false if font does not exist in the OS.
|
||||
virtual bool Create(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
|
||||
|
||||
// writes the char into the specified 32bpp texture
|
||||
virtual void GetCharRGBA( wchar_t ch, int rgbaWide, int rgbaTall, unsigned char *rgba);
|
||||
|
||||
// returns true if the font is equivalent to that specified
|
||||
virtual bool IsEqualTo(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags);
|
||||
|
||||
// returns true only if this font is valid for use
|
||||
virtual bool IsValid();
|
||||
|
||||
// gets the abc widths for a character
|
||||
virtual void GetCharABCWidths(int ch, int &a, int &b, int &c);
|
||||
|
||||
// set the font to be the one to currently draw with in the gdi
|
||||
ATSUStyle *SetAsActiveFont( CGContextRef cgContext );
|
||||
|
||||
// returns the height of the font, in pixels
|
||||
virtual int GetHeight();
|
||||
|
||||
// returns requested height of font.
|
||||
virtual int GetHeightRequested();
|
||||
|
||||
// returns the ascent of the font, in pixels (ascent=units above the base line)
|
||||
virtual int GetAscent();
|
||||
|
||||
// returns the maximum width of a character, in pixels
|
||||
virtual int GetMaxCharWidth();
|
||||
|
||||
// returns the flags used to make this font
|
||||
virtual int GetFlags();
|
||||
|
||||
// returns true if this font is underlined
|
||||
virtual bool GetUnderlined() { return m_bUnderlined; }
|
||||
|
||||
// gets the name of this font
|
||||
const char *GetName() { return m_szName.String(); }
|
||||
const char *GetFamilyName() { return NULL; }
|
||||
|
||||
// gets the weight of the font
|
||||
virtual int GetWeight() { return m_iWeight; }
|
||||
|
||||
// gets the width of ch given its position around before and after chars
|
||||
void GetKernedCharWidth( wchar_t ch, wchar_t chBefore, wchar_t chAfter, float &wide, float &abcA );
|
||||
|
||||
#ifdef DBGFLAG_VALIDATE
|
||||
void Validate( CValidator &validator, char *pchName );
|
||||
#endif
|
||||
|
||||
protected:
|
||||
CUtlString m_szName;
|
||||
int m_iTall;
|
||||
int m_iWeight;
|
||||
int m_iFlags;
|
||||
bool m_bAntiAliased;
|
||||
bool m_bRotary;
|
||||
bool m_bAdditive;
|
||||
int m_iDropShadowOffset;
|
||||
bool m_bUnderlined;
|
||||
int m_iOutlineSize;
|
||||
|
||||
int m_iHeight;
|
||||
int m_iMaxCharWidth;
|
||||
int m_iAscent;
|
||||
|
||||
int m_iScanLines;
|
||||
int m_iBlur;
|
||||
float *m_pGaussianDistribution;
|
||||
|
||||
private:
|
||||
bool CreateStyle( float flFontSize, bool bBold );
|
||||
bool CreateTextLayout();
|
||||
|
||||
// abc widths
|
||||
struct abc_t
|
||||
{
|
||||
short b;
|
||||
char a;
|
||||
char c;
|
||||
};
|
||||
|
||||
// Cache for storing asian abc widths (since it's too big too just store them all).
|
||||
struct abc_cache_t
|
||||
{
|
||||
wchar_t wch;
|
||||
abc_t abc;
|
||||
};
|
||||
|
||||
// Cache for storing asian abc widths (since it's too big too just store them all).
|
||||
struct kernedSize
|
||||
{
|
||||
float wide;
|
||||
float abcA;
|
||||
};
|
||||
|
||||
struct kerned_abc_cache_t
|
||||
{
|
||||
wchar_t wch;
|
||||
wchar_t wchBefore;
|
||||
wchar_t wchAfter;
|
||||
kernedSize abc;
|
||||
};
|
||||
|
||||
static bool ExtendedABCWidthsCacheLessFunc(const abc_cache_t &lhs, const abc_cache_t &rhs);
|
||||
static bool ExtendedKernedABCWidthsCacheLessFunc(const kerned_abc_cache_t &lhs, const kerned_abc_cache_t &rhs);
|
||||
|
||||
CUtlRBTree<abc_cache_t, unsigned short> m_ExtendedABCWidthsCache;
|
||||
CUtlRBTree<kerned_abc_cache_t, unsigned short> m_ExtendedKernedABCWidthsCache;
|
||||
|
||||
char *m_pContextMemory;
|
||||
ATSUFontID m_ATSUFont;
|
||||
CGContextRef m_ContextRef;
|
||||
ATSUStyle m_ATSUStyle;
|
||||
ATSUTextLayout m_ATSUTextLayout;
|
||||
};
|
||||
|
||||
#endif // OSXFONT_H
|
37
common/vgui_surfacelib/vguifont.h
Normal file
37
common/vgui_surfacelib/vguifont.h
Normal file
@ -0,0 +1,37 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef VGUIFONT_H
|
||||
#define VGUIFONT_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
// Structure passed to CWin32Font::GetCharsRGBA
|
||||
struct newChar_t
|
||||
{
|
||||
wchar_t wch; // A new character to generate texture data for
|
||||
int fontWide; // Texel width of the character
|
||||
int fontTall; // Texel height of the character
|
||||
int offset; // Offset into the buffer given to GetCharsRGBA
|
||||
};
|
||||
|
||||
#ifdef WIN32
|
||||
#include "Win32Font.h"
|
||||
typedef CWin32Font font_t;
|
||||
#elif defined(OSX)
|
||||
#include "osxfont.h"
|
||||
typedef COSXFont font_t;
|
||||
#elif defined(LINUX)
|
||||
#include "linuxfont.h"
|
||||
typedef CLinuxFont font_t;
|
||||
#else
|
||||
#error
|
||||
#endif
|
||||
|
||||
|
||||
#endif //VGUIFONT_H
|
Reference in New Issue
Block a user