1 ////////////////////////////////////////////////////////////
\r
3 // SFML - Simple and Fast Multimedia Library
\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
\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
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
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
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
25 #ifndef SFML_FONT_HPP
\r
26 #define SFML_FONT_HPP
\r
28 ////////////////////////////////////////////////////////////
\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
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
58 ////////////////////////////////////////////////////////////
\r
59 /// Default constructor
\r
61 ////////////////////////////////////////////////////////////
\r
64 ////////////////////////////////////////////////////////////
\r
65 /// Load the font from a file
\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
71 /// \return True if loading was successful
\r
73 ////////////////////////////////////////////////////////////
\r
74 bool LoadFromFile(const std::string& Filename, unsigned int CharSize = 30, const Unicode::Text& Charset = ourDefaultCharset);
\r
76 ////////////////////////////////////////////////////////////
\r
77 /// Load the font from a file in memory
\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
84 /// \return True if loading was successful
\r
86 ////////////////////////////////////////////////////////////
\r
87 bool LoadFromMemory(const char* Data, std::size_t SizeInBytes, unsigned int CharSize = 30, const Unicode::Text& Charset = ourDefaultCharset);
\r
89 ////////////////////////////////////////////////////////////
\r
90 /// Get the base size of characters in the font;
\r
91 /// All glyphs dimensions are based on this value
\r
93 /// \return Base size of characters
\r
95 ////////////////////////////////////////////////////////////
\r
96 unsigned int GetCharacterSize() const;
\r
98 ////////////////////////////////////////////////////////////
\r
99 /// Get the description of a glyph (character)
\r
100 /// given by its unicode value
\r
102 /// \param CodePoint : Unicode value of the character to get
\r
104 /// \return Glyph's visual settings, or an invalid glyph if character not found
\r
106 ////////////////////////////////////////////////////////////
\r
107 const Glyph& GetGlyph(Uint32 CodePoint) const;
\r
109 ////////////////////////////////////////////////////////////
\r
110 /// Get the image containing the rendered characters (glyphs)
\r
112 /// \return Image containing glyphs
\r
114 ////////////////////////////////////////////////////////////
\r
115 const Image& GetImage() const;
\r
117 ////////////////////////////////////////////////////////////
\r
118 /// Get the SFML default built-in font (Arial)
\r
120 /// \return Instance of the default font
\r
122 ////////////////////////////////////////////////////////////
\r
123 static const Font& GetDefaultFont();
\r
127 friend class priv::FontLoader;
\r
129 ////////////////////////////////////////////////////////////
\r
130 // Static member data
\r
131 ////////////////////////////////////////////////////////////
\r
132 static Uint32 ourDefaultCharset[]; ///< The default charset (all printable ISO-8859-1 characters)
\r
134 ////////////////////////////////////////////////////////////
\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
145 #endif // SFML_FONT_HPP
\r