]> git.sesse.net Git - casparcg/blob - SFML-1.6/include/SFML/Graphics/Font.hpp
(no commit message)
[casparcg] / SFML-1.6 / include / SFML / Graphics / Font.hpp
1 ////////////////////////////////////////////////////////////\r
2 //\r
3 // SFML - Simple and Fast Multimedia Library\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
5 //\r
6 // This software is provided 'as-is', without any express or implied warranty.\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.\r
8 //\r
9 // Permission is granted to anyone to use this software for any purpose,\r
10 // including commercial applications, and to alter it and redistribute it freely,\r
11 // subject to the following restrictions:\r
12 //\r
13 // 1. The origin of this software must not be misrepresented;\r
14 //    you must not claim that you wrote the original software.\r
15 //    If you use this software in a product, an acknowledgment\r
16 //    in the product documentation would be appreciated but is not required.\r
17 //\r
18 // 2. Altered source versions must be plainly marked as such,\r
19 //    and must not be misrepresented as being the original software.\r
20 //\r
21 // 3. This notice may not be removed or altered from any source distribution.\r
22 //\r
23 ////////////////////////////////////////////////////////////\r
24 \r
25 #ifndef SFML_FONT_HPP\r
26 #define SFML_FONT_HPP\r
27 \r
28 ////////////////////////////////////////////////////////////\r
29 // Headers\r
30 ////////////////////////////////////////////////////////////\r
31 #include <SFML/System/Resource.hpp>\r
32 #include <SFML/System/Vector2.hpp>\r
33 #include <SFML/System/Unicode.hpp>\r
34 #include <SFML/Graphics/Glyph.hpp>\r
35 #include <SFML/Graphics/Image.hpp>\r
36 #include <SFML/Graphics/Rect.hpp>\r
37 #include <map>\r
38 #include <string>\r
39 \r
40 \r
41 namespace sf\r
42 {\r
43 class String;\r
44 \r
45 namespace priv\r
46 {\r
47 class FontLoader;\r
48 }\r
49 ////////////////////////////////////////////////////////////\r
50 /// Font is the low-level class for loading and\r
51 /// manipulating character fonts. This class is meant to\r
52 /// be used by sf::String\r
53 ////////////////////////////////////////////////////////////\r
54 class SFML_API Font : public Resource<Font>\r
55 {\r
56 public :\r
57 \r
58     ////////////////////////////////////////////////////////////\r
59     /// Default constructor\r
60     ///\r
61     ////////////////////////////////////////////////////////////\r
62     Font();\r
63 \r
64     ////////////////////////////////////////////////////////////\r
65     /// Load the font from a file\r
66     ///\r
67     /// \param Filename : Font file to load\r
68     /// \param CharSize : Size of characters in bitmap - the bigger, the higher quality (30 by default)\r
69     /// \param Charset :  Characters set to generate (by default, contains the ISO-8859-1 printable characters)\r
70     ///\r
71     /// \return True if loading was successful\r
72     ///\r
73     ////////////////////////////////////////////////////////////\r
74     bool LoadFromFile(const std::string& Filename, unsigned int CharSize = 30, const Unicode::Text& Charset = ourDefaultCharset);\r
75 \r
76     ////////////////////////////////////////////////////////////\r
77     /// Load the font from a file in memory\r
78     ///\r
79     /// \param Data :        Pointer to the data to load\r
80     /// \param SizeInBytes : Size of the data, in bytes\r
81     /// \param CharSize :    Size of characters in bitmap - the bigger, the higher quality (30 by default)\r
82     /// \param Charset :     Characters set to generate (by default, contains the ISO-8859-1 printable characters)\r
83     ///\r
84     /// \return True if loading was successful\r
85     ///\r
86     ////////////////////////////////////////////////////////////\r
87     bool LoadFromMemory(const char* Data, std::size_t SizeInBytes, unsigned int CharSize = 30, const Unicode::Text& Charset = ourDefaultCharset);\r
88 \r
89     ////////////////////////////////////////////////////////////\r
90     /// Get the base size of characters in the font;\r
91     /// All glyphs dimensions are based on this value\r
92     ///\r
93     /// \return Base size of characters\r
94     ///\r
95     ////////////////////////////////////////////////////////////\r
96     unsigned int GetCharacterSize() const;\r
97 \r
98     ////////////////////////////////////////////////////////////\r
99     /// Get the description of a glyph (character)\r
100     /// given by its unicode value\r
101     ///\r
102     /// \param CodePoint : Unicode value of the character to get\r
103     ///\r
104     /// \return Glyph's visual settings, or an invalid glyph if character not found\r
105     ///\r
106     ////////////////////////////////////////////////////////////\r
107     const Glyph& GetGlyph(Uint32 CodePoint) const;\r
108 \r
109     ////////////////////////////////////////////////////////////\r
110     /// Get the image containing the rendered characters (glyphs)\r
111     ///\r
112     /// \return Image containing glyphs\r
113     ///\r
114     ////////////////////////////////////////////////////////////\r
115     const Image& GetImage() const;\r
116 \r
117     ////////////////////////////////////////////////////////////\r
118     /// Get the SFML default built-in font (Arial)\r
119     ///\r
120     /// \return Instance of the default font\r
121     ///\r
122     ////////////////////////////////////////////////////////////\r
123     static const Font& GetDefaultFont();\r
124 \r
125 private :\r
126 \r
127     friend class priv::FontLoader;\r
128 \r
129     ////////////////////////////////////////////////////////////\r
130     // Static member data\r
131     ////////////////////////////////////////////////////////////\r
132     static Uint32 ourDefaultCharset[]; ///< The default charset (all printable ISO-8859-1 characters)\r
133 \r
134     ////////////////////////////////////////////////////////////\r
135     // Member data\r
136     ////////////////////////////////////////////////////////////\r
137     Image                   myTexture;  ///< Texture holding the bitmap font\r
138     unsigned int            myCharSize; ///< Size of characters in the bitmap font\r
139     std::map<Uint32, Glyph> myGlyphs;   ///< Rendering settings of each character (glyph)\r
140 };\r
141 \r
142 } // namespace sf\r
143 \r
144 \r
145 #endif // SFML_FONT_HPP\r