Open 3D Engine AtomLyIntegration Gem API Reference  24.09
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::FontTexture Class Reference

#include <FontTexture.h>

Public Member Functions

int CreateFromFile (const AZStd::string &fileName, int width, int height, AZ::FontSmoothMethod smoothMethod, AZ::FontSmoothAmount smoothAmount, int widthCharCount=16, int heightCharCount=16)
 
int CreateFromMemory (unsigned char *fileData, int dataSize, int width, int height, AZ::FontSmoothMethod smoothMethod, AZ::FontSmoothAmount smoothAmount, int widthCharCount, int heightCharCount, float sizeRatio)
 
int Create (int width, int height, AZ::FontSmoothMethod smoothMethod, AZ::FontSmoothAmount smoothAmount, int widthCharCount=16, int heightCharCount=16, float sizeRatio=IFFontConstants::defaultSizeRatio)
 
int Release ()
 
int SetEncoding (FT_Encoding encoding)
 
FT_Encoding GetEncoding ()
 
int GetCellWidth ()
 
int GetCellHeight ()
 
int GetWidth ()
 
int GetHeight ()
 
int GetWidthCellCount ()
 
int GetHeightCellCount ()
 
float GetTextureCellWidth ()
 
float GetTextureCellHeight ()
 
FONT_TEXTURE_TYPE * GetBuffer ()
 
uint32_t GetSlotChar (int slotIndex) const
 
TextureSlotGetCharSlot (uint32_t character, const AtomFont::GlyphSize &glyphSize=AtomFont::defaultGlyphSize)
 
TextureSlotGetGradientSlot ()
 
TextureSlotGetLRUSlot ()
 
TextureSlotGetMRUSlot ()
 
int PreCacheString (const char *string, int *updated=0, float sizeRatio=IFFontConstants::defaultSizeRatio, const AtomFont::GlyphSize &glyphSize=AtomFont::defaultGlyphSize, const FFont::FontHintParams &glyphFlags=FFont::FontHintParams())
 
void GetTextureCoord (TextureSlot *slot, float texCoords[4], int &characterSizeX, int &characterSizeY, int &m_characterOffsetX, int &m_characterOffsetY, const AtomFont::GlyphSize &glyphSize=AtomFont::defaultGlyphSize) const
 
int GetCharacterWidth (uint32_t character) const
 
int GetHorizontalAdvance (uint32_t character, const AtomFont::GlyphSize &glyphSize=AtomFont::defaultGlyphSize) const
 
void CreateGradientSlot ()
 
int WriteToFile (const AZStd::string &fileName)
 
bool GetMonospaced () const
 
Vec2 GetKerning (uint32_t leftGlyph, uint32_t rightGlyph)
 
float GetAscenderToHeightRatio ()
 

Static Public Member Functions

static AtomFont::GlyphSize ClampGlyphSize (const AtomFont::GlyphSize &glyphSize, int cellWidth, int cellHeight)
 Clamps the given glyph size to the given max cell width and height dimensions.
 

Detailed Description

Stores the glyphs of a font within a single cpu texture.

The texture resolution is configurable, as is the number of slots within the texture.

A texture slot contains a single glyph within the font and are uniform size throughout the font texture (each slot occupies the same size regardless of the size of a glyph being stored, so a '.' occupies the same amount of space as a 'W', for example).

Font glyph buffrs are read from FreeType and copied into the texture.

See also
TextureSlot, FontRenderer

Member Function Documentation

◆ CreateFromMemory()

int AZ::FontTexture::CreateFromMemory ( unsigned char *  fileData,
int  dataSize,
int  width,
int  height,
AZ::FontSmoothMethod  smoothMethod,
AZ::FontSmoothAmount  smoothAmount,
int  widthCharCount,
int  heightCharCount,
float  sizeRatio 
)

Default texture slot width/height is 16x8 slots, allowing for 128 glyphs to be stored in the font texture. This was previously 16x16, allowing 256 glyphs to be stored. For reference, there are 95 printable ASCII characters, so by reducing the number of slots, the height of the font texture can be halved (for some nice memory savings). We may want to make this configurable in the font XML (especially for languages with a large number of printable chars).

◆ GetHorizontalAdvance()

int AZ::FontTexture::GetHorizontalAdvance ( uint32_t  character,
const AtomFont::GlyphSize glyphSize = AtomFont::defaultGlyphSize 
) const

Gets the horizontal advance for the given glyph/char.

Parameters
characterThe glyph (UTF32) to get the horizontal advance for.
glyphSizeThe rendered size of the glyph to get the advance for (the same glyph could be stored in the font texture at multiple sizes).

◆ PreCacheString()

int AZ::FontTexture::PreCacheString ( const char *  string,
int *  updated = 0,
float  sizeRatio = IFFontConstants::defaultSizeRatio,
const AtomFont::GlyphSize glyphSize = AtomFont::defaultGlyphSize,
const FFont::FontHintParams glyphFlags = FFont::FontHintParams() 
)

Returns 1 if texture updated, returns 2 if texture not updated, returns 0 on error

Parameters
stringA string of glyphs (UTF8) to added to the font texture (if they don't already exist in the font texture)
updatedis the number of slots updated
sizeRatioA sizing scale that gets applied to all glyphs sizes before they are stored in the font texture.
glyphSizeThe resolution to render the glyphs in string at.
glyphFlagsControls hinting behavior for glyphs rendered to the font texture.

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