Skip to content

Commit 31954f7

Browse files
committed
Outline properly renders with filled text
1 parent 97c2f55 commit 31954f7

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src_c/font.c

+23-9
Original file line numberDiff line numberDiff line change
@@ -683,26 +683,37 @@ font_render(PyObject *self, PyObject *args, PyObject *kwds)
683683
return NULL;
684684
}
685685

686+
SDL_Surface *filled_with_outline_surf;
687+
686688
if (outline_size > 0) {
687689
TTF_SetFontOutline(font, outline_size);
688690

689691
if (!_create_font_surface(font, text, antialias, outline_color, backg,
690692
draw_backg, wraplength, &outline_surf)) {
691693
return NULL;
692694
}
693-
SDL_SetSurfaceBlendMode(outline_surf, SDL_BLENDMODE_BLEND);
694695

695696
TTF_SetFontOutline(font, 0);
696697

697-
// `surf` and `outline_surf` are **NOT** the same size.
698-
SDL_Rect dstrect;
699-
dstrect.x = outline_surf->w / 2 - surf->w / 2;
700-
dstrect.y = outline_surf->h / 2 - surf->h / 2;
701-
dstrect.w = surf->w;
702-
dstrect.h = surf->h;
703-
SDL_BlitSurface(surf, NULL, outline_surf, &dstrect);
698+
filled_with_outline_surf = PG_CreateSurface(
699+
outline_surf->w, outline_surf->h, SDL_PIXELFORMAT_RGBA32);
704700

705-
final = (PyObject *)pgSurface_New(outline_surf);
701+
// `surf` and `outline_surf` are **NOT** the same size.
702+
SDL_Rect outlinerect;
703+
outlinerect.x = filled_with_outline_surf->w / 2 - outline_surf->w / 2;
704+
outlinerect.y = filled_with_outline_surf->h / 2 - outline_surf->h / 2;
705+
outlinerect.w = outline_surf->w;
706+
outlinerect.h = outline_surf->h;
707+
SDL_Rect fillrect;
708+
fillrect.x = filled_with_outline_surf->w / 2 - surf->w / 2;
709+
fillrect.y = filled_with_outline_surf->h / 2 - surf->h / 2;
710+
fillrect.w = surf->w;
711+
fillrect.h = surf->h;
712+
SDL_BlitSurface(surf, NULL, filled_with_outline_surf, &fillrect);
713+
SDL_BlitSurface(outline_surf, NULL, filled_with_outline_surf,
714+
&outlinerect);
715+
716+
final = (PyObject *)pgSurface_New(filled_with_outline_surf);
706717
}
707718
else {
708719
final = (PyObject *)pgSurface_New(surf);
@@ -712,6 +723,9 @@ font_render(PyObject *self, PyObject *args, PyObject *kwds)
712723
SDL_FreeSurface(surf);
713724
if (outline_surf != NULL)
714725
SDL_FreeSurface(outline_surf);
726+
727+
if (filled_with_outline_surf != NULL)
728+
SDL_FreeSurface(filled_with_outline_surf);
715729
}
716730
return final;
717731
}

0 commit comments

Comments
 (0)