Skip to content

Commit

Permalink
font/sdl_ttf_compat: Avoid rendering twice in pango_draw_text()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
irydacea committed Mar 13, 2021
1 parent 0e013c5 commit 995bfef
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/font/sdl_ttf_compat.cpp
Expand Up @@ -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) {
Expand Down

0 comments on commit 995bfef

Please sign in to comment.