wavelength 1.0.0
Loading...
Searching...
No Matches
rndfont.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <map>
5
6#include "math/vector2.h"
7#include "os/binstream.h"
8#include "os/mem.h"
9#include "os/prnstream.h"
10#include "os/string.h"
11#include "rnd/rndmat.h"
12#include "rnd/rndobject.h"
13
20class RndFont : public RndObject {
21public:
27 class CharInfo {
28 public:
29 float mWidth;
32 };
33
41 explicit RndFont(const char *pszName);
42
49 ~RndFont() override;
50
57 void *operator new(size_t nSize) {
58 return PoolMemAlloc(static_cast<int>(nSize), "Font", 0);
59 }
60
66 void operator delete(void *pBlock) {
67 PoolMemFree(pBlock);
68 }
69
77 void DumpText(PrnStream &stream) override;
78
86 void Save(BinStream &stream) override;
87
96 void Replace(RndObject *pFrom, RndObject *pTo) override;
97
105 const char *ClassName() const override {
106 return sClassName;
107 }
108
117 void Copy(const RndObject *pSource, int nFlags) override;
118
128 void Load(BinStream &stream) override;
129
144 void
145 Set(RndMat *pMat, const char *pszChars, float fRows, float fCols, float fSize, float fSpace);
146
156
169 CharInfo CellInfo(int nRow, int nCol) const;
170
182 void CharUv(char ch, Vector2 &uvStart, Vector2 &uvEnd) const;
183
194 float CharWidth(char ch) const;
195
204 static RndObject *New(const char *pszName) {
205 return new RndFont(pszName);
206 }
207
214 static const char *sClassName;
215
222 static int sRev;
223
225 const String &GetChars() const {
226 return mChars;
227 }
228
230 float GetCols() const {
231 return mCols;
232 }
233
235 RndMat *GetMat() const {
236 return mMat;
237 }
238
240 float GetRows() const {
241 return mRows;
242 }
243
245 float GetSize() const {
246 return mSize;
247 }
248
250 float GetSpace() const {
251 return mSpace;
252 }
253
254protected:
264
265private:
266 std::map<char, CharInfo> mCharMap;
267 RndMat *mMat;
268 float mRows;
269 float mCols;
270 float mSize;
271 float mSpace;
272 String mChars;
273};
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Text output stream.
Definition prnstream.h:16
The placement of one character.
Definition rndfont.h:27
Vector2 mUvStart
Definition rndfont.h:30
Vector2 mUvEnd
Definition rndfont.h:31
float mWidth
Definition rndfont.h:29
void Replace(RndObject *pFrom, RndObject *pTo) override
Replace the material when it is the object being replaced.
float CharWidth(char ch) const
Report the advance of a character.
float GetCols() const
Definition rndfont.h:230
void DumpText(PrnStream &stream) override
Write a description of the font.
void BuildCharMap()
Measure the cell of each character in the texture and record its placement.
~RndFont() override
Drop the reference on the material.
static const char * sClassName
The class name a .rnd file writes, Font.
Definition rndfont.h:214
float GetSize() const
Definition rndfont.h:245
CharInfo CellInfo(int nRow, int nCol) const
Measure the opaque columns of one cell of the texture.
float GetRows() const
Definition rndfont.h:240
RndFont(const char *pszName)
Construct a font of one cell without a material or characters.
const char * ClassName() const override
Report the class name.
Definition rndfont.h:105
void ReleaseRefs()
Drop the reference on the material.
void Load(BinStream &stream) override
Read what Save() wrote, or an earlier version of it, then place the characters.
void CharUv(char ch, Vector2 &uvStart, Vector2 &uvEnd) const
Report the texture coordinates of a character.
const String & GetChars() const
Definition rndfont.h:225
void Save(BinStream &stream) override
Write the font.
void Set(RndMat *pMat, const char *pszChars, float fRows, float fCols, float fSize, float fSpace)
Set the material, the characters, and the grid, then place the characters.
static RndObject * New(const char *pszName)
Create a font.
Definition rndfont.h:204
void Copy(const RndObject *pSource, int nFlags) override
Copy another font, then place the characters again.
float GetSpace() const
Definition rndfont.h:250
static int sRev
The format version Save() writes and Load() accepts.
Definition rndfont.h:222
RndMat * GetMat() const
Definition rndfont.h:235
Surface description: blending, lighting colours, culling, and a list of texture stages.
Definition rndmat.h:20
RndObject(const char *pszName)
Construct an object and register it under a name.
Growable text buffer that is also a PrnStream.
Definition string.h:19
void * PoolMemAlloc(int nSize, const char *pszTag, int nAlign)
Allocate a block from the pool heaps and bill it to a tag.
void PoolMemFree(void *pBlock)
Return a block PoolMemAlloc() handed out to the pool heap that owns it.
Two-component vector, used for texture coordinates.
Definition vector2.h:12