Beispiel #1
0
shared_string make_text_ellipsis(const shared_string &text, int font_size,
		int max_width, bool with_tags, bool parse_for_style)
{
	static const std::string ellipsis = "...";

	SDL_Color unused_color;
	int unused_int;
	int style = TTF_STYLE_NORMAL;
	if(parse_for_style) parse_markup(text.begin(), text.end(), &unused_int, &unused_color, &style);

	if(line_width(with_tags ? text : shared_string(del_tags(text)), font_size, style) <= max_width)
		return text;
	if(line_width(ellipsis, font_size, style) > max_width)
		return "";

	std::string current_substring;

	utils::utf8_iterator itor(text);

	for(; itor != utils::utf8_iterator::end(text); ++itor) {
		std::string tmp = current_substring;
		tmp.append(itor.substr().first, itor.substr().second);
		tmp += ellipsis;

		if (line_width(with_tags ? tmp : del_tags(tmp), font_size, style) > max_width) {
			return current_substring + ellipsis;
		}

		current_substring.append(itor.substr().first, itor.substr().second);
	}

	return text; // Should not happen
}
Beispiel #2
0
 bool operator()(const partial_string& x,const shared_string& y)const
 {
   return x.str<y.substr(0,x.str.size());
 }
Beispiel #3
0
 bool operator()( const std::string& a, const shared_string& b )const
 {
    return less( a.c_str(), b.c_str() );
 }
Beispiel #4
0
inline void from_string( shared_string& out, const string& in ){ out.assign( in.begin(), in.end() ); }
Beispiel #5
0
inline std::string to_string( const shared_string& str ) { return std::string( str.begin(), str.end() ); }