示例#1
0
文件: font.cpp 项目: dodikk/iWesnoth
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
}
void test_vector_with_string_pointers(void)
{
  using shared_string = std::shared_ptr<mtr::string>;
  {
    mtr::vector<shared_string> v1;
    auto v2 = v1.append(shared_string(new mtr::string("Shared string one")))
                .append(shared_string(new mtr::string("Shared string two")))
                .append(shared_string(new mtr::string("Shared string three")))
                .append(shared_string(new mtr::string("Shared string four")))
                .append(shared_string(new mtr::string("Shared string five")))
                .append(shared_string(new mtr::string("Shared string six")));

    v2.foreach(0)([](int a, const shared_string &s) -> int { std::cout << *s << std::endl; });
    v2.foreach(0)([](int, const shared_string &s) -> int { std::cout << *s << std::endl; });
  }
}
示例#3
0
			void check_existance_of_basic_types()
			{
				BOOST_CHECK_NO_THROW( index( 14 ) );
				BOOST_CHECK_NO_THROW( shared_string( new std::string("hello tests") ) );
			}