-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadFont.h
44 lines (33 loc) · 1.24 KB
/
LoadFont.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
#pragma once
#include <string>
#include <memory>
#include <vector>
#include "SDLWrapper.h"
#include "MapFile.h"
#include "stb_truetype.h"
class Font {
public:
static const uint32_t kCharsetLatin = 0x1;
static const uint32_t kCharsetCyrillic = 0x2;
static const uint32_t kCharsetGreek = 0x4;
Font(const MappedFile &fontFile, float fontSize, uint32_t extraCharsetSupport = 0);
~Font();
bool Ok() const { return ok; }
bool GetGlyphRect(int charCode, SDL_Rect& glyphRect) const;
bool GetGlyphGeometry(int charCode, stbtt_packedchar &glyphGeometry) const;
/// Returns the internal surface that holds the glyphs.
/// Use GetGlyphGeometry() to find out coordinates of a glyph image in this surface.
SDL::Surface& GetSurface() { return *(fontSurface.get()); }
SDL_Rect ComputeTextSize(const std::wstring &text);
private:
const stbtt_packedchar* GetPackedChar(int charCode) const;
uint32_t encodedCharsets = 0;
bool ok = false;
int encodedCharCount = 0;
std::unique_ptr<SDL::Surface> fontSurface = nullptr;
stbtt_fontinfo fontInfo = { 0 };
std::vector<stbtt_pack_range> packedCharRanges;
std::array<stbtt_packedchar, 767> packedCharsBasic;
std::array<stbtt_packedchar, 256> packedCharsCyrillic;
std::array<stbtt_packedchar, 143> packedCharsGreek;
};