本文整理汇总了C++中FontMetrics::line_height方法的典型用法代码示例。如果您正苦于以下问题:C++ FontMetrics::line_height方法的具体用法?C++ FontMetrics::line_height怎么用?C++ FontMetrics::line_height使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FontMetrics
的用法示例。
在下文中一共展示了FontMetrics::line_height方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clipped_text
std::string Font::clipped_text(const CanvasPtr &canvas, const Sizef &box_size, const std::string &text, const std::string &ellipsis_text)
{
std::string out_string;
out_string.reserve(text.length());
Pointf pos;
FontMetrics fm = font_metrics(canvas);
float descent = fm.descent();
float line_spacing = fm.line_height();
std::vector<std::string> lines = Text::split(text, "\n", false);
for (std::vector<std::string>::size_type i = 0; i < lines.size(); i++)
{
if (i == 0 || pos.y + descent < box_size.height)
{
Sizef size = measure_text(canvas, lines[i]).bbox_size;
if (pos.x + size.width <= box_size.width)
{
if (!out_string.empty())
out_string += "\n";
out_string += lines[i];
}
else
{
Sizef ellipsis = measure_text(canvas, ellipsis_text).bbox_size;
int seek_start = 0;
int seek_end = lines[i].size();
int seek_center = (seek_start + seek_end) / 2;
UTF8_Reader utf8_reader(lines[i].data(), lines[i].length());
while (true)
{
utf8_reader.set_position(seek_center);
utf8_reader.move_to_leadbyte();
if (seek_center != utf8_reader.position())
utf8_reader.next();
seek_center = utf8_reader.position();
if (seek_center == seek_end)
break;
utf8_reader.set_position(seek_start);
utf8_reader.next();
if (utf8_reader.position() == seek_end)
break;
Sizef text_size = measure_text(canvas, lines[i].substr(0, seek_center)).bbox_size;
if (pos.x + text_size.width + ellipsis.width >= box_size.width)
seek_end = seek_center;
else
seek_start = seek_center;
seek_center = (seek_start + seek_end) / 2;
}
if (!out_string.empty())
out_string += "\n";
out_string += lines[i].substr(0, seek_center) + ellipsis_text;
}
pos.y += line_spacing;
}
}
return out_string;
}