Documentation de SFML 2.6.2

Attention: cette page se réfère à une ancienne version de SFML. Cliquez ici pour passer à la dernière version.
Loading...
Searching...
No Matches
Font.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2023 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
31#include <SFML/Graphics/Export.hpp>
32#include <SFML/Graphics/Glyph.hpp>
33#include <SFML/Graphics/Texture.hpp>
34#include <SFML/Graphics/Rect.hpp>
35#include <map>
36#include <string>
37#include <vector>
38
39
40namespace sf
41{
42class InputStream;
43
48class SFML_GRAPHICS_API Font
49{
50public:
51
56 struct Info
57 {
58 std::string family;
59 };
60
61public:
62
70
77 Font(const Font& copy);
78
86
107 bool loadFromFile(const std::string& filename);
108
128 bool loadFromMemory(const void* data, std::size_t sizeInBytes);
129
151
158 const Info& getInfo() const;
159
182 const Glyph& getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness = 0) const;
183
200 bool hasGlyph(Uint32 codePoint) const;
201
218 float getKerning(Uint32 first, Uint32 second, unsigned int characterSize, bool bold = false) const;
219
231 float getLineSpacing(unsigned int characterSize) const;
232
246 float getUnderlinePosition(unsigned int characterSize) const;
247
260 float getUnderlineThickness(unsigned int characterSize) const;
261
274 const Texture& getTexture(unsigned int characterSize) const;
275
290 void setSmooth(bool smooth);
291
300 bool isSmooth() const;
301
310 Font& operator =(const Font& right);
311
312private:
313
318 struct Row
319 {
320 Row(unsigned int rowTop, unsigned int rowHeight) : width(0), top(rowTop), height(rowHeight) {}
321
322 unsigned int width;
323 unsigned int top;
324 unsigned int height;
325 };
326
328 // Types
330 typedef std::map<Uint64, Glyph> GlyphTable;
331
336 struct Page
337 {
338 explicit Page(bool smooth);
339
340 GlyphTable glyphs;
341 Texture texture;
342 unsigned int nextRow;
343 std::vector<Row> rows;
344 };
345
350 void cleanup();
351
360 Page& loadPage(unsigned int characterSize) const;
361
373 Glyph loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness) const;
374
385 IntRect findGlyphRect(Page& page, unsigned int width, unsigned int height) const;
386
395 bool setCurrentSize(unsigned int characterSize) const;
396
398 // Types
400 typedef std::map<unsigned int, Page> PageTable;
401
403 // Member data
405 void* m_library;
406 void* m_face;
407 void* m_streamRec;
408 void* m_stroker;
409 int* m_refCount;
410 bool m_isSmooth;
411 Info m_info;
412 mutable PageTable m_pages;
413 mutable std::vector<Uint8> m_pixelBuffer;
414 #ifdef SFML_SYSTEM_ANDROID
415 void* m_stream;
416 #endif
417};
418
419} // namespace sf
420
421
422#endif // SFML_FONT_HPP
423
424
Class for loading and manipulating character fonts.
Definition Font.hpp:49
float getLineSpacing(unsigned int characterSize) const
Get the line spacing.
const Glyph & getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness=0) const
Retrieve a glyph of the font.
Font()
Default constructor.
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.
void setSmooth(bool smooth)
Enable or disable the smooth filter.
const Info & getInfo() const
Get the font information.
~Font()
Destructor.
bool loadFromFile(const std::string &filename)
Load the font from a file.
float getKerning(Uint32 first, Uint32 second, unsigned int characterSize, bool bold=false) const
Get the kerning offset of two glyphs.
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.
bool hasGlyph(Uint32 codePoint) const
Determine if this font has a glyph representing the requested code point.
bool isSmooth() const
Tell whether the smooth filter is enabled or not.
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:49
Holds various information about a font.
Definition Font.hpp:57
std::string family
The font family.
Definition Font.hpp:58