resonance 1.0.1
Loading...
Searching...
No Matches
Rnd::Font Class Reference

Glyph atlas, either a host font description or a grid of cells inside a material texture. More...

#include <font.h>

Inheritance diagram for Rnd::Font:
Collaboration diagram for Rnd::Font:

Classes

class  CharInfo
 Measured metrics of one glyph. More...

Public Types

enum  Type { kFontTypeDefault = 0 , kFontTypeBuiltin = 1 , kFontTypeMaterial = 2 }
 Which of the two descriptions a font supplies. More...

Public Member Functions

 Font (const HxStr &name)
 Construct a Default font with a one-cell grid.
virtual ~Font ()
 Drop the reference on the material and release the character map.
virtual void DumpText (Dbg &sink)
 Write a description of this font to sink.
virtual void Save (Stream &stream)
 Write this font to stream at revision 2.
virtual void Replace (Object *pFrom, Object *pTo)
 Retarget the material when it is the object being replaced.
virtual const HxStr & ClassName () const
 Report the class key a .rnd file writes for a font.
virtual void Copy (const Object *pSource, unsigned nFlags)
 Copy the state of pSource into this font.
virtual void Load (Stream &stream)
 Read this font from stream.
virtual void SetBuiltin (int nHeight, FontWeight weight, int nItalic, FontFamily family, const HxStr &name)
 Describe a Builtin host font.
virtual void GetBuiltin (int *nHeightOut, FontWeight *weightOut, int *nItalicOut, FontFamily *familyOut, HxStr &nameOut)
 Report the Builtin host font description.
float GetCharAdvance (char ch)
 Report the horizontal advance of one character.
void GetCharUV (char ch, Vector2 &uv0, Vector2 &uv1)
 Report the two texture-coordinate corners of one character.
void BuildCharMap ()
 Measure every character of mChars and record its metrics in mCharMap.
void SetAtlas (Mat *pMat, const HxStr &chars, float flRows, float flCols, float flSize, float flSpace)
 Describe a Material font's glyph atlas in one call.
void SetMat (Mat *pMat)
 Replace the glyph atlas material.
void SetSize (float flSize)
 Change the height one cell occupies.
Public Member Functions inherited from Rnd::Object
 Object ()
 Construct an unnamed object.
 Object (const HxStr &name)
 Construct an object and register it under name.
virtual ~Object ()
 Erase the registry entry and release the name buffer.
void SetName (const HxStr &name)
 Re-register this object under a different name.
void AddRef (Object *pReferrer)
 Register pReferrer as a store of a pointer to this object.
void RemoveRef (Object *pReferrer)
 Drop one registration made by AddRef().

Static Public Member Functions

static void * operator new (size_t nSize)
 Allocate a font under the tag "Rnd::Font".
static void operator delete (void *pBlock)
 Release a font to the tagged heap.

Public Attributes

Type mType
 Which of the two descriptions this font supplies.
Mat * mMat
 Material whose first texture supplies the glyph atlas.
float mRows
 Cell rows of the glyph atlas.
float mCols
 Cell columns of the glyph atlas.
float mSize
 Height one cell occupies, in the units Rnd::Text builds its mesh in.
float mSpace
 Tracking added after every glyph, in the same units as mSize.
Public Attributes inherited from Rnd::Object
HxStr mName
int mInternal

Additional Inherited Members

Protected Member Functions inherited from Rnd::Object
void ReleaseAllRefs ()
 Tell every referrer to drop its pointer to this object.
Protected Attributes inherited from Rnd::Object
std::list< Object * > mRefs

Detailed Description

Glyph atlas, either a host font description or a grid of cells inside a material texture.

Its RTTI descriptor is at 0x008ef4c0. It has Rnd::Object as its only public non-virtual base at offset 0. The factory at 0x004cf060 pins the class at 0x60 bytes by requesting exactly that many. The Rnd::Object vptr therefore sits at +0x18 and this class's members run from +0x1c to +0x5f with no padding. The ten-entry vtable is at 0x008225d8, eight Rnd::Object slots followed by the pair of Builtin accessors this class declares.

The member titles come from the text DumpText() writes, "type:", " height:", " weight:", "italic:", " family:", " name:", " mat:", " rows:", " cols:", "size:", and " space:".

A Material font divides the first texture of its material into mRows by mCols cells of equal size and assigns the characters of mChars to those cells in reading order. BuildCharMap() then measures every glyph and records the result in mCharMap, so a character absent from mChars has no metrics, no advance, and a collapsed quad.

Member Enumeration Documentation

◆ Type

Which of the two descriptions a font supplies.

The three titles come from the printer at 0x004d07e0. The printer writes 'Default', 'Builtin', and 'Material' for the values below. A Builtin font describes a host font by height, weight, italic flag, family, and face name. A Material font is a glyph atlas inside a Rnd::Mat texture, and it is the only kind Rnd::Text builds geometry for.

Enumerator
kFontTypeDefault 
kFontTypeBuiltin 
kFontTypeMaterial 

Constructor & Destructor Documentation

◆ Font()

Rnd::Font::Font ( const HxStr & name)
explicit

Construct a Default font with a one-cell grid.

The height starts at 12, the weight at Normal, the family at Roman, the italic flag clear, both grid dimensions at 1.0, and the cell size and the tracking at 0.0. Neither string is allocated and no material is attached, so a font built this way measures nothing until it is loaded or copied.

Parameters
nameThe registry key for this object.
Ghidra address:
NTSC-U/C: 0x004cb1e8
Ghidra address:
PAL: 0x005094a8

◆ ~Font()

virtual Rnd::Font::~Font ( )
virtual

Drop the reference on the material and release the character map.

Ghidra address:
NTSC-U/C: 0x004cee70
Ghidra address:
PAL: 0x0050d1a8

Member Function Documentation

◆ operator new()

void * Rnd::Font::operator new ( size_t nSize)
static

Allocate a font under the tag "Rnd::Font".

Parameters
nSizeThe object size the compiler supplies.
Returns
The block.
Ghidra address:
NTSC-U/C: 0x004cecc0
Ghidra address:
PAL: 0x0050cff8

◆ operator delete()

void Rnd::Font::operator delete ( void * pBlock)
static

Release a font to the tagged heap.

Parameters
pBlockThe block.
Ghidra address:
NTSC-U/C: 0x004cece0
Ghidra address:
PAL: 0x0050d018

◆ DumpText()

virtual void Rnd::Font::DumpText ( Dbg & sink)
virtual

Write a description of this font to sink.

The base description comes first. Everything below is produced only at a positive dump level, and which fields follow the class tag depends on mType: a Builtin font writes the host font description and a Material font writes the atlas, while a Default font writes neither.

Parameters
sinkThe diagnostic sink to write to.
Ghidra address:
NTSC-U/C: 0x004ca470
Ghidra address:
PAL: 0x005086d8

Reimplemented from Rnd::Object.

◆ Save()

virtual void Rnd::Font::Save ( Stream & stream)
virtual

Write this font to stream at revision 2.

Parameters
streamThe stream to write to.
Ghidra address:
NTSC-U/C: 0x004ca720
Ghidra address:
PAL: 0x00508988

Implements Rnd::Object.

◆ Replace()

virtual void Rnd::Font::Replace ( Object * pFrom,
Object * pTo )
virtual

Retarget the material when it is the object being replaced.

Parameters
pFromThe object being replaced.
pToThe replacement, or null.
Ghidra address:
NTSC-U/C: 0x004d0690
Ghidra address:
PAL: 0x0050eac8

Implements Rnd::Object.

◆ ClassName()

virtual const HxStr & Rnd::Font::ClassName ( ) const
virtual

Report the class key a .rnd file writes for a font.

The returned string is the global at 0x006fecb0, which the class registration fills with "Font".

Returns
The class key.
Ghidra address:
NTSC-U/C: 0x004cefd0
Ghidra address:
PAL: 0x0050d330

Implements Rnd::Object.

◆ Copy()

virtual void Rnd::Font::Copy ( const Object * pSource,
unsigned nFlags )
virtual

Copy the state of pSource into this font.

Every field except the object name is copied and the character map is then emptied. nFlags is not read, and no base implementation is invoked. A pSource that is not a Font is dereferenced through the null the cast produces rather than rejected.

Parameters
pSourceThe font to copy from.
nFlagsUnread.
Ghidra address:
NTSC-U/C: 0x004cb0b8
Ghidra address:
PAL: 0x00509378

Implements Rnd::Object.

◆ Load()

virtual void Rnd::Font::Load ( Stream & stream)
virtual

Read this font from stream.

A revision above 2 produces the report "Can't load new Font" followed by the abort handler of Rnd::TheDbg. Revision 0 reads a character map of its own, with a 12-byte record rather than the 20-byte one this build uses, and then discards every entry; such a file supplies no material and no atlas either, and all five of those fields survive at their constructed values. Revision 0 and revision 1 both take the default character set rather than reading one, and revision 1 stores the two grid dimensions as integers.

The character map is emptied at the end whatever the revision, so the next measurement rebuilds it against the material that has just arrived.

Parameters
streamThe stream to read from.
Ghidra address:
NTSC-U/C: 0x004cac20
Ghidra address:
PAL: 0x00508eb8

Implements Rnd::Object.

◆ SetBuiltin()

virtual void Rnd::Font::SetBuiltin ( int nHeight,
FontWeight weight,
int nItalic,
FontFamily family,
const HxStr & name )
virtual

Describe a Builtin host font.

Vtable slot 8. The five fields it writes are the ones a Builtin font dumps and serialises. No direct call to this routine survives, and only a virtual dispatch through slot 8 could reduce that to a negative finding about the whole image.

Parameters
nHeightThe height.
weightThe stroke weight.
nItalicNon-zero for an italic face.
familyThe typeface family.
nameThe face name.
Ghidra address:
NTSC-U/C: 0x004cedd0
Ghidra address:
PAL: 0x0050d108

◆ GetBuiltin()

virtual void Rnd::Font::GetBuiltin ( int * nHeightOut,
FontWeight * weightOut,
int * nItalicOut,
FontFamily * familyOut,
HxStr & nameOut )
virtual

Report the Builtin host font description.

Vtable slot 9, and the exact inverse of SetBuiltin().

Parameters
nHeightOutReceives the height.
weightOutReceives the stroke weight.
nItalicOutReceives the italic flag.
familyOutReceives the typeface family.
nameOutReceives the face name.
Ghidra address:
NTSC-U/C: 0x004cef88
Ghidra address:
PAL: 0x0050d2e8

◆ GetCharAdvance()

float Rnd::Font::GetCharAdvance ( char ch)

Report the horizontal advance of one character.

Builds the character map first when it is empty. A character absent from the map advances by nothing at all rather than by a fallback width.

Parameters
chThe character to measure.
Returns
The advance, in the units Rnd::Text builds its mesh in.
Ghidra address:
NTSC-U/C: 0x004d0988
Ghidra address:
PAL: 0x0050edc0

◆ GetCharUV()

void Rnd::Font::GetCharUV ( char ch,
Vector2 & uv0,
Vector2 & uv1 )

Report the two texture-coordinate corners of one character.

Builds the character map first when it is empty. A character absent from the map yields two zero corners, which collapses its quad rather than drawing a substitute glyph.

Parameters
chThe character to look up.
uv0Receives the left and top corner.
uv1Receives the right and bottom corner.
Ghidra address:
NTSC-U/C: 0x004d08d8
Ghidra address:
PAL: 0x0050ed10

◆ BuildCharMap()

void Rnd::Font::BuildCharMap ( )

Measure every character of mChars and record its metrics in mCharMap.

Walks mChars in order, assigning each character the next cell of the mRows by mCols grid and wrapping to the next row after mCols cells. A character appearing twice in mChars is measured twice and the second measurement overwrites the first, so the later cell wins.

Ghidra address:
NTSC-U/C: 0x004ca978
Ghidra address:
PAL: 0x00508be0

◆ SetAtlas()

void Rnd::Font::SetAtlas ( Mat * pMat,
const HxStr & chars,
float flRows,
float flCols,
float flSize,
float flSpace )

Describe a Material font's glyph atlas in one call.

Drops the reference on the previous material and records the new one, clamps the row and column counts to at least 1, records the cell size, the tracking, and the atlas characters, and then runs OnChanged(), which takes the new reference and discards the measured metrics. mType is left as it was. The routine has no caller in the shipped build. The name is inferred.

Parameters
pMatThe atlas material, or null.
charsThe characters of the atlas cells, in reading order.
flRowsThe cell rows.
flColsThe cell columns.
flSizeThe height one cell occupies.
flSpaceThe tracking added after every glyph.
Ghidra address:
NTSC-U/C: 0x004d0530
Ghidra address:
PAL: 0x0050e968

◆ SetMat()

void Rnd::Font::SetMat ( Mat * pMat)

Replace the glyph atlas material.

Drops the reference on the previous material, records the new one, and then runs OnChanged(), which takes the new reference and discards the measured metrics. The title is inferred.

Parameters
pMatThe new material, or null.
Ghidra address:
NTSC-U/C: 0x004d0600
Ghidra address:
PAL: 0x0050ea38

◆ SetSize()

void Rnd::Font::SetSize ( float flSize)

Change the height one cell occupies.

Follows the same sequence as SetMat(), dropping and retaking the material reference around the store and discarding the measured metrics. The title is inferred.

Parameters
flSizeThe new mSize.
Ghidra address:
NTSC-U/C: 0x004d0648
Ghidra address:
PAL: 0x0050ea80

Member Data Documentation

◆ mType

Type Rnd::Font::mType

Which of the two descriptions this font supplies.

Public because Rnd::Text::BuildGlyphMesh() at 0x004c9780 tests it through a Rnd::Font pointer from outside this hierarchy, refusing to build geometry for anything but a Material font, and the image exposes no accessor for it. +0x1c

◆ mMat

Mat* Rnd::Font::mMat

Material whose first texture supplies the glyph atlas.

+0x44

◆ mRows

float Rnd::Font::mRows

Cell rows of the glyph atlas.

+0x48

◆ mCols

float Rnd::Font::mCols

Cell columns of the glyph atlas.

+0x4c

◆ mSize

float Rnd::Font::mSize

Height one cell occupies, in the units Rnd::Text builds its mesh in.

+0x50

◆ mSpace

float Rnd::Font::mSpace

Tracking added after every glyph, in the same units as mSize.

+0x54


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