OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Font.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_FONT_H
20 #define OPENXCOM_FONT_H
21 
22 #include <map>
23 #include <string>
24 #include <SDL.h>
25 #include <yaml-cpp/yaml.h>
26 
27 namespace OpenXcom
28 {
29 
30 class Surface;
31 class Palette;
32 
40 class Font
41 {
42 private:
43  static std::wstring _index;
44  static SDL_Color _palette[6];
45  Surface *_surface;
46  int _width, _height, _spacing;
47  std::map<wchar_t, SDL_Rect> _chars;
48  bool _monospace;
49 public:
51  Font();
53  ~Font();
55  static inline bool isLinebreak(wchar_t c) { return (c == L'\n' || c == L'\x02'); }
57  static inline bool isSpace(wchar_t c) { return (c == L' ' || c == L'\xA0'); }
59  static inline bool isSeparator(wchar_t c) { return (c == L'-' || c == '/'); }
61  static inline bool isNonBreakableSpace(wchar_t c) { return (c == L'\xA0'); }
63  static void setIndex(const std::wstring &index);
65  void load(const YAML::Node& node);
67  void loadTerminal();
69  void init();
71  Surface *getChar(wchar_t c);
73  int getWidth() const;
75  int getHeight() const;
77  int getSpacing() const;
79  SDL_Rect getCharSize(wchar_t c);
81  Surface *getSurface() const;
82 
83  void fix(const std::string &file, int width);
84 };
85 
86 }
87 
88 #endif
Surface * getSurface() const
Gets the font's surface.
Definition: Font.cpp:255
static bool isNonBreakableSpace(wchar_t c)
Checks if a character is a non-breaking space.
Definition: Font.h:61
int getHeight() const
Gets the font's character height.
Definition: Font.cpp:205
static void setIndex(const std::wstring &index)
Sets the character index for every font.
Definition: Font.cpp:58
~Font()
Cleans up the font.
Definition: Font.cpp:48
int getWidth() const
Gets the font's character width.
Definition: Font.cpp:196
static bool isSeparator(wchar_t c)
Checks if a character is a word separator.
Definition: Font.h:59
void init()
Determines the size and position of each character in the font.
Definition: Font.cpp:115
static bool isSpace(wchar_t c)
Checks if a character is a blank space (includes non-breaking spaces).
Definition: Font.h:57
static bool isLinebreak(wchar_t c)
Checks if a character is a linebreak.
Definition: Font.h:55
void loadTerminal()
Generate the terminal font.
Definition: Font.cpp:87
Takes care of loading and storing each character in a sprite font.
Definition: Font.h:40
Surface * getChar(wchar_t c)
Gets a particular character from the font, with its real size.
Definition: Font.cpp:180
int getSpacing() const
Gets the spacing between characters.
Definition: Font.cpp:216
SDL_Rect getCharSize(wchar_t c)
Gets the size of a particular character;.
Definition: Font.cpp:226
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39
Font()
Creates a blank font.
Definition: Font.cpp:41
void load(const YAML::Node &node)
Loads the font from YAML.
Definition: Font.cpp:67