-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
text_surface.hpp
66 lines (54 loc) · 1.58 KB
/
text_surface.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
Copyright (C) 2016 - 2018 by Chris Beck<render787@gmail.com>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#include "font_id.hpp" // for text_chunk
#include "color.hpp"
#include <SDL2/SDL_ttf.h>
#include <string>
#include <vector>
/***
* Note: This is specific to the SDL_TTF codepath.
*/
class surface;
namespace font {
class text_surface
{
public:
text_surface(const std::string& str, int size, color_t color, int style);
text_surface(int size, color_t color, int style);
void set_text(const std::string& str);
void measure() const;
size_t width() const;
size_t height() const;
#ifdef HAVE_FRIBIDI
bool is_rtl() const { return is_rtl_; } // Right-To-Left alignment
#endif
const std::vector<surface>& get_surfaces() const;
bool operator==(const text_surface& t) const;
bool operator!=(const text_surface& t) const { return !operator==(t); }
private:
int hash_;
int font_size_;
color_t color_;
int style_;
mutable int w_, h_;
std::string str_;
mutable bool initialized_;
mutable std::vector<text_chunk> chunks_;
mutable std::vector<surface> surfs_;
#ifdef HAVE_FRIBIDI
bool is_rtl_;
void bidi_cvt();
#endif
void hash();
};
} // end namespace font