-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCFontStorage.cpp
84 lines (71 loc) · 1.82 KB
/
CFontStorage.cpp
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
#include "CFontStorage.h"
#include "iostream"
#include "cstring"
using namespace std;
CFontStorage * FontStorage;
CFontStorage::CFontStorage()
{
for(int i = 0; i < MAX_FONTS_COUNT; i++) fonts[i] = NULL;
}
CFontStorage::~CFontStorage()
{
for(int i = 0; i < MAX_FONTS_COUNT; i++)
{
if(fonts[i]) delete fonts[i];
}
}
int CFontStorage::findFontName(char *fontName)
{
for(int i = 0; i < MAX_FONTS_COUNT; i++)
{
if(fonts[i])
{
if (!strcmp(fontName, fonts[i]->fontName))
{
return i;
}
}
}
return -1;
}
bool CFontStorage::setFont(char *fontName, char *fontFile)
{
#ifdef ONDEBUG
cout << "Loading font: name \"" << fontName << "\", file \"" << fontFile << "\" ..." << endl;
#endif
int fontId = findFontName(fontName); //fontId it is position in massive fonts[MAX_FONTS_COUNT];
if (fontId > -1)
{
cout << "-- ERROR: \"" << fontName << "\" font name already exist. Font not loaded." << endl;
return false;
}
for(int i = 0; i < MAX_FONTS_COUNT; i++)
{
if(fonts[i] == NULL)
{
fonts[i] = new sFont(fontName, new TFont(fontFile));
#ifdef ONDEBUG
cout << "-- OK: font loaded. Position: " << i << endl;
#endif
return true;
}
}
cout << "-- ERROR: font massive is full " << MAX_FONTS_COUNT << "/" << MAX_FONTS_COUNT <<". Font not loaded." << endl;
return false;
}
TFont* CFontStorage::getFont(char *fontName)
{
#ifdef ONDEBUG
cout << "Get font: name \"" << fontName << "\" ..." << endl;
#endif
int fontId = findFontName(fontName); //fontId it is position in massive fonts[MAX_FONTS_COUNT];
if (fontId == -1)
{
cout << "-- ERROR: can't found font with name: " << fontName << endl;
cout << " Try add font: setFont((char*)\"name\", (char*)\"path to .ttf file\");" << endl;
}
#ifdef ONDEBUG
cout << "-- OK: Font founded." << endl;
#endif
return fonts[fontId]->fontFile;
}