#pragma once #include "GrpTexture.h" #include "GrpImageTexture.h" #include #include FT_FREETYPE_H #include #include class CGraphicFontTexture : public CGraphicTexture { public: typedef wchar_t TCharacterKey; typedef struct SCharacterInfomation { short index; short width; short height; float left; float top; float right; float bottom; float advance; float bearingX; } TCharacterInfomation; typedef std::vector TPCharacterInfomationVector; public: CGraphicFontTexture(); virtual ~CGraphicFontTexture(); void Destroy(); bool Create(const char* c_szFontName, int fontSize, bool bItalic); bool CreateDeviceObjects(); void DestroyDeviceObjects(); bool CheckTextureIndex(DWORD dwTexture); void SelectTexture(DWORD dwTexture); bool UpdateTexture(); TCharacterInfomation* GetCharacterInfomation(wchar_t keyValue); TCharacterInfomation* UpdateCharacterInfomation(TCharacterKey keyValue); float GetKerning(wchar_t prev, wchar_t cur); bool IsEmpty() const; protected: void Initialize(); bool AppendTexture(); protected: typedef std::vector TGraphicImageTexturePointerVector; typedef std::map TCharacterInfomationMap; protected: FT_Face m_ftFace; // CPU-side atlas buffer (replaces CGraphicDib) DWORD* m_pAtlasBuffer; int m_atlasWidth; int m_atlasHeight; TGraphicImageTexturePointerVector m_pFontTextureVector; TCharacterInfomationMap m_charInfoMap; int m_x; int m_y; int m_step; bool m_isDirty; LONG m_fontSize; bool m_bItalic; // FreeType metrics cached per-font int m_ascender; int m_lineHeight; bool m_hasKerning; };