You.i Engine
CYITextEngine Class Reference

Detailed Description

Class for text rendering.

#include <graphics/YiTextEngine.h>

Public Member Functions

 CYITextEngine ()
 
virtual ~CYITextEngine ()
 
bool Init (uint16_t nMaxFonts, uint16_t uFontAtlasSize)
 
bool IsInitialized ()
 
std::unique_ptr< CYITextLayoutCreateTextLayout () const
 
ssize_t GetFontId (const CYIString &fontName) const
 
ssize_t GetFontId (const CYIString &fontFamilyName, const CYIString &fontStyleName, bool bIgnoreCase=false) const
 
ssize_t GetFontIdFromNameAndStyle (const CYIString &fontName, const CYIString &fontStyleName, bool bIgnoreCase=false) const
 
const YI_FONT_INFOGetFontInfo (ssize_t nFontID) const
 
std::vector< CYIStringGetFontStyles (ssize_t nFontID) const
 
std::vector< CYIStringGetFontStyles (const CYIString &fontFamilyName) const
 
std::vector< CYIStringReadFontStyles (const CYIString &url) const
 
std::vector< CYIStringReadFontStyles (const uint8_t *pFontData, uint32_t uDataSize) const
 
ssize_t AddFont (const CYIString &URL)
 
ssize_t AddFont (const CYIString &URL, const CYIString &fontName)
 
ssize_t AddFont (const CYIString &URL, const CYIString &fontName, const CYIString &fontStyle)
 
ssize_t AddFontWithOverrides (const CYIString &URL, const CYIString &fontName, const CYIString &fontFamily, const CYIString &fontStyle)
 
ssize_t AddFont (const uint8_t *pFontData, uint32_t uDataSize)
 
bool IsFontInFile (const CYIString &familyName, const CYIString &styleName, const CYIString &URL)
 
uint32_t GetNumFonts ()
 
YI_TEXT_HEIGHT GetTextHeight (ssize_t nFontID, int32_t nFontSize)
 
bool RenderText (const CYITextLayout *pTextLayout, CYIBitmap *pDest, const YI_TEXT_RENDER_INFO &rTextRenderInfo, const glm::vec2 &vRenderOffset, const YI_FLOAT_RECT *pTextExtents=nullptr)
 
int32_t RenderGlyphIntoAtlas (YI_GLYPH_DETAILS *pGlyph, CYIAbstractTextAtlas *pAtlas)
 
uint32_t GetCharacterIndex (ssize_t nFontID, uint32_t uChar) const
 
int32_t GetIndexOfPosition (const CYITextLayout *pTextLayout, float fX, float fY, float fHorizontalPixelRatio, float fVerticalPixelRatio) const
 
YI_FLOAT_RECT GetRectForTextRange (const CYITextLayout *pTextLayout, int32_t nStartIndex, int32_t nEndIndex, float fHorizontalPixelRatio, float fVerticalPixelRatio) const
 
CYITextAtlasGetTextAtlas ()
 
CYISDFTextAtlasGetSDFTextAtlas ()
 
bool SetTextAtlas (CYITextAtlas *pAtlas)
 
bool SetSDFTextAtlas (CYISDFTextAtlas *pAtlas)
 
CYITextRenderer * GetTextRenderer ()
 
uint16_t GetFontAtlasSize () const
 
std::shared_ptr< const CYITextLayoutGetTextLayout (const YI_TEXT_RENDER_INFO &rTextInfo)
 
void TryRemoveCachedTextLayout (const YI_TEXT_RENDER_INFO &rTextInfo)
 
ssize_t FindFontByFamilyName (const CYIString &fontFamilyName, YI_FONT_STYLE fontStyle=YI_FONT_STYLE_REGULAR)
 

Static Public Attributes

static const uint32_t g_uTextEllipsisCodepointIndex
 
static const float g_fLineSpacingFactor
 

Constructor & Destructor Documentation

CYITextEngine::CYITextEngine ( )
virtual CYITextEngine::~CYITextEngine ( )
virtual

Member Function Documentation

ssize_t CYITextEngine::AddFont ( const CYIString URL)

Add a font

ssize_t CYITextEngine::AddFont ( const CYIString URL,
const CYIString fontName 
)

Add a font. If the font file contains multiple styles, only the first style will be loaded and a warning will be logged.

See also
AddFont(const CYIString&, const CYIString&, const CYIString&)
ssize_t CYITextEngine::AddFont ( const CYIString URL,
const CYIString fontName,
const CYIString fontStyle 
)

Add a font. If the font file contains multiple styles and fontStyle is non-empty, that font style is loaded. If fontStyle is non-empty and that style cannot be found in the font file, a warning is logged and the first style is loaded instead.

ssize_t CYITextEngine::AddFont ( const uint8_t *  pFontData,
uint32_t  uDataSize 
)

Add a font from memory

ssize_t CYITextEngine::AddFontWithOverrides ( const CYIString URL,
const CYIString fontName,
const CYIString fontFamily,
const CYIString fontStyle 
)

Add a font. This overrides the font family and font style from the font itself and instead uses the provided values.

std::unique_ptr<CYITextLayout> CYITextEngine::CreateTextLayout ( ) const
ssize_t CYITextEngine::FindFontByFamilyName ( const CYIString fontFamilyName,
YI_FONT_STYLE  fontStyle = YI_FONT_STYLE_REGULAR 
)

Attempts to find a font with similar properties as the fontFamilyName. Returns the font ID for the first available font if no matches are found. Returns -1 if no fonts are available.

uint32_t CYITextEngine::GetCharacterIndex ( ssize_t  nFontID,
uint32_t  uChar 
) const

Retrieves the index of the given character in the font renderer. The index is managed by the font renderer.

uint16_t CYITextEngine::GetFontAtlasSize ( ) const

Returns the font atlas pixel dimension that the engine is configured to use. Font atlases are square so this dimension represents both width and height.

ssize_t CYITextEngine::GetFontId ( const CYIString fontName) const

Returns the font ID for the specified font name fontName. Returns -1 if the font cannot be found.

ssize_t CYITextEngine::GetFontId ( const CYIString fontFamilyName,
const CYIString fontStyleName,
bool  bIgnoreCase = false 
) const

Returns the font ID for the specified font family fontFamilyName and font style fontStyleName . If bIgnoreCase is true, the search will be case insensitive. Returns -1 if the font cannot be found.

ssize_t CYITextEngine::GetFontIdFromNameAndStyle ( const CYIString fontName,
const CYIString fontStyleName,
bool  bIgnoreCase = false 
) const

Returns the font ID for the specified font name fontName and font style fontStyleName. If bIgnoreCase is true, the search will be case insensitive. Returns -1 if the font cannot be found.

const YI_FONT_INFO& CYITextEngine::GetFontInfo ( ssize_t  nFontID) const

Returns the font information object for the font with engine ID nFontID. Returns an empty font information object if the provided font ID does not exist.

std::vector<CYIString> CYITextEngine::GetFontStyles ( ssize_t  nFontID) const

Returns a list of all available font styles for fonts that have the same font family name as the font with font ID nFontID .

std::vector<CYIString> CYITextEngine::GetFontStyles ( const CYIString fontFamilyName) const

Returns a list of all available font styles for family name fontFamilyName .

int32_t CYITextEngine::GetIndexOfPosition ( const CYITextLayout pTextLayout,
float  fX,
float  fY,
float  fHorizontalPixelRatio,
float  fVerticalPixelRatio 
) const

Get the index in the text closest to the specified local coordinate position, relative to the top left corner of the node containing the text. The horizontal and vertical pixel ratios can be obtained from the camera and are based on the scaling type used to load the After Effects composition. Currently this is only supported for single line text but the y position and vertical pixel ratios are added for future multiline support.

uint32_t CYITextEngine::GetNumFonts ( )

Get the number of fonts loaded

YI_FLOAT_RECT CYITextEngine::GetRectForTextRange ( const CYITextLayout pTextLayout,
int32_t  nStartIndex,
int32_t  nEndIndex,
float  fHorizontalPixelRatio,
float  fVerticalPixelRatio 
) const

Get the rect for the cached layout of text that has been rendered. If no text has been rendered, by calling RenderText previously, or invalid index values are passed then the rect will be set to 0 for all values.

CYISDFTextAtlas* CYITextEngine::GetSDFTextAtlas ( )

Returns the SDF text atlas. This will return NULL if it doesn't exist.

CYITextAtlas* CYITextEngine::GetTextAtlas ( )

Returns the regular text atlas.

YI_TEXT_HEIGHT CYITextEngine::GetTextHeight ( ssize_t  nFontID,
int32_t  nFontSize 
)

Get the total height of a font

std::shared_ptr<const CYITextLayout> CYITextEngine::GetTextLayout ( const YI_TEXT_RENDER_INFO rTextInfo)

Returns a computed or cached layout for the provided newInfo. If the provided text info object does not correspond to an existing cached text layout, a new text layout will be created and the text will be laid-out immediately.

CYITextRenderer* CYITextEngine::GetTextRenderer ( )
bool CYITextEngine::Init ( uint16_t  nMaxFonts,
uint16_t  uFontAtlasSize 
)

Initialize text engine with the maximuim number of fonts to cache, and the square pixel dimension of font atlases.

bool CYITextEngine::IsFontInFile ( const CYIString familyName,
const CYIString styleName,
const CYIString URL 
)

Returns true if the combination of familyName and styleName is the first one found in the file specified by URL

bool CYITextEngine::IsInitialized ( )
std::vector<CYIString> CYITextEngine::ReadFontStyles ( const CYIString url) const

Returns a list of all available font styles in the font file specified by url.

std::vector<CYIString> CYITextEngine::ReadFontStyles ( const uint8_t *  pFontData,
uint32_t  uDataSize 
) const

Returns a list of all available font styles in the font data pFontData.

int32_t CYITextEngine::RenderGlyphIntoAtlas ( YI_GLYPH_DETAILS pGlyph,
CYIAbstractTextAtlas pAtlas 
)

New rendering creating from atlas

Warning
This function does not check if the glyph is already present in the text atlas for performance reason. It is the user's responsibility to make sure that the texture atlas is not available before calling this function. The check can be done by calling CYITextEngine::GetFontAtlasTexture, which would return nullptr when the glyph is not available in the text atlas.
bool CYITextEngine::RenderText ( const CYITextLayout pTextLayout,
CYIBitmap pDest,
const YI_TEXT_RENDER_INFO rTextRenderInfo,
const glm::vec2 &  vRenderOffset,
const YI_FLOAT_RECT pTextExtents = nullptr 
)

Original rendering for simple word into single bitmap. The text must have been laid-out already in the pTextLayout object.

bool CYITextEngine::SetSDFTextAtlas ( CYISDFTextAtlas pAtlas)

Sets the SDF text atlas. Returns false if the current SDF atlas is not NULL.

bool CYITextEngine::SetTextAtlas ( CYITextAtlas pAtlas)

Sets the regular text atlas. Returns false if the current atlas is not NULL.

void CYITextEngine::TryRemoveCachedTextLayout ( const YI_TEXT_RENDER_INFO rTextInfo)

Attempts to remove a cached text layout. The layout will be removed only if there are no remaining users of it.

Member Data Documentation

const float CYITextEngine::g_fLineSpacingFactor
static

The factor used to calculate the spacing between lines of text. This is multiplied by a line's font size to get a line's leading value.

const uint32_t CYITextEngine::g_uTextEllipsisCodepointIndex
static

The codepoint index that should be used to set a style for the 'ellipsis' text.


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