class Font

Inherits: Resource

Font resource containing data about textual characters and how to render text.

Contains one or multiple font bitmaps, each for a specific size.

Public

Methods

~Font

virtual ~Font() noexcept

GetBitmap

SPtr<FontBitmapInformation> GetBitmap(float size) const

Returns font bitmap information for a specific font size.

size
Size of the font in points.

Returns: Bitmap object if it exists, false otherwise.

GetClosestExistingBitmapSize

float GetClosestExistingBitmapSize(float size) const

Finds a rendered bitmap closest to the provided size.

size
Size of the bitmap in points.

Returns: Nearest available bitmap size.

GetPointSizeForGlyphThatFitsArea

float GetPointSizeForGlyphThatFitsArea(u32 glyphId, const Size2I &size) const

Calculates the required font size (in points) in order to render a glyph that fits within an area of pixels, without stretching or cropping.

FindCharacterInformation

const CharacterInformation *FindCharacterInformation(u32 characterId, float sizeInPoints) const

Attempts to find information about a character with the specified id and size.

Returns null if character was not yet rendered via RenderGlyphs.

GetPage

const FontBitmapPage &GetPage(u32 pageIndex) const

Returns a font page information for a page at the specified index.

RenderGlyphs

bool RenderGlyphs(float sizeInPoints, const TArrayView<u32> &characterIds, bool bake = false)

Renders glyphs for particular characters in a particular size.

The rendered glyphs will be added to the first free texture page, or new texture page(s) will be allocated. Returns true if successful.

sizeInPoints
Size of the glyph in points.
characterIds
UTF32 character identifiers of the characters to render.
bake
If true the rendered glyph will be saved with the font the next time it is serialized, so it doesn't need to be re-rendered the next time its loaded.

ClearGlyphs

void ClearGlyphs(bool onlyRuntime = true)

Clears all the rendered glyph information.

onlyRuntime
If true, only data for runtime rendered glyphs will be cleared, baked data will remain.

ClearGlyphs

void ClearGlyphs(float size, bool onlyRuntime = true)

Clears all the rendered glyph information for a specific font size.

size
Font size in points.
onlyRuntime
If true, only data for runtime rendered glyphs will be cleared, baked data will remain.

staticCreate

static HFont Create(const FontCreateInformation &createInformation)

Creates a new font.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const override

Returns an interface you can use to access class' Run Time Type Information.

Internal

Methods

ClearGlyphs

void ClearGlyphs(FontBitmapInformation &bitmapInformation, bool onlyRuntime = true)

Clears all the rendered glyph information from the provided bitmap information.

bitmapInformation
Structure containing all character and other information for a particular font size.
onlyRuntime
If true, only data for runtime rendered glyphs will be cleared, baked data will remain.

RemovePage

void RemovePage(u32 pageIndex)

Removes a page at the specified index and updates all the existing character information to point to the next page.

All characters referencing this particular page must have been removed before calling this method.

Initialize

void Initialize() override

Initializes all the internal data of this object.

Must be called right after construction for new objects, or after deserialization for deserialized objects. If requested, render proxy is created and queued for initialization on the render thread.

Destroy

void Destroy() override

Frees all the data held by this object.

If the object has a render proxy, the internal reference to the render proxy will be released, but the proxy will not be destroyed unless this was the last reference. If render proxy destruction does happen, it is not immediate, but rather queued for destruction on the render thread.

staticCreateShared

static SPtr<Font> CreateShared(const FontCreateInformation &createInformation)

Creates a new font as a pointer instead of a resource handle.

staticCreateEmpty

static SPtr<Font> CreateEmpty()

Creates a Font without initializing it.

staticGetQuantizedFontSize

static float GetQuantizedFontSize(float size)

Retrieves font size that is quantized in a way we can use it to perform bitmap lookup.

Protected

Constructors

Font

Font(const FontCreateInformation &createInformation)

Methods

InitializeFontRenderer

bool InitializeFontRenderer()

Creates the font renderer for the currently assigned font data.

This must be called before RenderGlyph() is called. Returns false if the renderer cannot be initialized (usually means the font data is missing, or the renderer is already initialized).

DestroyFontRenderer

void DestroyFontRenderer()

Destroys the font renderer created in InitializeFontRenderer().

GetCoreDependencies

void GetCoreDependencies(Vector<CoreObject *> &dependencies) override

Populates the provided array with all core objects that this core object depends upon.

Dependencies are required for syncing to the render thread, so the system can be aware to update the dependant objects if a dependency is marked as dirty (for example updating a camera's viewport should also trigger an update on camera so it has a chance to potentially update its data).

Private

Fields

mInformation

FontInformation mInformation

mCharactersByPointSize

UnorderedMap<float, SPtr<FontBitmapInformation>> mCharactersByPointSize

mFontPages

Vector<FontBitmapPage> mFontPages

mImplementation

Implementation * mImplementation