Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CFont Class Reference

Storage for a bitmap font. More...

#include <Font.h>

Collaboration diagram for CFont:

Classes

struct  GlyphData
 
class  GlyphMap
 Relatively efficient lookup of GlyphData from 16-bit Unicode codepoint. More...
 

Public Member Functions

 CFont (FT_Library library, const std::array< float, 256 > &gammaCorrection)
 
 ~CFont ()=default
 
 MOVABLE (CFont)
 
 NONCOPYABLE (CFont)
 
bool HasRGB () const
 
float GetHeight () const
 
float GetCapHeight ()
 In typography, cap height is the height of a capital letter above the baseline for a particular typeface. More...
 
float GetCharacterWidth (wchar_t c)
 
float GetStrokeWidth () const
 
void CalculateStringSize (const wchar_t *string, float &w, float &h)
 
void GetGlyphBounds (float &x0, float &y0, float &x1, float &y1) const
 
CTexturePtr GetTexture () const
 
void InitalizeAtlasTextureIfNeeded (Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
 
void UploadAtlasTextureToGPU (Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
 
const GlyphData * GetGlyph (std::uint16_t i)
 

Private Types

using UniqueFTFace = std::unique_ptr< std::remove_pointer_t< FT_Face >, decltype(&ftFaceDeleter)>
 
using UniqueFTStroker = std::unique_ptr< std::remove_pointer_t< FT_Stroker >, decltype(&ftStrokerDeleter)>
 

Private Member Functions

bool AddFontFromPath (const OsPath &fontPath)
 
bool SetFontParams (Renderer::Backend::IDevice *device, const std::string &fontName, float size, float strokeWidth, float scale)
 
void BlendGlyphBitmapToTexture (const FT_Bitmap &bitmap, int targetX, int targetY, std::uint8_t r, std::uint8_t g, std::uint8_t b)
 
void BlendGlyphBitmapToTextureRGBA (const FT_Bitmap &bitmap, int targetX, int targetY, std::uint8_t r, std::uint8_t g, std::uint8_t b)
 
void BlendGlyphBitmapToTextureR8 (const FT_Bitmap &bitmap, int targetX, int targetY)
 
std::optional< CVector2D > GenerateStrokeGlyphBitmap (const FT_Glyph &glyph, std::uint16_t codepoint, FT_Render_Mode renderMode, const float baselineInAtlas)
 
std::optional< CVector2D > GenerateGlyphBitmap (FT_Glyph &glyph, std::uint16_t codepoint, FT_Render_Mode renderMode, CVector2D offset, const float baselineInAtlas)
 
const GlyphData * ExtractAndGenerateGlyph (std::uint16_t codepoint)
 
bool ConstructAtlasTexture (Renderer::Backend::IDevice *device)
 
Renderer::Backend::Sampler::Desc ChooseTextureFormatAndSampler ()
 

Static Private Member Functions

static void ftFaceDeleter (FT_Face face)
 
static void ftStrokerDeleter (FT_Stroker stroker)
 

Private Attributes

CTexturePtr m_Texture
 
bool m_HasRGB {true}
 
GlyphMap m_Glyphs
 
float m_Height
 
CRect m_Bounds
 
int m_AtlasX
 
int m_AtlasY
 
int m_AtlasWidth
 
int m_AtlasHeight
 
int m_AtlasPadding
 
bool m_IsDirty {false}
 
bool m_IsTextureInitialized {false}
 
float m_StrokeWidth {0.0f}
 
float m_Scale {1.0f}
 
std::unique_ptr< std::uint8_t[]> m_TexData
 
Renderer::Backend::Format m_TextureFormat {Renderer::Backend::Format::R8G8B8A8_UNORM}
 
int m_TextureFormatStride {4}
 
int m_AtlasSize {0}
 
float m_FontSize {0.0f}
 
std::string m_FontName
 
std::reference_wrapper< const std::array< float, 256 > > m_GammaCorrectionLUT
 
FT_Library m_FreeType
 
std::vector< std::unique_ptr< std::uint8_t[], AlignedDeleter > > m_FontsData
 
std::vector< UniqueFTFace > m_Faces
 
UniqueFTStroker m_Stroker {nullptr, &ftStrokerDeleter}
 

Static Private Attributes

static constexpr float MINIMAL_FONT_SIZE_ANTIALIASING {12.0f}
 Some fonts are not rendered well at small sizes, so we set a minimum size. More...
 

Friends

class CFontManager
 

Detailed Description

Storage for a bitmap font.

Loaded by CFontManager.

Member Typedef Documentation

◆ UniqueFTFace

using CFont::UniqueFTFace = std::unique_ptr<std::remove_pointer_t<FT_Face>, decltype(&ftFaceDeleter)>
private

◆ UniqueFTStroker

using CFont::UniqueFTStroker = std::unique_ptr<std::remove_pointer_t<FT_Stroker>, decltype(&ftStrokerDeleter)>
private

Constructor & Destructor Documentation

◆ CFont()

CFont::CFont ( FT_Library  library,
const std::array< float, 256 > &  gammaCorrection 
)
inline

◆ ~CFont()

CFont::~CFont ( )
default

Member Function Documentation

◆ AddFontFromPath()

bool CFont::AddFontFromPath ( const OsPath &  fontPath)
private

◆ BlendGlyphBitmapToTexture()

void CFont::BlendGlyphBitmapToTexture ( const FT_Bitmap &  bitmap,
int  targetX,
int  targetY,
std::uint8_t  r,
std::uint8_t  g,
std::uint8_t  b 
)
private

◆ BlendGlyphBitmapToTextureR8()

void CFont::BlendGlyphBitmapToTextureR8 ( const FT_Bitmap &  bitmap,
int  targetX,
int  targetY 
)
private

◆ BlendGlyphBitmapToTextureRGBA()

void CFont::BlendGlyphBitmapToTextureRGBA ( const FT_Bitmap &  bitmap,
int  targetX,
int  targetY,
std::uint8_t  r,
std::uint8_t  g,
std::uint8_t  b 
)
private

◆ CalculateStringSize()

void CFont::CalculateStringSize ( const wchar_t *  string,
float &  w,
float &  h 
)

◆ ChooseTextureFormatAndSampler()

Renderer::Backend::Sampler::Desc CFont::ChooseTextureFormatAndSampler ( )
private

◆ ConstructAtlasTexture()

bool CFont::ConstructAtlasTexture ( Renderer::Backend::IDevice *  device)
private

◆ ExtractAndGenerateGlyph()

const CFont::GlyphData * CFont::ExtractAndGenerateGlyph ( std::uint16_t  codepoint)
private

◆ ftFaceDeleter()

static void CFont::ftFaceDeleter ( FT_Face  face)
inlinestaticprivate

◆ ftStrokerDeleter()

static void CFont::ftStrokerDeleter ( FT_Stroker  stroker)
inlinestaticprivate

◆ GenerateGlyphBitmap()

std::optional< CVector2D > CFont::GenerateGlyphBitmap ( FT_Glyph &  glyph,
std::uint16_t  codepoint,
FT_Render_Mode  renderMode,
CVector2D  offset,
const float  baselineInAtlas 
)
private

◆ GenerateStrokeGlyphBitmap()

std::optional< CVector2D > CFont::GenerateStrokeGlyphBitmap ( const FT_Glyph &  glyph,
std::uint16_t  codepoint,
FT_Render_Mode  renderMode,
const float  baselineInAtlas 
)
private

◆ GetCapHeight()

float CFont::GetCapHeight ( )

In typography, cap height is the height of a capital letter above the baseline for a particular typeface.

It specifically is the height of capital letters that are flat—such as H or I—as opposed to round letters such as O, or pointed letters like A, both of which may display overshoot. The height of the small letters is the x-height. REf: https://en.wikipedia.org/wiki/Cap_height

◆ GetCharacterWidth()

float CFont::GetCharacterWidth ( wchar_t  c)

◆ GetGlyph()

const CFont::GlyphData * CFont::GetGlyph ( std::uint16_t  i)

◆ GetGlyphBounds()

void CFont::GetGlyphBounds ( float &  x0,
float &  y0,
float &  x1,
float &  y1 
) const
inline

◆ GetHeight()

float CFont::GetHeight ( ) const

◆ GetStrokeWidth()

float CFont::GetStrokeWidth ( ) const
inline

◆ GetTexture()

CTexturePtr CFont::GetTexture ( ) const
inline

◆ HasRGB()

bool CFont::HasRGB ( ) const
inline

◆ InitalizeAtlasTextureIfNeeded()

void CFont::InitalizeAtlasTextureIfNeeded ( Renderer::Backend::IDeviceCommandContext *  deviceCommandContext)

◆ MOVABLE()

CFont::MOVABLE ( CFont  )

◆ NONCOPYABLE()

CFont::NONCOPYABLE ( CFont  )

◆ SetFontParams()

bool CFont::SetFontParams ( Renderer::Backend::IDevice *  device,
const std::string &  fontName,
float  size,
float  strokeWidth,
float  scale 
)
private

◆ UploadAtlasTextureToGPU()

void CFont::UploadAtlasTextureToGPU ( Renderer::Backend::IDeviceCommandContext *  deviceCommandContext)

Friends And Related Function Documentation

◆ CFontManager

friend class CFontManager
friend

Member Data Documentation

◆ m_AtlasHeight

int CFont::m_AtlasHeight
private

◆ m_AtlasPadding

int CFont::m_AtlasPadding
private

◆ m_AtlasSize

int CFont::m_AtlasSize {0}
private

◆ m_AtlasWidth

int CFont::m_AtlasWidth
private

◆ m_AtlasX

int CFont::m_AtlasX
private

◆ m_AtlasY

int CFont::m_AtlasY
private

◆ m_Bounds

CRect CFont::m_Bounds
private

◆ m_Faces

std::vector<UniqueFTFace> CFont::m_Faces
private

◆ m_FontName

std::string CFont::m_FontName
private

◆ m_FontsData

std::vector<std::unique_ptr<std::uint8_t[], AlignedDeleter> > CFont::m_FontsData
private

◆ m_FontSize

float CFont::m_FontSize {0.0f}
private

◆ m_FreeType

FT_Library CFont::m_FreeType
private

◆ m_GammaCorrectionLUT

std::reference_wrapper<const std::array<float, 256> > CFont::m_GammaCorrectionLUT
private

◆ m_Glyphs

GlyphMap CFont::m_Glyphs
private

◆ m_HasRGB

bool CFont::m_HasRGB {true}
private

◆ m_Height

float CFont::m_Height
private

◆ m_IsDirty

bool CFont::m_IsDirty {false}
private

◆ m_IsTextureInitialized

bool CFont::m_IsTextureInitialized {false}
private

◆ m_Scale

float CFont::m_Scale {1.0f}
private

◆ m_Stroker

UniqueFTStroker CFont::m_Stroker {nullptr, &ftStrokerDeleter}
private

◆ m_StrokeWidth

float CFont::m_StrokeWidth {0.0f}
private

◆ m_TexData

std::unique_ptr<std::uint8_t[]> CFont::m_TexData
private

◆ m_Texture

CTexturePtr CFont::m_Texture
private

◆ m_TextureFormat

◆ m_TextureFormatStride

int CFont::m_TextureFormatStride {4}
private

◆ MINIMAL_FONT_SIZE_ANTIALIASING

constexpr float CFont::MINIMAL_FONT_SIZE_ANTIALIASING {12.0f}
staticconstexprprivate

Some fonts are not rendered well at small sizes, so we set a minimum size.

Because we are using a bitmap blending mode, when a font is using small size, We need to use a different render mode, one with less antialiasing.


The documentation for this class was generated from the following files: