diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/text.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/ui/text.c b/src/ui/text.c index b581aee3..325a201f 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -41,8 +41,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
41 | 41 | ||
42 | #include <SDL_surface.h> | 42 | #include <SDL_surface.h> |
43 | #include <SDL_hints.h> | 43 | #include <SDL_hints.h> |
44 | #include <SDL_version.h> | ||
44 | #include <stdarg.h> | 45 | #include <stdarg.h> |
45 | 46 | ||
47 | #if SDL_VERSION_ATLEAST(2, 0, 10) | ||
48 | # define LAGRANGE_RASTER_DEPTH 8 | ||
49 | # define LAGRANGE_RASTER_FORMAT SDL_PIXELFORMAT_INDEX8 | ||
50 | #else | ||
51 | # define LAGRANGE_RASTER_DEPTH 32 | ||
52 | # define LAGRANGE_RASTER_FORMAT SDL_PIXELFORMAT_RGBA8888 | ||
53 | #endif | ||
54 | |||
46 | iDeclareType(Font) | 55 | iDeclareType(Font) |
47 | iDeclareType(Glyph) | 56 | iDeclareType(Glyph) |
48 | iDeclareTypeConstructionArgs(Glyph, iChar ch) | 57 | iDeclareTypeConstructionArgs(Glyph, iChar ch) |
@@ -473,7 +482,15 @@ static SDL_Surface *rasterizeGlyph_Font_(const iFont *d, uint32_t glyphIndex, fl | |||
473 | SDL_Surface *surface8 = | 482 | SDL_Surface *surface8 = |
474 | SDL_CreateRGBSurfaceWithFormatFrom(bmp, w, h, 8, w, SDL_PIXELFORMAT_INDEX8); | 483 | SDL_CreateRGBSurfaceWithFormatFrom(bmp, w, h, 8, w, SDL_PIXELFORMAT_INDEX8); |
475 | SDL_SetSurfacePalette(surface8, text_.grayscale); | 484 | SDL_SetSurfacePalette(surface8, text_.grayscale); |
485 | #if LAGRANGE_RASTER_DEPTH != 8 | ||
486 | /* Convert to the cache format. */ | ||
487 | SDL_Surface *surf = SDL_ConvertSurfaceFormat(surface8, LAGRANGE_RASTER_FORMAT, 0); | ||
488 | free(bmp); | ||
489 | SDL_FreeSurface(surface8); | ||
490 | return surf; | ||
491 | #else | ||
476 | return surface8; | 492 | return surface8; |
493 | #endif | ||
477 | } | 494 | } |
478 | 495 | ||
479 | #if 0 | 496 | #if 0 |
@@ -708,7 +725,9 @@ void cacheTextGlyphs_Font_(iFont *d, const iRangecc text) { | |||
708 | if (buf == NULL) { | 725 | if (buf == NULL) { |
709 | rasters = new_Array(sizeof(iRasterGlyph)); | 726 | rasters = new_Array(sizeof(iRasterGlyph)); |
710 | buf = SDL_CreateRGBSurfaceWithFormat( | 727 | buf = SDL_CreateRGBSurfaceWithFormat( |
711 | 0, bufSize.x, bufSize.y, 8, SDL_PIXELFORMAT_INDEX8); | 728 | 0, bufSize.x, bufSize.y, |
729 | LAGRANGE_RASTER_DEPTH, | ||
730 | LAGRANGE_RASTER_FORMAT); | ||
712 | SDL_SetSurfacePalette(buf, text_.grayscale); | 731 | SDL_SetSurfacePalette(buf, text_.grayscale); |
713 | } | 732 | } |
714 | SDL_Surface *surfaces[2] = { | 733 | SDL_Surface *surfaces[2] = { |
@@ -739,7 +758,9 @@ void cacheTextGlyphs_Font_(iFont *d, const iRangecc text) { | |||
739 | } | 758 | } |
740 | iForIndices(i, surfaces) { | 759 | iForIndices(i, surfaces) { |
741 | if (surfaces[i]) { | 760 | if (surfaces[i]) { |
742 | free(surfaces[i]->pixels); | 761 | if (surfaces[i]->flags & SDL_PREALLOC) { |
762 | free(surfaces[i]->pixels); | ||
763 | } | ||
743 | SDL_FreeSurface(surfaces[i]); | 764 | SDL_FreeSurface(surfaces[i]); |
744 | } | 765 | } |
745 | } | 766 | } |