font.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. pygame - Python Game Library
  3. Copyright (C) 2000-2001 Pete Shinners
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this library; if not, write to the Free
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. Pete Shinners
  16. pete@shinners.org
  17. */
  18. #include <Python.h>
  19. #if defined(HAVE_SNPRINTF) /* also defined in SDL_ttf (SDL.h) */
  20. #undef HAVE_SNPRINTF /* remove GCC macro redefine warning */
  21. #endif
  22. #include <SDL_ttf.h>
  23. /* test font initialization */
  24. #define FONT_INIT_CHECK() \
  25. if(!(*(int*)PyFONT_C_API[2])) \
  26. return RAISE(PyExc_SDLError, "font system not initialized")
  27. #define PYGAMEAPI_FONT_NUMSLOTS 3
  28. typedef struct {
  29. PyObject_HEAD
  30. TTF_Font* font;
  31. PyObject* weakreflist;
  32. } PyFontObject;
  33. #define PyFont_AsFont(x) (((PyFontObject*)x)->font)
  34. #ifndef PYGAMEAPI_FONT_INTERNAL
  35. #define PyFont_Check(x) ((x)->ob_type == (PyTypeObject*)PyFONT_C_API[0])
  36. #define PyFont_Type (*(PyTypeObject*)PyFONT_C_API[0])
  37. #define PyFont_New (*(PyObject*(*)(TTF_Font*))PyFONT_C_API[1])
  38. /*slot 2 taken by FONT_INIT_CHECK*/
  39. #define import_pygame_font() { \
  40. PyObject *module = PyImport_ImportModule(MODPREFIX "font"); \
  41. if (module != NULL) { \
  42. PyObject *dict = PyModule_GetDict(module); \
  43. PyObject *c_api = PyDict_GetItemString(dict, PYGAMEAPI_LOCAL_ENTRY); \
  44. if(PyCObject_Check(c_api)) {\
  45. void** localptr = (void**)PyCObject_AsVoidPtr(c_api); \
  46. memcpy(PyFONT_C_API, localptr, sizeof(void*)*PYGAMEAPI_FONT_NUMSLOTS); \
  47. } Py_DECREF(module); } }
  48. #endif
  49. static void* PyFONT_C_API[PYGAMEAPI_FONT_NUMSLOTS] = {NULL};