Documentation de SFML 2.4.2

Attention: cette page se réfère à une ancienne version de SFML. Cliquez ici pour passer à la dernière version.
Font.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2017 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 <SFML/System/Vector2.hpp>
36 #include <SFML/System/String.hpp>
37 #include <map>
38 #include <string>
39 #include <vector>
40 
41 
42 namespace sf
43 {
44 class InputStream;
45 
50 class SFML_GRAPHICS_API Font
51 {
52 public:
53 
58  struct Info
59  {
60  std::string family;
61  };
62 
63 public:
64 
71  Font();
72 
79  Font(const Font& copy);
80 
87  ~Font();
88 
109  bool loadFromFile(const std::string& filename);
110 
130  bool loadFromMemory(const void* data, std::size_t sizeInBytes);
131 
152  bool loadFromStream(InputStream& stream);
153 
160  const Info& getInfo() const;
161 
180  const Glyph& getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness = 0) const;
181 
198  float getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const;
199 
211  float getLineSpacing(unsigned int characterSize) const;
212 
226  float getUnderlinePosition(unsigned int characterSize) const;
227 
240  float getUnderlineThickness(unsigned int characterSize) const;
241 
254  const Texture& getTexture(unsigned int characterSize) const;
255 
264  Font& operator =(const Font& right);
265 
266 private:
267 
272  struct Row
273  {
274  Row(unsigned int rowTop, unsigned int rowHeight) : width(0), top(rowTop), height(rowHeight) {}
275 
276  unsigned int width;
277  unsigned int top;
278  unsigned int height;
279  };
280 
282  // Types
284  typedef std::map<Uint64, Glyph> GlyphTable;
285 
290  struct Page
291  {
292  Page();
293 
294  GlyphTable glyphs;
295  Texture texture;
296  unsigned int nextRow;
297  std::vector<Row> rows;
298  };
299 
304  void cleanup();
305 
317  Glyph loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness) const;
318 
329  IntRect findGlyphRect(Page& page, unsigned int width, unsigned int height) const;
330 
339  bool setCurrentSize(unsigned int characterSize) const;
340 
342  // Types
344  typedef std::map<unsigned int, Page> PageTable;
345 
347  // Member data
349  void* m_library;
350  void* m_face;
351  void* m_streamRec;
352  void* m_stroker;
353  int* m_refCount;
354  Info m_info;
355  mutable PageTable m_pages;
356  mutable std::vector<Uint8> m_pixelBuffer;
357  #ifdef SFML_SYSTEM_ANDROID
358  void* m_stream;
359  #endif
360 };
361 
362 } // namespace sf
363 
364 
365 #endif // SFML_FONT_HPP
366 
367 
Class for loading and manipulating character fonts.
Definition: Font.hpp:50
Structure describing a glyph.
Definition: Glyph.hpp:41
Abstract class for custom file input streams.
Definition: InputStream.hpp:41
Holds various information about a font.
Definition: Font.hpp:58
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:47
std::string family
The font family.
Definition: Font.hpp:60