2
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version. The Blender
8
* Foundation also sells licenses for use in proprietary software under
9
* the Blender License. See http://www.blender.org/BL/ for information
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software Foundation,
19
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
22
* All rights reserved.
24
* This is a new part of Blender.
26
* Contributor(s): Joilnen Leite
28
* ***** END GPL/BL DUAL LICENSE BLOCK *****
31
#include "BKE_global.h"
32
#include "BKE_packedFile.h"
33
#include "DNA_vfont_types.h"
34
#include "DNA_packedFile_types.h"
38
extern PyObject *M_Text3d_LoadFont( PyObject * self, PyObject * args );
40
/*--------------------Python API function prototypes for the Font module----*/
41
PyObject *M_Font_New( PyObject * self, PyObject * args );
42
static PyObject *M_Font_Get( PyObject * self, PyObject * args );
44
/*------------------------Python API Doc strings for the Font module--------*/
45
char M_Font_doc[] = "The Blender Font module\n\n\
46
This module provides control over **Font Data** objects in Blender.\n\n\
48
from Blender import Text3d.Font\n\
49
l = Text3d.Font.New()\n";
50
char M_Font_New_doc[] = "(name) - return a new Font of name 'name'.";
51
char M_Font_Get_doc[] = "(name) - return a new Font of name 'name'.";
53
/*----- Python method structure definition for Blender.Text3d.Font module---*/
54
struct PyMethodDef M_Font_methods[] = {
55
{"New", ( PyCFunction ) M_Font_New, METH_VARARGS, M_Font_New_doc},
56
{"Get", ( PyCFunction ) M_Font_Get, METH_VARARGS, M_Font_New_doc},
60
/*--------------- Python BPy_Bone methods declarations:-------------------*/
61
static PyObject *Font_getName( BPy_Font * self );
62
static PyObject *Font_setName( BPy_Font * self, PyObject * args );
63
static PyObject *Font_pack( BPy_Font * self, PyObject * args );
64
static PyObject *Font_isPacked( BPy_Font * self );
66
/*--------------- Python BPy_Font methods table:--------------------------*/
67
static PyMethodDef BPy_Font_methods[] = {
68
{"GetName", ( PyCFunction ) Font_getName, METH_NOARGS,
69
"() - return Font name"},
70
{"getName", ( PyCFunction ) Font_getName, METH_NOARGS,
71
"() - return Font name"},
72
{"setName", ( PyCFunction ) Font_setName, METH_VARARGS,
73
"() - return Font name"},
74
{"pack", ( PyCFunction ) Font_pack, METH_VARARGS,
75
"() - pack/unpack Font"},
76
{"isPacked", ( PyCFunction ) Font_isPacked, METH_NOARGS,
77
"() - pack/unpack Font"},
81
/*--------------- Python TypeBone callback function prototypes----------*/
82
static void Font_dealloc( BPy_Font * font );
83
static PyObject *Font_getAttr( BPy_Font * bone, char *name );
84
static int Font_setAttr( BPy_Font * font, char *name, PyObject * v );
85
static int Font_compare( BPy_Font * a1, BPy_Font * a2 );
86
static PyObject *Font_repr( BPy_Font * font );
88
PyTypeObject Font_Type = {
89
PyObject_HEAD_INIT( NULL )
92
sizeof( BPy_Font ), /* tp_basicsize */
95
( destructor ) Font_dealloc, /* tp_dealloc */
97
( getattrfunc ) Font_getAttr, /* tp_getattr */
98
( setattrfunc ) Font_setAttr, /* tp_setattr */
99
( cmpfunc ) Font_compare, /* tp_compare */
100
( reprfunc ) Font_repr, /* tp_repr */
101
0, /* tp_as_number */
102
0, /* tp_as_sequence */
103
0, /* tp_as_mapping */
108
BPy_Font_methods, /* tp_methods */
112
/*--------------- Font Module Init-----------------------------*/
113
PyObject *Font_Init( void )
117
Font_Type.ob_type = &PyType_Type;
119
submodule = Py_InitModule3( "Blender.Text3d.Font",
120
M_Font_methods, M_Font_doc );
122
return ( submodule );
125
/*--------------- Bone module internal callbacks-----------------*/
126
/*---------------BPy_Bone internal callbacks/methods-------------*/
128
//--------------- dealloc------------------------------------------
129
static void Font_dealloc( BPy_Font * self )
131
PyObject_DEL( self );
134
/*---------------getattr-------------------------------------------*/
135
static PyObject *Font_getAttr( BPy_Font * self, char *name )
137
return Py_FindMethod( BPy_Font_methods, ( PyObject * ) self, name );
140
/*--------------- setattr-------------------------------------------*/
141
static int Font_setAttr( BPy_Font * self, char *name, PyObject * value )
146
/*--------------- repr---------------------------------------------*/
147
static PyObject *Font_repr( BPy_Font * self )
150
return PyString_FromFormat( "[Font \"%s\"]",
153
return PyString_FromString( "NULL" );
156
/*--------------- compare------------------------------------------*/
157
static int Font_compare( BPy_Font * a, BPy_Font * b )
159
VFont *pa = a->font, *pb = b->font;
160
return ( pa == pb ) ? 0 : -1;
163
/*--------------- Font_CreatePyObject---------------------------------*/
164
PyObject *Font_CreatePyObject( struct VFont * font )
168
blen_font = ( BPy_Font * ) PyObject_NEW( BPy_Font, &Font_Type );
170
/*set the all important Bone flag*/
171
blen_font->font = font;
173
return ( ( PyObject * ) blen_font );
176
/*--------------- Font_CheckPyObject--------------------------------*/
177
int Font_CheckPyObject( PyObject * py_obj )
179
return ( py_obj->ob_type == &Font_Type );
182
/*--------------- Font_FromPyObject---------------------------------*/
183
struct VFont *Font_FromPyObject( PyObject * py_obj )
187
blen_obj = ( BPy_Font * ) py_obj;
188
if( !( ( BPy_Font * ) py_obj )->font ) { /*test to see if linked to text3d*/
192
//use bone datastruct
193
return ( blen_obj->font );
197
/*--------------- Python Font Module methods------------------------*/
199
/*--------------- Blender.Text3d.Font.New()-----------------------*/
200
PyObject *M_Font_New( PyObject * self, PyObject * args )
202
char *name_str = "<builtin>";
203
// char *parent_str = "";
204
BPy_Font *py_font = NULL; /* for Font Data object wrapper in Python */
207
if( !PyArg_ParseTuple( args, "|s", &name_str ) )
208
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
209
"expected string or empty argument" ) );
211
/*create python font*/
212
if( !S_ISDIR(BLI_exist(name_str)) ) {
213
tmp= Py_BuildValue("(s)", name_str);
214
py_font= (BPy_Font *) M_Text3d_LoadFont (self, Py_BuildValue("(s)", name_str));
218
return EXPP_incr_ret( Py_None );
219
return ( PyObject * ) py_font;
222
/*--------------- Blender.Text3d.Font.Get()-----------------------*/
223
static PyObject *M_Font_Get( PyObject * self, PyObject * args )
225
return M_Font_New (self, args);
228
/*--------------- Python BPy_Font methods---------------------------*/
230
/*--------------- BPy_Font.getName()--------------------------------*/
231
static PyObject *Font_getName( BPy_Font * self )
233
PyObject *attr = NULL;
236
attr = PyString_FromString( self->font->name );
240
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
241
"couldn't get Bone.name attribute" ) );
244
/*--------------- BPy_Font.setName()---------------------------------*/
245
static PyObject *Font_setName( BPy_Font * self, PyObject * args )
250
if( !PyArg_ParseTuple( args, "s", &name ) )
251
return ( EXPP_ReturnPyObjError
252
( PyExc_AttributeError,
253
"expected string argument" ) );
255
/* guarantee a null terminated string of reasonable size */
256
PyOS_snprintf( buf, sizeof( buf ), "%s", name );
259
BLI_strncpy( self->font->name, buf, sizeof( buf ) );
260
return EXPP_incr_ret( Py_None );
263
/*--------------- BPy_Font.pack()---------------------------------*/
264
static PyObject *Font_pack( BPy_Font * self, PyObject * args )
267
if( !PyArg_ParseTuple( args, "i", &pack ) )
268
return ( EXPP_ReturnPyObjError
269
( PyExc_AttributeError,
270
"expected string argument" ) );
271
if( pack && !self->font->packedfile )
272
self->font->packedfile = newPackedFile(self->font->name);
273
else if (self->font->packedfile)
274
if (unpackVFont(self->font, PF_ASK) == RET_OK)
275
G.fileflags &= ~G_AUTOPACK;
278
return EXPP_incr_ret( Py_None );
281
/*--------------- BPy_Font.ispack()---------------------------------*/
282
static PyObject *Font_isPacked( BPy_Font * self )
284
if (G.fileflags & G_AUTOPACK)
285
return EXPP_incr_ret_True();
287
return EXPP_incr_ret_False();