-
Notifications
You must be signed in to change notification settings - Fork 0
/
fonts_internal.h
95 lines (83 loc) · 2.99 KB
/
fonts_internal.h
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
/** Copyright (C) 2008 Josh Ventura
*** Copyright (C) 2010 Alasdair Morrison <tgmg@g-java.com>
*** Copyright (C) 2014 Robert B. Colton
***
*** This file is a part of the ENIGMA Development Environment.
***
*** ENIGMA is free software: you can redistribute it and/or modify it under the
*** terms of the GNU General Public License as published by the Free Software
*** Foundation, version 3 of the license or any later version.
***
*** This application and its source code is distributed AS-IS, WITHOUT ANY
*** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
*** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
*** details.
***
*** You should have received a copy of the GNU General Public License along
*** with this code. If not, see <http://www.gnu.org/licenses/>
**/
//FIXME: this should be ifdef shellmain but enigmas in a sorry state
#ifdef JUST_DEFINE_IT_RUN
# error This file includes non-ENIGMA STL headers and should not be included from SHELLmain.
#endif
#ifndef ENIGMA_FONTS_INTERNAL_H
#define ENIGMA_FONTS_INTERNAL_H
#include "Graphics_Systems/graphics_mandatory.h"
#include "AssetArray.h"
#include <string>
#include <vector>
#include <stdint.h>
namespace enigma
{
struct fontglyph
{
fontglyph() : x(0), y(0), x2(0), y2(0), tx(0), ty(0), tx2(0), ty2(0), xs(0) {}
bool empty();
int x, y, x2, y2; // Draw coordinates, relative to the top-left corner of a full glyph. Added to xx and yy for draw.
float tx, ty, tx2, ty2; // Texture coords: used to locate glyph on bound font texture
float xs; // Spacing: used to increment xx
};
struct fontglyphrange {
fontglyphrange() : glyphstart(0) {}
unsigned int glyphstart;
std::vector<fontglyph> glyphs;
};
class SpriteFont
{
public:
SpriteFont() : name(""), fontname(""), fontsize(0),
bold(false), italic(false), height(0), yoffset(0), texture(-1),
twid(0), thgt(0) {}
// Trivia
std::string name, fontname;
int fontsize;
bool bold, italic;
// Metrics and such
std::vector<fontglyphrange> glyphRanges;
unsigned int height, yoffset;
// Texture layer
int texture;
int twid, thgt;
void destroy() {
glyphRanges.clear();
if (texture >= 0) graphics_delete_texture(texture);
texture = -1;
}
bool isDestroyed() const { return texture == -1 || glyphRanges.empty(); }
static const char* getAssetTypeName() { return "font"; }
};
struct rawfont {
std::string name;
int id;
std::string fontname;
int fontsize; bool bold, italic;
unsigned int glyphRangeCount;
};
extern std::vector<rawfont> rawfontdata;
extern AssetArray<SpriteFont, -1> sprite_fonts;
extern int rawfontcount, rawfontmaxid;
int font_new(uint32_t gs, uint32_t gc); // Creates a new font, allocating 'gc' glyphs
int font_pack(SpriteFont *font, int spr, uint32_t gcount, bool prop, int sep);
fontglyph findGlyph(const SpriteFont& fnt, uint32_t character);
} //namespace enigma
#endif //ENIGMA_FONTS_INTERNAL_H