Commits

Anonymous committed 60093dc

Fixed bug when drawing text on palette surfaces.

Comments (0)

Files changed (5)

src/freetype/ft_mod.c

 */
 
 #define PYGAME_FREETYPE_INTERNAL
+#define PYGAME_FREETYPE_FONT_INTERNAL
 
+#include "pgfreetype.h"
+#include "ft_wrap.h"
 #include "ft_mod.h"
-#include "ft_wrap.h"
-#include "pgfreetype.h"
 #include "freetypebase_doc.h"
 
 static int _ft_traverse (PyObject *mod, visitproc visit, void *arg);

src/freetype/ft_mod.h

 #ifndef _PYGAME_FREETYPEMOD_H_
 #define _PYGAME_FREETYPEMOD_H_
 
-#include "pgcompat.h"
-
-#define PYGAME_FREETYPE_INTERNAL
-#define PYGAME_FREETYPE_FONT_INTERNAL
-
 extern PyTypeObject PyFreeTypeFont_Type;
 #define PyFreeTypeFont_Check(x) (PyObject_TypeCheck(x, &PyFreeTypeFont_Type))
 PyObject* PyFreeTypeFont_New(const char *file, int face_index);

src/freetype/ft_render_cb.c

             {                                               \
                 FT_UInt32 pixel = (FT_UInt32)_getp;         \
                                                             \
-                GET_RGB_VALS(                               \
-                        pixel, surface->format,             \
-                        bgR, bgG, bgB, bgA);                \
+                if (_bpp == 1)                              \
+                {                                           \
+                    GET_PALETTE_VALS(                       \
+                            pixel, surface->format,         \
+                            bgR, bgG, bgB, bgA);            \
+                }                                           \
+                else                                        \
+                {                                           \
+                    GET_RGB_VALS(                           \
+                            pixel, surface->format,         \
+                            bgR, bgG, bgB, bgA);            \
+                                                            \
+                }                                           \
                                                             \
                 ALPHA_BLEND(                                \
                         color->r, color->g, color->b,       \
             {                                                           \
                 FT_UInt32 pixel = (FT_UInt32)_getp;                     \
                                                                         \
-                GET_RGB_VALS(                                           \
-                        pixel, surface->format,                         \
-                        bgR, bgG, bgB, bgA);                            \
+                if (_bpp == 1)                                          \
+                {                                                       \
+                    GET_PALETTE_VALS(                                   \
+                            pixel, surface->format,                     \
+                            bgR, bgG, bgB, bgA);                        \
+                }                                                       \
+                else                                                    \
+                {                                                       \
+                    GET_RGB_VALS(                                       \
+                            pixel, surface->format,                     \
+                            bgR, bgG, bgB, bgA);                        \
+                                                                        \
+                }                                                       \
                                                                         \
                 ALPHA_BLEND(                                            \
                         color->r, color->g, color->b, color->a,         \
 
 #define _CREATE_RGB_RENDER(_bpp, _getp, _setp, _blendp)                 \
     void __render_glyph_RGB##_bpp(int x, int y, FontSurface *surface,   \
-        FT_Bitmap *bitmap, FontColor *color)                              \
+        FT_Bitmap *bitmap, FontColor *color)                            \
     {                                                                   \
         const int off_x = (x < 0) ? -x : 0;                             \
         const int off_y = (y < 0) ? -y : 0;                             \
                 {                                                       \
                     FT_UInt32 pixel = (FT_UInt32)_getp;                 \
                                                                         \
+                if (_bpp == 1)                                          \
+                {                                                       \
+                    GET_PALETTE_VALS(                                   \
+                            pixel, surface->format,                     \
+                            bgR, bgG, bgB, bgA);                        \
+                }                                                       \
+                else                                                    \
+                {                                                       \
                     GET_RGB_VALS(                                       \
                             pixel, surface->format,                     \
                             bgR, bgG, bgB, bgA);                        \
                                                                         \
+                }                                                       \
+                                                                        \
                     ALPHA_BLEND(                                        \
                             color->r, color->g, color->b, alpha,        \
                             bgR, bgG, bgB, bgA);                        \
 _CREATE_RGB_FILLER(3,  GET_PIXEL24(_dst),       _SET_PIXEL_24,          _BLEND_PIXEL_24)
 _CREATE_RGB_FILLER(2,  _GET_PIXEL(FT_UInt16),   _SET_PIXEL(FT_UInt16),  _BLEND_PIXEL(FT_UInt16))
 _CREATE_RGB_FILLER(1,  _GET_PIXEL(FT_Byte),     _SET_PIXEL(FT_Byte),    _BLEND_PIXEL_GENERIC(FT_Byte))
-
 #endif

src/freetype/ft_wrap.h

     ft_ptr = FREETYPE_STATE->freetype;                          \
     if (ft_ptr == NULL)                                         \
     {                                                           \
-        PyErr_SetString(PyExc_PyGameError,                      \
+        PyErr_SetString(PyExc_RuntimeError,                     \
             "The FreeType 2 library hasn't been initialized");  \
         return (rvalue);                                        \
     }
 
 int         PGFT_Render_ExistingSurface(FreeTypeInstance *ft, PyFreeTypeFont *font,
                 const FontRenderMode *render, PyObject *text, 
-                SDL_Surface *surface, int x, int y, FontColor *fgcolor, FontColor *bgcolor,
+                SDL_Surface *_surface, int x, int y, FontColor *fgcolor, FontColor *bgcolor,
                 int *_width, int *_height);
 
 int         PGFT_BuildRenderMode(FreeTypeInstance *ft, 

src/freetype/pgfreetype.h

 #define _PYGAME_FREETYPE_H_
 
 #include "pgbase.h"
+#include "pgcompat.h"
 
 #ifdef HAVE_PYGAME_SDL_VIDEO
 #   include <SDL.h>