OpenXcom  1.0
Open-source clone of the original X-Com
Font.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <map>
21 #include <vector>
22 #include <utility>
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 
33 struct FontImage
34 {
35  int width, height, spacing;
36  Surface *surface;
37 };
38 
45 class Font
46 {
47 private:
48  std::vector<FontImage> _images;
49  std::map< wchar_t, std::pair<size_t, SDL_Rect> > _chars;
50  bool _monospace;
52  void init(size_t index, const std::wstring &str);
53 public:
55  Font();
57  ~Font();
59  static inline bool isLinebreak(wchar_t c) { return (c == L'\n' || c == L'\x02'); }
61  static inline bool isSpace(wchar_t c) { return (c == L' ' || c == L'\xA0'); }
63  static inline bool isSeparator(wchar_t c) { return (c == L'-' || c == '/'); }
65  static inline bool isNonBreakableSpace(wchar_t c) { return (c == L'\xA0'); }
67  void load(const YAML::Node& node);
69  void loadTerminal();
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  SDL_Color *getPalette() const;
83  void setPalette(SDL_Color *colors, int firstcolor, int ncolors);
84 };
85 
86 }
static bool isNonBreakableSpace(wchar_t c)
Checks if a character is a non-breaking space.
Definition: Font.h:65
static bool isSeparator(wchar_t c)
Checks if a character is a word separator.
Definition: Font.h:63
static bool isSpace(wchar_t c)
Checks if a character is a blank space (includes non-breaking spaces).
Definition: Font.h:61
static bool isLinebreak(wchar_t c)
Checks if a character is a linebreak.
Definition: Font.h:59
Takes care of loading and storing each character in a sprite font.
Definition: Font.h:45
Element that is blit (rendered) onto the screen.
Definition: Surface.h:36
Definition: Font.h:33
Definition: BaseInfoState.cpp:40