This repository has been archived by the owner on Mar 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Font.h
70 lines (60 loc) · 1.75 KB
/
Font.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
#pragma once
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <algorithm>
#include <sstream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "Glyph.h"
#include "Texture.h"
#include "Color.h"
#define MAX_GLYPHS 256
using namespace std;
class Font
{
public:
Font(string fnt_filename = "");
virtual ~Font();
void parse(string filename = "");
void parse(istream& s);
void renderText(SDL_Renderer* r, string text, Color* c= nullptr, int size = 32, SDL_Rect * rect = nullptr, Uint8 al = Alignment::UNKNOWN);
void setColor(Color c) { setColor(c.r(), c.g(), c.b()); }
void setColor(Uint8 r, Uint8 g, Uint8 b);
friend ostream& operator<<(ostream&, const Font&);
string getName() const { return _name; }
int getPixelLength(string text, int size = 32);
int getPixelHeight(string text, int size = 32);
void setAlignment(Uint8 a) { _alignment = a; }
Uint8 getAlignment() const { return _alignment; }
private:
string _fntFilename = "";
string _path_to_files = "";
Uint8 _alignment = Alignment::LEFT | Alignment::CENTERY;
/* info */
string _name;
unsigned short _original_size = 0;
/* common */
unsigned short _lineHeight = 0;
unsigned short _base = 0;
unsigned short _scale_width = 0;
unsigned short _scale_height = 0;
unsigned short _pages_count = 0;
bool _packed = false;
unsigned short _alpha_chnl = 0;
unsigned short _red_chnl = 0;
unsigned short _green_chnl = 0;
unsigned short _blue_chnl = 0;
/* pages */
vector<string> _pages_filename;
vector<Texture> _pages;
/* chars */
unsigned short _chars_count;
map<unsigned short, Glyph> _glyphs;
void parseInfo(string infoLine);
void parseCommon(string commonLine);
void parsePages(string pageLine);
void parseChar(string charLine);
void updateAtlases();
};