Loading...
Searching...
No Matches
Font.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef SFML_FONT_HPP
26#define SFML_FONT_HPP
27
29// Headers
37#include <map>
38#include <string>
39#include <vector>
40
41
42namespace sf
43{
44class InputStream;
45
51{
52public:
53
58 struct Info
59 {
60 std::string family;
61 };
62
63public:
64
72
79 Font(const Font& copy);
80
88
105 bool loadFromFile(const std::string& filename);
106
124 bool loadFromMemory(const void* data, std::size_t sizeInBytes);
125
143
150 const Info& getInfo() const;
151
166 const Glyph& getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
167
184 float getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const;
185
197 float getLineSpacing(unsigned int characterSize) const;
198
212 float getUnderlinePosition(unsigned int characterSize) const;
213
226 float getUnderlineThickness(unsigned int characterSize) const;
227
240 const Texture& getTexture(unsigned int characterSize) const;
241
250 Font& operator =(const Font& right);
251
252private:
253
258 struct Row
259 {
260 Row(unsigned int rowTop, unsigned int rowHeight) : width(0), top(rowTop), height(rowHeight) {}
261
262 unsigned int width;
263 unsigned int top;
264 unsigned int height;
265 };
266
268 // Types
270 typedef std::map<Uint32, Glyph> GlyphTable;
271
276 struct Page
277 {
278 Page();
279
280 GlyphTable glyphs;
281 sf::Texture texture;
282 unsigned int nextRow;
283 std::vector<Row> rows;
284 };
285
290 void cleanup();
291
302 Glyph loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
303
314 IntRect findGlyphRect(Page& page, unsigned int width, unsigned int height) const;
315
324 bool setCurrentSize(unsigned int characterSize) const;
325
327 // Types
329 typedef std::map<unsigned int, Page> PageTable;
330
332 // Member data
334 void* m_library;
335 void* m_face;
336 void* m_streamRec;
337 int* m_refCount;
338 Info m_info;
339 mutable PageTable m_pages;
340 mutable std::vector<Uint8> m_pixelBuffer;
341 #ifdef SFML_SYSTEM_ANDROID
342 void* m_stream;
343 #endif
344};
345
346} // namespace sf
347
348
349#endif // SFML_FONT_HPP
350
351
#define SFML_GRAPHICS_API
const Glyph & getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const
Retrieve a glyph of the font.
float getLineSpacing(unsigned int characterSize) const
Get the line spacing.
Font()
Default constructor.
float getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const
Get the kerning offset of two glyphs.
const Texture & getTexture(unsigned int characterSize) const
Retrieve the texture containing the loaded glyphs of a certain size.
float getUnderlinePosition(unsigned int characterSize) const
Get the position of the underline.
Font(const Font &copy)
Copy constructor.
const Info & getInfo() const
Get the font information.
~Font()
Destructor.
bool loadFromFile(const std::string &filename)
Load the font from a file.
bool loadFromStream(InputStream &stream)
Load the font from a custom stream.
bool loadFromMemory(const void *data, std::size_t sizeInBytes)
Load the font from a file in memory.
float getUnderlineThickness(unsigned int characterSize) const
Get the thickness of the underline.
Structure describing a glyph.
Definition Glyph.hpp:42
Abstract class for custom file input streams.
Image living on the graphics card that can be used for drawing.
Definition Texture.hpp:48
unsigned int Uint32
Definition Config.hpp:179
Rect< int > IntRect
Definition Rect.hpp:190
Holds various information about a font.
Definition Font.hpp:59
std::string family
The font family.
Definition Font.hpp:60