The Game Engine  1
Font.cpp
Go to the documentation of this file.
1 #include "Font.h"
2 #include <iostream>
3 #include <string>
4 #include "fns.h"
5 #include "Game.h"
6 #include <GL/gl.h>
7 using namespace std;
8 
9 
10 Font::Font( FontType t, int s ) : type(t), size(s), count(1) {
11  tryLoadFont();
12 }
13 
14 Font::Font( int s ) : type(English), size(s), count(1) {
15  tryLoadFont();
16 }
17 
20  TTF_CloseFont(font);
21 }
22 
23 void Font::setSize(int s) {
24  if(s!=size) {
25  TTF_CloseFont(font);
26  font = TTF_OpenFont(fontFile.c_str(), s);
27  }
28 }
29 
31  string filePath = "";
32  string fontName = "";
33  #if defined(_WIN32)
34 
35  filePath = "C:\\Windows\\Fonts\\";
36  fontName = type == English ? "REFSAN.ttf":"msgothic.ttc";
37  #endif
38  #if defined(_APPLE_) && defined(_MACH_)
39  string fName = type == English ? "/Library/Fonts/msgothic.ttc" : "C:\\Windows\\Fonts\\msgothic.ttc";
40  #endif
41  #if defined(linux) || defined(__linux)
42  /*
43  /usr/share/fonts
44  /usr/local/share/fonts
45  ~/.fonts
46  */
48  string fName = type == English ? "C:\\Windows\\Fonts\\msgothic.ttc" : "C:\\Windows\\Fonts\\msgothic.ttc";
49  #endif
50 
51  fontFile = filePath.append(fontName);
52  // Load a font
53  font = TTF_OpenFont(fontFile.c_str(), size);
54  if (!font) {
55  cerr << "TTF_OpenFont() Failed: " << TTF_GetError() << endl;
56  return false;
57  }
58  return true;
59 }