23 #include <SDL2/SDL_ttf.h> 33 #define DBG_FT LOG_STREAM(debug, log_font) 34 #define LOG_FT LOG_STREAM(info, log_font) 35 #define WRN_FT LOG_STREAM(warn, log_font) 36 #define ERR_FT LOG_STREAM(err, log_font) 41 void text_surface::bidi_cvt()
43 char *c_str =
const_cast<char *
>(
str_.c_str());
44 FriBidiStrIndex len =
str_.length();
45 FriBidiChar *bidi_logical =
new FriBidiChar[len + 2];
46 FriBidiChar *bidi_visual =
new FriBidiChar[len + 2];
47 char *utf8str =
new char[4*len + 1];
48 FriBidiCharType base_dir = FRIBIDI_TYPE_ON;
52 n = fribidi_charset_to_unicode(FRIBIDI_CHAR_SET_UTF8, c_str, len, bidi_logical);
54 #pragma GCC diagnostic push 55 #pragma GCC diagnostic ignored "-Wunused-result" 56 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 58 fribidi_log2vis(bidi_logical, n, &base_dir, bidi_visual,
nullptr,
nullptr,
nullptr);
60 #pragma GCC diagnostic pop 63 fribidi_unicode_to_charset(FRIBIDI_CHAR_SET_UTF8, bidi_visual, n, utf8str);
64 is_rtl_ = base_dir == FRIBIDI_TYPE_RTL;
65 str_ = std::string(utf8str);
66 delete[] bidi_logical;
126 for(
const char c :
str_) {
127 h = ((h << 9) | (h >> (
sizeof(int) * 8 - 9))) ^ (
c);
140 if(ttfont ==
nullptr) {
145 TTF_SizeUTF8(ttfont.get(), chunk.text.c_str(), &
w, &
h);
147 h_ = std::max<int>(
h_,
h);
Note: Specific to sdl_ttf.
std::vector< text_chunk > chunks_
A string that should be rendered with a single font.
std::size_t width() const
static lg::log_domain log_font("font")
SDL_Color to_sdl() const
Returns the stored color as an color_t object.
static std::vector< text_chunk > split_text(const std::string &utf8_text)
Splits the UTF-8 text into text_chunks using the same font.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
const std::size_t max_text_line_width
static std::shared_ptr< TTF_Font > get_font(font_id)
text_surface(const std::string &str, int size, color_t color, int style)
void set_text(const std::string &str)
const std::vector< surface > & get_surfaces() const
static map_location::DIRECTION s
std::vector< surface > surfs_
std::size_t height() const
Standard logging facilities (interface).
bool operator==(const text_surface &t) const
static map_location::DIRECTION n