21 #define GETTEXT_DOMAIN "wesnoth-lib"
65 std::string::const_iterator
parse_markup(std::string::const_iterator i1,
66 std::string::const_iterator i2,
68 SDL_Color*
color,
int* style)
92 if (font_size) *font_size += 2;
95 if (font_size) *font_size -= 2;
98 if (style) *style |= TTF_STYLE_BOLD;
104 std::string::const_iterator
start = i1;
109 while (i1 != i2 && *i1 >=
'0' && *i1<=
'9') {
116 if (i1 != i2 &&
',' == (*i1)) {
118 while(i1 != i2 && *i1 >=
'0' && *i1<=
'9'){
126 if (i1 != i2 &&
',' == (*i1)) {
128 while(i1 != i2 && *i1 >=
'0' && *i1<=
'9'){
135 if (i1 != i2 &&
'>' == (*i1)) {
136 SDL_Color temp_color = {red,
green,
blue, 0};
137 if (color) *color = temp_color;
142 if (i1 == i2)
return i1;
154 std::vector<std::string> lines =
utils::split(text,
'\n', 0);
156 for(line = lines.begin(); line != lines.end(); ++line) {
157 std::string::const_iterator i1 = line->begin(),
166 std::stringstream markup;
170 <<
static_cast<int>(color.r) <<
","
171 << static_cast<int>(color.g) <<
","
172 <<
static_cast<int>(color.b) <<
">";
179 sprintf(buf,
"%02x%02x%02x", color.r, color.g, color.b);
190 const SDL_Rect area = {0,0,10000,10000};
196 int x,
int y,
bool use_tooltips,
int style)
201 const std::string& text = txt.empty() ? blank_text : txt;
209 std::string::const_iterator i1 = text.begin();
210 std::string::const_iterator i2 =
std::find(i1,text.end(),
'\n');
212 SDL_Color col =
color;
214 int text_style = style;
221 const SDL_Rect rect =
draw_text_line(dst, area, sz, col, new_string, x, y, use_tooltips, text_style);
230 if(i2 == text.end()) {
243 int x,
int y,
bool use_tooltips,
int style)
279 if (ch < 0x2e80)
return false;
283 (ch >= 0x4e00 && ch < 0x9fcf) ||
284 (ch >= 0x3400 && ch < 0x4dbf) ||
285 (ch >= 0x20000 && ch < 0x2a6df) ||
286 (ch >= 0xf900 && ch < 0xfaff) ||
287 (ch >= 0x3190 && ch < 0x319f) ||
290 (ch >= 0x2e80 && ch < 0x2eff) ||
291 (ch >= 0x2f00 && ch < 0x2fdf) ||
292 (ch >= 0x31c0 && ch < 0x31ef) ||
295 (ch >= 0x3104 && ch < 0x312e) ||
296 (ch >= 0x31a0 && ch < 0x31bb) ||
299 (ch >= 0xa490 && ch < 0xa4c7) ||
300 (ch >= 0xa000 && ch < 0xa48d) ||
303 (ch >= 0x3040 && ch <= 0x309f) ||
304 (ch >= 0x30a0 && ch <= 0x30ff) ||
305 (ch >= 0x1b000 && ch <= 0x1b001) ||
308 (ch >= 0x31f0 && ch <= 0x31ff) ||
311 (ch >= 0xac00 && ch < 0xd7af) ||
312 (ch >= 0x1100 && ch <= 0x11ff) ||
313 (ch >= 0xa960 && ch <= 0xa97c) ||
314 (ch >= 0xd7b0 && ch <= 0xd7fb) ||
317 (ch >= 0x3000 && ch < 0x303f) ||
320 (ch >= 0xff00 && ch < 0xffef);
331 SDL_Rect tsize =
line_size(tmp, font_size, style);
332 if(tsize.w > max_width) {
334 if(line.empty() &&
first) {
370 ch == 0x2018 || ch == 0x201c || ch == 0x3008 || ch == 0x300a || ch == 0x300c ||
371 ch == 0x300e || ch == 0x3010 || ch == 0x3014 || ch == 0xff08 || ch == 0xff3b ||
382 ch == 0x3016 || ch == 0x301a || ch == 0x301d;
391 ch == 0x2019 || ch == 0x201d || ch == 0x2026 || ch == 0x3001 || ch == 0x3002 ||
392 ch == 0x3005 || ch == 0x3009 || ch == 0x300b || ch == 0x300d || ch == 0x300f ||
393 ch == 0x3011 || ch == 0x3015 || ch == 0x3041 || ch == 0x3043 || ch == 0x3045 ||
394 ch == 0x3047 || ch == 0x3049 || ch == 0x3063 || ch == 0x3083 || ch == 0x3085 ||
395 ch == 0x3087 || ch == 0x308e || ch == 0x309d || ch == 0x309e || ch == 0x30a1 ||
396 ch == 0x30a3 || ch == 0x30a5 || ch == 0x30a7 || ch == 0x30a9 || ch == 0x30c3 ||
397 ch == 0x30e3 || ch == 0x30e5 || ch == 0x30e7 || ch == 0x30ee || ch == 0x30f5 ||
398 ch == 0x30f6 || ch == 0x30fb || ch == 0x30fc || ch == 0x30fd || ch == 0x30fe ||
399 ch == 0xff01 || ch == 0xff09 || ch == 0xff0c || ch == 0xff0e || ch == 0xff1a ||
400 ch == 0xff1b || ch == 0xff1f || ch == 0xff3d || ch == 0xff5d ||
403 ch == 0x31f0 || ch == 0x31f1 || ch == 0x31f2 || ch == 0x31f3 || ch == 0x31f4 ||
404 ch == 0x31f5 || ch == 0x31f6 || ch == 0x31f7 || ch == 0x31f8 || ch == 0x31f9 ||
405 ch == 0x31fa || ch == 0x31fb || ch == 0x31fc || ch == 0x31fd || ch == 0x31fe ||
418 ch == 0x301c || ch == 0xff0d || ch == 0xff64 || ch == 0xff65 || ch == 0x3017 ||
419 ch == 0x301b || ch == 0x301e;
424 if(no_break_before(ch))
432 if(no_break_after(ch))
441 int max_width,
int max_height,
int max_lines,
bool partial_line)
443 VALIDATE(max_width > 0,
_(
"The maximum text width is less than 1."));
449 size_t current_height = 0;
450 bool line_break =
false;
452 bool start_of_line =
true;
457 int style = TTF_STYLE_NORMAL;
463 format_string.clear();
464 while(ch != end && *ch < static_cast<ucs4::char_t>(0x100)
467 format_string.append(ch.
substr().first, ch.
substr().second);
473 style = TTF_STYLE_NORMAL;
475 current_line.clear();
476 start_of_line =
false;
480 if(current_word.empty() && ch ==
end) {
482 }
else if(current_word.empty()) {
483 if(*ch ==
' ' || *ch ==
'\n') {
489 *ch !=
' ' && *ch !=
'\n'; ++ch) {
491 if(!current_word.empty() &&
493 !no_break_after(previous))
496 if(!current_word.empty() &&
497 break_after(previous) &&
498 !no_break_before(*ch))
501 current_word.append(ch.
substr().first, ch.
substr().second);
508 if(current_word ==
"\n") {
510 current_word.clear();
511 start_of_line =
true;
516 line_width += word_width;
518 if(static_cast<long>(line_width) > max_width) {
519 if (!partial_line && static_cast<long>(word_width) > max_width) {
521 current_word, font_sz, style, max_width);
523 if(current_word ==
" ")
527 current_line += current_word;
532 if(line_break || (current_word.empty() && ch ==
end)) {
534 if(max_height > 0 && current_height + size.h >=
size_t(max_height)) {
539 wrapped_text +=
'\n';
542 wrapped_text += format_string + current_line;
543 current_line.clear();
545 current_height += size.h;
549 if(--max_lines == 0) {
559 int x,
int y,
int max_width)
562 return font::draw_text(gui, area, font_size, color, wrapped_text, x, y,
false);
566 sdl::timage draw_text_to_texture(
const SDL_Rect &area,
int size,
const SDL_Color &
color,
const std::string &text,
bool use_tooltips,
int style)
568 SDL_Rect rect =
text_area(text, size, style);
569 surface surf = SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32,
574 SDL_FillRect(surf,
nullptr, 0x000000ff);
575 draw_text(surf, area, size, color, text, 0, 0, use_tooltips, style);
577 return sdl::timage(surf);
const SDL_Color good_dmg_color
SDL_Rect text_area(const std::string &text, int size, int style)
Calculate the size of a text (in pixels) if it were to be drawn.
static void cut_word(std::string &line, std::string &word, int font_size, int style, int max_width)
const SDL_Color unit_type_color
std::string color2hexa(const SDL_Color &color)
Creates the hexadecimal string of a color, such as "#ffff00" for yellow.
const std::string weapon_details_sep
const SDL_Color BLACK_COLOR
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
SDL_Rect line_size(const std::string &line, int font_size, int style)
Determine the size of a line of text given a certain font size.
const char LARGE_TEXT
Standard markups for color, size, font, images.
std::string unescape(const std::string &str)
Remove all escape characters (backslash)
std::string word_wrap_text(const std::string &unwrapped_text, int font_size, int max_width, int max_height, int max_lines, bool partial_line)
Wrap text.
GLint GLint GLint GLint GLint GLint y
To lexical_cast(From value)
Lexical cast converts one type to another.
const SDL_Color NORMAL_COLOR
std::string span_color(const SDL_Color &color)
Creates pango markup of a color.
const SDL_Color inactive_details_color
const SDL_Color GOOD_COLOR
const SDL_Color bad_dmg_color
static UNUSEDNOWARN std::string _(const char *str)
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
const SDL_Color BAD_COLOR
GLubyte GLubyte GLubyte GLubyte w
const SDL_Color race_color
int font_scaled(int size)
GLenum GLuint GLsizei const char * buf
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
const SDL_Color weapon_details_color
std::string join(T const &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::string color2markup(const SDL_Color &color)
Create string of color-markup, such as "<255,255,0>" for yellow.
std::string::const_iterator parse_markup(std::string::const_iterator i1, std::string::const_iterator i2, int *font_size, SDL_Color *color, int *style)
Parses the markup-tags at the front of a string.
bool is_format_char(char c)
Determine if char is one of the special chars used as markup.
SDL_Rect draw_text(surface &dst, const SDL_Rect &area, int size, const SDL_Color &color, const std::string &txt, int x, int y, bool use_tooltips, int style)
Function to draw text on a surface.
const std::string weapon_details
SDL_Rect draw_wrapped_text(CVideo *gui, const SDL_Rect &area, int font_size, const SDL_Color &color, const std::string &text, int x, int y, int max_width)
Draw text on the screen, fit text to maximum width, no markup, no tooltips.
bool is_cjk_char(const ucs4::char_t ch)
Determine if a ucs4::char_t is a CJK character.
GLint GLint GLint GLint GLint x
static iterator_base end(const string_type &str)
SDL_Rect draw_text_line(surface &gui_surface, const SDL_Rect &area, int size, const SDL_Color &color, const std::string &text, int x, int y, bool use_tooltips, int style)
const SDL_Color weapon_color
const std::string weapon_numbers_sep
std::string del_tags(const std::string &text)
Copy string, but without tags at the beginning.
bool find(E event, F functor)
Tests whether an event handler is available.
const std::pair< typename string_type::const_iterator, typename string_type::const_iterator > & substr() const
const SDL_Color GRAY_COLOR
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
const SDL_Color inactive_ability_color
GLsizei const GLcharARB ** string
int line_width(const std::string &line, int font_size, int style)
Determine the width of a line of text given a certain font size.