Lysa  0.0
Lysa 3D Engine
Font Class Reference

Detailed Description

Font resource used to render text.

A font is defined by a font file and a size. Glyphs are packed into an atlas and common metrics (ascender, descender, line height) are exposed for text layout.

+ Inheritance diagram for Font:

Classes

struct  GlyphBounds
 
struct  GlyphInfo
 

Public Member Functions

 Font (const std::string &path)
 
 Font (const Font &font)
 
 ~Font () override
 
void getSize (const std::string &text, float fontScale, float &width, float &height)
 
float2 getSize (const std::string &text, float fontScale)
 
float getWidth (char c, float fontScale)
 
uint32 getFontSize () const
 
float getLineHeight () const
 
float getAscender () const
 
float getDescender () const
 
const GlyphInfogetGlyphInfo (uint32 index) const
 
const ImagegetAtlas () const
 
const FontParamsgetFontParams () const
 
void setOutlineColor (const float4 &color)
 
void setOutlineBias (const float bias)
 
void setOutlineWidthAbsolute (const float width)
 
void setOutlineWidthRelative (const float width)
 
void setOutlineBlur (const float blur)
 
void setOutlineThreshold (const float threshold)
 
auto getHarfBuzzFont () const
 
- Public Member Functions inherited from UnmanagedResource
 UnmanagedResource ()
 
 UnmanagedResource (const Resource &other)
 
- Public Member Functions inherited from Resource
bool operator== (const Resource &other) const
 
 Resource () = default
 
 Resource (const unique_id id)
 
virtual ~Resource () = default
 

Additional Inherited Members

- Public Attributes inherited from Resource
unique_id id {INVALID_ID}
 

Constructor & Destructor Documentation

Font ( const std::string &  path)

Construct a font resource from a font file.

Parameters
pathFont file path, relative to the application working directory.
Font ( const Font &  font)
~Font ( )
override

Member Function Documentation

float getAscender ( ) const
inline

Ascender in pixels (above the baseline).

const Image& getAtlas ( ) const
inline

Get the underlying glyph atlas image.

float getDescender ( ) const
inline

Descender in pixels (below the baseline).

const FontParams& getFontParams ( ) const
inline

Get current font rendering parameters.

uint32 getFontSize ( ) const
inline

Get the font size used to build the atlas (in pixels).

Returns
Atlas font size in pixels.
const GlyphInfo& getGlyphInfo ( uint32  index) const

Retrieve glyph information by glyph index.

Parameters
indexGlyph index as returned by the shaper.
auto getHarfBuzzFont ( ) const
inline

Access the underlying HarfBuzz font handle.

float getLineHeight ( ) const
inline

Line height relative to the font size.

float2 getSize ( const std::string &  text,
float  fontScale 
)

Compute the size in pixels for a UTF-8 string.

Parameters
textInput text.
fontScaleScale factor applied to the base font size (1.0 = atlas size).
Returns
Width (x) and height (y) in pixels.
void getSize ( const std::string &  text,
float  fontScale,
float &  width,
float &  height 
)

Compute the size in pixels for a UTF-8 string.

Parameters
textInput text.
fontScaleScale factor applied to the base font size (1.0 = atlas size).
widthOutput total width in pixels.
heightOutput total height in pixels.
float getWidth ( char  c,
float  fontScale 
)
void setOutlineBias ( const float  bias)
inline

Set the outline bias.

void setOutlineBlur ( const float  blur)
inline

Set the outline blur factor.

void setOutlineColor ( const float4 &  color)
inline

Set the outline color.

void setOutlineThreshold ( const float  threshold)
inline

Set the SDF/MSDF threshold.

void setOutlineWidthAbsolute ( const float  width)
inline

Set the absolute outline width (in pixels).

void setOutlineWidthRelative ( const float  width)
inline

Set the relative outline width (scaled by font size).