@@ -171,9 +171,24 @@ SDL_Surface* OverlayManager::RenderTextOutlinedWrapped(TTF_Font* font, const cha
171171 return nullptr ;
172172 }
173173
174- // Draw text twice, but outline is a bit bigger
175174 int oldOutline = TTF_GetFontOutline (font);
176175 TTF_SetFontOutline (font, outlineWidth);
176+
177+ // Verify that the string won't require wrapping (which could cause the outline and the text
178+ // to diverge due to different wrapping positions).
179+ //
180+ // FIXME: We do this rather than just disabling wrapping entirely (wrapWidth = 0) because we
181+ // need further testing to ensure that all renderers can handle non-NPOT overlay textures.
182+ for (const QString& line : QString (text).split (' \n ' )) {
183+ int extent, count;
184+ if (TTF_MeasureUTF8 (font, line.toUtf8 (), wrapWidth, &extent, &count) == 0 && count < line.size ()) {
185+ // If it requires wrapping, render it without the outline
186+ TTF_SetFontOutline (font, oldOutline);
187+ return TTF_RenderUTF8_Blended_Wrapped (font, text, textColor, wrapWidth);
188+ }
189+ }
190+
191+ // Draw text twice, but outline is a bit bigger
177192 auto outlineSurface = TTF_RenderUTF8_Blended_Wrapped (font, text, outlineColor, wrapWidth);
178193 TTF_SetFontOutline (font, 0 );
179194 auto textSurface = TTF_RenderUTF8_Blended_Wrapped (font, text, textColor, wrapWidth);
0 commit comments