Однако границы неверны. Я устанавливаю размер шрифта на 70, но рассчитанная высота составляет около 50. Ширина также неточна.
Код: Выделить всё
Winpp::Vector2 Winpp::Text::CalculateSize(std::wstring text, Winpp::Font font) {
Gdiplus::GraphicsPath path;
Gdiplus::Point orgn(0, 0);
std::string fn = font.GetFontName();
Gdiplus::FontFamily fm(std::wstring(fn.begin(), fn.end()).c_str());
INT st = Gdiplus::FontStyleRegular;
if (font.IsBold()) st |= Gdiplus::FontStyleBold;
if (font.IsItalic()) st |= Gdiplus::FontStyleItalic;
if (font.IsStrikeout()) st |= Gdiplus::FontStyleStrikeout;
if (font.IsUnderline()) st |= Gdiplus::FontStyleUnderline;
Gdiplus::REAL emSize = font.GetFontSize(); // For example, 70
path.AddString(text.c_str(), text.size(), &fm, st, emSize, orgn, nullptr);
// Optional: path.Widen(&pen); for outlines
Gdiplus::RectF rect;
path.GetBounds(&rect);
return Vector2(std::ceil(rect.Width), std::ceil(rect.Height));
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... h-outlines
Мобильная версия