1// SuperTux
2// Copyright (C) 2018 Ingo Ruhnke <grumbel@gmail.com>,
3// Tobias Markus <tobbi.bugs@googlemail.com>
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18#ifndef HEADER_SUPERTUX_VIDEO_TTF_FONT_HPP
19#define HEADER_SUPERTUX_VIDEO_TTF_FONT_HPP
20
21#include <SDL_ttf.h>
22
23#include "video/color.hpp"
24#include "video/font.hpp"
25
26class Canvas;
27class Painter;
28class Vector;
29
30class TTFFont final : public Font
31{
32public:
33 TTFFont(const std::string& filename, int size, float line_spacing = 1.0f, int shadowsize = 0, int border = 0);
34 virtual ~TTFFont();
35
36 float get_line_spacing() {
37 return m_line_spacing;
38 }
39
40 virtual float get_height() const override {
41 return static_cast<float>(m_font_size) * m_line_spacing;
42 }
43
44 virtual float get_text_width(const std::string& text) const override;
45 virtual float get_text_height(const std::string& text) const override;
46
47 virtual std::string wrap_to_width(const std::string& text, float width, std::string* overflow) override;
48
49 virtual void draw_text(Canvas& canvas, const std::string& text,
50 const Vector& pos, FontAlignment alignment, int layer, const Color& color) override;
51
52 int get_shadow_size() const { return m_shadow_size; }
53 int get_border() const { return m_border; }
54
55 TTF_Font* get_ttf_font() const { return m_font; }
56
57private:
58 TTF_Font* m_font;
59 std::string m_filename;
60 int m_font_size;
61 float m_line_spacing;
62 int m_shadow_size;
63 int m_border;
64
65private:
66 TTFFont(const TTFFont&) = delete;
67 TTFFont& operator=(const TTFFont&) = delete;
68};
69
70#endif
71
72/* EOF */
73