Avoid another allocation, this time with atlas fonts

This commit is contained in:
Henrik Rydgård 2024-10-16 14:35:54 +02:00
parent ce980af01e
commit 3def2ddb00

View File

@ -521,7 +521,6 @@ void DrawBuffer::MeasureTextRect(FontID font_id, std::string_view text, const Bo
return;
}
std::string toMeasure = std::string(text);
int wrap = align & (FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT);
if (wrap) {
const AtlasFont *font = fontAtlas_->getFont(font_id);
@ -532,10 +531,12 @@ void DrawBuffer::MeasureTextRect(FontID font_id, std::string_view text, const Bo
*h = 0.0f;
return;
}
std::string toMeasure = std::string(text);
AtlasWordWrapper wrapper(*font, fontscalex, toMeasure, bounds.w, wrap);
toMeasure = wrapper.Wrapped();
} else {
MeasureText(font_id, text, w, h);
}
MeasureText(font_id, toMeasure, w, h);
}
void DrawBuffer::DrawTextShadow(FontID font, std::string_view text, float x, float y, Color color, int flags) {