Lysa  0.0
Lysa 3D Engine
Font Class Reference

Detailed Description

Font resource used to render text.

+ Inheritance diagram for Font:

Classes

struct  Caret
 
struct  GlyphBounds
 
struct  GlyphInfo
 
struct  ShapedGlyph
 
struct  TextRun
 

Public Member Functions

 Font (const std::string &path)
 
 Font (std::span< const char > fontData, std::string_view atlasMetadata, std::span< const char > atlasImage, const std::string &name)
 
 Font (const Font &font)
 
 ~Font () override
 
std::shared_ptr< Font > clone ()
 
void getSize (const std::string &text, float fontScale, float &width, float &height)
 
void getSize (const std::string &text, float fontScale, float &width, float &height, TextDirection direction)
 
float2 getSize (const std::string &text, float fontScale)
 
float2 getSize (const std::string &text, float fontScale, TextDirection direction)
 
std::vector< ShapedGlyph > shape (const std::string &text, TextDirection direction=TextDirection::AUTO) const
 
std::vector< Caret > caretPositions (const std::string &text, TextDirection direction=TextDirection::AUTO) const
 
float getWidth (char c, float fontScale)
 
uint32 getFontSize () const
 
float getLineHeight () const
 
float getAscender () const
 
float getDescender () const
 
const GlyphInfo & getGlyphInfo (uint32 index) const
 
const Image & getAtlas () const
 
const FontParams & getFontParams () const
 
float2 getPxRange () const
 
float4 getOutlineColor () const
 
float getOutlineThreshold () const
 
float getOutlineBias () const
 
float getOutlineWidthAbsolute () const
 
float getOutlineWidthRelative () const
 
float getRoundedOutline () const
 
float getRoundedInterior () const
 
float getOutlineBlur () const
 
void setPxRange (const float2 &range)
 
void setOutlineColor (const float4 &color)
 
void setOutlineBias (float bias)
 
void setOutlineWidthAbsolute (float width)
 
void setOutlineWidthRelative (float width)
 
void setOutlineBlur (float blur)
 
void setOutlineThreshold (float threshold)
 
void setRoundedOutline (float roundedOutline)
 
void setRoundedInterior (float roundedInterior)
 
auto getHarfBuzzFont () const
 
void setDirty ()
 
bool isDirty () const
 
void decrementDirty ()
 
- 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
 

Static Public Member Functions

static std::vector< TextRun > visualRuns (const std::string &text, TextDirection direction=TextDirection::AUTO)
 
static std::vector< uint32 > textBoundaries (const std::string &text)
 
static TextDirection localeDirection (const std::string &locale)
 

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 ( std::span< const char >  fontData,
std::string_view  atlasMetadata,
std::span< const char >  atlasImage,
const std::string &  name 
)

Construct a font resource from data in memory.

Parameters
fontDataContent of the TTF or OTF file.
atlasMetadataContent of the JSON atlas description generated by msdf-atlas-gen.
atlasImageContent of the PNG file holding the glyph atlas.
nameName of the font, used to identify the atlas image and in error messages.
Font ( const Font &  font)
~Font ( )
override

Member Function Documentation

std::vector<Caret> caretPositions ( const std::string &  text,
TextDirection  direction = TextDirection::AUTO 
) const

Returns caret positions

std::shared_ptr<Font> clone ( )
void decrementDirty ( )
inline
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.

float getOutlineBias ( ) const
inline

Get the outline bias.

float getOutlineBlur ( ) const
inline

Get the outline blur factor.

float4 getOutlineColor ( ) const
inline

Get the outline color (RGBA).

float getOutlineThreshold ( ) const
inline

Get the SDF/MSDF threshold.

float getOutlineWidthAbsolute ( ) const
inline

Get the absolute outline width (in pixels).

float getOutlineWidthRelative ( ) const
inline

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

float2 getPxRange ( ) const
inline

Get the SDF/MSDF pixel range (x = lower, y = upper).

float getRoundedInterior ( ) const
inline
float getRoundedOutline ( ) const
inline
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.
void getSize ( const std::string &  text,
float  fontScale,
float &  width,
float &  height,
TextDirection  direction 
)

Computes the size on a ext.

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

Computes the size with an explicit Unicode paragraph direction.

float getWidth ( char  c,
float  fontScale 
)
bool isDirty ( ) const
inline
static TextDirection localeDirection ( const std::string &  locale)
static

Resolves a locale's default writing direction

void setDirty ( )
void setOutlineBias ( float  bias)

Set the outline bias.

void setOutlineBlur ( float  blur)

Set the outline blur factor.

void setOutlineColor ( const float4 &  color)

Set the outline color.

void setOutlineThreshold ( float  threshold)

Set the SDF/MSDF threshold.

void setOutlineWidthAbsolute ( float  width)

Set the absolute outline width (in pixels).

void setOutlineWidthRelative ( float  width)

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

void setPxRange ( const float2 &  range)

Set the SDF/MSDF pixel range (x = lower, y = upper).

void setRoundedInterior ( float  roundedInterior)
void setRoundedOutline ( float  roundedOutline)
std::vector<ShapedGlyph> shape ( const std::string &  text,
TextDirection  direction = TextDirection::AUTO 
) const

Applies Unicode bidi ordering, script itemization and HarfBuzz shaping

static std::vector<uint32> textBoundaries ( const std::string &  text)
static

Returns UTF-8 byte offsets of extended grapheme boundaries

static std::vector<TextRun> visualRuns ( const std::string &  text,
TextDirection  direction = TextDirection::AUTO 
)
static

Resolves Unicode bidi runs without changing the logical text