font/sdl_ttf_compat: Avoid rendering twice in pango_draw_text()

We need to obtain the text extents prior to rendering regardless. In the
best case, we do so in advance before rendering, which internally
doesn't recalculate the text layout if the rendering parameters haven't
been touched in the meantime. In the worst case, we calculate extents
twice but only render once.
This commit is contained in:
Iris Morelle 2021-03-13 19:54:31 -03:00
parent 0e013c59b6
commit 995bfef3df

View file

@ -152,16 +152,16 @@ SDL_Rect pango_draw_text(surface& dst, const SDL_Rect& area, int size, const col
.set_foreground_color(color)
.set_ellipse_mode(PANGO_ELLIPSIZE_END);
auto s = ptext.render();
auto extents = ptext.get_size();
bool ellipsized = false;
if(s->w > area.w) {
if(extents.x > area.w) {
ptext.set_maximum_width(area.w);
s = ptext.render();
ellipsized = true;
}
auto s = ptext.render();
SDL_Rect res = { x, y, s->w, s->h };
if(dst) {