diff options
-rw-r--r-- | src/ui/text.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/ui/text.c b/src/ui/text.c index 836d540f..8ed04bb4 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -263,14 +263,23 @@ iLocalDef iFont *font_Text_(enum iFontId id) { | |||
263 | return &text_.fonts[id]; | 263 | return &text_.fonts[id]; |
264 | } | 264 | } |
265 | 265 | ||
266 | static void freeBmp_(void *ptr) { | ||
267 | stbtt_FreeBitmap(ptr, NULL); | ||
268 | } | ||
269 | |||
266 | static SDL_Surface *rasterizeGlyph_Font_(const iFont *d, iChar ch, float xShift) { | 270 | static SDL_Surface *rasterizeGlyph_Font_(const iFont *d, iChar ch, float xShift) { |
267 | int w, h; | 271 | int w, h; |
268 | uint8_t *bmp = stbtt_GetCodepointBitmapSubpixel( | 272 | uint8_t *bmp = stbtt_GetCodepointBitmapSubpixel( |
269 | &d->font, d->scale, d->scale, xShift, 0.0f, ch, &w, &h, 0, 0); | 273 | &d->font, d->scale, d->scale, xShift, 0.0f, ch, &w, &h, 0, 0); |
270 | /* Note: `bmp` must be freed afterwards. */ | 274 | /* Note: `bmp` must be freed afterwards. */ |
271 | SDL_Surface *surface = | 275 | collect_Garbage(bmp, freeBmp_); |
276 | SDL_Surface *surface8 = | ||
272 | SDL_CreateRGBSurfaceWithFormatFrom(bmp, w, h, 8, w, SDL_PIXELFORMAT_INDEX8); | 277 | SDL_CreateRGBSurfaceWithFormatFrom(bmp, w, h, 8, w, SDL_PIXELFORMAT_INDEX8); |
273 | SDL_SetSurfacePalette(surface, text_.grayscale); | 278 | SDL_SetSurfacePalette(surface8, text_.grayscale); |
279 | SDL_PixelFormat *fmt = SDL_AllocFormat(SDL_PIXELFORMAT_RGBA8888); | ||
280 | SDL_Surface *surface = SDL_ConvertSurface(surface8, fmt, 0); | ||
281 | SDL_FreeFormat(fmt); | ||
282 | SDL_FreeSurface(surface8); | ||
274 | return surface; | 283 | return surface; |
275 | } | 284 | } |
276 | 285 | ||
@@ -330,6 +339,7 @@ static void cache_Font_(iFont *d, iGlyph *glyph, int hoff) { | |||
330 | NULL, | 339 | NULL, |
331 | NULL); | 340 | NULL); |
332 | tex = SDL_CreateTextureFromSurface(render, surface); | 341 | tex = SDL_CreateTextureFromSurface(render, surface); |
342 | SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_NONE); | ||
333 | glRect->size = init_I2(surface->w, surface->h); | 343 | glRect->size = init_I2(surface->w, surface->h); |
334 | } | 344 | } |
335 | /* Determine placement in the glyph cache texture, advancing in rows. */ | 345 | /* Determine placement in the glyph cache texture, advancing in rows. */ |
@@ -342,7 +352,6 @@ static void cache_Font_(iFont *d, iGlyph *glyph, int hoff) { | |||
342 | if (tex) { | 352 | if (tex) { |
343 | SDL_DestroyTexture(tex); | 353 | SDL_DestroyTexture(tex); |
344 | iAssert(surface); | 354 | iAssert(surface); |
345 | stbtt_FreeBitmap(surface->pixels, NULL); | ||
346 | SDL_FreeSurface(surface); | 355 | SDL_FreeSurface(surface); |
347 | } | 356 | } |
348 | } | 357 | } |