aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/fonts/texture_font.h
blob: 510badbc68a505c5d57f0b0c414bc796a963a411 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef __JE_TEXTURE_FONT_H__
#define __JE_TEXTURE_FONT_H__

#include <map>
#include <vector>

#include "../../math/vector4.hpp"

#include "../graphic.h"
#include "../bitmap.h"

#include "page.h"
#include "font.h"
#include "text.h"

namespace JinEngine
{
	namespace Graphics
	{
		namespace Fonts
		{

			/// 
			/// 
			/// 
			class TextureFont : public Font, public Graphic, public Object
			{
			public:
				///
				///
				///
				TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh);

				///
				///
				///
				TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh);

				///
				///
				///
				TextureFont(const Bitmap* bitmap, const Text& text, Color mask, int cellh);

				///
				///
				///
				TextureFont(const Bitmap* bitmap, const Text& text, int cellw, int cellh);

				///
				///
				///
				~TextureFont();

				///
				///
				///
				Page* typeset(const Text& text, int lineheight, int spacing = 0) override;

				///
				///
				///
				Page* typeset(const Content& text, int lineheight, int spacing = 0) override;

				///
				///
				///
				void render(const Page* page, int x, int y) override;

				///
				///
				///
				void render(const Content& text, int x, int y, int linehgiht, int spacing = 0) override;

				///
				///
				///
				void render(const Text& text, int x, int y, int lineheight, int spacing = 0)override;

			private:

				///
				///
				///
				struct TextureGlyph
				{
					float x, y, w, h;
				};

				///
				///
				///
				int getCharWidth(int c);

				///
				///
				///
				int getCharHeight(int c);

				///
				///
				///
				int getTextWidth(const Content& text, int spacing = 0);

				///
				///
				///
				int getTextHeight(const Content& text, int lineheight);

				///
				///
				///
				void getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing = 0);

				///
				///
				///
				const TextureGlyph* findGlyph(Codepoint codepoint) const;


				///
				///
				///
				std::map<Codepoint, TextureGlyph> glyphs;

			};

		} // namespace Fonts
	} // namespace Graphics
} // namespace JinEngine 

#endif