Mercurial > pygame
annotate src/font.c @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | 6cc8196e0181 |
| children |
| rev | line source |
|---|---|
| 7 | 1 /* |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
2 pygame - Python Game Library |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
3 Copyright (C) 2000-2001 Pete Shinners |
| 7 | 4 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
6 modify it under the terms of the GNU Library General Public |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
7 License as published by the Free Software Foundation; either |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
8 version 2 of the License, or (at your option) any later version. |
| 7 | 9 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
13 Library General Public License for more details. |
| 7 | 14 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
15 You should have received a copy of the GNU Library General Public |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
16 License along with this library; if not, write to the Free |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 7 | 18 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
19 Pete Shinners |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
20 pete@shinners.org |
| 7 | 21 */ |
| 22 | |
|
606
d38f864d01ec
Changes to appease gcc4 may be use uninitialized warnings.
Rene Dudfield <renesd@gmail.com>
parents:
580
diff
changeset
|
23 |
| 7 | 24 /* |
| 29 | 25 * font module for pygame |
| 7 | 26 */ |
| 27 #define PYGAMEAPI_FONT_INTERNAL | |
|
648
4f34da33993f
When rendering unicode, use the python c function to convert
pygame
parents:
627
diff
changeset
|
28 #include "font.h" |
| 532 | 29 #include <stdio.h> |
| 29 | 30 #include <string.h> |
| 7 | 31 #include "pygame.h" |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
32 #include "pgcompat.h" |
| 1937 | 33 #include "doc/font_doc.h" |
| 524 | 34 #include "structmember.h" |
| 7 | 35 |
|
2106
8adeba25d5c7
[BUG] Mac builds fail: maybe using older versions of SDL_ttf or SDL_mixer. Restore version conditional code in font and music modules.
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
36 /* Require SDL_ttf 2.0.6 or later for rwops support */ |
|
8adeba25d5c7
[BUG] Mac builds fail: maybe using older versions of SDL_ttf or SDL_mixer. Restore version conditional code in font and music modules.
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
37 #ifdef TTF_MAJOR_VERSION |
|
8adeba25d5c7
[BUG] Mac builds fail: maybe using older versions of SDL_ttf or SDL_mixer. Restore version conditional code in font and music modules.
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
38 #define FONT_HAVE_RWOPS 1 |
|
8adeba25d5c7
[BUG] Mac builds fail: maybe using older versions of SDL_ttf or SDL_mixer. Restore version conditional code in font and music modules.
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
39 #else |
|
8adeba25d5c7
[BUG] Mac builds fail: maybe using older versions of SDL_ttf or SDL_mixer. Restore version conditional code in font and music modules.
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
40 #define FONT_HAVE_RWOPS 0 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
41 #endif |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
42 |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
43 #if PY3 |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
44 #define RAISE_TEXT_TYPE_ERROR() \ |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
45 RAISE(PyExc_TypeError, "text must be a unicode or bytes"); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
46 #else |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
47 #define RAISE_TEXT_TYPE_ERROR() \ |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
48 RAISE(PyExc_TypeError, "text must be a string or unicode"); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
49 #endif |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
50 |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
51 /* For filtering out UCS-4 and larger characters when Python is |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
52 * built with Py_UNICODE_WIDE. |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
53 */ |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
54 #if defined(Py_UNICODE_WIDE) |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
55 #define IS_UCS_2(c) ((c) < 0x10000L) |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
56 #else |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
57 #define IS_UCS_2(c) 1 |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
58 #endif |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
59 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
60 static PyTypeObject PyFont_Type; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
61 static PyObject* PyFont_New (TTF_Font*); |
| 7 | 62 #define PyFont_Check(x) ((x)->ob_type == &PyFont_Type) |
| 63 | |
| 64 static int font_initialized = 0; | |
|
2108
bded4713cf23
[BUG] Fix some MSVC warnings in hope of solving an error raised in font_test.py.
Lenard Lindstrom <len-l@telus.net>
parents:
2106
diff
changeset
|
65 static const char font_defaultname[] = "freesansbold.ttf"; |
|
bded4713cf23
[BUG] Fix some MSVC warnings in hope of solving an error raised in font_test.py.
Lenard Lindstrom <len-l@telus.net>
parents:
2106
diff
changeset
|
66 static const char pkgdatamodule_name[] = "pygame.pkgdata"; |
|
bded4713cf23
[BUG] Fix some MSVC warnings in hope of solving an error raised in font_test.py.
Lenard Lindstrom <len-l@telus.net>
parents:
2106
diff
changeset
|
67 static const char resourcefunc_name[] = "getResource"; |
|
1581
9f910eda60c5
Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents:
1563
diff
changeset
|
68 |
|
505
951a91f0ab40
Added an extensible package data acquisition system (pkgdata)
bob
parents:
491
diff
changeset
|
69 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
70 /* |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
71 */ |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
72 static int |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
73 utf_8_needs_UCS_4(const char *str) |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
74 { |
|
2112
9d4e31c20a7e
minor changes to merged fsencoding files that may fix the Mac GCC error
Lenard Lindstrom <len-l@telus.net>
parents:
2111
diff
changeset
|
75 static const Uint8 first = '\xF0'; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
76 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
77 while (*str) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
78 if ((Uint8)*str >= first) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
79 return 1; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
80 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
81 ++str; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
82 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
83 return 0; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
84 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
85 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
86 /* Return an encoded file path, a file-like object or a NULL pointer. |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
87 * May raise a Python error. Use PyErr_Occurred to check. |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
88 */ |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
89 static PyObject* |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
90 font_resource (const char *filename) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
91 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
92 PyObject* pkgdatamodule = NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
93 PyObject* resourcefunc = NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
94 PyObject* result = NULL; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
95 PyObject* tmp; |
|
505
951a91f0ab40
Added an extensible package data acquisition system (pkgdata)
bob
parents:
491
diff
changeset
|
96 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
97 pkgdatamodule = PyImport_ImportModule(pkgdatamodule_name); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
98 if (pkgdatamodule == NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
99 return NULL; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
100 } |
| 565 | 101 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
102 resourcefunc = PyObject_GetAttrString(pkgdatamodule, resourcefunc_name); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
103 Py_DECREF(pkgdatamodule); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
104 if (resourcefunc == NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
105 return NULL; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
106 } |
|
505
951a91f0ab40
Added an extensible package data acquisition system (pkgdata)
bob
parents:
491
diff
changeset
|
107 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
108 result = PyObject_CallFunction(resourcefunc, "s", filename); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
109 Py_DECREF(resourcefunc); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
110 if (result == NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
111 return NULL; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
112 } |
|
505
951a91f0ab40
Added an extensible package data acquisition system (pkgdata)
bob
parents:
491
diff
changeset
|
113 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
114 #if PY3 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
115 tmp = PyObject_GetAttrString(result, "name"); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
116 if (tmp != NULL) { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
117 Py_DECREF(result); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
118 result = tmp; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
119 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
120 else if (!PyErr_ExceptionMatches(PyExc_MemoryError)) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
121 PyErr_Clear(); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
122 } |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
123 #else |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
124 if (PyFile_Check(result)) |
|
1581
9f910eda60c5
Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents:
1563
diff
changeset
|
125 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
126 tmp = PyFile_Name(result); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
127 Py_INCREF(tmp); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
128 Py_DECREF(result); |
|
580
f384e54cc75a
return file names if the resource loader returns a file()
bob
parents:
577
diff
changeset
|
129 result = tmp; |
|
f384e54cc75a
return file names if the resource loader returns a file()
bob
parents:
577
diff
changeset
|
130 } |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
131 #endif |
|
580
f384e54cc75a
return file names if the resource loader returns a file()
bob
parents:
577
diff
changeset
|
132 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
133 tmp = RWopsEncodeFilePath(result, NULL); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
134 if (tmp == NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
135 Py_DECREF(result); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
136 return NULL; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
137 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
138 else if (tmp != Py_None) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
139 Py_DECREF(result); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
140 result = tmp; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
141 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
142 else { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
143 Py_DECREF(tmp); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
144 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
145 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
146 return result; |
| 7 | 147 } |
| 148 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
149 static void |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
150 font_autoquit (void) |
| 7 | 151 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
152 if (font_initialized) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
153 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
154 font_initialized = 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
155 TTF_Quit (); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
156 } |
| 7 | 157 } |
| 158 | |
| 159 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
160 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
161 font_autoinit (PyObject* self) |
| 7 | 162 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
163 if (!font_initialized) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
164 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
165 PyGame_RegisterQuit (font_autoquit); |
| 7 | 166 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
167 if (TTF_Init ()) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
168 return PyInt_FromLong (0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
169 font_initialized = 1; |
| 7 | 170 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
171 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
172 return PyInt_FromLong (font_initialized); |
| 7 | 173 } |
| 174 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
175 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
176 fontmodule_quit (PyObject* self) |
| 7 | 177 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
178 font_autoquit (); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
179 Py_RETURN_NONE; |
| 7 | 180 } |
| 181 | |
| 182 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
183 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
184 fontmodule_init (PyObject* self) |
| 7 | 185 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
186 PyObject* result; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
187 int istrue; |
| 7 | 188 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
189 result = font_autoinit (self); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
190 istrue = PyObject_IsTrue (result); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
191 Py_DECREF (result); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
192 if (!istrue) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
193 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
194 Py_RETURN_NONE; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
195 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
196 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
197 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
198 get_init (PyObject* self) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
199 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
200 return PyInt_FromLong (font_initialized); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
201 } |
| 7 | 202 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
203 /* font object methods */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
204 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
205 font_get_height (PyObject* self) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
206 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
207 TTF_Font* font = PyFont_AsFont (self); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
208 return PyInt_FromLong (TTF_FontHeight (font)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
209 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
210 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
211 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
212 font_get_descent (PyObject* self) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
213 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
214 TTF_Font* font = PyFont_AsFont (self); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
215 return PyInt_FromLong (TTF_FontDescent (font)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
216 } |
| 7 | 217 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
218 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
219 font_get_ascent (PyObject* self) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
220 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
221 TTF_Font* font = PyFont_AsFont (self); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
222 return PyInt_FromLong (TTF_FontAscent (font)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
223 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
224 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
225 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
226 font_get_linesize (PyObject* self) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
227 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
228 TTF_Font* font = PyFont_AsFont (self); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
229 return PyInt_FromLong (TTF_FontLineSkip (font)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
230 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
231 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
232 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
233 font_get_bold (PyObject* self) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
234 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
235 TTF_Font* font = PyFont_AsFont (self); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
236 return PyInt_FromLong ((TTF_GetFontStyle (font) & TTF_STYLE_BOLD) != 0); |
| 7 | 237 } |
| 238 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
239 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
240 font_set_bold (PyObject* self, PyObject* args) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
241 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
242 TTF_Font* font = PyFont_AsFont (self); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
243 int style, val; |
| 7 | 244 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
245 if (!PyArg_ParseTuple (args, "i", &val)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
246 return NULL; |
| 7 | 247 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
248 style = TTF_GetFontStyle (font); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
249 if (val) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
250 style |= TTF_STYLE_BOLD; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
251 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
252 style &= ~TTF_STYLE_BOLD; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
253 TTF_SetFontStyle (font, style); |
| 7 | 254 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
255 Py_RETURN_NONE; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
256 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
257 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
258 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
259 font_get_italic (PyObject* self) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
260 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
261 TTF_Font* font = PyFont_AsFont (self); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
262 return PyInt_FromLong ((TTF_GetFontStyle (font) & TTF_STYLE_ITALIC) != 0); |
| 7 | 263 } |
| 264 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
265 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
266 font_set_italic (PyObject* self, PyObject* args) |
| 7 | 267 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
268 TTF_Font* font = PyFont_AsFont (self); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
269 int style, val; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
270 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
271 if (!PyArg_ParseTuple (args, "i", &val)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
272 return NULL; |
| 7 | 273 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
274 style = TTF_GetFontStyle (font); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
275 if(val) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
276 style |= TTF_STYLE_ITALIC; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
277 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
278 style &= ~TTF_STYLE_ITALIC; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
279 TTF_SetFontStyle (font, style); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
280 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
281 Py_RETURN_NONE; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
282 } |
| 7 | 283 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
284 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
285 font_get_underline (PyObject* self) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
286 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
287 TTF_Font* font = PyFont_AsFont (self); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
288 return PyInt_FromLong |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
289 ((TTF_GetFontStyle (font) & TTF_STYLE_UNDERLINE) != 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
290 } |
| 7 | 291 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
292 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
293 font_set_underline (PyObject* self, PyObject* args) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
294 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
295 TTF_Font* font = PyFont_AsFont (self); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
296 int style, val; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
297 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
298 if (!PyArg_ParseTuple (args, "i", &val)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
299 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
300 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
301 style = TTF_GetFontStyle (font); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
302 if(val) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
303 style |= TTF_STYLE_UNDERLINE; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
304 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
305 style &= ~TTF_STYLE_UNDERLINE; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
306 TTF_SetFontStyle (font, style); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
307 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
308 Py_RETURN_NONE; |
| 7 | 309 } |
| 310 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
311 static PyObject* |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
312 font_render(PyObject* self, PyObject* args) |
| 7 | 313 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
314 TTF_Font* font = PyFont_AsFont (self); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
315 int aa; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
316 PyObject* text, *final; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
317 PyObject* fg_rgba_obj, *bg_rgba_obj = NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
318 Uint8 rgba[4]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
319 SDL_Surface* surf; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
320 SDL_Color foreg, backg; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
321 int just_return; |
|
738
d1ad73342c83
Fixed up some cases which were segfaulting.
Rene Dudfield <renesd@gmail.com>
parents:
654
diff
changeset
|
322 |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
323 if (!PyArg_ParseTuple(args, "OiO|O", &text, &aa, &fg_rgba_obj, |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
324 &bg_rgba_obj)) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
325 return NULL; |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
326 } |
| 7 | 327 |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
328 if (!RGBAFromColorObj(fg_rgba_obj, rgba)) { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
329 return RAISE(PyExc_TypeError, "Invalid foreground RGBA argument"); |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
330 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
331 foreg.r = rgba[0]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
332 foreg.g = rgba[1]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
333 foreg.b = rgba[2]; |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
334 if (bg_rgba_obj != NULL) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
335 if (!RGBAFromColorObj(bg_rgba_obj, rgba)) { |
|
3023
6cc8196e0181
Font.render can set backgound to None. Fixes #49.
Rene Dudfield <renesd@gmail.com>
parents:
2120
diff
changeset
|
336 bg_rgba_obj = NULL; |
|
6cc8196e0181
Font.render can set backgound to None. Fixes #49.
Rene Dudfield <renesd@gmail.com>
parents:
2120
diff
changeset
|
337 backg.r = 0; |
|
6cc8196e0181
Font.render can set backgound to None. Fixes #49.
Rene Dudfield <renesd@gmail.com>
parents:
2120
diff
changeset
|
338 backg.g = 0; |
|
6cc8196e0181
Font.render can set backgound to None. Fixes #49.
Rene Dudfield <renesd@gmail.com>
parents:
2120
diff
changeset
|
339 backg.b = 0; |
|
6cc8196e0181
Font.render can set backgound to None. Fixes #49.
Rene Dudfield <renesd@gmail.com>
parents:
2120
diff
changeset
|
340 backg.unused = 0; |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
341 } |
|
3023
6cc8196e0181
Font.render can set backgound to None. Fixes #49.
Rene Dudfield <renesd@gmail.com>
parents:
2120
diff
changeset
|
342 else |
|
6cc8196e0181
Font.render can set backgound to None. Fixes #49.
Rene Dudfield <renesd@gmail.com>
parents:
2120
diff
changeset
|
343 { |
|
6cc8196e0181
Font.render can set backgound to None. Fixes #49.
Rene Dudfield <renesd@gmail.com>
parents:
2120
diff
changeset
|
344 backg.r = rgba[0]; |
|
6cc8196e0181
Font.render can set backgound to None. Fixes #49.
Rene Dudfield <renesd@gmail.com>
parents:
2120
diff
changeset
|
345 backg.g = rgba[1]; |
|
6cc8196e0181
Font.render can set backgound to None. Fixes #49.
Rene Dudfield <renesd@gmail.com>
parents:
2120
diff
changeset
|
346 backg.b = rgba[2]; |
|
6cc8196e0181
Font.render can set backgound to None. Fixes #49.
Rene Dudfield <renesd@gmail.com>
parents:
2120
diff
changeset
|
347 backg.unused = 0; |
|
6cc8196e0181
Font.render can set backgound to None. Fixes #49.
Rene Dudfield <renesd@gmail.com>
parents:
2120
diff
changeset
|
348 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
349 } |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
350 else { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
351 backg.r = 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
352 backg.g = 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
353 backg.b = 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
354 backg.unused = 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
355 } |
| 7 | 356 |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
357 just_return = PyObject_Not(text); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
358 if (just_return) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
359 int height = TTF_FontHeight(font); |
|
738
d1ad73342c83
Fixed up some cases which were segfaulting.
Rene Dudfield <renesd@gmail.com>
parents:
654
diff
changeset
|
360 |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
361 if (just_return == -1 || |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
362 !(PyUnicode_Check(text) || Bytes_Check(text) || text == Py_None)) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
363 PyErr_Clear(); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
364 return RAISE_TEXT_TYPE_ERROR(); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
365 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
366 surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, height, 32, |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
367 0xff<<16, 0xff<<8, 0xff, 0); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
368 if (surf == NULL) { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
369 return RAISE(PyExc_SDLError, SDL_GetError()); |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
370 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
371 if (bg_rgba_obj != NULL) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
372 Uint32 c = SDL_MapRGB(surf->format, backg.r, backg.g, backg.b); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
373 SDL_FillRect(surf, NULL, c); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
374 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
375 else { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
376 SDL_SetColorKey(surf, SDL_SRCCOLORKEY, 0); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
377 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
378 } |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
379 else if (PyUnicode_Check(text)) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
380 PyObject *bytes = PyUnicode_AsEncodedString(text, "utf-8", "replace"); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
381 const char *astring = NULL; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
382 |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
383 if (!bytes) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
384 return NULL; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
385 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
386 astring = Bytes_AsString(bytes); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
387 if (strlen(astring) != Bytes_GET_SIZE(bytes)) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
388 Py_DECREF(bytes); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
389 return RAISE(PyExc_ValueError, |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
390 "A null character was found in the text"); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
391 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
392 if (utf_8_needs_UCS_4(astring)) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
393 Py_DECREF(bytes); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
394 return RAISE(PyExc_UnicodeError, |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
395 "A Unicode character above '\\uFFFF' was found;" |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
396 " not supported"); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
397 } |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
398 if (aa) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
399 if (bg_rgba_obj == NULL) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
400 surf = TTF_RenderUTF8_Blended(font, astring, foreg); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
401 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
402 else { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
403 surf = TTF_RenderUTF8_Shaded(font, astring, foreg, backg); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
404 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
405 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
406 else { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
407 surf = TTF_RenderUTF8_Solid(font, astring, foreg); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
408 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
409 Py_DECREF(bytes); |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
410 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
411 else if (Bytes_Check(text)) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
412 const char *astring = Bytes_AsString(text); |
| 401 | 413 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
414 if (strlen(astring) != Bytes_GET_SIZE(text)) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
415 return RAISE(PyExc_ValueError, |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
416 "A null character was found in the text"); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
417 } |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
418 if (aa) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
419 if (bg_rgba_obj == NULL) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
420 surf = TTF_RenderText_Blended(font, astring, foreg); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
421 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
422 else { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
423 surf = TTF_RenderText_Shaded(font, astring, foreg, backg); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
424 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
425 } |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
426 else { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
427 surf = TTF_RenderText_Solid(font, astring, foreg); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
428 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
429 } |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
430 else { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
431 return RAISE_TEXT_TYPE_ERROR(); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
432 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
433 if (surf == NULL) { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
434 return RAISE(PyExc_SDLError, TTF_GetError()); |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
435 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
436 if (!aa && (bg_rgba_obj != NULL) && !just_return) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
437 /* turn off transparancy */ |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
438 SDL_SetColorKey(surf, 0, 0); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
439 surf->format->palette->colors[0].r = backg.r; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
440 surf->format->palette->colors[0].g = backg.g; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
441 surf->format->palette->colors[0].b = backg.b; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
442 } |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
443 final = PySurface_New(surf); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
444 if (final == NULL) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
445 SDL_FreeSurface(surf); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
446 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
447 return final; |
| 7 | 448 } |
| 449 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
450 static PyObject* |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
451 font_size(PyObject* self, PyObject* args) |
| 7 | 452 { |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
453 TTF_Font* font = PyFont_AsFont(self); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
454 int w, h; |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
455 PyObject *text; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
456 const char *string; |
| 7 | 457 |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
458 if (!PyArg_ParseTuple(args, "O", &text)) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
459 return NULL; |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
460 } |
| 7 | 461 |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
462 if (PyUnicode_Check(text)) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
463 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
464 PyObject* bytes = PyUnicode_AsEncodedString(text, "utf-8", "strict"); |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
465 int ecode; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
466 |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
467 if (!bytes) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
468 return NULL; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
469 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
470 string = Bytes_AS_STRING(bytes); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
471 ecode = TTF_SizeUTF8(font, string, &w, &h); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
472 Py_DECREF(bytes); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
473 if (ecode) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
474 return RAISE (PyExc_SDLError, TTF_GetError()); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
475 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
476 } |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
477 else if (Bytes_Check(text)) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
478 string = Bytes_AS_STRING(text); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
479 if (TTF_SizeText(font, string, &w, &h)) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
480 return RAISE (PyExc_SDLError, TTF_GetError()); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
481 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
482 } |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
483 else { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
484 return RAISE_TEXT_TYPE_ERROR(); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
485 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
486 return Py_BuildValue("(ii)", w, h); |
| 7 | 487 } |
| 488 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
489 static PyObject* |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
490 font_metrics(PyObject* self, PyObject* args) |
|
797
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
491 { |
|
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
492 TTF_Font *font = PyFont_AsFont (self); |
|
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
493 PyObject *list; |
|
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
494 PyObject *textobj; |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
495 Py_ssize_t length; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
496 Py_ssize_t i; |
|
797
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
497 int minx; |
|
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
498 int maxx; |
|
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
499 int miny; |
|
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
500 int maxy; |
|
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
501 int advance; |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
502 PyObject *unicodeobj; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
503 PyObject *listitem; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
504 Py_UNICODE *buffer; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
505 Py_UNICODE ch; |
| 7 | 506 |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
507 if (!PyArg_ParseTuple(args, "O", &textobj)) { |
|
797
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
508 return NULL; |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
509 } |
|
797
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
510 |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
511 if (PyUnicode_Check (textobj)) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
512 unicodeobj = textobj; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
513 Py_INCREF (unicodeobj); |
|
797
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
514 } |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
515 else if (Bytes_Check (textobj)) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
516 unicodeobj = PyUnicode_FromEncodedObject(textobj, "latin-1", NULL); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
517 if (!unicodeobj) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
518 return NULL; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
519 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
520 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
521 else { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
522 return RAISE_TEXT_TYPE_ERROR (); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
523 } |
|
797
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
524 |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
525 length = PyUnicode_GET_SIZE(unicodeobj); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
526 list = PyList_New(length); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
527 if (!list) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
528 Py_DECREF (unicodeobj); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
529 return NULL; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
530 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
531 buffer = PyUnicode_AS_UNICODE(unicodeobj); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
532 for (i = 0; i != length; ++i) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
533 ch = buffer[i]; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
534 /* TODO: |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
535 * TTF_GlyphMetrics() seems to return a value for any character, |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
536 * using the default invalid character, if the char is not found. |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
537 */ |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
538 if (IS_UCS_2(ch) && /* conditional and */ |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
539 !TTF_GlyphMetrics(font, (Uint16) ch, &minx, |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
540 &maxx, &miny, &maxy, &advance)) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
541 listitem = Py_BuildValue("(iiiii)", |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
542 minx, maxx, miny, maxy, advance); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
543 if (!listitem) { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
544 Py_DECREF(list); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
545 Py_DECREF(unicodeobj); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
546 return NULL; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
547 } |
|
797
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
548 } |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
549 else { |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
550 /* Not UCS-2 or no matching metrics. */ |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
551 Py_INCREF(Py_None); |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
552 listitem = Py_None; |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
553 } |
|
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
554 PyList_SET_ITEM(list, i, listitem); |
|
797
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
555 } |
|
2072
f9445209a5fa
improve unicode handling
Lenard Lindstrom <len-l@telus.net>
parents:
2064
diff
changeset
|
556 Py_DECREF(unicodeobj); |
|
797
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
557 return list; |
|
7b1c1b758702
Added font metrics support. Thanks to Marcus, Guillaume Proux
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
558 } |
| 7 | 559 |
| 524 | 560 static PyMethodDef font_methods[] = |
| 7 | 561 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
562 { "get_height", (PyCFunction) font_get_height, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
563 DOC_FONTGETHEIGHT }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
564 { "get_descent", (PyCFunction) font_get_descent, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
565 DOC_FONTGETDESCENT }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
566 { "get_ascent", (PyCFunction) font_get_ascent, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
567 DOC_FONTGETASCENT }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
568 { "get_linesize", (PyCFunction) font_get_linesize, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
569 DOC_FONTGETLINESIZE }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
570 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
571 { "get_bold", (PyCFunction) font_get_bold, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
572 DOC_FONTGETBOLD }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
573 { "set_bold", font_set_bold, METH_VARARGS, DOC_FONTSETBOLD }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
574 { "get_italic", (PyCFunction) font_get_italic, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
575 DOC_FONTGETITALIC }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
576 { "set_italic", font_set_italic, METH_VARARGS, DOC_FONTSETITALIC }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
577 { "get_underline", (PyCFunction) font_get_underline, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
578 DOC_FONTGETUNDERLINE }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
579 { "set_underline", font_set_underline, METH_VARARGS, DOC_FONTSETUNDERLINE }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
580 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
581 { "metrics", font_metrics, METH_VARARGS, DOC_FONTMETRICS }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
582 { "render", font_render, METH_VARARGS, DOC_FONTRENDER }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
583 { "size", font_size, METH_VARARGS, DOC_FONTSIZE }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
584 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
585 { NULL, NULL, 0, NULL } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
586 }; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
587 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
588 /*font object internals*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
589 static void |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
590 font_dealloc (PyFontObject* self) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
591 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
592 TTF_Font* font = PyFont_AsFont (self); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
593 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
594 if (font && font_initialized) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
595 TTF_CloseFont (font); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
596 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
597 if (self->weakreflist) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
598 PyObject_ClearWeakRefs ((PyObject*) self); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
599 Py_TYPE(self)->tp_free ((PyObject*) self); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
600 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
601 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
602 static int |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
603 font_init(PyFontObject *self, PyObject *args, PyObject *kwds) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
604 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
605 int fontsize; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
606 TTF_Font *font = NULL; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
607 PyObject *obj; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
608 PyObject *oencoded; |
|
1581
9f910eda60c5
Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents:
1563
diff
changeset
|
609 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
610 self->font = NULL; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
611 if (!PyArg_ParseTuple(args, "Oi", &obj, &fontsize)) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
612 return -1; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
613 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
614 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
615 if (!font_initialized) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
616 RAISE(PyExc_SDLError, "font not initialized"); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
617 return -1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
618 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
619 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
620 Py_INCREF(obj); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
621 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
622 if (fontsize <= 1) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
623 fontsize = 1; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
624 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
625 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
626 if (obj == Py_None) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
627 Py_DECREF(obj); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
628 obj = font_resource(font_defaultname); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
629 if (obj == NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
630 if (PyErr_Occurred() == NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
631 PyErr_Format(PyExc_RuntimeError, |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
632 "default font '%.1024s' not found", |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
633 font_defaultname); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
634 } |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
635 goto error; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
636 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
637 fontsize = (int)(fontsize * .6875); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
638 if (fontsize <= 1) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
639 fontsize = 1; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
640 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
641 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
642 else { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
643 oencoded = RWopsEncodeFilePath(obj, NULL); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
644 if (oencoded == NULL) { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
645 goto error; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
646 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
647 if (oencoded == Py_None) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
648 Py_DECREF(oencoded); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
649 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
650 else { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
651 Py_DECREF(obj); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
652 obj = oencoded; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
653 } |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
654 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
655 if (Bytes_Check(obj)) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
656 const char *filename = Bytes_AS_STRING(obj); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
657 FILE *test; |
|
1581
9f910eda60c5
Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents:
1563
diff
changeset
|
658 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
659 /*check if it is a valid file, else SDL_ttf segfaults*/ |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
660 test = fopen(filename, "rb"); |
|
2111
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
661 if (test == NULL) { |
|
1613
6a2f740abd67
clean up r 2117 bug fix
Lenard Lindstrom <len-l@telus.net>
parents:
1612
diff
changeset
|
662 PyObject *tmp = NULL; |
|
6a2f740abd67
clean up r 2117 bug fix
Lenard Lindstrom <len-l@telus.net>
parents:
1612
diff
changeset
|
663 |
|
2108
bded4713cf23
[BUG] Fix some MSVC warnings in hope of solving an error raised in font_test.py.
Lenard Lindstrom <len-l@telus.net>
parents:
2106
diff
changeset
|
664 if (strcmp(filename, font_defaultname) == 0) { |
|
2111
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
665 /* filename is the default font; get it's resource |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
666 */ |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
667 tmp = font_resource(font_defaultname); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
668 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
669 if (tmp == NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
670 if (PyErr_Occurred() == NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
671 PyErr_Format(PyExc_IOError, |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
672 "unable to read font file '%.1024s'", |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
673 filename); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
674 } |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
675 goto error; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
676 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
677 Py_DECREF(obj); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
678 obj = tmp; |
|
2111
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
679 if (Bytes_Check(obj)) { |
|
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
680 filename = Bytes_AS_STRING(obj); |
|
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
681 test = fopen(filename, "rb"); |
|
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
682 if (test == NULL) { |
|
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
683 PyErr_Format(PyExc_IOError, |
|
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
684 "unable to read font file '%.1024s'", |
|
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
685 filename); |
|
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
686 goto error; |
|
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
687 } |
|
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
688 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
689 } |
|
2111
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
690 if (Bytes_Check(obj)) { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
691 fclose(test); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
692 Py_BEGIN_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
693 font = TTF_OpenFont(filename, fontsize); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
694 Py_END_ALLOW_THREADS; |
|
2111
94c53571021e
fix bugs related to run_test.py
Lenard Lindstrom <len-l@telus.net>
parents:
2108
diff
changeset
|
695 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
696 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
697 if (font == NULL) { |
|
2106
8adeba25d5c7
[BUG] Mac builds fail: maybe using older versions of SDL_ttf or SDL_mixer. Restore version conditional code in font and music modules.
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
698 #if FONT_HAVE_RWOPS |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
699 SDL_RWops *rw = RWopsFromFileObject(obj); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
700 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
701 if (rw == NULL) { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
702 goto error; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
703 } |
|
2064
1009740fcb90
[BUG] Font loading from file object patch, and test. Thanks Janosch Graf
Rene Dudfield <renesd@gmail.com>
parents:
1937
diff
changeset
|
704 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
705 if (RWopsCheckObject(rw)) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
706 font = TTF_OpenFontIndexRW(rw, 1, fontsize, 0); |
|
2064
1009740fcb90
[BUG] Font loading from file object patch, and test. Thanks Janosch Graf
Rene Dudfield <renesd@gmail.com>
parents:
1937
diff
changeset
|
707 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
708 else { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
709 Py_BEGIN_ALLOW_THREADS; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
710 font = TTF_OpenFontIndexRW(rw, 1, fontsize, 0); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
711 Py_END_ALLOW_THREADS; |
|
2064
1009740fcb90
[BUG] Font loading from file object patch, and test. Thanks Janosch Graf
Rene Dudfield <renesd@gmail.com>
parents:
1937
diff
changeset
|
712 } |
|
2106
8adeba25d5c7
[BUG] Mac builds fail: maybe using older versions of SDL_ttf or SDL_mixer. Restore version conditional code in font and music modules.
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
713 #else |
|
8adeba25d5c7
[BUG] Mac builds fail: maybe using older versions of SDL_ttf or SDL_mixer. Restore version conditional code in font and music modules.
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
714 RAISE (PyExc_NotImplementedError, |
|
8adeba25d5c7
[BUG] Mac builds fail: maybe using older versions of SDL_ttf or SDL_mixer. Restore version conditional code in font and music modules.
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
715 "nonstring fonts require SDL_ttf-2.0.6"); |
|
8adeba25d5c7
[BUG] Mac builds fail: maybe using older versions of SDL_ttf or SDL_mixer. Restore version conditional code in font and music modules.
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
716 goto error; |
|
8adeba25d5c7
[BUG] Mac builds fail: maybe using older versions of SDL_ttf or SDL_mixer. Restore version conditional code in font and music modules.
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
717 #endif |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
718 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
719 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
720 if (font == NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
721 RAISE(PyExc_RuntimeError, SDL_GetError()); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
722 goto error; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
723 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
724 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
725 Py_DECREF(obj); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
726 self->font = font; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
727 return 0; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
728 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
729 error: |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
2083
diff
changeset
|
730 Py_DECREF(obj); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
731 return -1; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
732 } |
| 7 | 733 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
734 static PyTypeObject PyFont_Type = |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
735 { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
736 TYPE_HEAD (NULL, 0) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
737 "pygame.font.Font", |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
738 sizeof(PyFontObject), |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
739 0, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
740 (destructor)font_dealloc, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
741 0, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
742 0, /*getattr*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
743 0, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
744 0, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
745 0, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
746 0, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
747 NULL, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
748 0, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
749 (hashfunc)NULL, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
750 (ternaryfunc)NULL, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
751 (reprfunc)NULL, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
752 0L,0L,0L, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
753 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
754 DOC_PYGAMEFONTFONT, /* Documentation string */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
755 0, /* tp_traverse */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
756 0, /* tp_clear */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
757 0, /* tp_richcompare */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
758 offsetof(PyFontObject, weakreflist), /* tp_weaklistoffset */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
759 0, /* tp_iter */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
760 0, /* tp_iternext */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
761 font_methods, /* tp_methods */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
762 0, /* tp_members */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
763 0, /* tp_getset */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
764 0, /* tp_base */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
765 0, /* tp_dict */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
766 0, /* tp_descr_get */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
767 0, /* tp_descr_set */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
768 0, /* tp_dictoffset */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
769 (initproc)font_init, /* tp_init */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
770 0, /* tp_alloc */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
771 0, /* tp_new */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
772 }; |
| 7 | 773 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
774 //PyType_GenericNew, /* tp_new */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
775 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
776 /*font module methods*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
777 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
778 get_default_font (PyObject* self) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
779 { |
|
1563
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1553
diff
changeset
|
780 return Text_FromUTF8 (font_defaultname); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
781 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
782 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
783 static PyMethodDef _font_methods[] = |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
784 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
785 { "__PYGAMEinit__", (PyCFunction) font_autoinit, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
786 "auto initialize function for font" }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
787 { "init", (PyCFunction) fontmodule_init, METH_NOARGS, DOC_PYGAMEFONTINIT }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
788 { "quit", (PyCFunction) fontmodule_quit, METH_NOARGS, DOC_PYGAMEFONTQUIT }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
789 { "get_init", (PyCFunction) get_init, METH_NOARGS, DOC_PYGAMEFONTGETINIT }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
790 { "get_default_font", (PyCFunction) get_default_font, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
791 DOC_PYGAMEFONTGETDEFAULTFONT }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
792 { NULL, NULL, 0, NULL } |
| 7 | 793 }; |
| 794 | |
| 795 | |
| 796 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
797 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
798 PyFont_New (TTF_Font* font) |
| 7 | 799 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
800 PyFontObject* fontobj; |
| 577 | 801 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
802 if (!font) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
803 return RAISE (PyExc_RuntimeError, "unable to load font."); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
804 fontobj = (PyFontObject *) PyFont_Type.tp_new (&PyFont_Type, NULL, NULL); |
| 7 | 805 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
806 if (fontobj) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
807 fontobj->font = font; |
| 524 | 808 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
809 return (PyObject*) fontobj; |
| 7 | 810 } |
| 811 | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
812 MODINIT_DEFINE (font) |
| 7 | 813 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
814 PyObject *module, *apiobj; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
815 static void* c_api[PYGAMEAPI_FONT_NUMSLOTS]; |
| 7 | 816 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
817 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
818 static struct PyModuleDef _module = { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
819 PyModuleDef_HEAD_INIT, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
820 "font", |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
821 DOC_PYGAMEFONT, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
822 -1, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
823 _font_methods, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
824 NULL, NULL, NULL, NULL |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
825 }; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
826 #endif |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
827 |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
828 /* imported needed apis; Do this first so if there is an error |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
829 the module is not loaded. |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
830 */ |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
831 import_pygame_base (); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
832 if (PyErr_Occurred ()) { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
833 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
834 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
835 import_pygame_color (); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
836 if (PyErr_Occurred ()) { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
837 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
838 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
839 import_pygame_surface (); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
840 if (PyErr_Occurred ()) { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
841 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
842 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
843 import_pygame_rwobject (); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
844 if (PyErr_Occurred ()) { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
845 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
846 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
847 |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
848 /* type preparation */ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
849 if (PyType_Ready (&PyFont_Type) < 0) { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
850 MODINIT_ERROR; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
851 } |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
852 PyFont_Type.tp_new = PyType_GenericNew; |
| 7 | 853 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
854 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
855 module = PyModule_Create (&_module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
856 #else |
|
1581
9f910eda60c5
Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents:
1563
diff
changeset
|
857 module = Py_InitModule3 (MODPREFIX "font", |
|
9f910eda60c5
Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents:
1563
diff
changeset
|
858 _font_methods, |
|
9f910eda60c5
Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents:
1563
diff
changeset
|
859 DOC_PYGAMEFONT); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
860 #endif |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
861 if (module == NULL) { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
862 MODINIT_ERROR; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
863 } |
| 7 | 864 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
865 Py_INCREF ((PyObject*) &PyFont_Type); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
866 if (PyModule_AddObject (module, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
867 "FontType", |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
868 (PyObject *) &PyFont_Type) == -1) { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
869 Py_DECREF ((PyObject *) &PyFont_Type); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
870 DECREF_MOD (module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
871 MODINIT_ERROR; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
872 } |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
873 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
874 Py_INCREF ((PyObject*) &PyFont_Type); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
875 if (PyModule_AddObject (module, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
876 "Font", |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
877 (PyObject *) &PyFont_Type) == -1) { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
878 Py_DECREF ((PyObject *) &PyFont_Type); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
879 DECREF_MOD (module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
880 MODINIT_ERROR; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
881 } |
| 7 | 882 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
883 /* export the c api */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
884 c_api[0] = &PyFont_Type; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
885 c_api[1] = PyFont_New; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
797
diff
changeset
|
886 c_api[2] = &font_initialized; |
|
2120
42e2bde1a12c
Use capsule objects in preference to cobject objects. This allows Pygame to build an run from Python 3.2, which has to cobjects.
Lenard Lindstrom <len-l@telus.net>
parents:
2112
diff
changeset
|
887 apiobj = encapsulate_api (c_api, "font"); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
888 if (apiobj == NULL) { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
889 DECREF_MOD (module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
890 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
891 } |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
892 if (PyModule_AddObject (module, PYGAMEAPI_LOCAL_ENTRY, apiobj) == -1) { |
|
1877
4f5abc24884f
Memory leak in a few modules. Thanks Lorenz Quack.
Rene Dudfield <renesd@gmail.com>
parents:
1613
diff
changeset
|
893 Py_DECREF (apiobj); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
894 DECREF_MOD (module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
895 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
896 } |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
897 MODINIT_RETURN (module); |
| 7 | 898 } |
