Skip to content

Commit

Permalink
Avoid another allocation, this time with atlas fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Oct 16, 2024
1 parent ce980af commit 3def2dd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Common/Render/DrawBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 3def2dd

Please sign in to comment.