1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/********************************************************************
*
*	File:		fsCFont.h
*
*	Purpose:	bgfx font implementation. Bakes a glyph atlas with
*				stb_truetype into a bgfx texture at load time.
*
*********************************************************************/

#ifndef fsCFonthdr
#define fsCFonthdr

#include <map>
#include <memory>

#include <bgfx/bgfx.h>

#include "../../fsIFont.h"


class fsCFont : public fsIFont
{

	friend class fsIFont;
	friend class fsCRenderer;
	friend class fsCNativeTextSprite;

public:

	virtual ~fsCFont();<--- Destructor in derived class

protected:

	void initialiseDo(const fsSFontParams& pParams) override;

	fsCFont();

private:

	struct fsSGlyph
	{
		// atlas rect in texels
		fsF32 mX0 = 0;
		fsF32 mY0 = 0;
		fsF32 mX1 = 0;
		fsF32 mY1 = 0;
		// layout offsets relative to the baseline pen position
		fsF32 mXOff = 0;
		fsF32 mYOff = 0;
		fsF32 mXAdvance = 0;
	};

	const fsSGlyph* glyphGet(fsS32 pCodepoint) const;

	std::map<fsS32, fsSGlyph> mGlyphs;
	bgfx::TextureHandle mTexture = BGFX_INVALID_HANDLE;
	fsS32 mAtlasWidth = 0;
	fsS32 mAtlasHeight = 0;
	fsF32 mPointSize = 0;
	fsF32 mAscent = 0;
	fsF32 mLineHeight = 0;

};

#endif