|
resonance 1.0.1
|
Glyph atlas, either a host font description or a grid of cells inside a material texture. More...
#include <font.h>


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 |
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.
| enum Rnd::Font::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 | |
|
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.
| name | The registry key for this object. |
|
virtual |
Drop the reference on the material and release the character map.
|
static |
Allocate a font under the tag "Rnd::Font".
| nSize | The object size the compiler supplies. |
|
static |
Release a font to the tagged heap.
| pBlock | The block. |
|
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.
| sink | The diagnostic sink to write to. |
Reimplemented from Rnd::Object.
|
virtual |
Write this font to stream at revision 2.
| stream | The stream to write to. |
Implements Rnd::Object.
Retarget the material when it is the object being replaced.
| pFrom | The object being replaced. |
| pTo | The replacement, or null. |
Implements Rnd::Object.
|
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".
Implements Rnd::Object.
|
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.
| pSource | The font to copy from. |
| nFlags | Unread. |
Implements Rnd::Object.
|
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.
| stream | The stream to read from. |
Implements Rnd::Object.
|
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.
| nHeight | The height. |
| weight | The stroke weight. |
| nItalic | Non-zero for an italic face. |
| family | The typeface family. |
| name | The face name. |
|
virtual |
Report the Builtin host font description.
Vtable slot 9, and the exact inverse of SetBuiltin().
| nHeightOut | Receives the height. |
| weightOut | Receives the stroke weight. |
| nItalicOut | Receives the italic flag. |
| familyOut | Receives the typeface family. |
| nameOut | Receives the face name. |
| 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.
| ch | The character to measure. |
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.
| ch | The character to look up. |
| uv0 | Receives the left and top corner. |
| uv1 | Receives the right and bottom corner. |
| 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.
| 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.
| pMat | The atlas material, or null. |
| chars | The characters of the atlas cells, in reading order. |
| flRows | The cell rows. |
| flCols | The cell columns. |
| flSize | The height one cell occupies. |
| flSpace | The tracking added after every glyph. |
| 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.
| pMat | The new material, or null. |
| 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.
| flSize | The new mSize. |
| 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
| Mat* Rnd::Font::mMat |
Material whose first texture supplies the glyph atlas.
+0x44
| float Rnd::Font::mRows |
Cell rows of the glyph atlas.
+0x48
| float Rnd::Font::mCols |
Cell columns of the glyph atlas.
+0x4c
| float Rnd::Font::mSize |
Height one cell occupies, in the units Rnd::Text builds its mesh in.
+0x50
| float Rnd::Font::mSpace |
Tracking added after every glyph, in the same units as mSize.
+0x54