~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Text3d.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: Text3d.c,v 1.22 2006/12/27 05:04:19 campbellbarton Exp $
 
2
 * $Id: Text3d.c,v 1.30 2007/03/26 02:10:22 campbellbarton Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
27
27
 *
28
28
 * Contributor(s): Joilnen Leite
29
29
 *                 Johnny Matthews
 
30
 *                 Campbell BArton
30
31
 *
31
32
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
32
33
 */
33
 
 
 
34
 
34
35
#include "Text3d.h" /*This must come first*/
35
36
 
36
37
#include "DNA_object_types.h"
44
45
#include "constant.h"
45
46
#include "Font.h"
46
47
#include "gen_utils.h"
47
 
 
48
 
//no prototypes declared in header files - external linkage outside of python
 
48
#include "gen_library.h"
 
49
 
 
50
 
 
51
enum t3d_consts {
 
52
        EXPP_T3D_ATTR_FRAME_WIDTH = 0,
 
53
        EXPP_T3D_ATTR_FRAME_HEIGHT,
 
54
        EXPP_T3D_ATTR_FRAME_X,
 
55
        EXPP_T3D_ATTR_FRAME_Y
 
56
};
 
57
 
 
58
 
 
59
/*no prototypes declared in header files - external linkage outside of python*/
49
60
extern VFont *get_builtin_font(void);  
50
61
extern void freedisplist(struct ListBase *lb);
51
62
extern VFont *give_vfontpointer(int);
80
91
/* Python Text3d_Type callback function prototypes:                          */
81
92
/*****************************************************************************/
82
93
/* int Text3dPrint (BPy_Text3d *msh, FILE *fp, int flags); */
83
 
static void Text3dDeAlloc( BPy_Text3d * self );
84
 
static int Text3dSetAttr( BPy_Text3d * self, char *name, PyObject * value );
85
 
static PyObject *Text3dGetAttr( BPy_Text3d * self, char *name );
86
 
static PyObject *Text3dRepr( BPy_Text3d * self );
 
94
 
 
95
 
 
96
static PyObject *Text3d_repr( BPy_Text3d * self );
 
97
static int Text3d_compare( BPy_Text3d * a, BPy_Text3d * b );
87
98
 
88
99
/*****************************************************************************/
89
100
/* Python BPy_Text3d methods declarations:                                   */
123
134
static PyObject *Text3d_setAlignment( BPy_Text3d * self, PyObject * args );
124
135
static PyObject *Text3d_getFont( BPy_Text3d * self );
125
136
static PyObject *Text3d_setFont( BPy_Text3d * self, PyObject * args );
 
137
static PyObject *Text3d_addFrame( BPy_Text3d * self );
 
138
static PyObject *Text3d_removeFrame( BPy_Text3d * self, PyObject * args );
126
139
 
127
140
/*****************************************************************************/
128
141
/* Python BPy_Text3d methods table:                                            */
199
212
        METH_NOARGS, "() - Gets font list for Text3d"},
200
213
        {"setFont", ( PyCFunction ) Text3d_setFont,
201
214
        METH_VARARGS, "() - Sets font for Text3d"},
 
215
        {"addFrame", ( PyCFunction ) Text3d_addFrame,
 
216
        METH_NOARGS, "() - adds a new text frame"},
 
217
        {"removeFrame", ( PyCFunction ) Text3d_removeFrame,
 
218
        METH_VARARGS, "(index) - remove this frame"},
202
219
        {NULL, NULL, 0, NULL}
203
220
};
204
221
 
 
222
 
 
223
static PyObject *Text3d_getTotalFrames( BPy_Text3d * self )
 
224
{
 
225
        return PyInt_FromLong( (long)(self->curve->totbox ) );
 
226
}
 
227
 
 
228
static PyObject *Text3d_getActiveFrame( BPy_Text3d * self )
 
229
{
 
230
        return PyInt_FromLong( (long)(self->curve->actbox-1) );
 
231
}
 
232
 
 
233
static int Text3d_setActiveFrame( BPy_Text3d * self, PyObject * value )
 
234
{
 
235
        struct Curve *curve= self->curve;       
 
236
        PyObject* frame_int = PyNumber_Int( value );
 
237
        int index;
 
238
        
 
239
 
 
240
        if( !frame_int )
 
241
                return EXPP_ReturnIntError( PyExc_TypeError,
 
242
                                "expected integer argument" );
 
243
        
 
244
        index = ( int )PyInt_AS_LONG( frame_int );
 
245
        index ++;
 
246
        if (index < 1 || index > curve->totbox)
 
247
                return EXPP_ReturnIntError( PyExc_IndexError,
 
248
                                "index out of range" );
 
249
        
 
250
        curve->actbox = index;
 
251
        
 
252
        return 0;
 
253
}
 
254
 
 
255
 
 
256
static PyObject *getFloatAttr( BPy_Text3d *self, void *type )
 
257
{
 
258
        float param;
 
259
        struct Curve *curve= self->curve;
 
260
        
 
261
        switch( (int)type ) {
 
262
        case EXPP_T3D_ATTR_FRAME_WIDTH: 
 
263
                param = curve->tb[curve->actbox-1].w;
 
264
                break;
 
265
        case EXPP_T3D_ATTR_FRAME_HEIGHT: 
 
266
                param = curve->tb[curve->actbox-1].h;
 
267
                break;
 
268
        case EXPP_T3D_ATTR_FRAME_X: 
 
269
                param = curve->tb[curve->actbox-1].x;
 
270
                break;
 
271
        case EXPP_T3D_ATTR_FRAME_Y: 
 
272
                param = curve->tb[curve->actbox-1].y;
 
273
                break;
 
274
        
 
275
        default:
 
276
                return EXPP_ReturnPyObjError( PyExc_RuntimeError, 
 
277
                                "undefined type in getFloatAttr" );
 
278
        }
 
279
        return PyFloat_FromDouble( param );
 
280
}
 
281
 
 
282
static int setFloatAttrClamp( BPy_Text3d *self, PyObject *value, void *type )
 
283
{
 
284
        float *param;
 
285
        struct Curve *curve= self->curve;
 
286
        float min, max;
 
287
 
 
288
        switch( (int)type ) {
 
289
        case EXPP_T3D_ATTR_FRAME_WIDTH:
 
290
                min = 0.0;
 
291
                max = 50.0;
 
292
                param = &(curve->tb[curve->actbox-1].w);
 
293
                break;
 
294
        case EXPP_T3D_ATTR_FRAME_HEIGHT:
 
295
                min = 0.0;
 
296
                max = 50.0;
 
297
                param = &(curve->tb[curve->actbox-1].h);
 
298
                break;
 
299
        case EXPP_T3D_ATTR_FRAME_X:
 
300
                min = 0.0;
 
301
                max = 50.0;
 
302
                param = &(curve->tb[curve->actbox-1].x);
 
303
                break;
 
304
        case EXPP_T3D_ATTR_FRAME_Y:
 
305
                min = 0.0;
 
306
                max = 50.0;
 
307
                param = &(curve->tb[curve->actbox-1].y);
 
308
                break;
 
309
        
 
310
        default:
 
311
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
312
                                "undefined type in setFloatAttrClamp" );
 
313
        }
 
314
 
 
315
        return EXPP_setFloatClamped( value, param, min, max );
 
316
}
 
317
 
 
318
/*****************************************************************************/
 
319
/* Python attributes get/set structure:                                      */
 
320
/*****************************************************************************/
 
321
static PyGetSetDef BPy_Text3d_getseters[] = {
 
322
        GENERIC_LIB_GETSETATTR, /* didnt have any attributes, at least lets have the standard ID attrs */
 
323
        {"activeFrame",
 
324
         (getter)Text3d_getActiveFrame, (setter)Text3d_setActiveFrame,
 
325
         "the index of the active text frame",
 
326
         NULL},
 
327
        {"totalFrames",
 
328
         (getter)Text3d_getTotalFrames, (setter)NULL,
 
329
         "the total number of text frames",
 
330
         NULL},
 
331
 
 
332
        {"frameWidth",
 
333
         (getter)getFloatAttr, (setter)setFloatAttrClamp,
 
334
         "the width of the active text frame",
 
335
         (void *)EXPP_T3D_ATTR_FRAME_WIDTH},
 
336
        {"frameHeight",
 
337
         (getter)getFloatAttr, (setter)setFloatAttrClamp,
 
338
         "the height of the active text frame",
 
339
         (void *)EXPP_T3D_ATTR_FRAME_HEIGHT},
 
340
        {"frameX",
 
341
         (getter)getFloatAttr, (setter)setFloatAttrClamp,
 
342
         "the X position of the active text frame",
 
343
         (void *)EXPP_T3D_ATTR_FRAME_X},
 
344
        {"frameY",
 
345
         (getter)getFloatAttr, (setter)setFloatAttrClamp,
 
346
         "the Y position of the active text frame",
 
347
         (void *)EXPP_T3D_ATTR_FRAME_Y},
 
348
        {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
 
349
};
 
350
 
205
351
/*****************************************************************************/
206
352
/* Python Text3d_Type structure definition:                                  */
207
353
/*****************************************************************************/
212
358
        sizeof( BPy_Text3d ),   /* tp_basicsize */
213
359
        0,                      /* tp_itemsize */
214
360
        /* methods */
215
 
        ( destructor ) Text3dDeAlloc,   /* tp_dealloc */
216
 
        0,                      /* tp_print */
217
 
        ( getattrfunc ) Text3dGetAttr,  /* tp_getattr */
218
 
        ( setattrfunc ) Text3dSetAttr,  /* tp_setattr */
219
 
        0,                      /* tp_compare */
220
 
        ( reprfunc ) Text3dRepr,        /* tp_repr */
221
 
        0,                      /* tp_as_number */
222
 
        0,                      /* tp_as_sequence */
223
 
        0,                      /* tp_as_mapping */
224
 
        0,                      /* tp_as_hash */
225
 
        0, 0, 0, 0, 0, 0,
226
 
        0,                      /* tp_doc */
227
 
        0, 0, 0, 0, 0, 0,
228
 
        BPy_Text3d_methods,     /* tp_methods */
229
 
        0,                      /* tp_members */
 
361
        NULL,                   /* tp_dealloc */
 
362
        NULL,                   /* tp_print */
 
363
        NULL,                   /* tp_getattr */
 
364
        NULL,                   /* tp_setattr */
 
365
        ( cmpfunc ) Text3d_compare,                     /* tp_compare */
 
366
        ( reprfunc ) Text3d_repr,       /* tp_repr */
 
367
        /* Method suites for standard classes */
 
368
 
 
369
        NULL,                       /* PyNumberMethods *tp_as_number; */
 
370
        NULL,                       /* PySequenceMethods *tp_as_sequence; */
 
371
        NULL,                       /* PyMappingMethods *tp_as_mapping; */
 
372
 
 
373
        /* More standard operations (here for binary compatibility) */
 
374
 
 
375
        ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
 
376
        NULL,                       /* ternaryfunc tp_call; */
 
377
        NULL,                       /* reprfunc tp_str; */
 
378
        NULL,                       /* getattrofunc tp_getattro; */
 
379
        NULL,                       /* setattrofunc tp_setattro; */
 
380
 
 
381
        /* Functions to access object as input/output buffer */
 
382
        NULL,                       /* PyBufferProcs *tp_as_buffer; */
 
383
 
 
384
  /*** Flags to define presence of optional/expanded features ***/
 
385
        Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
 
386
 
 
387
        NULL,                       /*  char *tp_doc;  Documentation string */
 
388
  /*** Assigned meaning in release 2.0 ***/
 
389
        /* call function for all accessible objects */
 
390
        NULL,                       /* traverseproc tp_traverse; */
 
391
 
 
392
        /* delete references to contained objects */
 
393
        NULL,                       /* inquiry tp_clear; */
 
394
 
 
395
  /***  Assigned meaning in release 2.1 ***/
 
396
  /*** rich comparisons ***/
 
397
        NULL,                       /* richcmpfunc tp_richcompare; */
 
398
 
 
399
  /***  weak reference enabler ***/
 
400
        0,                          /* long tp_weaklistoffset; */
 
401
 
 
402
  /*** Added in release 2.2 ***/
 
403
        /*   Iterators */
 
404
        NULL,                       /* getiterfunc tp_iter; */
 
405
        NULL,                       /* iternextfunc tp_iternext; */
 
406
 
 
407
  /*** Attribute descriptor and subclassing stuff ***/
 
408
        BPy_Text3d_methods,           /* struct PyMethodDef *tp_methods; */
 
409
        NULL,                       /* struct PyMemberDef *tp_members; */
 
410
        BPy_Text3d_getseters,         /* struct PyGetSetDef *tp_getset; */
 
411
        NULL,                       /* struct _typeobject *tp_base; */
 
412
        NULL,                       /* PyObject *tp_dict; */
 
413
        NULL,                       /* descrgetfunc tp_descr_get; */
 
414
        NULL,                       /* descrsetfunc tp_descr_set; */
 
415
        0,                          /* long tp_dictoffset; */
 
416
        NULL,                       /* initproc tp_init; */
 
417
        NULL,                       /* allocfunc tp_alloc; */
 
418
        NULL,                       /* newfunc tp_new; */
 
419
        /*  Low-level free-memory routine */
 
420
        NULL,                       /* freefunc tp_free;  */
 
421
        /* For PyObject_IS_GC */
 
422
        NULL,                       /* inquiry tp_is_gc;  */
 
423
        NULL,                       /* PyObject *tp_bases; */
 
424
        /* method resolution order */
 
425
        NULL,                       /* PyObject *tp_mro;  */
 
426
        NULL,                       /* PyObject *tp_cache; */
 
427
        NULL,                       /* PyObject *tp_subclasses; */
 
428
        NULL,                       /* PyObject *tp_weaklist; */
 
429
        NULL
230
430
};
231
431
 
 
432
 
232
433
/* 
233
434
 *   Text3d_update( )
234
435
 *   method to update display list for a Curve.
255
456
                         ( PyExc_AttributeError,
256
457
                           "expected string argument or no argument" ) );
257
458
 
258
 
        bltext3d = add_curve( OB_FONT );        /* first create the Curve Data in Blender */
 
459
        bltext3d = add_curve( "Text", OB_FONT );        /* first create the Curve Data in Blender */
259
460
        bltext3d->vfont= get_builtin_font();
260
461
        bltext3d->vfont->id.us++;
261
462
        bltext3d->str= MEM_mallocN(12, "str");
369
570
        PyObject *submodule, *dict;
370
571
 
371
572
        //add module...
372
 
        Text3d_Type.ob_type = &PyType_Type;
 
573
        if( PyType_Ready( &Text3d_Type ) < 0 )
 
574
                return NULL;
 
575
        
373
576
        submodule = Py_InitModule3( "Blender.Text3d", M_Text3d_methods, 
374
577
                M_Text3D_doc);
375
578
 
395
598
        return ( submodule );
396
599
}
397
600
 
398
 
static void Text3dDeAlloc( BPy_Text3d * self )
399
 
{
400
 
        PyObject_DEL( self );
401
 
}
402
 
 
403
 
/*****************************************************************************/
404
 
/* Function:    Text3dGetAttr                                                */
405
 
/* Description: This is a callback function for the BPy_Text3d type. It is   */
406
 
/*              the function that accesses BPy_Text3d "member variables" and */
407
 
/*              methods.                                                     */
408
 
/*****************************************************************************/
409
 
static PyObject *Text3dGetAttr( BPy_Text3d * self, char *name )
410
 
{
411
 
        return Py_FindMethod( BPy_Text3d_methods, ( PyObject * ) self, name );
412
 
}
413
 
 
414
 
/*****************************************************************************
415
 
 * Function:    Text3dSetAttr                                                
416
 
 * Description: Callback function for the BPy_Effect type to  
417
 
 *              sets Text3d Data attributes (member variables). 
418
 
 * 
419
 
 ****************************************************************************/
420
 
 
421
 
static int Text3dSetAttr( BPy_Text3d * self, char *name, PyObject * value )
422
 
{
423
 
        return 0;               /* normal exit */
424
 
}
425
 
 
426
 
 
427
601
/****************************************************************************
428
 
 * Function:    Text3dRepr                                                   
 
602
 * Function:    Text3d_repr                                                   
429
603
 * Description: Callback function for the BPy_Text3d type to It      
430
604
 *               build a meaninful string to represent Text3d objects.      
431
605
 *
432
606
 ***************************************************************************/
433
607
 
434
 
static PyObject *Text3dRepr( BPy_Text3d * self )
 
608
static PyObject *Text3d_repr( BPy_Text3d * self )
435
609
{
436
610
        /* skip over CU in idname.  CUTEXT */
437
611
        return PyString_FromFormat( "[Text3d \"%s\"]",
438
612
                                                                self->curve->id.name + 2 ); 
439
613
}
440
614
 
441
 
 
442
 
 
443
 
int Text3d_CheckPyObject( PyObject * py_obj )
 
615
/****************************************************************************
 
616
 * Function:    Text3d_compare                                                   
 
617
 * Description: Callback function for the BPy_Text3d type to Compare 2 types
 
618
 *
 
619
 ***************************************************************************/
 
620
 
 
621
/* mat_a==mat_b or mat_a!=mat_b*/
 
622
static int Text3d_compare( BPy_Text3d * a, BPy_Text3d * b )
444
623
{
445
 
        return ( py_obj->ob_type == &Text3d_Type );
 
624
        return ( a->curve == b->curve) ? 0 : -1;
446
625
}
447
626
 
448
627
struct Text3d *Text3d_FromPyObject( PyObject * py_obj )
940
1119
                self->curve->vfont= vf;
941
1120
        }
942
1121
        else {
943
 
                load_vfont (pyobj->font->name);
944
 
                vf= exist_vfont(pyobj->font->name);
 
1122
                vf= load_vfont (pyobj->font->name);
945
1123
                if (vf) {
946
1124
                        id_us_plus((ID *)vf);
947
1125
                        self->curve->vfont->id.us--;
951
1129
        Py_RETURN_NONE;
952
1130
}
953
1131
 
 
1132
static PyObject *Text3d_addFrame( BPy_Text3d * self )
 
1133
{
 
1134
        Curve *cu = self->curve;
 
1135
        
 
1136
        if (cu->totbox >= 256)  
 
1137
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
1138
                        "limited to 256 frames" );
 
1139
        
 
1140
        cu->totbox++;   
 
1141
        cu->tb[cu->totbox-1]= cu->tb[cu->totbox-2];
 
1142
        Py_RETURN_NONE;
 
1143
}
 
1144
 
 
1145
static PyObject *Text3d_removeFrame( BPy_Text3d * self, PyObject * args )
 
1146
{
 
1147
        Curve *cu = self->curve;
 
1148
        int index, i;
 
1149
        
 
1150
        if (cu->totbox == 1)
 
1151
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
1152
                        "cannot remove the last frame" );
 
1153
        
 
1154
        index = cu->totbox-1;
 
1155
        
 
1156
        if( !PyArg_ParseTuple( args, "|i", &index ) )
 
1157
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
1158
                        "expected an int" );
 
1159
        
 
1160
        if (index < 0 || index >= cu->totbox )
 
1161
                return EXPP_ReturnPyObjError( PyExc_IndexError,
 
1162
                        "index out of range" );
 
1163
        
 
1164
        for (i = index; i < cu->totbox; i++) cu->tb[i]= cu->tb[i+1];
 
1165
        cu->totbox--;
 
1166
        cu->actbox--;
 
1167
        Py_RETURN_NONE;
 
1168
}
 
1169
 
 
1170
 
954
1171
PyObject *M_Text3d_LoadFont( PyObject * self, PyObject * args )
955
1172
{
956
1173
        char *fontfile= NULL;