libSDL2pp
C++11 bindings/wrapper for SDL2
Font.hh
1/*
2 libSDL2pp - C++11 bindings/wrapper for SDL2
3 Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 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
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL2PP_FONT_HH
23#define SDL2PP_FONT_HH
24
25#include <string>
26
27#include <SDL_ttf.h>
28
29#include <SDL2pp/Optional.hh>
30#include <SDL2pp/Point.hh>
31#include <SDL2pp/Surface.hh>
32#include <SDL2pp/Export.hh>
33
34namespace SDL2pp {
35
36class RWops;
37
48class SDL2PP_EXPORT Font {
49private:
50 TTF_Font* font_;
51
52public:
53
56
63 explicit Font(TTF_Font* font);
64
78 Font(const std::string& file, int ptsize, long index = 0);
79
93 Font(RWops& rwops, int ptsize, long index = 0);
94
101 virtual ~Font();
102
104
107
114 Font(Font&& other) noexcept;
115
124 Font& operator=(Font&& other) noexcept;
125
132 Font(const Font&) = delete;
133
140 Font& operator=(const Font&) = delete;
141
143
146
153 TTF_Font* Get() const;
154
157
169 int GetStyle() const;
170
203 Font& SetStyle(int style = TTF_STYLE_NORMAL);
204
213 int GetOutline() const;
214
230 Font& SetOutline(int outline = 0);
231
233
236
247 int GetHinting() const;
248
270 Font& SetHinting(int hinting = TTF_HINTING_NORMAL);
271
281 bool GetKerning() const;
282
301 Font& SetKerning(bool allowed = true);
302
304
307
322 int GetHeight() const;
323
342 int GetAscent() const;
343
363 int GetDescent() const;
364
375 int GetLineSkip() const;
376
378
381
395 long GetNumFaces() const;
396
414 bool IsFixedWidth() const;
415
426 Optional<std::string> GetFamilyName() const;
427
438 Optional<std::string> GetStyleName() const;
439
441
444
455 int IsGlyphProvided(Uint16 ch) const;
456
473 void GetGlyphMetrics(Uint16 ch, int& minx, int& maxx, int& miny, int& maxy, int& advance) const;
474
488 Rect GetGlyphRect(Uint16 ch) const;
489
503 int GetGlyphAdvance(Uint16 ch) const;
504
506
509
526 Point GetSizeText(const std::string& text) const;
527
544 Point GetSizeUTF8(const std::string& text) const;
545
562 Point GetSizeUNICODE(const Uint16* text) const;
563
580 Point GetSizeUNICODE(const std::u16string& text) const;
581
583
586
600 Surface RenderText_Solid(const std::string& text, SDL_Color fg);
601
615 Surface RenderUTF8_Solid(const std::string& text, SDL_Color fg);
616
630 Surface RenderUNICODE_Solid(const Uint16* text, SDL_Color fg);
631
645 Surface RenderUNICODE_Solid(const std::u16string& text, SDL_Color fg);
646
660 Surface RenderGlyph_Solid(Uint16 ch, SDL_Color fg);
661
663
666
681 Surface RenderText_Shaded(const std::string& text, SDL_Color fg, SDL_Color bg);
682
697 Surface RenderUTF8_Shaded(const std::string& text, SDL_Color fg, SDL_Color bg);
698
713 Surface RenderUNICODE_Shaded(const Uint16* text, SDL_Color fg, SDL_Color bg);
714
729 Surface RenderUNICODE_Shaded(const std::u16string& text, SDL_Color fg, SDL_Color bg);
730
745 Surface RenderGlyph_Shaded(Uint16 ch, SDL_Color fg, SDL_Color bg);
746
748
751
765 Surface RenderText_Blended(const std::string& text, SDL_Color fg);
766
780 Surface RenderUTF8_Blended(const std::string& text, SDL_Color fg);
781
795 Surface RenderUNICODE_Blended(const Uint16* text, SDL_Color fg);
796
810 Surface RenderUNICODE_Blended(const std::u16string& text, SDL_Color fg);
811
825 Surface RenderGlyph_Blended(Uint16 ch, SDL_Color fg);
826
828};
829
830}
831
832#endif
Holder of a loaded font.
Definition: Font.hh:48
Font(const Font &)=delete
Deleted copy constructor.
Font & operator=(const Font &)=delete
Deleted assignment operator.
2D point
Definition: Point.hh:51
I/O abstraction.
Definition: RWops.hh:156
2D rectangle
Definition: Rect.hh:50
Image stored in system memory with direct access to pixel data.
Definition: Surface.hh:53