-
Notifications
You must be signed in to change notification settings - Fork 2
/
Font.cpp
62 lines (49 loc) · 1.04 KB
/
Font.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
/*
* File: Font.cpp
* Author: dude719
*
* Created on April 19, 2015, 6:52 AM
*/
#include "Font.h"
const char* Font::DEFAULT_FONT = "Arial";
const char* Font::EXTENSION = ".ttf";
int Font::DEFAULT_SIZE = 12;
Font::Font()
{
strcpy(szName, DEFAULT_FONT);
Load();
}
Font::Font(const char* fontName)
{
strcpy(szName, fontName);
Load();
}
const char* Font::GetName()
{
return szName;
}
bool Font::SetFont(const char* fontName)
{
if (face)
FT_Done_Face(face);
strcpy(szName, fontName);
return Load();
}
bool Font::Load()
{
char* szFile = (char*)malloc(strlen(szName) + strlen(EXTENSION) + 1);
strcpy(szFile, szName);
strcat(szFile, EXTENSION);
printf("Font file: %s\n", szFile);
if(FT_New_Face(ft_lib, szFile, 0, &face) != 0)
{
printf("Unable to load %s\n", szFile);
FT_Done_Face(face);
delete[] szFile;
return false;
}
FT_Set_Pixel_Sizes(face, 0, DEFAULT_SIZE);
//FT_Set_Char_Size(face, 50, 50, WINDOW_WIDTH, WINDOW_HEIGHT);
delete[] szFile;
return true;
}